From f5723961ef7fc9c71222e8b45e0de39e7f15e90e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 19 Feb 2014 14:34:18 +0000 Subject: Update 'baserock-system-config-sync' tests to check permissions --- tests/run_tests.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index ea92924..36dff01 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -12,6 +12,34 @@ then exit 1 fi +compare_dirs() { + + # Temporary files used to compare the file permissions + file1=$(mktemp) + file2=$(mktemp) + + set +e + ( + set -e + # Getting the file permissions + (cd "$1" && busybox find * -exec busybox stat -c '%n %a' {} + | sort) > "$file1" + (cd "$2" && busybox find * -exec busybox stat -c '%n %a' {} + | sort) > "$file2" + + # Compare file contents + diff -r "$1" "$2" + + # Compare permissions + diff "$file1" "$file2" + ) + local ret="$?" + + # Clean temporary files + rm "$file1" + rm "$file2" + + return $ret +} + echo "Starting baserock-system-config-sync tests" merge_pass_folder="bscs-merge.pass" merge_fail_folder="bscs-merge.fail" @@ -33,7 +61,7 @@ for folder in "$merge_pass_folder/"*.in; do if [ "$exit_code" -ne 0 ]; then echo ": FAILED (exit code "$exit_code")" 1>&2 exit 1 - elif ! diff -r "$TMPDIR/"*/ "$out_folder/" &>> "$bscs_log"; then + elif ! compare_dirs "$TMPDIR/"*/ "$out_folder/" &>> "$bscs_log"; then echo ": FAILED (different diff)" 1>&2 exit 1 else @@ -73,7 +101,7 @@ exit_code="$?" if [ "$exit_code" -ne 0 ]; then echo ": FAILED (exit code "$exit_code")" 1>&2 exit 1 -elif ! diff -r "$TMPDIR/"*/ "$out_folder/" &>> "$bscs_log"; then +elif ! compare_dirs "$TMPDIR/"*/ "$out_folder/" &>> "$bscs_log"; then echo ": FAILED (different diff)" 1>&2a exit 1 else -- cgit v1.2.1 From d71ff3eaa4a55b32659e165efe4b78149ef240cb Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 19 Feb 2014 13:03:39 +0000 Subject: Modify the way to use 'patch' in 'baserock-system-config-sync'. baserock-sytem-config-sync: Changes here are caused by a bug found in GNU patch managing the permissions of the files when using the patch command like: patch -t -o To reproduce the bug: echo foo > file1 echo bar > file2 diff -u file1 file2 | patch 1 -t -o file3 ls -l You can check that the permissions of 'file3' are different than the permissions of 'file1' or 'file2'. To avoid the bug, this patch changes the way we are using patch, using it as following: patch -t Since the output file is not specified, the output file will be the file in which we want to apply the patch. And due we cannot specify the output file, we are copying the file to the destination directory, and then applying the patch there. As a consequence of changing the way of using patch, now 'patch' generates an extra file when patching fails. This file is added in the test suite also in this commit. --- baserock-system-config-sync/baserock-system-config-sync | 8 ++++++-- .../upgrades.out/systems/version2/run/etc/file7.orig | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync index cb5984d..a093b15 100755 --- a/baserock-system-config-sync/baserock-system-config-sync +++ b/baserock-system-config-sync/baserock-system-config-sync @@ -151,13 +151,17 @@ merge_regular_file() { cp -a "$vu" "$vt" ;; 'none exists exists') - if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$v2" -t -o "$vt"); then + cp -a "$v2" "$vt" + if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$vt" -t); then cp -a "$v2" "$vt" # merge failed, use v2 + # 'patch' creates a file '.rej' with the diff that did not apply fi ;; 'exists exists exists') - if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$v2" -t -o "$vt"); then + cp -a "$v2" "$vt" + if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$vt" -t); then cp -a "$v2" "$vt" # merge failed, use v2 + # 'patch' creates a file '.rej' with the diff that did not apply fi ;; *) diff --git a/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig b/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig new file mode 100644 index 0000000..93c46eb --- /dev/null +++ b/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig @@ -0,0 +1,2 @@ +whereami=v1,vu,v2 +version=v2 -- cgit v1.2.1