main - lvmdbusd: Check for KeyError in refresh
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d51fb57f1abf9e24aa8...
Commit: d51fb57f1abf9e24aa8c74df5ffd717e2d45c103
Parent: feaf46863b4d53ee352b451c8f6f6ce8b77a15cc
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 8 15:39:30 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Check for KeyError in refresh
Bubble up a LvmBug if we get a KeyError on a lvm column name.
---
daemons/lvmdbusd/lvmdb.py.in | 60 ++++++++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/daemons/lvmdbusd/lvmdb.py.in b/daemons/lvmdbusd/lvmdb.py.in
index 2346d01e9..8d0cc59e1 100644
--- a/daemons/lvmdbusd/lvmdb.py.in
+++ b/daemons/lvmdbusd/lvmdb.py.in
@@ -15,7 +15,7 @@ import pprint as prettyprint
import os
from lvmdbusd import cmdhandler
-from lvmdbusd.utils import log_debug, log_error
+from lvmdbusd.utils import log_debug, log_error, lvm_column_key, LvmBug
class DataStore(object):
@@ -309,32 +309,38 @@ class DataStore(object):
:param log Add debug log entry/exit messages
:return: None
"""
- self.num_refreshes += 1
- if log:
- log_debug("lvmdb - refresh entry")
-
- # Grab everything first then parse it
- # Do a single lvm retrieve for everything in json
- a = cmdhandler.lvm_full_report_json()
-
- _pvs, _pvs_lookup, _pvs_in_vgs = self._parse_pvs_json(a)
- _vgs, _vgs_lookup = self._parse_vgs_json(a)
- _lvs, _lvs_in_vgs, _lvs_hidden, _lvs_lookup = self._parse_lvs_json(a)
-
- # Set all
- self.pvs = _pvs
- self.pv_path_to_uuid = _pvs_lookup
- self.vg_name_to_uuid = _vgs_lookup
- self.lv_full_name_to_uuid = _lvs_lookup
-
- self.vgs = _vgs
- self.lvs = _lvs
- self.lvs_in_vgs = _lvs_in_vgs
- self.pvs_in_vgs = _pvs_in_vgs
- self.lvs_hidden = _lvs_hidden
-
- # Create lookup table for which LV and segments are on each PV
- self.pv_lvs, self.lv_pvs = self._parse_pv_in_lvs()
+ try:
+ self.num_refreshes += 1
+ if log:
+ log_debug("lvmdb - refresh entry")
+
+ # Grab everything first then parse it
+ # Do a single lvm retrieve for everything in json
+ a = cmdhandler.lvm_full_report_json()
+
+ _pvs, _pvs_lookup, _pvs_in_vgs = self._parse_pvs_json(a)
+ _vgs, _vgs_lookup = self._parse_vgs_json(a)
+ _lvs, _lvs_in_vgs, _lvs_hidden, _lvs_lookup = self._parse_lvs_json(a)
+
+ # Set all
+ self.pvs = _pvs
+ self.pv_path_to_uuid = _pvs_lookup
+ self.vg_name_to_uuid = _vgs_lookup
+ self.lv_full_name_to_uuid = _lvs_lookup
+
+ self.vgs = _vgs
+ self.lvs = _lvs
+ self.lvs_in_vgs = _lvs_in_vgs
+ self.pvs_in_vgs = _pvs_in_vgs
+ self.lvs_hidden = _lvs_hidden
+
+ # Create lookup table for which LV and segments are on each PV
+ self.pv_lvs, self.lv_pvs = self._parse_pv_in_lvs()
+ except KeyError as ke:
+ key = ke.args[0]
+ if lvm_column_key(key):
+ raise LvmBug("missing JSON key: '%s'" % key)
+ raise ke
if log:
log_debug("lvmdb - refresh exit")
1 year, 7 months
main - lvmdbusd: Use common func. for checking missing LV keys
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=feaf46863b4d53ee352...
Commit: feaf46863b4d53ee352b451c8f6f6ce8b77a15cc
Parent: ed9072dad8316e65c22ad4530984174fd488b56c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 8 15:38:31 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Use common func. for checking missing LV keys
---
daemons/lvmdbusd/lv.py | 6 ++----
daemons/lvmdbusd/pv.py | 4 ++--
daemons/lvmdbusd/utils.py | 15 +++++++++++++++
daemons/lvmdbusd/vg.py | 5 ++---
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/daemons/lvmdbusd/lv.py b/daemons/lvmdbusd/lv.py
index 5dd698e29..30c105342 100644
--- a/daemons/lvmdbusd/lv.py
+++ b/daemons/lvmdbusd/lv.py
@@ -21,7 +21,7 @@ from .utils import n, n32, d
from .loader import common
from .state import State
from . import background
-from .utils import round_size, mt_remove_dbus_objects
+from .utils import round_size, mt_remove_dbus_objects, lvm_column_key
from .job import JobState
@@ -136,9 +136,7 @@ def lvs_state_retrieve(selection, cache_refresh=True):
except KeyError as ke:
# Sometimes lvm omits returning one of the keys we requested.
key = ke.args[0]
- if key.startswith("lv_") or key.startswith("vg_") or key.startswith("pool_") or \
- key.endswith("_percent") or key.startswith("move_") or key.startswith("vdo_") or \
- key in ["origin_uuid", "segtype", "origin", "data_lv", "metadata_lv"]:
+ if lvm_column_key(key):
raise LvmBug("missing JSON key: '%s'" % key)
raise ke
return rc
diff --git a/daemons/lvmdbusd/pv.py b/daemons/lvmdbusd/pv.py
index 2037f9c91..316ed37b1 100644
--- a/daemons/lvmdbusd/pv.py
+++ b/daemons/lvmdbusd/pv.py
@@ -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, _handle_execute
+ lv_object_path_method, _handle_execute, lvm_column_key
from .loader import common
from .request import RequestEntry
from .state import State
@@ -42,7 +42,7 @@ def pvs_state_retrieve(selection, cache_refresh=True):
except KeyError as ke:
# Sometimes lvm omits returning one of the keys we requested.
key = ke.args[0]
- if key.startswith("pv") or key.startswith("vg") or (key in ['dev_size', 'pe_start']):
+ if lvm_column_key(key):
raise LvmBug("missing JSON key: '%s'" % key)
raise ke
return rc
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index 3443bdad7..dcb3e06bd 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -781,6 +781,21 @@ def extract_stack_trace(exception):
return ''.join(traceback.format_exception(None, exception, exception.__traceback__))
+def lvm_column_key(key):
+ # Check LV
+ if key.startswith("lv_") or key.startswith("vg_") or key.startswith("pool_") or \
+ key.endswith("_percent") or key.startswith("move_") or key.startswith("vdo_") or \
+ key in ["origin_uuid", "segtype", "origin", "data_lv", "metadata_lv"]:
+ return True
+ # Check VG
+ if key.startswith("vg_") or key.startswith("lv_") or key.startswith("pv_") or \
+ key in ["max_lv", "max_pv", "snap_count"]:
+ return True
+ # Check PV
+ if key.startswith("pv") or key.startswith("vg") or (key in ['dev_size', 'pe_start']):
+ return True
+ return False
+
class LvmBug(RuntimeError):
"""
Things that are clearly a bug with lvm itself.
diff --git a/daemons/lvmdbusd/vg.py b/daemons/lvmdbusd/vg.py
index 928146fdb..6e7d6ec9b 100644
--- a/daemons/lvmdbusd/vg.py
+++ b/daemons/lvmdbusd/vg.py
@@ -20,7 +20,7 @@ from .request import RequestEntry
from .loader import common
from .state import State
from . import background
-from .utils import round_size, mt_remove_dbus_objects, LvmBug
+from .utils import round_size, mt_remove_dbus_objects, LvmBug, lvm_column_key
from .job import JobState
@@ -46,8 +46,7 @@ def vgs_state_retrieve(selection, cache_refresh=True):
except KeyError as ke:
# Sometimes lvm omits returning one of the keys we requested.
key = ke.args[0]
- if key.startswith("vg_") or key.startswith("lv_") or key.startswith("pv_") or \
- key in ["max_lv", "max_pv", "snap_count"]:
+ if lvm_column_key(key):
raise LvmBug("missing JSON key: '%s'" % key)
raise ke
return rc
1 year, 7 months
main - lvmdbusd: Correct undefined var
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ed9072dad8316e65c22...
Commit: ed9072dad8316e65c22ad4530984174fd488b56c
Parent: a326e35cda10b922dfa29d27e9c03e3b56282ba5
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 8 15:37:34 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Correct undefined var
---
daemons/lvmdbusd/fetch.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/daemons/lvmdbusd/fetch.py b/daemons/lvmdbusd/fetch.py
index 199b86073..9da62590a 100644
--- a/daemons/lvmdbusd/fetch.py
+++ b/daemons/lvmdbusd/fetch.py
@@ -6,6 +6,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import errno
from .pv import load_pvs
from .vg import load_vgs
@@ -167,7 +168,7 @@ class StateUpdate(object):
log_error("Too many errors in update_thread, exiting daemon")
cfg.debug.dump()
cfg.flightrecorder.dump()
- bailing(e)
+ bailing(errno.EFAULT)
cfg.exit_daemon()
else:
# Slow things down when encountering errors
1 year, 7 months
main - lvmdbustest: Check for self.pvs
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a326e35cda10b922dfa...
Commit: a326e35cda10b922dfa29d27e9c03e3b56282ba5
Parent: ead80d134dd6afb288453bd20c5ab25daa450b06
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 8 15:29:55 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbustest: Check for self.pvs
If we don't make it through setUp, self.pvs will not exist.
---
test/dbus/lvmdbustest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 18cac35d6..045dbb2b0 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -454,7 +454,7 @@ class TestDbusService(unittest.TestCase):
# Check to make sure the PVs we had to start exist, else re-create
# them
self.objs, self.bus = get_objects()
- if len(self.pvs) != len(self.objs[PV_INT]):
+ if hasattr(self, "pvs") and len(self.pvs) != len(self.objs[PV_INT]):
for p in self.pvs:
found = False
for pc in self.objs[PV_INT]:
1 year, 7 months
main - lvmdbustest: Move signals to last
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ead80d134dd6afb2884...
Commit: ead80d134dd6afb288453bd20c5ab25daa450b06
Parent: 9fc24b1d3b205af1b2e3c4799c575e72a8640842
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 8 15:28:52 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbustest: Move signals to last
When we do the signal testing we default back to fork & exec. Put these
on the end to maximize our lvm shell testing until we fix this proper.
---
test/dbus/lvmdbustest.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 0d06177c0..18cac35d6 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -2314,7 +2314,7 @@ class TestDbusService(unittest.TestCase):
self.assertTrue('Job is not complete!' in str(e))
raise e
- def test_sigint(self):
+ def test_z_sigint(self):
# Issue SIGINT while daemon is processing work to ensure we shut down.
di = DaemonInfo.get()
self.assertTrue(di is not None)
@@ -2349,7 +2349,7 @@ class TestDbusService(unittest.TestCase):
"Failed to exit after sending signal %f seconds after "
"queuing up work for signal %d" % (sleep_amt, signal.SIGINT))
- def test_singleton_daemon(self):
+ def test_z_singleton_daemon(self):
# Ensure we can only have 1 daemon running at a time, daemon should exit with 114 if already running
di = DaemonInfo.get()
self.assertTrue(di is not None)
1 year, 7 months
main - lvmdbusd: Handle 'exit' for lvm_shell_proxy
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9fc24b1d3b205af1b2e...
Commit: 9fc24b1d3b205af1b2e3c4799c575e72a8640842
Parent: b3d13c50d7adb838675929968317f9e42a2f485f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 6 16:24:20 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Handle 'exit' for lvm_shell_proxy
Useful for testing `exit_shell` when running interactively.
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 3 +++
1 file changed, 3 insertions(+)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
index 9696a70a5..fb6ce6164 100755
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -280,6 +280,9 @@ if __name__ == "__main__":
while in_line:
in_line = input("lvm> ")
if in_line:
+ if in_line == "exit":
+ shell.exit_shell()
+ sys.exit(0)
start = time.time()
ret, out, err = shell.call_lvm(in_line.split())
end = time.time()
1 year, 7 months
main - lvmdbusd: Use pseudo tty to get "lvm>" prompt again
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b3d13c50d7adb838675...
Commit: b3d13c50d7adb838675929968317f9e42a2f485f
Parent: 664a06650db5acca2ac9a285e6ebddbde6157300
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 6 16:23:06 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Use pseudo tty to get "lvm>" prompt again
When lvm is compiled with editline, if the file descriptors don't look like
a tty, then no "lvm> " prompt is done. Having lvm output the shell prompt
when consuming JSON on a report file descriptor is very useful in
determining if lvm command is complete.
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 112 ++++++++++++++++++---------------
1 file changed, 63 insertions(+), 49 deletions(-)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
old mode 100644
new mode 100755
index 77c0078ee..9696a70a5
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -14,11 +14,11 @@
import subprocess
import shlex
import os
+import pty
import sys
import tempfile
import time
import select
-from .utils import extract_stack_trace
try:
import simplejson as json
@@ -28,7 +28,9 @@ except ImportError:
from lvmdbusd.cfg import LVM_CMD, run
from lvmdbusd.utils import log_debug, log_error, add_no_notify, make_non_block,\
- read_decoded
+ read_decoded, extract_stack_trace, LvmBug
+
+SHELL_PROMPT = "lvm> "
def _quote_arg(arg):
@@ -44,7 +46,7 @@ class LVMShellProxy(object):
# up trying to get one.
#
# Returns stdout, report (JSON), stderr
- def _read_response(self):
+ def _read_response(self, no_output=False):
stdout = ""
report = ""
stderr = ""
@@ -60,50 +62,49 @@ class LVMShellProxy(object):
while keep_reading and run.value != 0:
try:
rd_fd = [
- self.lvm_shell.stdout.fileno(),
+ self.parent_stdout_fd,
self.report_stream.fileno(),
- self.lvm_shell.stderr.fileno()]
+ self.parent_stderr_fd]
ready = select.select(rd_fd, [], [], 2)
for r in ready[0]:
- if r == self.lvm_shell.stdout.fileno():
- stdout += read_decoded(self.lvm_shell.stdout)
+ if r == self.parent_stdout_fd:
+ stdout += self.parent_stdout.readline()
elif r == self.report_stream.fileno():
report += read_decoded(self.report_stream)
- elif r == self.lvm_shell.stderr.fileno():
- stderr += read_decoded(self.lvm_shell.stderr)
+ elif r == self.parent_stderr_fd:
+ stderr += self.parent_stderr.readline()
# Check to see if the lvm process died on us
if self.lvm_shell.poll() is not None:
raise Exception(self.lvm_shell.returncode, "%s" % stderr)
- cur_report_len = len(report)
- if cur_report_len != 0:
- # Only bother to parse if we have more data and the last 2 characters match expected
- # complete JSON, prevents excessive JSON parsing attempts
- if prev_report_len != cur_report_len and report[-2:] == "}\n":
- prev_report_len = cur_report_len
-
- # Parse the JSON if it's good we are done,
- # if not we will try to read some more.
- try:
- report_json = json.loads(report)
- keep_reading = False
- except ValueError:
- pass
-
- # As long as lvm is spewing something on one of the FDs we will
- # keep trying. If we get a few timeouts with no activity, and
- # we don't have valid JSON, we will raise an error.
- if len(ready) == 0 and keep_reading:
- extra_passes -= 1
- if extra_passes <= 0:
- if len(report):
- raise ValueError("Invalid json: %s" %
- report)
- else:
- raise ValueError(
- "lvm returned no JSON output!")
+ if stdout.endswith(SHELL_PROMPT):
+ if no_output:
+ keep_reading = False
+ else:
+ cur_report_len = len(report)
+ if cur_report_len != 0:
+ # Only bother to parse if we have more data
+ if prev_report_len != cur_report_len:
+ prev_report_len = cur_report_len
+ # Parse the JSON if it's good we are done,
+ # if not we will try to read some more.
+ try:
+ report_json = json.loads(report)
+ keep_reading = False
+ except ValueError:
+ pass
+
+ if keep_reading:
+ extra_passes -= 1
+ if extra_passes <= 0:
+ if len(report):
+ raise LvmBug("Invalid json: %s" %
+ report)
+ else:
+ raise LvmBug(
+ "lvm returned no JSON output!")
except IOError as ioe:
log_debug(str(ioe))
@@ -119,10 +120,8 @@ class LVMShellProxy(object):
return stdout, report_json, stderr
def _write_cmd(self, cmd):
- cmd_bytes = bytes(cmd, "utf-8")
- num_written = self.lvm_shell.stdin.write(cmd_bytes)
- assert (num_written == len(cmd_bytes))
- self.lvm_shell.stdin.flush()
+ self.parent_stdin.write(cmd)
+ self.parent_stdin.flush()
def __init__(self):
# Create a temp directory
@@ -147,22 +146,37 @@ class LVMShellProxy(object):
if "LVM" in k:
local_env[k] = v
+ self.parent_stdin_fd, child_stdin_fd = pty.openpty()
+ self.parent_stdout_fd, child_stdout_fd = pty.openpty()
+ self.parent_stderr_fd, child_stderr_fd = pty.openpty()
+ self.parent_stdin = os.fdopen(self.parent_stdin_fd, "w")
+ self.parent_stdout = os.fdopen(self.parent_stdout_fd, "r")
+ self.parent_stderr = os.fdopen(self.parent_stderr_fd, "r")
+
# run the lvm shell
self.lvm_shell = subprocess.Popen(
[LVM_CMD],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=local_env,
- stderr=subprocess.PIPE, close_fds=True, pass_fds=(lvm_fd,), shell=False)
+ stdin=child_stdin_fd,
+ stdout=child_stdout_fd, env=local_env,
+ stderr=child_stderr_fd, close_fds=True,
+ pass_fds=(lvm_fd,), shell=False)
try:
- make_non_block(self.lvm_shell.stdout)
- make_non_block(self.lvm_shell.stderr)
+ make_non_block(self.parent_stdout_fd)
+ make_non_block(self.parent_stderr_fd)
- # Close our copy of the lvm_fd, child process is open in its process space
+ # Close our copies of the child FDs there were created with the fork, we don't need them open.
os.close(lvm_fd)
-
- # Assume we are ready as we may not get the lvm prompt message depending on
- # if we are using readline or editline.
-
+ os.close(child_stdin_fd)
+ os.close(child_stdout_fd)
+ os.close(child_stderr_fd)
+
+ # wait for the first prompt
+ log_debug("waiting for first prompt...")
+ errors = self._read_response(no_output=True)[2]
+ if errors and len(errors):
+ raise LvmBug(errors)
+ log_debug("lvm prompt read!!!")
except:
raise
finally:
1 year, 7 months
main - lvmdbusd: Remove PID from log messages
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=664a06650db5acca2ac...
Commit: 664a06650db5acca2ac9a285e6ebddbde6157300
Parent: b6dc96d8ef03e7af6624ab88a94654ffa94c50ba
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Aug 31 21:25:36 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Remove PID from log messages
Previously the daemon would output PID:TID. If it's running under systemd
it skips outputting PID as systemd already does this.
---
daemons/lvmdbusd/cfg.py | 2 ++
daemons/lvmdbusd/main.py | 17 +++++++++++++++++
daemons/lvmdbusd/utils.py | 8 ++++++--
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py
index 5b342bc20..142cfabc7 100644
--- a/daemons/lvmdbusd/cfg.py
+++ b/daemons/lvmdbusd/cfg.py
@@ -113,3 +113,5 @@ def exit_daemon():
# Debug data for lvm
lvmdebug = None
+
+systemd = False
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index ab66efcc9..ac309aa69 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -129,6 +129,20 @@ def process_args():
return args
+def running_under_systemd():
+ """"
+ Checks to see if we are running under systemd, by checking damon fd 0, 1
+ systemd sets stdin to /dev/null and 1 & 2 are a socket
+ """
+ base = "/proc/self/fd"
+ stdout = os.readlink("%s/0" % base)
+ if stdout == "/dev/null":
+ stdout = os.readlink("%s/1" % base)
+ if "socket" in stdout:
+ return True
+ return False
+
+
def main():
start = time.time()
use_session = os.getenv('LVMDBUSD_USE_SESSION', False)
@@ -142,6 +156,9 @@ def main():
# only used for 'fullreport' at this time.
cfg.lvmdebug = utils.LvmDebugData()
+ # Indicator if we are running under systemd
+ cfg.systemd = running_under_systemd()
+
# Add simple command line handling
cfg.args = process_args()
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index ec40236a5..3443bdad7 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -308,13 +308,17 @@ class DebugMessages(object):
def _format_log_entry(msg):
tid = ctypes.CDLL('libc.so.6').syscall(186)
- if STDOUT_TTY:
+ if not cfg.systemd and STDOUT_TTY:
msg = "%s: %d:%d - %s" % \
(datetime.datetime.now().strftime("%b %d %H:%M:%S.%f"),
os.getpid(), tid, msg)
else:
- msg = "%d:%d - %s" % (os.getpid(), tid, msg)
+ if cfg.systemd:
+ # Systemd already puts the daemon pid in the log, we'll just add the tid
+ msg = "[%d]: %s" % (tid, msg)
+ else:
+ msg = "[%d:%d]: %s" % (os.getpid(), tid, msg)
return msg
1 year, 7 months
main - lvmdbustest: Utilize addCleanup in unit test
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b6dc96d8ef03e7af662...
Commit: b6dc96d8ef03e7af6624ab88a94654ffa94c50ba
Parent: e977b70bfb0a26a8dd5cd06d581cb810e2a6f10b
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Aug 31 18:03:16 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbustest: Utilize addCleanup in unit test
Register the clean up with addCleanup so we ensure clean_up gets run
regardless of what happens in setUp.
---
test/dbus/lvmdbustest.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index c932d0830..0d06177c0 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -383,6 +383,9 @@ class DaemonInfo(object):
# noinspection PyUnresolvedReferences
class TestDbusService(unittest.TestCase):
def setUp(self):
+
+ self.addCleanup(self.clean_up)
+
# Because of the sensitive nature of running LVM tests we will only
# run if we have PVs and nothing else, so that we can be confident that
# we are not mucking with someone's data on their system
@@ -463,11 +466,6 @@ class TestDbusService(unittest.TestCase):
# print('Re-creating PV=', p)
self._pv_create(p)
- def tearDown(self):
- # If we get here it means we passed setUp, so lets remove anything
- # and everything that remains, besides the PVs themselves
- self.clean_up()
-
def _check_consistency(self):
# Only do consistency checks if we aren't running the unit tests
# concurrently
1 year, 7 months
main - lvmdbusd: Remove duplicate code
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e977b70bfb0a26a8dd5...
Commit: e977b70bfb0a26a8dd5cd06d581cb810e2a6f10b
Parent: f4c03faa6556489444cf9402b2a35c46e7282ed3
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Aug 31 15:42:48 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500
lvmdbusd: Remove duplicate code
The logic for _cache_lv and _writecache_lv was identical except for which
underlying lvm command to run. Factor out common.
---
daemons/lvmdbusd/lv.py | 40 ++++++++++------------------------------
1 file changed, 10 insertions(+), 30 deletions(-)
diff --git a/daemons/lvmdbusd/lv.py b/daemons/lvmdbusd/lv.py
index 134843346..5dd698e29 100644
--- a/daemons/lvmdbusd/lv.py
+++ b/daemons/lvmdbusd/lv.py
@@ -751,7 +751,7 @@ class Lv(LvCommon):
cfg.worker_q.put(r)
@staticmethod
- def _writecache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
+ def _caching_common(method, lv_uuid, lv_name, lv_object_path, cache_options):
# Make sure we have a dbus object representing it
dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
@@ -760,7 +760,7 @@ class Lv(LvCommon):
if lv_to_cache:
fcn = lv_to_cache.lv_full_name()
- rc, out, err = cmdhandler.lv_writecache_lv(
+ rc, out, err = method(
dbo.lv_full_name(), fcn, cache_options)
if rc == 0:
# When we cache an LV, the cache pool and the lv that is getting
@@ -777,9 +777,14 @@ class Lv(LvCommon):
else:
raise dbus.exceptions.DBusException(
LV_INTERFACE, 'LV to cache with object path %s not present!' %
- lv_object_path)
+ lv_object_path)
return lv_converted
+ @staticmethod
+ def _writecache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
+ return Lv._caching_common(cmdhandler.lv_writecache_lv, lv_uuid,
+ lv_name, lv_object_path, cache_options)
+
@dbus.service.method(
dbus_interface=LV_INTERFACE,
in_signature='oia{sv}',
@@ -959,33 +964,8 @@ class LvCachePool(Lv):
@staticmethod
def _cache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
- # Make sure we have a dbus object representing cache pool
- dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
-
- # Make sure we have dbus object representing lv to cache
- lv_to_cache = cfg.om.get_object_by_path(lv_object_path)
-
- if lv_to_cache:
- fcn = lv_to_cache.lv_full_name()
- rc, out, err = cmdhandler.lv_cache_lv(
- dbo.lv_full_name(), fcn, cache_options)
- if rc == 0:
- # When we cache an LV, the cache pool and the lv that is getting
- # cached need to be removed from the object manager and
- # re-created as their interfaces have changed!
- mt_remove_dbus_objects((dbo, lv_to_cache))
- cfg.load()
-
- lv_converted = cfg.om.get_object_path_by_lvm_id(fcn)
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE, 'LV to cache with object path %s not present!' %
- lv_object_path)
- return lv_converted
+ return Lv._caching_common(cmdhandler.lv_cache_lv, lv_uuid, lv_name,
+ lv_object_path, cache_options)
@dbus.service.method(
dbus_interface=CACHE_POOL_INTERFACE,
1 year, 7 months