How to use _hotplug_server 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

...175 self.new_net = self._create_network(tenant_id=self.tenant_id)176 self.new_subnet = self._create_subnet(177 network=self.new_net,178 gateway_ip=None)179 def _hotplug_server(self):180 old_floating_ip, server = self.floating_ip_tuple181 ip_address = old_floating_ip.floating_ip_address182 private_key = self._get_server_key(server)183 ssh_client = self.get_remote_client(ip_address,184 private_key=private_key)185 old_nic_list = self._get_server_nics(ssh_client)186 # get a port from a list of one item187 port_list = self._list_ports(device_id=server['id'])188 self.assertEqual(1, len(port_list))189 old_port = port_list[0]190 _, interface = self.interface_client.create_interface(191 server=server['id'],192 network_id=self.new_net.id)193 self.addCleanup(self.network_client.wait_for_resource_deletion,194 'port',195 interface['port_id'])196 self.addCleanup(self.delete_wrapper,197 self.interface_client.delete_interface,198 server['id'], interface['port_id'])199 def check_ports():200 self.new_port_list = [port for port in201 self._list_ports(device_id=server['id'])202 if port != old_port]203 return len(self.new_port_list) == 1204 if not test.call_until_true(check_ports, CONF.network.build_timeout,205 CONF.network.build_interval):206 raise exceptions.TimeoutException("No new port attached to the "207 "server in time (%s sec) !"208 % CONF.network.build_timeout)209 new_port = net_resources.DeletablePort(client=self.network_client,210 **self.new_port_list[0])211 def check_new_nic():212 new_nic_list = self._get_server_nics(ssh_client)213 self.diff_list = [n for n in new_nic_list if n not in old_nic_list]214 return len(self.diff_list) == 1215 if not test.call_until_true(check_new_nic, CONF.network.build_timeout,216 CONF.network.build_interval):217 raise exceptions.TimeoutException("Interface not visible on the "218 "guest after %s sec"219 % CONF.network.build_timeout)220 num, new_nic = self.diff_list[0]221 ssh_client.assign_static_ip(nic=new_nic,222 addr=new_port.fixed_ips[0]['ip_address'])223 ssh_client.turn_nic_on(nic=new_nic)224 def _get_server_nics(self, ssh_client):225 reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+):')226 ipatxt = ssh_client.get_ip_list()227 return reg.findall(ipatxt)228 def _check_network_internal_connectivity(self, network):229 """230 via ssh check VM internal connectivity:231 - ping internal gateway and DHCP port, implying in-tenant connectivity232 pinging both, because L3 and DHCP agents might be on different nodes233 """234 floating_ip, server = self.floating_ip_tuple235 # get internal ports' ips:236 # get all network ports in the new network237 internal_ips = (p['fixed_ips'][0]['ip_address'] for p in238 self._list_ports(tenant_id=server['tenant_id'],239 network_id=network.id)240 if p['device_owner'].startswith('network'))241 self._check_server_connectivity(floating_ip, internal_ips)242 def _check_network_external_connectivity(self):243 """244 ping public network default gateway to imply external connectivity245 """246 if not CONF.network.public_network_id:247 msg = 'public network not defined.'248 LOG.info(msg)249 return250 subnet = self._list_subnets(251 network_id=CONF.network.public_network_id)252 self.assertEqual(1, len(subnet), "Found %d subnets" % len(subnet))253 external_ips = [subnet[0]['gateway_ip']]254 self._check_server_connectivity(self.floating_ip_tuple.floating_ip,255 external_ips)256 def _check_server_connectivity(self, floating_ip, address_list):257 ip_address = floating_ip.floating_ip_address258 private_key = self._get_server_key(self.floating_ip_tuple.server)259 ssh_source = self._ssh_to_server(ip_address, private_key)260 for remote_ip in address_list:261 try:262 self.assertTrue(self._check_remote_connectivity(ssh_source,263 remote_ip),264 "Timed out waiting for %s to become "265 "reachable" % remote_ip)266 except Exception:267 LOG.exception("Unable to access {dest} via ssh to "268 "floating-ip {src}".format(dest=remote_ip,269 src=floating_ip))270 debug.log_ip_ns()271 raise272 @test.attr(type='smoke')273 @test.services('compute', 'network')274 def test_network_basic_ops(self):275 """276 For a freshly-booted VM with an IP address ("port") on a given277 network:278 - the Tempest host can ping the IP address. This implies, but279 does not guarantee (see the ssh check that follows), that the280 VM has been assigned the correct IP address and has281 connectivity to the Tempest host.282 - the Tempest host can perform key-based authentication to an283 ssh server hosted at the IP address. This check guarantees284 that the IP address is associated with the target VM.285 - the Tempest host can ssh into the VM via the IP address and286 successfully execute the following:287 - ping an external IP address, implying external connectivity.288 - ping an external hostname, implying that dns is correctly289 configured.290 - ping an internal IP address, implying connectivity to another291 VM on the same network.292 - detach the floating-ip from the VM and verify that it becomes293 unreachable294 - associate detached floating ip to a new VM and verify connectivity.295 VMs are created with unique keypair so connectivity also asserts that296 floating IP is associated with the new VM instead of the old one297 """298 self._setup_network_and_servers()299 self._check_public_network_connectivity(should_connect=True)300 self._check_network_internal_connectivity(network=self.network)301 self._check_network_external_connectivity()302 self._disassociate_floating_ips()303 self._check_public_network_connectivity(should_connect=False,304 msg="after disassociate "305 "floating ip")306 self._reassociate_floating_ips()307 self._check_public_network_connectivity(should_connect=True,308 msg="after re-associate "309 "floating ip")310 @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach,311 'NIC hotplug not available')312 @test.attr(type='smoke')313 @test.services('compute', 'network')314 def test_hotplug_nic(self):315 """316 1. create a new network, with no gateway (to prevent overwriting VM's317 gateway)318 2. connect VM to new network319 3. set static ip and bring new nic up320 4. check VM can ping new network dhcp port321 """322 self._setup_network_and_servers()323 self._check_public_network_connectivity(should_connect=True)324 self._create_new_network()325 self._hotplug_server()...

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