Francesco Romani has uploaded a new change for review. Change subject: janitorial: use the response module in vmpowerdown ......................................................................
janitorial: use the response module in vmpowerdown This patch makes vmpowerdown.py use the response module. Change-Id: I314d4b15eb6c6104cc7bb2e58ad07ca08d868c66 Signed-off-by: Francesco Romani <from...@redhat.com> --- M lib/vdsm/response.py M tests/responseTests.py M vdsm/virt/vmpowerdown.py 3 files changed, 15 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/45/38445/1 diff --git a/lib/vdsm/response.py b/lib/vdsm/response.py index bded95e..0984680 100644 --- a/lib/vdsm/response.py +++ b/lib/vdsm/response.py @@ -22,10 +22,10 @@ from vdsm.define import errCode -def success(**kwargs): +def success(message=None, **kwargs): kwargs["status"] = { "code": 0, - "message": "Done" + "message": message or "Done" } return kwargs diff --git a/tests/responseTests.py b/tests/responseTests.py index 3579b45..c806445 100644 --- a/tests/responseTests.py +++ b/tests/responseTests.py @@ -52,6 +52,14 @@ self.assertEqual(res, {"status": doneCode}) + def test_success_with_message(self): + MESSAGE = "the message was overwritten" + res = response.success(message=MESSAGE) + + template = doneCode + self.assertEqual(res["status"]["code"], template["code"]) + self.assertEqual(res["status"]["message"], MESSAGE) + def test_success_with_args(self): res = response.success(a=1, b=2) diff --git a/vdsm/virt/vmpowerdown.py b/vdsm/virt/vmpowerdown.py index 2382a88..aae927d 100644 --- a/vdsm/virt/vmpowerdown.py +++ b/vdsm/virt/vmpowerdown.py @@ -19,8 +19,8 @@ # import libvirt +from vdsm import response from vdsm import utils -from vdsm.define import doneCode, errCode class VmPowerDown(object): @@ -69,15 +69,12 @@ self.event.clear() self.chain.start() - return {'status': {'code': doneCode['code'], - 'message': self.returnMsg}} + return response.success(message=self.returnMsg) else: # No tools, no ACPI - return { - 'status': { - 'code': errCode['exist']['status']['code'], - 'message': 'VM without ACPI or active oVirt guest agent. ' - 'Try Forced Shutdown.'}} + return response.error('exist', + message='VM without ACPI or active oVirt ' + 'guest agent. Try Forced Shutdown.') class VmShutdown(VmPowerDown): -- To view, visit https://gerrit.ovirt.org/38445 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I314d4b15eb6c6104cc7bb2e58ad07ca08d868c66 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <from...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches