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

Apply missing coments from PR#1212 #1240

Merged
merged 2 commits into from
Jun 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions convert2rhel/backup/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ def enable(self):

def restore(self):
"""Rollback subscription related changes"""
if not self.enabled:
return

loggerinst.task("Rollback: RHSM-related actions")

if self.enabled:
try:
subscription.unregister_system()
except subscription.UnregisterError as e:
loggerinst.warning(str(e))
except OSError:
loggerinst.warning("subscription-manager not installed, skipping")
try:
subscription.unregister_system()
except subscription.UnregisterError as e:
loggerinst.warning(str(e))
except OSError:
loggerinst.warning("subscription-manager not installed, skipping")

super(RestorableSystemSubscription, self).restore()

Expand All @@ -71,11 +73,15 @@ def __init__(self):
self._is_attached = False

def enable(self):
if self.enabled:
r0x0d marked this conversation as resolved.
Show resolved Hide resolved
return

self._is_attached = subscription.auto_attach_subscription()
super(RestorableAutoAttachmentSubscription, self).enable()

def restore(self):
if self._is_attached:
loggerinst.task("Rollback: Removing auto-attached subscription")
subscription.remove_subscription()
super(RestorableAutoAttachmentSubscription, self).restore()

Expand Down
8 changes: 8 additions & 0 deletions convert2rhel/unit_tests/backup/subscription_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def test_restore_auto_attach_not_enabled(self, auto_attach_subscription, monkeyp
auto_attach_subscription.restore()
assert subscription.remove_subscription.call_count == 0

def test_already_enabled(self, auto_attach_subscription, monkeypatch):
monkeypatch.setattr(subscription, "auto_attach_subscription", mock.Mock())
auto_attach_subscription.enabled = True

auto_attach_subscription.enable()

assert subscription.auto_attach_subscription.call_count == 0


class TestRestorableDisableRepositories:
@pytest.mark.parametrize(
Expand Down