Commit 521940cd authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Enable DLC for termina

Concierge now supports a dlc_id parameter to boot a trusted VM from a
DLC. Set this when the crostini dlc flag is enabled. With this CL it
is now possible to use termina-dlc on any board with dlc enabled.

Bug: chromium:953544
Change-Id: I95fba796e6f80f10e308dd306b5ef1befd416e62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2397455
Auto-Submit: Fergus Dall <sidereal@google.com>
Commit-Queue: Nic Hollingum <hollingum@google.com>
Reviewed-by: default avatarNic Hollingum <hollingum@google.com>
Cr-Commit-Position: refs/heads/master@{#805155}
parent d8bbe351
......@@ -1181,6 +1181,10 @@ void CrostiniManager::StartTerminaVm(std::string name,
}
vm_tools::concierge::StartVmRequest request;
base::Optional<std::string> dlc_id = termina_installer_.GetDlcId();
if (dlc_id.has_value()) {
request.mutable_vm()->set_dlc_id(*dlc_id);
}
request.set_name(std::move(name));
request.set_start_termina(true);
request.set_owner_id(owner_id_);
......
......@@ -160,6 +160,15 @@ class CrostiniManagerTest : public testing::Test {
std::move(closure).Run();
}
void EnsureTerminaInstalled() {
base::RunLoop run_loop;
crostini_manager()->InstallTermina(
base::BindOnce([](base::OnceClosure callback,
CrostiniResult) { std::move(callback).Run(); },
run_loop.QuitClosure()));
run_loop.Run();
}
CrostiniManagerTest()
: task_environment_(content::BrowserTaskEnvironment::REAL_IO_THREAD),
local_state_(std::make_unique<ScopedTestingLocalState>(
......@@ -432,6 +441,7 @@ TEST_F(CrostiniManagerTest, StartTerminaVmMountError) {
response.set_mount_result(vm_tools::concierge::StartVmResponse::FAILURE);
fake_concierge_client_->set_start_vm_response(response);
EnsureTerminaInstalled();
crostini_manager()->StartTerminaVm(
kVmName, disk_path, 0,
base::BindOnce(&ExpectFailure, run_loop()->QuitClosure()));
......@@ -451,6 +461,7 @@ TEST_F(CrostiniManagerTest, StartTerminaVmMountErrorThenSuccess) {
vm_tools::concierge::StartVmResponse::PARTIAL_DATA_LOSS);
fake_concierge_client_->set_start_vm_response(response);
EnsureTerminaInstalled();
crostini_manager()->StartTerminaVm(
kVmName, disk_path, 0,
base::BindOnce(&ExpectSuccess, run_loop()->QuitClosure()));
......@@ -464,6 +475,7 @@ TEST_F(CrostiniManagerTest, StartTerminaVmSuccess) {
base::HistogramTester histogram_tester{};
const base::FilePath& disk_path = base::FilePath(kVmName);
EnsureTerminaInstalled();
crostini_manager()->StartTerminaVm(
kVmName, disk_path, 0,
base::BindOnce(&ExpectSuccess, run_loop()->QuitClosure()));
......@@ -477,6 +489,7 @@ TEST_F(CrostiniManagerTest, OnStartTremplinRecordsRunningVm) {
const std::string owner_id = CryptohomeIdForProfile(profile());
// Start the Vm.
EnsureTerminaInstalled();
crostini_manager()->StartTerminaVm(
kVmName, disk_path, 0,
base::BindOnce(&ExpectSuccess, run_loop()->QuitClosure()));
......
......@@ -43,9 +43,11 @@ void TerminaInstaller::Install(
if (base::FeatureList::IsEnabled(chromeos::features::kCrostiniUseDlc)) {
RemoveComponentIfPresent(std::move(remove_callback), uninstall_result_ptr);
InstallDlc(std::move(callback));
dlc_id_ = kCrostiniDlcName;
} else {
RemoveDlcIfPresent(std::move(remove_callback), uninstall_result_ptr);
InstallComponent(std::move(callback));
dlc_id_ = base::nullopt;
}
}
......@@ -308,4 +310,9 @@ base::FilePath TerminaInstaller::GetInstallLocation() {
return *termina_location_;
}
base::Optional<std::string> TerminaInstaller::GetDlcId() {
CHECK(termina_location_) << "GetDlcId() called while termina not installed";
return dlc_id_;
}
} // namespace crostini
......@@ -54,6 +54,9 @@ class TerminaInstaller {
// get a Success response back before calling this method.
base::FilePath GetInstallLocation();
// Get the id of the installed DLC, or nullopt if DLC is not being used.
base::Optional<std::string> GetDlcId();
private:
void InstallDlc(base::OnceCallback<void(InstallResult)> callback);
void OnInstallDlc(base::OnceCallback<void(InstallResult)> callback,
......@@ -80,6 +83,7 @@ class TerminaInstaller {
bool component_update_check_needed_{true};
base::Optional<base::FilePath> termina_location_{base::nullopt};
base::Optional<std::string> dlc_id_{};
base::WeakPtrFactory<TerminaInstaller> weak_ptr_factory_{this};
};
......
......@@ -110,6 +110,7 @@ class TerminaInstallTest : public testing::Test {
EXPECT_EQ(termina_installer_.GetInstallLocation(),
base::FilePath(dlc_root_path_));
EXPECT_EQ(termina_installer_.GetDlcId(), "termina-dlc");
run_loop.Run();
}
......@@ -310,6 +311,7 @@ TEST_F(TerminaComponentInstallTest, InstallComponent) {
EXPECT_TRUE(component_manager_->IsRegisteredMayBlock(
imageloader::kTerminaComponentName));
EXPECT_EQ(termina_installer_.GetInstallLocation(), component_mount_path_);
EXPECT_EQ(termina_installer_.GetDlcId(), base::nullopt);
}
TEST_F(TerminaComponentInstallTest, InstallComponentOffline) {
......@@ -336,6 +338,7 @@ TEST_F(TerminaComponentInstallTest, InstallComponentWithDlcInstalled) {
imageloader::kTerminaComponentName));
CheckDlcNotInstalled();
EXPECT_EQ(termina_installer_.GetInstallLocation(), component_mount_path_);
EXPECT_EQ(termina_installer_.GetDlcId(), base::nullopt);
}
TEST_F(TerminaComponentInstallTest, InstallComponentWithDlcInstalledError) {
......@@ -350,6 +353,7 @@ TEST_F(TerminaComponentInstallTest, InstallComponentWithDlcInstalledError) {
EXPECT_TRUE(component_manager_->IsRegisteredMayBlock(
imageloader::kTerminaComponentName));
EXPECT_EQ(termina_installer_.GetInstallLocation(), component_mount_path_);
EXPECT_EQ(termina_installer_.GetDlcId(), base::nullopt);
}
TEST_F(TerminaComponentInstallTest, LoadComponentAlreadyInstalled) {
......
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