Esempio n. 1
0
    def start(self, *, instance_name: str) -> None:
        """Passthrough for running multipass start.

        :param str instance_name: the name of the instance to start.
        """
        cmd = [self.provider_cmd, "start", instance_name]
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderStartError(
                provider_name=self.provider_name, exit_code=process_error.returncode
            ) from process_error
Esempio n. 2
0
    def test_launch_with_disk_from_environment(self):
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT_DISK", "400G")
        )
        self.multipass_cmd_mock().start.side_effect = errors.ProviderStartError(
            provider_name="multipass", exit_code=1
        )

        instance = Multipass(project=self.project, echoer=self.echoer_mock)
        instance.create()

        self.multipass_cmd_mock().launch.assert_called_once_with(
            instance_name=self.instance_name,
            mem="2G",
            disk="400G",
            image="16.04",
            cloud_init=mock.ANY,
        )
Esempio n. 3
0
    def setUp(self):
        super().setUp()

        patcher = mock.patch(
            "snapcraft.internal.build_providers._multipass."
            "_multipass.MultipassCommand",
            spec=MultipassCommand,
        )
        self.multipass_cmd_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch(
            "snapcraft.internal.build_providers._multipass._multipass._get_platform",
            return_value="darwin",
        )
        patcher.start()
        self.addCleanup(patcher.stop)

        self.multipass_cmd_mock().start.side_effect = errors.ProviderStartError(
            provider_name="multipass", exit_code=1
        )

        # default data returned for info
        self.multipass_cmd_mock().info.return_value = _DEFAULT_INSTANCE_INFO.encode()
Esempio n. 4
0
    def setUp(self):
        super().setUp()

        patcher = mock.patch(
            "snapcraft.internal.build_providers._multipass._multipass._get_platform",
            return_value=self.platform,
        )
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch(
            "snapcraft.internal.build_providers._multipass."
            "_multipass.MultipassCommand",
            spec=MultipassCommand,
        )
        self.multipass_cmd_mock = patcher.start()
        self.addCleanup(patcher.stop)

        self.project = get_project(base=self.base)

        def execute_effect(*, command, instance_name, hide_output):
            if command == ["printenv", "HOME"]:
                return "/home/multipass".encode()
            elif hide_output:
                return None
            else:
                return b""

        self.multipass_cmd_mock().execute.side_effect = execute_effect

        self.multipass_cmd_mock().start.side_effect = errors.ProviderStartError(
            provider_name="multipass", exit_code=1
        )

        # default data returned for info
        self.multipass_cmd_mock().info.return_value = _DEFAULT_INSTANCE_INFO.encode()
Esempio n. 5
0
    def test_ephemeral_instance_with_contextmanager(self):
        self.multipass_cmd_mock().start.side_effect = errors.ProviderStartError(
            provider_name="multipass", exit_code=1
        )

        with Multipass(
            project=self.project, echoer=self.echoer_mock, is_ephemeral=True
        ) as instance:
            instance.provision_project("source.tar")
            instance.build_project()
            instance.retrieve_snap()

        self.multipass_cmd_mock().launch.assert_called_once_with(
            instance_name=self.instance_name,
            mem="2G",
            disk="256G",
            image="16.04",
            cloud_init=mock.ANY,
        )
        # Given SnapInjector is mocked, we only need to verify the commands
        # called from the Multipass class.
        self.multipass_cmd_mock().execute.assert_has_calls(
            [
                mock.call(
                    instance_name=self.instance_name, command=["mkdir", "~/project"]
                ),
                mock.call(
                    instance_name=self.instance_name,
                    command=["tar", "-xvf", "source.tar", "-C", "~/project"],
                ),
                mock.call(
                    instance_name=self.instance_name,
                    command=[
                        "snapcraft",
                        "snap",
                        "--output",
                        "project-name_{}.snap".format(self.project.deb_arch),
                    ],
                ),
            ]
        )
        self.multipass_cmd_mock().info.assert_called_once_with(
            instance_name=self.instance_name, output_format="json"
        )

        self.multipass_cmd_mock().copy_files.assert_has_calls(
            [
                mock.call(
                    destination="{}:source.tar".format(self.instance_name),
                    source="source.tar",
                ),
                mock.call(
                    destination="project-name_{}.snap".format(self.project.deb_arch),
                    source="{}:~/project/project-name_{}.snap".format(
                        self.instance_name, self.project.deb_arch
                    ),
                ),
            ]
        )
        self.multipass_cmd_mock().stop.assert_called_once_with(
            instance_name=self.instance_name
        )
        self.multipass_cmd_mock().delete.assert_called_once_with(
            instance_name=self.instance_name, purge=True
        )