Skip to content

Commit

Permalink
Apply missing coments from PR#1212 (#1240)
Browse files Browse the repository at this point in the history
* Apply missing coments from PR#1212

The following comments are applied in this patch:

- #1212 (comment)
- #1212 (comment)
- #1212 (comment)
  • Loading branch information
r0x0d authored Jun 13, 2024
1 parent 8d66248 commit 9f75793
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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:
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

0 comments on commit 9f75793

Please sign in to comment.