From: beierlm Date: Wed, 18 May 2022 01:25:29 +0000 (-0400) Subject: Bug 2024 X-Git-Tag: v12.0.0rc1~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=bc5a52409c5d3690ebf6810a31662c0846847020;p=osm%2FNBI.git Bug 2024 Creates a rollback for deleting files created before validation failure Fixes Bug 2024 Change-Id: I7c3ab4ace06acad073dac492a25b78c2d5a11427 Signed-off-by: beierlm --- diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 590380a..ddec65c 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -268,6 +268,8 @@ class DescriptorTopic(BaseTopic): # TODO change to Content-Disposition filename https://tools.ietf.org/html/rfc6266 file_pkg = None error_text = "" + fs_rollback = [] + try: if content_range_text: content_range = ( @@ -296,9 +298,10 @@ class DescriptorTopic(BaseTopic): else: self.fs.file_delete(proposed_revision_path, ignore_non_exist=True) self.fs.mkdir(proposed_revision_path) + fs_rollback.append(proposed_revision_path) storage = self.fs.get_params() - storage["folder"] = _id + storage["folder"] = proposed_revision_path file_path = (proposed_revision_path, filename) if self.fs.file_exists(file_path, "file"): @@ -464,17 +467,6 @@ class DescriptorTopic(BaseTopic): self.fs.file_delete(proposed_revision_path, ignore_non_exist=True) raise e - # Copy the revision to the active package name by its original id - shutil.rmtree(self.fs.path + current_revision_path, ignore_errors=True) - os.rename(self.fs.path + proposed_revision_path, self.fs.path + current_revision_path) - self.fs.file_delete(current_revision_path, ignore_non_exist=True) - self.fs.mkdir(current_revision_path) - self.fs.reverse_sync(from_path=current_revision_path) - shutil.rmtree(self.fs.path + _id) - - current_desc["_admin"]["storage"] = storage - current_desc["_admin"]["onboardingState"] = "ONBOARDED" - current_desc["_admin"]["operationalState"] = "ENABLED" indata = self._remove_envelop(indata) @@ -482,18 +474,33 @@ class DescriptorTopic(BaseTopic): if kwargs: self._update_input_with_kwargs(indata, kwargs) + current_desc["_admin"]["storage"] = storage + current_desc["_admin"]["onboardingState"] = "ONBOARDED" + current_desc["_admin"]["operationalState"] = "ENABLED" + current_desc["_admin"]["modified"] = time() + current_desc["_admin"]["revision"] = revision + deep_update_rfc7396(current_desc, indata) current_desc = self.check_conflict_on_edit( session, current_desc, indata, _id=_id ) - current_desc["_admin"]["modified"] = time() - current_desc["_admin"]["revision"] = revision + + # Copy the revision to the active package name by its original id + shutil.rmtree(self.fs.path + current_revision_path, ignore_errors=True) + os.rename(self.fs.path + proposed_revision_path, self.fs.path + current_revision_path) + self.fs.file_delete(current_revision_path, ignore_non_exist=True) + self.fs.mkdir(current_revision_path) + self.fs.reverse_sync(from_path=current_revision_path) + + shutil.rmtree(self.fs.path + _id) + self.db.replace(self.topic, _id, current_desc) # Store a copy of the package as a point in time revision revision_desc = dict(current_desc) revision_desc["_id"] = _id + ":" + str(revision_desc["_admin"]["revision"]) self.db.create(self.topic + "_revisions", revision_desc) + fs_rollback = [] indata["_id"] = _id self._send_msg("edited", indata) @@ -525,6 +532,8 @@ class DescriptorTopic(BaseTopic): finally: if file_pkg: file_pkg.close() + for file in fs_rollback: + self.fs.file_delete(file, ignore_non_exist=True) def get_file(self, session, _id, path=None, accept_header=None): """ diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index aac0b0b..84aeda3 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -557,6 +557,9 @@ class NsrTopic(BaseTopic): "image": [], "affinity-or-anti-affinity-group": [], } + if "revision" in nsd["_admin"]: + nsr_descriptor["revision"] = nsd["_admin"]["revision"] + ns_request["nsr_id"] = nsr_id if ns_request and ns_request.get("config-units"): nsr_descriptor["config-units"] = ns_request["config-units"] diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index f19f44d..29e085a 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -172,7 +172,7 @@ query string: ADMIN: To act as an administrator or a different project PUBLIC: To get public descriptors or set a descriptor as public SET_PROJECT: To make a descriptor available for other project - + Header field name Reference Example Descriptions Accept IETF RFC 7231 [19] application/json Content-Types that are acceptable for the response. This header field shall be present if the response is expected to have a non-empty message body. diff --git a/osm_nbi/tests/test_descriptor_topics.py b/osm_nbi/tests/test_descriptor_topics.py index 6b9b2c3..147f3e7 100755 --- a/osm_nbi/tests/test_descriptor_topics.py +++ b/osm_nbi/tests/test_descriptor_topics.py @@ -202,7 +202,7 @@ class Test_VnfdTopic(TestCase): ) self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state") storage = admin["storage"] - self.assertEqual(storage["folder"], did, "Wrong storage folder") + self.assertEqual(storage["folder"], did + ":1", "Wrong storage folder") self.assertEqual( storage["descriptor"], "package", "Wrong storage descriptor" ) @@ -1406,7 +1406,7 @@ class Test_NsdTopic(TestCase): ) self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state") storage = admin["storage"] - self.assertEqual(storage["folder"], did, "Wrong storage folder") + self.assertEqual(storage["folder"], did + ":1", "Wrong storage folder") self.assertEqual( storage["descriptor"], "package", "Wrong storage descriptor" )