Ejemplo n.º 1
0
    def Run(self, args):
        """Run the 'gcloud test run' command to invoke a test in Firebase Test Lab.

    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.
    """
        device_catalog = util.GetAndroidCatalog(self.context)
        arg_manager.AndroidArgsManager(device_catalog).Prepare(args)

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

        bucket_ops = results_bucket.ResultsBucketOps(project,
                                                     args.results_bucket,
                                                     _UniqueGcsObjectName(),
                                                     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_name = PickHistoryName(args)
        history_id = tr_history_picker.GetToolResultsHistoryId(history_name)

        matrix = matrix_creator.CreateMatrix(args, self.context, history_id,
                                             bucket_ops.gcs_results_root)
        monitor = matrix_ops.MatrixMonitor(matrix.testMatrixId, 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)
            log.status.Print('')
            if args. async:
                return url
            log.status.Print(
                'Test 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()
Ejemplo n.º 2
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)
            log.status.Print('')
            if args. async:
                return url
            log.status.Print(
                'Test 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()