-
Notifications
You must be signed in to change notification settings - Fork 16
/
validate_release.py
executable file
·120 lines (99 loc) · 4.35 KB
/
validate_release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python3
import argparse
import ctypes
import json
import os
import pwd
import subprocess
import sys
import tempfile
import time
import urllib.request as request
def handle_options():
"""Setup option parsing
"""
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true', default=None,
help='More verbose output.')
parser.add_argument('-b' , '--bios', action='store', default=None,
help='Use specified bios file for qemu')
parser.add_argument('-V' , '--vnc', action='store', default=0,
help='Use specified vnc port number')
args = parser.parse_args()
if args.bios is None:
print("Error: -b|--bios require")
# print("{0}").format(parser.usage)
sys.exit(1)
return args
def spin_up_installer():
print(">>> Spinning new installer into ./installer-val.img")
if os.path.isfile('./installer-val.img'):
os.remove('./installer-val.img')
cp = subprocess.run(['qemu-img', 'create', 'installer-val.img', '2G'])
cp = subprocess.run(['sudo', 'python3', 'ister.py', '-t',
'installer-config-vm.json'])
cp.check_returncode()
def validate_installer(args, expectfile, unitfile, alternative_check=None):
print(">>> Configuring installer-val.img to be driven by expect using new ister and gui")
cp = subprocess.run(['sudo', './update_gui_expect.sh', 'installer-val.img',
expectfile, unitfile])
cp.check_returncode()
print(">>> Create target image for install")
if os.path.isfile('installer-target.img'):
os.remove('./installer-target.img')
cp = subprocess.run(['qemu-img', 'create', 'installer-target.img', '10G'])
cp.check_returncode()
print(">>> Booting installer-val.img against installer-target.img")
cp = subprocess.run(['sudo', 'qemu-system-x86_64', '-enable-kvm', '-m',
'1024', '-vnc', '0.0.0.0:{}'.format(args.vnc), '-cpu', 'host', '-drive',
'file=installer-target.img,if=virtio,aio=threads',
'-drive', 'file=installer-val.img,if=virtio,aio=threads',
'-net', 'nic,model=virtio', '-net',
'user,hostfwd=tcp::2233-:22', '-smp', '2',
'-bios', args.bios])
cp.check_returncode()
if not alternative_check:
print(">>> Installing boot canary into installer-target.mg")
cp = subprocess.run(['sudo', './install-canary.sh', 'installer-target.img'])
cp.check_returncode()
print(">>> Booting installer-target.img")
cp = subprocess.run(['sudo', 'qemu-system-x86_64', '-enable-kvm', '-m',
'1024', '-vnc', '0.0.0.0:{}'.format(args.vnc), '-cpu', 'host', '-drive',
'file=installer-target.img,if=virtio,aio=threads',
'-net', 'nic,model=virtio', '-net',
'user,hostfwd=tcp::2233-:22', '-smp', '2',
'-bios', args.bios])
cp.check_returncode()
# Check for boot canary
cp = subprocess.run(['sudo', './check-canary.sh', 'installer-target.img'])
status_code = cp.returncode
else:
status_code = alternative_check(args)
if status_code == 0:
status = ">>> SUCCESS! Boot Canary detected!"
else:
status = ">>> Failure: installer-target.img failed to boot"
print(status)
return status
def encryption_validation(args):
cp = subprocess.run(['sudo', './post-encryption.expect', args.bios])
cp.check_returncode()
return cp.returncode
def main():
"""Start the installer
"""
args = handle_options()
try:
spin_up_installer()
autostatus = validate_installer(args, 'autoinstall.expect', 'ister-expect.service')
manstatus = validate_installer(args, 'maninstall.expect', 'ister-manexpect.service')
encryptstatus = validate_installer(args, 'encryption.expect', 'ister-encryption.service', encryption_validation)
print('\nAutomatic Installation', autostatus)
print('Manual Installation ', manstatus)
print('Manual Installation root Encrypted ', encryptstatus)
except Exception as exep:
print("Failed: {}".format(exep))
sys.exit(-1)
sys.exit(0)
if __name__ == '__main__':
main()