Skip to content

Commit

Permalink
fix simulate_cib_error report
Browse files Browse the repository at this point in the history
Putting only one CIB in the report is not enough info. Both original and
changed CIB as well as crm_simulate output would be needed. All that
info can be seen in debug messages. So there is no need to put it in the
report.
  • Loading branch information
tomjelinek authored and ondrejmular committed Dec 13, 2019
1 parent e36dd29 commit 731cb69
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
7 changes: 5 additions & 2 deletions pcs/cli/common/console_report.py
Expand Up @@ -816,8 +816,11 @@ def joined_list(item_list, optional_transformations=None):
,

codes.CIB_SIMULATE_ERROR: lambda info:
"Unable to simulate changes in CIB: {reason}\n{cib}"
.format(**info)
"Unable to simulate changes in CIB{_reason}"
.format(
_reason=format_optional(info["reason"], ": {0}"),
**info
)
,

codes.CIB_PUSH_FORCED_FULL_DUE_TO_CRM_FEATURE_SET: lambda info:
Expand Down
10 changes: 8 additions & 2 deletions pcs/cli/common/test/test_console_report.py
Expand Up @@ -1938,8 +1938,14 @@ class CibSimulateError(NameBuildTest):
code = codes.CIB_SIMULATE_ERROR
def test_success(self):
self.assert_message_from_report(
"Unable to simulate changes in CIB: error message\n<cib />",
reports.cib_simulate_error("error message", "<cib />")
"Unable to simulate changes in CIB: error message",
reports.cib_simulate_error("error message")
)

def test_empty_reason(self):
self.assert_message_from_report(
"Unable to simulate changes in CIB",
reports.cib_simulate_error("")
)


Expand Down
12 changes: 0 additions & 12 deletions pcs/lib/commands/test/resource/test_resource_enable_disable.py
Expand Up @@ -1732,12 +1732,6 @@ def test_simulate_error(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some stderr",
# curently, there is no way to normalize xml with our lxml
# version 4.2.3, so this never passes equality tests
# cib=self.config.calls.get(
# "runner.pcmk.simulate_cib"
# ).check_stdin.expected_stdin
# ,
),
],
expected_in_processor=False
Expand Down Expand Up @@ -1991,12 +1985,6 @@ def test_simulate_error(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some stderr",
# curently, there is no way to normalize xml with our lxml
# version 4.2.3, so this never passes equality tests
# cib=self.config.calls.get(
# "runner.pcmk.simulate_cib"
# ).check_stdin.expected_stdin
# ,
),
],
expected_in_processor=False
Expand Down
8 changes: 4 additions & 4 deletions pcs/lib/pacemaker/live.py
Expand Up @@ -218,7 +218,7 @@ def simulate_cib_xml(runner, cib_xml):
transitions_file = write_tmpfile(None)
except EnvironmentError as e:
raise LibraryError(
reports.cib_simulate_error(format_environment_error(e), cib_xml)
reports.cib_simulate_error(format_environment_error(e))
)

cmd = [
Expand All @@ -231,7 +231,7 @@ def simulate_cib_xml(runner, cib_xml):
stdout, stderr, retval = runner.run(cmd, stdin_string=cib_xml)
if retval != 0:
raise LibraryError(
reports.cib_simulate_error(stderr.strip(), cib_xml)
reports.cib_simulate_error(stderr.strip())
)

try:
Expand All @@ -244,7 +244,7 @@ def simulate_cib_xml(runner, cib_xml):
return stdout, transitions_xml, new_cib_xml
except EnvironmentError as e:
raise LibraryError(
reports.cib_simulate_error(format_environment_error(e), cib_xml)
reports.cib_simulate_error(format_environment_error(e))
)

def simulate_cib(runner, cib):
Expand All @@ -266,7 +266,7 @@ def simulate_cib(runner, cib):
)
except (etree.XMLSyntaxError, etree.DocumentInvalid) as e:
raise LibraryError(
reports.cib_simulate_error(str(e), cib_xml)
reports.cib_simulate_error(str(e))
)

### wait for idle
Expand Down
7 changes: 0 additions & 7 deletions pcs/lib/pacemaker/test/test_live.py
Expand Up @@ -480,7 +480,6 @@ def test_error_creating_cib(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some error",
cib="<cib />",
),
)
mock_runner.run.assert_not_called()
Expand All @@ -497,7 +496,6 @@ def test_error_creating_transitions(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some error",
cib="<cib />",
),
)
mock_runner.run.assert_not_called()
Expand All @@ -523,7 +521,6 @@ def test_error_running_simulate(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some error",
cib="<cib />",
),
)

Expand All @@ -549,7 +546,6 @@ def test_error_reading_cib(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some error",
cib="<cib />",
),
)

Expand All @@ -576,7 +572,6 @@ def test_error_reading_transitions(self, mock_write_tmpfile):
fixture.error(
report_codes.CIB_SIMULATE_ERROR,
reason="some error",
cib="<cib />",
),
)

Expand Down Expand Up @@ -612,7 +607,6 @@ def test_invalid_cib(self, mock_simulate):
reason=(
"Start tag expected, '<' not found, line 1, column 1"
),
cib=self.cib_xml,
),
)

Expand All @@ -627,7 +621,6 @@ def test_invalid_transitions(self, mock_simulate):
reason=(
"Start tag expected, '<' not found, line 1, column 1"
),
cib=self.cib_xml,
),
)

Expand Down
4 changes: 1 addition & 3 deletions pcs/lib/reports.py
Expand Up @@ -1406,18 +1406,16 @@ def cib_diff_error(reason, cib_old, cib_new):
}
)

def cib_simulate_error(reason, cib):
def cib_simulate_error(reason):
"""
cannot simulate effects a CIB would have on a live cluster
string reason -- error description
string cib -- the CIB whose effects were to be simulated
"""
return ReportItem.error(
report_codes.CIB_SIMULATE_ERROR,
info={
"reason": reason,
"cib": cib,
}
)

Expand Down

0 comments on commit 731cb69

Please sign in to comment.