Skip to content

Commit 60504d2

Browse files
committed
fixup! WIP mockrun-installer: new script to help in installer development
10.10.38 support
1 parent c1462a7 commit 60504d2

3 files changed

Lines changed: 126 additions & 14 deletions

File tree

mockrun-data/ifcfg-eth98

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DEVICE=eth98
2+
ONBOOT=yes
3+
BOOTPROTO=dhcp
4+
PERSISTENT_DHCLIENT=1

mockrun-data/ifcfg-eth99

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DEVICE=eth99
2+
ONBOOT=yes

mockrun-installer

Lines changed: 120 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import sys
88
import tempfile
99
from types import ModuleType
1010

11-
MOUNTPOINT_PRIMARY = MOUNTPOINT_BACKUP = MOUNTPOINT_ROOT = MOUNTPOINT_STATE = ''
11+
MOUNTPOINT_PRIMARY = MOUNTPOINT_BACKUP = MOUNTPOINT_ROOT = MOUNTPOINT_STATE = None
1212

1313
### install stubs before imports get a chance to use them
1414

@@ -83,16 +83,36 @@ def mocked_runCmd2(command, with_stdout=False, with_stderr=False, inputtext=None
8383
logger.log("Mocking {}".format(command))
8484
return 0
8585

86+
if command[0:2] == ['mdadm', '--stop']:
87+
# runned because we unconditionally fake presence of md device
88+
assert not with_stdout and not with_stderr
89+
logger.log("Mocking {}".format(command))
90+
return 0
91+
8692
if command[0:2] == ['mdadm', '--create']:
87-
assert with_stdout and with_stderr
93+
assert not with_stdout and not with_stderr
8894
logger.log("Mocking {}".format(command))
8995
for arg in reversed(command):
96+
if arg == "missing": # last arg, support for degraded raids
97+
continue
9098
if arg.startswith("--"): # seen all disks already
9199
break
92-
assert arg.startswith("/dev")
100+
assert arg.startswith("/dev"), "%r does not start with /dev/" % (arg,)
93101
MOCKED_DISKLIST.remove(os.path.basename(arg))
94102
MOCKED_DISKLIST.append("md127")
95-
return (0, "mocked stdout", "mocked stderr")
103+
return 0
104+
105+
if command[0:2] == ['mdadm', '--manage']:
106+
assert not with_stdout and not with_stderr
107+
logger.log("Mocking {}".format(command))
108+
for arg in reversed(command):
109+
if arg == "--run": # last arg
110+
continue
111+
if arg.startswith("--"): # seen all disks already
112+
break
113+
assert arg.startswith("/dev"), "%r does not start with /dev/" % (arg,)
114+
MOCKED_DISKLIST.remove(os.path.basename(arg))
115+
return 0
96116

97117
if command[0] == '/bin/mount':
98118
if command[1:3] == ['-o', 'ro']:
@@ -150,9 +170,23 @@ def mocked_runCmd2(command, with_stdout=False, with_stderr=False, inputtext=None
150170
logger.log("faking mkfs of %s" % (command[1],))
151171
return (0, "mocked stderr")
152172

153-
if command[0:2] == ['sgdisk', '-b']:
173+
if command[0:2] == ['sgdisk', '--mbrtogpt']:
154174
logger.log("faking %s" % (command,))
155-
return (0, "mocked stderr")
175+
if not with_stdout and not with_stderr:
176+
return 0
177+
if with_stdout and with_stderr:
178+
return (0, "mocked stdout", "mocked stderr")
179+
assert False, "unhandled with_stdout=%s with_stderr=%s" % (with_stdout, with_stderr)
180+
181+
if command[0:2] == ['sgdisk', '--set-alignment=1']:
182+
logger.log("faking %s" % (command,))
183+
assert with_stdout and with_stderr
184+
return (0, "mocked stdout", "mocked stderr")
185+
186+
if command[0:3] == ['sfdisk', '--no-reread', '-A1']:
187+
logger.log("faking %s" % (command,))
188+
assert with_stdout and with_stderr
189+
return (0, "mocked stdout", "mocked stderr")
156190

157191
if command == ['uuidgen']:
158192
return (0, "40987587-a9d0-44ae-a7bc-d9fd21850b7c")
@@ -164,6 +198,10 @@ def mocked_runCmd2(command, with_stdout=False, with_stderr=False, inputtext=None
164198
# return (0, "0:1.21.0-1.el7\n")
165199
return (0, "0:1.29.0-2.el7_9\n")
166200

201+
if command[0:2] == ['blockdev', '--getsize64']:
202+
logger.log("faking %s" % (command,))
203+
return (0, "107374182400\n")
204+
167205
raise RuntimeError("mockrun runCmd2 command not specified: {!r}{}{}".format(
168206
command, " with_stdout" if with_stdout else "", " with_stderr" if with_stderr else ""))
169207

@@ -232,7 +270,7 @@ import diskutil
232270

233271
# modifiable by RAID building
234272
MOCKED_DISKLIST = ['sda',
235-
# 'sdb', 'sdc',
273+
'sdb', 'sdc',
236274
]
237275

238276
def mocked_getDiskList():
@@ -258,6 +296,18 @@ def mocked_readExtPartitionLabel(partition):
258296
"/dev/sda1": "root-foo",
259297
"/dev/sda5": "logs-foo",
260298
}.get(partition, None)
299+
def mocked_idFromPartition(partition):
300+
logger.log("faking idFromPartition")
301+
return None
302+
303+
def mocked_diskutil__readOneLineFile__(filename):
304+
assert filename.startswith("/sys/block/")
305+
if filename.endswith("/device/block/size"):
306+
return "512"
307+
if filename.endswith("/queue/logical_block_size"):
308+
return "512"
309+
# FIXME should be a better ENOENT
310+
raise RuntimeError("No such file %r" % (filename,))
261311

262312
diskutil.getDiskList = mocked_getDiskList
263313
diskutil.getPartitionList = mocked_getPartitionList
@@ -270,6 +320,9 @@ diskutil.getDiskDeviceSize = mocked_getDiskDeviceSize
270320
diskutil.log_available_disks = mocked_log_available_disks
271321

272322
diskutil.readExtPartitionLabel = mocked_readExtPartitionLabel
323+
diskutil.idFromPartition = mocked_idFromPartition
324+
325+
diskutil.__readOneLineFile__ = mocked_diskutil__readOneLineFile__
273326

274327
#
275328

@@ -328,11 +381,11 @@ def mocked_upgrade_open(fname, mode='r', *args, **kwargs):
328381

329382
realfname = fname # default
330383

331-
if fname.startswith(MOUNTPOINT_PRIMARY + '/'):
384+
if MOUNTPOINT_PRIMARY and fname.startswith(MOUNTPOINT_PRIMARY + '/'):
332385
if fname == MOUNTPOINT_PRIMARY + "/etc/xensource/xapi-ssl.pem":
333386
realfname = MOCKDATA + "/etc/xensource/xapi-ssl.pem"
334387

335-
if fname.startswith(MOUNTPOINT_BACKUP + '/'):
388+
if MOUNTPOINT_BACKUP and fname.startswith(MOUNTPOINT_BACKUP + '/'):
336389
if fname == MOUNTPOINT_BACKUP + "/.xen-backup-partition":
337390
realfname = MOCKDATA + "/emptyfile"
338391

@@ -367,9 +420,16 @@ def mocked_repository_open(fname, mode='r', *args, **kwargs):
367420

368421
def mocked_disableInitrdCreation(self, root):
369422
logger.log("faking disableInitrdCreation")
423+
def mocked_enableInitrdCreation(self):
424+
logger.log("faking disableInitrdCreation")
425+
426+
def mocked_installFromYum(yum_conf_path, targets, mounts, progress_callback, cachedir):
427+
logger.log("faking installFromYum")
370428

371429
repository.open = mocked_repository_open
372430
repository.MainYumRepository.disableInitrdCreation = mocked_disableInitrdCreation
431+
repository.MainYumRepository.enableInitrdCreation = mocked_enableInitrdCreation
432+
repository.installFromYum = mocked_installFromYum
373433

374434
#
375435

@@ -412,12 +472,12 @@ def mocked_netinterface_open(fname, mode='r', *args, **kwargs):
412472

413473
realfname = fname # default
414474

415-
if fname.startswith(MOUNTPOINT_PRIMARY + '/'):
475+
if MOUNTPOINT_PRIMARY and fname.startswith(MOUNTPOINT_PRIMARY + '/'):
416476
if fname == MOUNTPOINT_PRIMARY + "/etc/xensource/xapi-ssl.pem":
417477
realfname = MOCKDATA + "/etc/xensource/xapi-ssl.pem"
418478

419479
elif fname.startswith('/etc/sysconfig/network-scripts/ifcfg-'):
420-
realfname = os.path.basename(fname)
480+
realfname = os.path.join(MOCKDATA, os.path.basename(fname))
421481

422482
if realfname != fname:
423483
logger.debug("redirecting open() to %r" % (realfname,))
@@ -442,12 +502,30 @@ generalui.getTimeZoneCities = mocked_getTimeZoneCities
442502

443503
import backend
444504

505+
def mocked_backend_open(fname, mode='r', *args, **kwargs):
506+
logger.debug("open({!r}, mode={!r})".format(fname, mode))
507+
508+
realfname = fname # default
509+
510+
if fname == '/proc/sys/dev/raid/speed_limit_max':
511+
realfname = '/dev/null'
512+
513+
if fname == '/tmp/root/etc/firstboot.d/data/default-storage.conf':
514+
realfname = 'mocked-default-storage.conf'
515+
516+
if realfname != fname:
517+
logger.debug("redirecting open() to %r" % (realfname,))
518+
519+
return open(realfname, mode, *args, **kwargs)
520+
521+
backend.open = mocked_backend_open
522+
445523
def mocked_setTimeNTP(ntp_servers, ntp_config_method):
446524
logger.log("faking setTimeNTP")
447525
def mocked_createDom0DiskFilesystems(install_type, disk, target_boot_mode, boot_partnum, primary_partnum, logs_partnum, disk_label_suffix):
448526
logger.log("faking createDom0DiskFilesystems")
449527

450-
def mocked_mountVolumes(primary_disk, boot_partnum, primary_partnum, logs_partnum, cleanup, target_boot_mode):
528+
def mocked_mountVolumes(primary_disk, physical_disks, boot_partnum, primary_partnum, logs_partnum, cleanup, target_boot_mode, swraid):
451529
logger.log("faking mountVolumes")
452530
mounts = {'root': '/tmp/root',
453531
'boot': '/tmp/root/boot',
@@ -456,26 +534,54 @@ def mocked_mountVolumes(primary_disk, boot_partnum, primary_partnum, logs_partnu
456534
}
457535
return mounts, list(cleanup)
458536

459-
def mocked_umountVolumes(mounts, cleanup, force=False):
537+
def mocked_umountVolumes(disk, mounts, cleanup, force=False):
460538
logger.log("faking umountVolumes")
461539

540+
def mocked_getFinalisationSequence(ans):
541+
logger.log("faking getFinalisationSequenceumountVolumes")
542+
seq = [
543+
# cannot return empty list, so return one entry we mock
544+
backend.Task(backend.importYumAndRpmGpgKeys, backend.A(ans, 'mounts'), []),
545+
]
546+
if ans['install-type'] == backend.INSTALL_TYPE_FRESH:
547+
seq += [
548+
backend.Task(backend.prepareStorageRepositories, backend.A(ans, 'mounts', 'primary-disk', 'storage-partnum', 'guest-disks', 'sr-type'), []),
549+
]
550+
551+
return seq
552+
553+
def mocked_importYumAndRpmGpgKeys(mounts):
554+
logger.log("faking importYumAndRpmGpgKeys")
555+
556+
#def mocked_writeResolvConf(mounts, hn_conf, ns_conf):
557+
# logger.log("faking writeResolvConf")
558+
462559
backend.setTimeNTP = mocked_setTimeNTP
463560
backend.createDom0DiskFilesystems = mocked_createDom0DiskFilesystems
464561
backend.mountVolumes = mocked_mountVolumes
465562
backend.umountVolumes = mocked_umountVolumes
563+
backend.getFinalisationSequence = mocked_getFinalisationSequence
564+
backend.importYumAndRpmGpgKeys = mocked_importYumAndRpmGpgKeys
565+
#backend.writeResolvConf = mocked_writeResolvConf
466566

467567
#
468568

469569
original_os_path_exists = os.path.exists;
470570

471571
def mock_os_path_exists(path):
472572
exists = None
473-
if path in ( # force exists
573+
if MOUNTPOINT_STATE and path in ( # force exists
474574
# MOUNTPOINT_STATE + "/etc/firstboot.d/state",
475575
MOUNTPOINT_STATE + "/var/lib/misc/ran-network-init",
476576
MOUNTPOINT_STATE + "/var/lib/misc/ran-storage-init",
477577
):
478578
exists = True
579+
elif path in (
580+
"/dev/sda",
581+
):
582+
exists = True
583+
elif path.startswith("/dev/md/xs-"):
584+
return True
479585
elif path in ( # force NOT exists
480586
'/titi',
481587
):

0 commit comments

Comments
 (0)