The function "_mock_vmsnapshot_lookup" doesn't handle the case when the
provided snapshot name doesn't exist. In that case, it returns None.
Fix the function mentioned above so when the provided snapshot name
doesn't exist, a proper exception is raised.
Signed-off-by: CrÃstian Deives <cristiandeives(a)gmail.com>
---
src/kimchi/mockmodel.py | 3 +++
tests/test_rest.py | 4 ++++
2 files changed, 7 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 413ac5d..dcb8bc1 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -31,6 +31,7 @@ from lxml.builder import E
from kimchi import config
from kimchi import imageinfo
from kimchi import osinfo
+from kimchi.exception import NotFoundError
from kimchi.model.debugreports import DebugReportsModel
from kimchi.model.host import DeviceModel
from kimchi.model.libvirtstoragepool import IscsiPoolDef, NetfsPoolDef
@@ -419,6 +420,8 @@ class MockModel(Model):
if sn.name == name:
return sn.info
+ raise NotFoundError('KCHSNAP0003E', {'name': name, 'vm':
vm_name})
+
def _mock_vmsnapshot_delete(self, vm_name, name):
snapshots = MockModel._mock_snapshots.get(vm_name, [])
for sn in snapshots:
diff --git a/tests/test_rest.py b/tests/test_rest.py
index ee350b2..c1b81e8 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -334,6 +334,10 @@ class RestTests(unittest.TestCase):
task = json.loads(self.request('/tasks/%s' % task['id']).read())
self.assertEquals('finished', task['status'])
+ # Look up a non-existing snapshot
+ resp = self.request('/vms/test-vm/snapshots/snap404', '{}',
'GET')
+ self.assertEquals(404, resp.status)
+
# Look up a snapshot
resp = self.request('/vms/test-vm/snapshots/%s' % params['name'],
'{}',
'GET')
--
2.1.0