Esempio n. 1
0
    def test_satellite_config_file(self):
        # Username and password are required for a valid sat5 destination
        with open(os.path.join(self.config_dir, "test.conf"), "w") as f:
            f.write("""
[test]
type=libvirt
sat_server=sat.example.com
sat_username=sat_username
sat_password=sat_password
""")
        conf = parse_file(os.path.join(self.config_dir, "test.conf"))
        effective_config = EffectiveConfig()
        conf_values = conf.pop("test")
        effective_config["test"] = ConfigSection.from_dict(
            conf_values,
            "test",
            effective_config
        )
        config_manager = DestinationToSourceMapper(effective_config)
        self.assertEqual(len(config_manager.configs), 1)
        # There should only be one destination detected
        self.assertEqual(len(config_manager.dests), 1)
        # Which should be a Satellite5DestinationInfo
        dest_info = config_manager.dests.pop()
        self.assertTrue(isinstance(dest_info, Satellite5DestinationInfo), 'The destination info '
                                                                          'we got was not of the '
                                                                          'expected type')
        manager = Manager.fromInfo(self.logger, effective_config, dest_info)
        self.assertTrue(isinstance(manager, Satellite))
        self.assertEqual(dest_info.sat_server, 'sat.example.com')
    def test_sm_config_override(self, initConfig, HTTPSConnection,
                                RhsmProxyHTTPSConnection):
        """Test if overriding options from rhsm.conf works."""

        conn = MagicMock()
        conn.getresponse.return_value.status = 200
        conn.getresponse.return_value.read.return_value = '{"result": "ok"}'
        HTTPSConnection.return_value = conn
        RhsmProxyHTTPSConnection.return_value = conn

        def config_get(section, key):
            return {
                'server/proxy_hostname': 'proxy.server.test',
                'rhsm/consumerCertDir': '',
                'server/hostname': 'server.test',
                'server/port': '8081',
                'server/prefix': 'old_prefix',
            }.get('%s/%s' % (section, key), None)

        initConfig.return_value.get.side_effect = config_get
        config_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, config_dir)
        with open(os.path.join(config_dir, "test.conf"), "w") as f:
            f.write("""
[test]
type=libvirt
owner=owner
rhsm_hostname=host
rhsm_port=8080
rhsm_prefix=/prefix
rhsm_proxy_hostname=
rhsm_proxy_port=8443
rhsm_insecure=1
rhsm_username=user
rhsm_password=passwd
""")

        conf = parse_file(os.path.join(config_dir, "test.conf"))
        effective_config = EffectiveConfig()
        conf_values = conf.pop("test")
        effective_config["test"] = VirtConfigSection.from_dict(
            conf_values, "test", effective_config)
        config_manager = DestinationToSourceMapper(effective_config)
        self.assertEqual(len(config_manager.configs), 1)
        config = config_manager.configs[0]
        manager = Manager.fromOptions(self.logger, Mock(), config)
        self.assertTrue(isinstance(manager, SubscriptionManager))
        self.assertEqual(config.rhsm_hostname, 'host')
        self.assertEqual(config.rhsm_port, '8080')

        manager._connect(config)
        self.assertFalse(RhsmProxyHTTPSConnection.called,
                         "It shouldn't use proxy")
        self.assertTrue(HTTPSConnection.called)
        conn.request.assert_called_with('GET',
                                        '/prefix/status/',
                                        body=ANY,
                                        headers=ANY)
Esempio n. 3
0
    def filter_hosts(self, filter_something, filter_type=''):
        config_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, config_dir)
        with open(os.path.join(config_dir, "test.conf"), "w") as f:
            f.write("""
[test]
type=esx
server=does.not.exist
username=username
password=password
owner=owner
env=env
{filter_something}
{filter_type}
""".format(filter_something=filter_something, filter_type=filter_type))
        conf = parse_file(os.path.join(config_dir, "test.conf"))
        test_conf_values = conf.pop('test')
        effective_config = EffectiveConfig()
        effective_config['test'] = VirtConfigSection.from_dict(
            test_conf_values,
            'test',
            effective_config
        )
        effective_config.validate()
        config_manager = DestinationToSourceMapper(effective_config)
        self.assertEqual(len(config_manager.configs), 1)
        config = config_manager.configs[0][1]

        included_hypervisor = Hypervisor('12345', guestIds=[
            Guest('guest-2', xvirt.CONFIG_TYPE, Guest.STATE_RUNNING),
        ])
        excluded_hypervisor = Hypervisor('00000', guestIds=[
            Guest('guest-1', xvirt.CONFIG_TYPE, Guest.STATE_RUNNING),
        ])

        assoc = {
            'hypervisors': [
                excluded_hypervisor,
                included_hypervisor,
            ]
        }

        report = HostGuestAssociationReport(config, assoc)
        assert report.association == {
            'hypervisors': [
                included_hypervisor
            ]
        }
Esempio n. 4
0
 def test_read_effective_config_from_file(self):
     config_dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, config_dir)
     with open(os.path.join(config_dir, "test.conf"), "w") as f:
         f.write(CONFIG_SECTION_TEXT)
     conf = parse_file(os.path.join(config_dir, "test.conf"))
     effective_config = EffectiveConfig()
     conf_values = conf.pop(CUSTOM_SECTION_NAME)
     effective_config[CUSTOM_SECTION_NAME] = ConfigSection.from_dict(
         conf_values, CUSTOM_SECTION_NAME, effective_config)
     self.assertEqual(type(effective_config[CUSTOM_SECTION_NAME]),
                      CustomConfigSection)
     self.assertEqual(effective_config[CUSTOM_SECTION_NAME]['my_str'],
                      'foo')
     validate_messages = effective_config.validate()
     self.assertEqual(validate_messages, [])
Esempio n. 5
0
    def filter_hosts(self, filter_something, filter_type=''):
        config_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, config_dir)
        with open(os.path.join(config_dir, "test.conf"), "w") as f:
            f.write("""
[test]
type=esx
server=does.not.exist
username=username
password=password
owner=owner
env=env
{filter_something}
{filter_type}
""".format(filter_something=filter_something, filter_type=filter_type))
        conf = parse_file(os.path.join(config_dir, "test.conf"))
        test_conf_values = conf.pop('test')
        effective_config = EffectiveConfig()
        effective_config['test'] = VirtConfigSection.from_dict(
            test_conf_values, 'test', effective_config)
        effective_config.validate()
        config_manager = DestinationToSourceMapper(effective_config)
        self.assertEqual(len(config_manager.configs), 1)
        config = config_manager.configs[0][1]

        included_hypervisor = Hypervisor('12345',
                                         guestIds=[
                                             Guest('guest-2',
                                                   xvirt.CONFIG_TYPE,
                                                   Guest.STATE_RUNNING),
                                         ])
        excluded_hypervisor = Hypervisor('00000',
                                         guestIds=[
                                             Guest('guest-1',
                                                   xvirt.CONFIG_TYPE,
                                                   Guest.STATE_RUNNING),
                                         ])

        assoc = {
            'hypervisors': [
                excluded_hypervisor,
                included_hypervisor,
            ]
        }

        report = HostGuestAssociationReport(config, assoc)
        assert report.association == {'hypervisors': [included_hypervisor]}
Esempio n. 6
0
 def test_read_sam_effective_config_from_file(self):
     config_dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, config_dir)
     with open(os.path.join(config_dir, "test.conf"), "w") as f:
         f.write(LIBVIRT_SECTION_TEXT)
     conf = parse_file(os.path.join(config_dir, "test.conf"))
     self.init_effective_config()
     conf_values = conf.pop(MY_SECTION_NAME)
     self.effective_config[MY_SECTION_NAME] = ConfigSection.from_dict(
         conf_values, MY_SECTION_NAME, self.effective_config)
     self.assertEqual(type(self.effective_config[MY_SECTION_NAME]),
                      LibvirtdConfigSection)
     self.assertEqual(self.effective_config[MY_SECTION_NAME]['server'],
                      'ssh://192.168.122.10')
     validate_messages = self.effective_config.validate()
     self.assertIsNotNone(validate_messages)
     del self.effective_config[MY_SECTION_NAME]
 def test_read_sam_effective_config_from_file(self):
     config_dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, config_dir)
     with open(os.path.join(config_dir, "test.conf"), "w") as f:
         f.write(LIBVIRT_SECTION_TEXT)
     conf = parse_file(os.path.join(config_dir, "test.conf"))
     self.init_effective_config()
     conf_values = conf.pop(MY_SECTION_NAME)
     self.effective_config[MY_SECTION_NAME] = ConfigSection.from_dict(
         conf_values,
         MY_SECTION_NAME,
         self.effective_config
     )
     self.assertEqual(type(self.effective_config[MY_SECTION_NAME]), LibvirtdConfigSection)
     self.assertEqual(self.effective_config[MY_SECTION_NAME]['server'], 'ssh://192.168.122.10')
     validate_messages = self.effective_config.validate()
     self.assertIsNotNone(validate_messages)
     del self.effective_config[MY_SECTION_NAME]