[Kimchi-devel] [PATCH] Return empty dict when VM doesn't have current snasphot

Crístian Viana vianac at linux.vnet.ibm.com
Thu Nov 20 00:08:17 UTC 2014


The current API design is to return an error 404 when a current snapshot
doesn't exist on a virtual machine. But it was decided that the best
approach is to return an empty structure instead.

Return an empty dict instead of raising an error when a VM doesn't have
a current snapshot. Also, update the tests accordingly.

Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
 src/kimchi/model/vmsnapshots.py | 2 +-
 tests/test_model.py             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/model/vmsnapshots.py b/src/kimchi/model/vmsnapshots.py
index ad8460e..0da9dc3 100644
--- a/src/kimchi/model/vmsnapshots.py
+++ b/src/kimchi/model/vmsnapshots.py
@@ -177,7 +177,7 @@ class CurrentVMSnapshotModel(object):
             snap_name = vir_snap.getName().decode('utf-8')
         except libvirt.libvirtError, e:
             if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN_SNAPSHOT:
-                raise NotFoundError('KCHSNAP0007E', {'vm': vm_name})
+                return {}
 
             raise OperationFailed('KCHSNAP0008E',
                                   {'vm': vm_name, 'err': e.message})
diff --git a/tests/test_model.py b/tests/test_model.py
index c68b01f..0681be9 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -124,8 +124,8 @@ class ModelTests(unittest.TestCase):
             inst.vm_poweroff(u'kimchi-vm')
             vm = inst.vm_lookup(u'kimchi-vm')
 
-            self.assertRaises(NotFoundError, inst.currentvmsnapshot_lookup,
-                              u'kimchi-vm')
+            empty_snap = inst.currentvmsnapshot_lookup(u'kimchi-vm')
+            self.assertEquals({}, empty_snap)
 
             # this snapshot should be deleted when its VM is deleted
             params = {'name': u'mysnap'}
-- 
1.9.3




More information about the Kimchi-devel mailing list