Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix purge --local regression #625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions opensvc/core/objects/svc.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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