Skip to content

Commit

Permalink
livepatch: refresh snapd before installing livepatch
Browse files Browse the repository at this point in the history
  • Loading branch information
orndorffgrant committed Feb 13, 2024
1 parent 4e9a479 commit ae56423
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions uaclient/entitlements/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,16 @@ def handle_required_snaps(self) -> bool:

snap.run_snapd_wait_cmd()

try:
snap.refresh_snap("snapd")
except exceptions.ProcessExecutionError as e:
LOG.warning("Failed to refresh snapd snap", exc_info=e)
event.info(
messages.EXECUTING_COMMAND_FAILED.format(
command="snap refresh snapd"
)
)

http_proxy = http.validate_proxy(
"http", self.cfg.http_proxy, http.PROXY_VALIDATION_SNAP_HTTP_URL
)
Expand Down
10 changes: 10 additions & 0 deletions uaclient/entitlements/livepatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ def _perform_enable(self, silent: bool = False) -> bool:

snap.run_snapd_wait_cmd()

try:
snap.refresh_snap("snapd")
except exceptions.ProcessExecutionError as e:
LOG.warning("Failed to refresh snapd snap", exc_info=e)
event.info(
messages.EXECUTING_COMMAND_FAILED.format(
command="snap refresh snapd"
)
)

http_proxy = http.validate_proxy(
"http", self.cfg.http_proxy, http.PROXY_VALIDATION_SNAP_HTTP_URL
)
Expand Down
12 changes: 12 additions & 0 deletions uaclient/entitlements/tests/test_livepatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ class TestLivepatchEntitlementEnable:
["/usr/bin/snap", "wait", "system", "seed.loaded"], capture=True
)
]
mocks_snapd_refresh = [
mock.call(
["/usr/bin/snap", "refresh", "snapd"],
capture=True,
)
]
mocks_livepatch_install = [
mock.call(
["/usr/bin/snap", "install", "canonical-livepatch"],
Expand All @@ -409,6 +415,7 @@ class TestLivepatchEntitlementEnable:
mocks_snapd_install
+ mocks_snapd_install_as_a_snap
+ mocks_snap_wait_seed
+ mocks_snapd_refresh
+ mocks_livepatch_install
)
mocks_config = [
Expand Down Expand Up @@ -547,6 +554,7 @@ def test_enable_continues_when_snap_install_snapd_fails(
None,
None,
None,
None,
]

assert entitlement.enable()
Expand Down Expand Up @@ -601,6 +609,7 @@ def test_enable_installs_only_livepatch_snap_when_absent_but_snapd_present(
assert entitlement.enable()
assert (
self.mocks_snap_wait_seed
+ self.mocks_snapd_refresh
+ self.mocks_livepatch_install
+ self.mocks_config
in m_subp.call_args_list
Expand Down Expand Up @@ -653,6 +662,7 @@ def test_enable_does_not_install_livepatch_snap_when_present(
mock.call(
[SNAP_CMD, "wait", "system", "seed.loaded"], capture=True
),
mock.call([SNAP_CMD, "refresh", "snapd"], capture=True),
mock.call(
[
livepatch.LIVEPATCH_CMD,
Expand Down Expand Up @@ -712,6 +722,7 @@ def test_enable_does_not_disable_inactive_livepatch_snap_when_present(
mock.call(
[SNAP_CMD, "wait", "system", "seed.loaded"], capture=True
),
mock.call([SNAP_CMD, "refresh", "snapd"], capture=True),
mock.call(
[
livepatch.LIVEPATCH_CMD,
Expand Down Expand Up @@ -804,6 +815,7 @@ def test_enable_alerts_user_that_snapd_does_not_wait_command(
stderr=stderr_msg,
),
True,
True,
]

fake_stdout = io.StringIO()
Expand Down
4 changes: 4 additions & 0 deletions uaclient/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def install_snap(
)


def refresh_snap(snap: str):
system.subp([SNAP_CMD, "refresh", snap], capture=True)


def get_snap_info(snap: str) -> SnapPackage:
snap_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
snap_sock.connect(SNAPD_SOCKET_PATH)
Expand Down

0 comments on commit ae56423

Please sign in to comment.