From f14aa894d36463cf13fbfa404526a2a57d45fcd6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 17 May 2020 14:27:45 +0000 Subject: [PATCH] ci: Test for clock skew 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 | 2 ++ tests/libtest.sh | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/admin-test.sh b/tests/admin-test.sh index 03b455a3..c716d0a5 100644 --- a/tests/admin-test.sh +++ b/tests/admin-test.sh @@ -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" diff --git a/tests/libtest.sh b/tests/libtest.sh index 315c4df5..ca457fa2 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -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} }