def test_snapcraft_not_installed_on_host(self): self.useFixture(fixture_setup.FakeStore()) snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() self.get_assertion_mock.assert_not_called() self.provider.run_mock.assert_has_calls([ call(["snap", "set", "system", ANY]), call(["snap", "watch", "--last=auto-refresh?"]), call(["snap", "install", "--channel", "stable", "core"]), call([ "snap", "install", "--classic", "--channel", "stable", "snapcraft" ]), ]) self.provider.push_file_mock.assert_not_called() self.assertThat( self.registry_filepath, FileContains( dedent("""\ core: - revision: '10000' snapcraft: - revision: '25' """)), )
def test_snapcraft_installed_on_host_from_store_rerun_refreshes(self): self.useFixture(fixture_setup.FakeStore()) snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() self.provider.run_mock.reset_mock() snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() self.provider.run_mock.assert_has_calls([ call(["snap", "set", "system", ANY]), call(["snap", "watch", "--last=auto-refresh?"]), call(["snap", "refresh", "--channel", "stable", "core"]), call([ "snap", "refresh", "--classic", "--channel", "stable", "snapcraft" ]), ])
def test_snapd_not_on_host_installs_from_store(self): self.useFixture(fixture_setup.FakeStore()) snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") with patch( "snapcraft_legacy.internal.repo.snaps.SnapPackage.get_local_snap_info", side_effect=repo.errors.SnapdConnectionError("core", "url"), ): snap_injector.apply() self.get_assertion_mock.assert_not_called() self.provider.run_mock.assert_has_calls([ call(["snap", "set", "system", ANY]), call(["snap", "watch", "--last=auto-refresh?"]), call(["snap", "install", "--channel", "stable", "core"]), call([ "snap", "install", "--classic", "--channel", "stable", "snapcraft" ]), ]) self.provider.push_file_mock.assert_not_called() self.assertThat( self.registry_filepath, FileContains( dedent("""\ core: - revision: '10000' snapcraft: - revision: '25' """)), )
def test_snapcraft_installed_on_host_from_store_rerun_is_nop(self): self.fake_snapd.snaps_result = [ { "name": "core", "confinement": "strict", "id": "2kkitQ", "channel": "stable", "revision": "123", }, { "name": "snapcraft", "confinement": "classic", "id": "3lljuR", "channel": "edge", "revision": "345", }, ] self.get_assertion_mock.side_effect = [ b"fake-assertion-account-store", b"fake-assertion-declaration-core", b"fake-assertion-revision-core-123", b"fake-assertion-account-store", b"fake-assertion-declaration-snapcraft", b"fake-assertion-revision-snapcraft-345", ] snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() self.provider.run_mock.reset_mock() snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() self.provider.run_mock.assert_not_called()
def test_snapcraft_installed_on_host_from_store(self): self.fake_snapd.snaps_result = [ { "name": "snapd", "confinement": "strict", "id": "2kkitQ", "channel": "edge", "revision": "1", "tracking-channel": "latest/edge", }, { "name": "core18", "confinement": "strict", "id": "2kkibb", "channel": "stable", "revision": "123", "tracking-channel": "latest/beta", }, { "name": "snapcraft", "confinement": "classic", "id": "3lljuR", "channel": "edge", "revision": "345", "tracking-channel": "latest/candidate", }, ] self.get_assertion_mock.side_effect = [ b"fake-assertion-account-store", b"fake-assertion-declaration-snapd", b"fake-assertion-revision-snapd-1", b"fake-assertion-account-store", b"fake-assertion-declaration-core18", b"fake-assertion-revision-core18-123", b"fake-assertion-account-store", b"fake-assertion-declaration-snapcraft", b"fake-assertion-revision-snapcraft-345", ] snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("snapd") snap_injector.add("core18") snap_injector.add("snapcraft") snap_injector.apply() get_assertion_calls = [ call([ "account-key", "public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul", ]), call(["snap-declaration", "snap-name=snapd"]), call(["snap-revision", "snap-revision=1", "snap-id=2kkitQ"]), call([ "account-key", "public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul", ]), call(["snap-declaration", "snap-name=core18"]), call(["snap-revision", "snap-revision=123", "snap-id=2kkibb"]), call([ "account-key", "public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul", ]), call(["snap-declaration", "snap-name=snapcraft"]), call(["snap-revision", "snap-revision=345", "snap-id=3lljuR"]), ] self.get_assertion_mock.assert_has_calls(get_assertion_calls) self.provider.run_mock.assert_has_calls([ call(["snap", "set", "system", "experimental.snapd-snap=true"]), call(["snap", "set", "system", ANY]), call(["snap", "watch", "--last=auto-refresh?"]), call(["snap", "ack", "/var/tmp/snapd.assert"]), call(["snap", "install", "/var/tmp/snapd.snap"]), call(["snap", "switch", "snapd", "--channel", "latest/edge"]), call(["snap", "ack", "/var/tmp/core18.assert"]), call(["snap", "install", "/var/tmp/core18.snap"]), call(["snap", "switch", "core18", "--channel", "latest/beta"]), call(["snap", "ack", "/var/tmp/snapcraft.assert"]), call(["snap", "install", "--classic", "/var/tmp/snapcraft.snap"]), call([ "snap", "switch", "snapcraft", "--channel", "latest/candidate" ]), ]) self.provider.push_file_mock.assert_has_calls([ call(source=ANY, destination="/var/tmp/snapd.snap"), call(source=ANY, destination="/var/tmp/snapd.assert"), call(source=ANY, destination="/var/tmp/core18.snap"), call(source=ANY, destination="/var/tmp/core18.assert"), call(source=ANY, destination="/var/tmp/snapcraft.snap"), call(source=ANY, destination="/var/tmp/snapcraft.assert"), ]) self.assertThat( self.registry_filepath, FileContains( dedent("""\ core18: - revision: '123' snapcraft: - revision: '345' snapd: - revision: '1' """)), )
def test_snapcraft_installed_on_host_with_dangerous(self): self.fake_snapd.snaps_result = [ { "name": "core", "confinement": "strict", "id": "2kkitQ", "channel": "stable", "revision": "123", }, { "name": "snapcraft", "confinement": "classic", "revision": "x20", "tracking-channel": "latest/stable", }, ] self.get_assertion_mock.side_effect = [ b"fake-assertion-account-store", b"fake-assertion-declaration-core", b"fake-assertion-revision-core-123", ] snap_injector = SnapInjector( registry_filepath=self.registry_filepath, runner=self.provider._run, file_pusher=self.provider._push_file, ) snap_injector.add("core") snap_injector.add("snapcraft") snap_injector.apply() get_assertion_calls = [ call([ "account-key", "public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul", ]), call(["snap-declaration", "snap-name=core"]), call(["snap-revision", "snap-revision=123", "snap-id=2kkitQ"]), ] self.get_assertion_mock.assert_has_calls(get_assertion_calls) # Check the call count to ensure the snap switch command does not sneak in. self.assertThat(self.provider.run_mock.call_count, Equals(6)) self.provider.run_mock.assert_has_calls([ call(["snap", "set", "system", ANY]), call(["snap", "watch", "--last=auto-refresh?"]), call(["snap", "ack", "/var/tmp/core.assert"]), call(["snap", "install", "/var/tmp/core.snap"]), call(["snap", "ack", "/var/tmp/snapcraft.assert"]), call([ "snap", "install", "--dangerous", "--classic", "/var/tmp/snapcraft.snap", ]), ]) self.assertThat( self.registry_filepath, FileContains( dedent("""\ core: - revision: '123' snapcraft: - revision: x20 """)), ) self.provider.push_file_mock.assert_has_calls([ call(source=ANY, destination="/var/tmp/core.snap"), call(source=ANY, destination="/var/tmp/core.assert"), call(source=ANY, destination="/var/tmp/snapcraft.snap"), call(source=ANY, destination="/var/tmp/snapcraft.assert"), ])