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