Change in vdsm[master]: exception: Make VdsmException reusable

nsoffer at redhat.com nsoffer at redhat.com
Fri Nov 20 22:32:25 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: exception: Make VdsmException reusable
......................................................................

exception: Make VdsmException reusable

VdsmException was initializing code and message to default values if
called without arguments. This make is useless as as base class for
more specific exceptions, defining real code and message.

GlusterException, the only exception inheriting from VdsmException,
avoided this issue by overriding __init__.

Change-Id: Icd6643d9670cb9b067e372bf5a1a6c57ced41954
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/exception.py
M tests/Makefile.am
A tests/exception_test.py
3 files changed, 52 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/75/48875/1

diff --git a/lib/vdsm/exception.py b/lib/vdsm/exception.py
index 98038e3..f81768d 100644
--- a/lib/vdsm/exception.py
+++ b/lib/vdsm/exception.py
@@ -24,10 +24,6 @@
     code = 0
     message = "Vdsm Exception"
 
-    def __init__(self, code=0, message='Vdsm Exception'):
-        self.code = code
-        self.message = message
-
     def __str__(self):
         return self.message
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5372034..602bd9a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,7 @@
 	deviceTests.py \
 	domainDescriptorTests.py \
 	encodingTests.py \
+	exception_test.py \
 	executorTests.py \
 	fileSDTests.py \
 	fileVolumeTests.py \
diff --git a/tests/exception_test.py b/tests/exception_test.py
new file mode 100644
index 0000000..3d8058f
--- /dev/null
+++ b/tests/exception_test.py
@@ -0,0 +1,51 @@
+#
+# Copyright 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from testlib import VdsmTestCase
+from vdsm.exception import VdsmException
+
+
+class SubExceptiong(VdsmException):
+    code = 42
+    message = "message"
+
+
+class TestVdsmException(VdsmTestCase):
+
+    def test_str(self):
+        e = VdsmException()
+        self.assertEqual(str(e), e.message)
+
+    def test_response(self):
+        e = VdsmException()
+        self.assertEqual(e.response(),
+                         {"status": {"code": 0, "message": "Vdsm Exception"}})
+
+
+class TestSubException(VdsmTestCase):
+
+    def test_str(self):
+        e = SubExceptiong()
+        self.assertEqual(str(e), "message")
+
+    def test_response(self):
+        e = SubExceptiong()
+        self.assertEqual(e.response(),
+                         {"status": {"code": 42, "message": "message"}})


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd6643d9670cb9b067e372bf5a1a6c57ced41954
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list