Best Python code snippet using tempest_python
Servers.py
Source:Servers.py
1# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP2# (c) Copyright 2017-2018 SUSE LLC3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15#16import logging17import logging.config18from ardana_configurationprocessor.cp.model.BuilderPlugin \19 import ArtifactMode20LOG = logging.getLogger(__name__)21SP = " "22class Servers(object):23 def render_servers(self):24 def _add_server_row(table, s, hypervisor=None, num_vms=0, show_hypervisor=False):25 row = table.tr26 if hypervisor:27 if show_hypervisor:28 span = num_vms + 129 id = row.td(rowspan=str(span))30 id.a("%s" % hypervisor, href="Servers/%s.html" % hypervisor)31 elif hypervisor == 'None':32 # Special case for non hypervisor servers when we have hypervisors33 # in the cloud34 id = row.td(klass='title')35 if s['id'] != hypervisor:36 id = row.td()37 id.a("%s" % s['id'], href="Servers/%s.html" % s['id'])38 else:39 id = row.td(klass='title')40 td = row.td('')41 td.a(s['role'], href="Server_Roles.html#%s.html" % s['role'])42 row.td(s.get('server_group', ''), escape=False)43 row.td(s['state'])44 if s['state'] == 'available':45 # No other data if the server / vm isn't allocated46 return47 cp = row.td48 if 'control-plane-name' in s:49 cp.a(" %s" % s['control-plane-name'],50 href="../Control_Planes.html#%s" % s['control-plane-name'])51 row.td(s.get('failure-zone', ''), escape=False)52 row.td(s.get('name', ''), escape=False)53 if s.get('hypervisor-id'):54 row.td(str(s.get('vm_no_of_vcpus', '')), escape=False)55 mem_size = s.get('memory-model', {}).get('vm_ram_size_in_k', 0)56 row.td(self.mem_size_string(mem_size))57 # Create a page for each server58 for s in sorted(self.servers, key=lambda s: s['id']):59 self._render_server(s)60 h = self._create_page()61 table = h.table()62 # Add the Titles63 title_row = table.tr64 # See if we have any vm-factories in this model65 vm_factories = {}66 for s in self.servers:67 if s.get('vm-factory', False):68 vm_factories[s['id']] = {'hypervisor': s,69 'vms': []}70 for s in self.servers:71 hypervisor = s.get('hypervisor-id')72 if hypervisor:73 vm_factories[hypervisor]['vms'].append(s)74 if vm_factories:75 title_row.td("Hypervisor", klass='title', align='center')76 for x in ['Id', 'Role', 'Group', 'State', 'Control Plane', 'Failure Zone', 'Name']:77 title_row.td(x, klass='title', align='center')78 if vm_factories:79 title_row.td("VCPUs", klass='title', align='center')80 title_row.td("Memory", klass='title', align='center')81 # Do any hypervisors and thier Vms first82 for hypervisor_name in sorted(vm_factories):83 hypervisor = vm_factories[hypervisor_name]84 first = True85 for vm in sorted(hypervisor['vms'], key=lambda vm: vm['id']):86 _add_server_row(table, vm, hypervisor_name, len(hypervisor['vms']), show_hypervisor=first)87 first = False88 _add_server_row(table, hypervisor['hypervisor'], hypervisor_name, show_hypervisor=False)89 # Add any other servers90 for s in sorted(self.servers, key=lambda s: s['id']):91 if not s.get('hypervisor-id') and not s.get('vm-factory', False):92 if vm_factories:93 _add_server_row(table, s, hypervisor='None', show_hypervisor=False)94 else:95 _add_server_row(table, s, show_hypervisor=False)96 file_name = "%s/Server_View.html" % (self._file_path)97 self.add_artifact(file_name, ArtifactMode.CREATED)98 fp = open(file_name, 'w')99 fp.write(str(h))100 fp.close101 def _render_server(self, s):102 h = self._create_page(link_prefix="../")103 h.br104 h.h2("Server ID: %s" % s['id'])105 title = h.h3()106 title.text("Role: ")107 title.a("%s" % s['role'],108 href="../Server_Roles.html#%s" % s['role'])109 h.h3("Status: %s" % s['state'])110 h_name = h.h3111 h_name.text("Hostname: ")112 if 'hostname' in s and s.get('hostname'):113 h_name.text(str(s['hostname']))114 cp_link = h.h3115 cp_link.text("Control Plane:")116 if 'control-plane-name' in s:117 cp_link.a(" %s" % s['control-plane-name'],118 href="../Control_Planes.html#%s" % s['control-plane-name'])119 zone_link = h.h3120 zone_link.text("Failure Zone:")121 if 'failure-zone' in s:122 zone_link.a(" %s" % s['failure-zone'], href="../Server_Groups.html")123 #124 # VMs125 #126 if 'vms' in s:127 h.h3("VMs")128 vm_table = h.table129 title_row = vm_table.tr130 for x in ['Id', 'vCPUs', 'Memory']:131 title_row.td(x, klass='title', align='center')132 for vm in s.get('vms', []):133 row = vm_table.tr134 id = row.td()135 id.a("%s" % vm['vm'], href="%s.html" % vm['vm'])136 row.td(str(vm['vcpus']))137 row.td(self.mem_size_string(vm['ram']))138 h.br139 h.br140 #141 # Services142 #143 h.h3("Services")144 service_table = h.table145 for service, components in s.get('services', {}).iteritems():146 row = service_table.tr147 row.td(service, valign='top')148 comp_text = row.td("", valign='top')149 for comp in components:150 comp_text.text(comp)151 comp_text.br152 h.br153 h.br154 #155 # Disks156 #157 title = h.h3()158 title.text("Disks (")159 title.a("%s" % s['disk-model']['name'],160 href="../Disk_Models.html#%s" % s['disk-model']['name'])161 title.text(")")162 self.render_disk_model(h, s['disk-model'])163 h.br164 h.br165 #166 # Networks167 #168 title = h.h3()169 title.text("Network Interfaces (")170 title.a("%s" % s['if-model'],171 href="../Interface_Models.html#%s" % s['if-model'])172 title.text(")")173 iface_table = h.table()174 # Count the number of networks175 nr_networks = 0176 interfaces = s['interfaces']177 # Un allcoated servers have a list instead of a dict178 if isinstance(interfaces, list):179 iface = {}180 for i in interfaces:181 iface[i['name']] = i182 interfaces = iface183 for if_name, if_data in interfaces.iteritems():184 nr_networks += len(if_data.get('networks', {}))185 for if_name, if_data in interfaces.iteritems():186 row = iface_table.tr187 networks = if_data.get('networks', {})188 row.td(if_name, rowspan=str(len(networks)))189 first_net = True190 for net_name, net_data in networks.iteritems():191 if not first_net:192 row = iface_table.tr193 else:194 first_net = False195 text = row.td("")196 text.a(net_name, href="../Networks.html#%s" % (net_name))197 if 'addr' in net_data:198 text.text("%s(%s)" % (SP, net_data['addr']), escape=False)199 text.text("<br>", escape=False)200 # Routes201 routes_td = row.td("", valign='top')202 if 'routes' in net_data:203 routes_td.text("Routes%sto:<br>" % SP, escape=False)204 for route in net_data['routes']:205 if route['default']:206 routes_td.text("%s<I>default</I><br>" % (SP * 4), escape=False)207 else:208 routes_td.text("%s" % (SP * 4), escape=False)209 routes_td.a(route['net_name'], href="../Networks.html#%s" % route['net_name'])210 routes_td.br211 h.br212 h.br213 #214 # Nic Mapping215 #216 title = h.h3()217 if not s['nic_map']:218 title.text("NIC Mapping: None")219 else:220 title.text("NIC Mapping (%s)" % s['nic_map']['name'])221 nic_map_table = h.table222 title_row = nic_map_table.tr()223 title_row.td("Name", klass="title", align='center')224 title_row.td("Bus Address", klass="title", align='center')225 title_row.td("Type", klass="title", align='center')226 for port in s['nic_map']['physical-ports']:227 if 'nic-device-type' in port:228 title_row.td("Device Type", klass="title", align='center')229 break230 for port in s['nic_map']['physical-ports']:231 row = nic_map_table.tr232 row.td(port['logical-name'])233 row.td(port['bus-address'])234 row.td(port['type'])235 if 'nic-device-type' in port:236 row.td("%s (%s)" % (port['nic-device-type']['name'],237 port['nic-device-type']['family']))238 h.br239 h.br240 #241 # Memory Model242 #243 if s.get('memory-model', {}):244 title = h.h3()245 title.text("Memory Model (")246 title.a("%s" % s['memory-model']['name'],247 href="../Memory_Models.html#%s" % s['memory-model']['name'])248 title.text(")")249 for model in self.memory_models:250 if model['name'] == s['memory-model']['name']:251 self.render_memory_model(h, model)252 h.br253 h.br254 file_name = "%s/Servers/%s.html" % (self._file_path, s['id'])255 self.add_artifact(file_name, ArtifactMode.CREATED)256 fp = open(file_name, 'w')257 fp.write(str(h))258 fp.close259 @staticmethod260 def mem_size_string(mem_size):261 suffix = ''262 if mem_size > 1024:263 suffix = 'M'264 mem_size = int(mem_size / 1024)265 if mem_size > 1024:266 suffix = 'G'267 mem_size = int(mem_size / 1024)...
hypervisors.py
Source:hypervisors.py
1# Copyright 2014 NEC Corporation. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import copy15from tempest.api_schema.response.compute import hypervisors16list_hypervisors_detail = copy.deepcopy(17 hypervisors.common_list_hypervisors_detail)18# Defining extra attributes for V3 show hypervisor schema19list_hypervisors_detail['response_body']['properties']['hypervisors'][20 'items']['properties']['os-pci:pci_stats'] = {'type': 'array'}21show_hypervisor = copy.deepcopy(hypervisors.common_show_hypervisor)22# Defining extra attributes for V3 show hypervisor schema23show_hypervisor['response_body']['properties']['hypervisor']['properties'][24 'os-pci:pci_stats'] = {'type': 'array'}25hypervisors_servers = copy.deepcopy(hypervisors.common_hypervisors_info)26# Defining extra attributes for V3 show hypervisor schema27hypervisors_servers['response_body']['properties']['hypervisor']['properties'][28 'servers'] = {29 'type': 'array',30 'items': {31 'type': 'object',32 'properties': {33 # NOTE: Now the type of 'id' is integer,34 # but here allows 'string' also because we35 # will be able to change it to 'uuid' in36 # the future.37 'id': {'type': ['integer', 'string']},38 'name': {'type': 'string'}39 }40 }41 }42# V3 API response body always contains the 'servers' attribute even there43# is no server (VM) are present on Hypervisor host.44hypervisors_servers['response_body']['properties']['hypervisor'][...
test_iaasgateway_sco.py
Source:test_iaasgateway_sco.py
...25 path="/flavors/detail"26 result = self.call_nova_api("GET",path,None)27 return result;28 29 def show_hypervisor(self):30 path = "/os-hypervisors/1"31 result = self.call_nova_api("GET",path,None)32 return result;33 def tearDown(self):34 pass35 def testKeystone(self):36 ret=self.list_users()37 print "users %s " % ret38 ret=self.list_domains()39 print "domains %s " % ret40 41 def testnova(self):42 #r43 ret = self.list_flavors()44 print "flavor %s" % ret45 46 ret = self.show_hypervisor()47 print "hyperviosr %s " % ret48 49if __name__ == "__main__":50 #import sys;sys.argv = ['', 'Test.testGlancePost']...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!