From 76144a9a772f50cb3ec80757d9f1c1ec119eee6a Mon Sep 17 00:00:00 2001 From: "stark, steven" Date: Mon, 4 Jan 2021 11:40:12 -0800 Subject: [VVP] ONAP client performance improvement First of multiple performance patches. Adding ability to cache data for use by the onap-client. Changing API call for SDC to get VF and Service models. Previously to find a service model, onap-client queried for all models and then searched by name. New api call to query by name, then find latest version. Issue-ID: VVP-503 Signed-off-by: stark, steven Change-Id: I071cadbe52163f0b375bc81ac4a9fd640bd5ca4a --- onap-client/onap_client/client/catalog.py | 104 ++++++++++++++++----- onap-client/onap_client/client/request.py | 8 +- onap-client/onap_client/lib.py | 14 +-- .../onap_client/sdc/catalog/service_catalog.py | 18 ++++ onap-client/onap_client/sdc/catalog/vnf_catalog.py | 18 ++++ onap-client/onap_client/sdc/license_model.py | 2 + onap-client/onap_client/sdc/service.py | 55 +++++++---- onap-client/onap_client/sdc/tests/test_service.py | 6 ++ onap-client/onap_client/sdc/tests/test_vnf.py | 9 ++ onap-client/onap_client/sdc/vnf.py | 78 +++++++++++----- onap-client/onap_client/sdc/vsp.py | 11 ++- onap-client/onap_client/so/service_instance.py | 7 +- .../onap_client/so/tests/test_module_instance.py | 12 +++ .../onap_client/so/tests/test_service_instance.py | 6 +- .../onap_client/so/tests/test_vnf_instance.py | 18 ++++ onap-client/onap_client/so/vnf_instance.py | 4 +- onap-client/onap_client/tests/utils.py | 4 +- onap-client/requirements.txt | 2 +- onap-client/setup.py | 2 +- 19 files changed, 283 insertions(+), 95 deletions(-) diff --git a/onap-client/onap_client/client/catalog.py b/onap-client/onap_client/client/catalog.py index 989d975..7c2eb0d 100644 --- a/onap-client/onap_client/client/catalog.py +++ b/onap-client/onap_client/client/catalog.py @@ -59,6 +59,7 @@ def get_modules(): class Catalog(ABC): """Abstract class for an ONAP client, automatically loads child classes as attributes.""" + class CallHandle: """Attached as an attribute for each catalog entry in a catalog. Used to make a request to ONAP.""" @@ -66,37 +67,41 @@ class Catalog(ABC): def __init__(self, catalog_resource, response_callback=None, verify=False): self.resource = catalog_resource self.verify_request = verify - self.callback = response_callback if response_callback else self.empty_callback + self.callback = ( + response_callback if response_callback else self.empty_callback + ) def empty_callback(self, *args, **kwargs): pass - def __call__(self, **kwargs): + def __call__(self, raise_on_error=True, attempts=3, **kwargs): self.callback(message=f"Submitting request: {self.resource.description}") - response_handler = make_request(self.resource, self.verify_request, **kwargs) + response_handler = make_request( + self.resource, attempts, self.verify_request, **kwargs + ) self.callback(response_handler=response_handler) if not response_handler.success: - self.callback(message=f"Request Failure: {self.resource.catalog_resource_name} {response_handler.response_data}") - raise exceptions.RequestFailure( - "Failed making request for catalog item {}: {}".format( - self.resource.catalog_resource_name, - response_handler.response_data + self.callback( + message=f"Failed making request for catalog item: {response_handler.status_code} {self.resource.catalog_resource_name} {response_handler.response_data}" + ) + if raise_on_error: + raise exceptions.RequestFailure( + "Failed making request for catalog item {}: {}".format( + self.resource.catalog_resource_name, + response_handler.response_data, + ) ) + else: + self.callback( + message=f"{response_handler.status_code} {self.resource.catalog_resource_name} Request was Successful" ) - self.callback(message="Request was Successful") - return response_handler - def __init__( - self, - config_file=None, - history_buffer=[], - **kwargs - ): + def __init__(self, config_file=None, history_buffer=[], **kwargs): """Iterates through all child classes and attaches them as attributes, named after the namespace property. @@ -107,6 +112,7 @@ class Catalog(ABC): if not config_file: config_file = os.environ.get("OC_CONFIG") or "/etc/onap_client/config.yaml" + self._cache = CatalogCache() self.catalog_items = {} self.modules = get_modules() self._config_overrides = kwargs @@ -116,7 +122,9 @@ class Catalog(ABC): self.add_to_history("Creating ONAP Client...") for cls in self.__class__.__subclasses__(): - subclass = cls(config_file=config_file, history_buffer=self.history, **kwargs) + subclass = cls( + config_file=config_file, history_buffer=self.history, **kwargs + ) namespace = subclass.namespace catalog_resources = subclass.catalog_resources @@ -136,7 +144,11 @@ class Catalog(ABC): callback = self.add_to_history - setattr(self, item_name.lower(), self.CallHandle(resource, response_callback=callback, verify=verify)) + setattr( + self, + item_name.lower(), + self.CallHandle(resource, response_callback=callback, verify=verify), + ) def add_to_history(self, message="", response_handler=None): if response_handler: @@ -163,10 +175,7 @@ class Catalog(ABC): def add_message_to_history(self, message): current_time = datetime.now() - history_message = { - "date": f"{current_time}", - "message": message - } + history_message = {"date": f"{current_time}", "message": message} self.history.append(history_message) @property @@ -190,6 +199,12 @@ class Catalog(ABC): utility_functions[func[0]] = func[1] return utility_functions + def cache(self, *args, **kwargs): + self._cache.cache(*args, **kwargs) + + def get_cached(self, *args, **kwargs): + return self._cache.get_cached(*args, **kwargs) + def set_config(self, config_file): self.config = config.load_config(config_file, "onap_client") verify = self.config.REQUESTS_VERIFY @@ -204,10 +219,55 @@ class Catalog(ABC): def override_check(self): o = self._config_overrides.get(override_key) return o if o else func(self) + return override_check + return decorator +class CatalogCache: + """Basic helper dict to cache data from requests""" + def __init__(self): + self._cached_data = { + "service": {}, + "vnf": {}, + "license_model": {}, + "vsp": {}, + "other": {}, + } + + def cache(self, *items, cache=None): + if cache is None: + cache = self._cached_data + + items = list(items) + item = items.pop(0) + + if len(items) == 1: + cache[item] = items.pop(0) + return + + if item not in cache: + cache[item] = {} + + self.cache(*items, cache=cache[item]) + + def get_cached(self, *items, cache=None): + if not cache: + cache = self._cached_data + + items = list(items) + item = items.pop(0) + + if item not in cache: + return None + + if not len(items): + return cache[item] + + return self.get_cached(*items, cache=cache[item]) + + class APICatalogResource: """Class representation of a single catalog entry""" diff --git a/onap-client/onap_client/client/request.py b/onap-client/onap_client/client/request.py index fa9bf15..eb65b56 100644 --- a/onap-client/onap_client/client/request.py +++ b/onap-client/onap_client/client/request.py @@ -59,13 +59,13 @@ class RequestHandler: """ self.request_object = request_object - def make_request(self, verify): + def make_request(self, attempts, verify): r = Request(self.request_object) logger.info("Submitting request: {}".format(self.request_object.description)) # TODO # Add verify to config file - return ResponseHandler(r.request(verify=verify), self.request_object) + return ResponseHandler(r.request(attempts, verify=verify), self.request_object) class Request: @@ -113,10 +113,10 @@ class Request: except TypeError: logger.info(debug_request) - def request(self, verify=True): + def request(self, attempts, verify=True): http = requests.Session() retry_strategy = Retry( - total=3, + total=attempts, backoff_factor=5, status_forcelist=[404, 429, 500, 501, 502, 503, 504], method_whitelist=["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE", "POST"], diff --git a/onap-client/onap_client/lib.py b/onap-client/onap_client/lib.py index 40024ce..02641ce 100644 --- a/onap-client/onap_client/lib.py +++ b/onap-client/onap_client/lib.py @@ -43,7 +43,7 @@ from onap_client import exceptions from onap_client.client.request import RequestHandler, APICatalogRequestObject -def make_request(catalog_item, verify_request, **kwargs): +def make_request(catalog_item, attempts, verify_request, **kwargs): """Makes a request using by merging an APICatalogResource and kwargs to fill in the required parameters @@ -58,17 +58,7 @@ def make_request(catalog_item, verify_request, **kwargs): request_handler = RequestHandler(catalog_request) - return request_handler.make_request(verify_request) - - # if not response_handler.success: - # raise exceptions.RequestFailure( - # "Failed making request for catalog item {}: {}".format( - # catalog_item.catalog_resource_name, - # response_handler.response_data - # ) - # ) - - # return response_handler + return request_handler.make_request(attempts, verify_request) def validate_request(catalog_item, kwargs): diff --git a/onap-client/onap_client/sdc/catalog/service_catalog.py b/onap-client/onap_client/sdc/catalog/service_catalog.py index 8a3566c..32749ff 100644 --- a/onap-client/onap_client/sdc/catalog/service_catalog.py +++ b/onap-client/onap_client/sdc/catalog/service_catalog.py @@ -366,6 +366,24 @@ class ServiceCatalog(SDCClient): }, "auth": self.auth, }, + "GET_SERVICE_BY_NAME_VERSION": { + "verb": "GET", + "description": "Gets a Service in the SDC catalog", + "uri": partial( + "{endpoint}{service_path}/serviceName/{catalog_service_name}/serviceVersion/{catalog_service_version}".format, + endpoint=self.config.sdc.SDC_BE_ENDPOINT, + service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, + ), + "uri-parameters": ["catalog_service_name", "catalog_service_version"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "USER_ID": self.sdc_designer_user_id, + "X-FromAppId": self.config.application_id, + }, + "auth": self.auth, + }, "GET_SDC_SERVICE": { "verb": "GET", "description": "Gets a service from the SDC Catalog", diff --git a/onap-client/onap_client/sdc/catalog/vnf_catalog.py b/onap-client/onap_client/sdc/catalog/vnf_catalog.py index fe1a251..8d0ad32 100644 --- a/onap-client/onap_client/sdc/catalog/vnf_catalog.py +++ b/onap-client/onap_client/sdc/catalog/vnf_catalog.py @@ -460,6 +460,24 @@ class VNFCatalog(SDCClient): "return_data": {"catalog_resource_name": ("name",)}, "auth": self.auth, }, + "GET_RESOURCE_BY_NAME_VERSION": { + "verb": "GET", + "description": "Gets a VNF in the SDC catalog", + "uri": partial( + "{endpoint}{service_path}/resourceName/{catalog_resource_name}/resourceVersion/{catalog_resource_version}".format, + endpoint=self.config.sdc.SDC_BE_ENDPOINT, + service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, + ), + "uri-parameters": ["catalog_resource_name", "catalog_resource_version"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "USER_ID": self.sdc_designer_user_id, + "X-FromAppId": self.config.application_id, + }, + "auth": self.auth, + }, "GET_CATALOG_RESOURCE_METADATA": { "verb": "GET", "description": "Gets metadata for a VNF in the SDC catalog", diff --git a/onap-client/onap_client/sdc/license_model.py b/onap-client/onap_client/sdc/license_model.py index ed5ba80..ba71527 100644 --- a/onap-client/onap_client/sdc/license_model.py +++ b/onap-client/onap_client/sdc/license_model.py @@ -97,6 +97,8 @@ class LicenseModel(Resource): license_model = self.oc.sdc.license_model.get_license_model(**self.attributes) self.attributes["tosca"] = license_model.response_data + self.oc.cache("license_model", self.license_model_name, "tosca", self.tosca) + def _output(self): return self.tosca diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py index c405e42..1bccb36 100644 --- a/onap-client/onap_client/sdc/service.py +++ b/onap-client/onap_client/sdc/service.py @@ -121,7 +121,7 @@ class Service(Resource): """Creates a service object in SDC""" service = None - existing = get_service_id(service_input.get("service_name"), oc=self.oc) + existing, __ = get_service_id(service_input.get("service_name"), oc=self.oc) if existing is None: service = create_service(service_input, oc=self.oc) elif service_input.get("allow_update"): @@ -144,13 +144,19 @@ class Service(Resource): resource_id = resource.get("resource_id") resource_properties = resource.get("properties") if not resource_id: - resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) + cached_resource = self.oc.get_cached("vnf", catalog_resource_name, "tosca") + if not cached_resource: + resource_id, __ = get_vnf_id(catalog_resource_name, oc=self.oc) + else: + resource_id = cached_resource.get("uniqueId") + if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( resource_name ) ) + resource_origin = resource.get("origin_type") self.add_resource(resource_id, resource_name, origin_type=resource_origin) for k, v in resource_properties.items(): @@ -209,6 +215,8 @@ class Service(Resource): self._refresh() + self.oc.cache("service", self.service_name, "tosca", self.tosca) + def add_resource( self, catalog_resource_id, catalog_resource_name, origin_type="VF" ): @@ -380,27 +388,42 @@ def get_service(service_name, oc=None): if not oc: oc = Client() - return oc.sdc.service.get_sdc_service( - catalog_service_id=get_service_id(service_name, oc=oc) - ).response_data + catalog_service_id, catalog_service = get_service_id(service_name, oc=oc) + if not catalog_service: + return oc.sdc.service.get_sdc_service( + catalog_service_id=catalog_service_id + ).response_data + else: + return catalog_service @utility def get_service_id(service_name, oc=None): - """Queries SDC for the uniqueId of a service model""" if not oc: oc = Client() - response = oc.sdc.service.get_services() - results = response.response_data.get("services", []) - update_time = -1 - catalog_service = {} - for service in results: - 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") + response = oc.sdc.service.get_service_by_name_version( + catalog_service_name=service_name, + catalog_service_version="1.0", + raise_on_error=False, + attempts=1, + ) + if not response.success: + return None, None + + versions = response.response_data.get("allVersions") + catalog_service_id = "" + catalog_service = None + highest_version = 0 + for version, service_id in versions.items(): + if float(version) > highest_version: + highest_version = float(version) + catalog_service_id = service_id + + if highest_version == 1.0: + catalog_service = response.response_data + + return catalog_service_id, catalog_service def get_service_uuid(service_name, oc=None): diff --git a/onap-client/onap_client/sdc/tests/test_service.py b/onap-client/onap_client/sdc/tests/test_service.py index 77eadbd..ad79a44 100644 --- a/onap-client/onap_client/sdc/tests/test_service.py +++ b/onap-client/onap_client/sdc/tests/test_service.py @@ -102,6 +102,12 @@ def test_vnf_create(): "uniqueId": SERVICE_MODEL_ID, } ) + mockup_catalog_item( + oc.sdc.service.catalog_items["GET_SERVICE_BY_NAME_VERSION"], + override_uri_params={"catalog_service_name": SERVICE_NAME, "catalog_service_version": "1.0"}, + override_return_data={}, + status=404 + ) service = Service( instantiation_type="A-la-carte", diff --git a/onap-client/onap_client/sdc/tests/test_vnf.py b/onap-client/onap_client/sdc/tests/test_vnf.py index da3dd86..06fb750 100644 --- a/onap-client/onap_client/sdc/tests/test_vnf.py +++ b/onap-client/onap_client/sdc/tests/test_vnf.py @@ -65,6 +65,9 @@ def test_vnf_create(): {"name": "nf_role", "value": "dfankafd"}, ] }, + "allVersions": { + "1.0": CATALOG_RESOURCE_ID + }, "name": VNF_NAME, } mockup_catalog_item( @@ -107,6 +110,12 @@ def test_vnf_create(): override_return_data=return_data, override_uri_params={"catalog_resource_id": CATALOG_RESOURCE_ID}, ) + mockup_catalog_item( + oc.sdc.vnf.catalog_items["GET_RESOURCE_BY_NAME_VERSION"], + override_return_data=return_data, + override_uri_params={"catalog_resource_name": VNF_NAME, "catalog_resource_version": "1.0"}, + status=404, + ) mockup_catalog_item( oc.sdc.vnf.catalog_items["CERTIFY_CATALOG_RESOURCE"], override_return_data=return_data, diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py index af5f71f..4f7e4d7 100644 --- a/onap-client/onap_client/sdc/vnf.py +++ b/onap-client/onap_client/sdc/vnf.py @@ -34,7 +34,6 @@ # limitations under the License. # # ============LICENSE_END============================================ - from onap_client.lib import generate_dummy_string from onap_client.resource import Resource from onap_client import exceptions @@ -126,11 +125,11 @@ class VNF(Resource): """Creates a vnf object in SDC""" vnf = None - existing = get_vnf_id(vnf_input.get("vnf_name"), oc=self.oc) - if not existing: + existing_vnf_id, __ = get_vnf_id(vnf_input.get("vnf_name"), oc=self.oc) + if not existing_vnf_id: vnf = create_vnf(vnf_input, oc=self.oc) elif vnf_input.get("allow_update"): - vnf = update_vnf(existing, vnf_input, oc=self.oc) + vnf = update_vnf(existing_vnf_id, vnf_input, oc=self.oc) else: raise exceptions.ResourceAlreadyExistsException( "VNF resource {} already exists".format(vnf_input.get("vnf_name")) @@ -191,6 +190,8 @@ class VNF(Resource): self.attributes["catalog_resource_name"] = vnf.catalog_resource_name self.attributes["tosca"] = vnf.response_data + self.oc.cache("vnf", self.vnf_name, "tosca", self.tosca) + def _add_instance_properties(self, instance_id, properties_dict): for k, v in properties_dict.items(): # updating vm_type properties @@ -211,7 +212,7 @@ class VNF(Resource): resource_relationship = resource.get("relationship", {}) if not resource_id: - resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) + resource_id, __ = get_vnf_id(catalog_resource_name, oc=self.oc) if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( @@ -522,11 +523,13 @@ def update_vnf(catalog_resource_id, vnf_input, oc=None): if existing_vnf.get("lifecycleState") != "NOT_CERTIFIED_CHECKOUT": vnf = oc.sdc.vnf.checkout_catalog_resource(catalog_resource_id=catalog_resource_id).response_data else: - vnf = oc.sdc.vnf.get_catalog_resource_metadata(catalog_resource_id=catalog_resource_id).response_data.get("metadata", {}) + vnf = existing_vnf new_vnf_metadata = oc.sdc.vnf.get_catalog_resource_metadata(catalog_resource_id=vnf.get("uniqueId")).response_data.get("metadata", {}) - csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name", oc=oc) + csar_version = oc.get_cached("vsp", vnf_input.get("software_product_name"), "csar_version") + if not csar_version: + csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name", oc=oc) vnf["csarVersion"] = csar_version vnf["componentMetadata"] = new_vnf_metadata @@ -549,9 +552,14 @@ def create_vnf(vnf_input, oc=None): if not oc: oc = Client() - software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name"), oc=oc) - software_product_version_id = vsp.get_vsp_version_id(software_product_id, oc=oc) - vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id, oc=oc) + vsp_model = oc.get_cached("vsp", vnf_input.get("software_product_name"), "tosca") + if not vsp_model: + software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name"), oc=oc) + software_product_version_id = vsp.get_vsp_version_id(software_product_id, oc=oc) + vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id, oc=oc) + else: + software_product_id = vsp_model.get("id") + software_product_version_id = vsp_model.get("version") vsp_vendor = vsp_model.get("vendorName") vsp_category = vsp_model.get("category") @@ -571,7 +579,12 @@ def create_vnf(vnf_input, oc=None): break category["subcategories"] = vsp_sub_categories - vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id, oc=oc) + + owner = oc.get_cached("vsp", vnf_input.get("software_product_name"), "owner") + if not owner: + owner = vsp.get_vsp_owner(software_product_id, oc=oc) + + vnf_input["contact_id"] = owner vnf = oc.sdc.vnf.add_catalog_resource(**vnf_input, categories=[category]) @@ -664,9 +677,13 @@ def get_vnf(vnf_name, oc=None): if not oc: oc = Client() - return oc.sdc.vnf.get_catalog_resource( - catalog_resource_id=get_vnf_id(vnf_name, oc=oc) - ).response_data + catalog_resource_id, catalog_resource = get_vnf_id(vnf_name, oc=oc) + if not catalog_resource: + return oc.sdc.vnf.get_catalog_resource( + catalog_resource_id=catalog_resource_id + ).response_data + else: + return catalog_resource def get_resource_category(category_name, oc=None): @@ -681,16 +698,29 @@ def get_resource_category(category_name, oc=None): def get_vnf_id(vnf_name, oc=None): + """Returns the latest VNF id for a VNF Model. If there is only one version + of a VNF model, that will also be returned""" if not oc: oc = Client() - response = oc.sdc.vnf.get_resources() - results = response.response_data.get("resources", []) - catalog_resource = {} - update_time = -1 - for vnf in results: - 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") + response = oc.sdc.vnf.get_resource_by_name_version( + catalog_resource_name=vnf_name, + catalog_resource_version="1.0", + raise_on_error=False, + attempts=1, + ) + if not response.success: + return None, None + + versions = response.response_data.get("allVersions") + catalog_resource_id = "" + catalog_resource = None + highest_version = 0 + for version, vnf_id in versions.items(): + if float(version) > highest_version: + highest_version = float(version) + catalog_resource_id = vnf_id + + if highest_version == 1.0: + catalog_resource = response.response_data + return catalog_resource_id, catalog_resource diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py index 3a8dcde..100fca0 100644 --- a/onap-client/onap_client/sdc/vsp.py +++ b/onap-client/onap_client/sdc/vsp.py @@ -124,6 +124,9 @@ class VSP(Resource): vsp = self.oc.sdc.vsp.get_software_product(**self.attributes) self.attributes["tosca"] = vsp.response_data + self.oc.cache("vsp", self.software_product_name, "tosca", self.tosca) + self.oc.cache("vsp", self.software_product_name, "owner", self.owner) + def _output(self): return self.tosca @@ -136,14 +139,16 @@ def update_vsp(existing_vsp, vsp_input, oc=None): existing_vsp_version_id = existing_vsp.get("version") if get_vsp_version_id(existing_vsp_id, search_key="status", oc=oc) == "Certified": - oc.sdc.vsp.update_software_product( + response_data = oc.sdc.vsp.update_software_product( software_product_id=existing_vsp_id, software_product_version_id=existing_vsp_version_id, description=vsp_input.get("update_message", "New VSP Version") - ) + ).response_data + oc.cache("vsp", existing_vsp.get("name"), "csar_version", response_data.get("name")) + existing_vsp_version_id = response_data.get("id") vsp_input["software_product_id"] = existing_vsp_id - vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id, oc=oc) + vsp_input["software_product_version_id"] = existing_vsp_version_id oc.sdc.vsp.upload_heat_package(**vsp_input) oc.sdc.vsp.validate_software_product(**vsp_input) diff --git a/onap-client/onap_client/so/service_instance.py b/onap-client/onap_client/so/service_instance.py index 2b1774d..23d2b24 100644 --- a/onap-client/onap_client/so/service_instance.py +++ b/onap-client/onap_client/so/service_instance.py @@ -85,12 +85,7 @@ class ServiceInstance(Resource): instance_input["tenant_id"] = tenant_id instance_input["customer_id"] = instance_input.get("customer_name") - service_model = self.oc.sdc.service.get_sdc_service( - catalog_service_id=sdc.service.get_service_id( - instance_input.get("model_name"), - oc=self.oc - ) - ).response_data + service_model = sdc.service.get_service(instance_input.get("model_name"), oc=self.oc) instance_input["model_invariant_id"] = service_model["invariantUUID"] instance_input["model_version_id"] = service_model["uniqueId"] diff --git a/onap-client/onap_client/so/tests/test_module_instance.py b/onap-client/onap_client/so/tests/test_module_instance.py index 0e8c655..8ec8a59 100644 --- a/onap-client/onap_client/so/tests/test_module_instance.py +++ b/onap-client/onap_client/so/tests/test_module_instance.py @@ -138,6 +138,18 @@ def test_module_instance(): ] } ) + mockup_catalog_item( + oc.sdc.service.catalog_items["GET_SERVICE_BY_NAME_VERSION"], + override_uri_params={"catalog_service_name": SERVICE_MODEL_NAME, "catalog_service_version": "1.0"}, + override_return_data={ + "uniqueId": SERVICE_MODEL_ID, + "allVersions": { + "1.0": "badid", + "2.0": SERVICE_MODEL_ID + }, + "name": SERVICE_MODEL_NAME, + } + ) mockup_catalog_item( oc.sdc.vnf.catalog_items["GET_CATALOG_RESOURCE"], override_return_data={ diff --git a/onap-client/onap_client/so/tests/test_service_instance.py b/onap-client/onap_client/so/tests/test_service_instance.py index b215fbf..fed5ac9 100644 --- a/onap-client/onap_client/so/tests/test_service_instance.py +++ b/onap-client/onap_client/so/tests/test_service_instance.py @@ -69,9 +69,9 @@ def test_service_instance(): }, ) mockup_catalog_item( - oc.sdc.service.catalog_items["GET_SDC_SERVICE"], - override_uri_params={"catalog_service_id": SERVICE_MODEL_ID}, - override_return_data={"invariantUUID": SERVICE_MODEL_INVARIANT_ID, "uniqueId": SERVICE_MODEL_ID} + oc.sdc.service.catalog_items["GET_SERVICE_BY_NAME_VERSION"], + override_uri_params={"catalog_service_name": SERVICE_MODEL_NAME, "catalog_service_version": "1.0"}, + override_return_data={"invariantUUID": SERVICE_MODEL_INVARIANT_ID, "uniqueId": SERVICE_MODEL_ID, "allVersions": {"1.0": SERVICE_MODEL_ID}} ) mockup_catalog_item( oc.aai.cloud_infrastructure.catalog_items["GET_CLOUD_REGION_TENANTS"], diff --git a/onap-client/onap_client/so/tests/test_vnf_instance.py b/onap-client/onap_client/so/tests/test_vnf_instance.py index 88334b0..9f03cca 100644 --- a/onap-client/onap_client/so/tests/test_vnf_instance.py +++ b/onap-client/onap_client/so/tests/test_vnf_instance.py @@ -90,6 +90,20 @@ def test_vnf_instance(): ], } ) + + mockup_catalog_item( + oc.sdc.service.catalog_items["GET_SERVICE_BY_NAME_VERSION"], + override_uri_params={"catalog_service_name": SERVICE_MODEL_NAME, "catalog_service_version": "1.0"}, + override_return_data={ + "uniqueId": SERVICE_MODEL_ID, + "allVersions": { + "1.0": "badid", + "2.0": SERVICE_MODEL_ID + }, + "name": SERVICE_MODEL_NAME, + } + ) + mockup_catalog_item( oc.sdc.service.catalog_items["GET_SDC_SERVICE"], override_uri_params={"catalog_service_id": SERVICE_MODEL_ID}, @@ -106,6 +120,7 @@ def test_vnf_instance(): ] } ) + mockup_catalog_item( oc.sdc.vnf.catalog_items["GET_CATALOG_RESOURCE"], override_return_data={ @@ -113,6 +128,7 @@ def test_vnf_instance(): }, override_uri_params={"catalog_resource_id": VNF_ACTUAL_UUID}, ) + mockup_catalog_item( oc.sdnc.configuration.catalog_items["GET_SERVICE_INSTANCES"], override_return_data={ @@ -138,6 +154,7 @@ def test_vnf_instance(): } }, ) + mockup_catalog_item( oc.so.service_instantiation.catalog_items["CREATE_VNF_INSTANCE"], override_return_data={ @@ -146,6 +163,7 @@ def test_vnf_instance(): } } ) + mockup_catalog_item( oc.so.service_instantiation.catalog_items["GET_REQUEST_STATUS"], override_uri_params={"request_id": REQUEST_ID}, diff --git a/onap-client/onap_client/so/vnf_instance.py b/onap-client/onap_client/so/vnf_instance.py index 32fcda7..44d84e9 100644 --- a/onap-client/onap_client/so/vnf_instance.py +++ b/onap-client/onap_client/so/vnf_instance.py @@ -134,8 +134,10 @@ def get_vnf_model_component(service_model_name, vnf_model_name, oc=None): if not oc: oc = Client() + catalog_service_id, catalog_service = sdc.service.get_service_id(service_model_name, oc=oc) + service_model = oc.sdc.service.get_sdc_service( - catalog_service_id=sdc.service.get_service_id(service_model_name, oc=oc) + catalog_service_id=catalog_service_id ).response_data for component in service_model.get("componentInstances", []): diff --git a/onap-client/onap_client/tests/utils.py b/onap-client/onap_client/tests/utils.py index ddcca9e..a97e0e3 100644 --- a/onap-client/onap_client/tests/utils.py +++ b/onap-client/onap_client/tests/utils.py @@ -53,7 +53,7 @@ def mockup_return_item(item, item_list): def mockup_catalog_item( - catalog_resource, override_return_data=None, override_uri_params={} + catalog_resource, override_return_data=None, override_uri_params={}, status=None ): uri = catalog_resource.uri if isinstance(uri, functools.partial): @@ -75,5 +75,5 @@ def mockup_catalog_item( getattr(responses, catalog_resource.verb), uri, json=return_items, - status=catalog_resource.success_code, + status=catalog_resource.success_code if not status else status, ) diff --git a/onap-client/requirements.txt b/onap-client/requirements.txt index 94f928b..5d1bc8c 100644 --- a/onap-client/requirements.txt +++ b/onap-client/requirements.txt @@ -36,7 +36,7 @@ # ============LICENSE_END============================================ jinja2 PyYaml -requests +requests==2.22.0 PTable simplejson prettytable diff --git a/onap-client/setup.py b/onap-client/setup.py index 0b4dae0..f0b9ed4 100644 --- a/onap-client/setup.py +++ b/onap-client/setup.py @@ -43,7 +43,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="onap-client", - version="1.4.0", + version="1.5.0", author="Steven Stark", author_email="steven.stark@att.com", description="Python API wrapper for ONAP applications", -- cgit 1.2.3-korg