Commit bc5a5240 authored by Mark Beierl's avatar Mark Beierl Committed by garciadeblas
Browse files

Bug 2024



Creates a rollback for deleting files created before validation
failure

Fixes Bug 2024

Change-Id: I7c3ab4ace06acad073dac492a25b78c2d5a11427
Signed-off-by: default avatarbeierlm <mark.beierl@canonical.com>
parent 50e815b3
Loading
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -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):
        """
+3 −0
Original line number Diff line number Diff line
@@ -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"]
+2 −2
Original line number Diff line number Diff line
@@ -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"
                )
+1 −1

File changed.

Contains only whitespace changes.