def pcs(testfile, args): """ Run pcs with -f on specified file Return tuple with: shell stdoutdata shell returncode """ arg_split = args.split() arg_split_temp = [] in_quote = False for arg in arg_split: if in_quote: arg_split_temp[-1] = arg_split_temp[-1] + " " + arg.replace( "'", "") if arg.find("'") != -1: in_quote = False else: arg_split_temp.append(arg.replace("'", "")) if arg.find("'") != -1 and not (arg[0] == "'" and arg[-1] == "'"): in_quote = True conf_opts = [] if "--corosync_conf" not in args: corosync_conf = rc("corosync.conf") conf_opts.append("--corosync_conf=" + corosync_conf) if "--cluster_conf" not in args: cluster_conf = rc("cluster.conf") conf_opts.append("--cluster_conf=" + cluster_conf) return utils.run([__pcs_location, "-f", testfile] + conf_opts + arg_split_temp)
def pcs(testfile, args = ""): """ Run pcs with -f on specified file Return tuple with: shell stdoutdata shell returncode """ if args == "": args = testfile testfile = _temp_cib arg_split = args.split() arg_split_temp = [] in_quote = False for arg in arg_split: if in_quote: arg_split_temp[-1] = arg_split_temp[-1] + " " + arg.replace("'", "") if arg.find("'") != -1: in_quote = False else: arg_split_temp.append(arg.replace("'", "")) if arg.find("'") != -1 and not (arg[0] == "'" and arg[-1] == "'"): in_quote = True conf_opts = [] if "--corosync_conf" not in args: corosync_conf = rc("corosync.conf") conf_opts.append("--corosync_conf=" + corosync_conf) if "--cluster_conf" not in args: cluster_conf = rc("cluster.conf") conf_opts.append("--cluster_conf=" + cluster_conf) return utils.run( [__pcs_location, "-f", testfile] + conf_opts + arg_split_temp )
class ResourceTest(TestCase, get_assert_pcs_effect_mixin(get_cib_resources)): empty_cib = rc("cib-empty.xml") temp_cib = rc("temp-cib.xml") def setUp(self): shutil.copy(self.empty_cib, self.temp_cib) self.pcs_runner = PcsRunner(self.temp_cib)
def setUp(self): if fencing_level_attribute_supported: shutil.copy(rc("cib-empty-2.5-withnodes.xml"), temp_cib) else: shutil.copy(rc("cib-empty-2.3-withnodes.xml"), temp_cib) self.pcs_runner = PcsRunner(temp_cib) self.config = "" self.config_lines = []
def test_success_file(self): self.mock_runner.run.return_value = "", "", 0 lib.upgrade_cib(self.mock_runner, rc("cib-empty.xml")) self.mock_runner.run.assert_called_once_with( ["/usr/sbin/cibadmin", "--upgrade", "--force"], env_extend={ "CIB_file": rc("cib-empty.xml"), })
def __init__(self, cib_file=_temp_cib, corosync_conf_file=None, cluster_conf_file=None): self.cib_file = cib_file self.corosync_conf_file = (rc("corosync.conf") if corosync_conf_file is None else corosync_conf_file) self.cluster_conf_file = (rc("cluster.conf") if cluster_conf_file is None else cluster_conf_file)
def __init__( self, cib_file=_temp_cib, corosync_conf_file=None, cluster_conf_file=None ): self.cib_file = cib_file self.corosync_conf_file = ( rc("corosync.conf") if corosync_conf_file is None else corosync_conf_file ) self.cluster_conf_file = ( rc("cluster.conf") if cluster_conf_file is None else cluster_conf_file )
def test_upgrade_for_promoted_max(self): shutil.copy(rc("cib-empty-2.8.xml"), self.temp_cib) self.assert_pcs_success( "resource bundle create B container docker image=pcs:test") self.assert_pcs_success( "resource bundle update B container promoted-max=3", "CIB has been upgraded to the latest schema version.\n")
def test_set_desired_file_access(self): #setup file_path = rc("temp-keyfile") if os.path.exists(file_path): os.remove(file_path) with open(file_path, "w") as file: file.write("content") #check assumptions stat = os.stat(file_path) self.assertNotEqual('600', oct(stat.st_mode)[-3:]) current_user = pwd.getpwuid(os.getuid())[0] if current_user != settings.pacemaker_uname: file_user = pwd.getpwuid(stat.st_uid)[0] self.assertNotEqual(file_user, settings.pacemaker_uname) current_group = grp.getgrgid(os.getgid())[0] if current_group != settings.pacemaker_gname: file_group = grp.getgrgid(stat.st_gid)[0] self.assertNotEqual(file_group, settings.pacemaker_gname) #run tested method env.set_keyfile_access(file_path) #check stat = os.stat(file_path) self.assertEqual('600', oct(stat.st_mode)[-3:]) file_user = pwd.getpwuid(stat.st_uid)[0] self.assertEqual(file_user, settings.pacemaker_uname) file_group = grp.getgrgid(stat.st_gid)[0] self.assertEqual(file_group, settings.pacemaker_gname)
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()
def test_remove_ip_when_booth_resource_add_failed(self): mock_resource_create = mock.Mock(side_effect=[None, SystemExit(1)]) mock_resource_remove = mock.Mock() mock_create_id = mock.Mock(side_effect=["ip_id","booth_id","group_id"]) ip = "1.2.3.4" booth_config_file_path = rc("/path/to/booth.conf") booth_resource.get_creator(mock_resource_create, mock_resource_remove)( ip, booth_config_file_path, mock_create_id ) self.assertEqual(mock_resource_create.mock_calls, [ mock.call( clone_opts=[], group=u'group_id', meta_values=[], op_values=[], ra_id=u'ip_id', ra_type=u'ocf:heartbeat:IPaddr2', ra_values=[u'ip=1.2.3.4'], ), mock.call( clone_opts=[], group='group_id', meta_values=[], op_values=[], ra_id='booth_id', ra_type='ocf:pacemaker:booth-site', ra_values=['config=/path/to/booth.conf'], ) ]) mock_resource_remove.assert_called_once_with("ip_id")
def test_returns_cib_from_cib_data(self): cib_filename = "cib-empty.xml" (self.config #Value of cib_data is unimportant here. See details in sibling test. .env.set_cib_data("whatever").runner.cib.load(filename=cib_filename)) assert_xml_equal(etree_to_str(self.env_assist.get_env().get_cib()), open(rc(cib_filename)).read())
def fixture_agent_load_calls(): return [ Call( "crm_resource --show-metadata ocf:heartbeat:Dummy", open(rc("resource_agent_ocf_heartbeat_dummy.xml")).read() ), ]
def cib_resources(cib_resources_xml, cib_base_file=None): cib_xml = open(rc(cib_base_file or "cib-empty.xml")).read() cib = etree.fromstring(cib_xml) resources_section = cib.find(".//resources") for child in etree.fromstring(cib_resources_xml): resources_section.append(child) return etree_to_str(cib)
def state_complete(resource_status_xml): status = etree.parse(rc("crm_mon.minimal.xml")).getroot() resource_status = etree.fromstring(resource_status_xml) for resource in resource_status.xpath(".//resource"): _default_element_attributes( resource, { "active": "true", "managed": "true", "failed": "false", "failure_ignored": "false", "nodes_running_on": "1", "orphaned": "false", "resource_agent": "ocf::heartbeat:Dummy", "role": "Started", }) for clone in resource_status.xpath(".//clone"): _default_element_attributes(clone, { "failed": "false", "failure_ignored": "false", }) for bundle in resource_status.xpath(".//bundle"): _default_element_attributes( bundle, { "type": "docker", "image": "image:name", "unique": "false", "failed": "false", }) status.append(resource_status) return etree_to_str(status)
class RemoteTest(ResourceTest): corosync_conf = rc("corosync.conf") def setUp(self): super().setUp() self.pcs_runner.corosync_conf_opt = self.corosync_conf self.pcs_runner.mock_settings = get_mock_settings("crm_resource_binary")
def load( self, node_name_list=None, name="corosync_conf.load", auto_tie_breaker=None ): content = open(rc("corosync.conf")).read() corosync_conf = None if node_name_list: corosync_conf = ConfigFacade.from_string(content).config for nodelist in corosync_conf.get_sections(name="nodelist"): corosync_conf.del_section(nodelist) nodelist_section = Section("nodelist") corosync_conf.add_section(nodelist_section) for i, node_name in enumerate(node_name_list): node_section = Section("node") node_section.add_attribute("ring0_addr", node_name) node_section.add_attribute("nodeid", i) nodelist_section.add_section(node_section) if auto_tie_breaker is not None: corosync_conf = ( corosync_conf if corosync_conf else ConfigFacade.from_string(content).config ) for quorum in corosync_conf.get_sections(name="quorum"): quorum.set_attribute( "auto_tie_breaker", "1" if auto_tie_breaker else "0" ) if corosync_conf: content = corosync_conf.export() self.load_content(content, name)
def test_success(self): path = rc("corosync.conf") settings.corosync_conf_file = path self.assertEqual( lib.get_local_corosync_conf(), open(path).read() )
def call_dummy_metadata(): return [ Call( "crm_resource --show-metadata ocf:heartbeat:Dummy", open(rc("resource_agent_ocf_heartbeat_dummy.xml")).read() ), ]
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")
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()
def load_state(self, name="runner.pcmk.load_state", filename="crm_mon.minimal.xml", resources=None, raw_resources=None): """ Create call for loading pacemaker state. string name -- key of the call string filename -- points to file with the status in the content string resources -- xml - resources section, will be put to state """ if resources and raw_resources is not None: raise AssertionError( "Cannot use 'resources' and 'raw_resources' together") state = etree.fromstring(open(rc(filename)).read()) if raw_resources is not None: resources = fixture_state_resources_xml(**raw_resources) if resources: state.append(complete_state_resources(etree.fromstring(resources))) self.__calls.place( name, RunnerCall( "crm_mon --one-shot --as-xml --inactive", stdout=etree_to_str(state), ))
def load_fenced_metadata( self, name="runner.pcmk.load_fenced_metadata", stdout=None, stderr="", returncode=0, instead=None, before=None, ): """ Create a call for loading fenced metadata - additional fence options string name -- the key of this call string stdout -- fenced stdout, default metadata if None string stderr -- fenced stderr int returncode -- fenced returncode string instead -- the key of a call instead of which this new call is to be placed string before -- the key of a call before which this new call is to be placed """ self.__calls.place( name, RunnerCall( "/usr/libexec/pacemaker/pacemaker-fenced metadata", stdout=( stdout if stdout is not None else open(rc("fenced_metadata.xml")).read() ), stderr=stderr, returncode=returncode ), before=before, instead=instead, )
def test_dump_cib_file(self, mock_tmpfile, mock_runner): expected_runner = mock.MagicMock() mock_runner.return_value = expected_runner mock_instance = mock.MagicMock() mock_instance.name = rc("file.tmp") mock_tmpfile.return_value = mock_instance env = LibraryEnvironment(self.mock_logger, self.mock_reporter, cib_data="<cib />") runner = env.cmd_runner() self.assertEqual(expected_runner, runner) mock_runner.assert_called_once_with(self.mock_logger, self.mock_reporter, { "LC_ALL": "C", "CIB_file": rc("file.tmp"), }) mock_tmpfile.assert_called_once_with("<cib />")
def setUpClass(cls): cls.patcher = mock.patch.object(LibraryEnvironment, "cmd_runner", lambda self: runner) cls.patcher.start() cls.patcher_corosync = mock.patch.object( LibraryEnvironment, "get_corosync_conf_data", lambda self: open(rc("corosync.conf")).read()) cls.patcher_corosync.start()
def test_error(self): path = rc("cluster.conf.nonexistent") settings.cluster_conf_file = path assert_raise_library_error( lib.get_local_cluster_conf, (severity.ERROR, report_codes.CLUSTER_CONF_READ_ERROR, { "path": path, "reason": "No such file or directory", }))
def test_error(self): path = rc("corosync.conf.nonexistent") settings.corosync_conf_file = path assert_raise_library_error( lib.get_local_corosync_conf, (severity.ERROR, report_codes.UNABLE_TO_READ_COROSYNC_CONFIG, { "path": path, "reason": "No such file or directory", }))
class BundleCreateCommon( TestCase, get_assert_pcs_effect_mixin(lambda cib: etree.tostring( # pylint:disable=undefined-variable etree.parse(cib).findall(".//resources")[0]))): temp_cib = rc("temp-cib.xml") def setUp(self): shutil.copy(self.empty_cib, self.temp_cib) self.pcs_runner = PcsRunner(self.temp_cib)
def test_success(self): shutil.copy(rc("cib-empty-2.0.xml"), self.temp_cib) self.assert_effect( "resource bundle create B1 container docker image=pcs:test", """ <resources> <bundle id="B1"> <docker image="pcs:test" /> </bundle> </resources> """, "CIB has been upgraded to the latest schema version.\n")
def load( self, modifiers=None, name="runner.cib.load", filename=None, before=None, returncode=0, stderr=None, instead=None, **modifier_shortcuts ): """ Create call for loading cib. string name -- key of the call list of callable modifiers -- every callable takes etree.Element and returns new etree.Element with desired modification. string filename -- points to file with cib in the content string before -- key of call before which this new call is to be placed int returncode string stderr string instead -- key of call instead of which this new call is to be placed dict modifier_shortcuts -- a new modifier is generated from each modifier shortcut. As key there can be keys of MODIFIER_GENERATORS. Value is passed into appropriate generator from MODIFIER_GENERATORS. For details see pcs.test.tools.fixture_cib (mainly the variable MODIFIER_GENERATORS - please refer it when you are adding params here) """ if(returncode != 0 or stderr is not None) and ( modifiers is not None or filename is not None or modifier_shortcuts ): raise AssertionError( "Do not combine parameters 'returncode' and 'stderr' with" " parameters 'modifiers', 'filename' and 'modifier_shortcuts'" ) command = "cibadmin --local --query" if returncode != 0: call = RunnerCall(command, stderr=stderr, returncode=returncode) else: cib = modify_cib( open(rc(filename if filename else self.cib_filename)).read(), modifiers, **modifier_shortcuts ) call = RunnerCall(command, stdout=cib) self.__calls.place(name, call, before=before, instead=instead)
def load_agent( self, name="runner.pcmk.load_agent", agent_name="ocf:heartbeat:Dummy", agent_filename=None, instead=None, ): """ Create call for loading resource agent metadata. string name -- key of the call string agent_name string agent_filename -- points to file with the agent metadata in the content string instead -- key of call instead of which this new call is to be placed """ if agent_filename: agent_metadata_filename = agent_filename elif agent_name in AGENT_FILENAME_MAP: agent_metadata_filename = AGENT_FILENAME_MAP[agent_name] else: raise AssertionError(( "Filename with metadata of agent '{0}' not specified.\n" "Please specify file with metadata for agent:\n" " a) explicitly for this test:" " config.runner.pcmk.load_agent(agent_name='{0}'," " filename='FILENAME_HERE.xml')\n" " b) implicitly for agent '{0}' in 'AGENT_FILENAME_MAP' in" " '{1}'\n" "Place agent metadata into '{2}FILENAME_HERE.xml'" ).format(agent_name, os.path.realpath(__file__), rc(""))) self.__calls.place( name, RunnerCall( "crm_resource --show-metadata {0}".format(agent_name), stdout=open(rc(agent_metadata_filename)).read() ), instead=instead, )
def fixture_cib(self): shutil.copy(rc('cib-empty-1.2.xml'), self.temp_cib) self.pcs_runner = PcsRunner(self.temp_cib) self.assert_pcs_success( "resource create --no-default-ops R ocf:heartbeat:Dummy") #add to cib: # <primitive class="ocf" id="R" provider="heartbeat" type="Dummy"> # <operations> # <op id="R-monitor-interval-60s" interval="60s" # name="monitor" # /> # </operations> # </primitive> cib_content = open(self.temp_cib).read() #clean self.pcs_runner = None shutil.copy(rc('cib-empty-1.2.xml'), self.temp_cib) return cib_content
def fixture_wait_and_get_state_calls(state_resource_xml): crm_mon = etree.fromstring(open(rc("crm_mon.minimal.xml")).read()) crm_mon.append(etree.fromstring(state_resource_xml)) return [ Call("crm_resource --wait --timeout=10"), Call( "crm_mon --one-shot --as-xml --inactive", etree_to_str(crm_mon), ), ]
def test_upgrade_for_promoted_max(self): shutil.copy(rc("cib-empty-2.8.xml"), self.temp_cib) self.assert_effect( "resource bundle create B1 container docker image=pcs:test " "promoted-max=2", """ <resources> <bundle id="B1"> <docker image="pcs:test" promoted-max="2" /> </bundle> </resources> """, "CIB has been upgraded to the latest schema version.\n")
def setUp(self): self.env_assist, self.config = get_env_tools(self) self.config.env.set_known_hosts_dests(KNOWN_HOSTS_DESTS) cib_xml_man = XmlManipulation.from_file(rc("cib-empty.xml")) cib_xml_man.append_to_first_tag_name( "resources", """ <primitive class="ocf" id="{0}" provider="heartbeat" type="VirtualDomain" /> """.format(VIRTUAL_MACHINE_ID)) self.config.env.set_cib_data(str(cib_xml_man))
def fixture_wait_and_get_state_calls(state_resource_xml): crm_mon = etree.fromstring(open(rc("crm_mon.minimal.xml")).read()) crm_mon.append(etree.fromstring(state_resource_xml)) return [ Call("crm_resource --wait --timeout=10"), Call( "crm_mon --one-shot --as-xml --inactive", etree.tostring(crm_mon).decode("utf-8"), ), ]
def fixture_cib(self): shutil.copy(rc('cib-empty-1.2.xml'), self.temp_cib) self.pcs_runner = PcsRunner(self.temp_cib) self.assert_pcs_success( "resource create --no-default-ops R ocf:heartbeat:Dummy" ) #add to cib: # <primitive class="ocf" id="R" provider="heartbeat" type="Dummy"> # <operations> # <op id="R-monitor-interval-60s" interval="60s" # name="monitor" # /> # </operations> # </primitive> cib_content = open(self.temp_cib).read() #clean self.pcs_runner = None shutil.copy(rc('cib-empty-1.2.xml'), self.temp_cib) return cib_content
def test_dump_cib_file(self, mock_tmpfile, mock_runner): expected_runner = mock.MagicMock() mock_runner.return_value = expected_runner mock_instance = mock.MagicMock() mock_instance.name = rc("file.tmp") mock_tmpfile.return_value = mock_instance env = LibraryEnvironment( self.mock_logger, self.mock_reporter, cib_data="<cib />" ) runner = env.cmd_runner() self.assertEqual(expected_runner, runner) mock_runner.assert_called_once_with( self.mock_logger, self.mock_reporter, { "LC_ALL": "C", "CIB_file": rc("file.tmp"), } ) mock_instance.write.assert_called_once_with("<cib />")
def test_error(self): path = rc("corosync.conf.nonexistent") settings.corosync_conf_file = path assert_raise_library_error( lib.get_local_corosync_conf, ( severity.ERROR, report_codes.UNABLE_TO_READ_COROSYNC_CONFIG, { "path": path, "reason": "No such file or directory", } ) )
def test_error(self): path = rc("cluster.conf.nonexistent") settings.cluster_conf_file = path assert_raise_library_error( lib.get_local_cluster_conf, ( severity.ERROR, report_codes.CLUSTER_CONF_READ_ERROR, { "path": path, "reason": "No such file or directory", } ) )
def fixture_cib_calls(cib_resources_xml): cib_xml = open(rc("cib-empty.xml")).read() cib = etree.fromstring(cib_xml) resources_section = cib.find(".//resources") for child in etree.fromstring(cib_resources_xml): resources_section.append(child) return [ Call("cibadmin --local --query", cib_xml), Call( "cibadmin --replace --verbose --xml-pipe --scope configuration", check_stdin=Call.create_check_stdin_xml(etree.tostring(cib)) ), ]
def test_corosync_conf_not_set_need_offline_fail( self, mock_get_corosync, mock_distribute, 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 def raiser(dummy_communicator, dummy_reporter, dummy_nodes, dummy_force): raise LibraryError( reports.corosync_not_running_check_node_error("test node") ) mock_check_offline.side_effect = raiser 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 assert_raise_library_error( lambda: env.push_corosync_conf(conf_facade), ( severity.ERROR, report_codes.COROSYNC_NOT_RUNNING_CHECK_NODE_ERROR, {"node": "test node"} ) ) mock_check_offline.assert_called_once_with( "mock node communicator", self.mock_reporter, "mock node list", False ) mock_distribute.assert_not_called() mock_reload.assert_not_called() mock_qdevice_reload.assert_not_called()
division, print_function, unicode_literals, ) import shutil from pcs.test.tools.pcs_unittest import TestCase from pcs.test.tools.assertions import AssertPcsMixin from pcs.test.tools.misc import ( get_test_resource as rc, ) from pcs.test.tools.pcs_runner import PcsRunner coro_conf = rc("corosync.conf") coro_qdevice_conf = rc("corosync-3nodes-qdevice.conf") temp_conf = rc("corosync.conf.tmp") class TestBase(TestCase, AssertPcsMixin): def setUp(self): shutil.copy(coro_conf, temp_conf) self.pcs_runner = PcsRunner(corosync_conf_file=temp_conf) def fixture_conf_qdevice(self): shutil.copy(coro_qdevice_conf, temp_conf) class QuorumConfigTest(TestBase): def test_no_device(self):
absolute_import, division, print_function, unicode_literals, ) import shutil import unittest from pcs.test.tools.misc import ( ac, get_test_resource as rc, ) from pcs.test.tools.pcs_runner import pcs empty_cib = rc("cib-empty-withnodes.xml") temp_cib = rc("temp-cib.xml") class NodeTest(unittest.TestCase): def setUp(self): shutil.copy(empty_cib, temp_cib) def test_node_maintenance(self): output, _ = pcs(temp_cib, "property") expected_out = """\ Cluster Properties: """ ac(expected_out, output) output, returnVal = pcs(temp_cib, "node maintenance rh7-1") ac("", output) self.assertEqual(returnVal, 0)
def setUp(self): self.create_covered_status = get_xml_manipulation_creator_from_file( rc('crm_mon.minimal.xml') ) self.covered_status = self.create_covered_status()
def setUp(self): shutil.copy(rc("cib-empty-with3nodes.xml"), temp_cib) self.pcs_runner = PcsRunner(temp_cib)
def setUp(self): shutil.copy(rc('cib-empty-1.2.xml'), self.temp_cib) self.pcs_runner = PcsRunner(self.temp_cib)
def fixture_status_xml(self, nodes, resources): xml_man = XmlManipulation.from_file(rc("crm_mon.minimal.xml")) doc = xml_man.tree.getroottree() doc.find("/summary/nodes_configured").set("number", str(nodes)) doc.find("/summary/resources_configured").set("number", str(resources)) return str(XmlManipulation(doc))
print_function, unicode_literals, ) import shutil import unittest from pcs.test.tools.misc import ( ac, get_test_resource as rc, ) from pcs.test.tools.pcs_runner import pcs from pcs import utils empty_cib = rc("cib-empty.xml") temp_cib = rc("temp-cib.xml") class PropertyTest(unittest.TestCase): def setUp(self): shutil.copy(empty_cib, temp_cib) def testEmpty(self): output, returnVal = pcs(temp_cib, "property") assert returnVal == 0, 'Unable to list resources' assert output == "Cluster Properties:\n", [output] def testDefaults(self): output, returnVal = pcs(temp_cib, "property --defaults") prop_defaults = output assert returnVal == 0, 'Unable to list resources'
def setUp(self): self.status = XmlManipulation.from_file(rc("crm_mon.minimal.xml"))
def setUp(self): self.create_cib = get_xml_manipulation_creator_from_file(rc("cib-empty.xml")) self.cib = self.create_cib()
) import shutil from pcs.test.tools import pcs_unittest as unittest from pcs.test.tools.assertions import AssertPcsMixin from pcs.test.tools.misc import ( ac, get_test_resource as rc, ) from pcs.test.tools.pcs_runner import ( pcs, PcsRunner, ) old_cib = rc("cib-empty.xml") empty_cib = rc("cib-empty-1.2.xml") temp_cib = rc("temp-cib.xml") class ACLTest(unittest.TestCase, AssertPcsMixin): pcs_runner = None def setUp(self): shutil.copy(empty_cib, temp_cib) self.pcs_runner = PcsRunner(temp_cib) def testAutoUpgradeofCIB(self): shutil.copy(old_cib, temp_cib) self.assert_pcs_success( 'acl show', "ACLs are disabled, run 'pcs acl enable' to enable\n\n"
absolute_import, division, print_function, unicode_literals, ) import os import shutil from pcs.test.tools import pcs_unittest as unittest from pcs.test.tools.assertions import AssertPcsMixin, console_report from pcs.test.tools.misc import get_test_resource as rc from pcs.test.tools.pcs_runner import PcsRunner EMPTY_CIB = rc("cib-empty.xml") TEMP_CIB = rc("temp-cib.xml") BOOTH_CONFIG_FILE = rc("temp-booth.cfg") BOOTH_KEY_FILE = rc("temp-booth.key") BOOTH_RESOURCE_AGENT_INSTALLED = os.path.exists( "/usr/lib/ocf/resource.d/pacemaker/booth-site" ) need_booth_resource_agent = unittest.skipUnless( BOOTH_RESOURCE_AGENT_INSTALLED, "test requires resource agent ocf:pacemaker:booth-site" " which is not istalled" )
def setUp(self): self.mock_logger = mock.MagicMock(logging.Logger) self.mock_reporter = MockLibraryReportProcessor() self.create_cib = get_xml_manipulation_creator_from_file( rc("cib-empty.xml") )
def testStonithDeleteRemovesLevel(self): shutil.copy(rc("cib-empty-with3nodes.xml"), temp_cib) output, returnVal = pcs( temp_cib, "stonith create n1-ipmi fence_ilo --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n2-ipmi fence_ilo --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n1-apc1 fence_apc --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n1-apc2 fence_apc --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n2-apc1 fence_apc --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n2-apc2 fence_apc --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith create n2-apc3 fence_apc --force" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs(temp_cib, "stonith level add 1 rh7-1 n1-ipmi") ac(output, "") self.assertEqual(returnVal, 0) output, returnVal = pcs( temp_cib, "stonith level add 2 rh7-1 n1-apc1,n1-apc2,n2-apc2" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs(temp_cib, "stonith level add 1 rh7-2 n2-ipmi") self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs( temp_cib, "stonith level add 2 rh7-2 n2-apc1,n2-apc2,n2-apc3" ) self.assertEqual(returnVal, 0) ac(output, "") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped n1-apc1\t(stonith:fence_apc):\tStopped n1-apc2\t(stonith:fence_apc):\tStopped n2-apc1\t(stonith:fence_apc):\tStopped n2-apc2\t(stonith:fence_apc):\tStopped n2-apc3\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Level 2 - n1-apc1,n1-apc2,n2-apc2 Target: rh7-2 Level 1 - n2-ipmi Level 2 - n2-apc1,n2-apc2,n2-apc3 """) output, returnVal = pcs(temp_cib, "stonith delete n2-apc2") self.assertEqual(returnVal, 0) ac(output, "Deleting Resource - n2-apc2\n") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped n1-apc1\t(stonith:fence_apc):\tStopped n1-apc2\t(stonith:fence_apc):\tStopped n2-apc1\t(stonith:fence_apc):\tStopped n2-apc3\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Level 2 - n1-apc1,n1-apc2 Target: rh7-2 Level 1 - n2-ipmi Level 2 - n2-apc1,n2-apc3 """) output, returnVal = pcs(temp_cib, "stonith delete n2-apc1") self.assertEqual(returnVal, 0) ac(output, "Deleting Resource - n2-apc1\n") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped n1-apc1\t(stonith:fence_apc):\tStopped n1-apc2\t(stonith:fence_apc):\tStopped n2-apc3\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Level 2 - n1-apc1,n1-apc2 Target: rh7-2 Level 1 - n2-ipmi Level 2 - n2-apc3 """) output, returnVal = pcs(temp_cib, "stonith delete n2-apc3") self.assertEqual(returnVal, 0) ac(output, "Deleting Resource - n2-apc3\n") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped n1-apc1\t(stonith:fence_apc):\tStopped n1-apc2\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Level 2 - n1-apc1,n1-apc2 Target: rh7-2 Level 1 - n2-ipmi """) output, returnVal = pcs(temp_cib, "resource delete n1-apc1") self.assertEqual(returnVal, 0) ac(output, "Deleting Resource - n1-apc1\n") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped n1-apc2\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Level 2 - n1-apc2 Target: rh7-2 Level 1 - n2-ipmi """) output, returnVal = pcs(temp_cib, "resource delete n1-apc2") self.assertEqual(returnVal, 0) ac(output, "Deleting Resource - n1-apc2\n") output, returnVal = pcs(temp_cib, "stonith") self.assertEqual(returnVal, 0) ac(output, """\ n1-ipmi\t(stonith:fence_ilo):\tStopped n2-ipmi\t(stonith:fence_ilo):\tStopped Target: rh7-1 Level 1 - n1-ipmi Target: rh7-2 Level 1 - n2-ipmi """)
division, print_function, unicode_literals, ) import os.path from pcs.test.tools.misc import get_test_resource as rc from pcs import utils __pcs_location = os.path.join( os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "pcs" ) _temp_cib = rc("temp-cib.xml") class PcsRunner(object): def __init__( self, cib_file=_temp_cib, corosync_conf_file=None, cluster_conf_file=None ): self.cib_file = cib_file self.corosync_conf_file = ( rc("corosync.conf") if corosync_conf_file is None else corosync_conf_file ) self.cluster_conf_file = ( rc("cluster.conf") if cluster_conf_file is None else cluster_conf_file )