Martin Sivák has uploaded a new change for review. Change subject: Fix an error when the brokerlink's return value has no data ......................................................................
Fix an error when the brokerlink's return value has no data This could happen during setup or the first execution of included daemons. The metadata file was present, but nobody has reported anything yet. Change-Id: I0f1e96595ca07c20bae6fba805ae2bc4ba3e5151 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1075126 Signed-off-by: Martin Sivak <[email protected]> (cherry picked from commit 8e54f5e09c35a6202d7eb549238a2b39acebbd1f) --- M ovirt_hosted_engine_ha/lib/brokerlink.py A ovirt_hosted_engine_ha/lib/brokerlink_test.py 2 files changed, 40 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha refs/changes/25/25825/1 diff --git a/ovirt_hosted_engine_ha/lib/brokerlink.py b/ovirt_hosted_engine_ha/lib/brokerlink.py index b197d87..9a3e41b 100644 --- a/ovirt_hosted_engine_ha/lib/brokerlink.py +++ b/ovirt_hosted_engine_ha/lib/brokerlink.py @@ -185,17 +185,18 @@ On success, returns the result without the "success" prefix. """ response = self._communicate(request) - parts = response.split(" ", 1) - if len(parts) > 1 and parts[0] == "success": + try: + status, message = response.split(" ", 1) + except ValueError: + status, message = response, "" + + if status == "success": self._log.debug("Successful response from socket") - return parts[1] + return message else: self._log.debug("Failed response from socket") - if len(parts) > 1: - msg = parts[1] - else: - msg = response - raise RequestError("Request failed: {0}".format(msg)) + raise RequestError("Request failed: {0}" + .format(message or response)) def _communicate(self, request): """ diff --git a/ovirt_hosted_engine_ha/lib/brokerlink_test.py b/ovirt_hosted_engine_ha/lib/brokerlink_test.py new file mode 100644 index 0000000..0ce137c --- /dev/null +++ b/ovirt_hosted_engine_ha/lib/brokerlink_test.py @@ -0,0 +1,31 @@ +import brokerlink +import unittest + + +class BrokerlinkTests(unittest.TestCase): + def test_checked_communicate_no_data(self): + """ + rhbz#1075126 + """ + b = brokerlink.BrokerLink() + b._communicate = lambda req: "success" + ret = b._checked_communicate("dummy request") + self.assertEqual("", ret) + + def test_checked_communicate_fail_no_data(self): + b = brokerlink.BrokerLink() + b._communicate = lambda req: "failure" + self.assertRaises(brokerlink.RequestError, + b._checked_communicate, "dummy request") + + def test_checked_communicate_fail_data(self): + b = brokerlink.BrokerLink() + b._communicate = lambda req: "failure data" + self.assertRaises(brokerlink.RequestError, + b._checked_communicate, "dummy request") + + def test_checked_communicate_data(self): + b = brokerlink.BrokerLink() + b._communicate = lambda req: "success data" + ret = b._checked_communicate("dummy request") + self.assertEqual("data", ret) -- To view, visit http://gerrit.ovirt.org/25825 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f1e96595ca07c20bae6fba805ae2bc4ba3e5151 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-ha Gerrit-Branch: ovirt-hosted-engine-ha-1.1 Gerrit-Owner: Martin Sivák <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
