blob: 92a3b3911cbe70af5d531ce8c17e2ed4cf2c1cac [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import math
import time
from autotest_lib.client.common_lib import autotemp
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib import utils
from autotest_lib.client.cros.update_engine import nebraska_wrapper
from autotest_lib.client.cros.update_engine import update_engine_test
from autotest_lib.client.cros.enterprise import enterprise_policy_base
class policy_DeviceAutoUpdateDisabled(
"""Test for the DeviceAutoUpdateDisabled policy."""
version = 1
_POLICY = 'DeviceAutoUpdateDisabled'
def _test_update_disabled(self, update_url, should_update):
Main test function.
Try to update and poll for start (or lack of start) to the update.
Check whether an update request was sent.
@param update_url: The URL to get an update from.
@param should_update: True or False whether the device should update.
# Log time is only in second accuracy. Assume no update request has
# occured since the current whole second started.
start_time = math.floor(time.time())'Update test start time: %s', start_time)
self._check_for_update(update_url, interactive=False)
exception=error.TestFail('Update did not start!'))
except error.TestFail as e:
if should_update:
raise e
if not should_update:
raise error.TestFail('Update started when it should not have!')
update_time = self._get_time_of_last_update_request()'Last update time: %s', update_time)
if should_update and (not update_time or update_time < start_time):
raise error.TestFail('No update request was sent!')
if not should_update and update_time and update_time >= start_time:
raise error.TestFail('Update request was sent!')
def run_once(self, case, image_url, enroll=True):
Entry point of this test.
@param case: True, False, or None for the value of the update policy.
@param image_url: Url of update image (this build).
# Because we are doing polimorphism and the EnterprisePolicyTest is
# earlier in the python MRO, this class's initialize() will get called,
# but not the UpdateEngineTest's initialize(). So we need to call it
# manually.
self.setup_case(device_policies={self._POLICY: case}, enroll=enroll)
metadata_dir = autotemp.tempdir()
base_url = ''.join(image_url.rpartition('/')[0:2])
with nebraska_wrapper.NebraskaWrapper(
update_payloads_address=base_url) as nebraska:
# When policy is False or not set, user should update.
should_update=case is not True)