1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

lvmdbusd: Remove duplicate error handling code

vg, lv, pv code had the same function for handling command execution.
Move to utility function and abstract the difference.
This commit is contained in:
Tony Asleson 2019-10-01 15:17:30 -05:00
parent 25e7bf021a
commit df38eb49ab
4 changed files with 16 additions and 24 deletions

View File

@ -10,7 +10,7 @@
from .automatedproperties import AutomatedProperties from .automatedproperties import AutomatedProperties
from . import utils 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 import dbus
from . import cmdhandler from . import cmdhandler
from . import cfg from . import cfg
@ -275,13 +275,7 @@ class LvCommon(AutomatedProperties):
@staticmethod @staticmethod
def handle_execute(rc, out, err): def handle_execute(rc, out, err):
if rc == 0: _handle_execute(rc, out, err, LV_INTERFACE)
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))
@staticmethod @staticmethod
def validate_dbus_object(lv_uuid, lv_name): def validate_dbus_object(lv_uuid, lv_name):

View File

@ -14,7 +14,7 @@ import dbus
from .cfg import PV_INTERFACE from .cfg import PV_INTERFACE
from . import cmdhandler from . import cmdhandler
from .utils import vg_obj_path_generate, n, pv_obj_path_generate, \ 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 .loader import common
from .request import RequestEntry from .request import RequestEntry
from .state import State from .state import State
@ -144,13 +144,7 @@ class Pv(AutomatedProperties):
@staticmethod @staticmethod
def handle_execute(rc, out, err): def handle_execute(rc, out, err):
if rc == 0: return _handle_execute(rc, out, err, PV_INTERFACE)
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))
@staticmethod @staticmethod
def validate_dbus_object(pv_uuid, pv_name): def validate_dbus_object(pv_uuid, pv_name):

View File

@ -26,6 +26,15 @@ import signal
STDOUT_TTY = os.isatty(sys.stdout.fileno()) 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): def rtype(dbus_type):
""" """
Decorator making sure that the decorated function returns a value of Decorator making sure that the decorated function returns a value of

View File

@ -10,7 +10,8 @@
from .automatedproperties import AutomatedProperties from .automatedproperties import AutomatedProperties
from . import utils 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 import dbus
from . import cfg from . import cfg
from .cfg import VG_INTERFACE from .cfg import VG_INTERFACE
@ -154,13 +155,7 @@ class Vg(AutomatedProperties):
@staticmethod @staticmethod
def handle_execute(rc, out, err): def handle_execute(rc, out, err):
if rc == 0: return _handle_execute(rc, out, err, VG_INTERFACE)
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))
@staticmethod @staticmethod
def validate_dbus_object(vg_uuid, vg_name): def validate_dbus_object(vg_uuid, vg_name):