1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

lvmdbusd: Handle different daemon options

- Prevent --lvmshell with --nojson, not a valid combination
- If user is preventing json, then no lvmshell usage
- Return boolean on Manager.UseLvmShell
This commit is contained in:
Tony Asleson 2016-08-29 14:26:16 -05:00
parent 1d1fe00846
commit 70d4e2e8d5
5 changed files with 30 additions and 12 deletions

View File

@ -126,11 +126,13 @@ def _shell_cfg():
lvm_shell = LVMShellProxy() lvm_shell = LVMShellProxy()
_t_call = lvm_shell.call_lvm _t_call = lvm_shell.call_lvm
cfg.SHELL_IN_USE = lvm_shell cfg.SHELL_IN_USE = lvm_shell
return True
except Exception: except Exception:
_t_call = call_lvm _t_call = call_lvm
cfg.SHELL_IN_USE = None cfg.SHELL_IN_USE = None
log_error(traceback.format_exc()) log_error(traceback.format_exc())
log_error("Unable to utilize lvm shell, dropping back to fork & exec") log_error("Unable to utilize lvm shell, dropping back to fork & exec")
return False
def set_execution(shell): def set_execution(shell):
@ -139,7 +141,7 @@ def set_execution(shell):
# If the user requested lvm shell and we are currently setup that # If the user requested lvm shell and we are currently setup that
# way, just return # way, just return
if cfg.SHELL_IN_USE and shell: if cfg.SHELL_IN_USE and shell:
return return True
else: else:
if not shell and cfg.SHELL_IN_USE: if not shell and cfg.SHELL_IN_USE:
cfg.SHELL_IN_USE.exit_shell() cfg.SHELL_IN_USE.exit_shell()
@ -147,7 +149,11 @@ def set_execution(shell):
_t_call = call_lvm _t_call = call_lvm
if shell: if shell:
_shell_cfg() if cfg.args.use_json:
return _shell_cfg()
else:
return False
return True
def time_wrapper(command, debug=False): def time_wrapper(command, debug=False):

View File

@ -24,7 +24,7 @@ except SystemError:
class DataStore(object): class DataStore(object):
def __init__(self, usejson=None): def __init__(self, usejson=True):
self.pvs = {} self.pvs = {}
self.vgs = {} self.vgs = {}
self.lvs = {} self.lvs = {}
@ -42,7 +42,7 @@ class DataStore(object):
# self.refresh() # self.refresh()
self.num_refreshes = 0 self.num_refreshes = 0
if usejson is None: if usejson:
self.json = cmdhandler.supports_json() self.json = cmdhandler.supports_json()
else: else:
self.json = usejson self.json = usejson

View File

@ -25,9 +25,10 @@ from .background import background_reaper
import traceback import traceback
import queue import queue
from . import udevwatch from . import udevwatch
from .utils import log_debug from .utils import log_debug, log_error
import argparse import argparse
import os import os
import sys
from .refresh import handle_external_event, event_complete from .refresh import handle_external_event, event_complete
@ -102,10 +103,12 @@ def main():
help="Dump debug messages", default=False, help="Dump debug messages", default=False,
dest='debug') dest='debug')
parser.add_argument("--nojson", action='store_false', 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') dest='use_json')
parser.add_argument("--lvmshell", action='store_true', 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') dest='use_lvm_shell')
use_session = os.getenv('LVMDBUSD_USE_SESSION', False) use_session = os.getenv('LVMDBUSD_USE_SESSION', False)
@ -115,6 +118,10 @@ def main():
cfg.args = parser.parse_args() 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) cmdhandler.set_execution(cfg.args.use_lvm_shell)
# List of threads that we start up # List of threads that we start up

View File

@ -167,14 +167,14 @@ class Manager(AutomatedProperties):
@dbus.service.method( @dbus.service.method(
dbus_interface=MANAGER_INTERFACE, dbus_interface=MANAGER_INTERFACE,
in_signature='b') in_signature='b', out_signature='b')
def UseLvmShell(self, yes_no): def UseLvmShell(self, yes_no):
""" """
Allow the client to enable/disable lvm shell, used for testing Allow the client to enable/disable lvm shell, used for testing
:param yes_no: :param yes_no:
:return: Nothing :return: Nothing
""" """
cmdhandler.set_execution(yes_no) return dbus.Boolean(cmdhandler.set_execution(yes_no))
@dbus.service.method( @dbus.service.method(
dbus_interface=MANAGER_INTERFACE, dbus_interface=MANAGER_INTERFACE,

View File

@ -50,7 +50,7 @@ def set_execution(lvmshell):
lvm_manager = dbus.Interface(bus.get_object( lvm_manager = dbus.Interface(bus.get_object(
BUSNAME, "/com/redhat/lvmdbus1/Manager"), BUSNAME, "/com/redhat/lvmdbus1/Manager"),
"com.redhat.lvmdbus1.Manager") "com.redhat.lvmdbus1.Manager")
lvm_manager.UseLvmShell(lvmshell) return lvm_manager.UseLvmShell(lvmshell)
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
@ -1155,13 +1155,18 @@ if __name__ == '__main__':
# Test forking & exec new each time # Test forking & exec new each time
test_shell = os.getenv('LVM_DBUS_TEST_SHELL', 1) test_shell = os.getenv('LVM_DBUS_TEST_SHELL', 1)
# Default to no lvm shell
set_execution(False) set_execution(False)
if test_shell == 0: if test_shell == 0:
unittest.main(exit=True) unittest.main(exit=True)
else: else:
print('\n *** Testing fork & exec *** \n')
unittest.main(exit=False) unittest.main(exit=False)
# Test lvm shell # Test lvm shell
print('\n *** Testing lvm shell *** \n') print('\n *** Testing lvm shell *** \n')
set_execution(True) if set_execution(True):
unittest.main() unittest.main()
else:
print("WARNING: Unable to dynamically configure "
"service to use lvm shell!")