summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Asleson <tasleson@redhat.com>2018-12-11 11:21:50 -0600
committerMarian Csontos <mcsontos@redhat.com>2018-12-17 16:11:15 +0100
commitda9b499bc28478d6c0d74d80e5e824a3567b1c29 (patch)
tree1fdb6bc70debe68575efcb68662b14e42850e167
parentcc59cb1abc24d2d88371eaee69ad28a0028419c4 (diff)
downloadlvm2-da9b499bc28478d6c0d74d80e5e824a3567b1c29.tar.gz
lvmdbusd: Handle missing lv_attr table lookups
If we don't know the meaning we will return the key with default text instead of raising an exception and taking the daemon out in the process. Resolves: rhbz1657950 (cherry picked from commit 51f08efaa700550740254093bacea270325f2ccf)
-rw-r--r--daemons/lvmdbusd/lv.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/daemons/lvmdbusd/lv.py b/daemons/lvmdbusd/lv.py
index ba9499f64..a80675fa4 100644
--- a/daemons/lvmdbusd/lv.py
+++ b/daemons/lvmdbusd/lv.py
@@ -10,7 +10,7 @@
from .automatedproperties import AutomatedProperties
from . import utils
-from .utils import vg_obj_path_generate
+from .utils import vg_obj_path_generate, log_error
import dbus
from . import cmdhandler
from . import cfg
@@ -24,6 +24,8 @@ from . import background
from .utils import round_size, mt_remove_dbus_objects
from .job import JobState
+import traceback
+
# Try and build a key for a LV, so that we sort the LVs with least dependencies
# first. This may be error prone because of the flexibility LVM
@@ -291,6 +293,22 @@ class LvCommon(AutomatedProperties):
(lv_uuid, lv_name))
return dbo
+ def attr_struct(self, index, type_map, default='undisclosed'):
+ try:
+ if self.state.Attr[index] not in type_map:
+ log_error("LV %s %s with lv_attr %s, lv_attr[%d] = "
+ "'%s' is not known" %
+ (self.Uuid, self.Name, self.Attr, index,
+ self.state.Attr[index]))
+
+ return dbus.Struct((self.state.Attr[index],
+ type_map.get(self.state.Attr[index], default)),
+ signature="(ss)")
+ except BaseException:
+ st = traceback.format_exc()
+ log_error("attr_struct: \n%s" % st)
+ return dbus.Struct(('?', 'Unavailable'), signature="(ss)")
+
@property
def VolumeType(self):
type_map = {'C': 'Cache', 'm': 'mirrored',
@@ -304,16 +322,14 @@ class LvCommon(AutomatedProperties):
'V': 'thin Volume', 't': 'thin pool', 'T': 'Thin pool data',
'e': 'raid or pool metadata or pool metadata spare',
'-': 'Unspecified'}
- return dbus.Struct((self.state.Attr[0], type_map[self.state.Attr[0]]),
- signature="as")
+ return self.attr_struct(0, type_map)
@property
def Permissions(self):
type_map = {'w': 'writable', 'r': 'read-only',
'R': 'Read-only activation of non-read-only volume',
'-': 'Unspecified'}
- return dbus.Struct((self.state.Attr[1], type_map[self.state.Attr[1]]),
- signature="(ss)")
+ return self.attr_struct(1, type_map)
@property
def AllocationPolicy(self):
@@ -322,8 +338,7 @@ class LvCommon(AutomatedProperties):
'i': 'inherited', 'I': 'inherited locked',
'l': 'cling', 'L': 'cling locked',
'n': 'normal', 'N': 'normal locked', '-': 'Unspecified'}
- return dbus.Struct((self.state.Attr[2], type_map[self.state.Attr[2]]),
- signature="(ss)")
+ return self.attr_struct(2, type_map)
@property
def FixedMinor(self):
@@ -338,8 +353,7 @@ class LvCommon(AutomatedProperties):
'd': 'mapped device present without tables',
'i': 'mapped device present with inactive table',
'X': 'unknown', '-': 'Unspecified'}
- return dbus.Struct((self.state.Attr[4], type_map[self.state.Attr[4]]),
- signature="(ss)")
+ return self.attr_struct(4, type_map)
@property
def TargetType(self):
@@ -358,8 +372,7 @@ class LvCommon(AutomatedProperties):
type_map = {'p': 'partial', 'r': 'refresh',
'm': 'mismatches', 'w': 'writemostly',
'X': 'X unknown', '-': 'Unspecified'}
- return dbus.Struct((self.state.Attr[8], type_map[self.state.Attr[8]]),
- signature="(ss)")
+ return self.attr_struct(8, type_map)
@property
def SkipActivation(self):