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
1diff --git a/curtin/block/__init__.py b/curtin/block/__init__.py
2index 0cf0866..2c1cc7c 100644
3--- a/curtin/block/__init__.py
4+++ b/curtin/block/__init__.py
5@@ -2,7 +2,6 @@
6 import re
7 from contextlib import contextmanager
8 import errno
9-import itertools
10 import os
11 import stat
12 import sys
13@@ -692,28 +691,6 @@ def get_scsi_wwid(device, replace_whitespace=False):
14 return None
15
16
17-def get_multipath_wwids():
18- """
19- Get WWIDs of all multipath devices available in the system.
20- """
21- multipath_devices = set()
22- multipath_wwids = set()
23- devuuids = [(d, i['UUID']) for d, i in blkid().items() if 'UUID' in i]
24- # Looking for two disks which contain filesystems with the same UUID.
25- for (dev1, uuid1), (dev2, uuid2) in itertools.combinations(devuuids, 2):
26- if uuid1 == uuid2:
27- multipath_devices.add(get_blockdev_for_partition(dev1)[0])
28- for device in multipath_devices:
29- wwid = get_scsi_wwid(device)
30- # Function get_scsi_wwid() may return None in case of errors or
31- # WWID field may be empty for some buggy disk. We don't want to
32- # propagate both of these value further to avoid generation of
33- # incorrect /etc/multipath/bindings file.
34- if wwid:
35- multipath_wwids.add(wwid)
36- return multipath_wwids
37-
38-
39 def get_root_device(dev, paths=None):
40 """
41 Get root partition for specified device, based on presence of any
42@@ -812,20 +789,6 @@ def get_volume_uuid(path):
43 return ''
44
45
46-def get_mountpoints():
47- """
48- Returns a list of all mountpoints where filesystems are currently mounted.
49- """
50- info = _lsblock()
51- proc_mounts = [mp for (dev, mp, vfs, opts, freq, passno) in
52- get_proc_mounts()]
53- lsblock_mounts = list(i.get("MOUNTPOINT") for name, i in info.items() if
54- i.get("MOUNTPOINT") is not None and
55- i.get("MOUNTPOINT") != "")
56-
57- return list(set(proc_mounts + lsblock_mounts))
58-
59-
60 def get_proc_mounts():
61 """
62 Returns a list of tuples for each entry in /proc/mounts
63@@ -885,15 +848,6 @@ def disk_to_byid_path(kname):
64 return mapping.get(dev_path(kname))
65
66
67-def disk_to_bypath_path(kname):
68- """"
69- Return a /dev/disk/by-path path to kname if present.
70- """
71-
72- mapping = _get_dev_disk_by_prefix('/dev/disk/by-path')
73- return mapping.get(dev_path(kname))
74-
75-
76 def get_device_mapper_links(devpath, first=False):
77 """ Return the best devlink to device at devpath. """
78 info = udevadm_info(devpath)
79@@ -946,30 +900,6 @@ def lookup_disk(serial):
80 return path
81
82
83-def lookup_dasd(bus_id):
84- """
85- Search for a dasd by its bus_id.
86-
87- :param bus_id: s390x ccw bus_id 0.0.NNNN specifying the dasd
88- :returns: dasd kernel device path (/dev/dasda)
89- """
90-
91- LOG.info('Processing ccw bus_id %s', bus_id)
92- sys_ccw_dev = '/sys/bus/ccw/devices/%s/block' % bus_id
93- if not os.path.exists(sys_ccw_dev):
94- raise ValueError('Failed to find a block device at %s' % sys_ccw_dev)
95-
96- dasds = os.listdir(sys_ccw_dev)
97- if not dasds or len(dasds) < 1:
98- raise ValueError("no dasd with device_id '%s' found" % bus_id)
99-
100- path = '/dev/%s' % dasds[0]
101- if not os.path.exists(path):
102- raise ValueError("path '%s' to block device for dasd with bus_id '%s' \
103- does not exist" % (path, bus_id))
104- return path
105-
106-
107 def sysfs_partition_data(blockdev=None, sysfs_path=None):
108 # given block device or sysfs_path, return a list of tuples
109 # of (kernel_name, number, offset, size)
110diff --git a/curtin/block/bcache.py b/curtin/block/bcache.py
111index c1a8d26..581379f 100644
112--- a/curtin/block/bcache.py
113+++ b/curtin/block/bcache.py
114@@ -155,17 +155,6 @@ def get_cacheset_members(cset_uuid):
115 return members
116
117
118-def get_cacheset_cachedev(cset_uuid):
119- """ Return a sysfs path to a cacheset cache device's bcache dir."""
120-
121- # XXX: bcache cachesets only have a single cache0 entry
122- cachedev = '/sys/fs/bcache/%s/cache0' % cset_uuid
123- if os.path.exists(cachedev):
124- return os.path.realpath(cachedev)
125-
126- return None
127-
128-
129 def attach_backing_to_cacheset(backing_device, cache_device, cset_uuid):
130 LOG.info("Attaching backing device to cacheset: "
131 "{} -> {} cset.uuid: {}".format(backing_device, cache_device,
132diff --git a/curtin/block/iscsi.py b/curtin/block/iscsi.py
133index 3c46500..f251994 100644
134--- a/curtin/block/iscsi.py
135+++ b/curtin/block/iscsi.py
136@@ -9,7 +9,7 @@ import os
137 import re
138 import shutil
139
140-from curtin import (paths, util, udev)
141+from curtin import (util, udev)
142 from curtin.block import (get_device_slave_knames,
143 path_to_kname)
144
145@@ -225,11 +225,6 @@ def ensure_disk_connected(rfc4173, write_config=True):
146 return iscsi_disk
147
148
149-def connected_disks():
150- global _ISCSI_DISKS
151- return _ISCSI_DISKS
152-
153-
154 def get_iscsi_volumes_from_config(cfg):
155 """Parse a curtin storage config and return a list
156 of iscsi disk rfc4173 uris for each configuration present.
157@@ -267,33 +262,6 @@ def get_iscsi_ports_from_config(cfg):
158 return ports
159
160
161-def disconnect_target_disks(target_root_path=None):
162- target_nodes_path = paths.target_path(target_root_path, '/etc/iscsi/nodes')
163- fails = []
164- if os.path.isdir(target_nodes_path):
165- for target in os.listdir(target_nodes_path):
166- if target not in iscsiadm_sessions():
167- LOG.debug('iscsi target %s not active, skipping', target)
168- continue
169- # conn is "host,port,lun"
170- for conn in os.listdir(
171- os.path.sep.join([target_nodes_path, target])):
172- host, port, _ = conn.split(',')
173- try:
174- util.subp(['sync'])
175- iscsiadm_logout(target, '%s:%s' % (host, port))
176- except util.ProcessExecutionError as e:
177- fails.append(target)
178- LOG.warn("Unable to logout of iSCSI target %s: %s",
179- target, e)
180- else:
181- LOG.warning('Skipping disconnect: failed to find iscsi nodes path: %s',
182- target_nodes_path)
183- if fails:
184- raise RuntimeError(
185- "Unable to logout of iSCSI targets: %s" % ', '.join(fails))
186-
187-
188 # Determines if a /dev/disk/by-path symlink matching the udev pattern
189 # for iSCSI disks is pointing at @kname
190 def kname_is_iscsi(kname):
191diff --git a/curtin/block/mdadm.py b/curtin/block/mdadm.py
192index a6ac970..fd26752 100644
193--- a/curtin/block/mdadm.py
194+++ b/curtin/block/mdadm.py
195@@ -92,11 +92,6 @@ READWRITE_RAID_STATES = [
196 'write-pending',
197 ]
198
199-VALID_RAID_ARRAY_STATES = (
200- ERROR_RAID_STATES +
201- READONLY_RAID_STATES +
202- READWRITE_RAID_STATES
203-)
204
205 # need a on-import check of version and set the value for later reference
206 ''' mdadm version < 3.3 doesn't include enough info when using --export
207@@ -353,15 +348,6 @@ def mdadm_stop(devpath, retries=None):
208 raise OSError('Failed to stop mdadm device %s', devpath)
209
210
211-def mdadm_remove(devpath):
212- assert_valid_devpath(devpath)
213-
214- LOG.info("mdadm removing: %s" % devpath)
215- out, err = util.subp(["mdadm", "--remove", devpath],
216- rcs=[0], capture=True)
217- LOG.debug("mdadm remove:\n%s\n%s", out, err)
218-
219-
220 def fail_device(mddev, arraydev):
221 assert_valid_devpath(mddev)
222
223@@ -559,14 +545,6 @@ def md_check_array_state_rw(md_devname):
224 return __md_check_array_state(md_devname, mode='READWRITE')
225
226
227-def md_check_array_state_ro(md_devname):
228- return __md_check_array_state(md_devname, mode='READONLY')
229-
230-
231-def md_check_array_state_error(md_devname):
232- return __md_check_array_state(md_devname, mode='ERROR')
233-
234-
235 def __mdadm_export_to_dict(output):
236 ''' convert Key=Value text output into dictionary '''
237 return dict(tok.split('=', 1) for tok in shlex.split(output))
238@@ -633,81 +611,6 @@ def __mdadm_detail_to_dict(input):
239 return data
240
241
242-def md_device_key_role(devname):
243- if not devname:
244- raise ValueError('Missing parameter devname')
245- return 'MD_DEVICE_' + dev_short(devname) + '_ROLE'
246-
247-
248-def md_device_key_dev(devname):
249- if not devname:
250- raise ValueError('Missing parameter devname')
251- return 'MD_DEVICE_' + dev_short(devname) + '_DEV'
252-
253-
254-def __upgrade_detail_dict(detail):
255- ''' This method attempts to convert mdadm --detail output into
256- a KEY=VALUE output the same as mdadm --detail --export from mdadm v3.3
257- '''
258- # if the input already has MD_UUID, it's already been converted
259- if 'MD_UUID' in detail:
260- return detail
261-
262- md_detail = {
263- 'MD_LEVEL': detail['raid_level'],
264- 'MD_DEVICES': detail['raid_devices'],
265- 'MD_METADATA': detail['version'],
266- 'MD_NAME': detail['name'].split()[0],
267- }
268-
269- # exmaine has ARRAY UUID
270- if 'array_uuid' in detail:
271- md_detail.update({'MD_UUID': detail['array_uuid']})
272- # query,detail has UUID
273- elif 'uuid' in detail:
274- md_detail.update({'MD_UUID': detail['uuid']})
275-
276- device = detail['device']
277-
278- # MD_DEVICE_vdc1_DEV=/dev/vdc1
279- md_detail.update({md_device_key_dev(device): device})
280-
281- if 'device_role' in detail:
282- role = detail['device_role']
283- if role != 'spare':
284- # device_role = Active device 1
285- role = role.split()[-1]
286-
287- # MD_DEVICE_vdc1_ROLE=spare
288- md_detail.update({md_device_key_role(device): role})
289-
290- return md_detail
291-
292-
293-def md_read_run_mdadm_map():
294- '''
295- md1 1.2 59beb40f:4c202f67:088e702b:efdf577a /dev/md1
296- md0 0.90 077e6a9e:edf92012:e2a6e712:b193f786 /dev/md0
297-
298- return
299- # md_shortname = (metaversion, md_uuid, md_devpath)
300- data = {
301- 'md1': (1.2, 59beb40f:4c202f67:088e702b:efdf577a, /dev/md1)
302- 'md0': (0.90, 077e6a9e:edf92012:e2a6e712:b193f786, /dev/md0)
303- '''
304-
305- mdadm_map = {}
306- run_mdadm_map = '/run/mdadm/map'
307- if os.path.exists(run_mdadm_map):
308- with open(run_mdadm_map, 'r') as fp:
309- data = fp.read().strip()
310- for entry in data.split('\n'):
311- (key, meta, md_uuid, dev) = entry.split()
312- mdadm_map.update({key: (meta, md_uuid, dev)})
313-
314- return mdadm_map
315-
316-
317 def md_check_array_uuid(md_devname, md_uuid):
318 valid_mdname(md_devname)
319
320@@ -750,22 +653,6 @@ def md_check_raidlevel(raidlevel):
321 return True
322
323
324-def md_block_until_in_sync(md_devname):
325- '''
326- sync_completed
327- This shows the number of sectors that have been completed of
328- whatever the current sync_action is, followed by the number of
329- sectors in total that could need to be processed. The two
330- numbers are separated by a '/' thus effectively showing one
331- value, a fraction of the process that is complete.
332- A 'select' on this attribute will return when resync completes,
333- when it reaches the current sync_max (below) and possibly at
334- other times.
335- '''
336- # FIXME: use selectors to block on: /sys/class/block/mdX/md/sync_completed
337- pass
338-
339-
340 def md_check_array_state(md_devname):
341 # check array state
342
343diff --git a/curtin/block/multipath.py b/curtin/block/multipath.py
344index 7ad1791..8010f29 100644
345--- a/curtin/block/multipath.py
346+++ b/curtin/block/multipath.py
347@@ -88,15 +88,6 @@ def is_mpath_partition(devpath, info=None):
348 return result
349
350
351-def mpath_partition_to_mpath_id(devpath):
352- """ Return the mpath id of a multipath partition. """
353- info = udev.udevadm_info(devpath)
354- if 'DM_MPATH' in info:
355- return info['DM_MPATH']
356-
357- return None
358-
359-
360 def remove_partition(devpath, retries=10):
361 """ Remove a multipath partition mapping. """
362 LOG.debug('multipath: removing multipath partition: %s', devpath)
363@@ -109,36 +100,6 @@ def remove_partition(devpath, retries=10):
364 util.wait_for_removal(devpath)
365
366
367-def remove_map(map_id, retries=10):
368- """ Remove a multipath device mapping. """
369- LOG.debug('multipath: removing multipath map: %s', map_id)
370- devpath = '/dev/mapper/%s' % map_id
371- for _ in range(0, retries):
372- util.subp(['multipath', '-v3', '-R3', '-f', map_id], rcs=[0, 1])
373- udev.udevadm_settle()
374- if not os.path.exists(devpath):
375- return
376-
377- util.wait_for_removal(devpath)
378-
379-
380-def find_mpath_members(multipath_id, paths=None):
381- """ Return a list of device path for each member of aspecified mpath_id."""
382- if not paths:
383- paths = show_paths()
384- for retry in range(0, 5):
385- orphans = [path for path in paths if 'orphan' in path['multipath']]
386- if len(orphans):
387- udev.udevadm_settle()
388- paths = show_paths()
389- else:
390- break
391-
392- members = ['/dev/' + path['device']
393- for path in paths if path['multipath'] == multipath_id]
394- return members
395-
396-
397 def find_mpath_id(devpath, maps=None):
398 """ Return the mpath_id associated with a specified device path. """
399 if not maps:
400@@ -170,17 +131,6 @@ def find_mpath_id_by_path(devpath, paths=None):
401 return None
402
403
404-def find_mpath_id_by_parent(multipath_id, partnum=None):
405- """ Return the mpath_id associated with a specified device path. """
406- devmap = dmname_to_blkdev_mapping()
407- LOG.debug('multipath: dm_name blk map: %s', devmap)
408- dm_name = multipath_id
409- if partnum:
410- dm_name += "-part%d" % int(partnum)
411-
412- return (dm_name, devmap.get(dm_name))
413-
414-
415 def find_mpath_partitions(mpath_id):
416 """
417 Return a generator of multipath ids which are partitions of 'mpath-id'
418diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
419index 4cf7301..46af022 100644
420--- a/curtin/commands/curthooks.py
421+++ b/curtin/commands/curthooks.py
422@@ -905,16 +905,6 @@ def copy_iscsi_conf(nodes_dir, target, target_nodes_dir='etc/iscsi/nodes'):
423 shutil.copytree(source_dir, target_dir)
424
425
426-def copy_mdadm_conf(mdadm_conf, target):
427- if not mdadm_conf:
428- LOG.warn("mdadm config must be specified, not copying")
429- return
430-
431- LOG.info("copying mdadm.conf into target")
432- shutil.copy(mdadm_conf, os.path.sep.join([target,
433- 'etc/mdadm/mdadm.conf']))
434-
435-
436 def copy_zpool_cache(zpool_cache, target):
437 if not zpool_cache:
438 LOG.warn("zpool_cache path must be specified, not copying")
439diff --git a/curtin/net/__init__.py b/curtin/net/__init__.py
440index 3b02f9d..2b56f17 100644
441--- a/curtin/net/__init__.py
442+++ b/curtin/net/__init__.py
443@@ -94,10 +94,6 @@ def is_physical(devname):
444 return os.path.exists(sys_dev_path(devname, "device"))
445
446
447-def is_present(devname):
448- return os.path.exists(sys_dev_path(devname))
449-
450-
451 def get_devicelist():
452 return os.listdir(SYS_CLASS_NET)
453
454diff --git a/tests/unittests/test_block.py b/tests/unittests/test_block.py
455index 78e331d..985700f 100644
456--- a/tests/unittests/test_block.py
457+++ b/tests/unittests/test_block.py
458@@ -29,22 +29,6 @@ class TestBlock(CiTestCase):
459 mock_util.subp.assert_called_with(expected_call, capture=True)
460 self.assertEqual(uuid, "182e8e23-5322-46c9-a1b8-cf2c6a88f9f7")
461
462- @mock.patch("curtin.block.get_proc_mounts")
463- @mock.patch("curtin.block._lsblock")
464- def test_get_mountpoints(self, mock_lsblk, mock_proc_mounts):
465- mock_lsblk.return_value = {"sda1": {"MOUNTPOINT": None},
466- "sda2": {"MOUNTPOINT": ""},
467- "sda3": {"MOUNTPOINT": "/mnt"}}
468- mock_proc_mounts.return_value = [
469- ('sysfs', '/sys', 'sysfs', 'sysfs_opts', '0', '0'),
470- ]
471-
472- mountpoints = block.get_mountpoints()
473-
474- self.assertTrue(mock_lsblk.called)
475- self.assertEqual(sorted(mountpoints),
476- sorted(["/mnt", "/sys"]))
477-
478 @mock.patch('curtin.block._lsblock')
479 def test_get_blockdev_sector_size(self, mock_lsblk):
480 mock_lsblk.return_value = {
481diff --git a/tests/unittests/test_block_bcache.py b/tests/unittests/test_block_bcache.py
482index 7936522..ecb8046 100644
483--- a/tests/unittests/test_block_bcache.py
484+++ b/tests/unittests/test_block_bcache.py
485@@ -271,19 +271,6 @@ class TestBlockBcache(CiTestCase):
486 self.assertEqual([bdev_target], results)
487 m_listdir.assert_called_with(cset_path)
488
489- @mock.patch('curtin.block.bcache.os.path.exists')
490- @mock.patch('curtin.block.bcache.os.path.realpath')
491- def test_get_cacheset_cachedev(self, m_real, m_exists):
492- """ get_cacheset_cachedev finds cacheset device path."""
493- cset_uuid = self.random_string()
494- cachedev_target = self.random_string()
495- cset_path = '/sys/fs/bcache/%s/cache0' % cset_uuid
496- m_exists.return_value = True
497- m_real.side_effect = iter([cachedev_target])
498- results = bcache.get_cacheset_cachedev(cset_uuid)
499- self.assertEqual(cachedev_target, results)
500- m_real.assert_called_with(cset_path)
501-
502 @mock.patch('curtin.block.bcache.is_backing')
503 @mock.patch('curtin.block.bcache.sysfs_path')
504 @mock.patch('curtin.block.bcache.os.listdir')
505diff --git a/tests/unittests/test_block_iscsi.py b/tests/unittests/test_block_iscsi.py
506index f8ef5d8..309c28e 100644
507--- a/tests/unittests/test_block_iscsi.py
508+++ b/tests/unittests/test_block_iscsi.py
509@@ -1,10 +1,8 @@
510 # This file is part of curtin. See LICENSE file for copyright and license info.
511
512 import mock
513-import os
514
515 from curtin.block import iscsi
516-from curtin import util
517 from .helpers import CiTestCase
518
519
520@@ -647,104 +645,4 @@ class TestBlockIscsiDiskFromConfig(CiTestCase):
521 self.assertEqual(expected_iscsi_disks, iscsi_disks)
522
523
524-class TestBlockIscsiDisconnect(CiTestCase):
525- # test that when disconnecting iscsi targets we
526- # check that the target has an active session before
527- # issuing a disconnect command
528-
529- def setUp(self):
530- super(TestBlockIscsiDisconnect, self).setUp()
531- self.add_patch('curtin.block.iscsi.util.subp', 'mock_subp')
532- self.add_patch('curtin.block.iscsi.iscsiadm_sessions',
533- 'mock_iscsi_sessions')
534- # fake target_root + iscsi nodes dir
535- self.target_path = self.tmp_dir()
536- self.iscsi_nodes = os.path.join(self.target_path, 'etc/iscsi/nodes')
537- util.ensure_dir(self.iscsi_nodes)
538-
539- def _fmt_disconnect(self, target, portal):
540- return ['iscsiadm', '--mode=node', '--targetname=%s' % target,
541- '--portal=%s' % portal, '--logout']
542-
543- def _setup_nodes(self, sessions, connection):
544- # setup iscsi_nodes dir (<fakeroot>/etc/iscsi/nodes) with content
545- for s in sessions:
546- sdir = os.path.join(self.iscsi_nodes, s)
547- connpath = os.path.join(sdir, connection)
548- util.ensure_dir(sdir)
549- util.write_file(connpath, content="")
550-
551- def test_disconnect_target_disk(self):
552- """Test iscsi disconnecting multiple sessions, all present"""
553-
554- sessions = [
555- 'curtin-53ab23ff-a887-449a-80a8-288151208091',
556- 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5',
557- 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4',
558- 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9'
559- ]
560- connection = '10.245.168.20,16395,1'
561- self._setup_nodes(sessions, connection)
562-
563- self.mock_iscsi_sessions.return_value = "\n".join(sessions)
564-
565- iscsi.disconnect_target_disks(self.target_path)
566-
567- expected_calls = []
568- for session in sessions:
569- (host, port, _) = connection.split(',')
570- disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port))
571- calls = [
572- mock.call(['sync']),
573- mock.call(disconnect, capture=True, log_captured=True),
574- mock.call(['udevadm', 'settle']),
575- ]
576- expected_calls.extend(calls)
577-
578- self.mock_subp.assert_has_calls(expected_calls, any_order=True)
579-
580- def test_disconnect_target_disk_skip_disconnected(self):
581- """Test iscsi does not attempt to disconnect already closed sessions"""
582- sessions = [
583- 'curtin-53ab23ff-a887-449a-80a8-288151208091',
584- 'curtin-94b62de1-c579-42c0-879e-8a28178e64c5',
585- 'curtin-556aeecd-a227-41b7-83d7-2bb471c574b4',
586- 'curtin-fd0f644b-7858-420f-9997-3ea2aefe87b9'
587- ]
588- connection = '10.245.168.20,16395,1'
589- self._setup_nodes(sessions, connection)
590- # Test with all sessions are already disconnected
591- self.mock_iscsi_sessions.return_value = ""
592-
593- iscsi.disconnect_target_disks(self.target_path)
594-
595- self.mock_subp.assert_has_calls([], any_order=True)
596-
597- @mock.patch('curtin.block.iscsi.iscsiadm_logout')
598- def test_disconnect_target_disk_raises_runtime_error(self, mock_logout):
599- """Test iscsi raises RuntimeError if we fail to logout"""
600- sessions = [
601- 'curtin-53ab23ff-a887-449a-80a8-288151208091',
602- ]
603- connection = '10.245.168.20,16395,1'
604- self._setup_nodes(sessions, connection)
605- self.mock_iscsi_sessions.return_value = "\n".join(sessions)
606- mock_logout.side_effect = util.ProcessExecutionError()
607-
608- with self.assertRaises(RuntimeError):
609- iscsi.disconnect_target_disks(self.target_path)
610-
611- expected_calls = []
612- for session in sessions:
613- (host, port, _) = connection.split(',')
614- disconnect = self._fmt_disconnect(session, "%s:%s" % (host, port))
615- calls = [
616- mock.call(['sync']),
617- mock.call(disconnect, capture=True, log_captured=True),
618- mock.call(['udevadm', 'settle']),
619- ]
620- expected_calls.extend(calls)
621-
622- self.mock_subp.assert_has_calls([], any_order=True)
623-
624 # vi: ts=4 expandtab syntax=python
625diff --git a/tests/unittests/test_block_mdadm.py b/tests/unittests/test_block_mdadm.py
626index b04cf82..a6654ce 100644
627--- a/tests/unittests/test_block_mdadm.py
628+++ b/tests/unittests/test_block_mdadm.py
629@@ -594,33 +594,6 @@ class TestBlockMdadmStop(CiTestCase):
630 self.mock_util_write_file.assert_has_calls(expected_writes)
631
632
633-class TestBlockMdadmRemove(CiTestCase):
634- def setUp(self):
635- super(TestBlockMdadmRemove, self).setUp()
636- self.add_patch('curtin.block.mdadm.util', 'mock_util')
637- self.add_patch('curtin.block.mdadm.lsb_release', 'mock_lsb_release')
638- self.add_patch('curtin.block.mdadm.is_valid_device', 'mock_valid')
639-
640- # Common mock settings
641- self.mock_valid.return_value = True
642- self.mock_lsb_release.return_value = {'codename': 'xenial'}
643- self.mock_util.subp.side_effect = [
644- ("", ""), # mdadm remove device
645- ]
646-
647- def test_mdadm_remove_no_devpath(self):
648- with self.assertRaises(ValueError):
649- mdadm.mdadm_remove(None)
650-
651- def test_mdadm_remove(self):
652- device = "/dev/vdc"
653- mdadm.mdadm_remove(device)
654- expected_calls = [
655- call(["mdadm", "--remove", device], rcs=[0], capture=True),
656- ]
657- self.mock_util.subp.assert_has_calls(expected_calls)
658-
659-
660 class TestBlockMdadmQueryDetail(CiTestCase):
661 def setUp(self):
662 super(TestBlockMdadmQueryDetail, self).setUp()
663@@ -716,7 +689,7 @@ class TestBlockMdadmDetailScan(CiTestCase):
664 (self.scan_output, ""), # mdadm --detail --scan
665 ]
666
667- def test_mdadm_remove(self):
668+ def test_mdadm_detail_scan(self):
669 data = mdadm.mdadm_detail_scan()
670 expected_calls = [
671 call(["mdadm", "--detail", "--scan"], capture=True),
672@@ -724,7 +697,7 @@ class TestBlockMdadmDetailScan(CiTestCase):
673 self.mock_util.subp.assert_has_calls(expected_calls)
674 self.assertEqual(self.scan_output, data)
675
676- def test_mdadm_remove_error(self):
677+ def test_mdadm_detail_scan_error(self):
678 self.mock_util.subp.side_effect = [
679 ("wark", "error"), # mdadm --detail --scan
680 ]
681@@ -825,50 +798,6 @@ class TestBlockMdadmMdHelpers(CiTestCase):
682 mock_attr.return_value = 'inactive'
683 self.assertFalse(mdadm.md_check_array_state_rw(mdname))
684
685- @patch('curtin.block.mdadm.md_sysfs_attr')
686- def test_md_check_array_state_ro(self, mock_attr):
687- mdname = '/dev/md0'
688- mock_attr.return_value = 'readonly'
689- self.assertTrue(mdadm.md_check_array_state_ro(mdname))
690-
691- @patch('curtin.block.mdadm.md_sysfs_attr')
692- def test_md_check_array_state_ro_false(self, mock_attr):
693- mdname = '/dev/md0'
694- mock_attr.return_value = 'inactive'
695- self.assertFalse(mdadm.md_check_array_state_ro(mdname))
696-
697- @patch('curtin.block.mdadm.md_sysfs_attr')
698- def test_md_check_array_state_error(self, mock_attr):
699- mdname = '/dev/md0'
700- mock_attr.return_value = 'inactive'
701- self.assertTrue(mdadm.md_check_array_state_error(mdname))
702-
703- @patch('curtin.block.mdadm.md_sysfs_attr')
704- def test_md_check_array_state_error_false(self, mock_attr):
705- mdname = '/dev/md0'
706- mock_attr.return_value = 'active'
707- self.assertFalse(mdadm.md_check_array_state_error(mdname))
708-
709- def test_md_device_key_role(self):
710- devname = '/dev/vda'
711- rolekey = mdadm.md_device_key_role(devname)
712- self.assertEqual('MD_DEVICE_vda_ROLE', rolekey)
713-
714- def test_md_device_key_role_no_dev(self):
715- devname = None
716- with self.assertRaises(ValueError):
717- mdadm.md_device_key_role(devname)
718-
719- def test_md_device_key_dev(self):
720- devname = '/dev/vda'
721- devkey = mdadm.md_device_key_dev(devname)
722- self.assertEqual('MD_DEVICE_vda_DEV', devkey)
723-
724- def test_md_device_key_dev_no_dev(self):
725- devname = None
726- with self.assertRaises(ValueError):
727- mdadm.md_device_key_dev(devname)
728-
729 @patch('curtin.block.util.load_file')
730 @patch('curtin.block.get_blockdev_for_partition')
731 @patch('curtin.block.mdadm.os.path.exists')
732diff --git a/tests/unittests/test_block_multipath.py b/tests/unittests/test_block_multipath.py
733index 96cbcba..a729936 100644
734--- a/tests/unittests/test_block_multipath.py
735+++ b/tests/unittests/test_block_multipath.py
736@@ -82,20 +82,6 @@ class TestMultipath(CiTestCase):
737 """is_mpath_member returns false if DM_PART is not present for dev."""
738 self.assertFalse(multipath.is_mpath_partition(self.random_string()))
739
740- def test_mpath_partition_to_mpath_id(self):
741- """mpath_part_to_mpath_id extracts MD_MPATH value from mp partition."""
742- dev = self.random_string()
743- mpath_id = self.random_string()
744- self.m_udev.udevadm_info.return_value = {'DM_MPATH': mpath_id}
745- self.assertEqual(mpath_id,
746- multipath.mpath_partition_to_mpath_id(dev))
747-
748- def test_mpath_partition_to_mpath_id_none(self):
749- """mpath_part_to_mpath_id returns none if DM_MPATH missing."""
750- dev = self.random_string()
751- self.m_udev.udevadm_info.return_value = {}
752- self.assertIsNone(multipath.mpath_partition_to_mpath_id(dev))
753-
754 @mock.patch('curtin.block.multipath.os.path.exists')
755 @mock.patch('curtin.block.multipath.util.wait_for_removal')
756 def test_remove_partition(self, m_wait, m_exists):
757@@ -122,52 +108,6 @@ class TestMultipath(CiTestCase):
758 self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
759 self.assertEqual(1, m_wait.call_count)
760
761- @mock.patch('curtin.block.multipath.os.path.exists')
762- @mock.patch('curtin.block.multipath.util.wait_for_removal')
763- def test_remove_map(self, m_wait, m_exists):
764- """multipath.remove_map runs multipath -f skips wait if map gone."""
765- map_id = self.random_string()
766- devpath = '/dev/mapper/%s' % map_id
767- m_exists.side_effect = iter([True, True, False])
768- multipath.remove_map(devpath)
769- expected = mock.call(
770- ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1])
771- self.m_subp.assert_has_calls([expected] * 3)
772- m_wait.assert_not_called()
773- self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
774-
775- @mock.patch('curtin.block.multipath.os.path.exists')
776- @mock.patch('curtin.block.multipath.util.wait_for_removal')
777- def test_remove_map_wait(self, m_wait, m_exists):
778- """multipath.remove_map runs multipath -f wait if map remains."""
779- map_id = self.random_string()
780- devpath = '/dev/mapper/%s' % map_id
781- m_exists.side_effect = iter([True, True, True])
782- multipath.remove_map(devpath, retries=3)
783- expected = mock.call(
784- ['multipath', '-v3', '-R3', '-f', devpath], rcs=[0, 1])
785- self.m_subp.assert_has_calls([expected] * 3)
786- self.assertEqual(3, self.m_udev.udevadm_settle.call_count)
787- self.assertEqual(1, m_wait.call_count)
788-
789- def test_find_mpath_members(self):
790- """find_mpath_members enumerates kernel block devs of a mpath_id."""
791- mp_id = 'mpatha'
792- paths = ['device=bar multipath=mpatha',
793- 'device=wark multipath=mpatha']
794- self.m_subp.return_value = ("\n".join(paths), "")
795- self.assertEqual(sorted(['/dev/bar', '/dev/wark']),
796- sorted(multipath.find_mpath_members(mp_id)))
797-
798- def test_find_mpath_members_empty(self):
799- """find_mpath_members returns empty list if mpath_id not found."""
800- mp_id = self.random_string()
801- paths = ['device=bar multipath=mpatha',
802- 'device=wark multipath=mpatha']
803- self.m_subp.return_value = ("\n".join(paths), "")
804-
805- self.assertEqual([], multipath.find_mpath_members(mp_id))
806-
807 def test_find_mpath_id(self):
808 """find_mpath_id returns mpath_id if device is part of mpath group."""
809 mp_id = 'mpatha'
810@@ -209,18 +149,6 @@ class TestMultipath(CiTestCase):
811 self.assertEqual(expected_mapping,
812 multipath.dmname_to_blkdev_mapping())
813
814- @mock.patch('curtin.block.multipath.dmname_to_blkdev_mapping')
815- def test_find_mpath_id_by_parent(self, m_dmmap):
816- """find_mpath_id_by_parent returns device mapper blk for given DM_NAME.
817- """
818- m_dmmap.return_value = {
819- 'mpatha': '/dev/dm-0', 'mpatha-part1': '/dev/dm-1'}
820- mpath_id = 'mpatha'
821- expected_result = ('mpatha-part1', '/dev/dm-1')
822- self.assertEqual(
823- expected_result,
824- multipath.find_mpath_id_by_parent(mpath_id, partnum=1))
825-
826 def test_find_mpath_id_by_path(self):
827 """find_mpath_id_by_path returns the mp_id if specified device is
828 member.

Subscribers

People subscribed via source and target branches