def test_create_camp_assembly(self): """Test creating a CAMP assembly from a local plan resource. Creates a plan resource then uses that to create an assembly resource. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=test_plans.sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'][len(self.client.base_url):]) ref_obj = json.dumps({'plan_uri': uri}) resp, body = self.client.post( 'camp/v1_1/assemblies', ref_obj, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 201) assem_resp = base.SolumResponse(resp=resp, body=body, body_type='json') uuid = assem_resp.uuid if uuid is not None: # share the Solum client's list of created assemblies self.client.created_assemblies.append(uuid)
def test_formats(self): """Tests normative statement RE-42 from the CAMP v1.1 specification: http://docs.oasis-open.org/camp/camp-spec/v1.1/csprd02/ camp-spec-v1.1-csprd02.pdf """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') resp, body = self.client.get('camp/v1_1/formats/') self.assertEqual(200, resp.status, 'GET formats resource') formats = json.loads(body) self.assertEqual('formats', formats['type']) self.assertEqual('Solum_CAMP_formats', formats['name']) format_links = formats['format_links'] # there should be one element in the Link array self.assertEqual(1, len(format_links), 'RE-42') json_link = format_links[0] self.assertEqual('JSON', json_link['target_name']) # get the URL of the platform_endpoint and strip the base URL url = json_link['href'][len(self.client.base_url) + 1:] # get our lone platform_endpoint resource resp, body = self.client.get(url) self.assertEqual(200, resp.status, 'GET JSON format resource') formatr = json.loads(body) self.assertEqual('format', formatr['type']) self.assertEqual('JSON', formatr['name'], 'RE-42') self.assertEqual('application/json', formatr['mime_type'], 'RE-42') self.assertEqual('RFC4627', formatr['version'], 'RE-42') self.assertEqual('http://www.ietf.org/rfc/rfc4627.txt', formatr['documentation'], 'RE-42')
def test_get_solum_plan(self): """Test the CAMP plans resource. Test that an plan resource created through the Solum API is visible via the CAMP API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using Solum p_resp = self.client.create_plan() self.assertEqual(201, p_resp.status) # get the CAMP plans resource resp, body = self.client.get('camp/v1_1/plans') self.assertEqual(200, resp.status, 'GET plans resource') plans_dct = json.loads(body) plan_links = plans_dct['plan_links'] self.assertEqual(1, len(plan_links)) p_link = plan_links[0] url = p_link['href'][len(self.client.base_url) + 1:] msg = ("GET Solum plan resource for %s" % p_link['target_name']) resp, body = self.client.get(url, headers={'content-type': 'application/x-yaml'}) self.assertEqual(200, resp.status, msg) # Solum plans are rendered in YAML plan = yamlutils.load(body) self.assertEqual(base.plan_sample_data['name'], plan['name']) self.assertEqual(base.plan_sample_data['description'], plan['description'])
def test_delete_plan_with_assemblies(self): """Test deleting a plan that has assemblies associated with it. Creates a plan, an assembly, then tries to delete the plan. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=test_plans.sample_data) self.assertEqual(resp.status, 201) plan_uri = (resp.data['uri'][len(self.client.base_url):]) ref_obj = json.dumps({'plan_uri': plan_uri}) resp, body = self.client.post( 'camp/v1_1/assemblies', ref_obj, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 201) assem_resp = base.SolumResponse(resp=resp, body=body, body_type='json') uuid = assem_resp.uuid if uuid is not None: # share the Solum client's list of created assemblies self.client.created_assemblies.append(uuid) # try to delete the plan before deleting the assembly # resp, body = self.client.delete(plan_uri[1:]) # self.assertEqual(409, resp.status) self.assertRaises(tempest_exceptions.Conflict, self.client.delete, plan_uri[1:])
def test_patch_plan(self): """PATCH a CAMP plan. Test the ability to modify a CAMP plan using the HTTP PATCH method with a JSON Patch request. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'] [len(self.client.base_url) + 1:]) patch_data = [ {"op": "add", "path": "/tags", "value": ["foo", "baz"]} ] patch_json = json.dumps(patch_data) resp, body = self.client.patch( uri, patch_json, headers={'content-type': 'application/json-patch+json'}) self.assertEqual(resp.status, 200) json_data = json.loads(body) self.assertIn('tags', json_data) tags = json_data['tags'] self.assertEqual(2, len(tags)) self.assertEqual('foo', tags[0]) self.assertEqual('baz', tags[1])
def test_get_solum_assembly(self): """Test the CAMP assemblies collection resource. Test that an assembly resource created through the Solum API is visible via the CAMP API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create an assembly using Solum p_resp = self.client.create_plan() self.assertEqual(201, p_resp.status) a_resp = self.client.create_assembly(plan_uuid=p_resp.uuid) self.assertEqual(201, a_resp.status) # get the CAMP assemblies resource resp, body = self.client.get('camp/v1_1/assemblies') self.assertEqual(200, resp.status, 'GET assemblies resource') assemblies_dct = json.loads(body) assem_links = assemblies_dct['assembly_links'] self.assertEqual(1, len(assem_links)) a_link = assem_links[0] url = a_link['href'][len(self.client.base_url) + 1:] msg = ("GET Solum assembly resource for %s" % a_link['target_name']) resp, body = self.client.get(url) self.assertEqual(200, resp.status, msg) # right now, this looks like a Solum assembly, not a CAMP assembly = json.loads(body) self.assertEqual('assembly', assembly['type']) self.assertEqual(base.assembly_sample_data['name'], assembly['name'])
def test_create_camp_assembly(self): """Test creating a CAMP assembly from a local plan resource. Creates a plan resource then uses that to create an assembly resource. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=test_plans.sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'] [len(self.client.base_url):]) ref_obj = json.dumps({'plan_uri': uri}) resp, body = self.client.post( 'camp/v1_1/assemblies', ref_obj, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 201) assem_resp = base.SolumResponse(resp=resp, body=body, body_type='json') uuid = assem_resp.uuid if uuid is not None: # share the Solum client's list of created assemblies self.client.created_assemblies.append(uuid)
def test_patch_plan(self): """PATCH a CAMP plan. Test the ability to modify a CAMP plan using the HTTP PATCH method with a JSON Patch request. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'][len(self.client.base_url) + 1:]) patch_data = [{"op": "add", "path": "/tags", "value": ["foo", "baz"]}] patch_json = json.dumps(patch_data) resp, body = self.client.patch( uri, patch_json, headers={'content-type': 'application/json-patch+json'}) self.assertEqual(resp.status, 200) json_data = json.loads(body) self.assertIn('tags', json_data) tags = json_data['tags'] self.assertEqual(2, len(tags)) self.assertEqual('foo', tags[0]) self.assertEqual('baz', tags[1])
def test_get_root_discovers_camp_v1_1(self): if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # get our platform_endpoints container resp, body = (self.client. request_without_auth('camp/platform_endpoints/', 'GET')) self.assertEqual(200, resp.status) endpoints = json.loads(body) self.assertEqual('platform_endpoints', endpoints['type']) self.assertEqual('Solum_CAMP_endpoints', endpoints['name']) pe_links = endpoints['platform_endpoint_links'] # there should be one element in the Link array self.assertEqual(1, len(pe_links)) camp_v1_1_link = pe_links[0] self.assertEqual('Solum_CAMP_v1_1_endpoint', camp_v1_1_link['target_name']) # get the URL of the platform_endpoint and strip the base URL rel_ep_url = camp_v1_1_link['href'][len(self.client.base_url) + 1:] # get our lone platform_endpoint resource resp, body = (self.client. request_without_auth(rel_ep_url, 'GET')) self.assertEqual(200, resp.status) endpoint = json.loads(body) self.assertEqual('platform_endpoint', endpoint['type']) self.assertEqual('Solum_CAMP_v1_1_endpoint', endpoint['name']) self.assertEqual('CAMP 1.1', endpoint['specification_version']) self.assertEqual('Solum CAMP 1.1', endpoint['implementation_version']) self.assertEqual('KEYSTONE-2.0', endpoint['auth_scheme']) self.assertEqual('%s/camp/v1_1/platform/' % self.client.base_url, endpoint['platform_uri'])
def test_type_definitions(self): """Test the CAMP type_definition metadata. Crawls tree rooted in type_definitions and verifies that all the resources exist and that all the links to the attribute_definition resources are valid and the attribute_definitions resources exist. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') resp, body = self.client.get('camp/v1_1/type_definitions') self.assertEqual(200, resp.status, 'GET type_definitions resource') defs_dct = json.loads(body) for link_dct in defs_dct['type_definition_links']: msg = ("GET type_definition resource for %s" % link_dct['target_name']) body = self._test_get_resource(link_dct['href'], msg, 'type_definition', link_dct['target_name']) def_dct = json.loads(body) for adl_dct in def_dct['attribute_definition_links']: msg = ("GET attribute_definition resource for %s" % link_dct['target_name']) self._test_get_resource(adl_dct['href'], msg, 'attribute_definition', adl_dct['target_name'])
def test_get_root_discovers_camp_v1_1(self): if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # get our platform_endpoints container resp, body = (self.client.request_without_auth( 'camp/platform_endpoints', 'GET')) self.assertEqual(200, resp.status) endpoints = json.loads(body) self.assertEqual('platform_endpoints', endpoints['type']) self.assertEqual('Solum_CAMP_endpoints', endpoints['name']) pe_links = endpoints['platform_endpoint_links'] # there should be one element in the Link array self.assertEqual(1, len(pe_links)) camp_v1_1_link = pe_links[0] self.assertEqual('Solum_CAMP_v1_1_endpoint', camp_v1_1_link['target_name']) # get the URL of the platform_endpoint and strip the base URL rel_ep_url = camp_v1_1_link['href'][len(self.client.base_url) + 1:] # get our lone platform_endpoint resource resp, body = (self.client.request_without_auth(rel_ep_url, 'GET')) self.assertEqual(200, resp.status) endpoint = json.loads(body) self.assertEqual('platform_endpoint', endpoint['type']) self.assertEqual('Solum_CAMP_v1_1_endpoint', endpoint['name']) self.assertEqual('CAMP 1.1', endpoint['specification_version']) self.assertEqual('Solum CAMP 1.1', endpoint['implementation_version']) self.assertEqual('KEYSTONE-2.0', endpoint['auth_scheme']) self.assertEqual('%s/camp/v1_1/platform' % self.client.base_url, endpoint['platform_uri'])
def _test_get_resource(self, url, rtype, name): if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') resp, body = self.client.get(url) self.assertEqual(200, resp.status, 'GET %s resource' % rtype) resource = json.loads(body) self.assertEqual(rtype, resource['type']) self.assertEqual(name, resource['name'])
def test_delete_no_plan(self): """Try to DELTE a plan that doesn't exist Test the ability of CAMP to respond with an HTTP 404 when the client tries to DELETE a plan that doesn' exist """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') self.assertRaises(tempest_exceptions.NotFound, self.client.delete, 'camp/v1_1/plans/no_plan')
def test_get_no_plan(self): """Try to GET a CAMP plan that doesn't exist Test the CAMP API's ability to respond with an HTTP 404 when doing a GET on a non-existent plan. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') self.assertRaises(tempest_exceptions.NotFound, self.client.get, 'camp/v1_1/plans/no_plan')
def test_create_invalid_yaml(self): """Try to create a CAMP plan from invalid YAML Test that an attempt to create a plan using an invalid document results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') self.assertRaises(tempest_exceptions.BadRequest, self.client.post, 'camp/v1_1/plans', 'invalid type', headers={'content-type': 'application/x-yaml'})
def test_create_bad_content_type(self): """Try to create a CAMP plan with a bogus Content-Type Test that an attempt to create a plan with an incorrect Content-Type header results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') yaml_data = yaml.dump(sample_data) self.assertRaises(tempest_exceptions.InvalidContentType, self.client.post, 'camp/v1_1/plans', yaml_data, headers={'content-type': 'image/jpeg'})
def test_create_camp_plan_with_private_github_repo(self): """Test CAMP support for private git repos Test that CAMP support the Solum private github case. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # copy the Solum test data and add a camp_version camp_data = copy.copy(solum_tests.sample_data_private) camp_data['camp_version'] = 'CAMP 1.1' resp = self._create_camp_plan(data=camp_data) self.assertEqual(resp.status, 201) self._assert_output_expected(resp.data, camp_data)
def test_get_platform_and_containers(self): if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # get and test our platform resource resp, body = self.client.get('camp/v1_1/platform/') self.assertEqual(200, resp.status, 'GET platform resource') platform = json.loads(body) self.assertEqual('platform', platform['type']) self.assertEqual('Solum_CAMP_v1_1_platform', platform['name']) self.assertEqual('CAMP 1.1', platform['specification_version']) self.assertEqual('Solum CAMP 1.1', platform['implementation_version']) # get and test the supported formats resource url = (platform['supported_formats_uri'] [len(self.client.base_url) + 1:]) self._test_get_resource(url, 'formats', 'Solum_CAMP_formats') # get and test the extensions resource url = (platform['extensions_uri'] [len(self.client.base_url) + 1:]) self._test_get_resource(url, 'extensions', 'Solum_CAMP_extensions') # get and test the type_definitions resource url = (platform['type_definitions_uri'] [len(self.client.base_url) + 1:]) self._test_get_resource(url, 'type_definitions', 'Solum_CAMP_type_definitions') # get and test the platform_endpoints resource url = (platform['platform_endpoints_uri'] [len(self.client.base_url) + 1:]) self._test_get_resource(url, 'platform_endpoints', 'Solum_CAMP_endpoints') # get and test the assemblies collection resource url = platform['assemblies_uri'][len(self.client.base_url) + 1:] self._test_get_resource(url, 'assemblies', 'Solum_CAMP_assemblies') # get and test the services collection resource url = platform['services_uri'][len(self.client.base_url) + 1:] self._test_get_resource(url, 'services', 'Solum_CAMP_services') # get and test the plans collection resource url = platform['plans_uri'][len(self.client.base_url) + 1:] self._test_get_resource(url, 'plans', 'Solum_CAMP_plans')
def test_get_solum_plan(self): """Test the visibility of Solum-created plans Test that an plan resource created through the Solum API is visible via the CAMP API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using Solum p_resp = self.client.create_plan() self.assertEqual(201, p_resp.status) new_plan = p_resp.yaml_data new_uuid = new_plan['uuid'] # try to get to the newly plan created through the CAMP plans # resource. it would be more efficient to simply take the UUID of the # newly created resource and create a CAMP API URI # (../camp/v1_1/plans/<uuid>) from that, but we want to test that a # link to the Solum-created plan appears in in the list of links in # the CAMP plans resource. resp, body = self.client.get('camp/v1_1/plans') self.assertEqual(200, resp.status, 'GET plans resource') # pick out the plan link for our new plan uuid plans_dct = json.loads(body) camp_link = None for link in plans_dct['plan_links']: link_uuid = link['href'].split("/")[-1] if link_uuid == new_uuid: camp_link = link msg = 'Unable to find link to newly created plan in CAMP plans' self.assertIsNotNone(camp_link, msg) url = camp_link['href'][len(self.client.base_url) + 1:] msg = ("GET Solum plan resource for %s" % camp_link['target_name']) resp, body = self.client.get(url) self.assertEqual(200, resp.status, msg) # CAMP plans are rendered in JSON plan = json.loads(body) self.assertEqual(base.plan_sample_data['name'], plan['name']) self.assertEqual(base.plan_sample_data['description'], plan['description'])
def test_create_bad_camp_version(self): """Try to create a CAMP plan from input with incorrect 'camp_version' Test that an attempt to create a plan with an incorrect 'camp_version' results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') bad_version_data = copy.copy(sample_data) bad_version_data['camp_version'] = 'CAMP 8.1' bad_version_str = yaml.dump(bad_version_data) self.assertRaises(tempest_exceptions.BadRequest, self.client.post, 'camp/v1_1/plans', bad_version_str, headers={'content-type': 'application/x-yaml'})
def test_get_solum_assembly(self): """Test the CAMP assemblies collection resource. Test that an assembly resource created through the Solum API is visible via the CAMP API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create an assembly using Solum p_resp = self.client.create_plan() self.assertEqual(201, p_resp.status) a_resp = self.client.create_assembly(plan_uuid=p_resp.uuid) self.assertEqual(201, a_resp.status) new_uuid = a_resp.uuid # try to get to the newly created assembly through the CAMP assemblies # resource. it would be more efficient to simply take the UUID of the # newly created resource and create a CAMP API URI # (../camp/v1_1/assemblies/<uuid>) from that, but we want to test that # a link to the Solum-created assembly appears in in the list of links # in the CAMP plans resource. resp, body = self.client.get('camp/v1_1/assemblies') self.assertEqual(200, resp.status, 'GET assemblies resource') # pick out the assemebly link for our new assembly uuid assemblies_dct = json.loads(body) camp_link = None for link in assemblies_dct['assembly_links']: link_uuid = link['href'].split("/")[-1] if link_uuid == new_uuid: camp_link = link msg = 'Unable to find link to newly created plan in CAMP plans' self.assertIsNotNone(camp_link, msg) url = camp_link['href'][len(self.client.base_url) + 1:] msg = ("GET Solum assembly resource for %s" % camp_link['target_name']) resp, body = self.client.get(url) self.assertEqual(200, resp.status, msg) assembly = json.loads(body) self.assertEqual('assembly', assembly['type']) self.assertEqual(base.assembly_sample_data['name'], assembly['name'])
def test_patch_no_plan(self): """Try to PATCH a non-existent CAMP plan Test that an attempt to PATCH a plan that doesn't exist results in an HTTP 404 "Not Found" error """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # use an invalid JSON Patch document to test correct error precedence patch_data = [{"op": "add", "value": ["foo", "baz"]}] patch_json = json.dumps(patch_data) # use a bad Content-Type to further test correct error precedence self.assertRaises(tempest_exceptions.NotFound, self.client.patch, 'camp/v1_1/plans/no_plan', patch_json, headers={'content-type': 'application/x-not-a-type'})
def test_delete_solum_plan_from_camp(self): """Test the ability to DELETE a Solum-created plan Test that an plan resource created through the Solum API can be deleted through the CAMP API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using Solum create_resp = self.client.create_plan() self.assertEqual(201, create_resp.status) uuid = create_resp.uuid # delete the plan using CAMP resp, body = self.client.delete('camp/v1_1/plans/%s' % uuid) self.assertEqual(204, resp.status) # remove the plan from the list of plans so we don't try to remove it # twice self.client.created_plans.remove(uuid)
def test_patch_no_plan(self): """Try to PATCH a non-existent CAMP plan Test that an attempt to PATCH a plan that doesn't exist results in an HTTP 404 "Not Found" error """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # use an invalid JSON Patch document to test correct error precedence patch_data = [ {"op": "add", "value": ["foo", "baz"]} ] patch_json = json.dumps(patch_data) # use a bad Content-Type to further test correct error precedence self.assertRaises(tempest_exceptions.NotFound, self.client.patch, 'camp/v1_1/plans/no_plan', patch_json, headers={'content-type': 'application/x-not-a-type'})
def test_plan_parameter_definitions(self): """Tests normative statement RMR-06 from the CAMP v1.1 specification: http://docs.oasis-open.org/camp/camp-spec/v1.1/csprd02/ camp-spec-v1.1-csprd02.pdf """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') resp, body = self.client.get('camp/v1_1/plans/') self.assertEqual(200, resp.status, 'GET plans resource') plans = json.loads(body) # get the URL of the parameter_definitions resource url = (plans['parameter_definitions_uri'] [len(self.client.base_url) + 1:]) # get the parameter_definitions resource resp, body = self.client.get(url) self.assertEqual(200, resp.status, 'GET plans parameter_definitions resource') pd_resc = json.loads(body) self.assertEqual('parameter_definitions', pd_resc['type']) self.assertIn('parameter_definition_links', pd_resc) pd_links = pd_resc['parameter_definition_links'] # The plan resource must reference parameter definitions for # the pdp_uri, plan_uri, pdp_file, and plan_file parameters. It # can reference additional parameter definitions. self.assertLessEqual(4, len(pd_links), "too few parameter definition links") expected_pds = ['pdp_uri', 'plan_uri', 'pdp_file', 'plan_file'] for pd_link in pd_links: expected_pds.remove(pd_link['target_name']) self.assertEqual(0, len(expected_pds), ('Missing parameter_definition from %s' % pd_resc['name']))
def test_patch_bad_content_type(self): """PATCH a CAMP plan using an incorrect content-type Test that an attempt to patch a plan with an incorrect Content-Type results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'][len(self.client.base_url) + 1:]) patch_data = [{"op": "add", "path": "/tags", "value": ["foo", "baz"]}] patch_json = json.dumps(patch_data) self.assertRaises(tempest_exceptions.InvalidContentType, self.client.patch, uri, patch_json, headers={'content-type': 'application/x-not-a-type'})
def test_assembly_parameter_definitions(self): """Tests normative statement RMR-03 from the CAMP v1.1 specification: http://docs.oasis-open.org/camp/camp-spec/v1.1/csprd02/ camp-spec-v1.1-csprd02.pdf """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') resp, body = self.client.get('camp/v1_1/assemblies/') self.assertEqual(200, resp.status, 'GET assemblies resource') assemblies = json.loads(body) # get the URL of the parameter_definitions resource url = ( assemblies['parameter_definitions_uri'][len(self.client.base_url) + 1:]) # get the parameter_definitions resource resp, body = self.client.get(url) self.assertEqual(200, resp.status, 'GET assembly parameter_definitions resource') pd_resc = json.loads(body) self.assertEqual('parameter_definitions', pd_resc['type']) self.assertIn('parameter_definition_links', pd_resc) pd_links = pd_resc['parameter_definition_links'] # The assembly resource must reference parameter definitions for # the pdp_uri, plan_uri, pdp_file, and plan_file parameters. It # can reference additional parameter definitions. self.assertLessEqual(4, len(pd_links), "too few parameter definition links") expected_pds = ['pdp_uri', 'plan_uri', 'pdp_file', 'plan_file'] for pd_link in pd_links: expected_pds.remove(pd_link['target_name']) self.assertEqual( 0, len(expected_pds), ('Missing parameter_definition from %s' % pd_resc['name']))
def test_patch_bad_content_type(self): """PATCH a CAMP plan using an incorrect content-type Test that an attempt to patch a plan with an incorrect Content-Type results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'] [len(self.client.base_url) + 1:]) patch_data = [ {"op": "add", "path": "/tags", "value": ["foo", "baz"]} ] patch_json = json.dumps(patch_data) self.assertRaises(tempest_exceptions.InvalidContentType, self.client.patch, uri, patch_json, headers={'content-type': 'application/x-not-a-type'})
def test_create_camp_plan(self): """Test the visibility of CAMP-created plans Test that an plan resource created through the CAMP API is visible through the Solum API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) self._assert_output_expected(resp.data, sample_data) uuid = resp.data['uuid'] # get the plan using the Solum API resp, body = self.client.get( 'v1/plans/%s' % uuid, headers={'content-type': 'application/x-yaml'}) self.assertEqual(resp.status, 200) yaml_data = yaml.load(body) self._assert_output_expected(yaml_data, sample_data)
def test_delete_camp_plan_from_solum(self): """Test the ability of the Solum API to delete a CAMP-created plan Test that an plan resource created through the CAMP API can be deleted through the Solum API. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) self._assert_output_expected(resp.data, sample_data) uuid = resp.data['uuid'] # delete the plan using the Solum API resp, body = self.client.delete('v1/plans/%s' % uuid) self.assertEqual(202, resp.status) # remove the plan from the list of plans so we don't try to remove it # twice self.client.created_plans.remove(uuid)
def test_patch_bad_json_patch(self): """PATCH a CAMP plan using invalid JSON Patch document Test that an attempt to patch a plan with a mal-formed JSON Patch request (missing 'path') results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'][len(self.client.base_url) + 1:]) patch_data = [{"op": "add", "value": ["foo", "baz"]}] patch_json = json.dumps(patch_data) self.assertRaises( tempest_exceptions.BadRequest, self.client.patch, uri, patch_json, headers={'content-type': 'application/json-patch+json'})
def test_delete_plan_with_assemblies(self): """Test deleting a plan what has assemblies associated with it. Creates a plan, an assembly, then tries to delete the plan. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=test_plans.sample_data) self.assertEqual(resp.status, 201) plan_uri = (resp.data['uri'] [len(self.client.base_url):]) ref_obj = json.dumps({'plan_uri': plan_uri}) resp, body = self.client.post( 'camp/v1_1/assemblies', ref_obj, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 201) assem_resp = base.SolumResponse(resp=resp, body=body, body_type='json') uuid = assem_resp.uuid if uuid is not None: # share the Solum client's list of created assemblies self.client.created_assemblies.append(uuid) # try to delete the plan before deleting the assembly # resp, body = self.client.delete(plan_uri[1:]) # self.assertEqual(409, resp.status) self.assertRaises(tempest_exceptions.Conflict, self.client.delete, plan_uri[1:])
def test_patch_bad_json_patch(self): """PATCH a CAMP plan using invalid JSON Patch document Test that an attempt to patch a plan with a mal-formed JSON Patch request (missing 'path') results in the proper error. """ if base.config_set_as('camp_enabled', False): self.skipTest('CAMP not enabled.') # create a plan using the CAMP API resp = self._create_camp_plan(data=sample_data) self.assertEqual(resp.status, 201) uri = (resp.data['uri'] [len(self.client.base_url) + 1:]) patch_data = [ {"op": "add", "value": ["foo", "baz"]} ] patch_json = json.dumps(patch_data) self.assertRaises(tempest_exceptions.BadRequest, self.client.patch, uri, patch_json, headers={'content-type': 'application/json-patch+json'})