From 8ad924b6ad7013e229776326058b5a25d0fb3ccd Mon Sep 17 00:00:00 2001 From: David Kranz Date: Fri, 16 Jan 2015 16:50:18 -0500 Subject: [PATCH] Change orchestration client to return one value and update tests Partially implements: blueprint clients-return-one-value Change-Id: I2be81f2b3776d54476f46fad5b79c3366d3bb489 --- tempest/api/orchestration/base.py | 8 +-- .../stacks/test_neutron_resources.py | 6 +- .../stacks/test_non_empty_stack.py | 24 ++++---- .../stacks/test_nova_keypair_resources.py | 4 +- .../api/orchestration/stacks/test_stacks.py | 10 ++-- .../stacks/test_swift_resources.py | 2 +- .../orchestration/stacks/test_templates.py | 6 +- tempest/cmd/cleanup_service.py | 2 +- .../orchestration/test_server_cfn_init.py | 8 +-- .../json/orchestration_client.py | 56 ++++++++++--------- 10 files changed, 64 insertions(+), 62 deletions(-) diff --git a/tempest/api/orchestration/base.py b/tempest/api/orchestration/base.py index 21f2578208..d3dffbfc76 100644 --- a/tempest/api/orchestration/base.py +++ b/tempest/api/orchestration/base.py @@ -68,13 +68,13 @@ class BaseOrchestrationTest(tempest.test.BaseTestCase): environment=None, files=None): if parameters is None: parameters = {} - resp, body = cls.client.create_stack( + body = cls.client.create_stack( stack_name, template=template_data, parameters=parameters, environment=environment, files=files) - stack_id = resp['location'].split('/')[-1] + stack_id = body.response['location'].split('/')[-1] stack_identifier = '%s/%s' % (stack_name, stack_id) cls.stacks.append(stack_identifier) return stack_identifier @@ -164,7 +164,7 @@ class BaseOrchestrationTest(tempest.test.BaseTestCase): def list_resources(self, stack_identifier): """Get a dict mapping of resource names to types.""" - _, resources = self.client.list_resources(stack_identifier) + resources = self.client.list_resources(stack_identifier) self.assertIsInstance(resources, list) for res in resources: self.assert_fields_in_dict(res, 'logical_resource_id', @@ -175,5 +175,5 @@ class BaseOrchestrationTest(tempest.test.BaseTestCase): for r in resources) def get_stack_output(self, stack_identifier, output_key): - _, body = self.client.get_stack(stack_identifier) + body = self.client.get_stack(stack_identifier) return self.stack_output(body, output_key) diff --git a/tempest/api/orchestration/stacks/test_neutron_resources.py b/tempest/api/orchestration/stacks/test_neutron_resources.py index 835271987a..ea6d4beeaa 100644 --- a/tempest/api/orchestration/stacks/test_neutron_resources.py +++ b/tempest/api/orchestration/stacks/test_neutron_resources.py @@ -65,14 +65,14 @@ class NeutronResourcesTestJSON(base.BaseOrchestrationTest): cls.stack_id = cls.stack_identifier.split('/')[1] try: cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE') - _, resources = cls.client.list_resources(cls.stack_identifier) + resources = cls.client.list_resources(cls.stack_identifier) except exceptions.TimeoutException as e: if CONF.compute_feature_enabled.console_output: # attempt to log the server console to help with debugging # the cause of the server not signalling the waitcondition # to heat. - _, body = cls.client.get_resource(cls.stack_identifier, - 'Server') + body = cls.client.get_resource(cls.stack_identifier, + 'Server') server_id = body['physical_resource_id'] LOG.debug('Console output for %s', server_id) _, output = cls.servers_client.get_console_output( diff --git a/tempest/api/orchestration/stacks/test_non_empty_stack.py b/tempest/api/orchestration/stacks/test_non_empty_stack.py index bf6c79c4d8..db1ac9adeb 100644 --- a/tempest/api/orchestration/stacks/test_non_empty_stack.py +++ b/tempest/api/orchestration/stacks/test_non_empty_stack.py @@ -47,7 +47,7 @@ class StacksTestJSON(base.BaseOrchestrationTest): cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE') def _list_stacks(self, expected_num=None, **filter_kwargs): - _, stacks = self.client.list_stacks(params=filter_kwargs) + stacks = self.client.list_stacks(params=filter_kwargs) self.assertIsInstance(stacks, list) if expected_num is not None: self.assertEqual(expected_num, len(stacks)) @@ -63,7 +63,7 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_stack_show(self): """Getting details about created stack should be possible.""" - _, stack = self.client.get_stack(self.stack_name) + stack = self.client.get_stack(self.stack_name) self.assertIsInstance(stack, dict) self.assert_fields_in_dict(stack, 'stack_name', 'id', 'links', 'parameters', 'outputs', 'disable_rollback', @@ -82,10 +82,10 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_suspend_resume_stack(self): """Suspend and resume a stack.""" - _, suspend_stack = self.client.suspend_stack(self.stack_identifier) + self.client.suspend_stack(self.stack_identifier) self.client.wait_for_stack_status(self.stack_identifier, 'SUSPEND_COMPLETE') - _, resume_stack = self.client.resume_stack(self.stack_identifier) + self.client.resume_stack(self.stack_identifier) self.client.wait_for_stack_status(self.stack_identifier, 'RESUME_COMPLETE') @@ -99,8 +99,8 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_show_resource(self): """Getting details about created resource should be possible.""" - _, resource = self.client.get_resource(self.stack_identifier, - self.resource_name) + resource = self.client.get_resource(self.stack_identifier, + self.resource_name) self.assertIsInstance(resource, dict) self.assert_fields_in_dict(resource, 'resource_name', 'description', 'links', 'logical_resource_id', @@ -113,7 +113,7 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_resource_metadata(self): """Getting metadata for created resources should be possible.""" - _, metadata = self.client.show_resource_metadata( + metadata = self.client.show_resource_metadata( self.stack_identifier, self.resource_name) self.assertIsInstance(metadata, dict) @@ -122,7 +122,7 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_list_events(self): """Getting list of created events for the stack should be possible.""" - _, events = self.client.list_events(self.stack_identifier) + events = self.client.list_events(self.stack_identifier) self.assertIsInstance(events, list) for event in events: @@ -137,13 +137,13 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='gate') def test_show_event(self): """Getting details about an event should be possible.""" - _, events = self.client.list_resource_events(self.stack_identifier, - self.resource_name) + events = self.client.list_resource_events(self.stack_identifier, + self.resource_name) self.assertNotEqual([], events) events.sort(key=lambda event: event['event_time']) event_id = events[0]['id'] - _, event = self.client.show_event(self.stack_identifier, - self.resource_name, event_id) + event = self.client.show_event(self.stack_identifier, + self.resource_name, event_id) self.assertIsInstance(event, dict) self.assert_fields_in_dict(event, 'resource_name', 'event_time', 'links', 'logical_resource_id', diff --git a/tempest/api/orchestration/stacks/test_nova_keypair_resources.py b/tempest/api/orchestration/stacks/test_nova_keypair_resources.py index 1da340ca8f..772bab395f 100644 --- a/tempest/api/orchestration/stacks/test_nova_keypair_resources.py +++ b/tempest/api/orchestration/stacks/test_nova_keypair_resources.py @@ -43,7 +43,7 @@ class NovaKeyPairResourcesYAMLTest(base.BaseOrchestrationTest): cls.stack_id = cls.stack_identifier.split('/')[1] cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE') - _, resources = cls.client.list_resources(cls.stack_identifier) + resources = cls.client.list_resources(cls.stack_identifier) cls.test_resources = {} for resource in resources: cls.test_resources[resource['logical_resource_id']] = resource @@ -70,7 +70,7 @@ class NovaKeyPairResourcesYAMLTest(base.BaseOrchestrationTest): @test.attr(type='gate') def test_stack_keypairs_output(self): - _, stack = self.client.get_stack(self.stack_name) + stack = self.client.get_stack(self.stack_name) self.assertIsInstance(stack, dict) output_map = {} diff --git a/tempest/api/orchestration/stacks/test_stacks.py b/tempest/api/orchestration/stacks/test_stacks.py index d7fbd6539b..5cdd8b4f47 100644 --- a/tempest/api/orchestration/stacks/test_stacks.py +++ b/tempest/api/orchestration/stacks/test_stacks.py @@ -28,7 +28,7 @@ class StacksTestJSON(base.BaseOrchestrationTest): @test.attr(type='smoke') def test_stack_list_responds(self): - _, stacks = self.client.list_stacks() + stacks = self.client.list_stacks() self.assertIsInstance(stacks, list) @test.attr(type='smoke') @@ -44,20 +44,20 @@ class StacksTestJSON(base.BaseOrchestrationTest): self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') # check for stack in list - _, stacks = self.client.list_stacks() + stacks = self.client.list_stacks() list_ids = list([stack['id'] for stack in stacks]) self.assertIn(stack_id, list_ids) # fetch the stack - _, stack = self.client.get_stack(stack_identifier) + stack = self.client.get_stack(stack_identifier) self.assertEqual('CREATE_COMPLETE', stack['stack_status']) # fetch the stack by name - _, stack = self.client.get_stack(stack_name) + stack = self.client.get_stack(stack_name) self.assertEqual('CREATE_COMPLETE', stack['stack_status']) # fetch the stack by id - _, stack = self.client.get_stack(stack_id) + stack = self.client.get_stack(stack_id) self.assertEqual('CREATE_COMPLETE', stack['stack_status']) # delete the stack diff --git a/tempest/api/orchestration/stacks/test_swift_resources.py b/tempest/api/orchestration/stacks/test_swift_resources.py index 307468e755..0288fd49b8 100644 --- a/tempest/api/orchestration/stacks/test_swift_resources.py +++ b/tempest/api/orchestration/stacks/test_swift_resources.py @@ -42,7 +42,7 @@ class SwiftResourcesTestJSON(base.BaseOrchestrationTest): cls.stack_id = cls.stack_identifier.split('/')[1] cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE') cls.test_resources = {} - _, resources = cls.client.list_resources(cls.stack_identifier) + resources = cls.client.list_resources(cls.stack_identifier) for resource in resources: cls.test_resources[resource['logical_resource_id']] = resource diff --git a/tempest/api/orchestration/stacks/test_templates.py b/tempest/api/orchestration/stacks/test_templates.py index 262c57645f..6113cab334 100644 --- a/tempest/api/orchestration/stacks/test_templates.py +++ b/tempest/api/orchestration/stacks/test_templates.py @@ -38,13 +38,13 @@ Resources: @test.attr(type='gate') def test_show_template(self): """Getting template used to create the stack.""" - _, template = self.client.show_template(self.stack_identifier) + self.client.show_template(self.stack_identifier) @test.attr(type='gate') def test_validate_template(self): """Validating template passing it content.""" - _, parameters = self.client.validate_template(self.template, - self.parameters) + self.client.validate_template(self.template, + self.parameters) class TemplateAWSTestJSON(TemplateYAMLTestJSON): diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py index 2928777b5f..a0bbb700b2 100644 --- a/tempest/cmd/cleanup_service.py +++ b/tempest/cmd/cleanup_service.py @@ -218,7 +218,7 @@ class StackService(BaseService): def list(self): client = self.client - _, stacks = client.list_stacks() + stacks = client.list_stacks() LOG.debug("List count, %s Stacks" % len(stacks)) return stacks diff --git a/tempest/scenario/orchestration/test_server_cfn_init.py b/tempest/scenario/orchestration/test_server_cfn_init.py index f09f00c05a..18b759e1c8 100644 --- a/tempest/scenario/orchestration/test_server_cfn_init.py +++ b/tempest/scenario/orchestration/test_server_cfn_init.py @@ -52,13 +52,13 @@ class CfnInitScenarioTest(manager.OrchestrationScenarioTest): # create the stack self.template = self._load_template(__file__, self.template_name) - _, stack = self.client.create_stack( + stack = self.client.create_stack( name=self.stack_name, template=self.template, parameters=self.parameters) stack = stack['stack'] - _, self.stack = self.client.get_stack(stack['id']) + self.stack = self.client.get_stack(stack['id']) self.stack_identifier = '%s/%s' % (self.stack_name, self.stack['id']) self.addCleanup(self.delete_wrapper, self.orchestration_client.delete_stack, @@ -77,7 +77,7 @@ class CfnInitScenarioTest(manager.OrchestrationScenarioTest): self.client.wait_for_resource_status( sid, 'SmokeServer', 'CREATE_COMPLETE') - _, server_resource = self.client.get_resource(sid, 'SmokeServer') + server_resource = self.client.get_resource(sid, 'SmokeServer') server_id = server_resource['physical_resource_id'] _, server = self.servers_client.get_server(server_id) server_ip =\ @@ -104,7 +104,7 @@ class CfnInitScenarioTest(manager.OrchestrationScenarioTest): self.client.wait_for_stack_status(sid, 'CREATE_COMPLETE') - _, stack = self.client.get_stack(sid) + stack = self.client.get_stack(sid) # This is an assert of great significance, as it means the following # has happened: diff --git a/tempest/services/orchestration/json/orchestration_client.py b/tempest/services/orchestration/json/orchestration_client.py index d23d934d12..55741986f2 100644 --- a/tempest/services/orchestration/json/orchestration_client.py +++ b/tempest/services/orchestration/json/orchestration_client.py @@ -46,7 +46,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['stacks'] + return service_client.ResponseBodyList(resp, body['stacks']) def create_stack(self, name, disable_rollback=True, parameters=None, timeout_mins=60, template=None, template_url=None, @@ -66,7 +66,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.post(uri, headers=headers, body=body) self.expected_success(201, resp.status) body = json.loads(body) - return resp, body + return service_client.ResponseBody(resp, body) def update_stack(self, stack_identifier, name, disable_rollback=True, parameters=None, timeout_mins=60, template=None, @@ -85,7 +85,7 @@ class OrchestrationClient(service_client.ServiceClient): uri = "stacks/%s" % stack_identifier resp, body = self.put(uri, headers=headers, body=body) self.expected_success(202, resp.status) - return resp, body + return service_client.ResponseBody(resp, body) def _prepare_update_create(self, name, disable_rollback=True, parameters=None, timeout_mins=60, @@ -121,7 +121,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['stack'] + return service_client.ResponseBody(resp, body['stack']) def suspend_stack(self, stack_identifier): """Suspend a stack.""" @@ -129,7 +129,7 @@ class OrchestrationClient(service_client.ServiceClient): body = {'suspend': None} resp, body = self.post(url, json.dumps(body)) self.expected_success(200, resp.status) - return resp, body + return service_client.ResponseBody(resp) def resume_stack(self, stack_identifier): """Resume a stack.""" @@ -137,7 +137,7 @@ class OrchestrationClient(service_client.ServiceClient): body = {'resume': None} resp, body = self.post(url, json.dumps(body)) self.expected_success(200, resp.status) - return resp, body + return service_client.ResponseBody(resp) def list_resources(self, stack_identifier): """Returns the details of a single resource.""" @@ -145,7 +145,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['resources'] + return service_client.ResponseBodyList(resp, body['resources']) def get_resource(self, stack_identifier, resource_name): """Returns the details of a single resource.""" @@ -153,13 +153,13 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['resource'] + return service_client.ResponseBody(resp, body['resource']) def delete_stack(self, stack_identifier): """Deletes the specified Stack.""" resp, _ = self.delete("stacks/%s" % str(stack_identifier)) self.expected_success(204, resp.status) - return resp + return service_client.ResponseBody(resp) def wait_for_resource_status(self, stack_identifier, resource_name, status, failure_pattern='^.*_FAILED$'): @@ -169,7 +169,7 @@ class OrchestrationClient(service_client.ServiceClient): while True: try: - resp, body = self.get_resource( + body = self.get_resource( stack_identifier, resource_name) except exceptions.NotFound: # ignore this, as the resource may not have @@ -205,7 +205,7 @@ class OrchestrationClient(service_client.ServiceClient): while True: try: - resp, body = self.get_stack(stack_identifier) + body = self.get_stack(stack_identifier) except exceptions.NotFound: if status == 'DELETE_COMPLETE': return @@ -234,7 +234,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['metadata'] + return service_client.ResponseBody(resp, body['metadata']) def list_events(self, stack_identifier): """Returns list of all events for a stack.""" @@ -242,7 +242,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['events'] + return service_client.ResponseBodyList(resp, body['events']) def list_resource_events(self, stack_identifier, resource_name): """Returns list of all events for a resource from stack.""" @@ -251,7 +251,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['events'] + return service_client.ResponseBodyList(resp, body['events']) def show_event(self, stack_identifier, resource_name, event_id): """Returns the details of a single stack's event.""" @@ -260,7 +260,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body['event'] + return service_client.ResponseBody(resp, body['event']) def show_template(self, stack_identifier): """Returns the template for the stack.""" @@ -268,7 +268,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body + return service_client.ResponseBody(resp, body) def _validate_template(self, post_body): """Returns the validation request result.""" @@ -276,7 +276,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.post('validate', post_body) self.expected_success(200, resp.status) body = json.loads(body) - return resp, body + return service_client.ResponseBody(resp, body) def validate_template(self, template, parameters=None): """Returns the validation result for a template with parameters.""" @@ -303,21 +303,21 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get('resource_types') self.expected_success(200, resp.status) body = json.loads(body) - return body['resource_types'] + return service_client.ResponseBodyList(resp, body['resource_types']) def get_resource_type(self, resource_type_name): """Return the schema of a resource type.""" url = 'resource_types/%s' % resource_type_name resp, body = self.get(url) self.expected_success(200, resp.status) - return json.loads(body) + return service_client.ResponseBody(resp, json.loads(body)) def get_resource_type_template(self, resource_type_name): """Return the template of a resource type.""" url = 'resource_types/%s/template' % resource_type_name resp, body = self.get(url) self.expected_success(200, resp.status) - return json.loads(body) + return service_client.ResponseBody(resp, json.loads(body)) def create_software_config(self, name=None, config=None, group=None, inputs=None, outputs=None, options=None): @@ -328,7 +328,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.post(url, headers=headers, body=body) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def get_software_config(self, conf_id): """Returns a software configuration resource.""" @@ -336,13 +336,14 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def delete_software_config(self, conf_id): """Deletes a specific software configuration.""" url = 'software_configs/%s' % str(conf_id) resp, _ = self.delete(url) self.expected_success(204, resp.status) + return service_client.ResponseBody(resp) def create_software_deploy(self, server_id=None, config_id=None, action=None, status=None, @@ -357,7 +358,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.post(url, headers=headers, body=body) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def update_software_deploy(self, deploy_id=None, server_id=None, config_id=None, action=None, status=None, @@ -372,7 +373,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.put(url, headers=headers, body=body) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def get_software_deploy_list(self): """Returns a list of all deployments.""" @@ -380,7 +381,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def get_software_deploy(self, deploy_id): """Returns a specific software deployment.""" @@ -388,7 +389,7 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def get_software_deploy_meta(self, server_id): """Return a config metadata for a specific server.""" @@ -396,13 +397,14 @@ class OrchestrationClient(service_client.ServiceClient): resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) - return body + return service_client.ResponseBody(resp, body) def delete_software_deploy(self, deploy_id): """Deletes a specific software deployment.""" url = 'software_deployments/%s' % str(deploy_id) resp, _ = self.delete(url) self.expected_success(204, resp.status) + return service_client.ResponseBody(resp) def _prep_software_config_create(self, name=None, conf=None, group=None, inputs=None, outputs=None, options=None):