• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import time
2
3from autotest_lib.client.common_lib import error
4from autotest_lib.server import test
5
6
7class platform_ActivateDate(test.test):
8    """
9    Tests that activate date is run correctly from a clean system state.
10    For context, activate date is an upstart script located in:
11        chromeos-base/chromeos-activate-date
12    It attempts to set the initial date when a new chromebook is first used
13    by the customer, which drives things like battery warranty issues.
14    """
15    version = 1
16
17    def run_once(self, host):
18        host.run('truncate -s 0 /var/log/messages')
19        host.run('activate_date --clean')
20
21        # Since the activate_date value was cleaned, this reboot will cause it
22        # to execute the activation sequence.
23        host.reboot()
24
25        # The activation sequence polls with a 200 second sleep, which seems
26        # pretty high, but we'll wait for at least one of those sleep cycles.
27        poll_interval = 10
28        max_num_attempts = 21
29
30        current_attempt = 1
31        success = False
32        while current_attempt <= max_num_attempts and not success:
33          # Autotest logs the grep command to the system log, so we're just
34          # going to search for it locally.
35          get_log_cmd = 'cat /var/log/messages'
36          success = 'Activation date set' in host.run(get_log_cmd).stdout
37          if not success:
38            current_attempt = current_attempt + 1
39            time.sleep(poll_interval)
40
41        if not success:
42          raise error.TestFail('Failed to set activation date')
43
44        # After this reboot, vpd_get_value ActivateDate should be set already
45        # because this is what prevents the init script from executing again.
46        host.reboot()
47
48        if not host.run('vpd_get_value ActivateDate').stdout:
49          raise error.TestFail(
50              'ActivateDate should be set correctly after reboot')
51