From 9fbeeed4e43dc37800de3c3f0cf6f7520dc31ccf Mon Sep 17 00:00:00 2001 From: Tomas Jelinek Date: Mon, 20 Jan 2020 12:34:55 +0100 Subject: [PATCH] tests: update for pacemaker-2.0.3-4 --- pcs_test/tier0/test_resource.py | 59 +++++++++++++------------- pcs_test/tier0/test_stonith.py | 75 +++++++++++++++++---------------- pcs_test/tools/assertions.py | 24 +++++++++-- 3 files changed, 88 insertions(+), 70 deletions(-) diff --git a/pcs_test/tier0/test_resource.py b/pcs_test/tier0/test_resource.py index b8b85dd2..45d98dff 100644 --- a/pcs_test/tier0/test_resource.py +++ b/pcs_test/tier0/test_resource.py @@ -10,6 +10,7 @@ from pcs_test.tier0.cib_resource.common import ResourceTest from pcs_test.tools.assertions import ( ac, AssertPcsMixin, + assert_pcs_status, ) from pcs_test.tools.bin_mock import get_mock_settings from pcs_test.tools.cib import get_assert_pcs_effect_mixin @@ -953,11 +954,11 @@ monitor interval=20 (A-monitor-interval-20) o,r = pcs(temp_cib, "resource status") assert r == 0 if PCMK_2_0_3_PLUS: - ac(o,"""\ + assert_pcs_status(o,"""\ * Resource Group: AGroup: - * A1\t(ocf::heartbeat:Dummy):\t Stopped - * A2\t(ocf::heartbeat:Dummy):\t Stopped - * A3\t(ocf::heartbeat:Dummy):\t Stopped + * A1\t(ocf::heartbeat:Dummy):\tStopped + * A2\t(ocf::heartbeat:Dummy):\tStopped + * A3\t(ocf::heartbeat:Dummy):\tStopped """) else: ac(o,"""\ @@ -1208,19 +1209,19 @@ monitor interval=20 (A-monitor-interval-20) output, returnVal = pcs(temp_cib, "resource") assert returnVal == 0 if PCMK_2_0_3_PLUS: - ac(output, """\ - * F\t(ocf::heartbeat:Dummy):\t Stopped - * G\t(ocf::heartbeat:Dummy):\t Stopped - * H\t(ocf::heartbeat:Dummy):\t Stopped + assert_pcs_status(output, """\ + * F\t(ocf::heartbeat:Dummy):\tStopped + * G\t(ocf::heartbeat:Dummy):\tStopped + * H\t(ocf::heartbeat:Dummy):\tStopped * Resource Group: RGA: - * A\t(ocf::heartbeat:Dummy):\t Stopped - * B\t(ocf::heartbeat:Dummy):\t Stopped - * C\t(ocf::heartbeat:Dummy):\t Stopped - * E\t(ocf::heartbeat:Dummy):\t Stopped - * D\t(ocf::heartbeat:Dummy):\t Stopped - * K\t(ocf::heartbeat:Dummy):\t Stopped - * J\t(ocf::heartbeat:Dummy):\t Stopped - * I\t(ocf::heartbeat:Dummy):\t Stopped + * A\t(ocf::heartbeat:Dummy):\tStopped + * B\t(ocf::heartbeat:Dummy):\tStopped + * C\t(ocf::heartbeat:Dummy):\tStopped + * E\t(ocf::heartbeat:Dummy):\tStopped + * D\t(ocf::heartbeat:Dummy):\tStopped + * K\t(ocf::heartbeat:Dummy):\tStopped + * J\t(ocf::heartbeat:Dummy):\tStopped + * I\t(ocf::heartbeat:Dummy):\tStopped """) else: ac(output, """\ @@ -2004,9 +2005,9 @@ monitor interval=20 (A-monitor-interval-20) o,r = pcs(temp_cib, "resource") if PCMK_2_0_3_PLUS: - ac(o,"""\ + assert_pcs_status(o,"""\ * Resource Group: AG: - * D1\t(ocf::heartbeat:Dummy):\t Stopped + * D1\t(ocf::heartbeat:Dummy):\tStopped * Clone Set: D0-clone [D0]: """) else: @@ -2348,10 +2349,10 @@ monitor interval=20 (A-monitor-interval-20) o,r = pcs(temp_cib, "resource status") assert r == 0 if PCMK_2_0_3_PLUS: - ac(o,"""\ + assert_pcs_status(o,"""\ * Resource Group: DGroup: - * D1\t(ocf::heartbeat:Dummy):\t Stopped - * D2\t(ocf::heartbeat:Dummy):\t Stopped + * D1\t(ocf::heartbeat:Dummy):\tStopped + * D2\t(ocf::heartbeat:Dummy):\tStopped """) else: ac(o,"""\ @@ -3560,12 +3561,12 @@ Error: role must be: Stopped, Started, Slave or Master (use --force to override) assert retVal == 0 output, retVal = pcs(temp_cib, "resource status") if PCMK_2_0_3_PLUS: - ac(output, outdent( + assert_pcs_status(output, outdent( """\ * Resource Group: dummies: - * dummy1\t(ocf::heartbeat:Dummy):\t Stopped - * dummy2\t(ocf::heartbeat:Dummy):\t Stopped - * dummy3\t(ocf::heartbeat:Dummy):\t Stopped + * dummy1\t(ocf::heartbeat:Dummy):\tStopped + * dummy2\t(ocf::heartbeat:Dummy):\tStopped + * dummy3\t(ocf::heartbeat:Dummy):\tStopped """ )) else: @@ -3652,12 +3653,12 @@ Error: role must be: Stopped, Started, Slave or Master (use --force to override) assert retVal == 0 output, retVal = pcs(temp_cib, "resource status") if PCMK_2_0_3_PLUS: - ac(output, outdent( + assert_pcs_status(output, outdent( """\ * Resource Group: dummies: - * dummy1\t(ocf::heartbeat:Dummy):\t Stopped - * dummy2\t(ocf::heartbeat:Dummy):\t Stopped - * dummy3\t(ocf::heartbeat:Dummy):\t Stopped + * dummy1\t(ocf::heartbeat:Dummy):\tStopped + * dummy2\t(ocf::heartbeat:Dummy):\tStopped + * dummy3\t(ocf::heartbeat:Dummy):\tStopped """ )) else: diff --git a/pcs_test/tier0/test_stonith.py b/pcs_test/tier0/test_stonith.py index 46938e75..097a79b9 100644 --- a/pcs_test/tier0/test_stonith.py +++ b/pcs_test/tier0/test_stonith.py @@ -517,13 +517,13 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped - * n1-apc1\t(stonith:fence_apc):\t Stopped - * n1-apc2\t(stonith:fence_apc):\t Stopped - * n2-apc1\t(stonith:fence_apc):\t Stopped - * n2-apc2\t(stonith:fence_apc):\t Stopped - * n2-apc3\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\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 @@ -531,7 +531,7 @@ class StonithTest(TestCase, AssertPcsMixin): Level 1 - n2-ipmi Level 2 - n2-apc1,n2-apc2,n2-apc3 """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -559,12 +559,12 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped - * n1-apc1\t(stonith:fence_apc):\t Stopped - * n1-apc2\t(stonith:fence_apc):\t Stopped - * n2-apc1\t(stonith:fence_apc):\t Stopped - * n2-apc3\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\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 @@ -572,7 +572,7 @@ class StonithTest(TestCase, AssertPcsMixin): Level 1 - n2-ipmi Level 2 - n2-apc1,n2-apc3 """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -599,11 +599,11 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped - * n1-apc1\t(stonith:fence_apc):\t Stopped - * n1-apc2\t(stonith:fence_apc):\t Stopped - * n2-apc3\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\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 @@ -611,7 +611,7 @@ class StonithTest(TestCase, AssertPcsMixin): Level 1 - n2-ipmi Level 2 - n2-apc3 """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -637,17 +637,17 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped - * n1-apc1\t(stonith:fence_apc):\t Stopped - * n1-apc2\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\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 """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -671,16 +671,16 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped - * n1-apc2\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\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 """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -704,14 +704,14 @@ class StonithTest(TestCase, AssertPcsMixin): if PCMK_2_0_3_PLUS: self.assert_pcs_success("stonith", outdent( """\ - * n1-ipmi\t(stonith:fence_apc):\t Stopped - * n2-ipmi\t(stonith:fence_apc):\t Stopped + * n1-ipmi\t(stonith:fence_apc):\tStopped + * n2-ipmi\t(stonith:fence_apc):\tStopped Target: rh7-1 Level 1 - n1-ipmi Target: rh7-2 Level 1 - n2-ipmi """ - )) + ), despace=True) else: self.assert_pcs_success("stonith", outdent( """\ @@ -1219,9 +1219,9 @@ class LevelConfig(LevelTestsBase): if PCMK_2_0_3_PLUS: result = outdent( """\ - * F1\t(stonith:fence_apc):\t Stopped - * F2\t(stonith:fence_apc):\t Stopped - * F3\t(stonith:fence_apc):\t Stopped + * F1\t(stonith:fence_apc):\tStopped + * F2\t(stonith:fence_apc):\tStopped + * F3\t(stonith:fence_apc):\tStopped """ ) else: @@ -1234,7 +1234,8 @@ class LevelConfig(LevelTestsBase): ) self.assert_pcs_success( "stonith", - result + "\n".join(indent(self.config_lines, 1)) + "\n" + result + "\n".join(indent(self.config_lines, 1)) + "\n", + despace=True ) self.pcs_runner.mock_settings["corosync_conf_file"] = rc( "corosync.conf" diff --git a/pcs_test/tools/assertions.py b/pcs_test/tools/assertions.py index db8f4df5..a2b7b4ac 100644 --- a/pcs_test/tools/assertions.py +++ b/pcs_test/tools/assertions.py @@ -59,7 +59,8 @@ class AssertPcsMixin: ) def assert_pcs_success( - self, command, stdout_full=None, stdout_start=None, stdout_regexp=None + self, command, stdout_full=None, stdout_start=None, stdout_regexp=None, + despace=False ): full = stdout_full if ( @@ -75,7 +76,8 @@ class AssertPcsMixin: stdout_full=full, stdout_start=stdout_start, stdout_regexp=stdout_regexp, - returncode=0 + returncode=0, + despace=despace, ) def assert_pcs_fail( @@ -99,7 +101,7 @@ class AssertPcsMixin: def assert_pcs_result( self, command, stdout_full=None, stdout_start=None, stdout_regexp=None, - returncode=0 + returncode=0, despace=False ): msg = ( "Please specify exactly one: stdout_start or stdout_full or" @@ -162,7 +164,11 @@ class AssertPcsMixin: ) else: expected_full = self.__prepare_output(stdout_full) - if stdout != expected_full: + if ( + (despace and _despace(stdout) != _despace(expected_full)) + or + (not despace and stdout != expected_full) + ): self.assertEqual( stdout, expected_full, @@ -386,3 +392,13 @@ def __report_item_equal(real_report_item, report_item_info): ) ) ) + +def assert_pcs_status(status1, status2): + if _despace(status1) != _despace(status2): + raise AssertionError( + "strings not equal:\n{0}".format(prepare_diff(status1, status2)) + ) + +def _despace(string): + # ignore whitespace changes between various pacemaker versions + return re.sub(r"[ \t]+", " ", string) -- 2.20.1