Merge lp:~roadmr/checkbox/lxc-fix-permissions-after-provisioning-fail into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 3706
Merged at revision: 3706
Proposed branch: lp:~roadmr/checkbox/lxc-fix-permissions-after-provisioning-fail
Merge into: lp:checkbox
Diff against target: 54 lines (+17/-13)
1 file modified
test-in-lxc.sh (+17/-13)
To merge this branch: bzr merge lp:~roadmr/checkbox/lxc-fix-permissions-after-provisioning-fail
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+256589@code.launchpad.net

Commit message

test-in-lxc: Fix file permissions if provisioning fails.

Writing files in the source tree during the provisioning phase is
not recommended, but if it happens, ensure that, after a possible
provisioning failure, permissions are reset to those of the user who
owned the original tree (using test-in-lxc.sh as reference).

Previously we would only fix file permissions after running the tests,
and the provisioning phase was assumed not to leave possibly-undeletable
files in the source directory.

Description of the change

test-in-lxc: Fix file permissions if provisioning fails.

Writing files in the source tree during the provisioning phase is
not recommended, but if it happens, ensure that, after a possible
provisioning failure, permissions are reset to those of the user who
owned the original tree (using test-in-lxc.sh as reference).

Previously we would only fix file permissions after running the tests,
and the provisioning phase was assumed not to leave possibly-undeletable
files in the source directory.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test-in-lxc.sh'
2--- test-in-lxc.sh 2014-06-16 21:31:53 +0000
3+++ test-in-lxc.sh 2015-04-16 21:55:51 +0000
4@@ -118,7 +118,7 @@
5 echo "[$target] Unable to provision requirements in container!"
6 echo "[$target] stdout: $(pastebinit $LOG_DIR/$target.provision.log)"
7 echo "[$target] stderr: $(pastebinit $LOG_DIR/$target.provision.err)"
8- echo "[$target] NOTE: unable to execute tests, marked as failed"
9+ fix_permissions
10 echo "[$target] Destroying failed container to reclaim resources"
11 sudo $LXC_DESTROY -f -n $target_container
12 return 1
13@@ -126,6 +126,21 @@
14 cat $TIMING | sed -e "s/^/[$target] (timing) /"
15 }
16
17+fix_permissions(){
18+ # Fix permissions.
19+ # provision-testing-environment runs as root and creates a series of
20+ # root-owned files in the branch directory. Later, tarmac will want
21+ # to delete these files, so after provisioning we change everything
22+ # under the branch directory to be owned by the unprivileged user,
23+ # so stuff can be deleted correctly later.
24+ echo "[$target] Fixing file permissions in source directory"
25+ if ! sudo $LXC_ATTACH --keep-env -n $target_container -- bash -c "chown -R --reference=test-in-lxc.sh $PWD" >$LOG_DIR/$target.fix-perms.log 2>$LOG_DIR/$target.fix-perms.err; then
26+ echo "[$target] Unable to fix permissions!"
27+ echo "[$target] stdout: $(pastebinit $LOG_DIR/$target.fix-perms.log)"
28+ echo "[$target] stderr: $(pastebinit $LOG_DIR/$target.fix-perms.err)"
29+ echo "[$target] Some files owned by root may have been left around, fix them manually with chown."
30+ fi
31+}
32
33 if [ "$1" = "" ]; then
34 # Releases we actually want to test should be included in target_list below.
35@@ -182,18 +197,7 @@
36 cat $TIMING | sed -e "s/^/[$target] (timing) /"
37 done
38
39- # Fix permissions.
40- # provision-testing-environment runs as root and creates a series of
41- # root-owned files in the branch directory. Later, tarmac will want
42- # to delete these files, so after provisioning we change everything
43- # under the branch directory to be owned by the unprivileged user,
44- # so stuff can be deleted correctly later.
45- if ! sudo $LXC_ATTACH --keep-env -n $target_container -- bash -c "chown -R --reference=test-in-lxc.sh $PWD" >$LOG_DIR/$target.fix-perms.log 2>$LOG_DIR/$target.fix-perms.err; then
46- echo "[$target] Unable to fix permissions!"
47- echo "[$target] stdout: $(pastebinit $LOG_DIR/$target.fix-perms.log)"
48- echo "[$target] stderr: $(pastebinit $LOG_DIR/$target.fix-perms.err)"
49- echo "[$target] Some files owned by root may have been left around, fix them manually with chown."
50- fi
51+ fix_permissions
52
53 echo "[$target] Destroying container"
54 # Stop the container first

Subscribers

People subscribed via source and target branches