1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +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()
_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):

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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)
if set_execution(True):
unittest.main()
else:
print("WARNING: Unable to dynamically configure "
"service to use lvm shell!")