Skip to content

Commit

Permalink
Regression fix: not purged object is not purged after 'purge --local'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cgalibern committed Jul 31, 2023
1 parent 11917cf commit 1b535d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions opensvc/core/objects/svc.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
13 changes: 13 additions & 0 deletions opensvc/tests/commands/svc/test_svc.py
Expand Up @@ -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")
Expand Down

0 comments on commit 1b535d7

Please sign in to comment.