From 1b535d7ca2968277d4897259e7fe3974d54beefb Mon Sep 17 00:00:00 2001 From: Cyril Galibern Date: Thu, 27 Jul 2023 23:17:22 +0200 Subject: [PATCH] Regression fix: not purged object is not purged after 'purge --local' call_action -> self.setup_environ -> os.environ['OPENSVC_SVC_ID'] = self.id -> create object if object is absent and not self.volatile So after purge/delete action the object is recreated The regression was introduced by #817b97660894971e18689393c6090d1a57a901c6 Reproduce bug with: om foo create om foo purge --local om foo ls --- opensvc/core/objects/svc.py | 9 +++++++++ opensvc/tests/commands/svc/test_svc.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/opensvc/core/objects/svc.py b/opensvc/core/objects/svc.py index 5a1bb50e0..b521558aa 100644 --- a/opensvc/core/objects/svc.py +++ b/opensvc/core/objects/svc.py @@ -730,6 +730,12 @@ def freezer(self): @lazy def id(self): + """ + return object id: + When object has no id a new id is created and if object is not volatile + the object config file is updated. + id should not be called on deleted object else new empty object will be created + """ try: return self.conf_get("DEFAULT", "id") except ex.OptNotFound as exc: @@ -2638,6 +2644,9 @@ def print_status(self): format_instance(self.path, data, mon_data=mon_data, discard_disabled=discard_disabled, nodename=nodename) def purge(self): + # Set volatile value to True to prevent config file re-creation after deletion (call to self.id will + # update/create config file when DEFAULT.id option is not found) + self.volatile = True self.options.unprovision = True self.delete() diff --git a/opensvc/tests/commands/svc/test_svc.py b/opensvc/tests/commands/svc/test_svc.py index e0717c079..9d9a8f366 100644 --- a/opensvc/tests/commands/svc/test_svc.py +++ b/opensvc/tests/commands/svc/test_svc.py @@ -4,6 +4,19 @@ from commands.svc import Mgr +@pytest.mark.ci +@pytest.mark.usefixtures("osvc_path_tests") +@pytest.mark.usefixtures("has_euid_0") +class TestPurgeLocal: + @staticmethod + def test_object_is_not_recreated_after_local_purge(): + svcname = "pytest" + assert Mgr()(argv=["-s", svcname, "create"]) == 0 + assert Mgr()(argv=["-s", svcname, "ls"]) == 0 + assert Mgr()(argv=["-s", svcname, "purge", "--local"]) == 0 + assert Mgr()(argv=["-s", svcname, "ls"]) > 0 + + @pytest.mark.ci @pytest.mark.usefixtures("osvc_path_tests") @pytest.mark.usefixtures("has_euid_0")