Skip to content

Commit

Permalink
Setup snapd for snapcraft_legacy providers (#3962)
Browse files Browse the repository at this point in the history
providers: setup and wait for snapd to be ready for snapcraft_legacy

Injecting a new version of snapd into a core18 environment can cause an
error when setting or unsetting the snapd proxy. This is resolved by
porting snapd setup code from `craft-providers` to snapcraft_legacy.

Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal authored Nov 2, 2022
1 parent f378ec3 commit 6122e30
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions snapcraft_legacy/internal/build_providers/_base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def launch_instance(self) -> None:
# what is on the host.
self._setup_snapcraft()

self._setup_snapd()

# Always update snapd proxy settings to match current http(s) proxy
# settings.
self._setup_snapd_proxy()
Expand Down Expand Up @@ -507,6 +509,16 @@ def _setup_snapcraft(self) -> None:

snap_injector.apply()

def _setup_snapd(self) -> None:
"""Configure snapd and wait until ready."""
self._run(["systemctl", "start", "snapd.socket"])

# Restart, not start, the service in case the environment
# has changed and the service is already running.
self._run(["systemctl", "restart", "snapd.service"])

self._run(["snap", "wait", "system", "seed.loaded"])

def _setup_snapd_proxy(self) -> None:
"""Configure snapd proxy settings from http(s)_proxy."""
http_proxy = self.build_provider_flags.get("http_proxy")
Expand Down
3 changes: 3 additions & 0 deletions tests/legacy/unit/build_providers/lxd/test_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ def test_create(self):
["apt-get", "update"],
["apt-get", "dist-upgrade", "--yes"],
["apt-get", "install", "--yes", "apt-transport-https"],
["systemctl", "start", "snapd.socket"],
["systemctl", "restart", "snapd.service"],
["snap", "wait", "system", "seed.loaded"],
["snap", "unset", "system", "proxy.http"],
["snap", "unset", "system", "proxy.https"],
]
Expand Down
14 changes: 14 additions & 0 deletions tests/legacy/unit/build_providers/test_base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def test_launch_instance(self):
call(["apt-get", "update"]),
call(["apt-get", "dist-upgrade", "--yes"]),
call(["apt-get", "install", "--yes", "apt-transport-https"]),
call(["systemctl", "start", "snapd.socket"]),
call(["systemctl", "restart", "snapd.service"]),
call(["snap", "wait", "system", "seed.loaded"]),
call(["snap", "unset", "system", "proxy.http"]),
call(["snap", "unset", "system", "proxy.https"]),
]
Expand Down Expand Up @@ -321,6 +324,17 @@ def test_start_instance(self):
# TODO add robustness to start. (LP: #1792242)
self.assertThat(provider.provider_project_dir, Not(DirExists()))

def test_setup_snapd(self):
provider = ProviderImpl(project=self.project, echoer=self.echoer_mock)
provider.launch_instance()

# False.
provider.run_mock.assert_has_calls == [
call(["systemctl", "start", "snapd.socket"]),
call(["systemctl", "restart", "snapd.service"]),
call(["snap", "wait", "system", "seed.loaded"]),
]

def test_clean_part(self):
provider = ProviderImpl(project=self.project, echoer=self.echoer_mock)

Expand Down

0 comments on commit 6122e30

Please sign in to comment.