本文整理汇总了Python中virtwho.config.init_config函数的典型用法代码示例。如果您正苦于以下问题:Python init_config函数的具体用法?Python init_config怎么用?Python init_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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")
示例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")
示例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)
示例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)
示例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)
示例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")
示例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)
示例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)
示例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'])
示例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'])
示例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)
示例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)
示例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)