コード例 #1
0
    def test__load_config__from_file(self, mock_open, mock_yaml):
        """Test loading of configuration from yaml file"""
        configfile = "/tmp/file"
        mock_open.read.return_value = "some_yaml"

        utils.load_config(configfile, clear_db_config=False)

        print mock_open.mock_calls
        mock_open.assert_called_once_with(configfile, 'r')
コード例 #2
0
    def test__load_config__clear_db(self, mock_rsce, mock_yaml):
        """
        Test loading of configuration from yaml file, but also clear the db
        """
        configfile = None

        utils.load_config(configfile, clear_db_config=True)

        self.mock_db.Database.delete_db_cfg.assert_called_once_with()
コード例 #3
0
    def test__load_config__from_bad_file(
        self, mock_open, mock_yaml, mock_exit
    ):
        """Test loading of configuration from a bad yaml file"""
        configfile = "/tmp/file"
        mock_open.side_effect = OSError("File doesn't exist!!!!")

        utils.load_config(configfile, clear_db_config=False)

        # should exit on OSError
        mock_exit.assert_called_once_with(1)
コード例 #4
0
    def test__load_config__keyerror(self, mock_rsce, mock_yaml, mock_exit):
        """
        Test loading of configuration from yaml file, but a needed entry
        is missing
        """
        configfile = None
        mock_rsce.return_value = ""
        mock_yaml.return_value = {}

        utils.load_config(configfile, clear_db_config=False)

        # should exit on keyerror
        mock_exit.assert_called_once_with(1)
コード例 #5
0
    def test__load_config__resource(self, mock_rsce, mock_yaml):
        """Test loading of configuration from yaml file"""
        configfile = None

        utils.load_config(configfile, clear_db_config=False)
        util_options = dir(utils.cfg)

        # check every config var is represented in utils
        options = dir(configuration)
        for option in options:
            if not option.startswith('__') and not option.endswith('__'):
                assert option in util_options

        self.mock_db.Database.load_config.assert_called_once_with()
コード例 #6
0
def main():
    """Do the thing"""
    usage = "usage: %prog"
    description = "Adaptation Engine"
    version = "%prog 1.1.1"

    output.OUTPUT.info("Initialising...")

    opt_parser = optparse.OptionParser(
        usage=usage,
        version=version,
        description=description
    )
    opt_parser.add_option(
        "-c",
        "--cfg",
        metavar="FILE",
        action="store",
        type="string",
        help="specify the full path to an alternate config FILE",
        dest="cfg_file",
        default=None
    )
    opt_parser.add_option(
        "--healthcheck",
        action="store_true",
        help="Perform a healthcheck",
        dest="healthcheck",
        default=False
    )
    opt_parser.add_option(
        "--clear-db-log",
        action="store_true",
        help="Delete log entries in the database",
        dest="clear_log",
        default=False
    )
    opt_parser.add_option(
        "--clear-db-config",
        action="store_true",
        help="Delete config stored in database",
        dest="clear_cfg",
        default=False
    )

    (options, args) = opt_parser.parse_args()

    utils.load_config(
        configfile=options.cfg_file,
        clear_db_config=options.clear_cfg
    )

    if options.clear_log:
        database.Database.delete_db_log()

    daemon = AdaptationEngine()

    def time_to_die(signal, frame):
        """Kill the adaptation engine processes"""
        LOGGER.info("Passing along SIGTERM")
        daemon.stop()
        sys.exit(0)
        output.OUTPUT.info("Done.")

    signal.signal(signal.SIGTERM, time_to_die)

    output.OUTPUT.info("Adaptation Engine started (ctrl+c to quit)...")

    try:
        if options.healthcheck:
            daemon.healthcheck()
        else:
            daemon.run()
            while True:
                time.sleep(1)
    except KeyboardInterrupt:
        daemon.stop()
        sys.exit(0)