From 8289d6c7834415878ae7524e8a718abbce49a1b0 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Wed, 12 Dec 2012 21:11:06 -0500 Subject: [PATCH] Ensure we add a new line when appending to rc.local When we add content to rc.local, if the file already exists then we need to make sure we add the content after a new line explicitly Fixes LP #1089668 Change-Id: I35be1496703b302f732363fa76ce832505eed599 (cherry picked from commit f393a513d7894ddb800e4dfc87da896600fb7421) --- nova/virt/disk/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 16bd9fe048c..ab63a89b28a 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -415,11 +415,14 @@ def _setup_selinux_for_keys(fs): # and so to append there you'd need something like: # utils.execute('sed', '-i', '${/^exit 0$/d}' rclocal, run_as_root=True) restorecon = [ - '#!/bin/sh\n', + '\n', '# Added by Nova to ensure injected ssh keys have the right context\n', 'restorecon -RF /root/.ssh/ 2>/dev/null || :\n', ] + if not fs.has_file(rclocal): + restorecon.insert(0, '#!/bin/sh') + rclocal_rel = os.path.relpath(rclocal, fs) _inject_file_into_fs(fs, rclocal_rel, ''.join(restorecon), append=True) utils.execute('chmod', 'a+x', rclocal, run_as_root=True)