blob: 40b6286f380f03f9c77eb6d6970cee751cd5999a [file] [log] [blame]
David Haddockdd35fb5e2018-05-03 14:52:33 -07001# Copyright 2018 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 logging
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.common_lib.cros import tpm_utils
9from autotest_lib.server import autotest
10from autotest_lib.server import test
11from autotest_lib.server import utils
12
13
14class rlz_CheckPing(test.test):
15 """ Tests we are sending the CAF and CAI RLZ pings for first user."""
16 version = 1
17
18 _CLIENT_TEST = 'desktopui_CheckRlzPingSent'
19
20 def _check_rlz_brand_code(self):
21 """Checks that we have an rlz brand code."""
22 try:
Greg Edelston7cea0c42019-11-26 15:17:22 -070023 self._host.run('cros_config / brand-code')
David Haddock7d2e0522018-12-04 19:59:11 -080024 except error.AutoservRunError as e:
25 raise error.TestFail('DUT is missing brand_code: %s.' %
26 e.result_obj.stderr)
David Haddockdd35fb5e2018-05-03 14:52:33 -070027
28
David Haddockb87c65e2018-11-20 15:53:09 -080029 def _set_vpd_values(self, retries=3):
30 """
31 Sets the required vpd values for the test.
32
33 @param retries: number of times to retry to write to vpd.
34
35 """
36 for i in range(retries):
37 try:
38 self._host.run('vpd -i RW_VPD -s should_send_rlz_ping=1')
39 break
David Haddock7d2e0522018-12-04 19:59:11 -080040 except error.AutoservRunError as e:
David Haddockb87c65e2018-11-20 15:53:09 -080041 logging.exception('Failed to write should_send_rlz_ping to vpd')
42 if i == retries-1:
43 raise error.TestFail('Failed to set should_send_rlz_ping '
David Haddock7d2e0522018-12-04 19:59:11 -080044 'VPD value on the DUT: %s' %
45 e.result_obj.stderr)
David Haddockb87c65e2018-11-20 15:53:09 -080046 for i in range(retries):
47 try:
48 self._host.run('dump_vpd_log --force')
49 break
David Haddock7d2e0522018-12-04 19:59:11 -080050 except error.AutoservRunError as e:
David Haddockb87c65e2018-11-20 15:53:09 -080051 logging.exception('Failed to dump vpd log')
52 if i == retries - 1:
David Haddock0d3afe92018-12-03 13:00:21 -080053 raise error.TestFail('Failed to dump vpd log: '
David Haddock7d2e0522018-12-04 19:59:11 -080054 '%s' % e.result_obj.stderr)
David Haddockdd35fb5e2018-05-03 14:52:33 -070055
56
David Haddockdd35fb5e2018-05-03 14:52:33 -070057 def _check_rlz_vpd_settings_post_ping(self):
58 """Checks that rlz related vpd settings are correct after the test."""
59 def should_send_rlz_ping():
Greg Edelston7cea0c42019-11-26 15:17:22 -070060 """Ask vpd (on the DUT) whether we are ready to send rlz ping"""
David Haddockdd35fb5e2018-05-03 14:52:33 -070061 return int(self._host.run('vpd -i RW_VPD -g '
62 'should_send_rlz_ping').stdout)
63
64 utils.poll_for_condition(lambda: should_send_rlz_ping() == 0,
65 timeout=60)
66
67 result = self._host.run('vpd -i RW_VPD -g rlz_embargo_end_date',
68 ignore_status=True)
69 if result.exit_status == 0:
70 raise error.TestFail('rlz_embargo_end_date still present in vpd.')
71
72
David Haddockdd35fb5e2018-05-03 14:52:33 -070073 def run_once(self, host, ping_timeout=30, logged_in=True):
Greg Edelston7cea0c42019-11-26 15:17:22 -070074 """Main test logic"""
David Haddockdd35fb5e2018-05-03 14:52:33 -070075 self._host = host
David Haddockb87c65e2018-11-20 15:53:09 -080076 if 'veyron_rialto' in self._host.get_board():
77 raise error.TestNAError('Skipping test on rialto device.')
78
David Haddockdd35fb5e2018-05-03 14:52:33 -070079 self._check_rlz_brand_code()
80
81 # Clear TPM owner so we have no users on DUT.
82 tpm_utils.ClearTPMOwnerRequest(self._host)
83
84 # Setup DUT to send rlz ping after a short timeout.
85 self._set_vpd_values()
David Haddockdd35fb5e2018-05-03 14:52:33 -070086 self._host.reboot()
87
88 # Login, do a Google search, check for CAF event in RLZ Data file.
89 client_at = autotest.Autotest(self._host)
90 client_at.run_test(self._CLIENT_TEST, ping_timeout=ping_timeout,
91 logged_in=logged_in)
92 client_at._check_client_test_result(self._host, self._CLIENT_TEST)
93
94 self._check_rlz_vpd_settings_post_ping()