Ejemplo n.º 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.side_effect = lambda x: copy.deepcopy(global_conf_dict)
        # cli option
        sys.argv = ["virtwho.py", "--reporter-id=cli"]
        # environment var
        os.environ["VIRTWHO_REPORTER_ID"] = "env"
        _, options = parse_options()
        # cli option should beat environment vars and virt-who.conf
        self.assertEqual(options[VW_GLOBAL]['reporter_id'], "cli")

        sys.argv = ["virtwho.py"]

        _, options = parse_options()
        self.assertEqual(options[VW_GLOBAL]['reporter_id'], "env")

        self.clearEnv()

        _, options = parse_options()
        self.assertEqual(options[VW_GLOBAL]['reporter_id'],
                         "/etc/virt-who.conf")

        parseFile.side_effect = lambda x: {}

        _, options = parse_options()
        self.assertEqual(options[VW_GLOBAL]['reporter_id'],
                         util.generate_reporter_id())
Ejemplo n.º 2
0
 def test_default_cmdline_options(self, parseFile, getLogger):
     self.setUpParseFile(parseFile)
     sys.argv = ["virtwho.py"]
     _, options = parse_options()
     self.assertFalse(options[VW_GLOBAL]['debug'])
     self.assertFalse(options[VW_GLOBAL]['oneshot'])
     self.assertEqual(options[VW_GLOBAL]['interval'], 3600)
     self.assertEqual(options[VW_GLOBAL]['reporter_id'],
                      util.generate_reporter_id())