diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py index 5815031ec..877f17cdb 100644 --- a/daemons/lvmdbusd/cmdhandler.py +++ b/daemons/lvmdbusd/cmdhandler.py @@ -126,11 +126,13 @@ def _shell_cfg(): lvm_shell = LVMShellProxy() _t_call = lvm_shell.call_lvm cfg.SHELL_IN_USE = lvm_shell + return True except Exception: _t_call = call_lvm cfg.SHELL_IN_USE = None log_error(traceback.format_exc()) log_error("Unable to utilize lvm shell, dropping back to fork & exec") + return False def set_execution(shell): @@ -139,7 +141,7 @@ def set_execution(shell): # If the user requested lvm shell and we are currently setup that # way, just return if cfg.SHELL_IN_USE and shell: - return + return True else: if not shell and cfg.SHELL_IN_USE: cfg.SHELL_IN_USE.exit_shell() @@ -147,7 +149,11 @@ def set_execution(shell): _t_call = call_lvm if shell: - _shell_cfg() + if cfg.args.use_json: + return _shell_cfg() + else: + return False + return True def time_wrapper(command, debug=False): diff --git a/daemons/lvmdbusd/lvmdb.py b/daemons/lvmdbusd/lvmdb.py index 2dc593bcb..187a930d9 100755 --- a/daemons/lvmdbusd/lvmdb.py +++ b/daemons/lvmdbusd/lvmdb.py @@ -24,7 +24,7 @@ except SystemError: class DataStore(object): - def __init__(self, usejson=None): + def __init__(self, usejson=True): self.pvs = {} self.vgs = {} self.lvs = {} @@ -42,7 +42,7 @@ class DataStore(object): # self.refresh() self.num_refreshes = 0 - if usejson is None: + if usejson: self.json = cmdhandler.supports_json() else: self.json = usejson diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py index d76b5c32b..5cf522df0 100644 --- a/daemons/lvmdbusd/main.py +++ b/daemons/lvmdbusd/main.py @@ -25,9 +25,10 @@ from .background import background_reaper import traceback import queue from . import udevwatch -from .utils import log_debug +from .utils import log_debug, log_error import argparse import os +import sys from .refresh import handle_external_event, event_complete @@ -102,10 +103,12 @@ def main(): help="Dump debug messages", default=False, dest='debug') parser.add_argument("--nojson", action='store_false', - help="Do not use LVM JSON output", default=None, + help="Do not use LVM JSON output (Note: This " + "does not work with --lvmshell", default=True, dest='use_json') parser.add_argument("--lvmshell", action='store_true', - help="Use the lvm shell, not fork & exec lvm", default=False, + help="Use the lvm shell, not fork & exec lvm", + default=False, dest='use_lvm_shell') use_session = os.getenv('LVMDBUSD_USE_SESSION', False) @@ -115,6 +118,10 @@ def main(): cfg.args = parser.parse_args() + if cfg.args.use_lvm_shell and not cfg.args.use_json: + log_error("You cannot specify --lvmshell and --nojson") + sys.exit(1) + cmdhandler.set_execution(cfg.args.use_lvm_shell) # List of threads that we start up diff --git a/daemons/lvmdbusd/manager.py b/daemons/lvmdbusd/manager.py index e0da82420..b1419290d 100644 --- a/daemons/lvmdbusd/manager.py +++ b/daemons/lvmdbusd/manager.py @@ -167,14 +167,14 @@ class Manager(AutomatedProperties): @dbus.service.method( dbus_interface=MANAGER_INTERFACE, - in_signature='b') + in_signature='b', out_signature='b') def UseLvmShell(self, yes_no): """ Allow the client to enable/disable lvm shell, used for testing :param yes_no: :return: Nothing """ - cmdhandler.set_execution(yes_no) + return dbus.Boolean(cmdhandler.set_execution(yes_no)) @dbus.service.method( dbus_interface=MANAGER_INTERFACE, diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py index 4d0143c3e..4327a9690 100755 --- a/test/dbus/lvmdbustest.py +++ b/test/dbus/lvmdbustest.py @@ -50,7 +50,7 @@ def set_execution(lvmshell): lvm_manager = dbus.Interface(bus.get_object( BUSNAME, "/com/redhat/lvmdbus1/Manager"), "com.redhat.lvmdbus1.Manager") - lvm_manager.UseLvmShell(lvmshell) + return lvm_manager.UseLvmShell(lvmshell) # noinspection PyUnresolvedReferences @@ -1155,13 +1155,18 @@ if __name__ == '__main__': # Test forking & exec new each time test_shell = os.getenv('LVM_DBUS_TEST_SHELL', 1) + # Default to no lvm shell set_execution(False) if test_shell == 0: unittest.main(exit=True) else: + print('\n *** Testing fork & exec *** \n') unittest.main(exit=False) # Test lvm shell print('\n *** Testing lvm shell *** \n') - set_execution(True) - unittest.main() + if set_execution(True): + unittest.main() + else: + print("WARNING: Unable to dynamically configure " + "service to use lvm shell!")