From cdb5ca1606a384b7810973701e6a4b6dcd19cff5 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2020 12:43:45 -0400 Subject: [PATCH 01/10] ssmlib: backends: add swap support to backends Just as volumes can be mounted, they can also be used as swap volumes. Add support for swap reporting to each available backend. Signed-off-by: John Pittman --- ssmlib/backends/crypt.py | 5 +++++ ssmlib/backends/lvm.py | 5 +++++ ssmlib/backends/md.py | 5 +++++ ssmlib/backends/multipath.py | 4 ++++ ssmlib/main.py | 3 +-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ssmlib/backends/crypt.py b/ssmlib/backends/crypt.py index 8d93fe9..a50e02c 100644 --- a/ssmlib/backends/crypt.py +++ b/ssmlib/backends/crypt.py @@ -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 \ @@ -197,6 +198,10 @@ 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" # 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 diff --git a/ssmlib/backends/lvm.py b/ssmlib/backends/lvm.py index 5ee57e5..e75a48b 100644 --- a/ssmlib/backends/lvm.py +++ b/ssmlib/backends/lvm.py @@ -410,6 +410,7 @@ 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): @@ -441,6 +442,10 @@ 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" self.parse_attr(lv, lv['attr']) def __getitem__(self, name): diff --git a/ssmlib/backends/md.py b/ssmlib/backends/md.py index de8d4ef..4f21636 100644 --- a/ssmlib/backends/md.py +++ b/ssmlib/backends/md.py @@ -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") @@ -81,6 +82,10 @@ 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" command = [MDADM, '--detail', devname] for line in misc.run(command, stderr=False)[1].split("\n"): array = line.split(":") diff --git a/ssmlib/backends/multipath.py b/ssmlib/backends/multipath.py index 66d9e80..0f46679 100644 --- a/ssmlib/backends/multipath.py +++ b/ssmlib/backends/multipath.py @@ -35,6 +35,7 @@ def __init__(self, options, data=None): self.options = options self.output = None self.problem = problem.ProblemSet(options) + self.swaps = misc.get_swaps() for mp_dev in self.get_mp_devices(): mpname = self.get_real_device(mp_dev) @@ -102,6 +103,9 @@ def get_volume_data(self, volname): data['dev_size'] = misc.get_device_size(data['dev_name']) data['nodes'] = [] data['total_nodes'] = 0 + for swap in self.swaps: + if swap[0] == data['dev_name']: + data['mount'] = "SWAP" for entry in zip(output[2::2],output[3::2]): """ Some string operations to remove the tree path symbols from the output. """ diff --git a/ssmlib/main.py b/ssmlib/main.py index 5e99ae4..43f0681 100644 --- a/ssmlib/main.py +++ b/ssmlib/main.py @@ -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)) @@ -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" From e722c12dc211bdf497ff79536073a5986ed73a64 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2020 12:44:59 -0400 Subject: [PATCH 02/10] multipath: add mount support to multipath backend Currently the multipath backend is not configured to show the mount point. Add that support. Signed-off-by: John Pittman --- ssmlib/backends/multipath.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ssmlib/backends/multipath.py b/ssmlib/backends/multipath.py index 0f46679..3c5581c 100644 --- a/ssmlib/backends/multipath.py +++ b/ssmlib/backends/multipath.py @@ -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' @@ -36,6 +41,7 @@ def __init__(self, options, data=None): 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) @@ -103,9 +109,12 @@ def get_volume_data(self, volname): data['dev_size'] = misc.get_device_size(data['dev_name']) data['nodes'] = [] data['total_nodes'] = 0 - for swap in self.swaps: - if swap[0] == data['dev_name']: - data['mount'] = "SWAP" + 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" for entry in zip(output[2::2],output[3::2]): """ Some string operations to remove the tree path symbols from the output. """ From 7509b7e39e760c5c3177952ee42f31cca6677173 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2020 12:45:56 -0400 Subject: [PATCH 03/10] ssm: correct all misspellings of additional In several places additional is incorrectly spelled "aditional". Correct these misspellings. Signed-off-by: John Pittman --- ssmlib/backends/lvm.py | 14 +++++++------- ssmlib/main.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ssmlib/backends/lvm.py b/ssmlib/backends/lvm.py index e75a48b..f7897a6 100644 --- a/ssmlib/backends/lvm.py +++ b/ssmlib/backends/lvm.py @@ -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): @@ -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']) @@ -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 @@ -413,7 +413,7 @@ def __init__(self, *args, **kwargs): 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 \ @@ -545,7 +545,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 @@ -604,7 +604,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']) diff --git a/ssmlib/main.py b/ssmlib/main.py index 43f0681..e603d4d 100644 --- a/ssmlib/main.py +++ b/ssmlib/main.py @@ -2607,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 " + From b4a46b7412deb7e2ecc0e2aef9d67cc73a4247c6 Mon Sep 17 00:00:00 2001 From: John Pittman Date: Tue, 14 Apr 2020 16:13:26 -0400 Subject: [PATCH 04/10] unittests: add multipath mount test Add test verifying mount check routine within get_volume_data() method from multipath backend. Also add real_dev listing to mount_data as it is needed in get_volume_data() check and fix a newline error. Signed-off-by: John Pittman --- tests/unittests/common.py | 5 ++++- tests/unittests/test_multipath.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unittests/common.py b/tests/unittests/common.py index 5495e22..91369a7 100644 --- a/tests/unittests/common.py +++ b/tests/unittests/common.py @@ -308,6 +308,7 @@ 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) @@ -315,6 +316,8 @@ def _mountVol(self, vol_name, pool_name, devices, 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): @@ -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) \ No newline at end of file + self._mountVol(vol_name, pool_name, devices, mount) diff --git a/tests/unittests/test_multipath.py b/tests/unittests/test_multipath.py index 7239c2a..f27058b 100644 --- a/tests/unittests/test_multipath.py +++ b/tests/unittests/test_multipath.py @@ -198,3 +198,9 @@ 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') + mp = MultipathDevice(options=self._options) + self.assertEqual(mp['mpatha']['mount'], '/mnt/test1') From da891a01be851e0b13b04e18ba21b4d1028177c1 Mon Sep 17 00:00:00 2001 From: John Pittman Date: Fri, 17 Apr 2020 15:37:20 -0400 Subject: [PATCH 05/10] unittests: add swap mount tests in available unittests Add a basic volume swap test to the two available unittests, lvm and multipath. Signed-off-by: John Pittman --- tests/unittests/test_lvm.py | 2 +- tests/unittests/test_multipath.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unittests/test_lvm.py b/tests/unittests/test_lvm.py index 6489ba8..e0e7719 100644 --- a/tests/unittests/test_lvm.py +++ b/tests/unittests/test_lvm.py @@ -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") diff --git a/tests/unittests/test_multipath.py b/tests/unittests/test_multipath.py index f27058b..b493adc 100644 --- a/tests/unittests/test_multipath.py +++ b/tests/unittests/test_multipath.py @@ -202,5 +202,8 @@ def test_mp_mock_raw_data(self): 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') From 514838c7e03e05bbbf2db36723bea27d6378ec07 Mon Sep 17 00:00:00 2001 From: John Pittman Date: Wed, 22 Apr 2020 11:35:52 -0400 Subject: [PATCH 06/10] bashtests: add LUKS2 support to crypt bashtests The check for type was hard coded to LUKS1. Add support for LUKS2 by adding a helper function to grab the version from luksDump and implement the function across the individual commands. Signed-off-by: John Pittman --- tests/bashtests/012-crypt-create.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/bashtests/012-crypt-create.sh b/tests/bashtests/012-crypt-create.sh index b668339..1819715 100755 --- a/tests/bashtests/012-crypt-create.sh +++ b/tests/bashtests/012-crypt-create.sh @@ -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 @@ -67,17 +72,17 @@ 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 +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 @@ -115,16 +120,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 @@ -138,7 +143,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 @@ -161,7 +166,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 From 33ea7db64509aa26e16a4854df1076735caad90e Mon Sep 17 00:00:00 2001 From: John Pittman Date: Wed, 22 Apr 2020 15:50:13 -0400 Subject: [PATCH 07/10] bashtests: add swap check for crypt volumes Add test for crypt volume initialized as swap. Also add the swap commands to the dependency check in test.py. Signed-off-by: John Pittman --- test.py | 5 ++++- tests/bashtests/012-crypt-create.sh | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index 721fe08..c1be10f 100755 --- a/test.py +++ b/test.py @@ -88,7 +88,10 @@ def check_system_dependencies(): 'lvm', 'dmsetup', 'cryptsetup', - 'multipath' + 'multipath', + 'mkswap', + 'swapon', + 'swapoff' ] missing = [] diff --git a/tests/bashtests/012-crypt-create.sh b/tests/bashtests/012-crypt-create.sh index 1819715..c1a0ed5 100755 --- a/tests/bashtests/012-crypt-create.sh +++ b/tests/bashtests/012-crypt-create.sh @@ -82,9 +82,11 @@ 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 +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 From 5f7dc4d40d2a3f9388938e0011a5e82aebf1ee75 Mon Sep 17 00:00:00 2001 From: John Pittman Date: Tue, 28 Apr 2020 15:15:59 -0400 Subject: [PATCH 08/10] bashtests: settle udev after configuring multipath Since we're not sure when the multipath devices are fully created along with sub-paths, we need to ensure that udev is settled prior to exiting mpath_setup(). Otherwise the rest of the script can become racy. Also add udevadm to binary check as we need this command. Signed-off-by: John Pittman --- test.py | 3 ++- tests/bashtests/lib/mpath.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index c1be10f..59847a1 100755 --- a/test.py +++ b/test.py @@ -91,7 +91,8 @@ def check_system_dependencies(): 'multipath', 'mkswap', 'swapon', - 'swapoff' + 'swapoff', + 'udevadm' ] missing = [] diff --git a/tests/bashtests/lib/mpath.sh b/tests/bashtests/lib/mpath.sh index f270068..36030c3 100644 --- a/tests/bashtests/lib/mpath.sh +++ b/tests/bashtests/lib/mpath.sh @@ -26,6 +26,7 @@ mpath_setup() { 1>&2 echo "An error occured with multipath configuration." return 1 fi + udevadm settle --timeout 15 return 0 } From 5b89190abf085e46518954d7c3a95910c19669ba Mon Sep 17 00:00:00 2001 From: John Pittman Date: Tue, 28 Apr 2020 16:32:53 -0400 Subject: [PATCH 09/10] bashtests: ignore mpath devices outside testing If the multipath bashtests are run on a system that already has multipath devices present, the tests will grab the wrong devices. Ensure the tests only look at the multipath device we have created. Also, as the multipath tests require targetcli and iscsiadm, add those to the system dependencies list and fix a newline error as well. Signed-off-by: John Pittman --- test.py | 4 +++- tests/bashtests/016-multipath.sh | 8 ++++---- tests/bashtests/lib/mpath.sh | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test.py b/test.py index 59847a1..2ec98e1 100755 --- a/test.py +++ b/test.py @@ -92,7 +92,9 @@ def check_system_dependencies(): 'mkswap', 'swapon', 'swapoff', - 'udevadm' + 'udevadm', + 'targetcli', + 'iscsiadm' ] missing = [] diff --git a/tests/bashtests/016-multipath.sh b/tests/bashtests/016-multipath.sh index a8e8855..b11372a 100755 --- a/tests/bashtests/016-multipath.sh +++ b/tests/bashtests/016-multipath.sh @@ -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 @@ -93,4 +93,4 @@ not ssm -f remove $DM not ssm -b multipath list not ssm -b multipath create $dev1 -exit 0 \ No newline at end of file +exit 0 diff --git a/tests/bashtests/lib/mpath.sh b/tests/bashtests/lib/mpath.sh index 36030c3..493fa89 100644 --- a/tests/bashtests/lib/mpath.sh +++ b/tests/bashtests/lib/mpath.sh @@ -79,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 From 14de320c11bad100a52473698daa06b70bccff90 Mon Sep 17 00:00:00 2001 From: John Pittman Date: Mon, 4 May 2020 11:41:10 -0400 Subject: [PATCH 10/10] ssmlib: backends: break after matching swaps As currently written, when attempting to match swaps, after the match, the loop will continue to iterate. This is unneeded. Correct by breaking from loop once a match is found. Signed-off-by: John Pittman --- ssmlib/backends/crypt.py | 1 + ssmlib/backends/lvm.py | 1 + ssmlib/backends/md.py | 1 + ssmlib/backends/multipath.py | 1 + 4 files changed, 4 insertions(+) diff --git a/ssmlib/backends/crypt.py b/ssmlib/backends/crypt.py index a50e02c..b5e6554 100644 --- a/ssmlib/backends/crypt.py +++ b/ssmlib/backends/crypt.py @@ -202,6 +202,7 @@ def __init__(self, *args, **kwargs): for swap in self.swaps: if swap[0] == dm['real_dev']: dm['mount'] = "SWAP" + 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 diff --git a/ssmlib/backends/lvm.py b/ssmlib/backends/lvm.py index f7897a6..0668464 100644 --- a/ssmlib/backends/lvm.py +++ b/ssmlib/backends/lvm.py @@ -446,6 +446,7 @@ def _fill_additional_info(self, lv): 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): diff --git a/ssmlib/backends/md.py b/ssmlib/backends/md.py index 4f21636..277797f 100644 --- a/ssmlib/backends/md.py +++ b/ssmlib/backends/md.py @@ -86,6 +86,7 @@ def get_volume_data(self, devname): 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(":") diff --git a/ssmlib/backends/multipath.py b/ssmlib/backends/multipath.py index 3c5581c..ba877cc 100644 --- a/ssmlib/backends/multipath.py +++ b/ssmlib/backends/multipath.py @@ -115,6 +115,7 @@ def get_volume_data(self, volname): 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. """