]> sourceware.org Git - lvm2.git/commitdiff
lvmdbusd: Remove duplicate error handling code
authorTony Asleson <tasleson@redhat.com>
Tue, 1 Oct 2019 20:17:30 +0000 (15:17 -0500)
committerTony Asleson <tasleson@redhat.com>
Wed, 30 Oct 2019 15:38:40 +0000 (10:38 -0500)
vg, lv, pv code had the same function for handling command execution.
Move to utility function and abstract the difference.

daemons/lvmdbusd/lv.py
daemons/lvmdbusd/pv.py
daemons/lvmdbusd/utils.py
daemons/lvmdbusd/vg.py

index c0029b85c42535a914101a2da81a36ce271ff268..f65e7da12d05abb21dececb075c52f73ea62f137 100644 (file)
@@ -10,7 +10,7 @@
 from .automatedproperties import AutomatedProperties
 
 from . import utils
-from .utils import vg_obj_path_generate, log_error
+from .utils import vg_obj_path_generate, log_error, _handle_execute
 import dbus
 from . import cmdhandler
 from . import cfg
@@ -275,13 +275,7 @@ class LvCommon(AutomatedProperties):
 
        @staticmethod
        def handle_execute(rc, out, err):
-               if rc == 0:
-                       cfg.load()
-               else:
-                       # Need to work on error handling, need consistent
-                       raise dbus.exceptions.DBusException(
-                               LV_INTERFACE,
-                               'Exit code %s, stderr = %s' % (str(rc), err))
+               _handle_execute(rc, out, err, LV_INTERFACE)
 
        @staticmethod
        def validate_dbus_object(lv_uuid, lv_name):
index e5f8b9d38ec9bfd190c584da9879b59e8f971177..9c0f1b23751d60845b9b49cc2ae89d0ad07e9ed7 100644 (file)
@@ -14,7 +14,7 @@ import dbus
 from .cfg import PV_INTERFACE
 from . import cmdhandler
 from .utils import vg_obj_path_generate, n, pv_obj_path_generate, \
-       lv_object_path_method
+       lv_object_path_method, _handle_execute
 from .loader import common
 from .request import RequestEntry
 from .state import State
@@ -144,13 +144,7 @@ class Pv(AutomatedProperties):
 
        @staticmethod
        def handle_execute(rc, out, err):
-               if rc == 0:
-                       cfg.load()
-               else:
-                       # Need to work on error handling, need consistent
-                       raise dbus.exceptions.DBusException(
-                               PV_INTERFACE,
-                               'Exit code %s, stderr = %s' % (str(rc), err))
+               return _handle_execute(rc, out, err, PV_INTERFACE)
 
        @staticmethod
        def validate_dbus_object(pv_uuid, pv_name):
index 3c006c48c6d7ee6a96b8b3b65ecf7bb11ab872ae..8d64117b9620a72d062c8c6d87e5d7c9c62fc193 100644 (file)
@@ -26,6 +26,15 @@ import signal
 STDOUT_TTY = os.isatty(sys.stdout.fileno())
 
 
+def _handle_execute(rc, out, err, interface):
+       if rc == 0:
+               cfg.load()
+       else:
+               # Need to work on error handling, need consistent
+               raise dbus.exceptions.DBusException(
+                       interface, 'Exit code %s, stderr = %s' % (str(rc), err))
+
+
 def rtype(dbus_type):
        """
        Decorator making sure that the decorated function returns a value of
index 7011ff899f3b48c658bccdf5a08290011dd70ff5..cfcc53b2213d10a30c69c077e0bbb78c237b2e03 100644 (file)
@@ -10,7 +10,8 @@
 from .automatedproperties import AutomatedProperties
 
 from . import utils
-from .utils import pv_obj_path_generate, vg_obj_path_generate, n
+from .utils import pv_obj_path_generate, vg_obj_path_generate, n, \
+       _handle_execute
 import dbus
 from . import cfg
 from .cfg import VG_INTERFACE
@@ -154,13 +155,7 @@ class Vg(AutomatedProperties):
 
        @staticmethod
        def handle_execute(rc, out, err):
-               if rc == 0:
-                       cfg.load()
-               else:
-                       # Need to work on error handling, need consistent
-                       raise dbus.exceptions.DBusException(
-                               VG_INTERFACE,
-                               'Exit code %s, stderr = %s' % (str(rc), err))
+               return _handle_execute(rc, out, err, VG_INTERFACE)
 
        @staticmethod
        def validate_dbus_object(vg_uuid, vg_name):
This page took 0.044315 seconds and 5 git commands to generate.