def main(): options = parse_args() if options.debug: setup_logging(logging.DEBUG) else: setup_logging(logging.INFO) # Disable mozci's validations disable_validations() run_exchange_topic(options.topic_base, options.dry_run)
def main(): global CONFIG, LOG, JOB_FACTORY # 0) Parse the command line arguments options = parse_args() # 1) Set up logging if options.debug or os.environ.get('LOGGING_LEVEL') == 'debug': LOG = setup_logging(logging.DEBUG) else: LOG = setup_logging(logging.INFO) # 2) Check required environment variables if options.load_env_variables: with open('env_variables.json') as file: env_variables = json.load(file) for env, value in env_variables.iteritems(): os.environ[env] = value # Do not print the value as it could be a secret LOG.info('Set {}'.format(env)) CONFIG['dry_run'] = options.dry_run or options.replay_file is not None or CONFIG['dry_run'] if not CONFIG['dry_run']: fail_check = False for env in REQUIRED_ENV_VARIABLES: if env not in os.environ: LOG.info('- {}'.format(env)) fail_check = True if fail_check: LOG.error('Please set all the missing environment variables above.') sys.exit(1) # 3) Enable memory saving (useful for Heroku) if options.memory_saving: transfer.MEMORY_SAVING_MODE = True # 4) Set the treeherder host if options.config_file and options.treeherder_server_url: # treeherder_server_url can be mistakenly set to two different values if we allow for this raw_input('Press Ctrl + C if you did not intent to use --treeherder-server-url with --config-file') if options.treeherder_server_url: CONFIG['treeherder_server_url'] = options.treeherder_server_url elif options.config_file: with open(options.config_file, 'r') as file: # Load information only relevant to pulse_actions pulse_actions_config = json.load(file).get('pulse_actions') if pulse_actions_config: # Inside of some of our handlers we set the Treeherder client # We would not want to try to test with a stage config yet # we query production instead of stage CONFIG['treeherder_server_url'] = pulse_actions_config['treeherder_server_url'] elif CONFIG['dry_run']: pass else: LOG.error("Set --treeherder-url if you're not using a config file") sys.exit(1) # 5) Set few constants which are used by message_handler if CONFIG['dry_run']: CONFIG['submit_to_treeherder'] = False CONFIG['acknowledge'] = False if options.submit_to_treeherder or os.environ.get('SUBMIT_TO_TREEHERDER'): CONFIG['submit_to_treeherder'] = True if options.acknowledge: CONFIG['acknowledge'] = True if options.do_not_route: CONFIG['route'] = False # 6) Set up the treeherder submitter if CONFIG['submit_to_treeherder']: JOB_FACTORY = initialize_treeherder_submission( server_url=CONFIG['treeherder_server_url'], client=os.environ['TREEHERDER_CLIENT_ID'], secret=os.environ['TREEHERDER_SECRET'], dry_run=CONFIG['dry_run'] ) # 7) XXX: Disable mozci's validations (this might not be needed anymore) disable_validations() # 8) Determine if normal run is requested or replaying of saved messages if options.replay_file: replay_messages( filepath=options.replay_file, process_message=message_handler, dry_run=True, ) else: # Normal execution path run_listener(config_file=options.config_file)
def test_disable_validations(): assert validate() is True disable_validations() assert validate() is False