Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run-local.sh: Various cleanups, prepare for job-runner #589

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Check which containers changed
id: containers_changed
run: |
tasks=$(git diff --name-only origin/main..HEAD -- tasks/ | grep -Ev 'run-local.sh|openssl.cnf|README|mock-github|.yaml' || true)
tasks=$(git diff --name-only origin/main..HEAD -- tasks/ | grep -Ev 'run-local.sh|openssl.cnf|README|mock-|.yaml' || true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to beg for a separate tasks/container/ directory...

# print for debugging
echo "tasks: $tasks"
[ -z "$tasks" ] || echo "tasks=true" >> "$GITHUB_OUTPUT"
Expand Down
8 changes: 8 additions & 0 deletions tasks/mock-git-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# used in integration test where we can't/don't want to push back to origin
set -eu
if [ "$1" = push ]; then
echo "$@" >> "${TEST_ATTACHMENTS}/git-push.log"
exit 0
fi
exec /usr/bin/git "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not crazy about this, but it's probably the best option for the time being...

In a certain sense, this is mocking in its purest form...

44 changes: 21 additions & 23 deletions tasks/run-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ S3_URL_POD=https://localhost.localdomain:9000
S3_URL_HOST=https://localhost.localdomain:$S3_PORT
# AMQP address from inside the cockpituous pod
AMQP_POD=localhost:5671
# mock GitHub API running in tasks pod
GHAPI_URL_POD="http://127.0.0.7:8443"

# CLI option defaults/values
PR=
Expand Down Expand Up @@ -257,8 +259,8 @@ test_mock_pr() {
# start mock GH server
PYTHONPATH=. ./mock-github cockpit-project/bots \$SHA &
GH_MOCK_PID=\$!
export GITHUB_API=http://127.0.0.7:8443
until curl --silent \$GITHUB_API; do sleep 0.1; done
export GITHUB_API=$GHAPI_URL_POD
until curl --silent --fail \$GITHUB_API/repos/cockpit-project/bots; do sleep 0.1; done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost commented here that hardcoding this was bad, for example, but that's obviously non-sense in this case.

Sometimes I think it would be better to have named this repository something different. I always get confused about things on the real GitHub (which should allow for generalization based on which fork is running the tests) vs. our mocked-up stuff.

This is officially a drive-by.


# simulate GitHub webhook event, put that into the webhook queue
PYTHONPATH=. ./mock-github --print-pr-event cockpit-project/bots \$SHA | \
Expand Down Expand Up @@ -344,26 +346,18 @@ test_pr() {

test_mock_image_refresh() {
podman cp "$MYDIR/mock-github" cockpituous-tasks:/work/bots/mock-github

# the last step of an image refresh is to push the branch back to origin; we can't nor
# want to do that here, so divert "git push" to a log file and check that
cat <<EOF | podman exec -i -u root cockpituous-tasks sh -euxc "cat > /usr/local/bin/git; chmod +x /usr/local/bin/git"
#!/bin/sh
if [ "\$1" = push ]; then
echo "\$@" >> /work/git-push.log
exit 0
fi
exec /usr/bin/git "\$@"
EOF
podman cp "$MYDIR/mock-git-push" cockpituous-tasks:/usr/local/bin/git

podman exec -i cockpituous-tasks sh -euxc "
cd bots
# start mock GH server; use a mock SHA, only used for posting statuses
SHA=123abc
# test mock PR against our checkout, so that cloning will work
SHA=\$(git rev-parse HEAD)

# start mock GH server
PYTHONPATH=. ./mock-github cockpit-project/bots \$SHA &
GH_MOCK_PID=\$!
export GITHUB_API=http://127.0.0.7:8443
until curl --silent \$GITHUB_API; do sleep 0.1; done
export GITHUB_API=$GHAPI_URL_POD
until curl --silent --fail \$GITHUB_API/repos/cockpit-project/bots; do sleep 0.1; done

# simulate GitHub webhook event, put that into the webhook queue
PYTHONPATH=. ./mock-github --print-image-refresh-event cockpit-project/bots \$SHA | \
Expand Down Expand Up @@ -395,20 +389,24 @@ EOF
assert_in 'Success.' "$LOG"

# branch was (mock) pushed
PUSH_LOG="$(podman exec -i cockpituous-tasks cat /work/git-push.log)"
PUSH_LOG_MATCH="$($CURL $LOGS_URL| grep -o "image-refresh-foonux-[[:alnum:]-]*/git-push.log<")"
PUSH_LOG="$($CURL "${LOGS_URL}${PUSH_LOG_MATCH%<}")"
assert_in 'push origin +HEAD:refs/heads/image-refresh-foonux-' "$PUSH_LOG"
podman exec -i cockpituous-tasks rm /work/git-push.log
podman exec -i -u root cockpituous-tasks rm /usr/local/bin/git

podman exec -i cockpituous-tasks sh -euxc '
# image is on the S3 server
cd bots
name=$(python3 -m lib.s3 ls '$S3_URL_POD'/images/ | grep -o "foonux.*qcow2")

# download image (it was not pushed to git, so need to use --state)
rm -f /cache/images/foonux*
./image-download --store $COCKPIT_IMAGE_UPLOAD_STORE --state "$name"

# validate image contents
qemu-img convert /cache/images/foonux-*.qcow2 /tmp/foonux.raw
grep "^fakeimage" /tmp/foonux.raw
rm /tmp/foonux.raw

# image is on the S3 server
cd bots
python3 -m lib.s3 ls '$S3_URL_POD'/images/ | grep "foonux.*qcow"
'
}

Expand Down