Merge ~mwhudson/curtin:dead-code into curtin:master

Proposed by Michael Hudson-Doyle
Status: Needs review
Proposed branch: ~mwhudson/curtin:dead-code
Merge into: curtin:master
Diff against target: 828 lines (+3/-567)
12 files modified
curtin/block/__init__.py (+0/-70)
curtin/block/bcache.py (+0/-11)
curtin/block/iscsi.py (+1/-33)
curtin/block/mdadm.py (+0/-113)
curtin/block/multipath.py (+0/-50)
curtin/commands/curthooks.py (+0/-10)
curtin/net/__init__.py (+0/-4)
tests/unittests/test_block.py (+0/-16)
tests/unittests/test_block_bcache.py (+0/-13)
tests/unittests/test_block_iscsi.py (+0/-102)
tests/unittests/test_block_mdadm.py (+2/-73)
tests/unittests/test_block_multipath.py (+0/-72)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
curtin developers Pending
Review via email: mp+396115@code.launchpad.net

Commit message

remove some unused code

Description of the change

My other ongoing curtin changes seem to be heading off into the weeds sadly, so here's something a little bit simpler, hopefully.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
~mwhudson/curtin:dead-code updated
3ba0d9e... by Michael Hudson-Doyle

fix flakes

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Dan Bungert (dbungert) wrote :

Is this still interesting?

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I'm all in favour of deleting unused code, but I guess I should probably be more piecemeal.

Unmerged commits

3ba0d9e... by Michael Hudson-Doyle

fix flakes

c942b26... by Michael Hudson-Doyle

remove unused code from curtin/net/__init__.py

5ee0119... by Michael Hudson-Doyle

remove unused code from curtin/commands/curthooks.py

9dba3c5... by Michael Hudson-Doyle

remove unused code from curtin/block/bcache.py

29cf3d7... by Michael Hudson-Doyle

remove unused code from curtin/block/multipath.py

a706ed3... by Michael Hudson-Doyle

remove unused code from curtin/block/mdadm.py

8f93aec... by Michael Hudson-Doyle

remove unused functions from curtin/block/iscsi.py

b9f2b53... by Michael Hudson-Doyle

remove unused functions from curtin/block/__init__.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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 @@
2import re2import re
3from contextlib import contextmanager3from contextlib import contextmanager
4import errno4import errno
5import itertools
6import os5import os
7import stat6import stat
8import sys7import sys
@@ -692,28 +691,6 @@ def get_scsi_wwid(device, replace_whitespace=False):
692 return None691 return None
693692
694693
695def get_multipath_wwids():
696 """
697 Get WWIDs of all multipath devices available in the system.
698 """
699 multipath_devices = set()
700 multipath_wwids = set()
701 devuuids = [(d, i['UUID']) for d, i in blkid().items() if 'UUID' in i]
702 # Looking for two disks which contain filesystems with the same UUID.
703 for (dev1, uuid1), (dev2, uuid2) in itertools.combinations(devuuids, 2):
704 if uuid1 == uuid2:
705 multipath_devices.add(get_blockdev_for_partition(dev1)[0])
706 for device in multipath_devices:
707 wwid = get_scsi_wwid(device)
708 # Function get_scsi_wwid() may return None in case of errors or
709 # WWID field may be empty for some buggy disk. We don't want to
710 # propagate both of these value further to avoid generation of
711 # incorrect /etc/multipath/bindings file.
712 if wwid:
713 multipath_wwids.add(wwid)
714 return multipath_wwids
715
716
717def get_root_device(dev, paths=None):694def get_root_device(dev, paths=None):
718 """695 """
719 Get root partition for specified device, based on presence of any696 Get root partition for specified device, based on presence of any
@@ -812,20 +789,6 @@ def get_volume_uuid(path):
812 return ''789 return ''
813790
814791
815def get_mountpoints():
816 """
817 Returns a list of all mountpoints where filesystems are currently mounted.
818 """
819 info = _lsblock()
820 proc_mounts = [mp for (dev, mp, vfs, opts, freq, passno) in
821 get_proc_mounts()]
822 lsblock_mounts = list(i.get("MOUNTPOINT") for name, i in info.items() if
823 i.get("MOUNTPOINT") is not None and
824 i.get("MOUNTPOINT") != "")
825
826 return list(set(proc_mounts + lsblock_mounts))
827
828
829def get_proc_mounts():792def get_proc_mounts():
830 """793 """
831 Returns a list of tuples for each entry in /proc/mounts794 Returns a list of tuples for each entry in /proc/mounts
@@ -885,15 +848,6 @@ def disk_to_byid_path(kname):
885 return mapping.get(dev_path(kname))848 return mapping.get(dev_path(kname))
886849
887850
888def disk_to_bypath_path(kname):
889 """"
890 Return a /dev/disk/by-path path to kname if present.
891 """
892
893 mapping = _get_dev_disk_by_prefix('/dev/disk/by-path')
894 return mapping.get(dev_path(kname))
895
896
897def get_device_mapper_links(devpath, first=False):851def get_device_mapper_links(devpath, first=False):
898 """ Return the best devlink to device at devpath. """852 """ Return the best devlink to device at devpath. """
899 info = udevadm_info(devpath)853 info = udevadm_info(devpath)
@@ -946,30 +900,6 @@ def lookup_disk(serial):
946 return path900 return path
947901
948902
949def lookup_dasd(bus_id):
950 """
951 Search for a dasd by its bus_id.
952
953 :param bus_id: s390x ccw bus_id 0.0.NNNN specifying the dasd
954 :returns: dasd kernel device path (/dev/dasda)
955 """
956
957 LOG.info('Processing ccw bus_id %s', bus_id)
958 sys_ccw_dev = '/sys/bus/ccw/devices/%s/block' % bus_id
959 if not os.path.exists(sys_ccw_dev):
960 raise ValueError('Failed to find a block device at %s' % sys_ccw_dev)
961
962 dasds = os.listdir(sys_ccw_dev)
963 if not dasds or len(dasds) < 1:
964 raise ValueError("no dasd with device_id '%s' found" % bus_id)
965
966 path = '/dev/%s' % dasds[0]
967 if not os.path.exists(path):
968 raise ValueError("path '%s' to block device for dasd with bus_id '%s' \
969 does not exist" % (path, bus_id))
970 return path
971
972
973def sysfs_partition_data(blockdev=None, sysfs_path=None):903def sysfs_partition_data(blockdev=None, sysfs_path=None):
974 # given block device or sysfs_path, return a list of tuples904 # given block device or sysfs_path, return a list of tuples
975 # of (kernel_name, number, offset, size)905 # 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):
155 return members155 return members
156156
157157
158def get_cacheset_cachedev(cset_uuid):
159 """ Return a sysfs path to a cacheset cache device's bcache dir."""
160
161 # XXX: bcache cachesets only have a single cache0 entry
162 cachedev = '/sys/fs/bcache/%s/cache0' % cset_uuid
163 if os.path.exists(cachedev):
164 return os.path.realpath(cachedev)
165
166 return None
167
168
169def attach_backing_to_cacheset(backing_device, cache_device, cset_uuid):158def attach_backing_to_cacheset(backing_device, cache_device, cset_uuid):
170 LOG.info("Attaching backing device to cacheset: "159 LOG.info("Attaching backing device to cacheset: "
171 "{} -> {} cset.uuid: {}".format(backing_device, cache_device,160 "{} -> {} cset.uuid: {}".format(backing_device, cache_device,
diff --git a/curtin/block/iscsi.py b/curtin/block/iscsi.py
index 3c46500..f251994 100644
--- a/curtin/block/iscsi.py
+++ b/curtin/block/iscsi.py
@@ -9,7 +9,7 @@ import os
9import re9import re
10import shutil10import shutil
1111
12from curtin import (paths, util, udev)12from curtin import (util, udev)
13from curtin.block import (get_device_slave_knames,13from curtin.block import (get_device_slave_knames,
14 path_to_kname)14 path_to_kname)
1515
@@ -225,11 +225,6 @@ def ensure_disk_connected(rfc4173, write_config=True):
225 return iscsi_disk225 return iscsi_disk
226226
227227
228def connected_disks():
229 global _ISCSI_DISKS
230 return _ISCSI_DISKS
231
232
233def get_iscsi_volumes_from_config(cfg):228def get_iscsi_volumes_from_config(cfg):
234 """Parse a curtin storage config and return a list229 """Parse a curtin storage config and return a list
235 of iscsi disk rfc4173 uris for each configuration present.230 of iscsi disk rfc4173 uris for each configuration present.
@@ -267,33 +262,6 @@ def get_iscsi_ports_from_config(cfg):
267 return ports262 return ports
268263
269264
270def disconnect_target_disks(target_root_path=None):
271 target_nodes_path = paths.target_path(target_root_path, '/etc/iscsi/nodes')
272 fails = []
273 if os.path.isdir(target_nodes_path):
274 for target in os.listdir(target_nodes_path):
275 if target not in iscsiadm_sessions():
276 LOG.debug('iscsi target %s not active, skipping', target)
277 continue
278 # conn is "host,port,lun"
279 for conn in os.listdir(
280 os.path.sep.join([target_nodes_path, target])):
281 host, port, _ = conn.split(',')
282 try:
283 util.subp(['sync'])
284 iscsiadm_logout(target, '%s:%s' % (host, port))
285 except util.ProcessExecutionError as e:
286 fails.append(target)
287 LOG.warn("Unable to logout of iSCSI target %s: %s",
288 target, e)
289 else:
290 LOG.warning('Skipping disconnect: failed to find iscsi nodes path: %s',
291 target_nodes_path)
292 if fails:
293 raise RuntimeError(
294 "Unable to logout of iSCSI targets: %s" % ', '.join(fails))
295
296
297# Determines if a /dev/disk/by-path symlink matching the udev pattern265# Determines if a /dev/disk/by-path symlink matching the udev pattern
298# for iSCSI disks is pointing at @kname266# for iSCSI disks is pointing at @kname
299def kname_is_iscsi(kname):267def 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 = [
92 'write-pending',92 'write-pending',
93]93]
9494
95VALID_RAID_ARRAY_STATES = (
96 ERROR_RAID_STATES +
97 READONLY_RAID_STATES +
98 READWRITE_RAID_STATES
99)
10095
101# need a on-import check of version and set the value for later reference96# need a on-import check of version and set the value for later reference
102''' mdadm version < 3.3 doesn't include enough info when using --export97''' mdadm version < 3.3 doesn't include enough info when using --export
@@ -353,15 +348,6 @@ def mdadm_stop(devpath, retries=None):
353 raise OSError('Failed to stop mdadm device %s', devpath)348 raise OSError('Failed to stop mdadm device %s', devpath)
354349
355350
356def mdadm_remove(devpath):
357 assert_valid_devpath(devpath)
358
359 LOG.info("mdadm removing: %s" % devpath)
360 out, err = util.subp(["mdadm", "--remove", devpath],
361 rcs=[0], capture=True)
362 LOG.debug("mdadm remove:\n%s\n%s", out, err)
363
364
365def fail_device(mddev, arraydev):351def fail_device(mddev, arraydev):
366 assert_valid_devpath(mddev)352 assert_valid_devpath(mddev)
367353
@@ -559,14 +545,6 @@ def md_check_array_state_rw(md_devname):
559 return __md_check_array_state(md_devname, mode='READWRITE')545 return __md_check_array_state(md_devname, mode='READWRITE')
560546
561547
562def md_check_array_state_ro(md_devname):
563 return __md_check_array_state(md_devname, mode='READONLY')
564
565
566def md_check_array_state_error(md_devname):
567 return __md_check_array_state(md_devname, mode='ERROR')
568
569
570def __mdadm_export_to_dict(output):548def __mdadm_export_to_dict(output):
571 ''' convert Key=Value text output into dictionary '''549 ''' convert Key=Value text output into dictionary '''
572 return dict(tok.split('=', 1) for tok in shlex.split(output))550 return dict(tok.split('=', 1) for tok in shlex.split(output))
@@ -633,81 +611,6 @@ def __mdadm_detail_to_dict(input):
633 return data611 return data
634612
635613
636def md_device_key_role(devname):
637 if not devname:
638 raise ValueError('Missing parameter devname')
639 return 'MD_DEVICE_' + dev_short(devname) + '_ROLE'
640
641
642def md_device_key_dev(devname):
643 if not devname:
644 raise ValueError('Missing parameter devname')
645 return 'MD_DEVICE_' + dev_short(devname) + '_DEV'
646
647
648def __upgrade_detail_dict(detail):
649 ''' This method attempts to convert mdadm --detail output into
650 a KEY=VALUE output the same as mdadm --detail --export from mdadm v3.3
651 '''
652 # if the input already has MD_UUID, it's already been converted
653 if 'MD_UUID' in detail:
654 return detail
655
656 md_detail = {
657 'MD_LEVEL': detail['raid_level'],
658 'MD_DEVICES': detail['raid_devices'],
659 'MD_METADATA': detail['version'],
660 'MD_NAME': detail['name'].split()[0],
661 }
662
663 # exmaine has ARRAY UUID
664 if 'array_uuid' in detail:
665 md_detail.update({'MD_UUID': detail['array_uuid']})
666 # query,detail has UUID
667 elif 'uuid' in detail:
668 md_detail.update({'MD_UUID': detail['uuid']})
669
670 device = detail['device']
671
672 # MD_DEVICE_vdc1_DEV=/dev/vdc1
673 md_detail.update({md_device_key_dev(device): device})
674
675 if 'device_role' in detail:
676 role = detail['device_role']
677 if role != 'spare':
678 # device_role = Active device 1
679 role = role.split()[-1]
680
681 # MD_DEVICE_vdc1_ROLE=spare
682 md_detail.update({md_device_key_role(device): role})
683
684 return md_detail
685
686
687def md_read_run_mdadm_map():
688 '''
689 md1 1.2 59beb40f:4c202f67:088e702b:efdf577a /dev/md1
690 md0 0.90 077e6a9e:edf92012:e2a6e712:b193f786 /dev/md0
691
692 return
693 # md_shortname = (metaversion, md_uuid, md_devpath)
694 data = {
695 'md1': (1.2, 59beb40f:4c202f67:088e702b:efdf577a, /dev/md1)
696 'md0': (0.90, 077e6a9e:edf92012:e2a6e712:b193f786, /dev/md0)
697 '''
698
699 mdadm_map = {}
700 run_mdadm_map = '/run/mdadm/map'
701 if os.path.exists(run_mdadm_map):
702 with open(run_mdadm_map, 'r') as fp:
703 data = fp.read().strip()
704 for entry in data.split('\n'):
705 (key, meta, md_uuid, dev) = entry.split()
706 mdadm_map.update({key: (meta, md_uuid, dev)})
707
708 return mdadm_map
709
710
711def md_check_array_uuid(md_devname, md_uuid):614def md_check_array_uuid(md_devname, md_uuid):
712 valid_mdname(md_devname)615 valid_mdname(md_devname)
713616
@@ -750,22 +653,6 @@ def md_check_raidlevel(raidlevel):
750 return True653 return True
751654
752655
753def md_block_until_in_sync(md_devname):
754 '''
755 sync_completed
756 This shows the number of sectors that have been completed of
757 whatever the current sync_action is, followed by the number of
758 sectors in total that could need to be processed. The two
759 numbers are separated by a '/' thus effectively showing one
760 value, a fraction of the process that is complete.
761 A 'select' on this attribute will return when resync completes,
762 when it reaches the current sync_max (below) and possibly at
763 other times.
764 '''
765 # FIXME: use selectors to block on: /sys/class/block/mdX/md/sync_completed
766 pass
767
768
769def md_check_array_state(md_devname):656def md_check_array_state(md_devname):
770 # check array state657 # check array state
771658
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):
88 return result88 return result
8989
9090
91def mpath_partition_to_mpath_id(devpath):
92 """ Return the mpath id of a multipath partition. """
93 info = udev.udevadm_info(devpath)
94 if 'DM_MPATH' in info:
95 return info['DM_MPATH']
96
97 return None
98
99
100def remove_partition(devpath, retries=10):91def remove_partition(devpath, retries=10):
101 """ Remove a multipath partition mapping. """92 """ Remove a multipath partition mapping. """
102 LOG.debug('multipath: removing multipath partition: %s', devpath)93 LOG.debug('multipath: removing multipath partition: %s', devpath)
@@ -109,36 +100,6 @@ def remove_partition(devpath, retries=10):
109 util.wait_for_removal(devpath)100 util.wait_for_removal(devpath)
110101
111102
112def remove_map(map_id, retries=10):
113 """ Remove a multipath device mapping. """
114 LOG.debug('multipath: removing multipath map: %s', map_id)
115 devpath = '/dev/mapper/%s' % map_id
116 for _ in range(0, retries):
117 util.subp(['multipath', '-v3', '-R3', '-f', map_id], rcs=[0, 1])
118 udev.udevadm_settle()
119 if not os.path.exists(devpath):
120 return
121
122 util.wait_for_removal(devpath)
123
124
125def find_mpath_members(multipath_id, paths=None):
126 """ Return a list of device path for each member of aspecified mpath_id."""
127 if not paths:
128 paths = show_paths()
129 for retry in range(0, 5):
130 orphans = [path for path in paths if 'orphan' in path['multipath']]
131 if len(orphans):
132 udev.udevadm_settle()
133 paths = show_paths()
134 else:
135 break
136
137 members = ['/dev/' + path['device']
138 for path in paths if path['multipath'] == multipath_id]
139 return members
140
141
142def find_mpath_id(devpath, maps=None):103def find_mpath_id(devpath, maps=None):
143 """ Return the mpath_id associated with a specified device path. """104 """ Return the mpath_id associated with a specified device path. """
144 if not maps:105 if not maps:
@@ -170,17 +131,6 @@ def find_mpath_id_by_path(devpath, paths=None):
170 return None131 return None
171132
172133
173def find_mpath_id_by_parent(multipath_id, partnum=None):
174 """ Return the mpath_id associated with a specified device path. """
175 devmap = dmname_to_blkdev_mapping()
176 LOG.debug('multipath: dm_name blk map: %s', devmap)
177 dm_name = multipath_id
178 if partnum:
179 dm_name += "-part%d" % int(partnum)
180
181 return (dm_name, devmap.get(dm_name))
182
183
184def find_mpath_partitions(mpath_id):134def find_mpath_partitions(mpath_id):
185 """135 """
186 Return a generator of multipath ids which are partitions of 'mpath-id'136 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'):
905 shutil.copytree(source_dir, target_dir)905 shutil.copytree(source_dir, target_dir)
906906
907907
908def copy_mdadm_conf(mdadm_conf, target):
909 if not mdadm_conf:
910 LOG.warn("mdadm config must be specified, not copying")
911 return
912
913 LOG.info("copying mdadm.conf into target")
914 shutil.copy(mdadm_conf, os.path.sep.join([target,
915 'etc/mdadm/mdadm.conf']))
916
917
918def copy_zpool_cache(zpool_cache, target):908def copy_zpool_cache(zpool_cache, target):
919 if not zpool_cache:909 if not zpool_cache:
920 LOG.warn("zpool_cache path must be specified, not copying")910 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):
94 return os.path.exists(sys_dev_path(devname, "device"))94 return os.path.exists(sys_dev_path(devname, "device"))
9595
9696
97def is_present(devname):
98 return os.path.exists(sys_dev_path(devname))
99
100
101def get_devicelist():97def get_devicelist():
102 return os.listdir(SYS_CLASS_NET)98 return os.listdir(SYS_CLASS_NET)
10399
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):
29 mock_util.subp.assert_called_with(expected_call, capture=True)29 mock_util.subp.assert_called_with(expected_call, capture=True)
30 self.assertEqual(uuid, "182e8e23-5322-46c9-a1b8-cf2c6a88f9f7")30 self.assertEqual(uuid, "182e8e23-5322-46c9-a1b8-cf2c6a88f9f7")
3131
32 @mock.patch("curtin.block.get_proc_mounts")
33 @mock.patch("curtin.block._lsblock")
34 def test_get_mountpoints(self, mock_lsblk, mock_proc_mounts):
35 mock_lsblk.return_value = {"sda1": {"MOUNTPOINT": None},
36 "sda2": {"MOUNTPOINT": ""},
37 "sda3": {"MOUNTPOINT": "/mnt"}}
38 mock_proc_mounts.return_value = [
39 ('sysfs', '/sys', 'sysfs', 'sysfs_opts', '0', '0'),
40 ]
41
42 mountpoints = block.get_mountpoints()
43
44 self.assertTrue(mock_lsblk.called)
45 self.assertEqual(sorted(mountpoints),
46 sorted(["/mnt", "/sys"]))
47
48 @mock.patch('curtin.block._lsblock')32 @mock.patch('curtin.block._lsblock')
49 def test_get_blockdev_sector_size(self, mock_lsblk):33 def test_get_blockdev_sector_size(self, mock_lsblk):
50 mock_lsblk.return_value = {34 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):
271 self.assertEqual([bdev_target], results)271 self.assertEqual([bdev_target], results)
272 m_listdir.assert_called_with(cset_path)272 m_listdir.assert_called_with(cset_path)
273273
274 @mock.patch('curtin.block.bcache.os.path.exists')
275 @mock.patch('curtin.block.bcache.os.path.realpath')
276 def test_get_cacheset_cachedev(self, m_real, m_exists):
277 """ get_cacheset_cachedev finds cacheset device path."""
278 cset_uuid = self.random_string()
279 cachedev_target = self.random_string()
280 cset_path = '/sys/fs/bcache/%s/cache0' % cset_uuid
281 m_exists.return_value = True
282 m_real.side_effect = iter([cachedev_target])
283 results = bcache.get_cacheset_cachedev(cset_uuid)
284 self.assertEqual(cachedev_target, results)
285 m_real.assert_called_with(cset_path)
286
287 @mock.patch('curtin.block.bcache.is_backing')274 @mock.patch('curtin.block.bcache.is_backing')
288 @mock.patch('curtin.block.bcache.sysfs_path')275 @mock.patch('curtin.block.bcache.sysfs_path')
289 @mock.patch('curtin.block.bcache.os.listdir')276 @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..309c28e 100644
--- a/tests/unittests/test_block_iscsi.py
+++ b/tests/unittests/test_block_iscsi.py
@@ -1,10 +1,8 @@
1# This file is part of curtin. See LICENSE file for copyright and license info.1# This file is part of curtin. See LICENSE file for copyright and license info.
22
3import mock3import mock
4import os
54
6from curtin.block import iscsi5from curtin.block import iscsi
7from curtin import util
8from .helpers import CiTestCase6from .helpers import CiTestCase
97
108
@@ -647,104 +645,4 @@ class TestBlockIscsiDiskFromConfig(CiTestCase):
647 self.assertEqual(expected_iscsi_disks, iscsi_disks)645 self.assertEqual(expected_iscsi_disks, iscsi_disks)
648646
649647
650class TestBlockIscsiDisconnect(CiTestCase):
651 # test that when disconnecting iscsi targets we
652 # check that the target has an active session before
653 # issuing a disconnect command
654
655 def setUp(self):
656 super(TestBlockIscsiDisconnect, self).setUp()
657 self.add_patch('curtin.block.iscsi.util.subp', 'mock_subp')
658 self.add_patch('curtin.block.iscsi.iscsiadm_sessions',
659 'mock_iscsi_sessions')
660 # fake target_root + iscsi nodes dir
661 self.target_path = self.tmp_dir()
662 self.iscsi_nodes = os.path.join(self.target_path, 'etc/iscsi/nodes')
663 util.ensure_dir(self.iscsi_nodes)
664
665 def _fmt_disconnect(self, target, portal):
666 return ['iscsiadm', '--mode=node', '--targetname=%s' % target,
667 '--portal=%s' % portal, '--logout']
668
669 def _setup_nodes(self, sessions, connection):
670 # setup iscsi_nodes dir (<fakeroot>/etc/iscsi/nodes) with content
671 for s in sessions:
672 sdir = os.path.join(self.iscsi_nodes, s)
673 connpath = os.path.join(sdir, connection)
674 util.ensure_dir(sdir)
675 util.write_file(connpath, content="")
676
677 def test_disconnect_target_disk(self):
678 """Test iscsi disconnecting multiple sessions, all present"""
679
680 sessions = [
681 'curtin-53ab23ff-a887-449a-80a8-288151208091',
682 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5',
683 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4',
684 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9'
685 ]
686 connection = '10.245.168.20,16395,1'
687 self._setup_nodes(sessions, connection)
688
689 self.mock_iscsi_sessions.return_value = "\n".join(sessions)
690
691 iscsi.disconnect_target_disks(self.target_path)
692
693 expected_calls = []
694 for session in sessions:
695 (host, port, _) = connection.split(',')
696 disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port))
697 calls = [
698 mock.call(['sync']),
699 mock.call(disconnect, capture=True, log_captured=True),
700 mock.call(['udevadm', 'settle']),
701 ]
702 expected_calls.extend(calls)
703
704 self.mock_subp.assert_has_calls(expected_calls, any_order=True)
705
706 def test_disconnect_target_disk_skip_disconnected(self):
707 """Test iscsi does not attempt to disconnect already closed sessions"""
708 sessions = [
709 'curtin-53ab23ff-a887-449a-80a8-288151208091',
710 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5',
711 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4',
712 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9'
713 ]
714 connection = '10.245.168.20,16395,1'
715 self._setup_nodes(sessions, connection)
716 # Test with all sessions are already disconnected
717 self.mock_iscsi_sessions.return_value = ""
718
719 iscsi.disconnect_target_disks(self.target_path)
720
721 self.mock_subp.assert_has_calls([], any_order=True)
722
723 @mock.patch('curtin.block.iscsi.iscsiadm_logout')
724 def test_disconnect_target_disk_raises_runtime_error(self, mock_logout):
725 """Test iscsi raises RuntimeError if we fail to logout"""
726 sessions = [
727 'curtin-53ab23ff-a887-449a-80a8-288151208091',
728 ]
729 connection = '10.245.168.20,16395,1'
730 self._setup_nodes(sessions, connection)
731 self.mock_iscsi_sessions.return_value = "\n".join(sessions)
732 mock_logout.side_effect = util.ProcessExecutionError()
733
734 with self.assertRaises(RuntimeError):
735 iscsi.disconnect_target_disks(self.target_path)
736
737 expected_calls = []
738 for session in sessions:
739 (host, port, _) = connection.split(',')
740 disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port))
741 calls = [
742 mock.call(['sync']),
743 mock.call(disconnect, capture=True, log_captured=True),
744 mock.call(['udevadm', 'settle']),
745 ]
746 expected_calls.extend(calls)
747
748 self.mock_subp.assert_has_calls([], any_order=True)
749
750# vi: ts=4 expandtab syntax=python648# 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):
594 self.mock_util_write_file.assert_has_calls(expected_writes)594 self.mock_util_write_file.assert_has_calls(expected_writes)
595595
596596
597class TestBlockMdadmRemove(CiTestCase):
598 def setUp(self):
599 super(TestBlockMdadmRemove, self).setUp()
600 self.add_patch('curtin.block.mdadm.util', 'mock_util')
601 self.add_patch('curtin.block.mdadm.lsb_release', 'mock_lsb_release')
602 self.add_patch('curtin.block.mdadm.is_valid_device', 'mock_valid')
603
604 # Common mock settings
605 self.mock_valid.return_value = True
606 self.mock_lsb_release.return_value = {'codename': 'xenial'}
607 self.mock_util.subp.side_effect = [
608 ("", ""), # mdadm remove device
609 ]
610
611 def test_mdadm_remove_no_devpath(self):
612 with self.assertRaises(ValueError):
613 mdadm.mdadm_remove(None)
614
615 def test_mdadm_remove(self):
616 device = "/dev/vdc"
617 mdadm.mdadm_remove(device)
618 expected_calls = [
619 call(["mdadm", "--remove", device], rcs=[0], capture=True),
620 ]
621 self.mock_util.subp.assert_has_calls(expected_calls)
622
623
624class TestBlockMdadmQueryDetail(CiTestCase):597class TestBlockMdadmQueryDetail(CiTestCase):
625 def setUp(self):598 def setUp(self):
626 super(TestBlockMdadmQueryDetail, self).setUp()599 super(TestBlockMdadmQueryDetail, self).setUp()
@@ -716,7 +689,7 @@ class TestBlockMdadmDetailScan(CiTestCase):
716 (self.scan_output, ""), # mdadm --detail --scan689 (self.scan_output, ""), # mdadm --detail --scan
717 ]690 ]
718691
719 def test_mdadm_remove(self):692 def test_mdadm_detail_scan(self):
720 data = mdadm.mdadm_detail_scan()693 data = mdadm.mdadm_detail_scan()
721 expected_calls = [694 expected_calls = [
722 call(["mdadm", "--detail", "--scan"], capture=True),695 call(["mdadm", "--detail", "--scan"], capture=True),
@@ -724,7 +697,7 @@ class TestBlockMdadmDetailScan(CiTestCase):
724 self.mock_util.subp.assert_has_calls(expected_calls)697 self.mock_util.subp.assert_has_calls(expected_calls)
725 self.assertEqual(self.scan_output, data)698 self.assertEqual(self.scan_output, data)
726699
727 def test_mdadm_remove_error(self):700 def test_mdadm_detail_scan_error(self):
728 self.mock_util.subp.side_effect = [701 self.mock_util.subp.side_effect = [
729 ("wark", "error"), # mdadm --detail --scan702 ("wark", "error"), # mdadm --detail --scan
730 ]703 ]
@@ -825,50 +798,6 @@ class TestBlockMdadmMdHelpers(CiTestCase):
825 mock_attr.return_value = 'inactive'798 mock_attr.return_value = 'inactive'
826 self.assertFalse(mdadm.md_check_array_state_rw(mdname))799 self.assertFalse(mdadm.md_check_array_state_rw(mdname))
827800
828 @patch('curtin.block.mdadm.md_sysfs_attr')
829 def test_md_check_array_state_ro(self, mock_attr):
830 mdname = '/dev/md0'
831 mock_attr.return_value = 'readonly'
832 self.assertTrue(mdadm.md_check_array_state_ro(mdname))
833
834 @patch('curtin.block.mdadm.md_sysfs_attr')
835 def test_md_check_array_state_ro_false(self, mock_attr):
836 mdname = '/dev/md0'
837 mock_attr.return_value = 'inactive'
838 self.assertFalse(mdadm.md_check_array_state_ro(mdname))
839
840 @patch('curtin.block.mdadm.md_sysfs_attr')
841 def test_md_check_array_state_error(self, mock_attr):
842 mdname = '/dev/md0'
843 mock_attr.return_value = 'inactive'
844 self.assertTrue(mdadm.md_check_array_state_error(mdname))
845
846 @patch('curtin.block.mdadm.md_sysfs_attr')
847 def test_md_check_array_state_error_false(self, mock_attr):
848 mdname = '/dev/md0'
849 mock_attr.return_value = 'active'
850 self.assertFalse(mdadm.md_check_array_state_error(mdname))
851
852 def test_md_device_key_role(self):
853 devname = '/dev/vda'
854 rolekey = mdadm.md_device_key_role(devname)
855 self.assertEqual('MD_DEVICE_vda_ROLE', rolekey)
856
857 def test_md_device_key_role_no_dev(self):
858 devname = None
859 with self.assertRaises(ValueError):
860 mdadm.md_device_key_role(devname)
861
862 def test_md_device_key_dev(self):
863 devname = '/dev/vda'
864 devkey = mdadm.md_device_key_dev(devname)
865 self.assertEqual('MD_DEVICE_vda_DEV', devkey)
866
867 def test_md_device_key_dev_no_dev(self):
868 devname = None
869 with self.assertRaises(ValueError):
870 mdadm.md_device_key_dev(devname)
871
872 @patch('curtin.block.util.load_file')801 @patch('curtin.block.util.load_file')
873 @patch('curtin.block.get_blockdev_for_partition')802 @patch('curtin.block.get_blockdev_for_partition')
874 @patch('curtin.block.mdadm.os.path.exists')803 @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):
82 """is_mpath_member returns false if DM_PART is not present for dev."""82 """is_mpath_member returns false if DM_PART is not present for dev."""
83 self.assertFalse(multipath.is_mpath_partition(self.random_string()))83 self.assertFalse(multipath.is_mpath_partition(self.random_string()))
8484
85 def test_mpath_partition_to_mpath_id(self):
86 """mpath_part_to_mpath_id extracts MD_MPATH value from mp partition."""
87 dev = self.random_string()
88 mpath_id = self.random_string()
89 self.m_udev.udevadm_info.return_value = {'DM_MPATH': mpath_id}
90 self.assertEqual(mpath_id,
91 multipath.mpath_partition_to_mpath_id(dev))
92
93 def test_mpath_partition_to_mpath_id_none(self):
94 """mpath_part_to_mpath_id returns none if DM_MPATH missing."""
95 dev = self.random_string()
96 self.m_udev.udevadm_info.return_value = {}
97 self.assertIsNone(multipath.mpath_partition_to_mpath_id(dev))
98
99 @mock.patch('curtin.block.multipath.os.path.exists')85 @mock.patch('curtin.block.multipath.os.path.exists')
100 @mock.patch('curtin.block.multipath.util.wait_for_removal')86 @mock.patch('curtin.block.multipath.util.wait_for_removal')
101 def test_remove_partition(self, m_wait, m_exists):87 def test_remove_partition(self, m_wait, m_exists):
@@ -122,52 +108,6 @@ class TestMultipath(CiTestCase):
122 self.assertEqual(3, self.m_udev.udevadm_settle.call_count)108 self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
123 self.assertEqual(1, m_wait.call_count)109 self.assertEqual(1, m_wait.call_count)
124110
125 @mock.patch('curtin.block.multipath.os.path.exists')
126 @mock.patch('curtin.block.multipath.util.wait_for_removal')
127 def test_remove_map(self, m_wait, m_exists):
128 """multipath.remove_map runs multipath -f skips wait if map gone."""
129 map_id = self.random_string()
130 devpath = '/dev/mapper/%s' % map_id
131 m_exists.side_effect = iter([True, True, False])
132 multipath.remove_map(devpath)
133 expected = mock.call(
134 ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1])
135 self.m_subp.assert_has_calls([expected] * 3)
136 m_wait.assert_not_called()
137 self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
138
139 @mock.patch('curtin.block.multipath.os.path.exists')
140 @mock.patch('curtin.block.multipath.util.wait_for_removal')
141 def test_remove_map_wait(self, m_wait, m_exists):
142 """multipath.remove_map runs multipath -f wait if map remains."""
143 map_id = self.random_string()
144 devpath = '/dev/mapper/%s' % map_id
145 m_exists.side_effect = iter([True, True, True])
146 multipath.remove_map(devpath, retries=3)
147 expected = mock.call(
148 ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1])
149 self.m_subp.assert_has_calls([expected] * 3)
150 self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
151 self.assertEqual(1, m_wait.call_count)
152
153 def test_find_mpath_members(self):
154 """find_mpath_members enumerates kernel block devs of a mpath_id."""
155 mp_id = 'mpatha'
156 paths = ['device=bar multipath=mpatha',
157 'device=wark multipath=mpatha']
158 self.m_subp.return_value = ("\n".join(paths), "")
159 self.assertEqual(sorted(['/dev/bar', '/dev/wark']),
160 sorted(multipath.find_mpath_members(mp_id)))
161
162 def test_find_mpath_members_empty(self):
163 """find_mpath_members returns empty list if mpath_id not found."""
164 mp_id = self.random_string()
165 paths = ['device=bar multipath=mpatha',
166 'device=wark multipath=mpatha']
167 self.m_subp.return_value = ("\n".join(paths), "")
168
169 self.assertEqual([], multipath.find_mpath_members(mp_id))
170
171 def test_find_mpath_id(self):111 def test_find_mpath_id(self):
172 """find_mpath_id returns mpath_id if device is part of mpath group."""112 """find_mpath_id returns mpath_id if device is part of mpath group."""
173 mp_id = 'mpatha'113 mp_id = 'mpatha'
@@ -209,18 +149,6 @@ class TestMultipath(CiTestCase):
209 self.assertEqual(expected_mapping,149 self.assertEqual(expected_mapping,
210 multipath.dmname_to_blkdev_mapping())150 multipath.dmname_to_blkdev_mapping())
211151
212 @mock.patch('curtin.block.multipath.dmname_to_blkdev_mapping')
213 def test_find_mpath_id_by_parent(self, m_dmmap):
214 """find_mpath_id_by_parent returns device mapper blk for given DM_NAME.
215 """
216 m_dmmap.return_value = {
217 'mpatha': '/dev/dm-0', 'mpatha-part1': '/dev/dm-1'}
218 mpath_id = 'mpatha'
219 expected_result = ('mpatha-part1', '/dev/dm-1')
220 self.assertEqual(
221 expected_result,
222 multipath.find_mpath_id_by_parent(mpath_id, partnum=1))
223
224 def test_find_mpath_id_by_path(self):152 def test_find_mpath_id_by_path(self):
225 """find_mpath_id_by_path returns the mp_id if specified device is153 """find_mpath_id_by_path returns the mp_id if specified device is
226 member.154 member.

Subscribers

People subscribed via source and target branches