Commit 705b3e98 authored by Olya Kalitova's avatar Olya Kalitova Committed by Commit Bot

Remove Crostini after failed configuration during installation

If during Crostini installation default Crostini container is failed to be
configured, removes Crostini at all so that "Retry" button installs
Crostini from the very beginning and Terminal app icon is not available
in a Chrome OS launcher.

Test: unit_tests --gtest_filter="Crostini*"
Bug: 1022784
Change-Id: I8d8c45cf6c39593657963786c117d384a6cecf9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917202
Commit-Queue: Olya Kalitova <okalitova@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720199}
parent bd1c791e
...@@ -377,14 +377,27 @@ void CrostiniInstaller::OnAnsibleSoftwareConfigurationFinished(bool success) { ...@@ -377,14 +377,27 @@ void CrostiniInstaller::OnAnsibleSoftwareConfigurationFinished(bool success) {
if (!success) { if (!success) {
LOG(ERROR) << "Failed to configure container"; LOG(ERROR) << "Failed to configure container";
HandleError(InstallerError::kErrorConfiguringContainer); CrostiniManager::GetForProfile(profile_)->RemoveCrostini(
kCrostiniDefaultVmName,
base::BindOnce(
&CrostiniInstaller::OnCrostiniRemovedAfterConfigurationFailed,
weak_ptr_factory_.GetWeakPtr()));
return; return;
} }
} }
void CrostiniInstaller::OnCrostiniRemovedAfterConfigurationFailed(
CrostiniResult result) {
if (result != CrostiniResult::SUCCESS) {
LOG(ERROR) << "Failed to remove Crostini after failed configuration";
}
HandleError(InstallerError::kErrorConfiguringContainer);
}
void CrostiniInstaller::OnContainerStarted(CrostiniResult result) { void CrostiniInstaller::OnContainerStarted(CrostiniResult result) {
if (result == CrostiniResult::CONTAINER_CONFIGURATION_FAILED) { if (result == CrostiniResult::CONTAINER_CONFIGURATION_FAILED) {
DCHECK_EQ(state_, State::ERROR); LOG(ERROR) << "Container start failed due to failed configuration";
NOTREACHED();
return; return;
} }
......
...@@ -125,6 +125,9 @@ class CrostiniInstaller : public KeyedService, ...@@ -125,6 +125,9 @@ class CrostiniInstaller : public KeyedService,
void OnCrostiniRestartFinished(crostini::CrostiniResult result); void OnCrostiniRestartFinished(crostini::CrostiniResult result);
void OnAvailableDiskSpace(int64_t bytes); void OnAvailableDiskSpace(int64_t bytes);
void OnCrostiniRemovedAfterConfigurationFailed(
crostini::CrostiniResult result);
Profile* profile_; Profile* profile_;
State state_ = State::IDLE; State state_ = State::IDLE;
......
...@@ -236,7 +236,7 @@ TEST_F(CrostiniInstallerTest, InstallFlowWithAnsibleInfra) { ...@@ -236,7 +236,7 @@ TEST_F(CrostiniInstallerTest, InstallFlowWithAnsibleInfra) {
Install(); Install();
base::RunLoop().RunUntilIdle(); task_environment_.RunUntilIdle();
test_helper.SendSucceededApplySignal(); test_helper.SendSucceededApplySignal();
mount_path_waiter_.WaitForMountPathCalled(); mount_path_waiter_.WaitForMountPathCalled();
...@@ -347,4 +347,30 @@ TEST_F(CrostiniInstallerTest, InstallerError) { ...@@ -347,4 +347,30 @@ TEST_F(CrostiniInstallerTest, InstallerError) {
<< "Installer should recover to installable state"; << "Installer should recover to installable state";
} }
TEST_F(CrostiniInstallerTest, InstallerErrorWhileConfiguring) {
AnsibleManagementTestHelper test_helper(profile_.get());
test_helper.SetUpAnsibleInfra();
test_helper.SetUpAnsibleInstallation(
vm_tools::cicerone::InstallLinuxPackageResponse::FAILED);
Expectation expect_progresses =
EXPECT_CALL(mock_callbacks_, OnProgress(_, _)).Times(AnyNumber());
// |OnProgress()| should not happens after |OnFinished()|
EXPECT_CALL(mock_callbacks_,
OnFinished(InstallerError::kErrorConfiguringContainer))
.After(expect_progresses);
Install();
task_environment_.RunUntilIdle();
histogram_tester_.ExpectUniqueSample(
"Crostini.SetupResult",
static_cast<base::HistogramBase::Sample>(
CrostiniInstaller::SetupResult::kErrorConfiguringContainer),
1);
EXPECT_TRUE(crostini_installer_->CanInstall())
<< "Installer should recover to installable state";
}
} // namespace crostini } // namespace crostini
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment