1# Copyright 2019 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import time 6 7from autotest_lib.client.cros.enterprise import enterprise_policy_base 8from autotest_lib.client.common_lib import error 9 10class policy_ReportUploadFrequency( 11 enterprise_policy_base.EnterprisePolicyTest): 12 """ 13 Tests the ReportUploadFrequency policy in Chrome OS. 14 15 """ 16 17 version = 1 18 19 20 def initialize(self, **kwargs): 21 super(policy_ReportUploadFrequency, self).initialize(**kwargs) 22 23 self.POLICY_NAME = 'ReportUploadFrequency' 24 self.POLICIES = {} 25 self.TEST_CASES = { 26 '60s': 60000, 27 } 28 29 30 def _check_report_upload_frequency(self, case_value): 31 """ 32 Grep syslog for "Starting status upload: have_device_status = 1" line 33 34 @param case_value: policy value in milliseconds 35 36 """ 37 38 # Case_value is in milliseconds, while upload_frequency must be 39 # in seconds 40 upload_frequency = case_value/1000 41 42 # Wait and check if a status report was sent 43 time.sleep(upload_frequency) 44 has_status_upload = False 45 46 with open('/var/log/messages') as syslog: 47 for ln in syslog: 48 if 'Starting status upload: have_device_status = 1' in ln: 49 has_status_upload = True 50 51 if not has_status_upload: 52 raise error.TestFail("No status upload was sent.") 53 54 55 def run_once(self, case): 56 """ 57 Setup and run the test configured for the specified test case. 58 59 @param case: Name of the test case to run. 60 61 """ 62 63 case_value = self.TEST_CASES[case] 64 self.POLICIES[self.POLICY_NAME] = case_value 65 66 self.setup_case(device_policies=self.POLICIES, enroll=True) 67 self._check_report_upload_frequency(case_value) 68