diff --git a/uaclient/entitlements/base.py b/uaclient/entitlements/base.py index 98e15cb72b..5e227b1b69 100644 --- a/uaclient/entitlements/base.py +++ b/uaclient/entitlements/base.py @@ -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 ) diff --git a/uaclient/entitlements/livepatch.py b/uaclient/entitlements/livepatch.py index 31200d2f7d..2bb6578d95 100644 --- a/uaclient/entitlements/livepatch.py +++ b/uaclient/entitlements/livepatch.py @@ -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 ) diff --git a/uaclient/entitlements/tests/test_livepatch.py b/uaclient/entitlements/tests/test_livepatch.py index ce49abb617..6c6c2913e4 100644 --- a/uaclient/entitlements/tests/test_livepatch.py +++ b/uaclient/entitlements/tests/test_livepatch.py @@ -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"], @@ -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 = [ @@ -547,6 +554,7 @@ def test_enable_continues_when_snap_install_snapd_fails( None, None, None, + None, ] assert entitlement.enable() @@ -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 @@ -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, @@ -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, @@ -804,6 +815,7 @@ def test_enable_alerts_user_that_snapd_does_not_wait_command( stderr=stderr_msg, ), True, + True, ] fake_stdout = io.StringIO() diff --git a/uaclient/snap.py b/uaclient/snap.py index 288716bae2..69c6e3fc5b 100644 --- a/uaclient/snap.py +++ b/uaclient/snap.py @@ -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)