Exemplo n.º 1
0
    def test_options_virt(self):
        for virt in ['esx', 'hyperv', 'rhevm']:
            self.clearEnv()
            sys.argv = [
                "virtwho.py",
                "--%s" % virt,
                "--%s-owner=owner" % virt,
                "--%s-env=env" % virt,
                "--%s-server=localhost" % virt,
                "--%s-username=username" % virt,
                "--%s-password=password" % virt
            ]
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, 'owner')
            self.assertEqual(options.env, 'env')
            self.assertEqual(options.server, 'localhost')
            self.assertEqual(options.username, 'username')
            self.assertEqual(options.password, 'password')

            sys.argv = ["virtwho.py"]
            virt_up = virt.upper()
            os.environ["VIRTWHO_%s" % virt_up] = "1"
            os.environ["VIRTWHO_%s_OWNER" % virt_up] = "xowner"
            os.environ["VIRTWHO_%s_ENV" % virt_up] = "xenv"
            os.environ["VIRTWHO_%s_SERVER" % virt_up] = "xlocalhost"
            os.environ["VIRTWHO_%s_USERNAME" % virt_up] = "xusername"
            os.environ["VIRTWHO_%s_PASSWORD" % virt_up] = "xpassword"
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, 'xowner')
            self.assertEqual(options.env, 'xenv')
            self.assertEqual(options.server, 'xlocalhost')
            self.assertEqual(options.username, 'xusername')
            self.assertEqual(options.password, 'xpassword')
Exemplo n.º 2
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())
Exemplo n.º 3
0
    def test_options_virt(self, parseFile, getLogger):
        self.setUpParseFile(parseFile)
        for virt in ['esx', 'hyperv', 'rhevm']:
            self.clearEnv()
            sys.argv = ["virtwho.py", "--%s" % virt, "--%s-owner=owner" % virt,
                        "--%s-env=env" % virt, "--%s-server=localhost" % virt,
                        "--%s-username=username" % virt,
                        "--%s-password=password" % virt]
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, 'owner')
            self.assertEqual(options.env, 'env')
            self.assertEqual(options.server, 'localhost')
            self.assertEqual(options.username, 'username')
            self.assertEqual(options.password, 'password')

            sys.argv = ["virtwho.py"]
            virt_up = virt.upper()
            os.environ["VIRTWHO_%s" % virt_up] = "1"
            os.environ["VIRTWHO_%s_OWNER" % virt_up] = "xowner"
            os.environ["VIRTWHO_%s_ENV" % virt_up] = "xenv"
            os.environ["VIRTWHO_%s_SERVER" % virt_up] = "xlocalhost"
            os.environ["VIRTWHO_%s_USERNAME" % virt_up] = "xusername"
            os.environ["VIRTWHO_%s_PASSWORD" % virt_up] = "xpassword"
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, 'xowner')
            self.assertEqual(options.env, 'xenv')
            self.assertEqual(options.server, 'xlocalhost')
            self.assertEqual(options.username, 'xusername')
            self.assertEqual(options.password, 'xpassword')
Exemplo n.º 4
0
    def test_options_debug(self):
        sys.argv = ["virtwho.py", "-d"]
        _, options = parseOptions()
        self.assertTrue(options.debug)

        sys.argv = ["virtwho.py"]
        os.environ["VIRTWHO_DEBUG"] = "1"
        _, options = parseOptions()
        self.assertTrue(options.debug)
Exemplo n.º 5
0
    def test_options_debug(self):
        sys.argv = ["virtwho.py", "-d"]
        _, options = parseOptions()
        self.assertTrue(options.debug)

        sys.argv = ["virtwho.py"]
        os.environ["VIRTWHO_DEBUG"] = "1"
        _, options = parseOptions()
        self.assertTrue(options.debug)
Exemplo n.º 6
0
    def test_options_debug(self, parseFile, getLogger):
        self.setUpParseFile(parseFile)
        sys.argv = ["virtwho.py", "-d"]
        _, options = parseOptions()
        self.assertTrue(options.debug)

        sys.argv = ["virtwho.py"]
        os.environ["VIRTWHO_DEBUG"] = "1"
        _, options = parseOptions()
        self.assertTrue(options.debug)
Exemplo n.º 7
0
 def test_sm_config_cmd(self):
     os.environ = {}
     sys.argv = ["virt-who", "--sam", "--libvirt"]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, SubscriptionManager))
Exemplo n.º 8
0
 def test_sm_config_env(self):
     os.environ = {"VIRTWHO_SAM": "1", "VIRTWHO_LIBVIRT": "1"}
     sys.argv = ["virt-who"]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, SubscriptionManager))
Exemplo n.º 9
0
    def test_minimum_interval_options(self, parseFile, getLogger):
        self.setUpParseFile(parseFile)
        sys.argv = ["virtwho.py", "--interval=5"]
        _, options = parseOptions()
        self.assertEqual(options.interval, 60)

        sys.argv = ["virtwho.py"]
        os.environ["VIRTWHO_INTERVAL"] = '1'

        _, options = parseOptions()
        self.assertEqual(options.interval, 60)

        self.clearEnv()
        bad_conf = {'global': {'interval': 1}}
        parseFile.return_value = bad_conf

        _, options = parseOptions()
        self.assertEqual(options.interval, 60)
Exemplo n.º 10
0
 def test_default_cmdline_options(self):
     sys.argv = ["virtwho.py"]
     _, options = parseOptions()
     self.assertFalse(options.debug)
     self.assertFalse(options.background)
     self.assertFalse(options.oneshot)
     self.assertEqual(options.interval, 3600)
     self.assertEqual(options.smType, 'sam')
     self.assertEqual(options.virtType, None)
Exemplo n.º 11
0
 def test_default_cmdline_options(self):
     sys.argv = ["virtwho.py"]
     _, options = parseOptions()
     self.assertFalse(options.debug)
     self.assertFalse(options.background)
     self.assertFalse(options.oneshot)
     self.assertEqual(options.interval, 3600)
     self.assertEqual(options.smType, 'sam')
     self.assertEqual(options.virtType, None)
Exemplo n.º 12
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())
Exemplo n.º 13
0
    def test_options_virt_satellite(self, parseFile, getLogger):
        self.setUpParseFile(parseFile)
        for virt in ['esx', 'hyperv', 'rhevm']:
            self.clearEnv()
            sys.argv = ["virtwho.py",
                        "--satellite",
                        "--satellite-server=localhost",
                        "--satellite-username=username",
                        "--satellite-password=password",
                        "--%s" % virt,
                        "--%s-server=localhost" % virt,
                        "--%s-username=username" % virt,
                        "--%s-password=password" % virt]
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, '')
            self.assertEqual(options.env, '')
            self.assertEqual(options.server, 'localhost')
            self.assertEqual(options.username, 'username')
            self.assertEqual(options.password, 'password')

            sys.argv = ["virtwho.py"]
            virt_up = virt.upper()
            os.environ["VIRTWHO_SATELLITE"] = "1"
            os.environ["VIRTWHO_SATELLITE_SERVER"] = "xlocalhost"
            os.environ["VIRTWHO_SATELLITE_USERNAME"] = "******"
            os.environ["VIRTWHO_SATELLITE_PASSWORD"] = "******"
            os.environ["VIRTWHO_%s" % virt_up] = "1"
            os.environ["VIRTWHO_%s_SERVER" % virt_up] = "xlocalhost"
            os.environ["VIRTWHO_%s_USERNAME" % virt_up] = "xusername"
            os.environ["VIRTWHO_%s_PASSWORD" % virt_up] = "xpassword"
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, '')
            self.assertEqual(options.env, '')
            self.assertEqual(options.server, 'xlocalhost')
            self.assertEqual(options.username, 'xusername')
            self.assertEqual(options.password, 'xpassword')
Exemplo n.º 14
0
 def test_satellite_config_env(self):
     os.environ = {
         "VIRTWHO_SATELLITE": "1",
         "VIRTWHO_SATELLITE_SERVER": "sat.example.com",
         "VIRTWHO_SATELLITE_USERNAME": "******",
         "VIRTWHO_SATELLITE_PASSWORD": "******",
         "VIRTWHO_LIBVIRT": "1",
     }
     sys.argv = ["virt-who"]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, Satellite))
Exemplo n.º 15
0
    def test_options_virt_satellite(self, getLogger):
        for virt in ['esx', 'hyperv', 'rhevm']:
            self.clearEnv()
            sys.argv = [
                "virtwho.py", "--satellite", "--satellite-server=localhost",
                "--satellite-username=username",
                "--satellite-password=password",
                "--%s" % virt,
                "--%s-server=localhost" % virt,
                "--%s-username=username" % virt,
                "--%s-password=password" % virt
            ]
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, '')
            self.assertEqual(options.env, '')
            self.assertEqual(options.server, 'localhost')
            self.assertEqual(options.username, 'username')
            self.assertEqual(options.password, 'password')

            sys.argv = ["virtwho.py"]
            virt_up = virt.upper()
            os.environ["VIRTWHO_SATELLITE"] = "1"
            os.environ["VIRTWHO_SATELLITE_SERVER"] = "xlocalhost"
            os.environ["VIRTWHO_SATELLITE_USERNAME"] = "******"
            os.environ["VIRTWHO_SATELLITE_PASSWORD"] = "******"
            os.environ["VIRTWHO_%s" % virt_up] = "1"
            os.environ["VIRTWHO_%s_SERVER" % virt_up] = "xlocalhost"
            os.environ["VIRTWHO_%s_USERNAME" % virt_up] = "xusername"
            os.environ["VIRTWHO_%s_PASSWORD" % virt_up] = "xpassword"
            _, options = parseOptions()
            self.assertEqual(options.virtType, virt)
            self.assertEqual(options.owner, '')
            self.assertEqual(options.env, '')
            self.assertEqual(options.server, 'xlocalhost')
            self.assertEqual(options.username, 'xusername')
            self.assertEqual(options.password, 'xpassword')
Exemplo n.º 16
0
 def test_satellite_config_cmd(self):
     os.environ = {}
     sys.argv = [
         "virt-who",
         "--satellite",
         "--satellite-server=sat.example.com",
         "--satellite-username=username",
         "--satellite-password=password",
         "--libvirt",
     ]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, Satellite))
Exemplo n.º 17
0
 def test_minimum_interval_options(self, getLogger):
     sys.argv = ["virtwho.py", "--interval=5"]
     _, options = parseOptions()
     self.assertEqual(options.interval, 60)
Exemplo n.º 18
0
 def test_minimum_interval_options(self, getLogger):
     sys.argv = ["virtwho.py", "--interval=5"]
     _, options = parseOptions()
     self.assertEqual(options.interval, 60)