Skip to content

Commit

Permalink
Allow missing rhn.conf file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbosdo committed Jul 7, 2023
1 parent 2869fb9 commit bd638b4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion python/spacewalk/common/rhnConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions python/spacewalk/common/rhnLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Accept missing rhn.conf file
6 changes: 3 additions & 3 deletions python/uyuni/common/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Accept missing rhn.conf file

0 comments on commit bd638b4

Please sign in to comment.