Best Python code snippet using localstack_python
test_cleanup_services.py
Source:test_cleanup_services.py
1# Copyright 2018 AT&T Corporation.2# 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 fixtures16from oslo_serialization import jsonutils as json17from tempest import clients18from tempest.cmd import cleanup_service19from tempest import config20from tempest.lib import exceptions21from tempest.tests import base22from tempest.tests import fake_config23from tempest.tests.lib import fake_credentials24from tempest.tests.lib import fake_http25class TestBaseService(base.TestCase):26 class TestException(cleanup_service.BaseService):27 def delete(self):28 raise exceptions.NotImplemented29 def dry_run(self):30 raise exceptions.NotImplemented31 def save_state(self):32 raise exceptions.NotImplemented33 def test_base_service_init(self):34 kwargs = {'data': {'data': 'test'},35 'is_dry_run': False,36 'saved_state_json': {'saved': 'data'},37 'is_preserve': False,38 'is_save_state': True,39 'tenant_id': 'project_id',40 'got_exceptions': []}41 base = cleanup_service.BaseService(kwargs)42 self.assertEqual(base.data, kwargs['data'])43 self.assertFalse(base.is_dry_run)44 self.assertEqual(base.saved_state_json, kwargs['saved_state_json'])45 self.assertFalse(base.is_preserve)46 self.assertTrue(base.is_save_state)47 self.assertEqual(base.tenant_filter['project_id'], kwargs['tenant_id'])48 self.assertEqual(base.got_exceptions, kwargs['got_exceptions'])49 def test_not_implemented_ex(self):50 kwargs = {'data': {'data': 'test'},51 'is_dry_run': False,52 'saved_state_json': {'saved': 'data'},53 'is_preserve': False,54 'is_save_state': False,55 'tenant_id': 'project_id',56 'got_exceptions': []}57 base = self.TestException(kwargs)58 # delete59 base.run()60 self.assertEqual(len(base.got_exceptions), 1)61 # save_state62 base.save_state = True63 base.run()64 self.assertEqual(len(base.got_exceptions), 2)65 # dry_run66 base.is_dry_run = True67 base.run()68 self.assertEqual(len(base.got_exceptions), 3)69class MockFunctionsBase(base.TestCase):70 def _create_response(self, body, status, headers):71 if status:72 if body:73 body = json.dumps(body)74 resp = fake_http.fake_http_response(headers, status=status), body75 return resp76 else:77 return body78 def _create_fixtures(self, fixtures_to_make):79 mocked_fixtures = []80 for fixture in fixtures_to_make:81 func, body, status = fixture82 mocked_response = self._create_response(body, status, None)83 if mocked_response == 'error':84 mocked_func = self.useFixture(fixtures.MockPatch(85 func, side_effect=Exception("error")))86 else:87 mocked_func = self.useFixture(fixtures.MockPatch(88 func, return_value=mocked_response))89 mocked_fixtures.append(mocked_func)90 return mocked_fixtures91 def run_function_with_mocks(self, function_to_run, functions_to_mock):92 """Mock a service client function for testing.93 :param function_to_run: The service client function to call.94 :param functions_to_mock: a list of tuples containing the function95 to mock, the response body, and the response status.96 EX:97 ('tempest.lib.common.rest_client.RestClient.get',98 {'users': ['']},99 200)100 """101 mocked_fixtures = self._create_fixtures(functions_to_mock)102 func_return = function_to_run()103 return func_return, mocked_fixtures104class BaseCmdServiceTests(MockFunctionsBase):105 def setUp(self):106 super(BaseCmdServiceTests, self).setUp()107 self.useFixture(fake_config.ConfigFixture())108 self.patchobject(config, 'TempestConfigPrivate',109 fake_config.FakePrivate)110 self.useFixture(fixtures.MockPatch(111 'tempest.cmd.cleanup_service._get_network_id',112 return_value=''))113 cleanup_service.init_conf()114 self.conf_values = {"flavors": cleanup_service.CONF_FLAVORS[0],115 "images": cleanup_service.CONF_IMAGES[0],116 "projects": cleanup_service.CONF_PROJECTS[0],117 "users": cleanup_service.CONF_USERS[0],118 "networks": cleanup_service.CONF_PUB_NETWORK,119 "security_groups":120 cleanup_service.CONF_PROJECTS[0],121 "ports": cleanup_service.CONF_PUB_NETWORK,122 "routers": cleanup_service.CONF_PUB_ROUTER,123 "subnetpools": cleanup_service.CONF_PROJECTS[0],124 }125 saved_state = {126 # Static list to ensure global service saved items are not deleted127 "users": {u'32rwef64245tgr20121qw324bgg': u'Lightning'},128 "flavors": {u'42': u'm1.tiny'},129 "images": {u'34yhwr-4t3q': u'stratus-0.3.2-x86_64-disk'},130 "roles": {u'3efrt74r45hn': u'president'},131 "projects": {u'f38ohgp93jj032': u'manhattan'},132 "domains": {u'default': u'Default'},133 # Static list to ensure project service saved items are not deleted134 "snapshots": {u'1ad4c789-7e8w-4dwg-afc5': u'saved-snapshot'},135 "servers": {u'7a6d4v7w-36ds-4216': u'saved-server'},136 "server_groups": {u'as6d5f7g-46ca-475e': u'saved-server-group'},137 "keypairs": {u'saved-key-pair': {138 u'fingerprint': u'7e:eb:ab:24',139 u'name': u'saved-key-pair'140 }},141 "volumes": {u'aa77asdf-1234': u'saved-volume'},142 "networks": {u'6722fc13-4319': {143 u'id': u'6722fc13-4319',144 u'name': u'saved-network'145 }},146 "floatingips": {u'9e82d248-408a': {147 u'id': u'9e82d248-408a',148 u'status': u'ACTIVE'149 }},150 "routers": {u'4s5w34hj-id44': u'saved-router'},151 "metering_label_rules": {u'93a973ce-4dc5': {152 u'direction': u'ingress',153 u'id': u'93a973ce-4dc5'154 }},155 "metering_labels": {u'723b346ce866-4c7q': u'saved-label'},156 "ports": {u'aa74aa4v-741a': u'saved-port'},157 "security_groups": {u'7q844add-3697': u'saved-sec-group'},158 "subnets": {u'55ttda4a-2584': u'saved-subnet'},159 "subnetpools": {u'8acf64c1-43fc': u'saved-subnet-pool'},160 "regions": {u'RegionOne': {}}161 }162 # Mocked methods163 get_method = 'tempest.lib.common.rest_client.RestClient.get'164 delete_method = 'tempest.lib.common.rest_client.RestClient.delete'165 log_method = 'tempest.cmd.cleanup_service.LOG.exception'166 # Override parameters167 service_class = 'BaseService'168 response = None169 service_name = 'default'170 def _create_cmd_service(self, service_type, is_save_state=False,171 is_preserve=False, is_dry_run=False):172 creds = fake_credentials.FakeKeystoneV3Credentials()173 os = clients.Manager(creds)174 return getattr(cleanup_service, service_type)(175 os,176 is_save_state=is_save_state,177 is_preserve=is_preserve,178 is_dry_run=is_dry_run,179 project_id='b8e3ece07bb049138d224436756e3b57',180 data={},181 saved_state_json=self.saved_state182 )183 def _test_delete(self, mocked_fixture_tuple_list, fail=False):184 serv = self._create_cmd_service(self.service_class)185 resp, fixtures = self.run_function_with_mocks(186 serv.run,187 mocked_fixture_tuple_list,188 )189 for fixture in fixtures:190 if fixture.mock.return_value == 'validate':191 fixture.mock.assert_called()192 elif fail is False and fixture.mock.return_value == 'exception':193 fixture.mock.assert_not_called()194 elif self.service_name in self.saved_state.keys():195 fixture.mock.assert_called_once()196 for key in self.saved_state[self.service_name].keys():197 self.assertNotIn(key, fixture.mock.call_args[0][0])198 else:199 fixture.mock.assert_called_once()200 self.assertFalse(serv.data)201 def _test_dry_run_true(self, mocked_fixture_tuple_list):202 serv = self._create_cmd_service(self.service_class, is_dry_run=True)203 _, fixtures = self.run_function_with_mocks(204 serv.run,205 mocked_fixture_tuple_list206 )207 for fixture in fixtures:208 if fixture.mock.return_value == 'delete':209 fixture.mock.assert_not_called()210 elif self.service_name in self.saved_state.keys():211 fixture.mock.assert_called_once()212 for key in self.saved_state[self.service_name].keys():213 self.assertNotIn(key, fixture.mock.call_args[0][0])214 else:215 fixture.mock.assert_called_once()216 def _test_saved_state_true(self, mocked_fixture_tuple_list):217 serv = self._create_cmd_service(self.service_class, is_save_state=True)218 _, fixtures = self.run_function_with_mocks(219 serv.run,220 mocked_fixture_tuple_list221 )222 for item in self.response[self.service_name]:223 self.assertIn(item['id'],224 serv.data[self.service_name])225 for fixture in fixtures:226 fixture.mock.assert_called_once()227 def _test_is_preserve_true(self, mocked_fixture_tuple_list):228 serv = self._create_cmd_service(self.service_class, is_preserve=True)229 resp, fixtures = self.run_function_with_mocks(230 serv.list,231 mocked_fixture_tuple_list232 )233 for fixture in fixtures:234 fixture.mock.assert_called_once()235 self.assertIn(resp[0], self.response[self.service_name])236 for rsp in resp:237 self.assertNotIn(rsp['id'], self.conf_values.values())238 self.assertNotIn(rsp['name'], self.conf_values.values())239class TestSnapshotService(BaseCmdServiceTests):240 service_class = 'SnapshotService'241 service_name = 'snapshots'242 response = {243 "snapshots": [244 {245 "status": "available",246 "metadata": {247 "name": "test"248 },249 "name": "test-volume-snapshot",250 "volume_id": "173f7b48-c4c1-4e70-9acc-086b39073506",251 "created_at": "2015-11-29T02:25:51.000000",252 "size": 1,253 "updated_at": "2015-11-20T05:36:40.000000",254 "id": "b1323cda-8e4b-41c1-afc5-2fc791809c8c",255 "description": "volume snapshot"256 },257 {258 "status": "available",259 "name": "saved-snapshot",260 "metadata": {},261 "id": "1ad4c789-7e8w-4dwg-afc5",262 "size": 1,263 "volume_id": "af7c41be-1ff6-4233-a690-7ed61c34347f",264 "created_at": "2015-11-20T05:39:40.000000",265 "updated_at": "2015-11-20T05:39:40.000000",266 "description": "snapshot in saved state"267 }268 ]269 }270 def test_delete_fail(self):271 delete_mock = [(self.get_method, self.response, 200),272 (self.delete_method, 'error', None),273 (self.log_method, 'exception', None)]274 self._test_delete(delete_mock, fail=True)275 def test_delete_pass(self):276 delete_mock = [(self.get_method, self.response, 200),277 (self.delete_method, None, 202),278 (self.log_method, 'exception', None)]279 self._test_delete(delete_mock)280 def test_dry_run(self):281 dry_mock = [(self.get_method, self.response, 200),282 (self.delete_method, "delete", None)]283 self._test_dry_run_true(dry_mock)284 def test_save_state(self):285 self._test_saved_state_true([(self.get_method, self.response, 200)])286class TestServerService(BaseCmdServiceTests):287 service_class = 'ServerService'288 service_name = 'servers'289 response = {290 "servers": [291 {292 "id": "22c91117-08de-4894-9aa9-6ef382400985",293 "links": [294 {295 "href": "http://openstack.example.com/v2/6f70-6ef0985",296 "rel": "self"297 },298 {299 "href": "http://openstack.example.com/6f70656e7-6ef35",300 "rel": "bookmark"301 }302 ],303 "name": "new-server-test"304 },305 {306 "id": "7a6d4v7w-36ds-4216",307 "links": [308 {309 "href": "http://openstack.example.com/v2/6f70-6ef0985",310 "rel": "self"311 },312 {313 "href": "http://openstack.example.com/6f70656e7-6ef35",314 "rel": "bookmark"315 }316 ],317 "name": "saved-server"318 }319 ]320 }321 def test_delete_fail(self):322 delete_mock = [(self.get_method, self.response, 200),323 (self.delete_method, 'error', None),324 (self.log_method, 'exception', None)]325 self._test_delete(delete_mock, fail=True)326 def test_delete_pass(self):327 delete_mock = [(self.get_method, self.response, 200),328 (self.delete_method, None, 204),329 (self.log_method, 'exception', None)]330 self._test_delete(delete_mock)331 def test_dry_run(self):332 dry_mock = [(self.get_method, self.response, 200),333 (self.delete_method, "delete", None)]334 self._test_dry_run_true(dry_mock)335 def test_save_state(self):336 self._test_saved_state_true([(self.get_method, self.response, 200)])337class TestServerGroupService(BaseCmdServiceTests):338 service_class = 'ServerGroupService'339 service_name = 'server_groups'340 validate_response = ('tempest.lib.services.compute.server_groups_client'341 '.ServerGroupsClient.validate_response')342 response = {343 "server_groups": [344 {345 "id": "616fb98f-46ca-475e-917e-2563e5a8cd19",346 "name": "test",347 "policy": "anti-affinity",348 "rules": {"max_server_per_host": 3},349 "members": [],350 "project_id": "6f70656e737461636b20342065766572",351 "user_id": "fake"352 },353 {354 "id": "as6d5f7g-46ca-475e",355 "name": "saved-server-group"356 }357 ]358 }359 def test_delete_fail(self):360 delete_mock = [(self.get_method, self.response, 200),361 (self.validate_response, 'validate', None),362 (self.delete_method, 'error', None),363 (self.log_method, 'exception', None)]364 self._test_delete(delete_mock, fail=True)365 def test_delete_pass(self):366 delete_mock = [(self.get_method, self.response, 200),367 (self.validate_response, 'validate', None),368 (self.delete_method, None, 204),369 (self.log_method, 'exception', None)]370 self._test_delete(delete_mock)371 def test_dry_run(self):372 dry_mock = [(self.get_method, self.response, 200),373 (self.validate_response, 'validate', None),374 (self.delete_method, "delete", None)]375 self._test_dry_run_true(dry_mock)376 def test_save_state(self):377 self._test_saved_state_true([(self.get_method, self.response, 200),378 (self.validate_response, 'validate', None)379 ])380class TestKeyPairService(BaseCmdServiceTests):381 service_class = 'KeyPairService'382 service_name = 'keypairs'383 validate_response = ('tempest.lib.services.compute.keypairs_client'384 '.KeyPairsClient.validate_response')385 response = {386 "keypairs": [387 {388 "keypair": {389 "fingerprint": "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:bd",390 "name": "keypair-5d935425-31d5-48a7-a0f1-e76e9813f2c3",391 "type": "ssh",392 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkF\n"393 }394 },395 {396 "keypair": {397 "fingerprint": "7e:eb:ab:24",398 "name": "saved-key-pair"399 }400 }401 ]402 }403 def _test_saved_state_true(self, mocked_fixture_tuple_list):404 serv = self._create_cmd_service(self.service_class, is_save_state=True)405 _, fixtures = self.run_function_with_mocks(406 serv.run,407 mocked_fixture_tuple_list408 )409 for item in self.response[self.service_name]:410 self.assertTrue(item['keypair']['name'],411 serv.data[self.service_name])412 for fixture in fixtures:413 fixture.mock.assert_called_once()414 def test_delete_fail(self):415 delete_mock = [(self.get_method, self.response, 200),416 (self.validate_response, 'validate', None),417 (self.delete_method, 'error', None),418 (self.log_method, 'exception', None)]419 self._test_delete(delete_mock, fail=True)420 def test_delete_pass(self):421 delete_mock = [(self.get_method, self.response, 200),422 (self.validate_response, 'validate', None),423 (self.delete_method, None, 204),424 (self.log_method, 'exception', None)]425 self._test_delete(delete_mock)426 def test_dry_run(self):427 dry_mock = [(self.get_method, self.response, 200),428 (self.validate_response, 'validate', None),429 (self.delete_method, "delete", None)]430 self._test_dry_run_true(dry_mock)431 def test_save_state(self):432 self._test_saved_state_true([433 (self.get_method, self.response, 200),434 (self.validate_response, 'validate', None)435 ])436class TestVolumeService(BaseCmdServiceTests):437 service_class = 'VolumeService'438 service_name = 'volumes'439 response = {440 "volumes": [441 {442 "id": "efa54464-8fab-47cd-a05a-be3e6b396188",443 "links": [444 {445 "href": "http://127.0.0.1:37097/v3/89af/volumes/efa54",446 "rel": "self"447 },448 {449 "href": "http://127.0.0.1:37097/89af/volumes/efa54464",450 "rel": "bookmark"451 }452 ],453 "name": "volume-name"454 },455 {456 "id": "aa77asdf-1234",457 "name": "saved-volume"458 }459 ]460 }461 def test_delete_fail(self):462 delete_mock = [(self.get_method, self.response, 200),463 (self.delete_method, 'error', None),464 (self.log_method, 'exception', None)]465 self._test_delete(delete_mock, fail=True)466 def test_delete_pass(self):467 delete_mock = [(self.get_method, self.response, 200),468 (self.delete_method, None, 202),469 (self.log_method, 'exception', None)]470 self._test_delete(delete_mock)471 def test_dry_run(self):472 dry_mock = [(self.get_method, self.response, 200),473 (self.delete_method, "delete", None)]474 self._test_dry_run_true(dry_mock)475 def test_save_state(self):476 self._test_saved_state_true([(self.get_method, self.response, 200)])477class TestVolumeQuotaService(BaseCmdServiceTests):478 service_class = 'VolumeQuotaService'479 service_name = 'volume_quota_service'480 response = {481 "quota_set": {482 "groups":483 {"reserved": 0, "limit": 10, "in_use": 0},484 "per_volume_gigabytes":485 {"reserved": 0, "limit": -1, "in_use": 0},486 "volumes":487 {"reserved": 0, "limit": 10, "in_use": 0},488 "gigabytes":489 {"reserved": 0, "limit": 1000, "in_use": 0},490 "backup_gigabytes":491 {"reserved": 0, "limit": 1000, "in_use": 0},492 "snapshots":493 {"reserved": 0, "limit": 10, "in_use": 0},494 "volumes_iscsi":495 {"reserved": 0, "limit": -1, "in_use": 0},496 "snapshots_iscsi":497 {"reserved": 0, "limit": -1, "in_use": 0},498 "backups":499 {"reserved": 0, "limit": 10, "in_use": 0},500 "gigabytes_iscsi":501 {"reserved": 0, "limit": -1, "in_use": 0},502 "id": "b8e3ece07bb049138d224436756e3b57"503 }504 }505 def test_delete_fail(self):506 delete_mock = [(self.delete_method, 'error', None),507 (self.log_method, 'exception', None)]508 self._test_delete(delete_mock, fail=True)509 def test_delete_pass(self):510 delete_mock = [(self.delete_method, None, 200),511 (self.log_method, 'exception', None)]512 self._test_delete(delete_mock)513 def test_dry_run(self):514 dry_mock = [(self.get_method, self.response, 200),515 (self.delete_method, "delete", None)]516 self._test_dry_run_true(dry_mock)517class TestNovaQuotaService(BaseCmdServiceTests):518 service_class = 'NovaQuotaService'519 service_name = 'nova_quota_service'520 response = {521 "limits": {522 "rate": [],523 "absolute": {524 "maxServerMeta": 128,525 "maxPersonality": 5,526 "totalServerGroupsUsed": 0,527 "maxImageMeta": 128,528 "maxPersonalitySize": 10240,529 "maxTotalKeypairs": 100,530 "maxSecurityGroupRules": 20,531 "maxServerGroups": 10,532 "totalCoresUsed": 0,533 "totalRAMUsed": 0,534 "totalInstancesUsed": 0,535 "maxSecurityGroups": 10,536 "totalFloatingIpsUsed": 0,537 "maxTotalCores": 20,538 "maxServerGroupMembers": 10,539 "maxTotalFloatingIps": 10,540 "totalSecurityGroupsUsed": 0,541 "maxTotalInstances": 10,542 "maxTotalRAMSize": 51200543 }544 }545 }546 def test_delete_fail(self):547 delete_mock = [(self.delete_method, 'error', None),548 (self.log_method, 'exception', None)]549 self._test_delete(delete_mock, fail=True)550 def test_delete_pass(self):551 delete_mock = [(self.delete_method, None, 202),552 (self.log_method, 'exception', None)]553 self._test_delete(delete_mock)554 def test_dry_run(self):555 dry_mock = [(self.get_method, self.response, 200),556 (self.delete_method, "delete", None)]557 self._test_dry_run_true(dry_mock)558class TestNetworkQuotaService(BaseCmdServiceTests):559 service_class = 'NetworkQuotaService'560 service_name = 'network_quota_service'561 response = {562 "quotas": [{563 "subnet": 110,564 "network": 100,565 "floatingip": 50,566 "tenant_id": "81e8490db559474dacb2212fca9cca2d",567 "subnetpool": -1,568 "security_group_rule": 100,569 "trunk": -1,570 "security_group": 10,571 "router": 10,572 "rbac_policy": 10, "project_id":573 "81e8490db559474dacb2212fca9cca2d", "port": 500574 }]575 }576 def test_delete_fail(self):577 delete_mock = [(self.delete_method, 'error', None),578 (self.log_method, 'exception', None)]579 self._test_delete(delete_mock, fail=True)580 def test_delete_pass(self):581 delete_mock = [(self.delete_method, None, 204),582 (self.log_method, 'exception', None)]583 self._test_delete(delete_mock)584 def test_dry_run(self):585 dry_mock = [(self.get_method, self.response, 200),586 (self.delete_method, "delete", None)]587 self._test_dry_run_true(dry_mock)588# Begin network service classes589class TestNetworkService(BaseCmdServiceTests):590 service_class = 'NetworkService'591 service_name = 'networks'592 response = {593 "networks": [594 {595 "admin_state_up": True,596 "availability_zone_hints": [],597 "availability_zones": [598 "nova"599 ],600 "created_at": "2016-03-08T20:19:41",601 "dns_domain": "my-domain.org.",602 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",603 "l2_adjacency": False,604 "mtu": 1500,605 "name": "net1",606 "port_security_enabled": True,607 "project_id": "4fd44f30292945e481c7b8a0c8908869",608 "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",609 "revision_number": 1,610 "router:external": False,611 "shared": False,612 "status": "ACTIVE",613 "subnets": [614 "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"615 ],616 "tenant_id": "4fd44f30292945e481c7b8a0c8908869",617 "updated_at": "2016-03-08T20:19:41",618 "vlan_transparent": True,619 "description": "",620 "is_default": False621 },622 {623 "id": "6722fc13-4319",624 "name": "saved-network"625 }626 ]627 }628 def test_delete_fail(self):629 delete_mock = [(self.get_method, self.response, 200),630 (self.delete_method, 'error', None),631 (self.log_method, 'exception', None)]632 self._test_delete(delete_mock, fail=True)633 def test_delete_pass(self):634 delete_mock = [(self.get_method, self.response, 200),635 (self.delete_method, None, 204),636 (self.log_method, 'exception', None)]637 self._test_delete(delete_mock)638 def test_dry_run(self):639 dry_mock = [(self.get_method, self.response, 200),640 (self.delete_method, "delete", None)]641 self._test_dry_run_true(dry_mock)642 def test_save_state(self):643 self._test_saved_state_true([(self.get_method, self.response, 200)])644 def test_preserve_list(self):645 self.response['networks'].append(646 {647 "admin_state_up": True,648 "availability_zone_hints": [],649 "availability_zones": [650 "nova"651 ],652 "created_at": "2017-03-08T20:19:41",653 "dns_domain": "my-domain.org.",654 "id": cleanup_service.CONF_PUB_NETWORK,655 "name": "net2",656 "port_security_enabled": True,657 "project_id": "4fd44f30292945e481c7b8a0c8908869",658 "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",659 "revision_number": 1,660 "status": "ACTIVE",661 "subnets": [662 "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"663 ],664 "tenant_id": "4fd44f30292945e481c7b8a0c8908869",665 "updated_at": "2018-03-08T20:19:41",666 "vlan_transparent": True,667 "is_default": False668 })669 self._test_is_preserve_true([(self.get_method, self.response, 200)])670class TestNetworkFloatingIpService(BaseCmdServiceTests):671 service_class = 'NetworkFloatingIpService'672 service_name = 'floatingips'673 response = {674 "floatingips": [675 {676 "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f",677 "description": "for test",678 "dns_domain": "my-domain.org.",679 "dns_name": "myfip",680 "created_at": "2016-12-21T10:55:50Z",681 "updated_at": "2016-12-21T10:55:53Z",682 "revision_number": 1,683 "project_id": "4969c491a3c74ee4af974e6d800c62de",684 "tenant_id": "4969c491a3c74ee4af974e6d800c62de",685 "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57",686 "fixed_ip_address": "10.0.0.3",687 "floating_ip_address": "172.24.4.228",688 "port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",689 "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7",690 "status": "ACTIVE",691 "port_details": {692 "status": "ACTIVE",693 "name": "",694 "admin_state_up": True,695 "network_id": "02dd8479-ef26-4398-a102-d19d0a7b3a1f",696 "device_owner": "compute:nova",697 "mac_address": "fa:16:3e:b1:3b:30",698 "device_id": "8e3941b4-a6e9-499f-a1ac-2a4662025cba"699 },700 "tags": ["tag1,tag2"],701 "port_forwardings": []702 },703 {704 "id": "9e82d248-408a",705 "status": "ACTIVE"706 }707 ]708 }709 def test_delete_fail(self):710 delete_mock = [(self.get_method, self.response, 200),711 (self.delete_method, 'error', None),712 (self.log_method, 'exception', None)]713 self._test_delete(delete_mock, fail=True)714 def test_delete_pass(self):715 delete_mock = [(self.get_method, self.response, 200),716 (self.delete_method, None, 204),717 (self.log_method, 'exception', None)]718 self._test_delete(delete_mock)719 def test_dry_run(self):720 dry_mock = [(self.get_method, self.response, 200),721 (self.delete_method, "delete", None)]722 self._test_dry_run_true(dry_mock)723 def test_save_state(self):724 self._test_saved_state_true([(self.get_method, self.response, 200)])725class TestNetworkRouterService(BaseCmdServiceTests):726 service_class = 'NetworkRouterService'727 service_name = 'routers'728 validate_response = ('tempest.lib.services.network.routers_client'729 '.RoutersClient.validate_response')730 response = {731 "routers": [732 {733 "admin_state_up": True,734 "availability_zone_hints": [],735 "availability_zones": [736 "nova"737 ],738 "created_at": "2018-03-19T19:17:04Z",739 "description": "",740 "distributed": False,741 "external_gateway_info": {742 "enable_snat": True,743 "external_fixed_ips": [744 {745 "ip_address": "172.24.4.3",746 "subnet_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"747 },748 {749 "ip_address": "2001:db8::c",750 "subnet_id": "0c56df5d-ace5-46c8-8f4c-45fa4e334d18"751 }752 ],753 "network_id": "ae34051f-aa6c-4c75-abf5-50dc9ac99ef3"754 },755 "flavor_id": "f7b14d9a-b0dc-4fbe-bb14-a0f4970a69e0",756 "ha": False,757 "id": "915a14a6-867b-4af7-83d1-70efceb146f9",758 "name": "router2",759 "revision_number": 1,760 "routes": [761 {762 "destination": "179.24.1.0/24",763 "nexthop": "172.24.3.99"764 }765 ],766 "status": "ACTIVE",767 "updated_at": "2018-03-19T19:17:22Z",768 "project_id": "0bd18306d801447bb457a46252d82d13",769 "tenant_id": "0bd18306d801447bb457a46252d82d13",770 "tags": ["tag1,tag2"]771 },772 {773 "id": "4s5w34hj-id44",774 "name": "saved-router"775 }776 ],777 # "ports" key is added to the response in order to simplify unit778 # testing - it's because NetworkRouterService's delete method lists779 # ports before deleting any router780 "ports": []781 }782 def _test_delete(self, mocked_fixture_tuple_list, fail=False):783 serv = self._create_cmd_service(self.service_class)784 resp, fixtures = self.run_function_with_mocks(785 serv.run,786 mocked_fixture_tuple_list,787 )788 for fixture in fixtures:789 if fail is False and fixture.mock.return_value == 'exception':790 fixture.mock.assert_not_called()791 elif self.service_name in self.saved_state.keys():792 fixture.mock.assert_called()793 for key in self.saved_state[self.service_name].keys():794 self.assertNotIn(key, fixture.mock.call_args[0][0])795 self.assertFalse(serv.data)796 def test_delete_fail(self):797 delete_mock = [(self.get_method, self.response, 200),798 (self.delete_method, 'error', None),799 (self.log_method, 'exception', None)]800 self._test_delete(delete_mock, fail=True)801 def test_delete_pass(self):802 delete_mock = [(self.get_method, self.response, 200),803 (self.delete_method, None, 204),804 (self.log_method, 'exception', None)]805 self._test_delete(delete_mock)806 def test_dry_run(self):807 dry_mock = [(self.get_method, self.response, 200),808 (self.delete_method, "delete", None)]809 self._test_dry_run_true(dry_mock)810 def test_save_state(self):811 self._test_saved_state_true([(self.get_method, self.response, 200)])812 def test_preserve_list(self):813 self.response['routers'].append(814 {815 "admin_state_up": True,816 "availability_zone_hints": [],817 "availability_zones": [818 "nova"819 ],820 "created_at": "2018-03-19T19:17:04Z",821 "id": cleanup_service.CONF_PUB_ROUTER,822 "name": "router-preserve",823 "status": "ACTIVE",824 "updated_at": "2018-03-19T19:17:22Z",825 "project_id": "0bd18306d801447bb457a46252d82d13",826 "tenant_id": "0bd18306d801447bb457a46252d82d13",827 "tags": ["tag1,tag2"]828 })829 self._test_is_preserve_true([(self.get_method, self.response, 200)])830class TestNetworkMeteringLabelRuleService(BaseCmdServiceTests):831 service_class = 'NetworkMeteringLabelRuleService'832 service_name = 'metering_label_rules'833 response = {834 "metering_label_rules": [835 {836 "remote_ip_prefix": "20.0.0.0/24",837 "direction": "ingress",838 "metering_label_id": "e131d186-b02d-4c0b-83d5-0c0725c4f812",839 "id": "9536641a-7d14-4dc5-afaf-93a973ce0eb8",840 "excluded": False841 },842 {843 "direction": "ingress",844 "id": "93a973ce-4dc5"845 }846 ]847 }848 def test_delete_fail(self):849 delete_mock = [(self.get_method, self.response, 200),850 (self.delete_method, 'error', None),851 (self.log_method, 'exception', None)]852 self._test_delete(delete_mock, fail=True)853 def test_delete_pass(self):854 delete_mock = [(self.get_method, self.response, 200),855 (self.delete_method, None, 204),856 (self.log_method, 'exception', None)]857 self._test_delete(delete_mock)858 def test_dry_run(self):859 dry_mock = [(self.get_method, self.response, 200),860 (self.delete_method, "delete", None)]861 self._test_dry_run_true(dry_mock)862 def test_save_state(self):863 self._test_saved_state_true([(self.get_method, self.response, 200)])864class TestNetworkMeteringLabelService(BaseCmdServiceTests):865 service_class = 'NetworkMeteringLabelService'866 service_name = 'metering_labels'867 response = {868 "metering_labels": [869 {870 "project_id": "45345b0ee1ea477fac0f541b2cb79cd4",871 "tenant_id": "45345b0ee1ea477fac0f541b2cb79cd4",872 "description": "label1 description",873 "name": "label1",874 "id": "a6700594-5b7a-4105-8bfe-723b346ce866",875 "shared": False876 },877 {878 "name": "saved-label",879 "id": "723b346ce866-4c7q",880 }881 ]882 }883 def test_delete_fail(self):884 delete_mock = [(self.get_method, self.response, 200),885 (self.delete_method, 'error', None),886 (self.log_method, 'exception', None)]887 self._test_delete(delete_mock, fail=True)888 def test_delete_pass(self):889 delete_mock = [(self.get_method, self.response, 200),890 (self.delete_method, None, 204),891 (self.log_method, 'exception', None)]892 self._test_delete(delete_mock)893 def test_dry_run(self):894 dry_mock = [(self.get_method, self.response, 200),895 (self.delete_method, "delete", None)]896 self._test_dry_run_true(dry_mock)897 def test_save_state(self):898 self._test_saved_state_true([(self.get_method, self.response, 200)])899class TestNetworkPortService(BaseCmdServiceTests):900 service_class = 'NetworkPortService'901 service_name = 'ports'902 response = {903 "ports": [904 {905 "admin_state_up": True,906 "allowed_address_pairs": [],907 "created_at": "2016-03-08T20:19:41",908 "description": "",909 "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824",910 "device_owner": "",911 "dns_assignment": {912 "hostname": "myport",913 "ip_address": "172.24.4.2",914 "fqdn": "myport.my-domain.org"915 },916 "dns_domain": "my-domain.org.",917 "dns_name": "myport",918 "extra_dhcp_opts": [919 {920 "opt_value": "pxelinux.0",921 "ip_version": 4,922 "opt_name": "bootfile-name"923 }924 ],925 "fixed_ips": [926 {927 "ip_address": "172.24.4.2",928 "subnet_id": "008ba151-0b8c-4a67-98b5-0d2b87666062"929 }930 ],931 "id": "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b",932 "ip_allocation": "immediate",933 "mac_address": "fa:16:3e:58:42:ed",934 "name": "test_port",935 "network_id": "70c1db1f-b701-45bd-96e0-a313ee3430b3",936 "project_id": "",937 "revision_number": 1,938 "security_groups": [],939 "status": "ACTIVE",940 "tags": ["tag1,tag2"],941 "tenant_id": "",942 "updated_at": "2016-03-08T20:19:41",943 "qos_policy_id": "29d5e02e-d5ab-4929-bee4-4a9fc12e22ae",944 "port_security_enabled": False945 },946 {947 "id": "aa74aa4v-741a",948 "name": "saved-port",949 "device_owner": ""950 }951 ]952 }953 def test_delete_fail(self):954 delete_mock = [(self.get_method, self.response, 200),955 (self.delete_method, 'error', None),956 (self.log_method, 'exception', None)]957 self._test_delete(delete_mock, fail=True)958 def test_delete_pass(self):959 delete_mock = [(self.get_method, self.response, 200),960 (self.delete_method, None, 204),961 (self.log_method, 'exception', None)]962 self._test_delete(delete_mock)963 def test_dry_run(self):964 dry_mock = [(self.get_method, self.response, 200),965 (self.delete_method, "delete", None)]966 self._test_dry_run_true(dry_mock)967 def test_save_state(self):968 self._test_saved_state_true([(self.get_method, self.response, 200)])969 def test_preserve_list(self):970 self.response['ports'].append(971 {972 "created_at": "2018-03-08T20:19:41",973 "description": "",974 "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824",975 "device_owner": "compute:router_gateway",976 "id": "d80b1a3b-4fc1-49f3-952e-1fdy1ws542",977 "ip_allocation": "immediate",978 "mac_address": "fa:16:3e:58:42:ed",979 "name": "preserve_port",980 "network_id": cleanup_service.CONF_PUB_NETWORK,981 "project_id": "",982 "security_groups": [],983 "status": "ACTIVE",984 "tags": ["tag1,tag2"],985 "tenant_id": "",986 "updated_at": "2018-03-08T20:19:41",987 })988 self._test_is_preserve_true([(self.get_method, self.response, 200)])989class TestNetworkSecGroupService(BaseCmdServiceTests):990 service_class = 'NetworkSecGroupService'991 service_name = 'security_groups'992 response = {993 "security_groups": [994 {995 "description": "default",996 "id": "85cc3048-abc3-43cc-89b3-377341426ac5",997 "name": "test",998 "security_group_rules": [999 {1000 "direction": "egress",1001 "ethertype": "IPv6",1002 "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff",1003 "security_group_id": "85cc3048-abc3-43cc-89b3-3773414",1004 "project_id": "e4f50856753b4dc6afee5fa6b9b6c550",1005 "revision_number": 1,1006 "tags": ["tag1,tag2"],1007 "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",1008 "created_at": "2018-03-19T19:16:56Z",1009 "updated_at": "2018-03-19T19:16:56Z",1010 "description": ""1011 }1012 ]1013 },1014 {1015 "id": "7q844add-3697",1016 "name": "saved-sec-group"1017 }1018 ]1019 }1020 def test_delete_fail(self):1021 delete_mock = [(self.get_method, self.response, 200),1022 (self.delete_method, 'error', None),1023 (self.log_method, 'exception', None)]1024 self._test_delete(delete_mock, fail=True)1025 def test_delete_pass(self):1026 delete_mock = [(self.get_method, self.response, 200),1027 (self.delete_method, None, 204),1028 (self.log_method, 'exception', None)]1029 self._test_delete(delete_mock)1030 def test_dry_run(self):1031 dry_mock = [(self.get_method, self.response, 200),1032 (self.delete_method, "delete", None)]1033 self._test_dry_run_true(dry_mock)1034 def test_save_state(self):1035 self._test_saved_state_true([(self.get_method, self.response, 200)])1036 def test_preserve_list(self):1037 self.response['security_groups'].append(1038 {1039 "description": "default",1040 "id": "85cc3048-abc3-43cc-89b3-377341426ac5",1041 "name": "test",1042 "security_group_rules": [1043 {1044 "direction": "egress",1045 "ethertype": "IPv6",1046 "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff",1047 "security_group_id": "85cc3048-abc3-43cc-89b3-3773414",1048 "project_id": cleanup_service.CONF_PROJECTS[0],1049 "revision_number": 1,1050 "tags": ["tag1,tag2"],1051 "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",1052 "created_at": "2018-03-19T19:16:56Z",1053 "updated_at": "2018-03-19T19:16:56Z",1054 "description": ""1055 }1056 ]1057 })1058 self._test_is_preserve_true([(self.get_method, self.response, 200)])1059class TestNetworkSubnetService(BaseCmdServiceTests):1060 service_class = 'NetworkSubnetService'1061 service_name = 'subnets'1062 response = {1063 "subnets": [1064 {1065 "name": "private-subnet",1066 "enable_dhcp": True,1067 "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",1068 "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",1069 "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",1070 "dns_nameservers": [],1071 "allocation_pools": [1072 {1073 "start": "10.0.0.2",1074 "end": "10.0.0.254"1075 }1076 ],1077 "host_routes": [],1078 "ip_version": 4,1079 "gateway_ip": "10.0.0.1",1080 "cidr": "10.0.0.0/24",1081 "id": "08eae331-0402-425a-923c-34f7cfe39c1b",1082 "created_at": "2016-10-10T14:35:34Z",1083 "revision_number": 2,1084 "service_types": [],1085 "tags": ["tag1,tag2"],1086 "updated_at": "2016-10-10T14:35:34Z"1087 },1088 {1089 "id": "55ttda4a-2584",1090 "name": "saved-subnet"1091 }1092 ]1093 }1094 def test_delete_fail(self):1095 delete_mock = [(self.get_method, self.response, 200),1096 (self.delete_method, 'error', None),1097 (self.log_method, 'exception', None)]1098 self._test_delete(delete_mock, fail=True)1099 def test_delete_pass(self):1100 delete_mock = [(self.get_method, self.response, 200),1101 (self.delete_method, None, 204),1102 (self.log_method, 'exception', None)]1103 self._test_delete(delete_mock)1104 def test_dry_run(self):1105 dry_mock = [(self.get_method, self.response, 200),1106 (self.delete_method, "delete", None)]1107 self._test_dry_run_true(dry_mock)1108 def test_save_state(self):1109 self._test_saved_state_true([(self.get_method, self.response, 200)])1110 def test_preserve_list(self):1111 self.response['subnets'].append(1112 {1113 "name": "public-subnet",1114 "network_id": cleanup_service.CONF_PUB_NETWORK,1115 "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",1116 "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",1117 "ip_version": 4,1118 "gateway_ip": "10.0.0.1",1119 "cidr": "10.0.0.0/24",1120 "id": "08eae331-0402-425a-923c-34f7cfe39c1b",1121 "created_at": "2018-10-10T14:35:34Z",1122 "service_types": [],1123 "tags": ["tag1,tag2"],1124 "updated_at": "2018-10-10T14:35:34Z"1125 })1126 self._test_is_preserve_true([(self.get_method, self.response, 200)])1127class TestNetworkSubnetPoolsService(BaseCmdServiceTests):1128 service_class = 'NetworkSubnetPoolsService'1129 service_name = 'subnetpools'1130 response = {1131 "subnetpools": [1132 {1133 "min_prefixlen": "64",1134 "default_prefixlen": "64",1135 "id": "03f761e6-eee0-43fc-a921-8acf64c14988",1136 "max_prefixlen": "64",1137 "name": "my-subnet-pool-ipv6",1138 "is_default": False,1139 "project_id": "9fadcee8aa7c40cdb2114fff7d569c08",1140 "tenant_id": "9fadcee8aa7c40cdb2114fff7d569c08",1141 "prefixes": [1142 "2001:db8:0:2::/64",1143 "2001:db8::/63"1144 ],1145 "ip_version": 6,1146 "shared": False,1147 "description": "",1148 "created_at": "2016-03-08T20:19:41",1149 "updated_at": "2016-03-08T20:19:41",1150 "revision_number": 2,1151 "tags": ["tag1,tag2"]1152 },1153 {1154 "id": "8acf64c1-43fc",1155 "name": "saved-subnet-pool"1156 }1157 ]1158 }1159 def test_delete_fail(self):1160 delete_mock = [(self.get_method, self.response, 200),1161 (self.delete_method, 'error', None),1162 (self.log_method, 'exception', None)]1163 self._test_delete(delete_mock, fail=True)1164 def test_delete_pass(self):1165 delete_mock = [(self.get_method, self.response, 200),1166 (self.delete_method, None, 204),1167 (self.log_method, 'exception', None)]1168 self._test_delete(delete_mock)1169 def test_dry_run(self):1170 dry_mock = [(self.get_method, self.response, 200),1171 (self.delete_method, "delete", None)]1172 self._test_dry_run_true(dry_mock)1173 def test_save_state(self):1174 self._test_saved_state_true([(self.get_method, self.response, 200)])1175 def test_preserve_list(self):1176 self.response['subnetpools'].append(1177 {1178 "min_prefixlen": "64",1179 "default_prefixlen": "64",1180 "id": "9acf64c1-43fc",1181 "name": "preserve-pool",1182 "project_id": cleanup_service.CONF_PROJECTS[0],1183 "created_at": "2016-03-08T20:19:41",1184 "updated_at": "2016-03-08T20:19:41"1185 })1186 self._test_is_preserve_true([(self.get_method, self.response, 200)])1187# begin global services1188class TestRegionService(BaseCmdServiceTests):1189 service_class = 'RegionService'1190 service_name = 'regions'1191 response = {1192 "regions": [{1193 "parent_region_id": None,1194 "id": "RegionOne",1195 "links": {1196 "self":1197 "http://10.0.145.61:5000/v3/regions/RegionOne"1198 },1199 "description": ""1200 },1201 {1202 "parent_region_id": None,1203 "id": "RegionTwo",1204 "links": {1205 "self":1206 "http://10.0.145.61:5000/v3/regions/RegionTwo"1207 },1208 "description": ""1209 }],1210 "links": {1211 "self":1212 "http://10.0.145.61:5000/v3/regions",1213 "next": None,1214 "previous": None1215 }1216 }1217 def test_delete_pass(self):1218 delete_mock = [(self.get_method, self.response, 200),1219 (self.delete_method, None, 204),1220 (self.log_method, "exception", None)]1221 self._test_delete(delete_mock)1222 def test_delete_fail(self):1223 delete_mock = [(self.get_method, self.response, 200),1224 (self.delete_method, 'error', None),1225 (self.log_method, "exception", None)]1226 self._test_delete(delete_mock, fail=True)1227 def test_dry_run(self):1228 dry_mock = [(self.get_method, self.response, 200),1229 (self.delete_method, "delete", None)]1230 self._test_dry_run_true(dry_mock)1231 def test_save_state(self):1232 self._test_saved_state_true([(self.get_method, self.response, 200)])1233class TestDomainService(BaseCmdServiceTests):1234 service_class = 'DomainService'1235 service_name = 'domains'1236 response = {1237 "domains": [1238 {1239 "description": "Destroy all humans",1240 "enabled": True,1241 "id": "5a75994a3",1242 "links": {1243 "self": "http://example.com/identity/v3/domains/5a75994a3"1244 },1245 "name": "Sky_net"1246 },1247 {1248 "description": "Owns users and tenants on Identity API",1249 "enabled": False,1250 "id": "default",1251 "links": {1252 "self": "http://example.com/identity/v3/domains/default"1253 },1254 "name": "Default"1255 }1256 ]1257 }1258 mock_update = ("tempest.lib.services.identity.v3."1259 "domains_client.DomainsClient.update_domain")1260 def test_delete_fail(self):1261 delete_mock = [(self.get_method, self.response, 200),1262 (self.delete_method, 'error', None),1263 (self.log_method, 'exception', None),1264 (self.mock_update, 'update', None)]1265 self._test_delete(delete_mock, fail=True)1266 def test_delete_pass(self):1267 delete_mock = [(self.get_method, self.response, 200),1268 (self.delete_method, None, 204),1269 (self.log_method, 'exception', None),1270 (self.mock_update, 'update', None)]1271 self._test_delete(delete_mock)1272 def test_dry_run(self):1273 dry_mock = [(self.get_method, self.response, 200),1274 (self.delete_method, "delete", None)]1275 self._test_dry_run_true(dry_mock)1276 def test_save_state(self):1277 self._test_saved_state_true([(self.get_method, self.response, 200)])1278class TestProjectsService(BaseCmdServiceTests):1279 service_class = 'ProjectService'1280 service_name = 'projects'1281 response = {1282 "projects": [1283 {1284 "is_domain": False,1285 "description": None,1286 "domain_id": "default",1287 "enabled": True,1288 "id": "f38ohgp93jj032",1289 "links": {1290 "self": "http://example.com/identity/v3/projects"1291 "/f38ohgp93jj032"1292 },1293 "name": "manhattan",1294 "parent_id": None1295 },1296 {1297 "is_domain": False,1298 "description": None,1299 "domain_id": "default",1300 "enabled": True,1301 "id": "098f89d3292ri4jf4",1302 "links": {1303 "self": "http://example.com/identity/v3/projects"1304 "/098f89d3292ri4jf4"1305 },1306 "name": "Apollo",1307 "parent_id": None1308 }1309 ]1310 }1311 def test_delete_fail(self):1312 delete_mock = [(self.get_method, self.response, 200),1313 (self.delete_method, 'error', None),1314 (self.log_method, 'exception', None)]1315 self._test_delete(delete_mock, fail=True)1316 def test_delete_pass(self):1317 delete_mock = [(self.get_method, self.response, 200),1318 (self.delete_method, None, 204),1319 (self.log_method, 'exception', None)]1320 self._test_delete(delete_mock)1321 def test_dry_run(self):1322 dry_mock = [(self.get_method, self.response, 200),1323 (self.delete_method, "delete", None)]1324 self._test_dry_run_true(dry_mock)1325 def test_save_state(self):1326 self._test_saved_state_true([(self.get_method, self.response, 200)])1327 def test_preserve_list(self):1328 self.response['projects'].append(1329 {1330 "is_domain": False,1331 "description": None,1332 "domain_id": "default",1333 "enabled": True,1334 "id": "r343q98h09f3092",1335 "links": {1336 "self": "http://example.com/identity/v3/projects"1337 "/r343q98h09f3092"1338 },1339 "name": cleanup_service.CONF_PROJECTS[0],1340 "parent_id": None1341 })1342 self._test_is_preserve_true([(self.get_method, self.response, 200)])1343class TestImagesService(BaseCmdServiceTests):1344 service_class = 'ImageService'1345 service_name = 'images'1346 response = {1347 "images": [1348 {1349 "status": "ACTIVE",1350 "name": "stratus-0.3.2-x86_64-disk",1351 "id": "34yhwr-4t3q",1352 "updated": "2014-11-03T16:40:10Z",1353 "links": [{1354 "href": "http://openstack.ex.com/v2/openstack/images/"1355 "34yhwr-4t3q",1356 "rel": "self"}],1357 "created": "2014-10-30T08:23:39Z",1358 "minDisk": 0,1359 "minRam": 0,1360 "progress": 0,1361 "metadata": {},1362 },1363 {1364 "status": "ACTIVE",1365 "name": "cirros-0.3.2-x86_64-disk",1366 "id": "1bea47ed-f6a9",1367 "updated": "2014-11-03T16:40:10Z",1368 "links": [{1369 "href": "http://openstack.ex.com/v2/openstack/images/"1370 "1bea47ed-f6a9",1371 "rel": "self"}],1372 "created": "2014-10-30T08:23:39Z",1373 "minDisk": 0,1374 "minRam": 0,1375 "progress": 0,1376 "metadata": {},1377 }1378 ]1379 }1380 def test_delete_fail(self):1381 delete_mock = [(self.get_method, self.response, 200),1382 (self.delete_method, 'error', None),1383 (self.log_method, 'exception', None)]1384 self._test_delete(delete_mock, fail=True)1385 def test_delete_pass(self):1386 delete_mock = [(self.get_method, self.response, 200),1387 (self.delete_method, None, 204),1388 (self.log_method, 'exception', None)]1389 self._test_delete(delete_mock)1390 def test_dry_run(self):1391 dry_mock = [(self.get_method, self.response, 200),1392 (self.delete_method, "delete", None)]1393 self._test_dry_run_true(dry_mock)1394 def test_save_state(self):1395 self._test_saved_state_true([(self.get_method, self.response, 200)])1396 def test_preserve_list(self):1397 self.response['images'].append(1398 {1399 "status": "ACTIVE",1400 "name": "cirros-0.3.2-x86_64-disk",1401 "id": cleanup_service.CONF_IMAGES[0],1402 "updated": "2014-11-03T16:40:10Z",1403 "links": [{1404 "href": "http://openstack.ex.com/v2/openstack/images/"1405 "None",1406 "rel": "self"}],1407 "created": "2014-10-30T08:23:39Z",1408 "minDisk": 0,1409 "minRam": 0,1410 "progress": 0,1411 "metadata": {},1412 })1413 self._test_is_preserve_true([(self.get_method, self.response, 200)])1414class TestFlavorService(BaseCmdServiceTests):1415 service_class = 'FlavorService'1416 service_name = 'flavors'1417 response = {1418 "flavors": [1419 {1420 "disk": 1,1421 "id": "42",1422 "links": [{1423 "href": "http://openstack.ex.com/v2/openstack/flavors/1",1424 "rel": "self"}, {1425 "href": "http://openstack.ex.com/openstack/flavors/1",1426 "rel": "bookmark"}],1427 "name": "m1.tiny",1428 "ram": 512,1429 "swap": 1,1430 "vcpus": 11431 },1432 {1433 "disk": 2,1434 "id": "13",1435 "links": [{1436 "href": "http://openstack.ex.com/v2/openstack/flavors/2",1437 "rel": "self"}, {1438 "href": "http://openstack.ex.com/openstack/flavors/2",1439 "rel": "bookmark"}],1440 "name": "m1.tiny",1441 "ram": 512,1442 "swap": 1,1443 "vcpus": 11444 }1445 ]1446 }1447 def test_delete_fail(self):1448 delete_mock = [(self.get_method, self.response, 200),1449 (self.delete_method, 'error', None),1450 (self.log_method, 'exception', None)]1451 self._test_delete(delete_mock, fail=True)1452 def test_delete_pass(self):1453 delete_mock = [(self.get_method, self.response, 200),1454 (self.delete_method, None, 202),1455 (self.log_method, 'exception', None)]1456 self._test_delete(delete_mock)1457 def test_dry_run(self):1458 dry_mock = [(self.get_method, self.response, 200),1459 (self.delete_method, "delete", None)]1460 self._test_dry_run_true(dry_mock)1461 def test_save_state(self):1462 self._test_saved_state_true([(self.get_method, self.response, 200)])1463 def test_preserve_list(self):1464 self.response['flavors'].append(1465 {1466 "disk": 3,1467 "id": cleanup_service.CONF_FLAVORS[0],1468 "links": [{1469 "href": "http://openstack.ex.com/v2/openstack/flavors/3",1470 "rel": "self"}, {1471 "href": "http://openstack.ex.com/openstack/flavors/3",1472 "rel": "bookmark"}],1473 "name": "m1.tiny",1474 "ram": 512,1475 "swap": 1,1476 "vcpus": 11477 })1478 self._test_is_preserve_true([(self.get_method, self.response, 200)])1479class TestRoleService(BaseCmdServiceTests):1480 service_class = 'RoleService'1481 service_name = 'roles'1482 response = {1483 "roles": [1484 {1485 "domain_id": "FakeDomain",1486 "id": "3efrt74r45hn",1487 "name": "president",1488 "links": {1489 "self": "http://ex.com/identity/v3/roles/3efrt74r45hn"1490 }1491 },1492 {1493 "domain_id": 'FakeDomain',1494 "id": "39ruo5sdk040",1495 "name": "vice-p",1496 "links": {1497 "self": "http://ex.com/identity/v3/roles/39ruo5sdk040"1498 }1499 }1500 ]1501 }1502 def test_delete_fail(self):1503 delete_mock = [(self.get_method, self.response, 200),1504 (self.delete_method, 'error', None),1505 (self.log_method, 'exception', None)]1506 self._test_delete(delete_mock, fail=True)1507 def test_delete_pass(self):1508 delete_mock = [(self.get_method, self.response, 200),1509 (self.delete_method, None, 204),1510 (self.log_method, 'exception', None)]1511 self._test_delete(delete_mock)1512 def test_dry_run(self):1513 dry_mock = [(self.get_method, self.response, 200),1514 (self.delete_method, "delete", None)]1515 self._test_dry_run_true(dry_mock)1516 def test_save_state(self):1517 self._test_saved_state_true([(self.get_method, self.response, 200)])1518class TestUserService(BaseCmdServiceTests):1519 service_class = 'UserService'1520 service_name = 'users'1521 response = {1522 "users": [1523 {1524 "domain_id": "TempestDomain",1525 "enabled": True,1526 "id": "e812fb332456423fdv1b1320121qwe2",1527 "links": {1528 "self": "http://example.com/identity/v3/users/"1529 "e812fb332456423fdv1b1320121qwe2",1530 },1531 "name": "Thunder",1532 "password_expires_at": "3102-11-06T15:32:17.000000",1533 },1534 {1535 "domain_id": "TempestDomain",1536 "enabled": True,1537 "id": "32rwef64245tgr20121qw324bgg",1538 "links": {1539 "self": "http://example.com/identity/v3/users/"1540 "32rwef64245tgr20121qw324bgg",1541 },1542 "name": "Lightning",1543 "password_expires_at": "1893-11-06T15:32:17.000000",1544 }1545 ]1546 }1547 def test_delete_fail(self):1548 delete_mock = [(self.get_method, self.response, 200),1549 (self.delete_method, 'error', None),1550 (self.log_method, 'exception', None)]1551 self._test_delete(delete_mock, fail=True)1552 def test_delete_pass(self):1553 delete_mock = [(self.get_method, self.response, 200),1554 (self.delete_method, None, 204),1555 (self.log_method, 'exception', None)]1556 self._test_delete(delete_mock)1557 def test_dry_run(self):1558 dry_mock = [(self.get_method, self.response, 200),1559 (self.delete_method, "delete", None)]1560 self._test_dry_run_true(dry_mock)1561 def test_save_state(self):1562 self._test_saved_state_true([(self.get_method, self.response, 200)])1563 def test_preserve_list(self):1564 self.response['users'].append(1565 {1566 "domain_id": "TempestDomain",1567 "enabled": True,1568 "id": "23ads5tg3rtrhe30121qwhyth",1569 "links": {1570 "self": "http://example.com/identity/v3/users/"1571 "23ads5tg3rtrhe30121qwhyth",1572 },1573 "name": cleanup_service.CONF_USERS[0],1574 "password_expires_at": "1893-11-06T15:32:17.000000",1575 })...
testrunnerstep.py
Source:testrunnerstep.py
...27 def location_id_method(unused_label):28 return LOCATION_ID29 def setUp(self):30 self.arch = Archivist("url", "authauthauth")31 def test_runner_step_with_delete_method(self):32 """33 Test runner step34 """35 step = _Step(36 self.arch,37 **{38 "action": "COMPLIANCE_POLICIES_CREATE",39 "wait_time": 10,40 "print_response": True,41 "description": "Testing runner events list",42 "asset_label": "Existing Asset",43 "delete": True,44 }45 )...
test_tasks_delete.py
Source:test_tasks_delete.py
1import behave2@behave.when(u'I delete task by "{delete_method}"')3def step_impl(context, delete_method):4 if delete_method == 'name':5 context.task_get = context.project.tasks.delete(task_name=context.task.name)6 elif delete_method == 'id':7 context.task_get = context.project.tasks.delete(task_id=context.task.id)8 elif delete_method == 'object':9 context.task_get = context.project.tasks.delete(task=context.task)10@behave.then(u'Task has been deleted')11def step_impl(context):12 try:13 context.project.tasks.get(taks_id=context.task.id)14 assert False15 except Exception:...
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!!