Best Python code snippet using tempest_python
test_server_actions.py
Source:test_server_actions.py
...175 # Verify the properties in the initial response are correct176 self.assertEqual(self.server_id, rebuilt_server['id'])177 rebuilt_image_id = rebuilt_server['image']['id']178 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))179 self.assert_flavor_equal(self.flavor_ref, rebuilt_server['flavor'])180 # Verify the server properties after the rebuild completes181 waiters.wait_for_server_status(self.client,182 rebuilt_server['id'], 'ACTIVE')183 server = self.client.show_server(rebuilt_server['id'])['server']184 rebuilt_image_id = server['image']['id']185 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))186 self.assertEqual(new_name, server['name'])187 self.assertEqual(original_addresses, server['addresses'])188 if CONF.validation.run_validation:189 validation_resources = self.get_class_validation_resources(190 self.os_primary)191 # Authentication is attempted in the following order of priority:192 # 1.The key passed in, if one was passed in.193 # 2.Any key we can find through an SSH agent (if allowed).194 # 3.Any "id_rsa", "id_dsa" or "id_ecdsa" key discoverable in195 # ~/.ssh/ (if allowed).196 # 4.Plain username/password auth, if a password was given.197 linux_client = remote_client.RemoteClient(198 self.get_server_ip(rebuilt_server, validation_resources),199 self.ssh_user,200 password,201 validation_resources['keypair']['private_key'],202 server=rebuilt_server,203 servers_client=self.client)204 linux_client.validate_authentication()205 @decorators.idempotent_id('aaa6cdf3-55a7-461a-add9-1c8596b9a07c')206 def test_rebuild_server(self):207 self._test_rebuild_server()208 @decorators.idempotent_id('30449a88-5aff-4f9b-9866-6ee9b17f906d')209 def test_rebuild_server_in_stop_state(self):210 # The server in stop state should be rebuilt using the provided211 # image and remain in SHUTOFF state212 server = self.client.show_server(self.server_id)['server']213 old_image = server['image']['id']214 new_image = (self.image_ref_alt215 if old_image == self.image_ref else self.image_ref)216 self.client.stop_server(self.server_id)217 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')218 rebuilt_server = (self.client.rebuild_server(self.server_id, new_image)219 ['server'])220 # If the server was rebuilt on a different image, restore it to the221 # original image once the test ends222 if self.image_ref_alt != self.image_ref:223 self.addCleanup(self._rebuild_server_and_check, old_image)224 # Verify the properties in the initial response are correct225 self.assertEqual(self.server_id, rebuilt_server['id'])226 rebuilt_image_id = rebuilt_server['image']['id']227 self.assertEqual(new_image, rebuilt_image_id)228 self.assert_flavor_equal(self.flavor_ref, rebuilt_server['flavor'])229 # Verify the server properties after the rebuild completes230 waiters.wait_for_server_status(self.client,231 rebuilt_server['id'], 'SHUTOFF')232 server = self.client.show_server(rebuilt_server['id'])['server']233 rebuilt_image_id = server['image']['id']234 self.assertEqual(new_image, rebuilt_image_id)235 self.client.start_server(self.server_id)236 # NOTE(mriedem): Marked as slow because while rebuild and volume-backed is237 # common, we don't actually change the image (you can't with volume-backed238 # rebuild) so this isn't testing much outside normal rebuild239 # (and it's slow).240 @decorators.attr(type='slow')241 @decorators.idempotent_id('b68bd8d6-855d-4212-b59b-2e704044dace')242 @utils.services('volume')243 def test_rebuild_server_with_volume_attached(self):244 # create a new volume and attach it to the server245 volume = self.create_volume()246 server = self.client.show_server(self.server_id)['server']247 self.attach_volume(server, volume)248 # run general rebuild test249 self._test_rebuild_server()250 # make sure the volume is attached to the instance after rebuild251 vol_after_rebuild = self.volumes_client.show_volume(volume['id'])252 vol_after_rebuild = vol_after_rebuild['volume']253 self.assertEqual('in-use', vol_after_rebuild['status'])254 self.assertEqual(self.server_id,255 vol_after_rebuild['attachments'][0]['server_id'])256 if CONF.validation.run_validation:257 validation_resources = self.get_class_validation_resources(258 self.os_primary)259 linux_client = remote_client.RemoteClient(260 self.get_server_ip(server, validation_resources),261 self.ssh_user,262 password=None,263 pkey=validation_resources['keypair']['private_key'],264 server=server,265 servers_client=self.client)266 linux_client.validate_authentication()267 def _test_resize_server_confirm(self, server_id, stop=False):268 # The server's RAM and disk space should be modified to that of269 # the provided flavor270 if stop:271 self.client.stop_server(server_id)272 waiters.wait_for_server_status(self.client, server_id,273 'SHUTOFF')274 self.client.resize_server(server_id, self.flavor_ref_alt)275 # NOTE(jlk): Explicitly delete the server to get a new one for later276 # tests. Avoids resize down race issues.277 self.addCleanup(self.delete_server, server_id)278 waiters.wait_for_server_status(self.client, server_id,279 'VERIFY_RESIZE')280 self.client.confirm_resize_server(server_id)281 expected_status = 'SHUTOFF' if stop else 'ACTIVE'282 waiters.wait_for_server_status(self.client, server_id,283 expected_status)284 server = self.client.show_server(server_id)['server']285 self.assert_flavor_equal(self.flavor_ref_alt, server['flavor'])286 if stop:287 # NOTE(mriedem): tearDown requires the server to be started.288 self.client.start_server(server_id)289 @decorators.idempotent_id('1499262a-9328-4eda-9068-db1ac57498d2')290 @testtools.skipUnless(CONF.compute_feature_enabled.resize,291 'Resize not available.')292 def test_resize_server_confirm(self):293 self._test_resize_server_confirm(self.server_id, stop=False)294 @decorators.idempotent_id('e6c28180-7454-4b59-b188-0257af08a63b')295 @decorators.related_bug('1728603')296 @testtools.skipUnless(CONF.compute_feature_enabled.resize,297 'Resize not available.')298 @utils.services('volume')299 def test_resize_volume_backed_server_confirm(self):300 # We have to create a new server that is volume-backed since the one301 # from setUp is not volume-backed.302 server = self.create_test_server(303 volume_backed=True, wait_until='ACTIVE')304 # NOTE(mgoddard): Get detailed server to ensure addresses are present305 # in fixed IP case.306 server = self.servers_client.show_server(server['id'])['server']307 self._test_resize_server_confirm(server['id'])308 if CONF.compute_feature_enabled.console_output:309 # Now do something interactive with the guest like get its console310 # output; we don't actually care about the output,311 # just that it doesn't raise an error.312 self.client.get_console_output(server['id'])313 if CONF.validation.run_validation:314 validation_resources = self.get_class_validation_resources(315 self.os_primary)316 linux_client = remote_client.RemoteClient(317 self.get_server_ip(server, validation_resources),318 self.ssh_user,319 password=None,320 pkey=validation_resources['keypair']['private_key'],321 server=server,322 servers_client=self.client)323 linux_client.validate_authentication()324 @decorators.idempotent_id('138b131d-66df-48c9-a171-64f45eb92962')325 @testtools.skipUnless(CONF.compute_feature_enabled.resize,326 'Resize not available.')327 def test_resize_server_confirm_from_stopped(self):328 self._test_resize_server_confirm(self.server_id, stop=True)329 @decorators.idempotent_id('c03aab19-adb1-44f5-917d-c419577e9e68')330 @testtools.skipUnless(CONF.compute_feature_enabled.resize,331 'Resize not available.')332 def test_resize_server_revert(self):333 # The server's RAM and disk space should return to its original334 # values after a resize is reverted335 self.client.resize_server(self.server_id, self.flavor_ref_alt)336 # NOTE(zhufl): Explicitly delete the server to get a new one for later337 # tests. Avoids resize down race issues.338 self.addCleanup(self.delete_server, self.server_id)339 waiters.wait_for_server_status(self.client, self.server_id,340 'VERIFY_RESIZE')341 self.client.revert_resize_server(self.server_id)342 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')343 server = self.client.show_server(self.server_id)['server']344 self.assert_flavor_equal(self.flavor_ref, server['flavor'])345 @decorators.idempotent_id('fbbf075f-a812-4022-bc5c-ccb8047eef12')346 @decorators.related_bug('1737599')347 @testtools.skipUnless(CONF.compute_feature_enabled.resize,348 'Resize not available.')349 @utils.services('volume')350 def test_resize_server_revert_with_volume_attached(self):351 # Tests attaching a volume to a server instance and then resizing352 # the instance. Once the instance is resized, revert the resize which353 # should move the instance and volume attachment back to the original354 # compute host.355 # Create a blank volume and attach it to the server created in setUp.356 volume = self.create_volume()357 server = self.client.show_server(self.server_id)['server']358 self.attach_volume(server, volume)359 # Now resize the server with the blank volume attached.360 self.client.resize_server(self.server_id, self.flavor_ref_alt)361 # Explicitly delete the server to get a new one for later362 # tests. Avoids resize down race issues.363 self.addCleanup(self.delete_server, self.server_id)364 waiters.wait_for_server_status(365 self.client, self.server_id, 'VERIFY_RESIZE')366 # Now revert the resize which should move the instance and it's volume367 # attachment back to the original source compute host.368 self.client.revert_resize_server(self.server_id)369 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')370 # Make sure everything still looks OK.371 server = self.client.show_server(self.server_id)['server']372 self.assert_flavor_equal(self.flavor_ref, server['flavor'])373 attached_volumes = server['os-extended-volumes:volumes_attached']374 self.assertEqual(1, len(attached_volumes))375 self.assertEqual(volume['id'], attached_volumes[0]['id'])376 @decorators.idempotent_id('b963d4f1-94b3-4c40-9e97-7b583f46e470')377 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,378 'Snapshotting not available, backup not possible.')379 @utils.services('image')380 def test_create_backup(self):381 # Positive test:create backup successfully and rotate backups correctly382 # create the first and the second backup383 # Check if glance v1 is available to determine which client to use. We384 # prefer glance v1 for the compute API tests since the compute image385 # API proxy was written for glance v1.386 if CONF.image_feature_enabled.api_v1:...
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!!