This is an automated email from the ASF dual-hosted git repository.
weizhou pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push:
new d89d40595cb cloudutils: fix adding rocky9 host failure due to missing
/etc/sysconfig/libvirtd (#7779)
d89d40595cb is described below
commit d89d40595cb12b8ec09febc4a2a6248a780bdc73
Author: Wei Zhou <[email protected]>
AuthorDate: Fri Jul 28 16:27:44 2023 +0800
cloudutils: fix adding rocky9 host failure due to missing
/etc/sysconfig/libvirtd (#7779)
---
python/lib/cloudutils/configFileOps.py | 68 +++++++++++++++++-----------------
1 file changed, 35 insertions(+), 33 deletions(-)
diff --git a/python/lib/cloudutils/configFileOps.py
b/python/lib/cloudutils/configFileOps.py
index 698f2b31a3a..41e9c7a1e8e 100644
--- a/python/lib/cloudutils/configFileOps.py
+++ b/python/lib/cloudutils/configFileOps.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import re
+import os
import tempfile
import shutil
from .utilities import bash
@@ -59,39 +60,42 @@ class configFileOps:
return ""
def save(self):
- fp = open(self.fileName, "r")
newLines = []
- for line in fp.readlines():
- matched = False
- for entry in self.entries:
- if entry.op == "add":
- if entry.separator == "=":
- matchString = "^\ *" + entry.name + ".*"
- elif entry.separator == " ":
- matchString = "^\ *" + entry.name + "\ *" + entry.value
- else:
- if entry.separator == "=":
- matchString = "^\ *" + entry.name + "\ *=\ *" +
entry.value
+ if os.path.exists(self.fileName) and os.path.isfile(self.fileName):
+ fp = open(self.fileName, "r")
+ for line in fp.readlines():
+ matched = False
+ for entry in self.entries:
+ if entry.op == "add":
+ if entry.separator == "=":
+ matchString = "^\ *" + entry.name + ".*"
+ elif entry.separator == " ":
+ matchString = "^\ *" + entry.name + "\ *" +
entry.value
else:
- matchString = "^\ *" + entry.name + "\ *" + entry.value
-
- match = re.match(matchString, line)
- if match is not None:
- if entry.op == "add" and entry.separator == "=":
- newline = "\n" + entry.name + "=" + entry.value + "\n"
- entry.setState("set")
- newLines.append(newline)
- self.backups.append([line, newline])
- matched = True
- break
- elif entry.op == "rm":
- entry.setState("set")
- self.backups.append([line, None])
- matched = True
- break
-
- if not matched:
- newLines.append(line)
+ if entry.separator == "=":
+ matchString = "^\ *" + entry.name + "\ *=\ *" +
entry.value
+ else:
+ matchString = "^\ *" + entry.name + "\ *" +
entry.value
+
+ match = re.match(matchString, line)
+ if match is not None:
+ if entry.op == "add" and entry.separator == "=":
+ newline = "\n" + entry.name + "=" + entry.value +
"\n"
+ entry.setState("set")
+ newLines.append(newline)
+ self.backups.append([line, newline])
+ matched = True
+ break
+ elif entry.op == "rm":
+ entry.setState("set")
+ self.backups.append([line, None])
+ matched = True
+ break
+
+ if not matched:
+ newLines.append(line)
+
+ fp.close()
for entry in self.entries:
if entry.getState() != "set":
@@ -101,8 +105,6 @@ class configFileOps:
self.backups.append([None, newline])
entry.setState("set")
- fp.close()
-
open(self.fileName, "w").writelines(newLines)
def replace_line(self, startswith,stanza,always_add=False):