From 28027fc26d5258efe5034bb975157a3f61dfcfec Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 27 Feb 2009 03:45:48 +0100 Subject: Be able to resolve hostname Copy /etc/hosts from host when resolver configuration is being copied, otherwise add hostname as a loopback alias. --- py/mock.py | 6 +++++- py/mock/backend.py | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'py') diff --git a/py/mock.py b/py/mock.py index 408b421..dd5d1af 100755 --- a/py/mock.py +++ b/py/mock.py @@ -40,6 +40,7 @@ import pwd import sys import time from optparse import OptionParser +from socket import gethostname # all of the variables below are substituted by the build system __VERSION__ = "unreleased_version" @@ -268,7 +269,6 @@ def setup_default_config_opts(config_opts, unprivUid): config_opts['yum.conf'] = '' config_opts['more_buildreqs'] = {} config_opts['files'] = {} - config_opts['files']['etc/hosts'] = "127.0.0.1 localhost localhost.localdomain\n" config_opts['macros'] = { '%_topdir': '%s/build' % config_opts['chroothome'], '%_rpmfilename': '%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm', @@ -519,6 +519,10 @@ def main(ret): # cmdline options override config options set_config_opts_per_cmdline(config_opts, options, args) + # default /etc/hosts contents + if not config_opts['use_host_resolv'] and not config_opts['files'].has_key('etc/hosts'): + config_opts['files']['etc/hosts'] = "127.0.0.1 localhost localhost.localdomain %s\n" % gethostname(); + # elevate privs uidManager._becomeUser(0, 0) diff --git a/py/mock/backend.py b/py/mock/backend.py index 86b3fb7..78358c7 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -227,13 +227,19 @@ class Root(object): pass os.symlink('yum/yum.conf', self.makeChrootPath("etc", "yum.conf")) - # set up resolv.conf + # set up resolver configuration if self.use_host_resolv: - resolvdir = self.makeChrootPath('etc') - resolvpath = self.makeChrootPath('etc', 'resolv.conf') - if os.path.exists(resolvpath): - os.remove(resolvpath) - shutil.copy2('/etc/resolv.conf', resolvdir) + etcdir = self.makeChrootPath('etc') + + resolvconfpath = self.makeChrootPath('etc', 'resolv.conf') + if os.path.exists(resolvconfpath): + os.remove(resolvconfpath) + shutil.copy2('/etc/resolv.conf', etcdir) + + hostspath = self.makeChrootPath('etc', 'hosts') + if os.path.exists(hostspath): + os.remove(hostspath) + shutil.copy2('/etc/hosts', etcdir) # files in /etc that need doing for key in self.chroot_file_contents: -- cgit