def _ConfigSetConverter(obj): return _ConfigSetMessage( node_config=messages.Convert(obj.node_config, messages.NodeConfig), build_channels=messages.ConvertList(obj.build_channels, messages.BuildChannelConfig), device_actions=messages.ConvertList(obj.device_actions, messages.DeviceAction), test_run_actions=messages.ConvertList(obj.test_run_actions, messages.TestRunAction), tests=messages.ConvertList(obj.tests, messages.Test), info=messages.Convert(obj.info, messages.ConfigSetInfo))
def _ConfigSetMessageConverter(msg): return ConfigSet( node_config=messages.Convert(msg.node_config, ndb_models.NodeConfig), build_channels=messages.ConvertList(msg.build_channels, ndb_models.BuildChannelConfig), device_actions=messages.ConvertList(msg.device_actions, ndb_models.DeviceAction), test_run_actions=messages.ConvertList(msg.test_run_actions, ndb_models.TestRunAction), tests=messages.ConvertList(msg.tests, ndb_models.Test), info=messages.Convert(msg.info, ndb_models.ConfigSetInfo))
def List(self, request): """Lists test plans.""" test_plans = list(ndb_models.TestPlan.query().order( ndb_models.TestPlan.name)) test_plan_msgs = mtt_messages.ConvertList(test_plans, mtt_messages.TestPlan) return mtt_messages.TestPlanList(test_plans=test_plan_msgs)
def List(self, request): """Lists device actions.""" device_actions = list(ndb_models.DeviceAction.query().order( ndb_models.DeviceAction.name)) device_action_msgs = mtt_messages.ConvertList( device_actions, mtt_messages.DeviceAction) return mtt_messages.DeviceActionList(device_actions=device_action_msgs)
def ListSummaries(self, request): """Fetches a page of test run summaries. Parameters: max_results: Maximum number of test runs to return page_token: Token for pagination backwards: True to fetch previous page of results labels: Labels to look for test: Test name to look for device_spec: A device spec to look for state: List of test run states to include device_build_id: Build ID to look for test_package_info: Test package to look for prev_test_run_id: Previous test run ID filter_query: Additional filters to apply (applied to test name, run target, labels, test package name and version, device build ID and product) """ query = ndb_models.TestRunSummary.query().order( -ndb_models.TestRunSummary.create_time, ndb_models.TestRunSummary.key) query = self._ApplyQueryFilters(query, request) result_filter = self._BuildTestRunFilterFunction(request) test_runs, prev_cursor, next_cursor = datastore_util.FetchPage( query, request.max_results, page_cursor=request.page_token, backwards=request.backwards, result_filter=result_filter) return mtt_messages.TestRunSummaryList( test_runs=mtt_messages.ConvertList(test_runs, mtt_messages.TestRunSummary), prev_page_token=prev_cursor, next_page_token=next_cursor)
def New(self, request): """Creates a new test run. Body: Test run request data """ labels = request.labels test_run_config = mtt_messages.Convert(request.test_run_config, ndb_models.TestRunConfig) if not test_run_config.device_specs: if not test_run_config.run_target: raise endpoints.BadRequestException( 'test_run_config.(device_specs or run_target) must be set') # For old run targets are one or more device serials. Convert them to # device specs for backward compatibility test_run_config.device_specs = mtt_messages.ConvertToDeviceSpecs( test_run_config.run_target) test_run_config.run_target = None # start test run test_run = test_kicker.CreateTestRun( labels=labels, test_run_config=test_run_config, rerun_context=request.rerun_context, rerun_configs=mtt_messages.ConvertList(request.rerun_configs, ndb_models.TestRunConfig)) return mtt_messages.Convert(test_run, mtt_messages.TestRun)
def ListBuildChannels(self, request): """Fetches a list of build channels used for importing config sets.""" channels = [] for channel_id in config_set_helper.CONFIG_SET_BUILD_CHANNEL_IDS: channels.append(build.GetBuildChannel(channel_id)) return mtt_messages.BuildChannelList( build_channels=mtt_messages.ConvertList(channels, mtt_messages.BuildChannel))
def _GetLegacyTestModuleResults( self, request_id: int) -> mtt_messages.TestModuleResultList: """Fetch legacy test module results from TFC.""" invocation_status = tfc_client.GetRequestInvocationStatus(request_id) test_group_statuses = sorted(invocation_status.test_group_statuses or [], key=lambda s: (s.is_complete, -s.failed_test_count)) results = mtt_messages.ConvertList(test_group_statuses, mtt_messages.TestModuleResult) return mtt_messages.TestModuleResultList( results=results, extra_info='Legacy test results from request %s' % request_id)
def _GetTestModuleResults( self, attempt_id: str) -> typing.List[mtt_messages.TestModuleResult]: """Fetch test module results from the DB.""" with sql_models.db.Session() as session: query = session.query(sql_models.TestModuleResult) query = query.order_by( sql_models.TestModuleResult.complete, sql_models.TestModuleResult.failed_tests.desc(), sql_models.TestModuleResult.id) query = query.filter_by(attempt_id=attempt_id) modules = query.all() return mtt_messages.ConvertList(modules, mtt_messages.TestModuleResult)
def ListBuildItems(self, request): """Fetches a list of build items. Parameters: build_channel_id: Build channel ID path: Build item path page_token: Token for pagination """ build_channel = self._GetBuildChannel(request.build_channel_id) build_items, next_page_token = build_channel.ListBuildItems( path=request.path, page_token=request.page_token) return mtt_messages.BuildItemList( build_items=mtt_messages.ConvertList( build_items, mtt_messages.BuildItem), next_page_token=next_page_token)
def ListTestCaseResults(self, request): """Fetches a page of test case results. Parameters: module_id: Test module ID max_results: Maximum number of test results to return page_token: Token for pagination status: Set of statuses to include name: Partial name filter (case-insensitive) """ with sql_models.db.Session() as session: # Find parent module module = session.query(sql_models.TestModuleResult).get( request.module_id) if not module: raise endpoints.NotFoundException('Module %s not found' % request.module_id) # Initialize query (ordered by insertion order) query = session.query(sql_models.TestCaseResult) query = query.order_by( sql_models.TestCaseResult.id).with_parent(module) # Apply page token (<last id>) if request.page_token: query = query.filter( sql_models.TestCaseResult.id > int(request.page_token)) # Apply filters if request.status: query = query.filter( sql_models.TestCaseResult.status.in_(request.status)) if request.name: query = query.filter( sql_models.TestCaseResult.name.contains(request.name)) # Fetch at most N + 1 results if request.max_results and request.max_results > 0: query = query.limit(request.max_results + 1) test_cases = query.all() # Generate next page token and response next_page_token = None if request.max_results and 0 < request.max_results < len(test_cases): test_cases = test_cases[:-1] next_page_token = str(test_cases[-1].id) results = mtt_messages.ConvertList(test_cases, mtt_messages.TestCaseResult) return mtt_messages.TestCaseResultList(results=results, next_page_token=next_page_token)
def List(self, request): """Lists registered build channels.""" objs = build.ListBuildChannels() build_channels = mtt_messages.ConvertList(objs, mtt_messages.BuildChannel) return mtt_messages.BuildChannelList(build_channels=build_channels)
def List(self, request): """Lists test suites.""" tests = list(ndb_models.Test.query().order(ndb_models.Test.name)) test_msgs = mtt_messages.ConvertList(tests, mtt_messages.Test) return mtt_messages.TestList(tests=test_msgs)