Exemplo n.º 1
0
 def connect_to_reference_network(self):
     """Connect to reference network and make sure that connection happen"""
     self.dut.droid.wakeLockAcquireBright()
     self.dut.droid.wakeUpNow()
     try:
         self.dut.droid.wifiConnectByConfig(
             self.reference_networks[0]["2g"])
         connect_result = self.dut.ed.pop_event(
             wifi_constants.CONNECT_BY_CONFIG_SUCCESS, SHORT_TIMEOUT)
         self.log.info(connect_result)
         return wutils.track_connection(
             self.dut, self.reference_networks[0]["2g"]["SSID"], 1)
     except Exception as error:
         self.log.exception(traceback.format_exc())
         self.log.error("Connection to network fail because %s", error)
         return False
     finally:
         self.dut.droid.wifiLockRelease()
         self.dut.droid.goToSleepNow()
    def setup_class(self):
        """It will setup the required dependencies from config file and configure
           the required networks for auto-join testing. Configured networks will
           not be removed. If networks are already configured it will skip
           configuring the networks

        Returns:
            True if successfully configured the requirements for testing.
        """
        self.dut = self.android_devices[0]
        wutils.wifi_test_device_init(self.dut)
        req_params = ("reference_networks", "other_network", "atten_val",
                      "ping_addr", "max_bugreports")
        self.unpack_userparams(req_params)
        self.log.debug("Connect networks :: {}".format(self.other_network))
        configured_networks = self.dut.droid.wifiGetConfiguredNetworks()
        self.log.debug("Configured networks :: {}".format(configured_networks))
        count_confnet = 0
        result = False
        if self.reference_networks[0]['2g']['ssid'] == self.reference_networks[
                0]['5g']['ssid']:
            self.ref_ssid_count = 1
        else:
            self.ref_ssid_count = 2  # Different SSID for 2g and 5g
        for confnet in configured_networks:
            if confnet[WifiEnums.
                       SSID_KEY] == self.reference_networks[0]['2g']['ssid']:
                count_confnet += 1
            elif confnet[WifiEnums.
                         SSID_KEY] == self.reference_networks[0]['5g']['ssid']:
                count_confnet += 1
        self.log.info("count_confnet {}".format(count_confnet))
        if count_confnet == self.ref_ssid_count:
            return
        else:
            self.log.info("Configured networks for testing")
            self.attenuators[0].set_atten(0)
            self.attenuators[1].set_atten(90)
            self.attenuators[2].set_atten(90)
            wait_time = 15
            self.dut.droid.wakeLockAcquireBright()
            self.dut.droid.wakeUpNow()
            try:
                self.dut.droid.wifiConnectByConfig(
                    self.reference_networks[0]['2g'])
                connect_result = self.dut.ed.pop_event(
                    wifi_constants.CONNECT_BY_CONFIG_SUCCESS, 1)
                self.log.info(connect_result)
                time.sleep(wait_time)
                if self.ref_ssid_count == 2:  #add 5g network as well
                    self.dut.droid.wifiConnectByConfig(
                        self.reference_networks[0]['5g'])
                    connect_result = self.dut.ed.pop_event(
                        wifi_constants.CONNECT_BY_CONFIG_SUCCESS, 1)
                    self.log.info(connect_result)
                    time.sleep(wait_time)
                self.dut.droid.wifiConnectByConfig(self.other_network)
                connect_result = self.dut.ed.pop_event(
                    wifi_constants.CONNECT_BY_CONFIG_SUCCESS)
                self.log.info(connect_result)
                wutils.track_connection(self.dut, self.other_network["ssid"],
                                        1)
                wutils.wifi_forget_network(self.dut,
                                           self.other_network["ssid"])
                time.sleep(wait_time)
                current_network = self.dut.droid.wifiGetConnectionInfo()
                self.log.info("Current network: {}".format(current_network))
                asserts.assert_true('network_id' in current_network,
                                    NETWORK_ID_ERROR)
                asserts.assert_true(current_network['network_id'] >= 0,
                                    NETWORK_ERROR)
            finally:
                self.dut.droid.wifiLockRelease()
                self.dut.droid.goToSleepNow()