1# Lint as: python2, python3 2# Copyright (c) 2021 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import dbus 7import logging 8 9from autotest_lib.client.bin import test 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.cros.cellular import cellular_logging 12from autotest_lib.client.cros.cellular import hermes_utils 13from autotest_lib.client.cros.cellular import mm1_constants 14 15log = cellular_logging.SetupCellularLogging('HermesMMInstallEnable') 16 17class cellular_HermesMM_InstallEnable(test.test): 18 """ 19 Tests Install & Enable functions on active/inactive Euicc and 20 validates the same on Modem Manager 21 22 This test fails when fails to Install/Enable a given Euicc profile 23 or not reflecting same on Modem Manager 24 25 Prerequisites 26 27 1) For test CI: 28 Before running this test on test CI, a profile needs to be created on 29 go/stork-profile. The profile needs to be linked to the EID of the dut. 30 Profiles with class=operational and type=Android GTS test are known to work 31 well with this test. 32 33 We rely on the SMDS event to find the activation code for the test. 34 There is a limit of 99 downloads before the profile needs to be deleted and 35 recreated.(b/181723689) 36 37 2) For prod CI: 38 Install a production profile before running the test. 39 40 """ 41 version = 1 42 43 def _validate_sim_data(self, euicc_path): 44 """ 45 Validate SIM details that Modem Manager getting from modem 46 47 Check Installed profile presence on an euicc 48 Check Profile enabled and same SIM details reflected on MM 49 50 @param euicc_path: available euicc dbus path as string 51 @raise error.TestFail if dbus exception happens or validation fail 52 53 """ 54 try: 55 logging.info('validate_sim_data start') 56 euicc = self.hermes_manager.get_euicc(euicc_path) 57 if not euicc: 58 logging.error('No Euicc enumerated') 59 raise error.TestFail('Validation of profile installation on MM' 60 ' failed as no euicc enumerated') 61 62 modem_proxy = self.mm_proxy.wait_for_modem( 63 mm1_constants.MM_MODEM_POLL_TIME) 64 if not modem_proxy: 65 logging.info('No modem object yet can not validate') 66 raise error.TestFail('Validation of profile installation on MM' 67 ' failed as no modem') 68 69 # Read MM SIM properties and validate with installed profile data 70 sim_proxy = modem_proxy.get_sim() 71 sim_props = sim_proxy.properties() 72 73 logging.info('MM-SIM properties are SimIdentifier:%s Active:%s' 74 ' Imsi:%s', sim_props['SimIdentifier'], 75 sim_props['Active'], sim_props['Imsi']) 76 77 if (sim_props['SimIdentifier'] == self.installed_iccid): 78 logging.info('===validate_sim_data succeeded===\n') 79 else: 80 raise error.TestFail('Validation of profile Installation on MM' 81 ' failed:' + self.installed_iccid) 82 83 return True 84 except dbus.DBusException as e: 85 logging.error('Resulted Modem Manager Validation error:%s', e) 86 raise error.TestFail('MM validation failed') 87 88 def run_once(self, test_env, is_prod_ci=False): 89 """ Install & Enable Euicc by enabling a profile """ 90 self.is_prod_ci = is_prod_ci 91 92 self.mm_proxy, self.hermes_manager, euicc_path = \ 93 hermes_utils.initialize_test(is_prod_ci) 94 95 logging.info('Getting profile to enable') 96 self.installed_iccid = hermes_utils.get_iccid_of_disabled_profile( 97 euicc_path, self.hermes_manager, self.is_prod_ci) 98 99 hermes_utils.enable_or_disable_profile_test( 100 euicc_path, self.hermes_manager, self.installed_iccid, True) 101 102 # Validate esim profile enabled is same as MM sim profile 103 self._validate_sim_data(euicc_path) 104 105 logging.info('HermesMMInstallEnableTest Completed') 106