From 70c6a75709b0001e9ffe26987563e14e3e6c6b3d Mon Sep 17 00:00:00 2001 From: Michal Jagiello Date: Fri, 3 Mar 2023 08:11:10 +0000 Subject: Archive Vendor Software Product Add a method to archive SDC VSP resource Issue-ID: INT-2193 Signed-off-by: Michal Jagiello Change-Id: If643ff47e6b7385eff5d745a5896bf4cb76c5c67 --- src/onapsdk/constants.py | 1 + src/onapsdk/sdc/__init__.py | 6 +++-- src/onapsdk/sdc/sdc_element.py | 9 +++----- src/onapsdk/sdc/sdc_resource.py | 5 +--- src/onapsdk/sdc/vsp.py | 44 ++++++++++++++++++++++++++++++++++-- src/onapsdk/utils/headers_creator.py | 2 +- 6 files changed, 52 insertions(+), 15 deletions(-) (limited to 'src/onapsdk') diff --git a/src/onapsdk/constants.py b/src/onapsdk/constants.py index 191e7aa..11bd03b 100644 --- a/src/onapsdk/constants.py +++ b/src/onapsdk/constants.py @@ -39,6 +39,7 @@ CERTIFY = "Certify" COMMIT = "Commit" CREATE_PACKAGE = "Create_Package" SUBMIT = "Submit" +ARCHIVE = "ARCHIVE" SUBMIT_FOR_TESTING = "certificationRequest" CHECKOUT = "checkout" UNDOCHECKOUT = "UNDOCHECKOUT" diff --git a/src/onapsdk/sdc/__init__.py b/src/onapsdk/sdc/__init__.py index 15280d9..c96c77f 100644 --- a/src/onapsdk/sdc/__init__.py +++ b/src/onapsdk/sdc/__init__.py @@ -458,9 +458,10 @@ class SdcOnboardable(SDC, ABC): @abstractmethod def _really_submit(self) -> None: """Really submit the SDC Vf in order to enable it.""" - @staticmethod + @abstractmethod - def _action_url(base: str, + def _action_url(self, + base: str, subpath: str, version_path: str, action_type: str = None) -> str: @@ -471,6 +472,7 @@ class SdcOnboardable(SDC, ABC): NotImplementedError: this is an abstract method. """ + @classmethod @abstractmethod def _sdc_path(cls) -> None: diff --git a/src/onapsdk/sdc/sdc_element.py b/src/onapsdk/sdc/sdc_element.py index f82fcb2..9273861 100644 --- a/src/onapsdk/sdc/sdc_element.py +++ b/src/onapsdk/sdc/sdc_element.py @@ -115,7 +115,7 @@ class SdcElement(SdcOnboardable, ABC): """ subpath = self._sdc_path() - if action == const.COMMIT: + if action in (const.COMMIT, const.ARCHIVE): subpath = "items" return subpath @@ -129,10 +129,7 @@ class SdcElement(SdcOnboardable, ABC): """ return "{}/versions/{}".format(self.identifier, self.version) - @staticmethod - def _action_url(base: str, - subpath: str, - version_path: str, + def _action_url(self, base: str, subpath: str, version_path: str, action_type: str = None) -> str: """ Generate action URL for SDC. @@ -183,7 +180,7 @@ class SdcElement(SdcOnboardable, ABC): str: Url which can be used to delete SDC element """ - return f"{self._get_all_url()}/{self.identifier}" + return f"{self._base_url()}/{self._sdc_path()}/{self.identifier}" def _copy_object(self, obj: 'SdcElement') -> None: """ diff --git a/src/onapsdk/sdc/sdc_resource.py b/src/onapsdk/sdc/sdc_resource.py index 29615db..bdd89ed 100644 --- a/src/onapsdk/sdc/sdc_resource.py +++ b/src/onapsdk/sdc/sdc_resource.py @@ -167,10 +167,7 @@ class SdcResource(SdcOnboardable, ABC): # pylint: disable=too-many-instance-att """ return self.unique_identifier - def _action_url(self, - base: str, - subpath: str, - version_path: str, + def _action_url(self, base: str, subpath: str, version_path: str, action_type: str = None) -> str: """ Generate action URL for SDC. diff --git a/src/onapsdk/sdc/vsp.py b/src/onapsdk/sdc/vsp.py index a6c4c24..a04b3c0 100644 --- a/src/onapsdk/sdc/vsp.py +++ b/src/onapsdk/sdc/vsp.py @@ -139,6 +139,13 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes self._generic_action, action=const.SUBMIT) + def archive(self) -> None: + """Archive VSP.""" + self._action("archive", + const.CERTIFIED, + self._generic_action, + action=const.ARCHIVE) + def create_csar(self) -> None: """Create the CSAR package in the SDC Vsp.""" self._action("create CSAR package", const.CERTIFIED, @@ -226,7 +233,10 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes def _generic_action(self, action=None): """Do a generic action for real.""" if action: - self._action_to_sdc(action, action_type="lifecycleState") + if action == const.ARCHIVE: + self._action_to_sdc(action, action_type=const.ARCHIVE) + else: + self._action_to_sdc(action, action_type="lifecycleState") def _create_csar_action(self): """Create CSAR package for real.""" @@ -319,6 +329,36 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes return self.send_message_json('GET', 'get vsp version', url) return {} + @classmethod + def _get_all_url(cls) -> str: + """ + Get URL for all elements in SDC. + + Returns: + str: the url + + """ + return f"{cls._base_url()}/items?itemType=vsp" + + def _action_url(self, base: str, subpath: str, version_path: str, + action_type: str = None) -> str: + """Generate action URL for VSP to send to SDC. + + Args: + base (str): base part of vsp action url + subpath (str): subpath of vsp action url + version_path (str): version path. If action is equal to ARCHIVE + it's going to be edited + action_type (str, optional): the type of action. + + Returns: + str: the URL to use + + """ + if action_type == const.ARCHIVE: + version_path = version_path.split("/")[0] + return super()._action_url(base, subpath, version_path, action_type) + @classmethod def import_from_sdc(cls, values: Dict[str, Any]) -> 'Vsp': """ @@ -334,7 +374,7 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes cls._logger.debug("importing VSP %s from SDC", values['name']) vsp = Vsp(values['name']) vsp.identifier = values['id'] - vsp.vendor = Vendor(name=values['vendorName']) + vsp.vendor = Vendor(name=values['properties']['vendorName']) return vsp def _really_submit(self) -> None: diff --git a/src/onapsdk/utils/headers_creator.py b/src/onapsdk/utils/headers_creator.py index 0f1bc79..75fc457 100644 --- a/src/onapsdk/utils/headers_creator.py +++ b/src/onapsdk/utils/headers_creator.py @@ -223,7 +223,7 @@ def headers_sdc_artifact_upload(base_header: Dict[str, str], data: str): headers["Accept"] = "application/json, text/plain, */*" headers["Accept-Encoding"] = "gzip, deflate, br" headers["Content-Type"] = "application/json; charset=UTF-8" - md5_content = hashlib.new('md5', data.encode('UTF-8'), + md5_content = hashlib.new('md5', data.encode('UTF-8'), # nosec usedforsecurity=False).hexdigest() # nosec content = base64.b64encode(md5_content.encode('ascii')).decode('UTF-8') headers["Content-MD5"] = content -- cgit 1.2.3-korg