示例#1
0
    def test_snapcraft_installed_on_host_from_store_rerun_refreshes(self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            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,
            snap_arch="amd64",
            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"]
                ),
            ]
        )
示例#2
0
    def test_snapcraft_not_installed_on_host(self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            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", "experimental.snapd-snap=true"]),
            call(["snap", "set", "core", 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'
                    """)),
        )
示例#3
0
    def test_snapd_not_on_host_installs_from_store(self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            snap_dir=self.provider._SNAPS_MOUNTPOINT,
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            runner=self.provider._run,
            snap_dir_mounter=self.provider._mount_snaps_directory,
            snap_dir_unmounter=self.provider._unmount_snaps_directory,
            file_pusher=self.provider._push_file,
        )
        snap_injector.add("core")
        snap_injector.add("snapcraft")

        with patch(
            "snapcraft.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", "core", ANY]),
                call(["snap", "watch", "--last=auto-refresh"]),
                call(["snap", "install", "--channel", "latest/stable", "core"]),
                call(
                    [
                        "snap",
                        "install",
                        "--classic",
                        "--channel",
                        "latest/stable",
                        "snapcraft",
                    ]
                ),
            ]
        )
        self.provider.mount_mock.assert_not_called()
        self.provider.unmount_mock.assert_not_called()
        self.provider.push_file_mock.assert_not_called()
        self.assertThat(
            self.registry_filepath,
            FileContains(
                dedent(
                    """\
                    core:
                    - revision: '10000'
                    snapcraft:
                    - revision: '25'
                    """
                )
            ),
        )
示例#4
0
    def test_snapcraft_not_installed_on_host_with_channel_from_environment(self):
        self.useFixture(fixture_setup.FakeStore())
        self.useFixture(
            fixtures.EnvironmentVariable(
                "SNAPCRAFT_BUILD_ENVIRONMENT_CHANNEL_SNAPCRAFT", "latest/edge"
            )
        )

        snap_injector = SnapInjector(
            snap_dir=self.provider._SNAPS_MOUNTPOINT,
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            runner=self.provider._run,
            snap_dir_mounter=self.provider._mount_snaps_directory,
            snap_dir_unmounter=self.provider._unmount_snaps_directory,
            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", "core", ANY]),
                call(["snap", "watch", "--last=auto-refresh"]),
                call(["snap", "install", "--channel", "latest/stable", "core"]),
                call(
                    [
                        "snap",
                        "install",
                        "--classic",
                        "--channel",
                        "latest/edge",
                        "snapcraft",
                    ]
                ),
            ]
        )
        self.provider.mount_mock.assert_not_called()
        self.provider.unmount_mock.assert_not_called()
        self.provider.push_file_mock.assert_not_called()
        self.assertThat(
            self.registry_filepath,
            FileContains(
                dedent(
                    """\
                    core:
                    - revision: '10000'
                    snapcraft:
                    - revision: '25'
                    """
                )
            ),
        )
示例#5
0
    def test_no_registry(self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            snap_dir=self.provider._SNAPS_MOUNTPOINT,
            registry_filepath=None,
            snap_arch="amd64",
            runner=self.provider._run,
            snap_dir_mounter=self.provider._mount_snaps_directory,
            snap_dir_unmounter=self.provider._unmount_snaps_directory,
            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", "core", ANY]),
            call(["snap", "watch", "--last=auto-refresh"]),
            call(["snap", "install", "--channel", "stable", "core"]),
            call([
                "snap", "install", "--classic", "--channel", "stable",
                "snapcraft"
            ]),
        ])
        self.provider.run_mock.reset_mock()

        snap_injector = SnapInjector(
            snap_dir=self.provider._SNAPS_MOUNTPOINT,
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            runner=self.provider._run,
            snap_dir_mounter=self.provider._mount_snaps_directory,
            snap_dir_unmounter=self.provider._unmount_snaps_directory,
            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", "core", ANY]),
            call(["snap", "watch", "--last=auto-refresh"]),
            call(["snap", "install", "--channel", "stable", "core"]),
            call([
                "snap", "install", "--classic", "--channel", "stable",
                "snapcraft"
            ]),
        ])
示例#6
0
    def test_no_registry(self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            registry_filepath=None,
            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", "install", "--channel", "stable", "core"]),
            call([
                "snap", "install", "--classic", "--channel", "stable",
                "snapcraft"
            ]),
        ])
        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", "install", "--channel", "stable", "core"]),
            call([
                "snap", "install", "--classic", "--channel", "stable",
                "snapcraft"
            ]),
        ])
示例#7
0
    def test_snapcraft_installed_on_host_from_store_but_injection_disabled(
            self):
        self.useFixture(fixture_setup.FakeStore())

        snap_injector = SnapInjector(
            snap_dir=self.provider._SNAPS_MOUNTPOINT,
            registry_filepath=self.registry_filepath,
            snap_arch="amd64",
            runner=self.provider._run,
            snap_dir_mounter=self.provider._mount_snaps_directory,
            snap_dir_unmounter=self.provider._unmount_snaps_directory,
            file_pusher=self.provider._push_file,
            inject_from_host=False,
        )
        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", "core", ANY]),
            call(["snap", "watch", "--last=auto-refresh"]),
            call(["snap", "install", "--channel", "stable", "core"]),
            call([
                "snap", "install", "--classic", "--channel", "stable",
                "snapcraft"
            ]),
        ])
        self.provider.mount_mock.assert_not_called()
        self.provider.unmount_mock.assert_not_called()
        self.provider.push_file_mock.assert_not_called()
        self.assertThat(
            self.registry_filepath,
            FileContains(
                dedent("""\
                    core:
                    - revision: '10000'
                    snapcraft:
                    - revision: '25'
                    """)),
        )
示例#8
0
 def setUp(self):
     super().setUp()
     self.fake_store = fixture_setup.FakeStore()
     self.useFixture(self.fake_store)
     self.client = storeapi.StoreClient()