예제 #1
0
 def warmup(self, host, router_hostname=None):
     self._router = None
     self._shill_xmlrpc_proxy = None
     config = buffet_config.BuffetConfig(
             log_verbosity=3,
             enable_ping=True,
             disable_pairing_security=True,
             device_whitelist='any',
             options={'wifi_bootstrap_mode': 'automatic'})
     config.restart_with_config(host=host)
     self._router = site_linux_router.build_router_proxy(
             test_name=self.__class__.__name__,
             client_hostname=host.hostname,
             router_addr=router_hostname,
             enable_avahi=True)
     self._shill_xmlrpc_proxy = wifi_client.get_xmlrpc_proxy(host)
     # Cleans up profiles, wifi credentials, sandboxes our new credentials.
     self._shill_xmlrpc_proxy.init_test_network_state()
     peerd_config.PeerdConfig(verbosity_level=3).restart_with_config(
             host=host)
예제 #2
0
 def __init__(self):
     """Initialization routine."""
     # We're going to confirm buffet is polling by issuing commands to
     # the mock GCD server, then checking that buffet gets them.  The
     # commands are test.TestEcho commands with a single parameter
     # |message|.  |self._expected_messages| is a list of these messages.
     self._expected_messages = []
     # We store our command definitions under this root.
     self._temp_dir_path = None
     # Spin up our mock server.
     self._gcd = fake_gcd_helper.FakeGCDHelper()
     self._gcd.start()
     # Create the command definition we want to use.
     self._temp_dir_path = tempfile.mkdtemp()
     commands_dir = os.path.join(self._temp_dir_path, 'commands')
     os.mkdir(commands_dir)
     command_definition_path = os.path.join(
         commands_dir, '%s.json' % TEST_COMMAND_CATEGORY)
     with open(command_definition_path, 'w') as f:
         f.write(json.dumps(TEST_COMMAND_DEFINITION))
     utils.run('chown -R buffet:buffet %s' % self._temp_dir_path)
     logging.debug('Created test commands definition: %s',
                   command_definition_path)
     # Create client proxies for interacting with oyr fake server.
     self._registration_client = registration.RegistrationClient(
         server_url=buffet_config.LOCAL_SERVICE_URL,
         api_key=buffet_config.TEST_API_KEY)
     self._device_client = devices.DevicesClient(
         server_url=buffet_config.LOCAL_SERVICE_URL,
         api_key=buffet_config.TEST_API_KEY)
     self._oauth_client = oauth.OAuthClient(
         server_url=buffet_config.LOCAL_SERVICE_URL,
         api_key=buffet_config.TEST_API_KEY)
     self._fail_control_client = fail_control.FailControlClient(
         server_url=buffet_config.LOCAL_SERVICE_URL,
         api_key=buffet_config.TEST_API_KEY)
     self._command_client = commands.CommandsClient(
         server_url=buffet_config.LOCAL_SERVICE_URL,
         api_key=buffet_config.TEST_API_KEY)
     self._config = buffet_config.BuffetConfig(
         log_verbosity=3, test_definitions_dir=self._temp_dir_path)
 def warmup(self, host):
     config = buffet_config.BuffetConfig(log_verbosity=3)
     config.restart_with_config(host=host)
예제 #4
0
    def run_once(self):
        """Test entry point."""
        buffet_config.BuffetConfig(
            disable_pairing_security=True).restart_with_config()
        buffet = buffet_dbus_helper.BuffetDBusHelper()

        check('', buffet.device_id)
        check('Chromium', buffet.oem_name)
        check('Brillo', buffet.model_name)
        check('AATST', buffet.model_id)
        check('', buffet.description)
        check('', buffet.location)

        buffet.manager.UpdateDeviceInfo(dbus.String('A'), dbus.String('B'),
                                        dbus.String('C'))

        check('A', buffet.name)
        check('B', buffet.description)
        check('C', buffet.location)

        # The test method better work.
        test_message = 'Hello world!'
        echoed_message = buffet.manager.TestMethod(test_message)
        if test_message != echoed_message:
            raise error.TestFail('Expected Manager.TestMethod to return %s '
                                 'but got %s instead.' %
                                 (test_message, echoed_message))

        # We should get the firmware version right.
        expected_version = None
        with open('/etc/lsb-release') as f:
            for line in f.readlines():
                pieces = line.split('=', 1)
                if len(pieces) != 2:
                    continue
                key = pieces[0].strip()
                if key == 'CHROMEOS_RELEASE_VERSION':
                    expected_version = pieces[1].strip()

        if expected_version is None:
            raise error.TestError('Failed to read version from lsb-release')
        raw_state = buffet.manager.GetState()
        parsed_state = json.loads(raw_state)
        logging.debug('%r', parsed_state)
        actual_version = parsed_state['base']['firmwareVersion']
        if actual_version != expected_version:
            raise error.TestFail(
                'Expected firmwareVersion "%s", but got "%s"' %
                (expected_version, actual_version))

        check(raw_state, buffet.state)
        expected_base_keys = sets.Set([
            'firmwareVersion', 'localDiscoveryEnabled',
            'localAnonymousAccessMaxRole', 'localPairingEnabled'
        ])
        missing_base_keys = sets.Set(expected_base_keys).difference(
            parsed_state['base'].keys())
        if missing_base_keys:
            raise error.TestFail('Missing base keys "%s"' % missing_base_keys)

        # Privet API
        shill = wifi_proxy.WifiProxy.get_proxy()
        shill.remove_all_wifi_entries()

        check({}, buffet.pairing_info)

        # But we should still be able to pair.
        helper = privet_helper.PrivetHelper()
        data = {'pairing': 'pinCode', 'crypto': 'none'}
        pairing = helper.send_privet_request(privet_helper.URL_PAIRING_START,
                                             request_data=data)
        # And now we should be able to see a pin code in our pairing status.
        pairing_info = buffet.pairing_info
        logging.debug(pairing_info)
        check(pairing_info.get('sessionId', ''), pairing['sessionId'])

        if not 'code' in pairing_info:
            raise error.TestFail('No code in pairing info (%r)' % pairing_info)
        # And if we start a new pairing session, the session ID should change.
        old_session_id = pairing_info['sessionId']
        pairing = helper.send_privet_request(privet_helper.URL_PAIRING_START,
                                             request_data=data)
        if pairing['sessionId'] == old_session_id:
            raise error.TestFail('Session IDs should change on each new '
                                 'pairing attempt.')
        # And if we start and complete a pairing session, we should have no
        # pairing information exposed.
        helper.privet_auth()
        check({}, buffet.pairing_info)