[elbe-devel] [PATCH 6/6] tests: simple-validation-image: test common finetuning actions

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon May 27 14:12:19 CEST 2024


Validate that the finetuning from XML ends up correctly in the final image.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 tests/simple-validation-image-test.py | 46 +++++++++++++++++++++++++++++++++++
 tests/simple-validation-image.xml     | 19 +++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/tests/simple-validation-image-test.py b/tests/simple-validation-image-test.py
index 718b4645de38..ba12326693f7 100755
--- a/tests/simple-validation-image-test.py
+++ b/tests/simple-validation-image-test.py
@@ -21,6 +21,50 @@ def test_build_directory_contents(build_dir):
     ]
 
 
+def _test_finetuning(root):
+    # <rm>var/cache/apt/archives/*.deb</rm>
+    for f in root.joinpath('var', 'cache', 'apt', 'archives').iterdir():
+        assert f.suffix != '.deb'
+
+    # <mkdir>/var/cache/test-dir</mkdir>
+    assert root.joinpath('var', 'cache', 'test-dir').is_dir()
+
+    # <mknod opts="c 0 5">/dev/null2</mknod>
+    assert root.joinpath('dev', 'null2').is_char_device()
+
+    # <cp path="/etc/hosts">/etc/hosts2</cp>
+    assert root.joinpath('etc', 'hosts2').is_file()
+    assert root.joinpath('etc', 'hosts2').read_text() == root.joinpath('etc', 'hosts').read_text()
+
+    # <mv path="/etc/issue">/etc/issue2</mv>
+    assert root.joinpath('etc', 'issue2').is_file()
+    assert not root.joinpath('etc', 'issue').exists()
+
+    # <ln path="/etc/hosts">/etc/hosts3</ln>
+    assert root.joinpath('etc', 'hosts3').is_symlink()
+    assert root.joinpath('etc', 'hosts3').readlink() == root.joinpath('etc', 'hosts')
+
+    # <adduser groups="nogroup,staff" shell="/bin/sh" uid="2000"
+    #          home="/home/nottestuser" system="true" create_home="true" create_group="true">
+    #   testuser
+    # </adduser>
+    assert '\ntestuser:x:2000:997::/home/nottestuser:/bin/sh\n' in \
+        root.joinpath('etc', 'passwd').read_text()
+
+    # <addgroup gid="2001" system="false">testgroup</addgroup>
+    assert '\ntestgroup:x:2001:\n' in root.joinpath('etc', 'group').read_text()
+
+    # <file dst="/testfile" encoding="plain" owner="nobody" group="nogroup" mode="640">
+    # 	Some cöntent wíth spe©ial characters
+    # </file>
+    assert root.joinpath('testfile').is_file()
+    assert root.joinpath('testfile').read_text() == 'Some cöntent wíth spe©ial characters'
+
+    # <raw_cmd>cat /etc/hosts | cat -n > /etc/hosts4</raw_cmd>
+    assert root.joinpath('etc', 'hosts4').is_file()
+    assert root.joinpath('etc', 'hosts4').read_text().startswith('     1\t127.0.0.1\tlocalhost\n')
+
+
 def _test_rfs_partition(part):
     assert part.number == 1
     assert part.start == 1 * 1024 * 1024
@@ -62,6 +106,8 @@ def _test_rfs_partition(part):
         assert getty_service.is_symlink()
         assert str(getty_service.readlink()) == '/lib/systemd/system/serial-getty at .service'
 
+        _test_finetuning(root)
+
 
 def test_image(build_dir):
     with elbevalidate.Image.from_file(build_dir / 'sda.img') as img:
diff --git a/tests/simple-validation-image.xml b/tests/simple-validation-image.xml
index e2fe03c4b9a8..64fe8cf9af3f 100644
--- a/tests/simple-validation-image.xml
+++ b/tests/simple-validation-image.xml
@@ -50,6 +50,25 @@ SPDX-FileCopyrightText: Linutronix GmbH
 			</bylabel>
 		</fstab>
 
+		<finetuning>
+			<rm>var/cache/apt/archives/*.deb</rm>
+			<mkdir>/var/cache/test-dir</mkdir>
+			<mknod opts="c 0 5">/dev/null2</mknod>
+			<cp path="/etc/hosts">/etc/hosts2</cp>
+			<mv path="/etc/issue">/etc/issue2</mv>
+			<ln path="/etc/hosts">/etc/hosts3</ln>
+
+			<adduser groups="nogroup,staff" shell="/bin/sh" uid="2000"
+				 home="/home/nottestuser" system="true" create_home="true" create_group="true">testuser</adduser>
+			<addgroup gid="2001" system="false">testgroup</addgroup>
+
+			<file dst="/testfile" encoding="plain" owner="nobody" group="nogroup" mode="640">
+				Some cöntent wíth spe©ial characters
+			</file>
+
+			<raw_cmd>cat /etc/hosts | cat -n > /etc/hosts4</raw_cmd>
+		</finetuning>
+
 		<project-finetuning>
 			<set_packer packer="none">sda.img</set_packer>
 		</project-finetuning>

-- 
2.45.1



More information about the elbe-devel mailing list