Example #1
0
 def _connect_wifi(self, run_num):
     """Helper function to make a connection to the associated AP."""
     assoc_params = self.assoc_params
     logging.info('Connection attempt %d', run_num)
     self.dut_obj.host.syslog('Connection attempt %d' % run_num)
     start_time = self.dut_obj.host.run("date '+%FT%T.%N%:z'").stdout
     start_time = start_time.strip()
     assoc_result = xmlrpc_datatypes.deserialize(
         self.dut_obj.wifi_client.shill.connect_wifi(assoc_params))
     end_time = self.dut_obj.host.run("date '+%FT%T.%N%:z'").stdout
     end_time = end_time.strip()
     success = assoc_result.success
     if not success:
         logging.error('Connection attempt %d failed; reason: %s',
                       run_num, assoc_result.failure_reason)
         result = ControlResult(uid=self.uid,
                                run_num=run_num,
                                success=success,
                                error_reason=assoc_result.failure_reason,
                                start_time=start_time,
                                end_time=end_time)
         return result
     else:
         logging.info('Connection attempt %d passed', run_num)
         return None
Example #2
0
    def connect_work_client(self, assoc_params):
        """
        Connect client to the AP.

        Tries to connect the work client to AP in WORK_CLIENT_CONNECTION_RETRIES
        tries. If we fail to connect in all tries then we would return False
        otherwise returns True on successful connection to the AP.

        @param assoc_params: an AssociationParameters object.
        @return a boolean: True if work client is successfully connected to AP
                or False on failing to connect to the AP

        """
        if not self.work_client.shill.init_test_network_state():
            logging.error('Failed to set up isolated test context profile for '
                          'work client.')
            return False

        success = False
        for i in range(WORK_CLIENT_CONNECTION_RETRIES):
            logging.info('Connecting work client to AP')
            assoc_result = xmlrpc_datatypes.deserialize(
                           self.work_client.shill.connect_wifi(assoc_params))
            success = assoc_result.success
            if not success:
                logging.error('Connection attempt of work client failed, try %d'
                              ' reason: %s', (i+1), assoc_result.failure_reason)
            else:
                logging.info('Work client connected to the AP')
                self.ssid = assoc_params.ssid
                break
        return success
 def _connect(self, wifi_params):
     assoc_result = xmlrpc_datatypes.deserialize(
         self.context.client.shill.connect_wifi(wifi_params))
     logging.info(
         'Finished connection attempt to %s with times: '
         'discovery=%.2f, association=%.2f, configuration=%.2f.',
         wifi_params.ssid, assoc_result.discovery_time,
         assoc_result.association_time, assoc_result.configuration_time)
     return assoc_result.success
Example #4
0
    def _verify_attenuator(self, ap_num, frequency_mhz, attenuator_num):
        """Verify that each phy has two attenuators controlling its signal.

        @param ap_num: int hostapd instance to test against.
        @param frequency_mhz: int frequency of the AP.
        @param attenuator_num: int attenuator num controlling one antenna on
                the AP.

        @return AttenuatorInfo object

        """
        logging.info('Verifying attenuator functionality')
        ai = AttenuatorInfo()
        # Remove knowledge of previous networks from shill.
        self.context.client.shill.init_test_network_state()
        # Isolate the client entirely.
        self.context.attenuator.set_variable_attenuation(
                attenuator_controller.MAX_VARIABLE_ATTENUATION)
        logging.info('Removing variable attenuation for attenuator=%d',
                     attenuator_num)
        # But allow one antenna on this phy.
        self.context.attenuator.set_variable_attenuation(
                0, attenuator_num=attenuator_num)
        client_conf = xmlrpc_datatypes.AssociationParameters(
                ssid=self.context.router.get_ssid(instance=ap_num))

        logging.info('Waiting for client signal levels to settle.')
        ai = self._wait_for_good_signal_levels(client_conf.ssid, ai)
        logging.info('Connecting to %s', client_conf.ssid)
        assoc_result = xmlrpc_datatypes.deserialize(
                self.context.client.shill.connect_wifi(client_conf))
        if not assoc_result.success:
            logging.error('Failed to connect to AP %d on attenuator %d',
                          ap_num, attenuator_num)
            return ai
        ai.allows_connection = True
        ai.zeroed_linked_signal = self.context.client.wifi_signal_level
        logging.info('Connected successfully')
        start_atten = self.context.attenuator.get_minimal_total_attenuation()
        for atten in range(start_atten,
                           min(start_atten + 20, FINAL_ATTENUATION),
                           ATTENUATION_STEP):
            self.context.attenuator.set_total_attenuation(
                    atten, frequency_mhz, attenuator_num=attenuator_num)
            time.sleep(2)
            logging.info('Attenuator %d signal at attenuation=%d is %d dBm.',
                         attenuator_num, atten,
                         self.context.client.wifi_signal_level)
        return ai
Example #5
0
    def configure_service_by_guid(self, raw_params):
        """Configure a service referenced by a GUID.

        @param raw_params serialized ConfigureServiceParameters.

        """
        params = xmlrpc_datatypes.deserialize(raw_params)
        shill = self._wifi_proxy
        properties = {}
        if params.autoconnect is not None:
            properties[shill.SERVICE_PROPERTY_AUTOCONNECT] = params.autoconnect
        if params.passphrase is not None:
            properties[shill.SERVICE_PROPERTY_PASSPHRASE] = params.passphrase
        if properties:
            self._wifi_proxy.configure_service_by_guid(params.guid, properties)
        return True
Example #6
0
    def configure_wifi_service(self, raw_params):
        """Configure a WiFi service

        @param raw_params serialized AssociationParameters.
        @return True on success, False otherwise.

        """
        params = xmlrpc_datatypes.deserialize(raw_params)
        return self._wifi_proxy.configure_wifi_service(
            params.ssid,
            params.security,
            params.security_parameters,
            save_credentials=params.save_credentials,
            station_type=params.station_type,
            hidden_network=params.is_hidden,
            guid=params.guid,
            autoconnect=params.autoconnect)
Example #7
0
    def assert_connect_wifi(self, wifi_params, description=None):
        """Connect to a WiFi network and check for success.

        Connect a DUT to a WiFi network and check that we connect successfully.

        @param wifi_params AssociationParameters describing network to connect.
        @param description string Additional text for logging messages.

        @returns AssociationResult if successful; None if wifi_params
                 contains expect_failure; asserts otherwise.

        """
        if description:
            connect_name = '%s (%s)' % (wifi_params.ssid, description)
        else:
            connect_name = '%s' % wifi_params.ssid
        logging.info('Connecting to %s.', connect_name)
        assoc_result = xmlrpc_datatypes.deserialize(
                self.client.shill.connect_wifi(wifi_params))
        logging.info('Finished connection attempt to %s with times: '
                     'discovery=%.2f, association=%.2f, configuration=%.2f.',
                     connect_name,
                     assoc_result.discovery_time,
                     assoc_result.association_time,
                     assoc_result.configuration_time)

        if assoc_result.success and wifi_params.expect_failure:
            raise error.TestFail(
                'Expected connection to %s to fail, but it was successful.' %
                connect_name)

        if not assoc_result.success and not wifi_params.expect_failure:
            raise error.TestFail(
                'Expected connection to %s to succeed, '
                'but it failed with reason: %s.' % (
                    connect_name, assoc_result.failure_reason))

        if wifi_params.expect_failure:
            logging.info('Unable to connect to %s, as intended.',
                         connect_name)
            return None

        logging.info('Connected successfully to %s.', connect_name)
        return assoc_result
Example #8
0
    def connect_wifi(self, raw_params):
        """Block and attempt to connect to wifi network.

        @param raw_params serialized AssociationParameters.
        @return serialized AssociationResult

        """
        logging.debug('connect_wifi()')
        params = xmlrpc_datatypes.deserialize(raw_params)
        params.security_config.install_client_credentials(self._tpm_store)
        wifi_if = params.bgscan_config.interface
        if wifi_if is None:
            logging.info('Using default interface for bgscan configuration')
            interfaces = self.list_controlled_wifi_interfaces()
            if not interfaces:
                return xmlrpc_datatypes.AssociationResult(
                    failure_reason='No wifi interfaces found?')

            if len(interfaces) > 1:
                logging.error('Defaulting to first interface of %r',
                              interfaces)
            wifi_if = interfaces[0]
        if not self._wifi_proxy.configure_bgscan(
                wifi_if,
                method=params.bgscan_config.method,
                short_interval=params.bgscan_config.short_interval,
                long_interval=params.bgscan_config.long_interval,
                signal=params.bgscan_config.signal):
            return xmlrpc_datatypes.AssociationResult(
                failure_reason='Failed to configure bgscan')

        raw = self._wifi_proxy.connect_to_wifi_network(
            params.ssid,
            params.security,
            params.security_parameters,
            params.save_credentials,
            station_type=params.station_type,
            hidden_network=params.is_hidden,
            guid=params.guid,
            discovery_timeout_seconds=params.discovery_timeout,
            association_timeout_seconds=params.association_timeout,
            configuration_timeout_seconds=params.configuration_timeout)
        result = xmlrpc_datatypes.AssociationResult.from_dbus_proxy_output(raw)
        return result
    def run_once(self, capturer, capturer_frequency, capturer_ht_type,
                 host, assoc_params, client, tries, debug_info=None):
        """ Main entry function for autotest.

        @param capturer: a packet capture device
        @param capturer_frequency: integer channel frequency in MHz.
        @param capturer_ht_type: string specifier of channel HT type.
        @param host: an Autotest host object, DUT.
        @param assoc_params: an AssociationParameters object.
        @param client: WiFiClient object
        @param tries: an integer, number of connection attempts.
        @param debug_info: a string of additional info to display on failure

        """

        results = []

        for i in range(1, tries + 1):
            client.shill.disconnect(assoc_params.ssid)
            if not client.shill.init_test_network_state():
                return 'Failed to set up isolated test context profile.'

            capturer.start_capture(capturer_frequency, ht_type=capturer_ht_type)
            try:
                success = False
                logging.info('Connection attempt %d', i)
                host.syslog('Connection attempt %d' % i)
                start_time = host.run("date '+%FT%T.%N%:z'").stdout.strip()
                assoc_result = xmlrpc_datatypes.deserialize(
                        client.shill.connect_wifi(assoc_params))
                end_time = host.run("date '+%FT%T.%N%:z'").stdout.strip()
                success = assoc_result.success
                if not success:
                    logging.info('Connection attempt %d failed; reason: %s',
                                 i, assoc_result.failure_reason)
                    results.append(
                            {'try' : i,
                             'error' : assoc_result.failure_reason,
                             'start_time': start_time,
                             'end_time': end_time})
                else:
                    logging.info('Connection attempt %d passed', i)
            finally:
                filename = str('connect_try_%d_%s.trc' % (i,
                               ('success' if success else 'fail')))
                capturer.stop_capture(save_dir=self.outputdir,
                                      save_filename=filename)
                if not success:
                    client.collect_debug_info('try_%d' % i)
                    chaos_clique_utils.collect_pcap_info(self.outputdir,
                                                         filename, i)
                client.shill.disconnect(assoc_params.ssid)
                client.shill.clean_profiles()

        if len(results) > 0:
            # error.TestError doesn't handle the formatting inline, doing it
            # here so it is clearer to read in the status.log file.
            msg = str('Failed on the following attempts:\n%s\n'
                      'With the assoc_params:\n%s\n'
                      'Debug info: %s\nDUT MAC:%s' %
                      (pprint.pformat(results), assoc_params, debug_info,
                       client.wifi_mac))
            raise error.TestFail(msg)
        logging.debug('Debug info: %s', debug_info)
    def run_once(self,
                 capturer,
                 capturer_frequency,
                 capturer_ht_type,
                 host,
                 assoc_params,
                 client,
                 debug_info=None,
                 conn_worker=None):
        """ Main entry function for autotest.

        @param capturer: a packet capture device
        @param capturer_frequency: integer channel frequency in MHz.
        @param capturer_ht_type: string specifier of channel HT type.
        @param host: an Autotest host object, DUT.
        @param assoc_params: an AssociationParameters object.
        @param client: WiFiClient object
        @param debug_info: a string of additional info to display on failure
        @param conn_worker: ConnectionWorkerAbstract or None, to run extra
            work after successful connection.

        """

        results = []

        client.shill.disconnect(assoc_params.ssid)
        if not client.shill.init_test_network_state():
            raise error.TestError('Failed to set up isolated test context '
                                  'profile.')

        capturer.start_capture(capturer_frequency, ht_type=capturer_ht_type)
        try:
            success = False
            for i in range(DUT_CONNECTION_RETRIES):
                logging.info('Connecting DUT (try: %d) to AP', (i + 1))
                host.syslog('Connection attempt %d' % (i + 1))
                assoc_result = xmlrpc_datatypes.deserialize(
                    client.shill.connect_wifi(assoc_params))
                success = assoc_result.success
                if not success:
                    logging.info(
                        'Connection attempt of DUT failed try %d;'
                        ' reason: %s', (i + 1), assoc_result.failure_reason)
                    continue
                else:
                    logging.info('DUT connected to the AP')
                    if conn_worker is not None:
                        conn_worker.run(client)
                    break

            if not success:
                msg = str('DUT failed to connect to the AP in %d tries:\n%s\n'
                          'With the assoc_params:\n%s\n Debug info: %s\n '
                          'DUT MAC: %s' %
                          (DUT_CONNECTION_RETRIES, pprint.pformat(results),
                           assoc_params, debug_info, client.wifi_mac))
                raise error.TestError(msg)
        finally:
            filename = str('connect_try_%s.trc' %
                           ('success' if success else 'fail'))
            capturer.stop_capture(save_dir=self.outputdir,
                                  save_filename=filename)
            client.shill.disconnect(assoc_params.ssid)
            client.shill.clean_profiles()