Commit 668d3947 authored by Olya Kalitova's avatar Olya Kalitova Committed by Commit Bot

Propagate CrostiniAnsiblePlaybook policy value to Crostinimanager

Propagates CrostiniAnsiblePlaybook policy value to CrostiniManager so
playbook applied to the default Crostini container during its
startup is the one specified by policy.

Test: unit_tests --gtest_filter="Crostini*"
Bug: 973793
Change-Id: I680faa6e3d570eab502d797633a39a12b8a3d6fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879298
Commit-Queue: Olya Kalitova <okalitova@chromium.org>
Reviewed-by: default avatarNic Hollingum <hollingum@google.com>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709865}
parent 2cb5cb3b
...@@ -2077,7 +2077,7 @@ void CrostiniManager::OnContainerStarted( ...@@ -2077,7 +2077,7 @@ void CrostiniManager::OnContainerStarted(
// pre-determined configuration to the default container. // pre-determined configuration to the default container.
if (signal.vm_name() == kCrostiniDefaultVmName && if (signal.vm_name() == kCrostiniDefaultVmName &&
signal.container_name() == kCrostiniDefaultContainerName && signal.container_name() == kCrostiniDefaultContainerName &&
IsCrostiniAnsibleInfrastructureEnabled()) { ShouldConfigureDefaultContainer(profile_)) {
AddLinuxPackageOperationProgressObserver( AddLinuxPackageOperationProgressObserver(
AnsibleManagementService::GetForProfile(profile_)); AnsibleManagementService::GetForProfile(profile_));
...@@ -2106,10 +2106,22 @@ void CrostiniManager::OnAnsibleInDefaultContainerInstalled(bool success) { ...@@ -2106,10 +2106,22 @@ void CrostiniManager::OnAnsibleInDefaultContainerInstalled(bool success) {
return; return;
} }
// TODO(https://crbug.com/998124): Propagate playbook to be applied. const base::FilePath ansible_playbook_file_path =
profile_->GetPrefs()->GetFilePath(
prefs::kCrostiniAnsiblePlaybookFilePath);
std::string playbook_content;
if (!base::ReadFileToString(ansible_playbook_file_path, &playbook_content)) {
LOG(ERROR) << "Failed to retrieve Ansible playbook content from "
<< ansible_playbook_file_path.value();
InvokeAndErasePendingContainerCallbacks(
&start_container_callbacks_, kCrostiniDefaultVmName,
kCrostiniDefaultContainerName, CrostiniResult::UNKNOWN_ERROR);
return;
}
AnsibleManagementService::GetForProfile(profile_) AnsibleManagementService::GetForProfile(profile_)
->ApplyAnsiblePlaybookToDefaultContainer( ->ApplyAnsiblePlaybookToDefaultContainer(
/*playbook=*/"---", playbook_content,
base::BindOnce( base::BindOnce(
&CrostiniManager::OnAnsiblePlaybookToDefaultContainerApplied, &CrostiniManager::OnAnsiblePlaybookToDefaultContainerApplied,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
...@@ -220,6 +221,18 @@ class CrostiniManagerTest : public testing::Test { ...@@ -220,6 +221,18 @@ class CrostiniManagerTest : public testing::Test {
fake_cicerone_client_->NotifyApplyAnsiblePlaybookProgress(signal); fake_cicerone_client_->NotifyApplyAnsiblePlaybookProgress(signal);
} }
void SetAnsibleInfra() {
scoped_feature_list_.Reset();
scoped_feature_list_.InitAndEnableFeature(
features::kCrostiniAnsibleInfrastructure);
base::FilePath ansible_playbook_file_path =
profile_->GetPath().AppendASCII("playbook.yaml");
const char playbook[] = "---";
base::WriteFile(ansible_playbook_file_path, playbook, strlen(playbook));
profile_->GetPrefs()->SetFilePath(prefs::kCrostiniAnsiblePlaybookFilePath,
ansible_playbook_file_path);
}
base::RunLoop* run_loop() { return run_loop_.get(); } base::RunLoop* run_loop() { return run_loop_.get(); }
Profile* profile() { return profile_.get(); } Profile* profile() { return profile_.get(); }
CrostiniManager* crostini_manager() { return crostini_manager_; } CrostiniManager* crostini_manager() { return crostini_manager_; }
...@@ -1541,9 +1554,7 @@ TEST_F(CrostiniManagerTest, StartContainerSuccess) { ...@@ -1541,9 +1554,7 @@ TEST_F(CrostiniManagerTest, StartContainerSuccess) {
} }
TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraInstallFailure) { TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraInstallFailure) {
scoped_feature_list_.Reset(); SetAnsibleInfra();
scoped_feature_list_.InitAndEnableFeature(
features::kCrostiniAnsibleInfrastructure);
// Response for failed Ansible installation. // Response for failed Ansible installation.
vm_tools::cicerone::InstallLinuxPackageResponse install_response; vm_tools::cicerone::InstallLinuxPackageResponse install_response;
...@@ -1560,9 +1571,7 @@ TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraInstallFailure) { ...@@ -1560,9 +1571,7 @@ TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraInstallFailure) {
} }
TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraApplicationFailure) { TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraApplicationFailure) {
scoped_feature_list_.Reset(); SetAnsibleInfra();
scoped_feature_list_.InitAndEnableFeature(
features::kCrostiniAnsibleInfrastructure);
// Response for successful Ansible installation. // Response for successful Ansible installation.
vm_tools::cicerone::InstallLinuxPackageResponse install_response; vm_tools::cicerone::InstallLinuxPackageResponse install_response;
...@@ -1590,9 +1599,7 @@ TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraApplicationFailure) { ...@@ -1590,9 +1599,7 @@ TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraApplicationFailure) {
} }
TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraSuccess) { TEST_F(CrostiniManagerTest, StartContainerWithAnsibleInfraSuccess) {
scoped_feature_list_.Reset(); SetAnsibleInfra();
scoped_feature_list_.InitAndEnableFeature(
features::kCrostiniAnsibleInfrastructure);
// Response for successful Ansible installation. // Response for successful Ansible installation.
vm_tools::cicerone::InstallLinuxPackageResponse install_response; vm_tools::cicerone::InstallLinuxPackageResponse install_response;
......
...@@ -358,8 +358,12 @@ bool IsCrostiniRunning(Profile* profile) { ...@@ -358,8 +358,12 @@ bool IsCrostiniRunning(Profile* profile) {
kCrostiniDefaultVmName); kCrostiniDefaultVmName);
} }
bool IsCrostiniAnsibleInfrastructureEnabled() { bool ShouldConfigureDefaultContainer(Profile* profile) {
return base::FeatureList::IsEnabled(features::kCrostiniAnsibleInfrastructure); const base::FilePath ansible_playbook_file_path =
profile->GetPrefs()->GetFilePath(prefs::kCrostiniAnsiblePlaybookFilePath);
return base::FeatureList::IsEnabled(
features::kCrostiniAnsibleInfrastructure) &&
!ansible_playbook_file_path.empty();
} }
void LaunchCrostiniApp(Profile* profile, void LaunchCrostiniApp(Profile* profile,
......
...@@ -70,9 +70,9 @@ bool IsCrostiniUIAllowedForProfile(Profile* profile, bool check_policy = true); ...@@ -70,9 +70,9 @@ bool IsCrostiniUIAllowedForProfile(Profile* profile, bool check_policy = true);
// Returns whether the default Crostini VM is running for the user. // Returns whether the default Crostini VM is running for the user.
bool IsCrostiniRunning(Profile* profile); bool IsCrostiniRunning(Profile* profile);
// Returns whether infrastructure for applying Ansible playbook to default // Returns whether default Crostini container should be configured according to
// Crostini container is enabled. // the configuration specified by CrostiniAnsiblePlaybook user policy.
bool IsCrostiniAnsibleInfrastructureEnabled(); bool ShouldConfigureDefaultContainer(Profile* profile);
// Launches the Crostini app with ID of |app_id| on the display with ID of // Launches the Crostini app with ID of |app_id| on the display with ID of
// |display_id|. |app_id| should be a valid Crostini app list id. // |display_id|. |app_id| should be a valid Crostini app list id.
...@@ -160,7 +160,7 @@ void PrepareShowCrostiniUpgradeContainerView(Profile* profile, ...@@ -160,7 +160,7 @@ void PrepareShowCrostiniUpgradeContainerView(Profile* profile,
// not open until PrepareShowCrostiniUpgradeContainerView is called again. // not open until PrepareShowCrostiniUpgradeContainerView is called again.
void CloseCrostiniUpgradeContainerView(); void CloseCrostiniUpgradeContainerView();
// Show the Crostini Software Config Upgrade dialog (for installing Ansible and // Show the Crostini Software Config dialog (for installing Ansible and
// applying an Ansible playbook in the container). // applying an Ansible playbook in the container).
void ShowCrostiniAnsibleSoftwareConfigView(Profile* profile); void ShowCrostiniAnsibleSoftwareConfigView(Profile* profile);
......
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