本文整理汇总了Python中pcs.lib.env.LibraryEnvironment类的典型用法代码示例。如果您正苦于以下问题:Python LibraryEnvironment类的具体用法?Python LibraryEnvironment怎么用?Python LibraryEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LibraryEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_corosync_conf_not_set_need_offline_success
def test_corosync_conf_not_set_need_offline_success(
self, mock_get_corosync, mock_distribute, mock_is_running, mock_reload,
mock_check_offline, mock_qdevice_reload
):
corosync_data = open(rc("corosync.conf")).read()
new_corosync_data = corosync_data.replace("version: 2", "version: 3")
mock_get_corosync.return_value = corosync_data
mock_is_running.return_value = False
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
self.assertTrue(env.is_corosync_conf_live)
self.assertEqual(corosync_data, env.get_corosync_conf_data())
self.assertEqual(corosync_data, env.get_corosync_conf().config.export())
self.assertEqual(2, mock_get_corosync.call_count)
conf_facade = CorosyncConfigFacade.from_string(new_corosync_data)
conf_facade._need_stopped_cluster = True
env.push_corosync_conf(conf_facade)
mock_check_offline.assert_called_once_with(
"mock node communicator",
self.mock_reporter,
"mock node list",
False
)
mock_distribute.assert_called_once_with(
"mock node communicator",
self.mock_reporter,
"mock node list",
new_corosync_data,
False
)
mock_reload.assert_not_called()
mock_qdevice_reload.assert_not_called()
示例2: test_push_cib_not_upgraded_live
def test_push_cib_not_upgraded_live(self, mock_replace_cib):
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
env.push_cib(etree.XML('<cib/>'))
mock_replace_cib.assert_called_once_with(
"mock cmd runner", '<cib/>', False
)
self.assertEqual([], env.report_processor.report_item_list)
示例3: test_node_communicator_all_options
def test_node_communicator_all_options(self, mock_comm):
expected_comm = mock.MagicMock()
mock_comm.return_value = expected_comm
user = "testuser"
groups = ["some", "group"]
tokens = {"node": "token"}
timeout = 10
env = LibraryEnvironment(
self.mock_logger,
self.mock_reporter,
user_login=user,
user_groups=groups,
auth_tokens_getter=lambda:tokens,
request_timeout=timeout
)
comm = env.node_communicator()
self.assertEqual(expected_comm, comm)
mock_comm.assert_called_once_with(
self.mock_logger,
self.mock_reporter,
tokens,
user,
groups,
timeout
)
示例4: test_get_cluster_conf_live
def test_get_cluster_conf_live(self, mock_get_local_cluster_conf):
env = LibraryEnvironment(
self.mock_logger, self.mock_reporter, cluster_conf_data=None
)
mock_get_local_cluster_conf.return_value = "cluster.conf data"
self.assertEqual("cluster.conf data", env.get_cluster_conf_data())
mock_get_local_cluster_conf.assert_called_once_with()
示例5: test_get_cluster_conf
def test_get_cluster_conf(self):
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
facade_obj = env.get_cluster_conf()
self.assertTrue(isinstance(facade_obj, ClusterConfFacade))
assert_xml_equal(
'<cluster/>', etree.tostring(facade_obj._config).decode()
)
示例6: test_corosync_conf_not_set
def test_corosync_conf_not_set(
self, mock_get_corosync, mock_distribute, mock_reload
):
corosync_data = open(rc("corosync.conf")).read()
new_corosync_data = corosync_data.replace("version: 2", "version: 3")
mock_get_corosync.return_value = corosync_data
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
self.assertTrue(env.is_corosync_conf_live)
self.assertEqual(corosync_data, env.get_corosync_conf_data())
self.assertEqual(corosync_data, env.get_corosync_conf().config.export())
self.assertEqual(2, mock_get_corosync.call_count)
env.push_corosync_conf(
CorosyncConfigFacade.from_string(new_corosync_data)
)
mock_distribute.assert_called_once_with(
"mock node communicator",
self.mock_reporter,
"mock node list",
new_corosync_data,
False
)
mock_reload.assert_called_once_with("mock cmd runner")
示例7: test_get_cib_no_version_live
def test_get_cib_no_version_live(
self, mock_get_cib_xml, mock_ensure_cib_version
):
mock_get_cib_xml.return_value = '<cib/>'
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
assert_xml_equal('<cib/>', etree.tostring(env.get_cib()).decode())
self.assertEqual(1, mock_get_cib_xml.call_count)
self.assertEqual(0, mock_ensure_cib_version.call_count)
self.assertFalse(env.cib_upgraded)
示例8: test_push_cib_upgraded_live
def test_push_cib_upgraded_live(self, mock_replace_cib):
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
env._cib_upgraded = True
env.push_cib(etree.XML('<cib/>'))
mock_replace_cib.assert_called_once_with(
"mock cmd runner",
'<cib/>'
)
self.assertFalse(env.cib_upgraded)
示例9: test_cmd_runner_no_options
def test_cmd_runner_no_options(self, mock_runner):
expected_runner = mock.MagicMock()
mock_runner.return_value = expected_runner
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
runner = env.cmd_runner()
self.assertEqual(expected_runner, runner)
mock_runner.assert_called_once_with(
self.mock_logger,
self.mock_reporter,
{}
)
示例10: test_get_cib_upgrade_live
def test_get_cib_upgrade_live(
self, mock_get_cib_xml, mock_ensure_cib_version
):
mock_get_cib_xml.return_value = '<cib/>'
mock_ensure_cib_version.return_value = etree.XML('<new_cib/>')
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
assert_xml_equal(
'<new_cib/>', etree.tostring(env.get_cib((1, 2, 3))).decode()
)
self.assertEqual(1, mock_get_cib_xml.call_count)
self.assertEqual(1, mock_ensure_cib_version.call_count)
self.assertTrue(env.cib_upgraded)
示例11: test_cib_not_set
def test_cib_not_set(self, mock_get_cib, mock_push_cib):
cib_data = "test cib data"
new_cib_data = "new test cib data"
mock_get_cib.return_value = cib_data
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
self.assertTrue(env.is_cib_live)
self.assertEqual(cib_data, env._get_cib_xml())
self.assertEqual(1, mock_get_cib.call_count)
env._push_cib_xml(new_cib_data)
self.assertEqual(1, mock_push_cib.call_count)
示例12: test_node_communicator_no_options
def test_node_communicator_no_options(self, mock_comm):
expected_comm = mock.MagicMock()
mock_comm.return_value = expected_comm
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
comm = env.node_communicator()
self.assertEqual(expected_comm, comm)
mock_comm.assert_called_once_with(
self.mock_logger,
self.mock_reporter,
{},
None,
[]
)
示例13: test_push_cib_upgraded_live
def test_push_cib_upgraded_live(self, mock_replace_cib):
env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
env._cib_upgraded = True
env.push_cib(etree.XML('<cib/>'))
mock_replace_cib.assert_called_once_with(
"mock cmd runner", '<cib/>', True
)
assert_report_item_list_equal(
env.report_processor.report_item_list,
[(
severity.INFO,
report_codes.CIB_UPGRADE_SUCCESSFUL,
{}
)]
)
示例14: PushCib
class PushCib(TestCase):
def setUp(self):
self.env = LibraryEnvironment(
mock.MagicMock(logging.Logger),
MockLibraryReportProcessor()
)
def test_run_only_push_when_without_wait(self, wait_for_idle, push_cib_xml):
self.env.push_cib(etree.fromstring("<cib/>"))
push_cib_xml.assert_called_once_with("<cib/>")
wait_for_idle.assert_not_called()
def test_run_wait_when_wait_specified(self, wait_for_idle, push_cib_xml):
self.env.push_cib(etree.fromstring("<cib/>"), 10)
push_cib_xml.assert_called_once_with("<cib/>")
wait_for_idle.assert_called_once_with(self.env.cmd_runner(), 10)
示例15: test_cmd_runner_all_options
def test_cmd_runner_all_options(self, mock_runner):
expected_runner = mock.MagicMock()
mock_runner.return_value = expected_runner
user = "testuser"
env = LibraryEnvironment(
self.mock_logger,
self.mock_reporter,
user_login=user
)
runner = env.cmd_runner()
self.assertEqual(expected_runner, runner)
mock_runner.assert_called_once_with(
self.mock_logger,
self.mock_reporter,
{"CIB_user": user}
)