aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMay Lippert <maybelle@chromium.org>2018-07-02 16:45:13 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-07-20 05:31:18 -0700
commita722b427ac5223635eafde4551dbb2db749ce252 (patch)
tree2b654481d6cd84c1240d96cd40b243875d4bb3fd
parent2d3967d969318f3041c766f377eed2ef88a613af (diff)
downloadlibbrillo-a722b427ac5223635eafde4551dbb2db749ce252.tar.gz
libbrillo: Add new policy (DeviceUpdateStagingSchedule) for staging updates.
Add a new device policy that will allow administrators to specify a schedule for rolling out updates to an organizational unit. BUG=chromium:858621 TEST=Used YAPS as DM server, verified that the new policy is parsed correctly. CQ-DEPEND=CL:1119162 Change-Id: I72852ddf86e6c7e432aea38a33c6fb3be4c7f315 Reviewed-on: https://chromium-review.googlesource.com/1123683 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: May Lippert <maybelle@chromium.org> Reviewed-by: Dan Erat <derat@chromium.org>
-rw-r--r--policy/device_policy.h10
-rw-r--r--policy/device_policy_impl.cc21
-rw-r--r--policy/device_policy_impl.h2
-rw-r--r--policy/mock_device_policy.h2
-rw-r--r--policy/tests/device_policy_impl_unittest.cc80
5 files changed, 115 insertions, 0 deletions
diff --git a/policy/device_policy.h b/policy/device_policy.h
index 52e73d5..998cc76 100644
--- a/policy/device_policy.h
+++ b/policy/device_policy.h
@@ -202,6 +202,16 @@ class DevicePolicy {
virtual bool GetDisallowedTimeIntervals(
std::vector<WeeklyTimeInterval>* intervals_out) const = 0;
+ // Writes the value of the DeviceUpdateStagingPercentOfFleetPerWeek policy to
+ // |staging_schedule_out|. Returns true on success.
+ // Values are expected to be mononically increasing in the range of [0, 100].
+ // Each value describes the percentage of the fleet that is expected to
+ // receive an update per week, e.g. [5, 20, 30, 100] means that 5% of devices
+ // should be updated in the first week, 20% should be updated in the second
+ // week, and so on.
+ virtual bool GetDeviceUpdateStagingSchedule(
+ std::vector<int> *staging_schedule_out) const = 0;
+
private:
// Verifies that the policy signature is correct.
virtual bool VerifyPolicySignature() = 0;
diff --git a/policy/device_policy_impl.cc b/policy/device_policy_impl.cc
index 4d506ba..0e4b852 100644
--- a/policy/device_policy_impl.cc
+++ b/policy/device_policy_impl.cc
@@ -4,6 +4,7 @@
#include "policy/device_policy_impl.h"
+#include <algorithm>
#include <memory>
#include <base/containers/adapters.h>
@@ -501,6 +502,26 @@ bool DevicePolicyImpl::GetUsbDetachableWhitelist(
return true;
}
+bool DevicePolicyImpl::GetDeviceUpdateStagingSchedule(
+ std::vector<int> *staging_schedule_out) const {
+ if (!device_policy_.has_auto_update_settings())
+ return false;
+
+ const em::AutoUpdateSettingsProto &proto =
+ device_policy_.auto_update_settings();
+
+ if (proto.staging_percent_of_fleet_per_week_size() == 0)
+ return false;
+
+ for (int i = 0; i < proto.staging_percent_of_fleet_per_week_size(); i++) {
+ // Limit the percentage to [0, 100]
+ staging_schedule_out->push_back(
+ std::max(std::min(proto.staging_percent_of_fleet_per_week(i), 100), 0));
+ }
+
+ return true;
+}
+
bool DevicePolicyImpl::GetAutoLaunchedKioskAppId(
std::string* app_id_out) const {
if (!device_policy_.has_device_local_accounts())
diff --git a/policy/device_policy_impl.h b/policy/device_policy_impl.h
index ee00f0f..9dbe847 100644
--- a/policy/device_policy_impl.h
+++ b/policy/device_policy_impl.h
@@ -80,6 +80,8 @@ class DevicePolicyImpl : public DevicePolicy {
bool GetSecondFactorAuthenticationMode(int* mode_out) const override;
bool GetDisallowedTimeIntervals(
std::vector<WeeklyTimeInterval>* intervals_out) const override;
+ bool GetDeviceUpdateStagingSchedule(
+ std::vector<int> *staging_schedule_out) const override;
// Methods that can be used only for testing.
void set_policy_data_for_testing(
diff --git a/policy/mock_device_policy.h b/policy/mock_device_policy.h
index 2999a18..f26433f 100644
--- a/policy/mock_device_policy.h
+++ b/policy/mock_device_policy.h
@@ -103,6 +103,8 @@ class MockDevicePolicy : public DevicePolicy {
MOCK_CONST_METHOD1(GetSecondFactorAuthenticationMode, bool(int*));
MOCK_CONST_METHOD1(GetDisallowedTimeIntervals,
bool(std::vector<WeeklyTimeInterval>*));
+ MOCK_CONST_METHOD1(GetDeviceUpdateStagingSchedule, bool(std::vector<int> *));
+
MOCK_METHOD0(VerifyPolicyFiles, bool(void));
MOCK_METHOD0(VerifyPolicySignature, bool(void));
};
diff --git a/policy/tests/device_policy_impl_unittest.cc b/policy/tests/device_policy_impl_unittest.cc
index 4ef5a3c..939c2b5 100644
--- a/policy/tests/device_policy_impl_unittest.cc
+++ b/policy/tests/device_policy_impl_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "policy/device_policy_impl.h"
@@ -11,6 +12,8 @@
namespace em = enterprise_management;
+using testing::ElementsAre;
+
namespace policy {
// Enterprise managed.
@@ -188,4 +191,81 @@ TEST(DevicePolicyImplTest, GetRollbackAllowedMilestones_SetTooSmall) {
EXPECT_EQ(0, value);
}
+// Update staging schedule has no values
+TEST(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_NoValues) {
+ em::ChromeDeviceSettingsProto device_policy_proto;
+ em::AutoUpdateSettingsProto *auto_update_settings =
+ device_policy_proto.mutable_auto_update_settings();
+ auto_update_settings->clear_staging_percent_of_fleet_per_week();
+ DevicePolicyImpl device_policy;
+ device_policy.set_policy_for_testing(device_policy_proto);
+ device_policy.set_install_attributes_for_testing(
+ std::make_unique<MockInstallAttributesReader>(
+ InstallAttributesReader::kDeviceModeEnterprise, true));
+
+ std::vector<int> staging_schedule;
+ EXPECT_FALSE(device_policy.GetDeviceUpdateStagingSchedule(&staging_schedule));
+}
+
+// Update staging schedule has valid values
+TEST(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid) {
+ em::ChromeDeviceSettingsProto device_policy_proto;
+ em::AutoUpdateSettingsProto *auto_update_settings =
+ device_policy_proto.mutable_auto_update_settings();
+ auto_update_settings->add_staging_percent_of_fleet_per_week(10);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(20);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(40);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(100);
+ DevicePolicyImpl device_policy;
+ device_policy.set_policy_for_testing(device_policy_proto);
+ device_policy.set_install_attributes_for_testing(
+ std::make_unique<MockInstallAttributesReader>(
+ InstallAttributesReader::kDeviceModeEnterprise, true));
+
+ std::vector<int> staging_schedule;
+ ASSERT_TRUE(device_policy.GetDeviceUpdateStagingSchedule(&staging_schedule));
+ EXPECT_THAT(staging_schedule, ElementsAre(10, 20, 40, 100));
+}
+
+// Update staging schedule has valid values, set using AD.
+TEST(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid_AD) {
+ em::ChromeDeviceSettingsProto device_policy_proto;
+ em::AutoUpdateSettingsProto *auto_update_settings =
+ device_policy_proto.mutable_auto_update_settings();
+ auto_update_settings->add_staging_percent_of_fleet_per_week(10);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(20);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(40);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(100);
+ DevicePolicyImpl device_policy;
+ device_policy.set_policy_for_testing(device_policy_proto);
+ device_policy.set_install_attributes_for_testing(
+ std::make_unique<MockInstallAttributesReader>(
+ InstallAttributesReader::kDeviceModeEnterpriseAD, true));
+
+ std::vector<int> staging_schedule;
+ ASSERT_TRUE(device_policy.GetDeviceUpdateStagingSchedule(&staging_schedule));
+ EXPECT_THAT(staging_schedule, ElementsAre(10, 20, 40, 100));
+}
+
+// Update staging schedule has values with values set larger than the max
+// allowed percentage and smaller than the min allowed percentage.
+TEST(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_SetOutsideAllowable) {
+ em::ChromeDeviceSettingsProto device_policy_proto;
+ em::AutoUpdateSettingsProto *auto_update_settings =
+ device_policy_proto.mutable_auto_update_settings();
+ auto_update_settings->add_staging_percent_of_fleet_per_week(-10);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(20);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(40);
+ auto_update_settings->add_staging_percent_of_fleet_per_week(110);
+ DevicePolicyImpl device_policy;
+ device_policy.set_policy_for_testing(device_policy_proto);
+ device_policy.set_install_attributes_for_testing(
+ std::make_unique<MockInstallAttributesReader>(
+ InstallAttributesReader::kDeviceModeEnterprise, true));
+
+ std::vector<int> staging_schedule;
+ ASSERT_TRUE(device_policy.GetDeviceUpdateStagingSchedule(&staging_schedule));
+ EXPECT_THAT(staging_schedule, ElementsAre(0, 20, 40, 100));
+}
+
} // namespace policy