-
-
Notifications
You must be signed in to change notification settings - Fork 741
Expand file tree
/
Copy pathtest_minimal_install.py
More file actions
171 lines (151 loc) · 4.25 KB
/
test_minimal_install.py
File metadata and controls
171 lines (151 loc) · 4.25 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import pytest
import subprocess
import string
import random
import pathlib
import json
import time
import sys
def simple_exec(cmd):
proc = subprocess.Popen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
output = b''
while proc.poll() is None:
line = proc.stdout.read(1024)
print(line.decode(), end='')
sys.stdout.flush()
output += line
time.sleep(0.01)
output += proc.stdout.read()
proc.stdout.close()
return {'exit_code' : proc.poll(), 'data' : output.decode().strip()}
def random_filename():
return ''.join([random.choice(string.ascii_letters) for x in range(20)]) + '.img'
def truncate_file(filename):
result = simple_exec(f"truncate -s 20G {filename}")
if not result['exit_code'] == 0:
raise AssertionError(f"Could not generate a testimage with truncate: {result['data']}")
return filename
def get_loopdev(filename):
result = simple_exec(f"""losetup -a | grep "{filename}" | awk -F ":" '{{print $1}}'""")
return result['data']
def detach_loopdev(path):
result = simple_exec(f"losetup -d {path}")
return result['exit_code'] == 0
def create_loopdev(path):
result = simple_exec(f"losetup -fP {path}")
return result['exit_code'] == 0
def test_stat_blockdev():
import archinstall
filename = pathlib.Path(random_filename()).resolve()
if loopdev := get_loopdev(filename):
if not detach_loopdev(loopdev):
raise AssertionError(f"Could not detach {loopdev} before performing test with {filename}.")
truncate_file(filename)
if not create_loopdev(filename):
raise AssertionError(f"Could not create a loopdev for {filename}")
if loopdev := get_loopdev(filename):
user_configuration = {
"audio": "pipewire",
"config_version": "2.4.2",
"debug": True,
"harddrives": [
loopdev
],
"mirror-region": {
"Sweden": {
"http://ftp.acc.umu.se/mirror/archlinux/$repo/os/$arch": True,
"http://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch": True,
"http://ftp.myrveln.se/pub/linux/archlinux/$repo/os/$arch": True,
"http://ftpmirror.infania.net/mirror/archlinux/$repo/os/$arch": True,
"https://ftp.acc.umu.se/mirror/archlinux/$repo/os/$arch": True,
"https://ftp.ludd.ltu.se/mirrors/archlinux/$repo/os/$arch": True,
"https://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch": True,
"https://ftp.myrveln.se/pub/linux/archlinux/$repo/os/$arch": True,
"https://mirror.osbeck.com/archlinux/$repo/os/$arch": True
}
},
"mount_point": None,
"nic": {
"dhcp": True,
"dns": None,
"gateway": None,
"iface": None,
"ip": None,
"type": "iso"
},
"packages": [
"nano"
],
"plugin": None,
"profile": {
"path": "/usr/lib/python3.10/site-packages/archinstall/profiles/minimal.py"
},
"script": "guided",
"silent": True,
"timezone": "Europe/Stockholm",
"version": "2.4.2"
}
user_credentials = {
"!encryption-password": "test",
"!superusers": {
"anton": {
"!password": "test"
}
},
"!users": {}
}
user_disk_layout = {
loopdev: {
"partitions": [
{
"boot": True,
"encrypted": False,
"filesystem": {
"format": "fat32"
},
"mountpoint": "/boot",
"size": "512MiB",
"start": "1MiB",
"type": "primary",
"wipe": True
},
{
"btrfs": {
"subvolumes": {
"@": "/",
"@.snapshots": "/.snapshots",
"@home": "/home",
"@log": "/var/log",
"@pkg": "/var/cache/pacman/pkg"
}
},
"encrypted": False,
"filesystem": {
"format": "btrfs",
"mount_options": [
"compress=zstd"
]
},
"mountpoint": None,
"size": "100%",
"start": "513MiB",
"type": "primary",
"wipe": True
}
],
"wipe": True
}
}
result = archinstall.SysCommand(f'archinstall --silent --config \'{json.dumps(user_configuration)}\' --creds \'{json.dumps(user_credentials)}\' --disk-layout \'{json.dumps(user_disk_layout)}\'', peak_output=True)
#print(result)
# Test ended, cleanup commences
if not detach_loopdev(loopdev):
raise AssertionError(f"Could not detach {loopdev} after performing tests on {filename}.")
else:
raise AssertionError(f"Could not retrieve a loopdev for testing on {filename}")
pathlib.Path(filename).resolve().unlink()