def _MasterNameIsWhitelisted(master_name): """Checks whether a master name is acceptable by checking a whitelist.""" bisect_bot_map = namespaced_stored_object.Get(BISECT_BOT_MAP_KEY) if not bisect_bot_map: return True # If there's no list available, all names are OK. whitelisted_masters = list(bisect_bot_map) return master_name in whitelisted_masters
def _GetChartValues(self): return { 'revision_info': namespaced_stored_object.Get(_REVISION_INFO_KEY) or {}, 'warning_message': layered_cache.Get('warning_message'), 'warning_bug': layered_cache.Get('warning_bug'), }
def AddRowsToCache(row_entities): """Adds a list of rows to the cache, in revision order. Updates multiple cache entries for different tests. Args: row_entities: List of Row entities. """ test_key_to_rows = {} for row in row_entities: test_key = row.parent_test if test_key in test_key_to_rows: graph_rows = test_key_to_rows[test_key] else: test_path = utils.TestPath(test_key) graph_rows = namespaced_stored_object.Get(_CACHE_KEY % test_path) if not graph_rows: # We only want to update caches for tests that people have looked at. continue test_key_to_rows[test_key] = graph_rows revisions = [r[0] for r in graph_rows] index = bisect.bisect_left(revisions, row.revision) if index < len(revisions) - 1: if revisions[index + 1] == row.revision: return # Already in cache. graph_rows.insert(index, _MakeTriplet(row)) for test_key in test_key_to_rows: graph_rows = test_key_to_rows[test_key] SetCache(utils.TestPath(test_key), graph_rows)
def _GetAvailableBisectBots(master_name): """Get all available bisect bots corresponding to a master name.""" bisect_bot_map = namespaced_stored_object.Get(_BISECT_BOT_MAP_KEY) for master, platform_bot_pairs in bisect_bot_map.iteritems(): if master_name.startswith(master): return sorted({bot for _, bot in platform_bot_pairs}) return []
def _GetTryServerMaster(bisect_job): """Returns the try server master to be used for bisecting.""" try_server_map = namespaced_stored_object.Get(_MASTER_TRY_SERVER_MAP_KEY) default = 'tryserver.chromium.perf' if not try_server_map: logging.warning('Could not get master to try server map, using default.') return default return try_server_map.get(bisect_job.master_name, default)
def _GetTryServerBucket(bisect_job): """Returns the bucket name to be used by buildbucket.""" master_bucket_map = namespaced_stored_object.Get(_MASTER_BUILDBUCKET_MAP_KEY) default = 'master.tryserver.chromium.perf' if not master_bucket_map: logging.warning( 'Could not get bucket to be used by buildbucket, using default.') return default return master_bucket_map.get(bisect_job.master_name, default)
def _GuessBrowserName(bisect_bot): """Returns a browser name string for Telemetry to use.""" default = 'release' browser_map = namespaced_stored_object.Get(_BOT_BROWSER_MAP_KEY) if not browser_map: return default for bot_name_prefix, browser_name in browser_map: if bisect_bot.startswith(bot_name_prefix): return browser_name return default
def testPost_WithKey_UpdatesNamespacedValues(self): namespaced_stored_object.Set('foo', 'XXXinternalYYY') namespaced_stored_object.SetExternal('foo', 'XXXYYY') self.testapp.post('/edit_site_config', { 'key': 'foo', 'external_value': '{"x": "y"}', 'internal_value': '{"x": "yz"}', 'xsrf_token': xsrf.GenerateToken(users.get_current_user()), }) self.assertEqual({'x': 'yz'}, namespaced_stored_object.Get('foo')) self.assertEqual({'x': 'y'}, namespaced_stored_object.GetExternal('foo'))
def RenderHtml(self, template_file, template_values, status=200): """Fills in template values for pages that show charts.""" revision_info = namespaced_stored_object.Get(_REVISION_INFO_KEY) or {} template_values.update({ 'revision_info': json.dumps(revision_info), 'warning_message': layered_cache.Get('warning_message'), 'warning_bug': layered_cache.Get('warning_bug'), }) return super(ChartHandler, self).RenderHtml(template_file, template_values, status)
def post(self): """Fetches a list of revisions and values for a given test. Request parameters: test_path: Full test path for a TestMetadata entity. Outputs: A JSON list of 3-item lists [revision, value, timestamp]. """ test_path = self.request.get('test_path') rows = namespaced_stored_object.Get(_CACHE_KEY % test_path) if not rows: rows = _UpdateCache(utils.TestKey(test_path)) self.response.out.write(json.dumps(rows))
def _BuilderType(master_name, use_archive): """Returns the builder_type string to use in the bisect config. Args: master_name: The test master name. use_archive: Whether or not to use archived builds. Returns: A string which indicates where the builds should be obtained from. """ if not use_archive: return '' builder_types = namespaced_stored_object.Get(_BUILDER_TYPES_KEY) if not builder_types or master_name not in builder_types: return 'perf' return builder_types[master_name]
def get(self): """Renders the UI with the form.""" key = self.request.get('key') if not key: self.RenderHtml('edit_site_config.html', {}) return value = stored_object.Get(key) external_value = namespaced_stored_object.GetExternal(key) internal_value = namespaced_stored_object.Get(key) self.RenderHtml('edit_site_config.html', { 'key': key, 'value': _FormatJson(value), 'external_value': _FormatJson(external_value), 'internal_value': _FormatJson(internal_value), })
def GuessBisectBot(master_name, bot_name): """Returns a bisect bot name based on |bot_name| (perf_id) string.""" fallback = 'linux_perf_bisect' bisect_bot_map = namespaced_stored_object.Get(_BISECT_BOT_MAP_KEY) if not bisect_bot_map: return fallback bot_name = bot_name.lower() for master, platform_bot_pairs in bisect_bot_map.iteritems(): # Treat ChromiumPerfFyi (etc.) the same as ChromiumPerf. if master_name.startswith(master): for platform, bisect_bot in platform_bot_pairs: if platform in bot_name: return bisect_bot # Nothing was found; log a warning and return a fall-back name. logging.warning('No bisect bot for %s/%s.', master_name, bot_name) return fallback
def post(self): """Accepts posted values, makes changes, and shows the form again.""" key = self.request.get('key') if not utils.IsInternalUser(): self.RenderHtml('edit_site_config.html', { 'error': 'Only internal users can post to this end-point.' }) return if not key: self.RenderHtml('edit_site_config.html', {}) return new_value_json = self.request.get('value').strip() new_external_value_json = self.request.get('external_value').strip() new_internal_value_json = self.request.get('internal_value').strip() template_params = { 'key': key, 'value': new_value_json, 'external_value': new_external_value_json, 'internal_value': new_internal_value_json, } try: new_value = json.loads(new_value_json or 'null') new_external_value = json.loads(new_external_value_json or 'null') new_internal_value = json.loads(new_internal_value_json or 'null') except ValueError: template_params['error'] = 'Invalid JSON in at least one field.' self.RenderHtml('edit_site_config.html', template_params) return old_value = stored_object.Get(key) old_external_value = namespaced_stored_object.GetExternal(key) old_internal_value = namespaced_stored_object.Get(key) stored_object.Set(key, new_value) namespaced_stored_object.SetExternal(key, new_external_value) namespaced_stored_object.Set(key, new_internal_value) _SendNotificationEmail( key, old_value, old_external_value, old_internal_value, new_value, new_external_value, new_internal_value) self.RenderHtml('edit_site_config.html', template_params)
def GetBisectDirectorForTester(master_name, bot): """Maps the name of a tester bot to its corresponding bisect director. Args: bot (str): The name of the tester bot in the tryserver.chromium.perf waterfall. (e.g. 'linux_perf_tester'). master_name (str): The name of the master where the bot is hosted. Returns: The name of the bisect director that can use the given tester (e.g. 'linux_perf_bisector') """ master_tester_map = namespaced_stored_object.Get(_TESTER_DIRECTOR_MAP_KEY) for master, recipe_tester_director_mapping in master_tester_map.iteritems(): if master_name.startswith(master): return recipe_tester_director_mapping.get(bot) return []
def testGet_ExternalUser_ExternalVersionReturned(self): self.SetCurrentUser('*****@*****.**') stored_object.Set('internal_only__foo', [1, 2, 3]) stored_object.Set('externally_visible__foo', [4, 5, 6]) self.assertEqual([4, 5, 6], namespaced_stored_object.Get('foo'))
def testGet_NothingSet_NoneReturned(self): self.assertIsNone(namespaced_stored_object.Get('foo'))
def testGet_InternalUser_InternalVersionReturned(self): self.SetCurrentUser('*****@*****.**') stored_object.Set('internal_only__foo', [1, 2, 3]) stored_object.Set('externally_visible__foo', [4, 5, 6]) self.assertEqual([1, 2, 3], namespaced_stored_object.Get('foo'))
def _IsBisectInternalOnly(bisect_job): """Checks if the bisect is for an internal-only test.""" internal_masters = namespaced_stored_object.Get(_INTERNAL_MASTERS_KEY) return internal_masters and bisect_job.master_name in internal_masters