add timezone stage
This commit is contained in:
parent
693cd4e6b0
commit
593c6de385
3 changed files with 89 additions and 6 deletions
30
stages/org.osbuild.timezone
Executable file
30
stages/org.osbuild.timezone
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def main(tree, options):
|
||||
zone = options["zone"]
|
||||
|
||||
# We need to remove the /etc/localtime symlink first, because it is created while we install RPM packages.
|
||||
# systemd-firstboot expects that if /etc/localtime exists it is a user-defined value and does not change it, but
|
||||
# the assumption is wrong, because it contains a default value from RPM package.
|
||||
# This is (hopefully) a temporary workaround.
|
||||
try:
|
||||
os.remove(f"{tree}/etc/localtime")
|
||||
# ^ This will fail once systemd RPM package stops shipping the file
|
||||
except FileNotFoundError:
|
||||
print("systemd does not ship /etc/localtime anymore. Remove the workaround")
|
||||
|
||||
subprocess.run(["systemd-firstboot", f"--root={tree}", f"--timezone={zone}"], check=True)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
@ -66,14 +66,35 @@ def test_web_server():
|
|||
assert curl.stdout.decode("utf-8").strip() == "hello, world!"
|
||||
|
||||
|
||||
def build_timezone_image():
|
||||
run_osbuild(rel_path("timezone-test.json"))
|
||||
|
||||
|
||||
def test_timezone():
|
||||
extract_dir = tempfile.mkdtemp(prefix="osbuild-")
|
||||
subprocess.run(["tar", "xf", OUTPUT_DIR + "/timezone-output.tar.xz"], cwd=extract_dir, check=True)
|
||||
ls = subprocess.run(["ls", "-l", "etc/localtime"], cwd=extract_dir, check=True, stdout=subprocess.PIPE)
|
||||
ls_output = ls.stdout.decode("utf-8")
|
||||
assert "Europe/Prague" in ls_output
|
||||
|
||||
|
||||
def evaluate_test(test):
|
||||
try:
|
||||
test()
|
||||
print(f"{RESET}{BOLD}{test.__name__}: Success{RESET}")
|
||||
except AssertionError as e:
|
||||
print(f"{RESET}{BOLD}{test.__name__}: {RESET}{RED}Fail{RESET}")
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.info("Running tests")
|
||||
build_web_server_image()
|
||||
tests = [test_web_server]
|
||||
with boot_image(IMAGE_PATH):
|
||||
for test in tests:
|
||||
try:
|
||||
test()
|
||||
print(f"{RESET}{BOLD}{test.__name__}: Success{RESET}")
|
||||
except AssertionError as e:
|
||||
print(f"{RESET}{BOLD}{test.__name__}: {RESET}{RED}Fail{RESET}")
|
||||
print(e)
|
||||
evaluate_test(test)
|
||||
|
||||
build_timezone_image()
|
||||
evaluate_test(test_timezone)
|
||||
|
||||
|
|
|
|||
32
test/timezone-test.json
Normal file
32
test/timezone-test.json
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "Example Image",
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.dnf",
|
||||
"options": {
|
||||
"releasever": "30",
|
||||
"repos": {
|
||||
"fedora": {
|
||||
"name": "Fedora",
|
||||
"metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
|
||||
"gpgkey": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch"
|
||||
}
|
||||
},
|
||||
"packages": ["@Core"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "org.osbuild.timezone",
|
||||
"options": {
|
||||
"zone": "Europe/Prague"
|
||||
}
|
||||
}
|
||||
],
|
||||
"assembler": {
|
||||
"name": "org.osbuild.tar",
|
||||
"options": {
|
||||
"filename": "timezone-output.tar.xz",
|
||||
"compression": "xz"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue