def main(): """Run the framework based on the schedule.""" # Configure the logger as the first thing as per the base # configuration. We need this to be the first thing, so that # we can see the messages logged by util.load_config(). logging.config.dictConfig(baseconfig.config_dict['logger']) _log.info('Cloudmarker %s', cloudmarker.__version__) # Parse the command line arguments and handle the options that can # be handled immediately. args = util.parse_cli() if args.print_base_config: print(baseconfig.config_yaml.strip()) return # Now load user's configuration files. config = util.load_config(args.config) # Then configure the logger once again to honour any logger # configuration defined in the user's configuration files. logging.config.dictConfig(config['logger']) # Finally, run the audits, either right now or as per a schedule, # depending on the command line options. if args.now: _log.info('Starting job now') job(config) else: _log.info('Scheduled to run job everyday at %s', config['schedule']) schedule.every().day.at(config['schedule']).do(job, config) while True: schedule.run_pending() time.sleep(60)
def test_load_config(self): path1 = os.path.join(data_path, 'config1.yaml') path2 = os.path.join(data_path, 'config2.yaml') path3 = os.path.join(data_path, 'missing.yaml') config = util.load_config([path1, path2, path3]) # The resulting config dict is a large dict containing the base # config along with config1.yaml and config2.yaml merged into # it. We test values only in config1.yaml and config2.yaml. self.assertEqual(config['foo'], 'bar') self.assertEqual(config['baz'], 'qux')
def main(): """Run the framework based on the schedule.""" args = util.parse_cli() config = util.load_config(args.config) logging.config.dictConfig(config['logger']) # Run the audits according to the schedule set in the configuration if the # 'force' flag is not set in the command line. if args.force: _log.info('Starting job now') job(config) else: _log.info('Scheduled to run job everyday at %s', config['schedule']) schedule.every().day.at(config['schedule']).do(job, config) while True: schedule.run_pending() time.sleep(60)
def main(): """Run the framework.""" args = util.parse_cli() config = util.load_config(args.config) logging.config.dictConfig(config['logger']) # Create an audit object for each audit configured to be run. audits = [] for audit_name in config['run']: audits.append(Audit(audit_name, config)) # Start all audits. for audit in audits: audit.start() # Wait for all audits to terminate. for audit in audits: audit.join()
def test_load_config(self): path1 = os.path.join(data_path, 'config1.yaml') path2 = os.path.join(data_path, 'config2.yaml') path3 = os.path.join(data_path, 'missing.yaml') config = util.load_config([path1, path2, path3]) self.assertEqual(config, {'foo': 'bar', 'baz': 'qux'})