Пример #1
0
    def test_options_hierarchy_for_reporter_id(self, parseFile, getLogger):
        # Set the value in all three possible locations
        # Mock /etc/virt-who.conf file
        global_conf_dict = {
            'global': {
                'reporter_id': "/etc/virt-who.conf"
            }
        }
        parseFile.return_value = global_conf_dict
        # cli option
        sys.argv = ["virtwho.py", "--reporter-id=cli"]
        # environment var
        os.environ["VIRTWHO_REPORTER_ID"] = "env"
        _, options = parseOptions()
        # cli option should beat environment vars and virt-who.conf
        self.assertEqual(options.reporter_id, "cli")

        sys.argv = ["virtwho.py"]

        _, options = parseOptions()
        self.assertEqual(options.reporter_id, "env")

        self.clearEnv()

        _, options = parseOptions()
        self.assertEqual(options.reporter_id, "/etc/virt-who.conf")

        parseFile.return_value = {'global': {}}

        _, options = parseOptions()
        self.assertEqual(options.reporter_id, util.generateReporterId())
Пример #2
0
class GlobalConfig(GeneralConfig):
    """
    This GeneralConfig subclass represents the config file
    that holds the global values used to control virt-who's
    operation.
    """
    DEFAULTS = {
        'debug': False,
        'oneshot': False,
        'print_': False,
        'log_per_config': False,
        'background': False,
        'configs': '',
        'reporter_id': util.generateReporterId(),
        'smType': None,
        'interval': DefaultInterval
    }
    LIST_OPTIONS = ('configs', )
    BOOL_OPTIONS = ('debug', 'oneshot', 'background', 'print_'
                    'log_per_config')
    INT_OPTIONS = ('interval', )

    @classmethod
    def fromFile(cls, filename, logger=None):
        global_config = parseFile(
            filename, logger=logger).get(VIRTWHO_GLOBAL_SECTION_NAME)
        if not global_config:
            if logger:
                logger.warning(
                    'Unable to find "%s" section in general config file: "%s"\nWill use defaults where required',
                    VIRTWHO_GLOBAL_SECTION_NAME, filename)
            global_config = {}
        return cls(**global_config)
Пример #3
0
 def test_default_cmdline_options(self, parseFile, getLogger):
     self.setUpParseFile(parseFile)
     sys.argv = ["virtwho.py"]
     _, options = parseOptions()
     self.assertFalse(options.debug)
     self.assertFalse(options.background)
     self.assertFalse(options.oneshot)
     self.assertEqual(options.interval, 60)
     self.assertEqual(options.smType, 'sam')
     self.assertEqual(options.virtType, None)
     self.assertEqual(options.reporter_id, util.generateReporterId())