Nir Soffer has uploaded a new change for review.

Change subject: exception: Add an exception for vdsm.define errors
......................................................................

exception: Add an exception for vdsm.define errors

Add an exception class for each error in vdsm.define.

The long term goal is simplifying error handling, so code can raise
error in whatever layer the error happened, and single error handler
will generate the response using the error response() method.

As a temporary step, define.errCode is using the new exceptions to build
the response dict. When callers are updated to raise the new exceptions,
we can drop the errCode dict and the define module.

Unfinished - only the first exceptions created, posting for initial
review.

Change-Id: I01b736c06414a3af758ad6bdabddb6c25b620756
Signed-off-by: Nir Soffer <[email protected]>
---
M lib/vdsm/define.py
M lib/vdsm/exception.py
2 files changed, 54 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/71/48871/3

diff --git a/lib/vdsm/define.py b/lib/vdsm/define.py
index 0943939..f4b13a2 100644
--- a/lib/vdsm/define.py
+++ b/lib/vdsm/define.py
@@ -19,31 +19,18 @@
 #
 
 from __future__ import absolute_import
+from . import exception
+
+# TODO: Drop after callers changed to raise the exceptions
 errCode = {
-    'noVM': {'status': {
-        'code': 1,
-        'message': 'Virtual machine does not exist'}},
-    'nfsErr': {'status': {
-        'code': 3,
-        'message': 'Image repository access timeout'}},
-    'exist': {'status': {
-        'code': 4,
-        'message': 'Virtual machine already exists'}},
-    'noVmType': {'status': {
-        'code': 5,
-        'message': 'Unsupported VM type'}},
-    'down': {'status': {
-        'code': 6,
-        'message': 'Virtual machine is down'}},
-    'copyerr': {'status': {
-        'code': 7,
-        'message': 'Copy failed'}},
-    'sparse': {'status': {
-        'code': 8,
-        'message': 'sparse creation faild'}},
-    'createErr': {'status': {
-        'code': 9,
-        'message': 'Error creating the requested VM'}},
+    'noVM': exception.NoSuchVM().response(),
+    'nfsErr': exception.AccessTimeout().response(),
+    'exist': exception.VMExists().response(),
+    'noVmType': exception.UnsupportedVMType().response(),
+    'down': exception.VMIsDown().response(),
+    'copyerr': exception.CopyFailed().response(),
+    'sparse': exception.CannotCreateSparse().response(),
+    'createErr': exception.CannotCreateVM().response(),
     'noConPeer': {'status': {
         'code': 10,
         'message': 'Could not connect to peer VDS'}},
diff --git a/lib/vdsm/exception.py b/lib/vdsm/exception.py
index ae8e518..fa19101 100644
--- a/lib/vdsm/exception.py
+++ b/lib/vdsm/exception.py
@@ -35,6 +35,49 @@
         return {'status': {'code': self.code, 'message': str(self)}}
 
 
+class NoSuchVM(VdsmException):
+    code = 1
+    message = 'Virtual machine does not exist'
+
+
+# TODO: check if we can reuse code=2
+
+
+class AccessTimeout(VdsmException):
+    code = 3
+    message = 'Image repository access timeout'
+
+
+class VMExists(VdsmException):
+    code = 4
+    message = 'Virtual machine already exists'
+
+
+class UnsupportedVMType(VdsmException):
+    code = 5
+    message = 'Unsupported VM type'
+
+
+class VMIsDown(VdsmException):
+    code = 6
+    message = 'Virtual machine is down'
+
+
+class CopyFailed(VdsmException):
+    code = 7
+    message = 'Copy failed'
+
+
+class CannotCreateSparse(VdsmException):
+    code = 8
+    message = 'Sparse creation faild'
+
+
+class CannotCreateVM(VdsmException):
+    code = 9
+    message = 'Error creating the requested VM'
+
+
 class GeneralException(VdsmException):
     code = 100
     message = "General Exception"


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I01b736c06414a3af758ad6bdabddb6c25b620756
Gerrit-PatchSet: 3
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
Gerrit-Reviewer: gerrit-hooks <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to