コード例 #1
0
    def Filter(self, context, args):
        """Modify the context that will be given to this group's commands when run.

    Args:
      context: {str:object}, The current context, which is a set of key-value
          pairs that can be used for common initialization among commands.
      args: argparse.Namespace: The same Namespace given to the corresponding
          .Run() invocation.

    Returns:
      The refined command context.
    """
        http = self.Http()
        testing_url = properties.VALUES.api_endpoint_overrides.testing.Get()
        toolresults_url = properties.VALUES.api_endpoint_overrides.toolresults.Get(
        )
        log.info('Test Service endpoint: [{0}]'.format(testing_url))
        log.info('Tool Results endpoint: [{0}]'.format(toolresults_url))

        # Create the Testing service client
        resources.SetParamDefault(api='test',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        # TODO(user) Support multiple versions when they exist
        testing_client_v1 = testing_v1.TestingV1(get_credentials=False,
                                                 url=testing_url,
                                                 http=http)
        testing_registry = resources.REGISTRY.CloneAndSwitchAPIs(
            testing_client_v1)
        context['testing_client'] = testing_client_v1
        context['testing_messages'] = testing_v1
        context['testing_registry'] = testing_registry

        # Create the Tool Results service client.
        resources.SetParamDefault(api='toolresults',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        toolresults_client_v1 = toolresults_v1beta3.ToolresultsV1beta3(
            get_credentials=False, url=toolresults_url, http=http)
        tr_registry = resources.REGISTRY.CloneAndSwitchAPIs(
            toolresults_client_v1)
        context['toolresults_client'] = toolresults_client_v1
        context['toolresults_messages'] = toolresults_v1beta3
        context['toolresults_registry'] = tr_registry

        # Get the android catalog and store in the context
        context['android_catalog'] = util.GetAndroidCatalog(context)

        # TODO(user): remove this message for general release.
        log.status.Print(
            '\nHave questions, feedback, or issues? Please let us know by using '
            'this Google Group:\n  https://groups.google.com/forum/#!forum'
            '/google-cloud-test-lab-external\n')

        return context
コード例 #2
0
ファイル: list.py プロジェクト: wsong/google-cloud-sdk
    def Run(self, args):
        """Run the 'gcloud test android devices list' command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation (i.e. group and command arguments combined).

    Returns:
      The list of device models we want to have printed later.
    """
        catalog = util.GetAndroidCatalog(self.context)
        return catalog.models
コード例 #3
0
  def Filter(self, context, args):
    """Modify the context that will be given to this group's commands when run.

    Args:
      context: {str:object}, The current context, which is a set of key-value
          pairs that can be used for common initialization among commands.
      args: argparse.Namespace: The same Namespace given to the corresponding
          .Run() invocation.

    Returns:
      The refined command context.
    """
    # Get the android catalog and store in the context
    context['android_catalog'] = util.GetAndroidCatalog(context)
    return context
コード例 #4
0
    def Run(self, args):
        """Run the 'gcloud test run' command to invoke a Google Cloud Test Lab test.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation (i.e. group and command arguments combined).

    Returns:
      One of:
        - a list of TestOutcome tuples (if ToolResults are available).
        - a URL string pointing to the user's results in ToolResults or GCS.
    """
        _EnsureUserAcceptsTermsOfService()
        arg_util.Prepare(args, util.GetAndroidCatalog(self.context))

        project = util.GetProject()
        tr_client = self.context['toolresults_client']
        tr_messages = self.context['toolresults_messages']
        storage_client = self.context['storage_client']

        # The Testing back-end needs a unique GCS object name within the results
        # bucket to prevent race conditions while processing test results. This
        # client uses the current time down to the microsecond in ISO format plus a
        # random 4-letter suffix. The format is: "YYYY-MM-DD_hh:mm:ss.ssssss_rrrr"
        unique_object = '{0}_{1}'.format(
            datetime.datetime.now().isoformat('_'),
            ''.join(random.sample(string.letters, 4)))
        bucket_ops = results_bucket.ResultsBucketOps(project,
                                                     args.results_bucket,
                                                     unique_object, tr_client,
                                                     tr_messages,
                                                     storage_client)
        bucket_ops.UploadFileToGcs(args.app)
        if args.test:
            bucket_ops.UploadFileToGcs(args.test)
        for obb_file in (args.obb_files or []):
            bucket_ops.UploadFileToGcs(obb_file)
        bucket_ops.LogGcsResultsUrl()

        tr_history_picker = history_picker.ToolResultsHistoryPicker(
            project, tr_client, tr_messages)
        history_id = tr_history_picker.FindToolResultsHistoryId(args)
        matrix = matrix_ops.CreateMatrix(args, self.context, history_id,
                                         bucket_ops.gcs_results_root)
        matrix_id = matrix.testMatrixId
        monitor = matrix_ops.MatrixMonitor(matrix_id, args.type, self.context)

        with ctrl_c_handler.CancellableTestSection(monitor):
            supported_executions = monitor.HandleUnsupportedExecutions(matrix)
            tr_ids = tool_results.GetToolResultsIds(matrix, monitor)

            url = tool_results.CreateToolResultsUiUrl(project, tr_ids)
            if args. async:
                return url
            log.status.Print(
                '\nTest results will be streamed to [{0}].'.format(url))

            # If we have exactly one testExecution, show detailed progress info.
            if len(supported_executions) == 1:
                monitor.MonitorTestExecutionProgress(
                    supported_executions[0].id)
            else:
                monitor.MonitorTestMatrixProgress()

        log.status.Print('\nMore details are available at [{0}].'.format(url))
        # Fetch the per-dimension test outcomes list, and also the "rolled-up"
        # matrix outcome from the Tool Results service.
        summary_fetcher = results_summary.ToolResultsSummaryFetcher(
            project, tr_client, tr_messages, tr_ids)
        self.exit_code = exit_code.ExitCodeFromRollupOutcome(
            summary_fetcher.FetchMatrixRollupOutcome(),
            tr_messages.Outcome.SummaryValueValuesEnum)
        return summary_fetcher.CreateMatrixOutcomeSummary()