Best Python code snippet using tempest_python
manager.py
Source:manager.py
...301 'within the required time (%s s).' %302 (floating_ip, status, floating_ip_status,303 build_timeout))304 raise lib_exc.TimeoutException(message)305 def wait_for_server_termination(self, server_id, ignore_error=False):306 """Waits for server to reach termination."""307 build_interval = CONF.compute.build_interval308 while True:309 try:310 rs_client = self._connect_server()311 resp, body = rs_client.get("servers/%s" % str(server_id))312 body = jsonutils.loads(body)313 except lib_exc.NotFound:314 return315 server_status = body['server']['status']316 if server_status == 'ERROR' and not ignore_error:317 raise lib_exc.BuildErrorException(server_id=server_id)318 time.sleep(build_interval)319 def wait_for_server_status(self, server_id, status, ready_wait=True,...
test_delete_server.py
Source:test_delete_server.py
...31 def test_delete_server_while_in_building_state(self):32 # Delete a server while it's VM state is Building33 server = self.create_test_server(wait_until='BUILD')34 self.client.delete_server(server['id'])35 waiters.wait_for_server_termination(self.client, server['id'])36 @decorators.idempotent_id('925fdfb4-5b13-47ea-ac8a-c36ae6fddb05')37 def test_delete_active_server(self):38 # Delete a server while it's VM state is Active39 server = self.create_test_server(wait_until='ACTIVE')40 self.client.delete_server(server['id'])41 waiters.wait_for_server_termination(self.client, server['id'])42 @decorators.idempotent_id('546d368c-bb6c-4645-979a-83ed16f3a6be')43 def test_delete_server_while_in_shutoff_state(self):44 # Delete a server while it's VM state is Shutoff45 server = self.create_test_server(wait_until='ACTIVE')46 self.client.stop_server(server['id'])47 waiters.wait_for_server_status(self.client, server['id'], 'SHUTOFF')48 self.client.delete_server(server['id'])49 waiters.wait_for_server_termination(self.client, server['id'])50 @decorators.idempotent_id('943bd6e8-4d7a-4904-be83-7a6cc2d4213b')51 @testtools.skipUnless(CONF.compute_feature_enabled.pause,52 'Pause is not available.')53 def test_delete_server_while_in_pause_state(self):54 # Delete a server while it's VM state is Pause55 server = self.create_test_server(wait_until='ACTIVE')56 self.client.pause_server(server['id'])57 waiters.wait_for_server_status(self.client, server['id'], 'PAUSED')58 self.client.delete_server(server['id'])59 waiters.wait_for_server_termination(self.client, server['id'])60 @decorators.idempotent_id('1f82ebd3-8253-4f4e-b93f-de9b7df56d8b')61 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,62 'Suspend is not available.')63 def test_delete_server_while_in_suspended_state(self):64 # Delete a server while it's VM state is Suspended65 server = self.create_test_server(wait_until='ACTIVE')66 self.client.suspend_server(server['id'])67 waiters.wait_for_server_status(self.client, server['id'], 'SUSPENDED')68 self.client.delete_server(server['id'])69 waiters.wait_for_server_termination(self.client, server['id'])70 @decorators.idempotent_id('bb0cb402-09dd-4947-b6e5-5e7e1cfa61ad')71 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,72 'Shelve is not available.')73 def test_delete_server_while_in_shelved_state(self):74 # Delete a server while it's VM state is Shelved75 server = self.create_test_server(wait_until='ACTIVE')76 compute.shelve_server(self.client, server['id'])77 self.client.delete_server(server['id'])78 waiters.wait_for_server_termination(self.client, server['id'])79 @decorators.idempotent_id('ab0c38b4-cdd8-49d3-9b92-0cb898723c01')80 @testtools.skipIf(not CONF.compute_feature_enabled.resize,81 'Resize not available.')82 def test_delete_server_while_in_verify_resize_state(self):83 # Delete a server while it's VM state is VERIFY_RESIZE84 server = self.create_test_server(wait_until='ACTIVE')85 self.client.resize_server(server['id'], self.flavor_ref_alt)86 waiters.wait_for_server_status(self.client, server['id'],87 'VERIFY_RESIZE')88 self.client.delete_server(server['id'])89 waiters.wait_for_server_termination(self.client, server['id'])90 @decorators.idempotent_id('d0f3f0d6-d9b6-4a32-8da4-23015dcab23c')91 @test.services('volume')92 def test_delete_server_while_in_attached_volume(self):93 # Delete a server while a volume is attached to it94 device = '/dev/%s' % CONF.compute.volume_device_name95 server = self.create_test_server(wait_until='ACTIVE')96 volume = self.create_volume()97 self.attach_volume(server, volume, device=device)98 self.client.delete_server(server['id'])99 waiters.wait_for_server_termination(self.client, server['id'])100 waiters.wait_for_volume_status(self.volumes_client,101 volume['id'], 'available')102class DeleteServersAdminTestJSON(base.BaseV2ComputeAdminTest):103 # NOTE: Server creations of each test class should be under 10104 # for preventing "Quota exceeded for instances".105 @classmethod106 def setup_clients(cls):107 super(DeleteServersAdminTestJSON, cls).setup_clients()108 cls.non_admin_client = cls.servers_client109 cls.admin_client = cls.os_adm.servers_client110 @decorators.idempotent_id('99774678-e072-49d1-9d2a-49a59bc56063')111 def test_delete_server_while_in_error_state(self):112 # Delete a server while it's VM state is error113 server = self.create_test_server(wait_until='ACTIVE')114 self.admin_client.reset_state(server['id'], state='error')115 # Verify server's state116 server = self.non_admin_client.show_server(server['id'])['server']117 self.assertEqual(server['status'], 'ERROR')118 self.non_admin_client.delete_server(server['id'])119 waiters.wait_for_server_termination(self.servers_client,120 server['id'],121 ignore_error=True)122 @decorators.idempotent_id('73177903-6737-4f27-a60c-379e8ae8cf48')123 def test_admin_delete_servers_of_others(self):124 # Administrator can delete servers of others125 server = self.create_test_server(wait_until='ACTIVE')126 self.admin_client.delete_server(server['id'])...
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!!