Michael Hudson-Doyle has proposed merging ~mwhudson/curtin:dead-code into curtin:master.
Commit message: remove some unused code Requested reviews: curtin developers (curtin-dev) For more details, see: https://code.launchpad.net/~mwhudson/curtin/+git/curtin/+merge/396115 My other ongoing curtin changes seem to be heading off into the weeds sadly, so here's something a little bit simpler, hopefully. -- Your team curtin developers is requested to review the proposed merge of ~mwhudson/curtin:dead-code into curtin:master.
diff --git a/curtin/block/__init__.py b/curtin/block/__init__.py index 0cf0866..2c1cc7c 100644 --- a/curtin/block/__init__.py +++ b/curtin/block/__init__.py @@ -2,7 +2,6 @@ import re from contextlib import contextmanager import errno -import itertools import os import stat import sys @@ -692,28 +691,6 @@ def get_scsi_wwid(device, replace_whitespace=False): return None -def get_multipath_wwids(): - """ - Get WWIDs of all multipath devices available in the system. - """ - multipath_devices = set() - multipath_wwids = set() - devuuids = [(d, i['UUID']) for d, i in blkid().items() if 'UUID' in i] - # Looking for two disks which contain filesystems with the same UUID. - for (dev1, uuid1), (dev2, uuid2) in itertools.combinations(devuuids, 2): - if uuid1 == uuid2: - multipath_devices.add(get_blockdev_for_partition(dev1)[0]) - for device in multipath_devices: - wwid = get_scsi_wwid(device) - # Function get_scsi_wwid() may return None in case of errors or - # WWID field may be empty for some buggy disk. We don't want to - # propagate both of these value further to avoid generation of - # incorrect /etc/multipath/bindings file. - if wwid: - multipath_wwids.add(wwid) - return multipath_wwids - - def get_root_device(dev, paths=None): """ Get root partition for specified device, based on presence of any @@ -812,20 +789,6 @@ def get_volume_uuid(path): return '' -def get_mountpoints(): - """ - Returns a list of all mountpoints where filesystems are currently mounted. - """ - info = _lsblock() - proc_mounts = [mp for (dev, mp, vfs, opts, freq, passno) in - get_proc_mounts()] - lsblock_mounts = list(i.get("MOUNTPOINT") for name, i in info.items() if - i.get("MOUNTPOINT") is not None and - i.get("MOUNTPOINT") != "") - - return list(set(proc_mounts + lsblock_mounts)) - - def get_proc_mounts(): """ Returns a list of tuples for each entry in /proc/mounts @@ -885,15 +848,6 @@ def disk_to_byid_path(kname): return mapping.get(dev_path(kname)) -def disk_to_bypath_path(kname): - """" - Return a /dev/disk/by-path path to kname if present. - """ - - mapping = _get_dev_disk_by_prefix('/dev/disk/by-path') - return mapping.get(dev_path(kname)) - - def get_device_mapper_links(devpath, first=False): """ Return the best devlink to device at devpath. """ info = udevadm_info(devpath) @@ -946,30 +900,6 @@ def lookup_disk(serial): return path -def lookup_dasd(bus_id): - """ - Search for a dasd by its bus_id. - - :param bus_id: s390x ccw bus_id 0.0.NNNN specifying the dasd - :returns: dasd kernel device path (/dev/dasda) - """ - - LOG.info('Processing ccw bus_id %s', bus_id) - sys_ccw_dev = '/sys/bus/ccw/devices/%s/block' % bus_id - if not os.path.exists(sys_ccw_dev): - raise ValueError('Failed to find a block device at %s' % sys_ccw_dev) - - dasds = os.listdir(sys_ccw_dev) - if not dasds or len(dasds) < 1: - raise ValueError("no dasd with device_id '%s' found" % bus_id) - - path = '/dev/%s' % dasds[0] - if not os.path.exists(path): - raise ValueError("path '%s' to block device for dasd with bus_id '%s' \ - does not exist" % (path, bus_id)) - return path - - def sysfs_partition_data(blockdev=None, sysfs_path=None): # given block device or sysfs_path, return a list of tuples # of (kernel_name, number, offset, size) diff --git a/curtin/block/bcache.py b/curtin/block/bcache.py index c1a8d26..581379f 100644 --- a/curtin/block/bcache.py +++ b/curtin/block/bcache.py @@ -155,17 +155,6 @@ def get_cacheset_members(cset_uuid): return members -def get_cacheset_cachedev(cset_uuid): - """ Return a sysfs path to a cacheset cache device's bcache dir.""" - - # XXX: bcache cachesets only have a single cache0 entry - cachedev = '/sys/fs/bcache/%s/cache0' % cset_uuid - if os.path.exists(cachedev): - return os.path.realpath(cachedev) - - return None - - def attach_backing_to_cacheset(backing_device, cache_device, cset_uuid): LOG.info("Attaching backing device to cacheset: " "{} -> {} cset.uuid: {}".format(backing_device, cache_device, diff --git a/curtin/block/iscsi.py b/curtin/block/iscsi.py index 3c46500..0e4ee17 100644 --- a/curtin/block/iscsi.py +++ b/curtin/block/iscsi.py @@ -225,11 +225,6 @@ def ensure_disk_connected(rfc4173, write_config=True): return iscsi_disk -def connected_disks(): - global _ISCSI_DISKS - return _ISCSI_DISKS - - def get_iscsi_volumes_from_config(cfg): """Parse a curtin storage config and return a list of iscsi disk rfc4173 uris for each configuration present. @@ -267,33 +262,6 @@ def get_iscsi_ports_from_config(cfg): return ports -def disconnect_target_disks(target_root_path=None): - target_nodes_path = paths.target_path(target_root_path, '/etc/iscsi/nodes') - fails = [] - if os.path.isdir(target_nodes_path): - for target in os.listdir(target_nodes_path): - if target not in iscsiadm_sessions(): - LOG.debug('iscsi target %s not active, skipping', target) - continue - # conn is "host,port,lun" - for conn in os.listdir( - os.path.sep.join([target_nodes_path, target])): - host, port, _ = conn.split(',') - try: - util.subp(['sync']) - iscsiadm_logout(target, '%s:%s' % (host, port)) - except util.ProcessExecutionError as e: - fails.append(target) - LOG.warn("Unable to logout of iSCSI target %s: %s", - target, e) - else: - LOG.warning('Skipping disconnect: failed to find iscsi nodes path: %s', - target_nodes_path) - if fails: - raise RuntimeError( - "Unable to logout of iSCSI targets: %s" % ', '.join(fails)) - - # Determines if a /dev/disk/by-path symlink matching the udev pattern # for iSCSI disks is pointing at @kname def kname_is_iscsi(kname): diff --git a/curtin/block/mdadm.py b/curtin/block/mdadm.py index a6ac970..fd26752 100644 --- a/curtin/block/mdadm.py +++ b/curtin/block/mdadm.py @@ -92,11 +92,6 @@ READWRITE_RAID_STATES = [ 'write-pending', ] -VALID_RAID_ARRAY_STATES = ( - ERROR_RAID_STATES + - READONLY_RAID_STATES + - READWRITE_RAID_STATES -) # need a on-import check of version and set the value for later reference ''' mdadm version < 3.3 doesn't include enough info when using --export @@ -353,15 +348,6 @@ def mdadm_stop(devpath, retries=None): raise OSError('Failed to stop mdadm device %s', devpath) -def mdadm_remove(devpath): - assert_valid_devpath(devpath) - - LOG.info("mdadm removing: %s" % devpath) - out, err = util.subp(["mdadm", "--remove", devpath], - rcs=[0], capture=True) - LOG.debug("mdadm remove:\n%s\n%s", out, err) - - def fail_device(mddev, arraydev): assert_valid_devpath(mddev) @@ -559,14 +545,6 @@ def md_check_array_state_rw(md_devname): return __md_check_array_state(md_devname, mode='READWRITE') -def md_check_array_state_ro(md_devname): - return __md_check_array_state(md_devname, mode='READONLY') - - -def md_check_array_state_error(md_devname): - return __md_check_array_state(md_devname, mode='ERROR') - - def __mdadm_export_to_dict(output): ''' convert Key=Value text output into dictionary ''' return dict(tok.split('=', 1) for tok in shlex.split(output)) @@ -633,81 +611,6 @@ def __mdadm_detail_to_dict(input): return data -def md_device_key_role(devname): - if not devname: - raise ValueError('Missing parameter devname') - return 'MD_DEVICE_' + dev_short(devname) + '_ROLE' - - -def md_device_key_dev(devname): - if not devname: - raise ValueError('Missing parameter devname') - return 'MD_DEVICE_' + dev_short(devname) + '_DEV' - - -def __upgrade_detail_dict(detail): - ''' This method attempts to convert mdadm --detail output into - a KEY=VALUE output the same as mdadm --detail --export from mdadm v3.3 - ''' - # if the input already has MD_UUID, it's already been converted - if 'MD_UUID' in detail: - return detail - - md_detail = { - 'MD_LEVEL': detail['raid_level'], - 'MD_DEVICES': detail['raid_devices'], - 'MD_METADATA': detail['version'], - 'MD_NAME': detail['name'].split()[0], - } - - # exmaine has ARRAY UUID - if 'array_uuid' in detail: - md_detail.update({'MD_UUID': detail['array_uuid']}) - # query,detail has UUID - elif 'uuid' in detail: - md_detail.update({'MD_UUID': detail['uuid']}) - - device = detail['device'] - - # MD_DEVICE_vdc1_DEV=/dev/vdc1 - md_detail.update({md_device_key_dev(device): device}) - - if 'device_role' in detail: - role = detail['device_role'] - if role != 'spare': - # device_role = Active device 1 - role = role.split()[-1] - - # MD_DEVICE_vdc1_ROLE=spare - md_detail.update({md_device_key_role(device): role}) - - return md_detail - - -def md_read_run_mdadm_map(): - ''' - md1 1.2 59beb40f:4c202f67:088e702b:efdf577a /dev/md1 - md0 0.90 077e6a9e:edf92012:e2a6e712:b193f786 /dev/md0 - - return - # md_shortname = (metaversion, md_uuid, md_devpath) - data = { - 'md1': (1.2, 59beb40f:4c202f67:088e702b:efdf577a, /dev/md1) - 'md0': (0.90, 077e6a9e:edf92012:e2a6e712:b193f786, /dev/md0) - ''' - - mdadm_map = {} - run_mdadm_map = '/run/mdadm/map' - if os.path.exists(run_mdadm_map): - with open(run_mdadm_map, 'r') as fp: - data = fp.read().strip() - for entry in data.split('\n'): - (key, meta, md_uuid, dev) = entry.split() - mdadm_map.update({key: (meta, md_uuid, dev)}) - - return mdadm_map - - def md_check_array_uuid(md_devname, md_uuid): valid_mdname(md_devname) @@ -750,22 +653,6 @@ def md_check_raidlevel(raidlevel): return True -def md_block_until_in_sync(md_devname): - ''' - sync_completed - This shows the number of sectors that have been completed of - whatever the current sync_action is, followed by the number of - sectors in total that could need to be processed. The two - numbers are separated by a '/' thus effectively showing one - value, a fraction of the process that is complete. - A 'select' on this attribute will return when resync completes, - when it reaches the current sync_max (below) and possibly at - other times. - ''' - # FIXME: use selectors to block on: /sys/class/block/mdX/md/sync_completed - pass - - def md_check_array_state(md_devname): # check array state diff --git a/curtin/block/multipath.py b/curtin/block/multipath.py index 7ad1791..8010f29 100644 --- a/curtin/block/multipath.py +++ b/curtin/block/multipath.py @@ -88,15 +88,6 @@ def is_mpath_partition(devpath, info=None): return result -def mpath_partition_to_mpath_id(devpath): - """ Return the mpath id of a multipath partition. """ - info = udev.udevadm_info(devpath) - if 'DM_MPATH' in info: - return info['DM_MPATH'] - - return None - - def remove_partition(devpath, retries=10): """ Remove a multipath partition mapping. """ LOG.debug('multipath: removing multipath partition: %s', devpath) @@ -109,36 +100,6 @@ def remove_partition(devpath, retries=10): util.wait_for_removal(devpath) -def remove_map(map_id, retries=10): - """ Remove a multipath device mapping. """ - LOG.debug('multipath: removing multipath map: %s', map_id) - devpath = '/dev/mapper/%s' % map_id - for _ in range(0, retries): - util.subp(['multipath', '-v3', '-R3', '-f', map_id], rcs=[0, 1]) - udev.udevadm_settle() - if not os.path.exists(devpath): - return - - util.wait_for_removal(devpath) - - -def find_mpath_members(multipath_id, paths=None): - """ Return a list of device path for each member of aspecified mpath_id.""" - if not paths: - paths = show_paths() - for retry in range(0, 5): - orphans = [path for path in paths if 'orphan' in path['multipath']] - if len(orphans): - udev.udevadm_settle() - paths = show_paths() - else: - break - - members = ['/dev/' + path['device'] - for path in paths if path['multipath'] == multipath_id] - return members - - def find_mpath_id(devpath, maps=None): """ Return the mpath_id associated with a specified device path. """ if not maps: @@ -170,17 +131,6 @@ def find_mpath_id_by_path(devpath, paths=None): return None -def find_mpath_id_by_parent(multipath_id, partnum=None): - """ Return the mpath_id associated with a specified device path. """ - devmap = dmname_to_blkdev_mapping() - LOG.debug('multipath: dm_name blk map: %s', devmap) - dm_name = multipath_id - if partnum: - dm_name += "-part%d" % int(partnum) - - return (dm_name, devmap.get(dm_name)) - - def find_mpath_partitions(mpath_id): """ Return a generator of multipath ids which are partitions of 'mpath-id' diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py index 4cf7301..46af022 100644 --- a/curtin/commands/curthooks.py +++ b/curtin/commands/curthooks.py @@ -905,16 +905,6 @@ def copy_iscsi_conf(nodes_dir, target, target_nodes_dir='etc/iscsi/nodes'): shutil.copytree(source_dir, target_dir) -def copy_mdadm_conf(mdadm_conf, target): - if not mdadm_conf: - LOG.warn("mdadm config must be specified, not copying") - return - - LOG.info("copying mdadm.conf into target") - shutil.copy(mdadm_conf, os.path.sep.join([target, - 'etc/mdadm/mdadm.conf'])) - - def copy_zpool_cache(zpool_cache, target): if not zpool_cache: LOG.warn("zpool_cache path must be specified, not copying") diff --git a/curtin/net/__init__.py b/curtin/net/__init__.py index 3b02f9d..2b56f17 100644 --- a/curtin/net/__init__.py +++ b/curtin/net/__init__.py @@ -94,10 +94,6 @@ def is_physical(devname): return os.path.exists(sys_dev_path(devname, "device")) -def is_present(devname): - return os.path.exists(sys_dev_path(devname)) - - def get_devicelist(): return os.listdir(SYS_CLASS_NET) diff --git a/tests/unittests/test_block.py b/tests/unittests/test_block.py index 78e331d..985700f 100644 --- a/tests/unittests/test_block.py +++ b/tests/unittests/test_block.py @@ -29,22 +29,6 @@ class TestBlock(CiTestCase): mock_util.subp.assert_called_with(expected_call, capture=True) self.assertEqual(uuid, "182e8e23-5322-46c9-a1b8-cf2c6a88f9f7") - @mock.patch("curtin.block.get_proc_mounts") - @mock.patch("curtin.block._lsblock") - def test_get_mountpoints(self, mock_lsblk, mock_proc_mounts): - mock_lsblk.return_value = {"sda1": {"MOUNTPOINT": None}, - "sda2": {"MOUNTPOINT": ""}, - "sda3": {"MOUNTPOINT": "/mnt"}} - mock_proc_mounts.return_value = [ - ('sysfs', '/sys', 'sysfs', 'sysfs_opts', '0', '0'), - ] - - mountpoints = block.get_mountpoints() - - self.assertTrue(mock_lsblk.called) - self.assertEqual(sorted(mountpoints), - sorted(["/mnt", "/sys"])) - @mock.patch('curtin.block._lsblock') def test_get_blockdev_sector_size(self, mock_lsblk): mock_lsblk.return_value = { diff --git a/tests/unittests/test_block_bcache.py b/tests/unittests/test_block_bcache.py index 7936522..ecb8046 100644 --- a/tests/unittests/test_block_bcache.py +++ b/tests/unittests/test_block_bcache.py @@ -271,19 +271,6 @@ class TestBlockBcache(CiTestCase): self.assertEqual([bdev_target], results) m_listdir.assert_called_with(cset_path) - @mock.patch('curtin.block.bcache.os.path.exists') - @mock.patch('curtin.block.bcache.os.path.realpath') - def test_get_cacheset_cachedev(self, m_real, m_exists): - """ get_cacheset_cachedev finds cacheset device path.""" - cset_uuid = self.random_string() - cachedev_target = self.random_string() - cset_path = '/sys/fs/bcache/%s/cache0' % cset_uuid - m_exists.return_value = True - m_real.side_effect = iter([cachedev_target]) - results = bcache.get_cacheset_cachedev(cset_uuid) - self.assertEqual(cachedev_target, results) - m_real.assert_called_with(cset_path) - @mock.patch('curtin.block.bcache.is_backing') @mock.patch('curtin.block.bcache.sysfs_path') @mock.patch('curtin.block.bcache.os.listdir') diff --git a/tests/unittests/test_block_iscsi.py b/tests/unittests/test_block_iscsi.py index f8ef5d8..c5b5121 100644 --- a/tests/unittests/test_block_iscsi.py +++ b/tests/unittests/test_block_iscsi.py @@ -647,104 +647,4 @@ class TestBlockIscsiDiskFromConfig(CiTestCase): self.assertEqual(expected_iscsi_disks, iscsi_disks) -class TestBlockIscsiDisconnect(CiTestCase): - # test that when disconnecting iscsi targets we - # check that the target has an active session before - # issuing a disconnect command - - def setUp(self): - super(TestBlockIscsiDisconnect, self).setUp() - self.add_patch('curtin.block.iscsi.util.subp', 'mock_subp') - self.add_patch('curtin.block.iscsi.iscsiadm_sessions', - 'mock_iscsi_sessions') - # fake target_root + iscsi nodes dir - self.target_path = self.tmp_dir() - self.iscsi_nodes = os.path.join(self.target_path, 'etc/iscsi/nodes') - util.ensure_dir(self.iscsi_nodes) - - def _fmt_disconnect(self, target, portal): - return ['iscsiadm', '--mode=node', '--targetname=%s' % target, - '--portal=%s' % portal, '--logout'] - - def _setup_nodes(self, sessions, connection): - # setup iscsi_nodes dir (<fakeroot>/etc/iscsi/nodes) with content - for s in sessions: - sdir = os.path.join(self.iscsi_nodes, s) - connpath = os.path.join(sdir, connection) - util.ensure_dir(sdir) - util.write_file(connpath, content="") - - def test_disconnect_target_disk(self): - """Test iscsi disconnecting multiple sessions, all present""" - - sessions = [ - 'curtin-53ab23ff-a887-449a-80a8-288151208091', - 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5', - 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4', - 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9' - ] - connection = '10.245.168.20,16395,1' - self._setup_nodes(sessions, connection) - - self.mock_iscsi_sessions.return_value = "\n".join(sessions) - - iscsi.disconnect_target_disks(self.target_path) - - expected_calls = [] - for session in sessions: - (host, port, _) = connection.split(',') - disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port)) - calls = [ - mock.call(['sync']), - mock.call(disconnect, capture=True, log_captured=True), - mock.call(['udevadm', 'settle']), - ] - expected_calls.extend(calls) - - self.mock_subp.assert_has_calls(expected_calls, any_order=True) - - def test_disconnect_target_disk_skip_disconnected(self): - """Test iscsi does not attempt to disconnect already closed sessions""" - sessions = [ - 'curtin-53ab23ff-a887-449a-80a8-288151208091', - 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5', - 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4', - 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9' - ] - connection = '10.245.168.20,16395,1' - self._setup_nodes(sessions, connection) - # Test with all sessions are already disconnected - self.mock_iscsi_sessions.return_value = "" - - iscsi.disconnect_target_disks(self.target_path) - - self.mock_subp.assert_has_calls([], any_order=True) - - @mock.patch('curtin.block.iscsi.iscsiadm_logout') - def test_disconnect_target_disk_raises_runtime_error(self, mock_logout): - """Test iscsi raises RuntimeError if we fail to logout""" - sessions = [ - 'curtin-53ab23ff-a887-449a-80a8-288151208091', - ] - connection = '10.245.168.20,16395,1' - self._setup_nodes(sessions, connection) - self.mock_iscsi_sessions.return_value = "\n".join(sessions) - mock_logout.side_effect = util.ProcessExecutionError() - - with self.assertRaises(RuntimeError): - iscsi.disconnect_target_disks(self.target_path) - - expected_calls = [] - for session in sessions: - (host, port, _) = connection.split(',') - disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port)) - calls = [ - mock.call(['sync']), - mock.call(disconnect, capture=True, log_captured=True), - mock.call(['udevadm', 'settle']), - ] - expected_calls.extend(calls) - - self.mock_subp.assert_has_calls([], any_order=True) - # vi: ts=4 expandtab syntax=python diff --git a/tests/unittests/test_block_mdadm.py b/tests/unittests/test_block_mdadm.py index b04cf82..a6654ce 100644 --- a/tests/unittests/test_block_mdadm.py +++ b/tests/unittests/test_block_mdadm.py @@ -594,33 +594,6 @@ class TestBlockMdadmStop(CiTestCase): self.mock_util_write_file.assert_has_calls(expected_writes) -class TestBlockMdadmRemove(CiTestCase): - def setUp(self): - super(TestBlockMdadmRemove, self).setUp() - self.add_patch('curtin.block.mdadm.util', 'mock_util') - self.add_patch('curtin.block.mdadm.lsb_release', 'mock_lsb_release') - self.add_patch('curtin.block.mdadm.is_valid_device', 'mock_valid') - - # Common mock settings - self.mock_valid.return_value = True - self.mock_lsb_release.return_value = {'codename': 'xenial'} - self.mock_util.subp.side_effect = [ - ("", ""), # mdadm remove device - ] - - def test_mdadm_remove_no_devpath(self): - with self.assertRaises(ValueError): - mdadm.mdadm_remove(None) - - def test_mdadm_remove(self): - device = "/dev/vdc" - mdadm.mdadm_remove(device) - expected_calls = [ - call(["mdadm", "--remove", device], rcs=[0], capture=True), - ] - self.mock_util.subp.assert_has_calls(expected_calls) - - class TestBlockMdadmQueryDetail(CiTestCase): def setUp(self): super(TestBlockMdadmQueryDetail, self).setUp() @@ -716,7 +689,7 @@ class TestBlockMdadmDetailScan(CiTestCase): (self.scan_output, ""), # mdadm --detail --scan ] - def test_mdadm_remove(self): + def test_mdadm_detail_scan(self): data = mdadm.mdadm_detail_scan() expected_calls = [ call(["mdadm", "--detail", "--scan"], capture=True), @@ -724,7 +697,7 @@ class TestBlockMdadmDetailScan(CiTestCase): self.mock_util.subp.assert_has_calls(expected_calls) self.assertEqual(self.scan_output, data) - def test_mdadm_remove_error(self): + def test_mdadm_detail_scan_error(self): self.mock_util.subp.side_effect = [ ("wark", "error"), # mdadm --detail --scan ] @@ -825,50 +798,6 @@ class TestBlockMdadmMdHelpers(CiTestCase): mock_attr.return_value = 'inactive' self.assertFalse(mdadm.md_check_array_state_rw(mdname)) - @patch('curtin.block.mdadm.md_sysfs_attr') - def test_md_check_array_state_ro(self, mock_attr): - mdname = '/dev/md0' - mock_attr.return_value = 'readonly' - self.assertTrue(mdadm.md_check_array_state_ro(mdname)) - - @patch('curtin.block.mdadm.md_sysfs_attr') - def test_md_check_array_state_ro_false(self, mock_attr): - mdname = '/dev/md0' - mock_attr.return_value = 'inactive' - self.assertFalse(mdadm.md_check_array_state_ro(mdname)) - - @patch('curtin.block.mdadm.md_sysfs_attr') - def test_md_check_array_state_error(self, mock_attr): - mdname = '/dev/md0' - mock_attr.return_value = 'inactive' - self.assertTrue(mdadm.md_check_array_state_error(mdname)) - - @patch('curtin.block.mdadm.md_sysfs_attr') - def test_md_check_array_state_error_false(self, mock_attr): - mdname = '/dev/md0' - mock_attr.return_value = 'active' - self.assertFalse(mdadm.md_check_array_state_error(mdname)) - - def test_md_device_key_role(self): - devname = '/dev/vda' - rolekey = mdadm.md_device_key_role(devname) - self.assertEqual('MD_DEVICE_vda_ROLE', rolekey) - - def test_md_device_key_role_no_dev(self): - devname = None - with self.assertRaises(ValueError): - mdadm.md_device_key_role(devname) - - def test_md_device_key_dev(self): - devname = '/dev/vda' - devkey = mdadm.md_device_key_dev(devname) - self.assertEqual('MD_DEVICE_vda_DEV', devkey) - - def test_md_device_key_dev_no_dev(self): - devname = None - with self.assertRaises(ValueError): - mdadm.md_device_key_dev(devname) - @patch('curtin.block.util.load_file') @patch('curtin.block.get_blockdev_for_partition') @patch('curtin.block.mdadm.os.path.exists') diff --git a/tests/unittests/test_block_multipath.py b/tests/unittests/test_block_multipath.py index 96cbcba..a729936 100644 --- a/tests/unittests/test_block_multipath.py +++ b/tests/unittests/test_block_multipath.py @@ -82,20 +82,6 @@ class TestMultipath(CiTestCase): """is_mpath_member returns false if DM_PART is not present for dev.""" self.assertFalse(multipath.is_mpath_partition(self.random_string())) - def test_mpath_partition_to_mpath_id(self): - """mpath_part_to_mpath_id extracts MD_MPATH value from mp partition.""" - dev = self.random_string() - mpath_id = self.random_string() - self.m_udev.udevadm_info.return_value = {'DM_MPATH': mpath_id} - self.assertEqual(mpath_id, - multipath.mpath_partition_to_mpath_id(dev)) - - def test_mpath_partition_to_mpath_id_none(self): - """mpath_part_to_mpath_id returns none if DM_MPATH missing.""" - dev = self.random_string() - self.m_udev.udevadm_info.return_value = {} - self.assertIsNone(multipath.mpath_partition_to_mpath_id(dev)) - @mock.patch('curtin.block.multipath.os.path.exists') @mock.patch('curtin.block.multipath.util.wait_for_removal') def test_remove_partition(self, m_wait, m_exists): @@ -122,52 +108,6 @@ class TestMultipath(CiTestCase): self.assertEqual(3, self.m_udev.udevadm_settle.call_count) self.assertEqual(1, m_wait.call_count) - @mock.patch('curtin.block.multipath.os.path.exists') - @mock.patch('curtin.block.multipath.util.wait_for_removal') - def test_remove_map(self, m_wait, m_exists): - """multipath.remove_map runs multipath -f skips wait if map gone.""" - map_id = self.random_string() - devpath = '/dev/mapper/%s' % map_id - m_exists.side_effect = iter([True, True, False]) - multipath.remove_map(devpath) - expected = mock.call( - ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1]) - self.m_subp.assert_has_calls([expected] * 3) - m_wait.assert_not_called() - self.assertEqual(3, self.m_udev.udevadm_settle.call_count) - - @mock.patch('curtin.block.multipath.os.path.exists') - @mock.patch('curtin.block.multipath.util.wait_for_removal') - def test_remove_map_wait(self, m_wait, m_exists): - """multipath.remove_map runs multipath -f wait if map remains.""" - map_id = self.random_string() - devpath = '/dev/mapper/%s' % map_id - m_exists.side_effect = iter([True, True, True]) - multipath.remove_map(devpath, retries=3) - expected = mock.call( - ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1]) - self.m_subp.assert_has_calls([expected] * 3) - self.assertEqual(3, self.m_udev.udevadm_settle.call_count) - self.assertEqual(1, m_wait.call_count) - - def test_find_mpath_members(self): - """find_mpath_members enumerates kernel block devs of a mpath_id.""" - mp_id = 'mpatha' - paths = ['device=bar multipath=mpatha', - 'device=wark multipath=mpatha'] - self.m_subp.return_value = ("\n".join(paths), "") - self.assertEqual(sorted(['/dev/bar', '/dev/wark']), - sorted(multipath.find_mpath_members(mp_id))) - - def test_find_mpath_members_empty(self): - """find_mpath_members returns empty list if mpath_id not found.""" - mp_id = self.random_string() - paths = ['device=bar multipath=mpatha', - 'device=wark multipath=mpatha'] - self.m_subp.return_value = ("\n".join(paths), "") - - self.assertEqual([], multipath.find_mpath_members(mp_id)) - def test_find_mpath_id(self): """find_mpath_id returns mpath_id if device is part of mpath group.""" mp_id = 'mpatha' @@ -209,18 +149,6 @@ class TestMultipath(CiTestCase): self.assertEqual(expected_mapping, multipath.dmname_to_blkdev_mapping()) - @mock.patch('curtin.block.multipath.dmname_to_blkdev_mapping') - def test_find_mpath_id_by_parent(self, m_dmmap): - """find_mpath_id_by_parent returns device mapper blk for given DM_NAME. - """ - m_dmmap.return_value = { - 'mpatha': '/dev/dm-0', 'mpatha-part1': '/dev/dm-1'} - mpath_id = 'mpatha' - expected_result = ('mpatha-part1', '/dev/dm-1') - self.assertEqual( - expected_result, - multipath.find_mpath_id_by_parent(mpath_id, partnum=1)) - def test_find_mpath_id_by_path(self): """find_mpath_id_by_path returns the mp_id if specified device is member.
-- Mailing list: https://launchpad.net/~curtin-dev Post to : curtin-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~curtin-dev More help : https://help.launchpad.net/ListHelp