diff options
author | stark, steven <steven.stark@att.com> | 2020-04-10 13:58:40 -0700 |
---|---|---|
committer | stark, steven <steven.stark@att.com> | 2020-04-14 08:11:03 -0700 |
commit | d6b3ac08745b099fbd0ea5ff9feec22a0247bf49 (patch) | |
tree | 24681e2239d99ca9ce7f73195b15feb46a74c850 /onap-client | |
parent | 71a1fd0d98c99692a25f9087ad5edfbd7cf00800 (diff) |
[VVP] adding support for updating checked out resources
- also fixing imports of client to skip tests*
Issue-ID: VVP-403
Signed-off-by: stark, steven <steven.stark@att.com>
Change-Id: I0f0bddb04d4de10b9003e4fc6380619539f41ca4
Diffstat (limited to 'onap-client')
-rw-r--r-- | onap-client/onap_client/client/clients.py | 8 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/catalog/service_catalog.py | 22 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/service.py | 61 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/vnf.py | 19 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/vsp.py | 11 | ||||
-rw-r--r-- | onap-client/setup.py | 2 |
6 files changed, 77 insertions, 46 deletions
diff --git a/onap-client/onap_client/client/clients.py b/onap-client/onap_client/client/clients.py index 0c4605f..9b7a0c6 100644 --- a/onap-client/onap_client/client/clients.py +++ b/onap-client/onap_client/client/clients.py @@ -79,7 +79,9 @@ def import_submodules(package, recursive=True): results = {} for loader, name, is_pkg in pkgutil.walk_packages(package.__path__): full_name = package.__name__ + "." + name - results[full_name] = importlib.import_module(full_name) - if recursive and is_pkg and full_name.find("tests") == -1: - results.update(import_submodules(full_name)) + if full_name.find("tests") == -1: + results[full_name] = importlib.import_module(full_name) + if recursive and is_pkg: + results.update(import_submodules(full_name)) + return results diff --git a/onap-client/onap_client/sdc/catalog/service_catalog.py b/onap-client/onap_client/sdc/catalog/service_catalog.py index eff2784..aeaa3da 100644 --- a/onap-client/onap_client/sdc/catalog/service_catalog.py +++ b/onap-client/onap_client/sdc/catalog/service_catalog.py @@ -153,6 +153,28 @@ CATALOG_RESOURCES = { sdc_properties.GLOBAL_SDC_PASSWORD, ), }, + "DELETE_RESOURCE_FROM_SERVICE": { + "verb": "DELETE", + "description": "Deletes a resource from a service.", + "uri": partial( + "{endpoint}{service_path}/{catalog_service_id}/resourceInstance/{resource_instance_id}".format, + endpoint=sdc_properties.SDC_BE_ENDPOINT, + service_path=sdc_properties.SDC_CATALOG_SERVICES_PATH, + ), + "uri-parameters": ["catalog_service_id", "resource_instance_id"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "USER_ID": sdc_properties.SDC_DESIGNER_USER_ID, + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": ( + sdc_properties.GLOBAL_SDC_USERNAME, + sdc_properties.GLOBAL_SDC_PASSWORD, + ), + }, "UPDATE_RESOURCE_VERSION": { "verb": "POST", "description": "Updates a component version in a service", diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py index 57ef646..55c8f5c 100644 --- a/onap-client/onap_client/sdc/service.py +++ b/onap-client/onap_client/sdc/service.py @@ -264,24 +264,24 @@ class Service(Resource): """ milli_timestamp = int(time.time() * 1000) component_instances = self.tosca.get("componentInstances", []) - existing = False if component_instances: for component in component_instances: if component.get("componentName") == catalog_resource_name: - existing = True - resource_instance = self.update_resource_instance_version(component) + service_client.delete_resource_from_service( + catalog_service_id=self.catalog_service_id, + resource_instance_id=component.get("uniqueId") + ) break - if not existing: - resource_instance = service_client.add_resource_instance( - **self.attributes, - posX=random.randrange(150, 550), # nosec - posY=random.randrange(150, 450), # nosec - milli_timestamp=milli_timestamp, - catalog_resource_id=catalog_resource_id, - catalog_resource_name=catalog_resource_name, - originType=origin_type, - ).response_data + resource_instance = service_client.add_resource_instance( + **self.attributes, + posX=random.randrange(150, 550), # nosec + posY=random.randrange(150, 450), # nosec + milli_timestamp=milli_timestamp, + catalog_resource_id=catalog_resource_id, + catalog_resource_name=catalog_resource_name, + originType=origin_type, + ).response_data response = { "id": resource_instance.get("uniqueId"), @@ -341,27 +341,18 @@ class Service(Resource): catalog_service_id=self.catalog_service_id ).response_data - def update_resource_instance_version(self, component): - resource_name = component.get("componentName") - resource_unique_id = component.get("uniqueId") - resource_id = component.get("componentUid") - - vf_id = get_vnf_id(resource_name) - - if vf_id != resource_id: - return service_client.update_resource_version( - catalog_service_id=self.catalog_service_id, - component_name=resource_unique_id, - component_id=vf_id - ).response_data - else: - return component - def update_service(existing_service_id, service_input): kwargs = service_input - service = service_client.checkout_catalog_service(catalog_service_id=existing_service_id).response_data + existing_service = service_client.get_sdc_service( + catalog_service_id=existing_service_id + ).response_data + + if existing_service.get("lifecycleState") != "NOT_CERTIFIED_CHECKOUT": + service = service_client.checkout_catalog_service(catalog_service_id=existing_service_id).response_data + else: + service = existing_service new_service_id = service.get("uniqueId") @@ -401,10 +392,14 @@ def get_service_id(service_name): """Queries SDC for the uniqueId of a service model""" response = service_client.get_services() results = response.response_data.get("services", []) + update_time = -1 + catalog_service = {} for service in results: - if service.get("name") == service_name: - return service["uniqueId"] - return None + if service.get("name") == service_name and service.get("lastUpdateDate") > update_time: + update_time = service.get("lastUpdateDate") + catalog_service = service + + return catalog_service.get("uniqueId") def get_service_uuid(service_name): diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py index d07882c..1d2989a 100644 --- a/onap-client/onap_client/sdc/vnf.py +++ b/onap-client/onap_client/sdc/vnf.py @@ -506,7 +506,14 @@ class VNF(Resource): def update_vnf(catalog_resource_id, vnf_input): - vnf = vnf_client.checkout_catalog_resource(catalog_resource_id=catalog_resource_id).response_data + existing_vnf = vnf_client.get_catalog_resource( + catalog_resource_id=catalog_resource_id + ).response_data + + if existing_vnf.get("lifecycleState") != "NOT_CERTIFIED_CHECKOUT": + vnf = vnf_client.checkout_catalog_resource(catalog_resource_id=catalog_resource_id).response_data + else: + vnf = vnf_client.get_catalog_resource_metadata(catalog_resource_id=catalog_resource_id).response_data.get("metadata", {}) new_vnf_metadata = vnf_client.get_catalog_resource_metadata(catalog_resource_id=vnf.get("uniqueId")).response_data.get("metadata", {}) @@ -622,7 +629,11 @@ def get_vnf(vnf_name): def get_vnf_id(vnf_name): response = vnf_client.get_resources() results = response.response_data.get("resources", []) + catalog_resource = {} + update_time = -1 for vnf in results: - if vnf.get("name") == vnf_name: - return vnf["uniqueId"] - return None + if vnf.get("name") == vnf_name and vnf.get("lastUpdateDate") > update_time: + update_time = vnf.get("lastUpdateDate") + catalog_resource = vnf + + return catalog_resource.get("uniqueId") diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py index 7e99ece..781f6eb 100644 --- a/onap-client/onap_client/sdc/vsp.py +++ b/onap-client/onap_client/sdc/vsp.py @@ -153,11 +153,12 @@ def update_vsp(existing_vsp, vsp_input): existing_vsp_id = existing_vsp.get("id") existing_vsp_version_id = existing_vsp.get("version") - vsp_client.update_software_product( - software_product_id=existing_vsp_id, - software_product_version_id=existing_vsp_version_id, - description=vsp_input.get("description", "New VSP Version") - ).response_data + if get_vsp_version_id(existing_vsp_id, search_key="status") == "Certified": + vsp_client.update_software_product( + software_product_id=existing_vsp_id, + software_product_version_id=existing_vsp_version_id, + description=vsp_input.get("description", "New VSP Version") + ) vsp_input["software_product_id"] = existing_vsp_id vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id) diff --git a/onap-client/setup.py b/onap-client/setup.py index ea37a9e..228c921 100644 --- a/onap-client/setup.py +++ b/onap-client/setup.py @@ -47,7 +47,7 @@ for file in os.listdir("etc/payloads"): setuptools.setup( name="onap-client", - version="0.4.1", + version="0.5.0", author="Steven Stark", author_email="steven.stark@att.com", description="Python API wrapper for ONAP applications", |