summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-07-19 09:07:23 -0400
committerMartin Kosek <mkosek@redhat.com>2012-08-03 12:09:56 +0200
commitc8abd24ebe612a3a0d415cece508b94a57c636fe (patch)
tree9aaf37c460e45857e96f19195552729def521816 /ipapython
parent1be46b322f1fe469cf3cc5e5a77a96b29f8beb7f (diff)
downloadfreeipa.git-c8abd24ebe612a3a0d415cece508b94a57c636fe.tar.gz
freeipa.git-c8abd24ebe612a3a0d415cece508b94a57c636fe.tar.xz
freeipa.git-c8abd24ebe612a3a0d415cece508b94a57c636fe.zip
Create /etc/sysconfig/network if it doesn't exist
When the --hostname option is given to ipa-client-install, we write HOSTNAME to /etc/sysconfig/network. When that file didn't exist, the installer crashed. Create the file if it doesn't exist and we need to write to it. https://fedorahosted.org/freeipa/ticket/2840
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py4
-rw-r--r--ipapython/platform/redhat.py16
2 files changed, 16 insertions, 4 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index bed5435b..1b059776 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -991,13 +991,15 @@ $)''', re.VERBOSE)
return old_values
-def backup_config_and_replace_variables(fstore, filepath, replacevars=dict(), appendvars=dict()):
+def backup_config_and_replace_variables(
+ fstore, filepath, replacevars=dict(), appendvars=dict()):
"""
Take a key=value based configuration file, back up it, and
write new version with certain values replaced or appended
All (key,value) pairs from replacevars and appendvars that
were not found in the configuration file, will be added there.
+ The file must exist before this function is called.
It is responsibility of a caller to ensure that replacevars and
appendvars do not overlap.
diff --git a/ipapython/platform/redhat.py b/ipapython/platform/redhat.py
index d3c23ab0..3f35cfcc 100644
--- a/ipapython/platform/redhat.py
+++ b/ipapython/platform/redhat.py
@@ -24,6 +24,8 @@ import os
import stat
import sys
import socket
+import stat
+
from ipapython import ipautil
from ipapython.platform import base
from ipalib import api
@@ -187,10 +189,18 @@ def backup_and_replace_hostname(fstore, statestore, hostname):
except ipautil.CalledProcessError, e:
print >>sys.stderr, "Failed to set this machine hostname to %s (%s)." % (hostname, str(e))
replacevars = {'HOSTNAME':hostname}
- old_values = ipautil.backup_config_and_replace_variables(fstore,
- "/etc/sysconfig/network",
- replacevars=replacevars)
+
+ filepath = '/etc/sysconfig/network'
+ if not os.path.exists(filepath):
+ # file doesn't exist; create it with correct ownership & mode
+ open(filepath, 'a').close()
+ os.chmod(filepath,
+ stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
+ os.chown(filepath, 0, 0)
+ old_values = ipautil.backup_config_and_replace_variables(
+ fstore, filepath, replacevars=replacevars)
restore_context("/etc/sysconfig/network")
+
if 'HOSTNAME' in old_values:
statestore.backup_state('network', 'hostname', old_values['HOSTNAME'])
else: