How to use restore_soft_deleted_server method in tempest

Best Python code snippet using tempest_python

test_servers_negative.py

Source:test_servers_negative.py Github

copy

Full Screen

1# Copyright 2012 OpenStack Foundation2# All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15import sys16from tempest_lib import exceptions as lib_exc17import testtools18from tempest.api.compute import base19from tempest.common.utils import data_utils20from tempest.common import waiters21from tempest import config22from tempest import test23CONF = config.CONF24class ServersNegativeTestJSON(base.BaseV2ComputeTest):25 credentials = ['primary', 'alt']26 def setUp(self):27 super(ServersNegativeTestJSON, self).setUp()28 try:29 waiters.wait_for_server_status(self.client, self.server_id,30 'ACTIVE')31 except Exception:32 self.__class__.server_id = self.rebuild_server(self.server_id)33 def tearDown(self):34 self.server_check_teardown()35 super(ServersNegativeTestJSON, self).tearDown()36 @classmethod37 def setup_clients(cls):38 super(ServersNegativeTestJSON, cls).setup_clients()39 cls.client = cls.servers_client40 cls.alt_client = cls.os_alt.servers_client41 @classmethod42 def resource_setup(cls):43 super(ServersNegativeTestJSON, cls).resource_setup()44 server = cls.create_test_server(wait_until='ACTIVE')45 cls.server_id = server['id']46 @test.attr(type=['negative'])47 @test.idempotent_id('dbbfd247-c40c-449e-8f6c-d2aa7c7da7cf')48 def test_server_name_blank(self):49 # Create a server with name parameter empty50 self.assertRaises(lib_exc.BadRequest,51 self.create_test_server,52 name='')53 @test.attr(type=['negative'])54 @test.idempotent_id('b8a7235e-5246-4a8f-a08e-b34877c6586f')55 @testtools.skipUnless(CONF.compute_feature_enabled.personality,56 'Nova personality feature disabled')57 def test_personality_file_contents_not_encoded(self):58 # Use an unencoded file when creating a server with personality59 file_contents = 'This is a test file.'60 person = [{'path': '/etc/testfile.txt',61 'contents': file_contents}]62 self.assertRaises(lib_exc.BadRequest,63 self.create_test_server,64 personality=person)65 @test.attr(type=['negative'])66 @test.idempotent_id('fcba1052-0a50-4cf3-b1ac-fae241edf02f')67 def test_create_with_invalid_image(self):68 # Create a server with an unknown image69 self.assertRaises(lib_exc.BadRequest,70 self.create_test_server,71 image_id=-1)72 @test.attr(type=['negative'])73 @test.idempotent_id('18f5227f-d155-4429-807c-ccb103887537')74 def test_create_with_invalid_flavor(self):75 # Create a server with an unknown flavor76 self.assertRaises(lib_exc.BadRequest,77 self.create_test_server,78 flavor=-1,)79 @test.attr(type=['negative'])80 @test.idempotent_id('7f70a4d1-608f-4794-9e56-cb182765972c')81 def test_invalid_access_ip_v4_address(self):82 # An access IPv4 address must match a valid address pattern83 IPv4 = '1.1.1.1.1.1'84 self.assertRaises(lib_exc.BadRequest,85 self.create_test_server, accessIPv4=IPv4)86 @test.attr(type=['negative'])87 @test.idempotent_id('5226dd80-1e9c-4d8a-b5f9-b26ca4763fd0')88 def test_invalid_ip_v6_address(self):89 # An access IPv6 address must match a valid address pattern90 IPv6 = 'notvalid'91 self.assertRaises(lib_exc.BadRequest,92 self.create_test_server, accessIPv6=IPv6)93 @test.idempotent_id('7ea45b3e-e770-46fa-bfcc-9daaf6d987c0')94 @testtools.skipUnless(CONF.compute_feature_enabled.resize,95 'Resize not available.')96 @test.attr(type=['negative'])97 def test_resize_nonexistent_server(self):98 # Resize a non-existent server99 nonexistent_server = data_utils.rand_uuid()100 self.assertRaises(lib_exc.NotFound,101 self.client.resize_server,102 nonexistent_server, self.flavor_ref)103 @test.idempotent_id('ced1a1d7-2ab6-45c9-b90f-b27d87b30efd')104 @testtools.skipUnless(CONF.compute_feature_enabled.resize,105 'Resize not available.')106 @test.attr(type=['negative'])107 def test_resize_server_with_non_existent_flavor(self):108 # Resize a server with non-existent flavor109 nonexistent_flavor = data_utils.rand_uuid()110 self.assertRaises(lib_exc.BadRequest, self.client.resize_server,111 self.server_id, flavor_ref=nonexistent_flavor)112 @test.idempotent_id('45436a7d-a388-4a35-a9d8-3adc5d0d940b')113 @testtools.skipUnless(CONF.compute_feature_enabled.resize,114 'Resize not available.')115 @test.attr(type=['negative'])116 def test_resize_server_with_null_flavor(self):117 # Resize a server with null flavor118 self.assertRaises(lib_exc.BadRequest, self.client.resize_server,119 self.server_id, flavor_ref="")120 @test.attr(type=['negative'])121 @test.idempotent_id('d4c023a0-9c55-4747-9dd5-413b820143c7')122 def test_reboot_non_existent_server(self):123 # Reboot a non existent server124 nonexistent_server = data_utils.rand_uuid()125 self.assertRaises(lib_exc.NotFound, self.client.reboot_server,126 nonexistent_server, type='SOFT')127 @test.idempotent_id('d1417e7f-a509-41b5-a102-d5eed8613369')128 @testtools.skipUnless(CONF.compute_feature_enabled.pause,129 'Pause is not available.')130 @test.attr(type=['negative'])131 def test_pause_paused_server(self):132 # Pause a paused server.133 self.client.pause_server(self.server_id)134 waiters.wait_for_server_status(self.client, self.server_id, 'PAUSED')135 self.assertRaises(lib_exc.Conflict,136 self.client.pause_server,137 self.server_id)138 self.client.unpause_server(self.server_id)139 @test.attr(type=['negative'])140 @test.idempotent_id('98fa0458-1485-440f-873b-fe7f0d714930')141 def test_rebuild_deleted_server(self):142 # Rebuild a deleted server143 server = self.create_test_server()144 self.client.delete_server(server['id'])145 waiters.wait_for_server_termination(self.client, server['id'])146 self.assertRaises(lib_exc.NotFound,147 self.client.rebuild_server,148 server['id'], self.image_ref_alt)149 @test.attr(type=['negative'])150 @test.idempotent_id('581a397d-5eab-486f-9cf9-1014bbd4c984')151 def test_reboot_deleted_server(self):152 # Reboot a deleted server153 server = self.create_test_server()154 self.client.delete_server(server['id'])155 waiters.wait_for_server_termination(self.client, server['id'])156 self.assertRaises(lib_exc.NotFound, self.client.reboot_server,157 server['id'], type='SOFT')158 @test.attr(type=['negative'])159 @test.idempotent_id('d86141a7-906e-4731-b187-d64a2ea61422')160 def test_rebuild_non_existent_server(self):161 # Rebuild a non existent server162 nonexistent_server = data_utils.rand_uuid()163 self.assertRaises(lib_exc.NotFound,164 self.client.rebuild_server,165 nonexistent_server,166 self.image_ref_alt)167 @test.attr(type=['negative'])168 @test.idempotent_id('fd57f159-68d6-4c2a-902b-03070828a87e')169 def test_create_numeric_server_name(self):170 server_name = 12345171 self.assertRaises(lib_exc.BadRequest,172 self.create_test_server,173 name=server_name)174 @test.attr(type=['negative'])175 @test.idempotent_id('c3e0fb12-07fc-4d76-a22e-37409887afe8')176 def test_create_server_name_length_exceeds_256(self):177 # Create a server with name length exceeding 256 characters178 server_name = 'a' * 256179 self.assertRaises(lib_exc.BadRequest,180 self.create_test_server,181 name=server_name)182 @test.attr(type=['negative'])183 @test.idempotent_id('4e72dc2d-44c5-4336-9667-f7972e95c402')184 def test_create_with_invalid_network_uuid(self):185 # Pass invalid network uuid while creating a server186 networks = [{'fixed_ip': '10.0.1.1', 'uuid': 'a-b-c-d-e-f-g-h-i-j'}]187 self.assertRaises(lib_exc.BadRequest,188 self.create_test_server,189 networks=networks)190 @test.attr(type=['negative'])191 @test.idempotent_id('7a2efc39-530c-47de-b875-2dd01c8d39bd')192 def test_create_with_non_existent_keypair(self):193 # Pass a non-existent keypair while creating a server194 key_name = data_utils.rand_name('key')195 self.assertRaises(lib_exc.BadRequest,196 self.create_test_server,197 key_name=key_name)198 @test.attr(type=['negative'])199 @test.idempotent_id('7fc74810-0bd2-4cd7-8244-4f33a9db865a')200 def test_create_server_metadata_exceeds_length_limit(self):201 # Pass really long metadata while creating a server202 metadata = {'a': 'b' * 260}203 self.assertRaises((lib_exc.BadRequest, lib_exc.OverLimit),204 self.create_test_server,205 metadata=metadata)206 @test.attr(type=['negative'])207 @test.idempotent_id('aa8eed43-e2cb-4ebf-930b-da14f6a21d81')208 def test_update_name_of_non_existent_server(self):209 # Update name of a non-existent server210 nonexistent_server = data_utils.rand_uuid()211 new_name = data_utils.rand_name('server') + '_updated'212 self.assertRaises(lib_exc.NotFound, self.client.update_server,213 nonexistent_server, name=new_name)214 @test.attr(type=['negative'])215 @test.idempotent_id('38204696-17c6-44da-9590-40f87fb5a899')216 def test_update_server_set_empty_name(self):217 # Update name of the server to an empty string218 new_name = ''219 self.assertRaises(lib_exc.BadRequest, self.client.update_server,220 self.server_id, name=new_name)221 @test.attr(type=['negative'])222 @test.idempotent_id('543d84c1-dd2e-4c6d-8cb2-b9da0efaa384')223 def test_update_server_of_another_tenant(self):224 # Update name of a server that belongs to another tenant225 new_name = self.server_id + '_new'226 self.assertRaises(lib_exc.NotFound,227 self.alt_client.update_server, self.server_id,228 name=new_name)229 @test.attr(type=['negative'])230 @test.idempotent_id('5c8e244c-dada-4590-9944-749c455b431f')231 def test_update_server_name_length_exceeds_256(self):232 # Update name of server exceed the name length limit233 new_name = 'a' * 256234 self.assertRaises(lib_exc.BadRequest,235 self.client.update_server,236 self.server_id,237 name=new_name)238 @test.attr(type=['negative'])239 @test.idempotent_id('1041b4e6-514b-4855-96a5-e974b60870a3')240 def test_delete_non_existent_server(self):241 # Delete a non existent server242 nonexistent_server = data_utils.rand_uuid()243 self.assertRaises(lib_exc.NotFound, self.client.delete_server,244 nonexistent_server)245 @test.attr(type=['negative'])246 @test.idempotent_id('5c75009d-3eea-423e-bea3-61b09fd25f9c')247 def test_delete_a_server_of_another_tenant(self):248 # Delete a server that belongs to another tenant249 self.assertRaises(lib_exc.NotFound,250 self.alt_client.delete_server,251 self.server_id)252 @test.attr(type=['negative'])253 @test.idempotent_id('75f79124-277c-45e6-a373-a1d6803f4cc4')254 def test_delete_server_pass_negative_id(self):255 # Pass an invalid string parameter to delete server256 self.assertRaises(lib_exc.NotFound, self.client.delete_server, -1)257 @test.attr(type=['negative'])258 @test.idempotent_id('f4d7279b-5fd2-4bf2-9ba4-ae35df0d18c5')259 def test_delete_server_pass_id_exceeding_length_limit(self):260 # Pass a server ID that exceeds length limit to delete server261 self.assertRaises(lib_exc.NotFound, self.client.delete_server,262 sys.maxint + 1)263 @test.attr(type=['negative'])264 @test.idempotent_id('c5fa6041-80cd-483b-aa6d-4e45f19d093c')265 def test_create_with_nonexistent_security_group(self):266 # Create a server with a nonexistent security group267 security_groups = [{'name': 'does_not_exist'}]268 self.assertRaises(lib_exc.BadRequest,269 self.create_test_server,270 security_groups=security_groups)271 @test.attr(type=['negative'])272 @test.idempotent_id('3436b02f-1b1e-4f03-881e-c6a602327439')273 def test_get_non_existent_server(self):274 # Get a non existent server details275 nonexistent_server = data_utils.rand_uuid()276 self.assertRaises(lib_exc.NotFound, self.client.show_server,277 nonexistent_server)278 @test.attr(type=['negative'])279 @test.idempotent_id('a31460a9-49e1-42aa-82ee-06e0bb7c2d03')280 def test_stop_non_existent_server(self):281 # Stop a non existent server282 nonexistent_server = data_utils.rand_uuid()283 self.assertRaises(lib_exc.NotFound, self.servers_client.stop_server,284 nonexistent_server)285 @test.idempotent_id('6a8dc0c6-6cd4-4c0a-9f32-413881828091')286 @testtools.skipUnless(CONF.compute_feature_enabled.pause,287 'Pause is not available.')288 @test.attr(type=['negative'])289 def test_pause_non_existent_server(self):290 # pause a non existent server291 nonexistent_server = data_utils.rand_uuid()292 self.assertRaises(lib_exc.NotFound, self.client.pause_server,293 nonexistent_server)294 @test.idempotent_id('705b8e3a-e8a7-477c-a19b-6868fc24ac75')295 @testtools.skipUnless(CONF.compute_feature_enabled.pause,296 'Pause is not available.')297 @test.attr(type=['negative'])298 def test_unpause_non_existent_server(self):299 # unpause a non existent server300 nonexistent_server = data_utils.rand_uuid()301 self.assertRaises(lib_exc.NotFound, self.client.unpause_server,302 nonexistent_server)303 @test.idempotent_id('c8e639a7-ece8-42dd-a2e0-49615917ba4f')304 @testtools.skipUnless(CONF.compute_feature_enabled.pause,305 'Pause is not available.')306 @test.attr(type=['negative'])307 def test_unpause_server_invalid_state(self):308 # unpause an active server.309 self.assertRaises(lib_exc.Conflict,310 self.client.unpause_server,311 self.server_id)312 @test.idempotent_id('d1f032d5-7b6e-48aa-b252-d5f16dd994ca')313 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,314 'Suspend is not available.')315 @test.attr(type=['negative'])316 def test_suspend_non_existent_server(self):317 # suspend a non existent server318 nonexistent_server = data_utils.rand_uuid()319 self.assertRaises(lib_exc.NotFound, self.client.suspend_server,320 nonexistent_server)321 @test.idempotent_id('7f323206-05a9-4bf8-996b-dd5b2036501b')322 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,323 'Suspend is not available.')324 @test.attr(type=['negative'])325 def test_suspend_server_invalid_state(self):326 # suspend a suspended server.327 self.client.suspend_server(self.server_id)328 waiters.wait_for_server_status(self.client, self.server_id,329 'SUSPENDED')330 self.assertRaises(lib_exc.Conflict,331 self.client.suspend_server,332 self.server_id)333 self.client.resume_server(self.server_id)334 @test.idempotent_id('221cd282-bddb-4837-a683-89c2487389b6')335 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,336 'Suspend is not available.')337 @test.attr(type=['negative'])338 def test_resume_non_existent_server(self):339 # resume a non existent server340 nonexistent_server = data_utils.rand_uuid()341 self.assertRaises(lib_exc.NotFound, self.client.resume_server,342 nonexistent_server)343 @test.idempotent_id('ccb6294d-c4c9-498f-8a43-554c098bfadb')344 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,345 'Suspend is not available.')346 @test.attr(type=['negative'])347 def test_resume_server_invalid_state(self):348 # resume an active server.349 self.assertRaises(lib_exc.Conflict,350 self.client.resume_server,351 self.server_id)352 @test.attr(type=['negative'])353 @test.idempotent_id('7dd919e7-413f-4198-bebb-35e2a01b13e9')354 def test_get_console_output_of_non_existent_server(self):355 # get the console output for a non existent server356 nonexistent_server = data_utils.rand_uuid()357 self.assertRaises(lib_exc.NotFound,358 self.client.get_console_output,359 nonexistent_server, length=10)360 @test.attr(type=['negative'])361 @test.idempotent_id('6f47992b-5144-4250-9f8b-f00aa33950f3')362 def test_force_delete_nonexistent_server_id(self):363 # force-delete a non existent server364 nonexistent_server = data_utils.rand_uuid()365 self.assertRaises(lib_exc.NotFound,366 self.client.force_delete_server,367 nonexistent_server)368 @test.attr(type=['negative'])369 @test.idempotent_id('9c6d38cc-fcfb-437a-85b9-7b788af8bf01')370 def test_restore_nonexistent_server_id(self):371 # restore-delete a non existent server372 nonexistent_server = data_utils.rand_uuid()373 self.assertRaises(lib_exc.NotFound,374 self.client.restore_soft_deleted_server,375 nonexistent_server)376 @test.attr(type=['negative'])377 @test.idempotent_id('7fcadfab-bd6a-4753-8db7-4a51e51aade9')378 def test_restore_server_invalid_state(self):379 # we can only restore-delete a server in 'soft-delete' state380 self.assertRaises(lib_exc.Conflict,381 self.client.restore_soft_deleted_server,382 self.server_id)383 @test.idempotent_id('abca56e2-a892-48ea-b5e5-e07e69774816')384 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,385 'Shelve is not available.')386 @test.attr(type=['negative'])387 def test_shelve_non_existent_server(self):388 # shelve a non existent server389 nonexistent_server = data_utils.rand_uuid()390 self.assertRaises(lib_exc.NotFound, self.client.shelve_server,391 nonexistent_server)392 @test.idempotent_id('443e4f9b-e6bf-4389-b601-3a710f15fddd')393 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,394 'Shelve is not available.')395 @test.attr(type=['negative'])396 def test_shelve_shelved_server(self):397 # shelve a shelved server.398 self.client.shelve_server(self.server_id)399 offload_time = CONF.compute.shelved_offload_time400 if offload_time >= 0:401 waiters.wait_for_server_status(self.client,402 self.server_id,403 'SHELVED_OFFLOADED',404 extra_timeout=offload_time)405 else:406 waiters.wait_for_server_status(self.client,407 self.server_id,408 'SHELVED')409 server = self.client.show_server(self.server_id)['server']410 image_name = server['name'] + '-shelved'411 params = {'name': image_name}412 images = self.compute_images_client.list_images(**params)['images']413 self.assertEqual(1, len(images))414 self.assertEqual(image_name, images[0]['name'])415 self.assertRaises(lib_exc.Conflict,416 self.client.shelve_server,417 self.server_id)418 self.client.unshelve_server(self.server_id)419 @test.idempotent_id('23d23b37-afaf-40d7-aa5d-5726f82d8821')420 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,421 'Shelve is not available.')422 @test.attr(type=['negative'])423 def test_unshelve_non_existent_server(self):424 # unshelve a non existent server425 nonexistent_server = data_utils.rand_uuid()426 self.assertRaises(lib_exc.NotFound, self.client.unshelve_server,427 nonexistent_server)428 @test.idempotent_id('8f198ded-1cca-4228-9e65-c6b449c54880')429 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,430 'Shelve is not available.')431 @test.attr(type=['negative'])432 def test_unshelve_server_invalid_state(self):433 # unshelve an active server.434 self.assertRaises(lib_exc.Conflict,435 self.client.unshelve_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