ci: Test for clock skew
authorColin Walters <walters@verbum.org>
Sun, 17 May 2020 14:27:45 +0000 (14:27 +0000)
committerColin Walters <walters@verbum.org>
Mon, 18 May 2020 18:48:28 +0000 (18:48 +0000)
I saw `tests/test-admin-deploy.none.sh` fail in one CI run, and
I want to check if it was because of clock skew, so fail
fast if we detect that.

xref https://github.com/ostreedev/ostree/pull/2099#issuecomment-629805375

tests/admin-test.sh
tests/libtest.sh

index 03b455a3d90fefd7ae92f64396a93aafe288f06b..c716d0a52a575331cbd47ff0344d260029892ea3 100644 (file)
@@ -306,6 +306,8 @@ prev_rev=$(${CMD_PREFIX} ostree rev-parse --repo=sysroot/ostree/repo testos/buil
 assert_not_streq ${head_rev} ${prev_rev}
 # check that we can't "upgrade" to an older commit without --allow-downgrade
 if ${CMD_PREFIX} ostree admin upgrade --os=testos --override-commit=${prev_rev} 2> err.txt; then
+    ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo show "${prev_rev}"
+    ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo show "${head_rev}"
     fatal "downgraded without --allow-downgrade?"
 fi
 assert_file_has_content err.txt "Upgrade.*is chronologically older"
index 315c4df501e564e6cc1ac397219fb5e2cc36e108..ca457fa21bd7779bbdb7665df35e66a359f1c6be 100755 (executable)
@@ -488,6 +488,11 @@ EOF
     cd ${oldpwd} 
 }
 
+timestamp_of_commit()
+{
+  date --date="$(ostree --repo=$1 show $2 | grep -Ee '^Date: ' | sed -e 's,^Date: *,,')" '+%s'
+}
+
 os_repository_new_commit ()
 {
     boot_checksum_iteration=${1:-0}
@@ -529,6 +534,13 @@ os_repository_new_commit ()
     echo "content iteration ${content_iteration}" > usr/bin/content-iteration
 
     ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit  --add-metadata-string "version=${version}" -b $branch -s "Build"
+    if ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo rev-parse ${branch} 2>/dev/null; then
+        prevdate=$(timestamp_of_commit ${test_tmpdir}/testos-repo "${branch}"^)
+        newdate=$(timestamp_of_commit ${test_tmpdir}/testos-repo "${branch}")
+        if [ $((${prevdate} > ${newdate})) = 1 ]; then
+            fatal "clock skew detected writing commits: prev=${prevdate} new=${newdate}"
+        fi
+    fi
     cd ${test_tmpdir}
 }