How to use _check_network_internal_connectivity method in tempest

Best Python code snippet using tempest_python

test_network_basic_ops.py

Source:test_network_basic_ops.py Github

copy

Full Screen

...248 def _get_server_nics(self, ssh_client):249 reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+):')250 ipatxt = ssh_client.get_ip_list()251 return reg.findall(ipatxt)252 def _check_network_internal_connectivity(self, network,253 should_connect=True):254 """255 via ssh check VM internal connectivity:256 - ping internal gateway and DHCP port, implying in-tenant connectivity257 pinging both, because L3 and DHCP agents might be on different nodes258 """259 floating_ip, server = self.floating_ip_tuple260 # get internal ports' ips:261 # get all network ports in the new network262 internal_ips = (p['fixed_ips'][0]['ip_address'] for p in263 self._list_ports(tenant_id=server['tenant_id'],264 network_id=network.id)265 if p['device_owner'].startswith('network'))266 self._check_server_connectivity(floating_ip,267 internal_ips,268 should_connect)269 def _check_network_external_connectivity(self):270 """271 ping public network default gateway to imply external connectivity272 """273 if not CONF.network.public_network_id:274 msg = 'public network not defined.'275 LOG.info(msg)276 return277 # We ping the external IP from the instance using its floating IP278 # which is always IPv4, so we must only test connectivity to279 # external IPv4 IPs if the external network is dualstack.280 v4_subnets = [s for s in self._list_subnets(281 network_id=CONF.network.public_network_id) if s['ip_version'] == 4]282 self.assertEqual(1, len(v4_subnets),283 "Found %d IPv4 subnets" % len(v4_subnets))284 external_ips = [v4_subnets[0]['gateway_ip']]285 self._check_server_connectivity(self.floating_ip_tuple.floating_ip,286 external_ips)287 def _check_server_connectivity(self, floating_ip, address_list,288 should_connect=True):289 ip_address = floating_ip.floating_ip_address290 private_key = self._get_server_key(self.floating_ip_tuple.server)291 ssh_source = self._ssh_to_server(ip_address, private_key)292 for remote_ip in address_list:293 if should_connect:294 msg = "Timed out waiting for "295 "%s to become reachable" % remote_ip296 else:297 msg = "ip address %s is reachable" % remote_ip298 try:299 self.assertTrue(self._check_remote_connectivity300 (ssh_source, remote_ip, should_connect),301 msg)302 except Exception:303 LOG.exception("Unable to access {dest} via ssh to "304 "floating-ip {src}".format(dest=remote_ip,305 src=floating_ip))306 raise307 @test.attr(type='smoke')308 @test.idempotent_id('f323b3ba-82f8-4db7-8ea6-6a895869ec49')309 @test.services('compute', 'network')310 def test_network_basic_ops(self):311 """312 For a freshly-booted VM with an IP address ("port") on a given313 network:314 - the Tempest host can ping the IP address. This implies, but315 does not guarantee (see the ssh check that follows), that the316 VM has been assigned the correct IP address and has317 connectivity to the Tempest host.318 - the Tempest host can perform key-based authentication to an319 ssh server hosted at the IP address. This check guarantees320 that the IP address is associated with the target VM.321 - the Tempest host can ssh into the VM via the IP address and322 successfully execute the following:323 - ping an external IP address, implying external connectivity.324 - ping an external hostname, implying that dns is correctly325 configured.326 - ping an internal IP address, implying connectivity to another327 VM on the same network.328 - detach the floating-ip from the VM and verify that it becomes329 unreachable330 - associate detached floating ip to a new VM and verify connectivity.331 VMs are created with unique keypair so connectivity also asserts that332 floating IP is associated with the new VM instead of the old one333 Verifies that floating IP status is updated correctly after each change334 """335 self._setup_network_and_servers()336 self.check_public_network_connectivity(should_connect=True)337 self._check_network_internal_connectivity(network=self.network)338 self._check_network_external_connectivity()339 self._disassociate_floating_ips()340 self.check_public_network_connectivity(should_connect=False,341 msg="after disassociate "342 "floating ip")343 self._reassociate_floating_ips()344 self.check_public_network_connectivity(should_connect=True,345 msg="after re-associate "346 "floating ip")347 @test.idempotent_id('1546850e-fbaa-42f5-8b5f-03d8a6a95f15')348 @testtools.skipIf(CONF.baremetal.driver_enabled,349 'Baremetal relies on a shared physical network.')350 @test.services('compute', 'network')351 def test_connectivity_between_vms_on_different_networks(self):352 """353 For a freshly-booted VM with an IP address ("port") on a given354 network:355 - the Tempest host can ping the IP address.356 - the Tempest host can ssh into the VM via the IP address and357 successfully execute the following:358 - ping an external IP address, implying external connectivity.359 - ping an external hostname, implying that dns is correctly360 configured.361 - ping an internal IP address, implying connectivity to another362 VM on the same network.363 - Create another network on the same tenant with subnet, create364 an VM on the new network.365 - Ping the new VM from previous VM failed since the new network366 was not attached to router yet.367 - Attach the new network to the router, Ping the new VM from368 previous VM succeed.369 """370 self._setup_network_and_servers()371 self.check_public_network_connectivity(should_connect=True)372 self._check_network_internal_connectivity(network=self.network)373 self._check_network_external_connectivity()374 self._create_new_network(create_gateway=True)375 name = data_utils.rand_name('server-smoke')376 self._create_server(name, self.new_net)377 self._check_network_internal_connectivity(network=self.new_net,378 should_connect=False)379 self.new_subnet.add_to_router(self.router.id)380 self._check_network_internal_connectivity(network=self.new_net,381 should_connect=True)382 @test.idempotent_id('c5adff73-e961-41f1-b4a9-343614f18cfa')383 @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach,384 'NIC hotplug not available')385 @testtools.skipIf(CONF.network.port_vnic_type in ['direct', 'macvtap'],386 'NIC hotplug not supported for '387 'vnic_type direct or macvtap')388 @test.services('compute', 'network')389 def test_hotplug_nic(self):390 """391 1. create a new network, with no gateway (to prevent overwriting VM's392 gateway)393 2. connect VM to new network394 3. set static ip and bring new nic up395 4. check VM can ping new network dhcp port396 """397 self._setup_network_and_servers()398 self.check_public_network_connectivity(should_connect=True)399 self._create_new_network()400 self._hotplug_server()401 self._check_network_internal_connectivity(network=self.new_net)402 @test.idempotent_id('04b9fe4e-85e8-4aea-b937-ea93885ac59f')403 @testtools.skipIf(CONF.baremetal.driver_enabled,404 'Router state cannot be altered on a shared baremetal '405 'network')406 @test.services('compute', 'network')407 def test_update_router_admin_state(self):408 """409 1. Check public connectivity before updating410 admin_state_up attribute of router to False411 2. Check public connectivity after updating412 admin_state_up attribute of router to False413 3. Check public connectivity after updating414 admin_state_up attribute of router to True415 """...

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