update_engine: Add Update Time Restrictions
Implementation for the update time restrictions policy where the admin
is allowed to choose time interval in which updates will not be checked.
- Adds WeeklyTime and WeeklyTimeInterval classes to update_engine to be
able to easily do interval range checking and time operations easily in
the policy. Added the wiring so the classes can be used as Values and
BoxedValues.
- Adds disallowed_intervals member to device_policy_provider, since this
contains the policy dictated disallowed intervals. The intervals are
obtained from libpolicy, a function was added to convert them to the
new WeeklyTime classes. Added the corresponding changes to the device
policy provider header and interface.
- Added the policy to chromeos_policy.cc so that it's taken into account
in UpdateCheckAllowed.
BUG=chromium:852860
TEST=cros_workon_make update_engine --test
Change-Id: If62a2b3650adf149ba87790345e1eb62f0e1bb1f
Reviewed-on: https://chromium-review.googlesource.com/1119397
Commit-Ready: Adolfo Higueros <adokar@google.com>
Tested-by: Adolfo Higueros <adokar@google.com>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/update_manager/boxed_value_unittest.cc b/update_manager/boxed_value_unittest.cc
index 04de3d4..3fa0f1a 100644
--- a/update_manager/boxed_value_unittest.cc
+++ b/update_manager/boxed_value_unittest.cc
@@ -30,6 +30,7 @@
#include "update_engine/update_manager/shill_provider.h"
#include "update_engine/update_manager/umtest_utils.h"
#include "update_engine/update_manager/updater_provider.h"
+#include "update_engine/update_manager/weekly_time.h"
using base::Time;
using base::TimeDelta;
@@ -258,4 +259,34 @@
.ToString());
}
+TEST(UmBoxedValueTest, WeeklyTimeIntervalToString) {
+ EXPECT_EQ("Start: day_of_week=2 time=100\nEnd: day_of_week=4 time=200",
+ BoxedValue(new WeeklyTimeInterval(
+ WeeklyTime(2, TimeDelta::FromMinutes(100)),
+ WeeklyTime(4, TimeDelta::FromMinutes(200))))
+ .ToString());
+ EXPECT_EQ("Start: day_of_week=1 time=10\nEnd: day_of_week=1 time=20",
+ BoxedValue(new WeeklyTimeInterval(
+ WeeklyTime(1, TimeDelta::FromMinutes(10)),
+ WeeklyTime(1, TimeDelta::FromMinutes(20))))
+ .ToString());
+}
+
+TEST(UmBoxedValueTest, WeeklyTimeIntervalVectorToString) {
+ WeeklyTimeIntervalVector intervals;
+ intervals.emplace_back(WeeklyTime(5, TimeDelta::FromMinutes(10)),
+ WeeklyTime(1, TimeDelta::FromMinutes(30)));
+ EXPECT_EQ(
+ "Disallowed intervals:\nStart: day_of_week=5 time=10\nEnd: "
+ "day_of_week=1 time=30\n",
+ BoxedValue(new WeeklyTimeIntervalVector(intervals)).ToString());
+ intervals.emplace_back(WeeklyTime(1, TimeDelta::FromMinutes(5)),
+ WeeklyTime(6, TimeDelta::FromMinutes(1000)));
+ EXPECT_EQ(
+ "Disallowed intervals:\nStart: day_of_week=5 time=10\nEnd: "
+ "day_of_week=1 time=30\nStart: day_of_week=1 time=5\nEnd: day_of_week=6 "
+ "time=1000\n",
+ BoxedValue(new WeeklyTimeIntervalVector(intervals)).ToString());
+}
+
} // namespace chromeos_update_manager