Skip to content

Commit eceeb52

Browse files
praiskupxsuchy
authored andcommitted
Do not fail (not just) hermetic builds for missing resolv.conf
First, Mock cannot guarantee that the host environment provides a resolv.conf file. We should simply warn the user instead of triggering a hard failure. Second, the check for "simple" isolation was incomplete. We need to check for USE_NSPAWN, as it accurately reflects the isolation=auto case. INFO: mock.py version 6.6 starting (python version = 3.14.2, NVR = mock-6.6-1.fc43), args: /usr/libexec/mock/mock --hermetic-build /buildroot/results/buildroot_lock.json /buildroot/results/buildroot_repo --spec /source/libecpg.spec --sources /source --resultdir /results Traceback (most recent call last): File "/usr/libexec/mock/mock", line 1132, in <module> exitStatus = main() File "/usr/lib/python3.14/site-packages/mockbuild/trace_decorator.py", line 93, in trace result = func(*args, **kw) File "/usr/libexec/mock/mock", line 769, in main util.setup_host_resolv(bootstrap_buildroot_config) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.14/site-packages/mockbuild/trace_decorator.py", line 93, in trace result = func(*args, **kw) File "/usr/lib/python3.14/site-packages/mockbuild/util.py", line 890, in setup_host_resolv shutil.copyfile('/etc/resolv.conf', resolv_path) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.14/shutil.py", line 313, in copyfile with open(src, 'rb') as fsrc: ~~~~^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf' Relates: https://bugzilla.redhat.com/show_bug.cgi?id=2433808 Closes: rpm-software-management#1697
1 parent 649b22c commit eceeb52

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mock/py/mockbuild/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ def clean_env():
860860

861861
@traceLog()
862862
def setup_host_resolv(config_opts):
863+
log = getLog()
863864
if not config_opts['use_host_resolv']:
864865
# If we don't copy host's resolv.conf, we at least want to resolve
865866
# our own hostname. See commit 28027fc26d.
@@ -869,7 +870,7 @@ def setup_host_resolv(config_opts):
869870
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
870871
''')
871872

872-
if config_opts['isolation'] == 'simple':
873+
if not USE_NSPAWN:
873874
# Not using nspawn -> don't touch /etc/resolv.conf; we already have
874875
# a valid file prepared by Buildroot._init() (if user requested).
875876
return
@@ -889,7 +890,10 @@ def setup_host_resolv(config_opts):
889890
os.chmod(resolv_path, 0o644)
890891

891892
if config_opts['use_host_resolv']:
892-
shutil.copyfile('/etc/resolv.conf', resolv_path)
893+
try:
894+
shutil.copyfile('/etc/resolv.conf', resolv_path)
895+
except FileNotFoundError:
896+
log.warning("Non-existing resolv.conf on host, using an empty one")
893897

894898
config_opts['nspawn_args'] += ['--bind={0}:/etc/resolv.conf'.format(resolv_path)]
895899

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Mock no longer fails if `resolv.conf` is missing on the host. While builds
2+
requiring network access (--enable-networking) will still fail later, Mock will
3+
no longer crash with a FileNotFoundError during the initialization phase.

0 commit comments

Comments
 (0)