Skip to content
Open
6 changes: 6 additions & 0 deletions ssmlib/backends/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, *args, **kwargs):
super(DmObject, self).__init__(*args, **kwargs)
self.type = 'crypt'
self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))
self.swaps = misc.get_swaps()
self.default_pool_name = SSM_CRYPT_DEFAULT_POOL

if not misc.check_binary('dmsetup') or \
Expand Down Expand Up @@ -197,6 +198,11 @@ def __init__(self, *args, **kwargs):
dm['real_dev'] = misc.get_real_device(devname)
if dm['real_dev'] in self.mounts:
dm['mount'] = self.mounts[dm['real_dev']]['mp']
else:
for swap in self.swaps:
if swap[0] == dm['real_dev']:
dm['mount'] = "SWAP"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a break after the assignment. There is no need to iterate over the rest of the entries in swap. This applies to all places in this patch except the one in DeviceInfo of course.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lukas and sorry for the wait. Good catch. I've made the requested correction. Please feel free to review at your convenience.

break

# Check if the device really exists in the system. In some cases
# (tests) DM_DEV_DIR can lie to us, if that is the case, simple
Expand Down
20 changes: 13 additions & 7 deletions ssmlib/backends/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def _parse_data(self, command):
for index in range(len(array))])
if self._skip_data(row):
continue
self._fill_aditional_info(row)
self._fill_additional_info(row)
self.data[self._data_index(row)] = row

def _fill_aditional_info(self, row):
def _fill_additional_info(self, row):
pass

def supported_since(self, version, string):
Expand Down Expand Up @@ -188,7 +188,7 @@ def __init__(self, *args, **kwargs):

self._parse_data(command)

def _fill_aditional_info(self, vg):
def _fill_additional_info(self, vg):
vg['type'] = 'lvm'
vg['pool_used'] = float(vg['pool_size']) - float(vg['pool_free'])

Expand Down Expand Up @@ -382,7 +382,7 @@ def __init__(self, *args, **kwargs):
def _data_index(self, row):
return misc.get_real_device(row['dev_name'])

def _fill_aditional_info(self, pv):
def _fill_additional_info(self, pv):
pv['hide'] = False
# If the device is not in any group we do not need this info
# and we do not want it to show up in the device listing
Expand Down Expand Up @@ -410,9 +410,10 @@ def __init__(self, *args, **kwargs):
'stripesize', 'type', 'lv_name', 'origin', 'attr', 'pool_lv']
self.handle_fs = True
self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))
self.swaps = misc.get_swaps()
self._parse_data(command)

def _fill_aditional_info(self, lv):
def _fill_additional_info(self, lv):
lv['dev_name'] = "{0}/{1}/{2}".format(DM_DEV_DIR, lv['pool_name'],
lv['lv_name'])
if lv['origin'] or \
Expand Down Expand Up @@ -441,6 +442,11 @@ def _fill_aditional_info(self, lv):

if lv['real_dev'] in self.mounts:
lv['mount'] = self.mounts[lv['real_dev']]['mp']
else:
for swap in self.swaps:
if swap[0] == lv['real_dev']:
lv['mount'] = "SWAP"
break
self.parse_attr(lv, lv['attr'])

def __getitem__(self, name):
Expand Down Expand Up @@ -540,7 +546,7 @@ def _skip_data(self, row):
def _data_index(self, row):
return misc.get_real_device(row['dev_name'])

def _fill_aditional_info(self, snap):
def _fill_additional_info(self, snap):
snap['dev_name'] = "{0}/{1}/{2}".format(DM_DEV_DIR, snap['pool_name'],
snap['lv_name'])
snap['hide'] = False
Expand Down Expand Up @@ -599,7 +605,7 @@ def __init__(self, *args, **kwargs):
global THIN_POOL_DATA
THIN_POOL_DATA = self.data

def _fill_aditional_info(self, vg):
def _fill_additional_info(self, vg):
vg['type'] = 'thin'
vg['pool_name'] = os.path.basename(vg['lv_name'])
vg['index_name'] = "{}/{}".format(vg['parent_pool'], vg['pool_name'])
Expand Down
6 changes: 6 additions & 0 deletions ssmlib/backends/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, *args, **kwargs):
return

self.mounts = misc.get_mounts('/dev/md')
self.swaps = misc.get_swaps()

mdnumber = misc.get_dmnumber("md")

Expand Down Expand Up @@ -81,6 +82,11 @@ def get_volume_data(self, devname):
data['pool_name'] = SSM_DM_DEFAULT_POOL
if data['dev_name'] in self.mounts:
data['mount'] = self.mounts[data['dev_name']]['mp']
else:
for swap in self.swaps:
if swap[0] == data['dev_name']:
data['mount'] = "SWAP"
break
command = [MDADM, '--detail', devname]
for line in misc.run(command, stderr=False)[1].split("\n"):
array = line.split(":")
Expand Down
14 changes: 14 additions & 0 deletions ssmlib/backends/multipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

MP="multipath"

try:
DM_DEV_DIR = os.environ['DM_DEV_DIR']
except KeyError:
DM_DEV_DIR = "/dev"

class Multipath(template.Backend):
def __init__(self, options, data=None):
self.type = 'multipath'
Expand All @@ -35,6 +40,8 @@ def __init__(self, options, data=None):
self.options = options
self.output = None
self.problem = problem.ProblemSet(options)
self.swaps = misc.get_swaps()
self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))

for mp_dev in self.get_mp_devices():
mpname = self.get_real_device(mp_dev)
Expand Down Expand Up @@ -102,6 +109,13 @@ def get_volume_data(self, volname):
data['dev_size'] = misc.get_device_size(data['dev_name'])
data['nodes'] = []
data['total_nodes'] = 0
if data['dev_name'] in self.mounts:
data['mount'] = self.mounts[data['dev_name']]['mp']
else:
for swap in self.swaps:
if swap[0] == data['dev_name']:
data['mount'] = "SWAP"
break
for entry in zip(output[2::2],output[3::2]):
""" Some string operations to remove the tree path symbols
from the output. """
Expand Down
9 changes: 4 additions & 5 deletions ssmlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ def __init__(self, options, data=None):
hide_dmnumbers.append(misc.get_dmnumber(name))

mounts = misc.get_mounts('/dev/')
swaps = misc.get_swaps()

for items in misc.get_partitions():
devices = dict(zip(self.attrs, items))
Expand All @@ -454,7 +453,7 @@ def __init__(self, options, data=None):
if devices['dev_name'] in mounts:
devices['mount'] = mounts[devices['dev_name']]['mp']

for item in swaps:
for item in misc.get_swaps():
if item[0] in self.data:
self.data[item[0]]['mount'] = "SWAP"

Expand Down Expand Up @@ -2608,13 +2607,13 @@ def _get_parser_global(self, prog):
parser.add_argument('--version', action='version',
version='%(prog)s {0}'.format(VERSION))
parser.add_argument('-v', '--verbose',
help="Show aditional information while executing.",
help="Show additional information while executing.",
action="store_true")
parser.add_argument('-vv',
help="Show yet more aditional information while executing.",
help="Show yet more additional information while executing.",
action="store_true")
parser.add_argument('-vvv',
help="Show yet more aditional information while executing.",
help="Show yet more additional information while executing.",
action="store_true")
parser.add_argument('-f', '--force',
help="Force execution in the case where ssm has some " +
Expand Down
8 changes: 7 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def check_system_dependencies():
'lvm',
'dmsetup',
'cryptsetup',
'multipath'
'multipath',
'mkswap',
'swapon',
'swapoff',
'udevadm',
'targetcli',
'iscsiadm'
]

missing = []
Expand Down
25 changes: 16 additions & 9 deletions tests/bashtests/012-crypt-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ pass() {
echo -e "${passwd}\n${passwd}"
}

crypt_vers() {
vers=$(cryptsetup luksDump $1 | grep "^Version:" | cut -f2)
echo "LUKS$vers"
}

fs1=ext4
fs2=ext4
fs3=ext4
Expand All @@ -67,19 +72,21 @@ ssm remove ${DEV}/$crypt_vol1

# Create encrypted volume
pass | ssm create $dev1
check crypt_vol_field $crypt_vol1 type LUKS1
check crypt_vol_field $crypt_vol1 type $(crypt_vers $dev1)
check crypt_vol_field $crypt_vol1 device $dev1
check list_table "$(ssm list vol)" $crypt_vol1 $SSM_CRYPT_DEFAULT_POOL none crypt

pass | ssm create $dev2 -e
check crypt_vol_field $crypt_vol2 type LUKS1
check crypt_vol_field $crypt_vol2 type $(crypt_vers $dev2)
check crypt_vol_field $crypt_vol2 device $dev2
check list_table "$(ssm list vol)" $crypt_vol2 $SSM_CRYPT_DEFAULT_POOL none crypt

pass | ssm create -e luks $dev3
check crypt_vol_field $crypt_vol3 type LUKS1
mkswap ${DEV}/$crypt_vol3 && swapon ${DEV}/$crypt_vol3
check crypt_vol_field $crypt_vol3 type $(crypt_vers $dev3)
check crypt_vol_field $crypt_vol3 device $dev3
check list_table "$(ssm list vol)" $crypt_vol3 $SSM_CRYPT_DEFAULT_POOL none crypt
check list_table "$(ssm list vol)" $crypt_vol3 $SSM_CRYPT_DEFAULT_POOL none crypt SWAP
swapoff ${DEV}/$crypt_vol3

pass | ssm create --fs $fs1 -e plain $dev4 $mnt1
check mountpoint $crypt_vol4 $mnt1
Expand Down Expand Up @@ -115,16 +122,16 @@ export SSM_DEFAULT_BACKEND='lvm'

# Try a short password with backend different than crypt
! echo -e "a\na" | ssm create $dev1 -e luks
! check crypt_vol_field $crypt_vol1 type LUKS1
! check crypt_vol_field $crypt_vol1 type $(crypt_vers $dev1)
# force it
echo -e "a\na" | ssm -f create $dev1 -e luks
check crypt_vol_field $crypt_vol1 type LUKS1
check crypt_vol_field $crypt_vol1 type $(crypt_vers ${DEV}/${SSM_LVM_DEFAULT_POOL}-$lvol1)
ssm remove ${DEV}/$crypt_vol1
ssm -f remove $SSM_LVM_DEFAULT_POOL || true

pass | ssm create --fs $fs3 $dev1 $dev2 $mnt1 -e
check mountpoint $crypt_vol1 $mnt1
check crypt_vol_field $crypt_vol1 type LUKS1
check crypt_vol_field $crypt_vol1 type $(crypt_vers ${DEV}/${SSM_LVM_DEFAULT_POOL}-$lvol1)
check crypt_vol_field $crypt_vol1 device ${SSM_LVM_DEFAULT_POOL}-$lvol1
check list_table "$(ssm list vol)" $crypt_vol1 $SSM_CRYPT_DEFAULT_POOL none $fs3 none none crypt
check list_table "$(ssm list vol)" $SSM_LVM_DEFAULT_POOL/$lvol1 $SSM_LVM_DEFAULT_POOL none linear
Expand All @@ -138,7 +145,7 @@ check list_table "$(ssm list vol)" $SSM_LVM_DEFAULT_POOL/$lvol2 $SSM_LVM_DEFAULT
check lv_field $SSM_LVM_DEFAULT_POOL/$lvol2 pv_count 4

pass | ssm create $dev5 -e luks
check crypt_vol_field $crypt_vol3 type LUKS1
check crypt_vol_field $crypt_vol3 type $(crypt_vers ${DEV}/${SSM_LVM_DEFAULT_POOL}-$lvol3)
check crypt_vol_field $crypt_vol3 device ${SSM_LVM_DEFAULT_POOL}-$lvol3
check list_table "$(ssm list vol)" $crypt_vol3 $SSM_CRYPT_DEFAULT_POOL none crypt
check list_table "$(ssm list vol)" $SSM_LVM_DEFAULT_POOL/$lvol3 $SSM_LVM_DEFAULT_POOL none linear
Expand All @@ -161,7 +168,7 @@ ssm -f remove $SSM_LVM_DEFAULT_POOL
ssm create $dev1 $dev2
ssm list
pass | ssm -b crypt create $DM_DEV_DIR/$SSM_LVM_DEFAULT_POOL/$lvol1
check crypt_vol_field $crypt_vol1 type LUKS1
check crypt_vol_field $crypt_vol1 type $(crypt_vers ${DEV}/${SSM_LVM_DEFAULT_POOL}-$lvol1)
check crypt_vol_field $crypt_vol1 device ${SSM_LVM_DEFAULT_POOL}-$lvol1
check list_table "$(ssm list vol)" $crypt_vol1 $SSM_CRYPT_DEFAULT_POOL none crypt
check list_table "$(ssm list vol)" $SSM_LVM_DEFAULT_POOL/$lvol1 $SSM_LVM_DEFAULT_POOL none linear
Expand Down
8 changes: 4 additions & 4 deletions tests/bashtests/016-multipath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ mpdev=$dev1
mpath_setup $mpdev

# get devices used in multipath
USED_DEVS=$(multipath -ll | \
MPATH=$(multipath -ll | grep md_block0 | cut -d " " -f 1)
USED_DEVS=$(multipath -ll $MPATH | \
grep "[0-9]\+:[0-9]\+:[0-9]\+:[0:9]\+" | \
sed -e "s/.*[0-9]\+:[0-9]\+:[0-9]\+:[0:9]\+ //" -e "s/ .*//")
MPATH=$(multipath -ll | head -n1 | cut -d " " -f 1)
DM="/dev/$(multipath -ll | head -n1 | cut -d " " -f 3)"
DM="/dev/$(multipath -ll | grep md_block0 | cut -d " " -f 3)"

# basic listing
check list_table "$(ssm list dev)" "^$DM" 9.80MB
Expand Down Expand Up @@ -93,4 +93,4 @@ not ssm -f remove $DM
not ssm -b multipath list
not ssm -b multipath create $dev1

exit 0
exit 0
3 changes: 2 additions & 1 deletion tests/bashtests/lib/mpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mpath_setup() {
1>&2 echo "An error occured with multipath configuration."
return 1
fi
udevadm settle --timeout 15
return 0
}

Expand Down Expand Up @@ -78,7 +79,7 @@ mpath_cleanup() {
head -n1 |\
tr -s ' ' |\
cut -d' ' -f3)
mdev=$(multipath -ll | head -n1 | cut -d' ' -f1)
mdev=$(multipath -ll | grep md_block0 | cut -d' ' -f1)
to_delete=$(lsblk | grep -B 1 $mdev | grep -v $mdev | cut -f1 -d ' ')
targetcli /iscsi/$iqn/tpg1/acls delete $hostiqn
targetcli /iscsi/$iqn/tpg1/portals delete 127.0.0.1 3260
Expand Down
5 changes: 4 additions & 1 deletion tests/unittests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,16 @@ def _mountVol(self, vol_name, pool_name, devices, mount):
_addVol.
"""
vol_path = "/dev/{0}/{1}".format(pool_name, vol_name)
real_dev = self.vol_data[vol_path]['real_dev']
self.vol_data[vol_path]['mount'] = mount
self.pool_data[pool_name]['mount'] = mount
self._addDir(mount)
self.mount_data[devices[0]] = {'dev': devices[0], 'mp': mount,
'root': "/"}
self.mount_data[vol_path] = {'dev': vol_path, 'mp': mount,
'root': "/"}
self.mount_data[real_dev] = {'dev': real_dev, 'mp': mount,
'root': "/"}

def _addVol(self, vol_name, vol_size, stripes, pool_name, devices,
mount=None, active=True, fstype=None):
Expand Down Expand Up @@ -380,4 +383,4 @@ def _addVol(self, vol_name, vol_size, stripes, pool_name, devices,
if fstype:
self.vol_data[vol_path]['fstype'] = fstype
if mount:
self._mountVol(vol_name, pool_name, devices, mount)
self._mountVol(vol_name, pool_name, devices, mount)
2 changes: 1 addition & 1 deletion tests/unittests/test_lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_lvm_mount(self):
self._addPool('my_pool', ['/dev/sdc2', '/dev/sdc3', '/dev/sdc1'])
self._addVol('vol001', 117283225, 1, 'default_pool', ['/dev/sda'],
'/mnt/test1')
self._addVol('vol002', 237284225, 1, 'my_pool', ['/dev/sda'])
self._addVol('vol002', 237284225, 1, 'my_pool', ['/dev/sda'], 'SWAP')

# Simple mount test
main.main("ssm mount /dev/default_pool/vol001 /mnt/test")
Expand Down
9 changes: 9 additions & 0 deletions tests/unittests/test_multipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,12 @@ def test_mp_mock_raw_data(self):
main.main("ssm list vol")
finally:
sys.stdout = self._stdout

def test_mp_mount(self):
self._mountVol('mpatha', self.vol_data['/dev/mapper/mpatha']['pool_name'],
['/dev/sda', '/dev/sdb'], '/mnt/test1')
self._mountVol('mpathb', self.vol_data['/dev/mapper/mpathb']['pool_name'],
["sdd", "sde", "sdf"], 'SWAP')
mp = MultipathDevice(options=self._options)
self.assertEqual(mp['mpatha']['mount'], '/mnt/test1')
self.assertEqual(mp['mpathb']['mount'], 'SWAP')