def test_get_self_config(self): expected = service_config_pb2.AclCfg(service_access_group='group') self.mock(storage, 'get_config_hash', mock.Mock()) self.mock(storage, 'get_config_by_hash', mock.Mock()) storage.get_config_hash.return_value = 'deadbeef', 'beefdead' storage.get_config_by_hash.return_value = 'service_access_group: "group"' actual = storage.get_self_config('acl.cfg', service_config_pb2.AclCfg) self.assertEqual(expected, actual) storage.get_config_hash.assert_called_once_with( 'services/sample-app', 'acl.cfg') storage.get_config_by_hash.assert_called_once_with('beefdead') # memcached: storage.get_config_hash.reset_mock() storage.get_config_by_hash.reset_mock() actual = storage.get_latest_as_message('services/sample-app', 'acl.cfg', service_config_pb2.AclCfg) self.assertEqual(expected, actual) self.assertFalse(storage.get_config_hash.called) self.assertFalse(storage.get_config_by_hash.called)
def test_get_self_config(self): expected = service_config_pb2.AclCfg(service_access_group='group') self.mock(storage, 'get_config_hash', mock.Mock()) self.mock(storage, 'get_config_by_hash', mock.Mock()) storage.get_config_hash.return_value = 'deadbeef', 'beefdead' storage.get_config_by_hash.return_value = 'service_access_group: "group"' actual = storage.get_self_config('acl.cfg', service_config_pb2.AclCfg) self.assertEqual(expected, actual) storage.get_config_hash.assert_called_once_with( 'services/sample-app', 'acl.cfg') storage.get_config_by_hash.assert_called_once_with('beefdead') # memcached: storage.get_config_hash.reset_mock() storage.get_config_by_hash.reset_mock() actual = storage.get_latest_as_message( 'services/sample-app', 'acl.cfg', service_config_pb2.AclCfg) self.assertEqual(expected, actual) self.assertFalse(storage.get_config_hash.called) self.assertFalse(storage.get_config_by_hash.called)
def test_message_field_merge(self): default_msg = service_config_pb2.ImportCfg( gitiles=service_config_pb2.ImportCfg.Gitiles(fetch_log_deadline=42)) self.mock(storage, 'get_latest', mock.Mock()) storage.get_latest.return_value = 'gitiles { fetch_archive_deadline: 10 }' msg = storage.get_self_config('import.cfg', lambda: default_msg) self.assertEqual(msg.gitiles.fetch_log_deadline, 42)
def test_message_field_merge(self): default_msg = service_config_pb2.ImportCfg( gitiles=service_config_pb2.ImportCfg.Gitiles( fetch_log_deadline=42)) self.mock(storage, 'get_latest', mock.Mock()) storage.get_latest.return_value = 'gitiles { fetch_archive_deadline: 10 }' msg = storage.get_self_config('import.cfg', lambda: default_msg) self.assertEqual(msg.gitiles.fetch_log_deadline, 42)
def get_projects(): """Returns a list of projects stored in services/luci-config:projects.cfg. Never returns None. Cached. """ cfg = storage.get_self_config(common.PROJECT_REGISTRY_FILENAME, service_config_pb2.ProjectsCfg) return cfg.projects or []
def get_projects(): """Returns a list of projects stored in services/luci-config:projects.cfg. Never returns None. Cached. """ cfg = storage.get_self_config( common.PROJECT_REGISTRY_FILENAME, service_config_pb2.ProjectsCfg) return cfg.projects or []
def get_gitiles_config(): cfg = service_config_pb2.ImportCfg(gitiles=DEFAULT_GITILES_IMPORT_CONFIG) try: cfg = storage.get_self_config('import.cfg', lambda: cfg) except text_format.ParseError as ex: # It is critical that get_gitiles_config() returns a valid config. # If import.cfg is broken, it should not break importing mechanism, # otherwise the system won't be able to heal itself by importing a fixed # config. logging.exception('import.cfg is broken') return cfg.gitiles
def get(self, name): cfg = storage.get_self_config('schemas.cfg', service_config_pb2.SchemasCfg) # Assume cfg was validated by validation.py if cfg: for schema in cfg.schemas: if schema.name == name: # Convert from unicode. assert schema.url self.redirect(str(schema.url)) return self.response.write('Schema %s not found\n' % name) self.response.set_status(httplib.NOT_FOUND)
def read_acl_cfg(): return storage.get_self_config(common.ACL_FILENAME, service_config_pb2.AclCfg)