From 921e38d3297373cea90531ca8de54df613b9bfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Fri, 7 Jul 2023 14:27:25 +0200 Subject: [PATCH] Allow missing rhn.conf file Now that rhnLog looks for the apache user and group in rhn.conf unit tests are failing if the file is not present. Use openSUSE values as default if rhn.conf is not available. --- python/spacewalk/common/rhnConfig.py | 6 +++++- python/spacewalk/common/rhnLog.py | 4 ++-- .../spacewalk-backend.changes.cbosdo.rhnconfig-nofile | 1 + python/uyuni/common/fileutils.py | 6 +++--- .../uyuni/uyuni-common-libs.changes.cbosdo.rhnconfig-nofile | 1 + 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 python/spacewalk/spacewalk-backend.changes.cbosdo.rhnconfig-nofile create mode 100644 python/uyuni/uyuni-common-libs.changes.cbosdo.rhnconfig-nofile diff --git a/python/spacewalk/common/rhnConfig.py b/python/spacewalk/common/rhnConfig.py index 0fce7040b747..a05b4d452fda 100644 --- a/python/spacewalk/common/rhnConfig.py +++ b/python/spacewalk/common/rhnConfig.py @@ -100,6 +100,9 @@ def is_initialized(self): def modifiedYN(self): """returns last modified time diff if rhn.conf has changed.""" + if not os.path.exists(self.filename): + return 0 + try: si = os.stat(self.filename) except OSError: @@ -142,7 +145,8 @@ def parse(self): # Now that we parsed the defaults, we parse the multi-key # self.filename configuration (ie, /etc/rhn/rhn.conf) - self.__parsedConfig = parse_file(self.filename) + if os.path.exists(self.filename): + self.__parsedConfig = parse_file(self.filename) # And now generate and cache the current component self.__merge() diff --git a/python/spacewalk/common/rhnLog.py b/python/spacewalk/common/rhnLog.py index 6d189a8c36f1..d3ff21ea5ea3 100644 --- a/python/spacewalk/common/rhnLog.py +++ b/python/spacewalk/common/rhnLog.py @@ -100,7 +100,7 @@ def initLOG(log_file="stderr", level=0, component=""): # fetch uid, gid so we can do a "chown ..." with cfg_component(component=None) as CFG: - apache_uid, apache_gid = getUidGid(CFG.httpd_user, CFG.httpd_group) + apache_uid, apache_gid = getUidGid(CFG.get('httpd_user', 'wwwrun'), CFG.get('httpd_group', 'www')) try: os.makedirs(log_path) @@ -187,7 +187,7 @@ def __init__(self, log_file, level, component): set_close_on_exec(self.fd) if newfileYN: with cfg_component(component=None) as CFG: - apache_uid, apache_gid = getUidGid(CFG.httpd_user, CFG.httpd_group) + apache_uid, apache_gid = getUidGid(CFG.get('httpd_user', 'wwwrun'), CFG.get('httpd_group', 'www')) os.chown(self.file, apache_uid, apache_gid) os.chmod(self.file, int('0660', 8)) except: diff --git a/python/spacewalk/spacewalk-backend.changes.cbosdo.rhnconfig-nofile b/python/spacewalk/spacewalk-backend.changes.cbosdo.rhnconfig-nofile new file mode 100644 index 000000000000..71b461e69276 --- /dev/null +++ b/python/spacewalk/spacewalk-backend.changes.cbosdo.rhnconfig-nofile @@ -0,0 +1 @@ +- Accept missing rhn.conf file diff --git a/python/uyuni/common/fileutils.py b/python/uyuni/common/fileutils.py index 3c6cb06a013c..91396583680f 100644 --- a/python/uyuni/common/fileutils.py +++ b/python/uyuni/common/fileutils.py @@ -301,9 +301,9 @@ def createPath(path, user=None, group=None, chmod=int('0755', 8)): """ with cfg_component(component=None) as CFG: if user is None: - user = CFG.httpd_user + user = CFG.get('httpd_user', 'wwwrun') if group is None: - group = CFG.httpd_group + group = CFG.get('httpd_group', 'www') path = cleanupAbsPath(path) if not os.path.exists(path): @@ -324,7 +324,7 @@ def setPermsPath(path, user=None, group='root', chmod=int('0750', 8)): """chown user.group and set permissions to chmod""" if user is None: with cfg_component(component=None) as CFG: - user = CFG.httpd_user + user = CFG.get('httpd_user', 'wwwrun') if not os.path.exists(path): raise OSError("*** ERROR: Path doesn't exist (can't set permissions): %s" % path) diff --git a/python/uyuni/uyuni-common-libs.changes.cbosdo.rhnconfig-nofile b/python/uyuni/uyuni-common-libs.changes.cbosdo.rhnconfig-nofile new file mode 100644 index 000000000000..71b461e69276 --- /dev/null +++ b/python/uyuni/uyuni-common-libs.changes.cbosdo.rhnconfig-nofile @@ -0,0 +1 @@ +- Accept missing rhn.conf file