Exemplo n.º 1
0
 def _GetDeviceList(self):
   with appurify_sanitized.SanitizeLogging(self._verbose_count,
                                           logging.WARNING):
     dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
   remote_device_helper.TestHttpResponse(dev_list_res,
                                        'Unable to generate access token.')
   return dev_list_res.json()['response']
Exemplo n.º 2
0
    def _DownloadTestResults(self, results_path):
        """Download the test results from remote device service.

    Downloads results in temporary location, and then copys results
    to results_path if results_path is not set to None.

    Args:
      results_path: Path to download appurify results zipfile.

    Returns:
      Path to downloaded file.
    """

        if self._results_temp_dir is None:
            self._results_temp_dir = tempfile.mkdtemp()
            logging.info('Downloading results to %s.' % self._results_temp_dir)
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                appurify_sanitized.utils.wget(
                    self._results['results']['url'],
                    self._results_temp_dir + '/results')
        if results_path:
            logging.info('Copying results to %s', results_path)
            if not os.path.exists(os.path.dirname(results_path)):
                os.makedirs(os.path.dirname(results_path))
            shutil.copy(self._results_temp_dir + '/results', results_path)
        return self._results_temp_dir + '/results'
Exemplo n.º 3
0
 def _SelectDevice(self):
     """Select which device to use."""
     logging.info('Finding device to run tests on.')
     with appurify_sanitized.SanitizeLogging(self._verbose_count,
                                             logging.WARNING):
         dev_list_res = appurify_sanitized.api.devices_list(
             self._access_token)
     remote_device_helper.TestHttpResponse(
         dev_list_res, 'Unable to generate access token.')
     device_list = dev_list_res.json()['response']
     random.shuffle(device_list)
     for device in device_list:
         if device['os_name'] != self._device_type:
             continue
         if self._remote_device and device['name'] != self._remote_device:
             continue
         if (self._remote_device_os
                 and device['os_version'] != self._remote_device_os):
             continue
         if ((self._remote_device and self._remote_device_os)
                 or device['available_devices_count']):
             logging.info('Found device: %s %s', device['name'],
                          device['os_version'])
             return device
     self._NoDeviceFound(device_list)
Exemplo n.º 4
0
 def _CollectTearDown(self):
   if self._GetTestStatus(self._test_run_id) != self.COMPLETE:
     with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                             logging.WARNING):
       test_abort_res = appurify_sanitized.api.tests_abort(
           self._env.token, self._test_run_id, reason='Test runner exiting.')
     remote_device_helper.TestHttpResponse(test_abort_res,
                                           'Unable to abort test.')
Exemplo n.º 5
0
 def _RevokeAccessToken(self):
   """Destroys access token for remote device service."""
   logging.info('Revoking remote service access token')
   with appurify_sanitized.SanitizeLogging(self._verbose_count,
                                           logging.WARNING):
     revoke_token_results = appurify_sanitized.api.access_token_revoke(
         self._access_token)
   remote_device_helper.TestHttpResponse(revoke_token_results,
                                         'Unable to revoke access token.')
Exemplo n.º 6
0
 def _GetAccessToken(self):
   """Generates access token for remote device service."""
   logging.info('Generating remote service access token')
   with appurify_sanitized.SanitizeLogging(self._verbose_count,
                                           logging.WARNING):
     access_token_results = appurify_sanitized.api.access_token_generate(
         self._api_key, self._api_secret)
   remote_device_helper.TestHttpResponse(access_token_results,
                                         'Unable to generate access token.')
   self._access_token = access_token_results.json()['response']['access_token']
Exemplo n.º 7
0
 def _UploadAppToDevice(self, app_path):
   """Upload app to device."""
   logging.info('Uploading %s to remote service.', app_path)
   with open(app_path, 'rb') as apk_src:
     with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                             logging.WARNING):
       upload_results = appurify_sanitized.api.apps_upload(
           self._env.token, apk_src, 'raw', name=self._test_instance.suite)
     remote_device_helper.TestHttpResponse(
         upload_results, 'Unable to upload %s.' % app_path)
     return upload_results.json()['response']['app_id']
Exemplo n.º 8
0
 def _UploadTestToDevice(self, test_type, test_path, app_id=None):
   """Upload test to device
   Args:
     test_type: Type of test that is being uploaded. Ex. uirobot, gtest..
   """
   logging.info('Uploading %s to remote service.' % test_path)
   with open(test_path, 'rb') as test_src:
     with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                             logging.WARNING):
       upload_results = appurify_sanitized.api.tests_upload(
           self._env.token, test_src, 'raw', test_type, app_id=app_id)
     remote_device_helper.TestHttpResponse(upload_results,
         'Unable to upload %s.' % test_path)
     return upload_results.json()['response']['test_id']
Exemplo n.º 9
0
  def _DownloadTestResults(self, results_path):
    """Download the test results from remote device service.

    Args:
      results_path: path to download results to.
    """
    if results_path:
      logging.info('Downloading results to %s.' % results_path)
      if not os.path.exists(os.path.basename(results_path)):
        os.makedirs(os.path.basename(results_path))
        with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                logging.WARNING):
          appurify_sanitized.utils.wget(self._results['results']['url'],
                                        results_path)
Exemplo n.º 10
0
  def _GetTestStatus(self, test_run_id):
    """Checks the state of the test, and sets self._results

    Args:
      test_run_id: Id of test on on remote service.
    """

    with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                            logging.WARNING):
      test_check_res = appurify_sanitized.api.tests_check_result(
          self._env.token, test_run_id)
    remote_device_helper.TestHttpResponse(test_check_res,
                                          'Unable to get test status.')
    self._results = test_check_res.json()['response']
    return self._results['status']
Exemplo n.º 11
0
 def _UploadTestToDevice(self, test_type, test_path, app_id=None):
     if test_path:
         logging.info("Ignoring test path.")
     data = {
         'access_token': self._env.token,
         'test_type': test_type,
         'app_id': app_id,
     }
     with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                             logging.WARNING):
         test_upload_res = appurify_sanitized.utils.post(
             'tests/upload', data, None)
     remote_device_helper.TestHttpResponse(
         test_upload_res, 'Unable to get UiRobot test id.')
     return test_upload_res.json()['response']['test_id']
Exemplo n.º 12
0
  def _GetTestByName(self, test_name):
    """Gets test_id for specific test.

    Args:
      test_name: Test to find the ID of.
    """
    with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                            logging.WARNING):
      test_list_res = appurify_sanitized.api.tests_list(self._env.token)
    remote_device_helper.TestHttpResponse(test_list_res,
                                          'Unable to get tests list.')
    for test in test_list_res.json()['response']:
      if test['test_type'] == test_name:
        return test['test_id']
    raise remote_device_helper.RemoteDeviceError(
        'No test found with name %s' % (test_name))
Exemplo n.º 13
0
    def RunTests(self):
        """Run the test."""
        if self._env.trigger:
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                test_start_res = appurify_sanitized.api.tests_run(
                    self._env.token, self._env.device_type_id, self._app_id,
                    self._test_id)
            remote_device_helper.TestHttpResponse(test_start_res,
                                                  'Unable to run test.')
            self._test_run_id = test_start_res.json(
            )['response']['test_run_id']
            logging.info('Test run id: %s' % self._test_run_id)

        if self._env.collect:
            current_status = ''
            timeout_counter = 0
            heartbeat_counter = 0
            while self._GetTestStatus(self._test_run_id) != self.COMPLETE:
                if self._results['detailed_status'] != current_status:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    current_status = self._results['detailed_status']
                    timeout_counter = 0
                    heartbeat_counter = 0
                if heartbeat_counter > self.HEARTBEAT_INTERVAL:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    heartbeat_counter = 0

                timeout = self._env.timeouts.get(current_status,
                                                 self._env.timeouts['unknown'])
                if timeout_counter > timeout:
                    raise remote_device_helper.RemoteDeviceError(
                        'Timeout while in %s state for %s seconds' %
                        (current_status, timeout),
                        is_infra_error=True)
                time.sleep(self.WAIT_TIME)
                timeout_counter += self.WAIT_TIME
                heartbeat_counter += self.WAIT_TIME
            self._DownloadTestResults(self._env.results_path)

            if self._results['results']['exception']:
                raise remote_device_helper.RemoteDeviceError(
                    self._results['results']['exception'], is_infra_error=True)

            return self._ParseTestResults()
Exemplo n.º 14
0
 def _SetTestConfig(self, runner_type, body):
     """Generates and uploads config file for test.
 Args:
   extras: Extra arguments to set in the config file.
 """
     logging.info('Generating config file for test.')
     with tempfile.TemporaryFile() as config:
         config_data = [
             '[appurify]', 'pcap=0', 'profiler=0', 'videocapture=0',
             '[%s]' % runner_type
         ]
         config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems())
         config.write(''.join('%s\n' % l for l in config_data))
         config.flush()
         config.seek(0)
         with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                 logging.WARNING):
             config_response = appurify_sanitized.api.config_upload(
                 self._env.token, config, self._test_id)
         remote_device_helper.TestHttpResponse(
             config_response, 'Unable to upload test config.')
Exemplo n.º 15
0
    def _SetTestConfig(self,
                       runner_type,
                       runner_configs,
                       network=appurify_constants.NETWORK.WIFI_1_BAR,
                       pcap=0,
                       profiler=0,
                       videocapture=0):
        """Generates and uploads config file for test.
    Args:
      runner_configs: Configs specific to the runner you are using.
      network: Config to specify the network environment the devices running
          the tests will be in.
      pcap: Option to set the recording the of network traffic from the device.
      profiler: Option to set the recording of CPU, memory, and network
          transfer usage in the tests.
      videocapture: Option to set video capture during the tests.

    """
        logging.info('Generating config file for test.')
        with tempfile.TemporaryFile() as config:
            config_data = [
                '[appurify]',
                'network=%s' % network,
                'pcap=%s' % pcap,
                'profiler=%s' % profiler,
                'videocapture=%s' % videocapture,
                '[%s]' % runner_type
            ]
            config_data.extend('%s=%s' % (k, v)
                               for k, v in runner_configs.iteritems())
            config.write(''.join('%s\n' % l for l in config_data))
            config.flush()
            config.seek(0)
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                config_response = appurify_sanitized.api.config_upload(
                    self._env.token, config, self._test_id)
            remote_device_helper.TestHttpResponse(
                config_response, 'Unable to upload test config.')