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

Christy Perez christy at linux.vnet.ibm.com
Thu Nov 20 14:56:20 UTC 2014


Reviewed-By: Christy Perez <christy at linux.vnet.ibm.com>

On 11/19/2014 06:08 PM, Crístian Viana wrote:
> 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'}
> 




More information about the Kimchi-devel mailing list