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_async', mock.Mock()) storage.get_latest_async.return_value = future( 'gitiles { fetch_archive_deadline: 10 }') msg = storage.get_self_config_async( 'import.cfg', lambda: default_msg).get_result() self.assertEqual(msg.gitiles.fetch_log_deadline, 42)
def get_gitiles_config(): cfg = service_config_pb2.ImportCfg(gitiles=DEFAULT_GITILES_IMPORT_CONFIG) try: cfg = storage.get_self_config_async( common.IMPORT_FILENAME, lambda: cfg).get_result() 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