def test_launch_for_type_base(self): self.project.info.name = "core18" self.project.info.type = "base" self.project.info.base = None instance = Multipass(project=self.project, echoer=self.echoer_mock) self.useFixture( fixtures.MockPatchObject( instance, "_get_instance_info", side_effect=[ errors.ProviderInfoError( provider_name="multipass", exit_code=1, stderr=b"error" ), {}, ], ) ) instance.create() self.multipass_cmd_mock().launch.assert_called_once_with( instance_name="snapcraft-core18", cpus="2", mem="2G", disk="256G", image="snapcraft:core18", cloud_init=mock.ANY, )
def test_destroy_instance_with_stop_delay_invalid(self): self.useFixture( fixtures.EnvironmentVariable( "SNAPCRAFT_BUILD_ENVIRONMENT_STOP_TIME", "A")) multipass = Multipass(project=self.project, echoer=self.echoer_mock) multipass.create() self.assertRaises(SnapcraftEnvironmentError, multipass.destroy) self.multipass_cmd_mock().stop.assert_not_called() self.multipass_cmd_mock().delete.assert_not_called()
def test_destroy_instance_with_stop_delay_0(self): self.useFixture( fixtures.EnvironmentVariable( "SNAPCRAFT_BUILD_ENVIRONMENT_STOP_TIME", "0")) multipass = Multipass(project=self.project, echoer=self.echoer_mock) multipass.create() multipass.destroy() self.multipass_cmd_mock().stop.assert_called_once_with( instance_name=self.instance_name) self.multipass_cmd_mock().delete.assert_not_called()
def test_launch_with_disk_from_environment(self): self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT_DISK", "400G")) 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, cpus="2", mem="2G", disk="400G", image="snapcraft:core16", )
def test_launch_with_ram_from_environment(self): self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY", "4G")) 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, cpus=mock.ANY, mem="4G", disk="256G", image="16.04", cloud_init=mock.ANY, )
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, )