Hello Dan Kenigsberg, Milan Zamazal,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/49017

to review the following change.

Change subject: vm: more robust support of event strings
......................................................................

vm: more robust support of event strings

Make vm.eventToString() more robust in presence
of unexpected data, like libvirt events we don't support yet.

Change-Id: Iae41085c49a76ad568ebfbfafe711fd7619f0421
Related-To: https://bugzilla.redhat.com/1273891
Backport-To: 3.6
Bug-Url: https://bugzilla.redhat.com/1284564
Signed-off-by: Francesco Romani <from...@redhat.com>
Reviewed-on: https://gerrit.ovirt.org/48517
Reviewed-by: Milan Zamazal <mzama...@redhat.com>
Reviewed-by: Dan Kenigsberg <dan...@redhat.com>
Continuous-Integration: Jenkins CI
---
M tests/vmUtilsTests.py
M vdsm/virt/vm.py
2 files changed, 13 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/17/49017/1

diff --git a/tests/vmUtilsTests.py b/tests/vmUtilsTests.py
index 53c4436..a4e4534 100644
--- a/tests/vmUtilsTests.py
+++ b/tests/vmUtilsTests.py
@@ -22,6 +22,7 @@
 from virt import vm
 from virt import vmexitreason
 
+from testlib import permutations, expandPermutations
 from testlib import VdsmTestCase as TestCaseBase
 
 
@@ -142,3 +143,11 @@
                 str(e),
                 vmexitreason.exitReasons.get(
                     vmexitreason.LIBVIRT_DOMAIN_MISSING))
+
+
+@expandPermutations
+class LibvirtEventDispatchTests(TestCaseBase):
+
+    @permutations([[-1], [1023]])
+    def test_eventToString_unknown_event(self, code):
+        self.assertTrue(vm.eventToString(code))
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index b3aebc3..b75215c 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -172,7 +172,10 @@
 
 
 def eventToString(event):
-    return _EVENT_STRINGS[event]
+    try:
+        return _EVENT_STRINGS[event]
+    except IndexError:
+        return "Unknown (%i)" % event
 
 
 class SetLinkAndNetworkError(Exception):


-- 
To view, visit https://gerrit.ovirt.org/49017
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae41085c49a76ad568ebfbfafe711fd7619f0421
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Francesco Romani <from...@redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <dan...@redhat.com>
Gerrit-Reviewer: Milan Zamazal <mzama...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to