本文整理汇总了Python中trove.guestagent.common.configuration.ConfigurationManager.parse_configuration方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationManager.parse_configuration方法的具体用法?Python ConfigurationManager.parse_configuration怎么用?Python ConfigurationManager.parse_configuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trove.guestagent.common.configuration.ConfigurationManager
的用法示例。
在下文中一共展示了ConfigurationManager.parse_configuration方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_write_configuration
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import parse_configuration [as 别名]
def test_read_write_configuration(self, read_file, write_file,
chown, chmod):
sample_path = Mock()
sample_owner = Mock()
sample_group = Mock()
sample_codec = MagicMock()
sample_requires_root = Mock()
sample_strategy = MagicMock()
sample_strategy.configure = Mock()
sample_strategy.parse_updates = Mock(return_value={})
manager = ConfigurationManager(
sample_path, sample_owner, sample_group, sample_codec,
requires_root=sample_requires_root,
override_strategy=sample_strategy)
manager.parse_configuration()
read_file.assert_called_with(sample_path, codec=sample_codec,
as_root=sample_requires_root)
with patch.object(manager, 'parse_configuration',
return_value={'key1': 'v1', 'key2': 'v2'}):
self.assertEqual('v1', manager.get_value('key1'))
self.assertIsNone(manager.get_value('key3'))
sample_contents = Mock()
manager.save_configuration(sample_contents)
write_file.assert_called_with(
sample_path, sample_contents, as_root=sample_requires_root)
chown.assert_called_with(sample_path, sample_owner, sample_group,
as_root=sample_requires_root)
chmod.assert_called_with(
sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)
sample_data = {}
manager.apply_system_override(sample_data)
manager.apply_user_override(sample_data)
manager.apply_system_override(sample_data, change_id='sys1')
manager.apply_user_override(sample_data, change_id='usr1')
manager.apply_system_override(sample_data, change_id='sys2',
pre_user=True)
sample_strategy.apply.has_calls([
call(manager.SYSTEM_POST_USER_GROUP,
manager.DEFAULT_CHANGE_ID, sample_data),
call(manager.USER_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
call(manager.SYSTEM_POST_USER_GROUP,
'sys1', sample_data),
call(manager.USER_GROUP, 'usr1', sample_data),
call(manager.SYSTEM_PRE_USER_GROUP,
'sys2', sample_data),
])
示例2: test_read_write_configuration
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import parse_configuration [as 别名]
def test_read_write_configuration(self, read_file, write_file, chown, chmod):
sample_path = Mock()
sample_owner = Mock()
sample_group = Mock()
sample_codec = MagicMock()
sample_requires_root = Mock()
sample_strategy = MagicMock()
sample_strategy.configure = Mock()
sample_strategy.parse_updates = Mock(return_value={})
manager = ConfigurationManager(
sample_path,
sample_owner,
sample_group,
sample_codec,
requires_root=sample_requires_root,
override_strategy=sample_strategy,
)
manager.parse_configuration()
read_file.assert_called_with(sample_path, codec=sample_codec)
with patch.object(manager, "parse_configuration", return_value={"key1": "v1", "key2": "v2"}):
self.assertEqual("v1", manager.get_value("key1"))
self.assertIsNone(manager.get_value("key3"))
sample_contents = Mock()
manager.save_configuration(sample_contents)
write_file.assert_called_with(sample_path, sample_contents, as_root=sample_requires_root)
chown.assert_called_with(sample_path, sample_owner, sample_group, as_root=sample_requires_root)
chmod.assert_called_with(sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)
sample_data = {}
manager.apply_system_override(sample_data)
manager.apply_user_override(sample_data)
manager.apply_system_override(sample_data, change_id="sys1")
manager.apply_user_override(sample_data, change_id="usr1")
sample_strategy.apply.has_calls(
[
call(manager.SYSTEM_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
call(manager.USER_GROUP, manager.DEFAULT_CHANGE_ID, sample_data),
call(manager.SYSTEM_GROUP, "sys1", sample_data),
call(manager.USER_GROUP, "usr1", sample_data),
]
)
示例3: test_read_write_configuration
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import parse_configuration [as 别名]
def test_read_write_configuration(self, read_file, write_file,
chown, chmod):
sample_path = Mock()
sample_owner = Mock()
sample_group = Mock()
sample_codec = MagicMock()
sample_requires_root = Mock()
manager = ConfigurationManager(
sample_path, sample_owner, sample_group, sample_codec,
requires_root=sample_requires_root)
manager.parse_configuration()
read_file.assert_called_with(sample_path, codec=sample_codec)
with patch.object(manager, 'parse_configuration',
return_value={'key1': 'v1', 'key2': 'v2'}):
self.assertEqual('v1', manager.get_value('key1'))
self.assertEqual(None, manager.get_value('key3'))
sample_contents = Mock()
manager.save_configuration(sample_contents)
write_file.assert_called_with(
sample_path, sample_contents, as_root=sample_requires_root)
chown.assert_called_with(sample_path, sample_owner, sample_group,
as_root=sample_requires_root)
chmod.assert_called_with(
sample_path, FileMode.ADD_READ_ALL, as_root=sample_requires_root)
sample_options = Mock()
with patch.object(manager, 'save_configuration') as save_config:
manager.render_configuration(sample_options)
save_config.assert_called_once_with(
sample_codec.serialize.return_value)
sample_codec.serialize.assert_called_once_with(sample_options)
with patch('trove.guestagent.common.configuration.'
'ConfigurationOverrideStrategy') as mock_strategy:
manager.set_override_strategy(mock_strategy)
manager._current_revision = 3
manager.save_configuration(sample_contents)
mock_strategy.remove_last.assert_called_once_with(
manager._current_revision + 1)
write_file.assert_called_with(
sample_path, sample_contents, as_root=sample_requires_root)
示例4: MongoDBApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import parse_configuration [as 别名]
#.........这里部分代码省略.........
mongodb_run_dir, user=system.MONGO_USER, group=system.MONGO_USER,
force=True, as_root=True)
def _configure_as_cluster_instance(self, cluster_config):
"""Configure this guest as a cluster instance and return its
new status.
"""
if cluster_config['instance_type'] == "query_router":
self._configure_as_query_router()
elif cluster_config["instance_type"] == "config_server":
self._configure_as_config_server()
elif cluster_config["instance_type"] == "member":
self._configure_as_cluster_member(
cluster_config['replica_set_name'])
else:
LOG.error(_("Bad cluster configuration; instance type "
"given as %s.") % cluster_config['instance_type'])
return ds_instance.ServiceStatuses.FAILED
if 'key' in cluster_config:
self._configure_cluster_security(cluster_config['key'])
def _configure_as_query_router(self):
LOG.info(_("Configuring instance as a cluster query router."))
self.is_query_router = True
# FIXME(pmalik): We should really have a separate configuration
# template for the 'mongos' process.
# Remove all storage configurations from the template.
# They apply only to 'mongod' processes.
# Already applied overrides will be integrated into the base file and
# their current groups removed.
config = guestagent_utils.expand_dict(
self.configuration_manager.parse_configuration())
if 'storage' in config:
LOG.debug("Removing 'storage' directives from the configuration "
"template.")
del config['storage']
self.configuration_manager.save_configuration(
guestagent_utils.flatten_dict(config))
# Apply 'mongos' configuration.
self._configure_network(MONGODB_PORT)
self.configuration_manager.apply_system_override(
{'sharding.configDB': ''}, CNF_CLUSTER)
def _configure_as_config_server(self):
LOG.info(_("Configuring instance as a cluster config server."))
self._configure_network(CONFIGSVR_PORT)
self.configuration_manager.apply_system_override(
{'sharding.clusterRole': 'configsvr'}, CNF_CLUSTER)
def _configure_as_cluster_member(self, replica_set_name):
LOG.info(_("Configuring instance as a cluster member."))
self.is_cluster_member = True
self._configure_network(MONGODB_PORT)
# we don't want these thinking they are in a replica set yet
# as that would prevent us from creating the admin user,
# so start mongo before updating the config.
# mongo will be started by the cluster taskmanager
self.start_db()
self.configuration_manager.apply_system_override(
{'replication.replSetName': replica_set_name}, CNF_CLUSTER)
def _configure_cluster_security(self, key_value):
"""Force cluster key-file-based authentication.
示例5: MongoDBApp
# 需要导入模块: from trove.guestagent.common.configuration import ConfigurationManager [as 别名]
# 或者: from trove.guestagent.common.configuration.ConfigurationManager import parse_configuration [as 别名]
#.........这里部分代码省略.........
new status.
"""
if cluster_config["instance_type"] == "query_router":
self._configure_as_query_router()
elif cluster_config["instance_type"] == "config_server":
self._configure_as_config_server()
elif cluster_config["instance_type"] == "member":
self._configure_as_cluster_member(cluster_config["replica_set_name"])
else:
LOG.error(_("Bad cluster configuration; instance type " "given as %s.") % cluster_config["instance_type"])
return ds_instance.ServiceStatuses.FAILED
if "key" in cluster_config:
self._configure_cluster_security(cluster_config["key"])
def _configure_as_query_router(self):
LOG.info(_("Configuring instance as a cluster query router."))
self.is_query_router = True
# Write the 'mongos' upstart script.
# FIXME(pmalik): The control script should really be written in the
# elements.
# The guestagent will choose the right daemon ('mongod' or 'mongos')
# based on the 'cluster_config' values.
upstart_contents = system.MONGOS_UPSTART_CONTENTS.format(config_file_placeholder=CONFIG_FILE)
operating_system.write_file(system.MONGOS_UPSTART, upstart_contents, as_root=True)
# FIXME(pmalik): We should really have a separate configuration
# template for the 'mongos' process.
# Remove all storage configurations from the template.
# They apply only to 'mongod' processes.
# Already applied overrides will be integrated into the base file and
# their current groups removed.
config = guestagent_utils.expand_dict(self.configuration_manager.parse_configuration())
if "storage" in config:
LOG.debug("Removing 'storage' directives from the configuration " "template.")
del config["storage"]
self.configuration_manager.save_configuration(guestagent_utils.flatten_dict(config))
# Apply 'mongos' configuration.
self._configure_network(MONGODB_PORT)
self.configuration_manager.apply_system_override({"sharding.configDB": ""}, CNF_CLUSTER)
def _configure_as_config_server(self):
LOG.info(_("Configuring instance as a cluster config server."))
self._configure_network(CONFIGSVR_PORT)
self.configuration_manager.apply_system_override({"sharding.clusterRole": "configsvr"}, CNF_CLUSTER)
def _configure_as_cluster_member(self, replica_set_name):
LOG.info(_("Configuring instance as a cluster member."))
self.is_cluster_member = True
self._configure_network(MONGODB_PORT)
# we don't want these thinking they are in a replica set yet
# as that would prevent us from creating the admin user,
# so start mongo before updating the config.
# mongo will be started by the cluster taskmanager
self.start_db()
self.configuration_manager.apply_system_override({"replication.replSetName": replica_set_name}, CNF_CLUSTER)
def _configure_cluster_security(self, key_value):
"""Force cluster key-file-based authentication.
"""
# Store the cluster member authentication key.
self.store_key(key_value)
# TODO(mvandijk): enable cluster security once Trove features are in