本文整理汇总了Python中virtwho.config.init_config函数的典型用法代码示例。如果您正苦于以下问题:Python init_config函数的具体用法?Python init_config怎么用?Python init_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init_config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_one_source_to_many_dests
def test_one_source_to_many_dests(self):
# This tests that there can be one source that specifies
# information for different destinations and that the correct mapping
# is created.
config_1 = combine_dicts(TestReadingConfigs.source_options_1,
TestReadingConfigs.dest_options_1)
# NOTE: virt-who today does not support config sections having the same
# name. Hence the only way to have one source go to multiple
# destinations (without new config options) is to have two sections
# with the same information but different section names
config_options_2 = TestReadingConfigs.source_options_1.copy()
config_options_2['name'] = 'test2'
config_2 = combine_dicts(config_options_2,
TestReadingConfigs.dest_options_2)
expected_dest_1 = Satellite6DestinationInfo(
**TestReadingConfigs.dest_options_1)
expected_dest_2 = Satellite6DestinationInfo(
**TestReadingConfigs.dest_options_2)
expected_mapping = {
expected_dest_1: [config_1['name']],
expected_dest_2: [config_2['name']] # config_2['name'] ==
# config_1['name']
}
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write(TestReadingConfigs.dict_to_ini(config_1) +
TestReadingConfigs.dict_to_ini(config_2))
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(manager.dest_to_sources_map, expected_mapping)
开发者ID:candlepin,项目名称:virt-who,代码行数:32,代码来源:test_config.py
示例2: testInvalidAndValidConfigs
def testInvalidAndValidConfigs(self):
valid_config_name = "valid_config"
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[%(valid_config_name)s]
type=esx
server=1.2.3.4
username=admin
password=password
owner=owner
env=env
rhsm_hostname=abc
[invalid_missing_owner]
type=esx
server=1.2.3.4
username=admin
password=password
env=env
rhsm_hostname=abc
""" % {'valid_config_name': valid_config_name})
config_manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
# There should be only one config, and that should be the one that is valid
self.assertEqual(len(config_manager.configs), 1)
self.assertEqual(config_manager.configs[0][1].name, valid_config_name)
开发者ID:candlepin,项目名称:virt-who,代码行数:25,代码来源:test_config.py
示例3: testCLIConfigOverridesGeneralConfigFile
def testCLIConfigOverridesGeneralConfigFile(self):
cli_config_file_path = os.path.join(self.custom_config_dir, "my_file.conf")
with open(cli_config_file_path, "w") as f:
f.write("""
[valid_cli_section]
server=5.5.5.5
username=admin1
password=password1
owner=owner1
rhsm_hostname=abc1
""")
cli_dict = {'configs': [cli_config_file_path]}
# alter the main conf file constant temporarily:
virtwho.config.VW_GENERAL_CONF_PATH = os.path.join(self.general_config_file_dir, "virt-who.conf")
with open(virtwho.config.VW_GENERAL_CONF_PATH, "w") as f:
f.write("""
[valid_default_main_conf_file_section]
server=1.2.3.4
username=admin
password=password
owner=owner
rhsm_hostname=abc
""")
config_manager = DestinationToSourceMapper(init_config({}, cli_dict, config_dir=self.config_dir))
# There should be only one config, and that should be the one passed from the cli
self.assertEqual(len(config_manager.configs), 1)
config = config_manager.configs[0][1]
self.assertEqual(config.name, "valid_cli_section")
self.assertEqual(config["server"], "5.5.5.5")
self.assertEqual(config["username"], "admin1")
self.assertEqual(config["password"], "password1")
self.assertEqual(config["owner"], "owner1")
self.assertEqual(config["rhsm_hostname"], "abc1")
开发者ID:virt-who,项目名称:virt-who,代码行数:35,代码来源:test_config.py
示例4: testCLIConfigOverridesDefaultDirectoryConfigs
def testCLIConfigOverridesDefaultDirectoryConfigs(self):
cli_config_file_path = os.path.join(self.custom_config_dir, "my_file.conf")
with open(cli_config_file_path, "w") as f:
f.write("""
[valid_cli_section]
server=5.5.5.5
username=admin1
password=password1
owner=owner1
env=env1
rhsm_hostname=abc1
""")
cli_dict = {'configs': [cli_config_file_path]}
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[valid_default_dir_section]
server=1.2.3.4
username=admin
password=password
owner=owner
env=env
rhsm_hostname=abc
""")
config_manager = DestinationToSourceMapper(init_config({}, cli_dict, config_dir=self.config_dir))
# There should be only one config, and that should be the one passed from the cli
self.assertEqual(len(config_manager.configs), 1)
config = config_manager.configs[0][1]
self.assertEqual(config.name, "valid_cli_section")
self.assertEqual(config["server"], "5.5.5.5")
self.assertEqual(config["username"], "admin1")
self.assertEqual(config["password"], "password1")
self.assertEqual(config["owner"], "owner1")
self.assertEqual(config["env"], "env1")
self.assertEqual(config["rhsm_hostname"], "abc1")
开发者ID:candlepin,项目名称:virt-who,代码行数:35,代码来源:test_config.py
示例5: test_read_hypervisor
def test_read_hypervisor(self):
with open(self.hypervisor_file, "w") as f:
f.write(HYPERVISOR_JSON)
with open(self.config_file, "w") as f:
f.write("""
[test]
type=fake
is_hypervisor=true
owner=taylor
env=swift
file=%s
""" % self.hypervisor_file)
effective_config = init_config({}, {}, config_dir=self.config_dir)
manager = DestinationToSourceMapper(effective_config)
self.assertEqual(len(manager.configs), 1)
virt = Virt.from_config(self.logger, manager.configs[0][1], None)
self.assertEqual(type(virt), FakeVirt)
mapping = virt.getHostGuestMapping()
self.assertTrue("hypervisors" in mapping)
hypervisors = mapping["hypervisors"]
self.assertEqual(len(hypervisors), 1)
hypervisor = hypervisors[0]
self.assertEqual(type(hypervisor), Hypervisor)
self.assertEqual(hypervisor.hypervisorId, "60527517-6284-7593-6AAB-75BF2A6375EF")
self.assertEqual(len(hypervisor.guestIds), 1)
guest = hypervisor.guestIds[0]
self.assertEqual(guest.uuid, "07ED8178-95D5-4244-BC7D-582A54A48FF8")
self.assertEqual(guest.state, 1)
开发者ID:candlepin,项目名称:virt-who,代码行数:29,代码来源:test_fake.py
示例6: test_invalid_config
def test_invalid_config(self):
with open(os.path.join(self.config_dir, "test.conf"), "w") as f:
f.write("""
Malformed configuration file
""")
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
# If there are only invalid configurations specified, and nothing has been specified via
# the command line or ENV then we should use the default
# TODO Remove the default hard-coded behaviour, and allow virt-who to output a
# configuration that will cause it to behave equivalently
self.assertEqual(len(manager.configs), 1)
self.assertEqual(manager.configs[0][0], VW_ENV_CLI_SECTION_NAME)
开发者ID:candlepin,项目名称:virt-who,代码行数:12,代码来源:test_config.py
示例7: testCLIConfigOverridesGeneralConfigFileButStillReadsItsGlobalAndDefaultsSections
def testCLIConfigOverridesGeneralConfigFileButStillReadsItsGlobalAndDefaultsSections(self):
cli_config_file_path = os.path.join(self.custom_config_dir, "my_file.conf")
with open(cli_config_file_path, "w") as f:
f.write("""
[valid_cli_section]
server=5.5.5.5
username=admin1
password=password1
owner=owner1
env=env1
rhsm_hostname=abc1
""")
cli_dict = {'configs': [cli_config_file_path]}
# alter the main conf file constant temporarily:
virtwho.config.VW_GENERAL_CONF_PATH = os.path.join(self.general_config_file_dir, "virt-who.conf")
with open(virtwho.config.VW_GENERAL_CONF_PATH, "w") as f:
f.write("""
[global]
interval=100
log_file=rhsm45.log
[defaults]
hypervisor_id=hostname
[valid_default_main_conf_file_section]
server=1.2.3.4
username=admin
password=password
owner=owner
env=env
rhsm_hostname=abc
""")
config_manager = DestinationToSourceMapper(init_config({}, cli_dict, config_dir=self.config_dir))
# There should be only one config, and that should be the one passed from the cli
self.assertEqual(len(config_manager.configs), 1)
config = config_manager.configs[0][1]
self.assertEqual(config.name, "valid_cli_section")
self.assertEqual(config["server"], "5.5.5.5")
self.assertEqual(config["username"], "admin1")
self.assertEqual(config["password"], "password1")
self.assertEqual(config["owner"], "owner1")
self.assertEqual(config["env"], "env1")
self.assertEqual(config["rhsm_hostname"], "abc1")
# Also, check that the default section values from the VW_GENERAL_CONF_PATH file are still read
# (and used when any of the keys are missing in the virt config)
self.assertEqual(config["hypervisor_id"], "hostname")
# Additionally, the global section from the VW_GENERAL_CONF_PATH file should be read in
self.assertEqual(config_manager.effective_config["global"]["log_file"], "rhsm45.log")
self.assertEqual(config_manager.effective_config["global"]["interval"], 100)
开发者ID:candlepin,项目名称:virt-who,代码行数:53,代码来源:test_config.py
示例8: testInvisibleConfigFile
def testInvisibleConfigFile(self):
with open(os.path.join(self.config_dir, ".test1.conf"), "w") as f:
f.write("""
[test1]
type=libvirt
server=1.2.3.4
username=admin
password=password
owner=root
""")
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertTrue("test1" not in [name for (name, config) in manager.configs],
"Hidden config file shouldn't be read")
开发者ID:virt-who,项目名称:virt-who,代码行数:13,代码来源:test_config.py
示例9: testNoOptionsConfig
def testNoOptionsConfig(self):
with open(os.path.join(self.config_dir, "test.conf"), "w") as f:
f.write("""
[test]
type=esx
""")
# Instantiating the DestinationToSourceMapper with an invalid config should not fail
# instead we expect that the list of configs managed by the DestinationToSourceMapper does not
# include the invalid one
config_manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
# There should be no configs parsed successfully, therefore the list of configs should
# be empty
self.assertEqual(len(config_manager.configs), 0)
开发者ID:candlepin,项目名称:virt-who,代码行数:13,代码来源:test_config.py
示例10: test_one_source_to_one_dest
def test_one_source_to_one_dest(self):
config_1 = combine_dicts(TestReadingConfigs.source_options_1,
TestReadingConfigs.dest_options_1)
expected_dest_1 = Satellite6DestinationInfo(
**TestReadingConfigs.dest_options_1)
expected_mapping = {
expected_dest_1: [config_1['name']]
}
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write(TestReadingConfigs.dict_to_ini(config_1))
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(manager.dest_to_sources_map, expected_mapping)
开发者ID:candlepin,项目名称:virt-who,代码行数:14,代码来源:test_config.py
示例11: testFilterHostNew
def testFilterHostNew(self):
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[test1]
type=esx
server=1.2.3.4
username=admin
password=password
owner=root
filter_hosts=12345
""")
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(len(manager.configs), 1)
self.assertEqual(manager.configs[0][1]["filter_hosts"], ['12345'])
开发者ID:virt-who,项目名称:virt-who,代码行数:14,代码来源:test_config.py
示例12: testEsxDisableSimplifiedVim
def testEsxDisableSimplifiedVim(self):
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[test1]
type=esx
server=1.2.3.4
username=admin
password=password
owner=root
simplified_vim=false
""")
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(len(manager.configs), 1)
_, config = manager.configs[0]
self.assertFalse(config['simplified_vim'])
开发者ID:virt-who,项目名称:virt-who,代码行数:15,代码来源:test_config.py
示例13: test_read_non_hypervisor_from_hypervisor
def test_read_non_hypervisor_from_hypervisor(self):
with open(self.hypervisor_file, "w") as f:
f.write(HYPERVISOR_JSON)
with open(self.config_file, "w") as f:
f.write("""
[test]
type=fake
is_hypervisor=false
file=%s
""" % self.hypervisor_file)
effective_config = init_config({}, {}, config_dir=self.config_dir)
# This is an invalid case, the config section that is invalid should have been dropped
self.assertNotIn('test', effective_config)
开发者ID:candlepin,项目名称:virt-who,代码行数:15,代码来源:test_fake.py
示例14: test_unreadable_config
def test_unreadable_config(self):
filename = os.path.join(self.config_dir, "test.conf")
with open(filename, "w") as f:
f.write("""
[test]
type=esx
server=1.2.3.4
username=admin
password=password
owner=root
""")
os.chmod(filename, 0)
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
# There should be at least one 'env/cmdline' section
self.assertEqual(len(manager.configs), 1)
开发者ID:virt-who,项目名称:virt-who,代码行数:15,代码来源:test_config.py
示例15: testMissingOwnerOption
def testMissingOwnerOption(self):
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[test1]
type=esx
server=1.2.3.4
username=admin
password=password
rhsm_hostname=abc
""")
# Instantiating the DestinationToSourceMapper with an invalid config should not fail
# instead we expect that the list of configs managed by the DestinationToSourceMapper does not
# include the invalid one
config_manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
# There should be no configs parsed successfully, therefore the list of configs should
# be empty
self.assertEqual(len(config_manager.configs), 0)
开发者ID:virt-who,项目名称:virt-who,代码行数:17,代码来源:test_config.py
示例16: test_read_hypervisor_from_non_hypervisor
def test_read_hypervisor_from_non_hypervisor(self):
with open(self.hypervisor_file, "w") as f:
f.write(NON_HYPERVISOR_JSON)
with open(self.config_file, "w") as f:
f.write("""
[test]
type=fake
is_hypervisor=true
owner=covfefe
env=covfefe
file=%s
""" % self.hypervisor_file)
effective_config = init_config({}, {}, config_dir=self.config_dir)
DestinationToSourceMapper(effective_config)
# The 'test' section is not valid here (as the json provided will not work with
# the is_hypervisor value set to true)
self.assertNotIn('test', effective_config)
开发者ID:candlepin,项目名称:virt-who,代码行数:18,代码来源:test_fake.py
示例17: testCryptedPassword
def testCryptedPassword(self, password):
password.return_value = (hexlify(Password._generate_key()), hexlify(Password._generate_key()))
passwd = "TestSecretPassword!"
crypted = hexlify(Password.encrypt(passwd)).decode('utf-8')
filename = os.path.join(self.config_dir, "test.conf")
with open(filename, "w") as f:
f.write("""
[test]
type=esx
server=1.2.3.4
username=admin
encrypted_password=%s
owner=root
""" % crypted)
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(len(manager.configs), 1)
self.assertEqual(manager.configs[0][1]['password'], passwd)
开发者ID:virt-who,项目名称:virt-who,代码行数:18,代码来源:test_config.py
示例18: testMultipleConfigsInFile
def testMultipleConfigsInFile(self):
config_1 = combine_dicts(TestReadingConfigs.source_options_1,
TestReadingConfigs.dest_options_1)
config_2 = combine_dicts(TestReadingConfigs.source_options_2,
TestReadingConfigs.dest_options_2)
with open(os.path.join(self.config_dir, "test.conf"), "w") as f:
f.write(TestReadingConfigs.dict_to_ini(config_1) +
TestReadingConfigs.dict_to_ini(config_2))
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(len(manager.configs), 2)
for name, config in manager.configs:
self.assertIn(config.name, [config_1["name"], config_2["name"]])
if config.name == config_1['name']:
self.assert_config_contains_all(config, config_1)
elif config.name == config_2['name']:
self.assert_config_contains_all(config, config_2)
开发者ID:candlepin,项目名称:virt-who,代码行数:18,代码来源:test_config.py
示例19: test_sm_config_file
def test_sm_config_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("""
[test]
type=libvirt
owner=owner
env=env
rhsm_hostname=host
rhsm_port=8080
rhsm_prefix=prefix
rhsm_proxy_hostname=proxy_host
rhsm_proxy_port=9090
rhsm_proxy_user=proxy_user
rhsm_proxy_password=proxy_password
rhsm_insecure=1
rhsm_username=user
rhsm_password=passwd
rhsm_no_proxy=filter
""")
config_manager = DestinationToSourceMapper(init_config({}, {}, config_dir=config_dir))
self.assertEqual(len(config_manager.configs), 1)
config = dict(config_manager.configs)["test"]
manager = Manager.from_config(self.logger, config)
self.assertTrue(isinstance(manager, SubscriptionManager))
self.assertEqual(config['rhsm_hostname'], 'host')
self.assertEqual(config['rhsm_port'], '8080')
manager._connect(config)
self.sm.connection.assert_called_with(
username='user',
password='passwd',
host='host',
ssl_port=8080,
handler='prefix',
proxy_hostname='proxy_host',
proxy_port='9090',
proxy_user='proxy_user',
proxy_password='proxy_password',
no_proxy='filter',
insecure='1',
correlation_id=manager.correlation_id)
开发者ID:candlepin,项目名称:virt-who,代码行数:44,代码来源:test_subscriptionmanager.py
示例20: testQuotesInConfig
def testQuotesInConfig(self):
with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[test1]
type=esx
server="http://1.2.3.4"
username='admin'
password=p"asswor'd
owner=" root "
""")
manager = DestinationToSourceMapper(init_config({}, {}, config_dir=self.config_dir))
self.assertEqual(len(manager.configs), 1)
config = manager.configs[0][1]
self.assertEqual(config.name, "test1")
self.assertEqual(config["type"], "esx")
self.assertEqual(config["server"], "http://1.2.3.4")
self.assertEqual(config["username"], "admin")
self.assertEqual(config["password"], "p\"asswor'd")
self.assertEqual(config["owner"], " root ")
开发者ID:virt-who,项目名称:virt-who,代码行数:19,代码来源:test_config.py
注:本文中的virtwho.config.init_config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论