How to use verify_device_metadata method in tempest

Best Python code snippet using tempest_python

test_device_tagging.py

Source:test_device_tagging.py Github

copy

Full Screen

...91 # bug in the 2.32 microversion, tags on block devices only worked with the92 # 2.32 microversion specifically. And tags on networks only worked between93 # 2.32 and 2.36 inclusive; the 2.37 microversion broke tags for networks.94 max_microversion = '2.32'95 def verify_device_metadata(self, md_json):96 md_dict = json.loads(md_json)97 for d in md_dict['devices']:98 if d['type'] == 'nic':99 if d['mac'] == self.port1['mac_address']:100 self.assertEqual(d['tags'], ['port-1'])101 if d['mac'] == self.port2['mac_address']:102 self.assertEqual(d['tags'], ['port-2'])103 if d['mac'] == self.net_2_100_mac:104 self.assertEqual(d['tags'], ['net-2-100'])105 if d['mac'] == self.net_2_200_mac:106 self.assertEqual(d['tags'], ['net-2-200'])107 # A hypervisor may present multiple paths to a tagged disk, so108 # there may be duplicated tags in the metadata, use set() to109 # remove duplicated tags.110 # Some hypervisors might report devices with no tags as well.111 found_devices = [d['tags'][0] for d in md_dict['devices']112 if d.get('tags')]113 try:114 self.assertEqual(set(found_devices), set(['port-1', 'port-2',115 'net-1', 'net-2-100',116 'net-2-200', 'boot',117 'other']))118 return True119 except Exception:120 return False121 # NOTE(mriedem): This is really more like a scenario test and is slow so122 # it's marked as such.123 @decorators.attr(type='slow')124 @decorators.idempotent_id('a2e65a6c-66f1-4442-aaa8-498c31778d96')125 @utils.services('network', 'volume', 'image')126 def test_tagged_boot_devices(self):127 # Create volumes128 # The create_volume methods waits for the volumes to be available and129 # the base class will clean them up on tearDown.130 boot_volume = self.create_volume(CONF.compute.image_ref)131 other_volume = self.create_volume()132 untagged_volume = self.create_volume()133 # Create networks134 net1 = self.networks_client.create_network(135 name=data_utils.rand_name('device-tagging-net1'))['network']136 self.addCleanup(self.networks_client.delete_network, net1['id'])137 net2 = self.networks_client.create_network(138 name=data_utils.rand_name('device-tagging-net2'))['network']139 self.addCleanup(self.networks_client.delete_network, net2['id'])140 # Create subnets141 subnet1 = self.subnets_client.create_subnet(142 network_id=net1['id'],143 cidr='10.1.1.0/24',144 ip_version=4)['subnet']145 self.addCleanup(self.subnets_client.delete_subnet, subnet1['id'])146 subnet2 = self.subnets_client.create_subnet(147 network_id=net2['id'],148 cidr='10.2.2.0/24',149 ip_version=4)['subnet']150 self.addCleanup(self.subnets_client.delete_subnet, subnet2['id'])151 # Create ports152 self.port1 = self.ports_client.create_port(153 network_id=net1['id'],154 name=data_utils.rand_name(self.__class__.__name__),155 fixed_ips=[{'subnet_id': subnet1['id']}])['port']156 self.addCleanup(self.ports_client.delete_port, self.port1['id'])157 self.port2 = self.ports_client.create_port(158 network_id=net1['id'],159 name=data_utils.rand_name(self.__class__.__name__),160 fixed_ips=[{'subnet_id': subnet1['id']}])['port']161 self.addCleanup(self.ports_client.delete_port, self.port2['id'])162 # Create server163 config_drive_enabled = CONF.compute_feature_enabled.config_drive164 validation_resources = self.get_test_validation_resources(165 self.os_primary)166 server = self.create_test_server(167 validatable=True,168 wait_until='ACTIVE',169 validation_resources=validation_resources,170 config_drive=config_drive_enabled,171 name=data_utils.rand_name('device-tagging-server'),172 networks=[173 # Validation network for ssh174 {175 'uuid': self.get_tenant_network()['id']176 },177 # Different tags for different ports178 {179 'port': self.port1['id'],180 'tag': 'port-1'181 },182 {183 'port': self.port2['id'],184 'tag': 'port-2'185 },186 # Two nics on same net, one tagged one not187 {188 'uuid': net1['id'],189 'tag': 'net-1'190 },191 {192 'uuid': net1['id']193 },194 # Two nics on same net, different IP195 {196 'uuid': net2['id'],197 'fixed_ip': '10.2.2.100',198 'tag': 'net-2-100'199 },200 {201 'uuid': net2['id'],202 'fixed_ip': '10.2.2.200',203 'tag': 'net-2-200'204 }205 ],206 block_device_mapping_v2=[207 # Boot volume208 {209 'uuid': boot_volume['id'],210 'source_type': 'volume',211 'destination_type': 'volume',212 'boot_index': 0,213 'tag': 'boot'214 },215 # Other volume216 {217 'uuid': other_volume['id'],218 'source_type': 'volume',219 'destination_type': 'volume',220 'boot_index': 1,221 'tag': 'other'222 },223 # Untagged volume224 {225 'uuid': untagged_volume['id'],226 'source_type': 'volume',227 'destination_type': 'volume',228 'boot_index': 2229 }230 ])231 self.addCleanup(self.delete_server, server['id'])232 server = self.servers_client.show_server(server['id'])['server']233 ssh_client = remote_client.RemoteClient(234 self.get_server_ip(server, validation_resources),235 CONF.validation.image_ssh_user,236 pkey=validation_resources['keypair']['private_key'],237 server=server,238 servers_client=self.servers_client)239 # Find the MAC addresses of our fixed IPs240 self.net_2_100_mac = None241 self.net_2_200_mac = None242 ifaces = self.interfaces_client.list_interfaces(server['id'])243 for iface in ifaces['interfaceAttachments']:244 if 'fixed_ips' in iface:245 for ip in iface['fixed_ips']:246 if ip['ip_address'] == '10.2.2.100':247 self.net_2_100_mac = iface['mac_addr']248 if ip['ip_address'] == '10.2.2.200':249 self.net_2_200_mac = iface['mac_addr']250 # Make sure we have the MACs we need, there's no reason for some to be251 # missing252 self.assertTrue(self.net_2_100_mac)253 self.assertTrue(self.net_2_200_mac)254 # Verify metadata from metadata API255 if CONF.compute_feature_enabled.metadata_service:256 self.verify_metadata_from_api(server, ssh_client,257 self.verify_device_metadata)258 # Verify metadata on config drive259 if CONF.compute_feature_enabled.config_drive:260 self.verify_metadata_on_config_drive(server, ssh_client,261 self.verify_device_metadata)262class TaggedBootDevicesTest_v242(TaggedBootDevicesTest):263 min_microversion = '2.42'264 max_microversion = 'latest'265class TaggedAttachmentsTest(DeviceTaggingBase):266 min_microversion = '2.49'267 max_microversion = 'latest'268 @classmethod269 def skip_checks(cls):270 super(TaggedAttachmentsTest, cls).skip_checks()271 if not CONF.compute_feature_enabled.metadata_service:272 raise cls.skipException('Metadata API must be enabled')273 def verify_device_metadata(self, md_json):274 md_dict = json.loads(md_json)275 found_devices = [d['tags'][0] for d in md_dict['devices']276 if d.get('tags')]277 try:278 self.assertItemsEqual(found_devices, ['nic-tag', 'volume-tag'])279 return True280 except Exception:281 return False282 def verify_empty_devices(self, md_json):283 md_dict = json.loads(md_json)284 try:285 self.assertEmpty(md_dict['devices'])286 return True287 except AssertionError:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful