From 19c4a2227fb51b5c4791a4e972d590c7f3256220 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Mar 2024 16:04:59 +0100 Subject: [PATCH] Revert "osbuild: ensure loop.Loop() has the required device node" This reverts commit 158acaac785056132bffa777755d93e490e2e2d6. With https://github.com/osbuild/bootc-image-builder/pull/238 the original reason to call mknod goes away so we can just revert it. osbuild now requires not only the loop device but also uses `losetup --partscan` quite a lot now so the mknod approach becomes impractical and the consumers of osbuild in a container should just setup devtmpfs. --- osbuild/loop.py | 13 ++----------- test/mod/test_loop.py | 11 ----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/osbuild/loop.py b/osbuild/loop.py index 7f6021913d..2e05638ede 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -15,9 +15,6 @@ "UnexpectedDevice" ] -# can be mocked in tests -DEV_PATH = "/dev" - class UnexpectedDevice(Exception): def __init__(self, expected_minor, rdev, mode): @@ -127,14 +124,8 @@ def __init__(self, minor, dir_fd=None): with contextlib.ExitStack() as stack: if not dir_fd: - dir_fd = os.open(DEV_PATH, os.O_DIRECTORY) + dir_fd = os.open("/dev", os.O_DIRECTORY) stack.callback(lambda: os.close(dir_fd)) - # ensure the device node is availale, in containers it may - # not get dynamically created - try: - self.mknod(dir_fd) - except FileExistsError: - pass self.fd = os.open(self.devname, os.O_RDWR, dir_fd=dir_fd) info = os.stat(self.fd) @@ -543,7 +534,7 @@ def __init__(self, dir_fd=None): with contextlib.ExitStack() as stack: if not dir_fd: - dir_fd = os.open(DEV_PATH, os.O_DIRECTORY) + dir_fd = os.open("/dev", os.O_DIRECTORY) stack.callback(lambda: os.close(dir_fd)) self.fd = os.open("loop-control", os.O_RDWR, dir_fd=dir_fd) diff --git a/test/mod/test_loop.py b/test/mod/test_loop.py index fb052122b0..a668491572 100644 --- a/test/mod/test_loop.py +++ b/test/mod/test_loop.py @@ -5,7 +5,6 @@ import contextlib import fcntl import os -import pathlib import threading import time from tempfile import TemporaryDirectory, TemporaryFile @@ -261,13 +260,3 @@ def on_close(l): def test_loop_handles_error_in_init(mocked_open): # pylint: disable=unused-argument with pytest.raises(FileNotFoundError): loop.Loop(999) - - -@pytest.mark.skipif(os.getuid() != 0, reason="root only") -def test_loop_create_mknod(): - # tmpdir must be /var/tmp because /tmp is usually mounted with "nodev" - with TemporaryDirectory(dir="/var/tmp") as tmpdir: - with patch.object(loop, "DEV_PATH", new=tmpdir): - lopo = loop.Loop(1337) - assert lopo.devname == "loop1337" - assert pathlib.Path(f"{tmpdir}/loop1337").is_block_device()