Enhance error messages in zypperpkg module

Enhance capture of error messages for Zypper calls in zypperpkg module.
This commit is contained in:
Yeray Gutiérrez Cedrés 2022-07-22 11:18:06 +01:00 committed by Megan Wilhite
parent 2c8088f005
commit 6312d20b4f
2 changed files with 11 additions and 1 deletions

View file

@ -294,6 +294,10 @@ class _Zypper:
self.__call_result["stderr"]
and self.__call_result["stderr"].strip()
or ""
) or (
self.__call_result["stdout"]
and self.__call_result["stdout"].strip()
or ""
)
if msg:
_error_msg.append(msg)

View file

@ -203,11 +203,17 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
):
zypper.__zypper__.xml.call("crashme")
output_to_user = "Output to user"
sniffer = RunSniffer(stdout=output_to_user, retcode=1)
with patch.dict("salt.modules.zypperpkg.__salt__", {"cmd.run_all": sniffer}):
with self.assertRaisesRegex(
CommandExecutionError, "^Zypper command failure: Check Zypper's logs.$"
CommandExecutionError,
"^Zypper command failure: {}$".format(output_to_user),
):
zypper.__zypper__.call("crashme again")
sniffer = RunSniffer(retcode=1)
with patch.dict("salt.modules.zypperpkg.__salt__", {"cmd.run_all": sniffer}):
zypper.__zypper__.noraise.call("stay quiet")
self.assertEqual(zypper.__zypper__.error_msg, "Check Zypper's logs.")