aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2023-03-03 08:11:10 +0000
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2023-03-03 08:24:25 +0000
commit70c6a75709b0001e9ffe26987563e14e3e6c6b3d (patch)
tree0a439f2fa76985e45c42925c1c78504e1ff9b4a9
parent04d216408b1fe94337775a6e528175733d055f25 (diff)
Archive Vendor Software Product
Add a method to archive SDC VSP resource Issue-ID: INT-2193 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: If643ff47e6b7385eff5d745a5896bf4cb76c5c67
-rw-r--r--src/onapsdk/constants.py1
-rw-r--r--src/onapsdk/sdc/__init__.py6
-rw-r--r--src/onapsdk/sdc/sdc_element.py9
-rw-r--r--src/onapsdk/sdc/sdc_resource.py5
-rw-r--r--src/onapsdk/sdc/vsp.py44
-rw-r--r--src/onapsdk/utils/headers_creator.py2
-rw-r--r--tests/test_vsp.py22
7 files changed, 70 insertions, 19 deletions
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."""
@@ -320,6 +330,36 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes
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':
"""
Import Vsp from SDC.
@@ -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
diff --git a/tests/test_vsp.py b/tests/test_vsp.py
index a1aa8a7..fa374fa 100644
--- a/tests/test_vsp.py
+++ b/tests/test_vsp.py
@@ -31,15 +31,15 @@ def test_get_all_no_vsp(mock_send):
assert Vsp.get_all() == []
mock_send.assert_called_once_with(
"GET", 'get Vsps',
- 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products')
+ 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items?itemType=vsp')
@mock.patch.object(Vsp, 'load_status')
@mock.patch.object(Vsp, 'send_message_json')
def test_get_all_some_vsps(mock_send, mock_load_status):
"""Returns a list of vsp."""
mock_send.return_value = {'results':[
- {'name': 'one', 'id': '1234', 'vendorName': 'vspOne'},
- {'name': 'two', 'id': '1235', 'vendorName': 'vspOne'}]}
+ {'name': 'one', 'id': '1234', 'properties': {'vendorName': 'vspOne'}},
+ {'name': 'two', 'id': '1235', 'properties': {'vendorName': 'vspOne'}}]}
assert len(Vsp.get_all()) == 2
vsp_1 = Vsp.get_all()[0]
assert vsp_1.name == "one"
@@ -52,7 +52,7 @@ def test_get_all_some_vsps(mock_send, mock_load_status):
assert vsp_2.created()
mock_send.assert_called_with(
"GET", 'get Vsps',
- 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products')
+ 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items?itemType=vsp')
@mock.patch.object(Vsp, 'created')
def test_init_no_name(mock_created):
@@ -797,3 +797,17 @@ def test_create_new_version(mock_load, mock_send):
"Create new VSP version",
"https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items/1232/versions/4321",
data='{"creationMethod": "major", "description": "New VSP version"}')
+
+
+@mock.patch.object(Vsp, 'load_status')
+@mock.patch.object(Vsp, "send_message")
+def test_archive_vsp(mock_send, mock_load):
+ vsp = Vsp(vendor=mock.MagicMock())
+ vsp._identifier = "1232"
+ vsp._version = "4321"
+ vsp._status = const.CERTIFIED
+ vsp.archive()
+ mock_send.assert_called_once_with("PUT",
+ "ARCHIVE Vsp",
+ "https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items/1232/actions",
+ data='{\n\n "action": "ARCHIVE"\n}')