1 # 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 5 import logging 6 7 from autotest_lib.client.common_lib import error 8 from autotest_lib.client.common_lib.cros import tpm_utils 9 from autotest_lib.server import autotest 10 from autotest_lib.server import test 11 from autotest_lib.server import utils 12 13 14 class 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: 23 self._host.run('mosys -k platform brand | grep brand') 24 except error.AutoservRunError as e: 25 raise error.TestFail('DUT is missing brand_code: %s.' % 26 e.result_obj.stderr) 27 28 29 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 40 except error.AutoservRunError as e: 41 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 ' 44 'VPD value on the DUT: %s' % 45 e.result_obj.stderr) 46 for i in range(retries): 47 try: 48 self._host.run('dump_vpd_log --force') 49 break 50 except error.AutoservRunError as e: 51 logging.exception('Failed to dump vpd log') 52 if i == retries - 1: 53 raise error.TestFail('Failed to dump vpd log: ' 54 '%s' % e.result_obj.stderr) 55 56 57 def _make_rootfs_writable(self): 58 """ Remove rootfs verification on DUT.""" 59 logging.info('Disabling rootfs on the DUT.') 60 cmd = ('/usr/share/vboot/bin/make_dev_ssd.sh ' 61 '--remove_rootfs_verification --force') 62 self._host.run(cmd) 63 self._host.reboot() 64 65 66 def _check_rlz_vpd_settings_post_ping(self): 67 """Checks that rlz related vpd settings are correct after the test.""" 68 def should_send_rlz_ping(): 69 return int(self._host.run('vpd -i RW_VPD -g ' 70 'should_send_rlz_ping').stdout) 71 72 utils.poll_for_condition(lambda: should_send_rlz_ping() == 0, 73 timeout=60) 74 75 result = self._host.run('vpd -i RW_VPD -g rlz_embargo_end_date', 76 ignore_status=True) 77 if result.exit_status == 0: 78 raise error.TestFail('rlz_embargo_end_date still present in vpd.') 79 80 81 def _reduce_rlz_ping_delay(self, ping_timeout): 82 """Changes the rlz ping delay so we can test it quickly.""" 83 84 # Removes any old rlz ping delays in the file. 85 self._host.run('sed -i /--rlz-ping-delay/d /etc/chrome_dev.conf') 86 self._host.run('echo --rlz-ping-delay=%d >> /etc/chrome_dev.conf' % 87 ping_timeout) 88 89 90 def run_once(self, host, ping_timeout=30, logged_in=True): 91 self._host = host 92 if 'veyron_rialto' in self._host.get_board(): 93 raise error.TestNAError('Skipping test on rialto device.') 94 95 self._check_rlz_brand_code() 96 97 # Clear TPM owner so we have no users on DUT. 98 tpm_utils.ClearTPMOwnerRequest(self._host) 99 100 # Setup DUT to send rlz ping after a short timeout. 101 self._set_vpd_values() 102 self._make_rootfs_writable() 103 self._reduce_rlz_ping_delay(ping_timeout) 104 self._host.reboot() 105 106 # Login, do a Google search, check for CAF event in RLZ Data file. 107 client_at = autotest.Autotest(self._host) 108 client_at.run_test(self._CLIENT_TEST, ping_timeout=ping_timeout, 109 logged_in=logged_in) 110 client_at._check_client_test_result(self._host, self._CLIENT_TEST) 111 112 self._check_rlz_vpd_settings_post_ping() 113