Added unattended installation of guided with test data
This commit is contained in:
parent
e1091ffc95
commit
8adade206a
|
|
@ -150,7 +150,7 @@ def get_arguments() -> Dict[str, Any]:
|
||||||
parsed_url = urllib.parse.urlparse(args.config)
|
parsed_url = urllib.parse.urlparse(args.config)
|
||||||
|
|
||||||
if not parsed_url.scheme: # The Profile was not a direct match on a remote URL, it must be a local file.
|
if not parsed_url.scheme: # The Profile was not a direct match on a remote URL, it must be a local file.
|
||||||
if not json_stream_to_structure('--config',args.config,config):
|
if not json_stream_to_structure('--config', args.config, config):
|
||||||
exit(1)
|
exit(1)
|
||||||
else: # Attempt to load the configuration from the URL.
|
else: # Attempt to load the configuration from the URL.
|
||||||
with urllib.request.urlopen(urllib.request.Request(args.config, headers={'User-Agent': 'ArchInstall'})) as response:
|
with urllib.request.urlopen(urllib.request.Request(args.config, headers={'User-Agent': 'ArchInstall'})) as response:
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
../examples/
|
|
||||||
|
|
@ -178,8 +178,8 @@ def perform_installation(mountpoint):
|
||||||
archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
|
archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
|
||||||
|
|
||||||
# Retrieve list of additional repositories and set boolean values appropriately
|
# Retrieve list of additional repositories and set boolean values appropriately
|
||||||
enable_testing = 'testing' in archinstall.arguments.get('additional-repositories', None)
|
enable_testing = 'testing' in archinstall.arguments.get('additional-repositories', [])
|
||||||
enable_multilib = 'multilib' in archinstall.arguments.get('additional-repositories', None)
|
enable_multilib = 'multilib' in archinstall.arguments.get('additional-repositories', [])
|
||||||
|
|
||||||
if installation.minimal_installation(testing=enable_testing, multilib=enable_multilib):
|
if installation.minimal_installation(testing=enable_testing, multilib=enable_multilib):
|
||||||
installation.set_locale(archinstall.arguments['sys-language'], archinstall.arguments['sys-encoding'].upper())
|
installation.set_locale(archinstall.arguments['sys-language'], archinstall.arguments['sys-encoding'].upper())
|
||||||
|
|
@ -126,6 +126,6 @@ def log(*args :str, **kwargs :Union[str, int, Dict[str, Union[str, int]]]) -> No
|
||||||
# Finally, print the log unless we skipped it based on level.
|
# Finally, print the log unless we skipped it based on level.
|
||||||
# We use sys.stdout.write()+flush() instead of print() to try and
|
# We use sys.stdout.write()+flush() instead of print() to try and
|
||||||
# fix issue #94
|
# fix issue #94
|
||||||
if kwargs.get('level', logging.INFO) != logging.DEBUG or storage['arguments'].get('verbose', False):
|
if kwargs.get('level', logging.INFO) != logging.DEBUG or hasattr(storage.get('arguments'), 'verbose') and storage['arguments'].verbose:
|
||||||
sys.stdout.write(f"{string}\n")
|
sys.stdout.write(f"{string}\n")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
../profiles/
|
|
||||||
|
|
@ -112,6 +112,4 @@ def test_stat_blockdev():
|
||||||
else:
|
else:
|
||||||
raise AssertionError(f"Could not retrieve a loopdev for testing on {filename}")
|
raise AssertionError(f"Could not retrieve a loopdev for testing on {filename}")
|
||||||
|
|
||||||
pathlib.Path(filename).resolve().unlink()
|
pathlib.Path(filename).resolve().unlink()
|
||||||
|
|
||||||
test_stat_blockdev()
|
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
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()
|
||||||
|
|
||||||
|
test_stat_blockdev()
|
||||||
Loading…
Reference in New Issue