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

Add e2e distribution tests #160

Merged
merged 30 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
94b8bd9
assume yes for yum installs
degray Dec 14, 2022
99958de
initial e2e script
degray Dec 14, 2022
6983b67
Initial gh action test
degray Dec 16, 2022
398a5dd
chdir before box update
degray Dec 16, 2022
4dddfa4
test nested virtualization
degray Dec 16, 2022
6d724d9
test cache
degray Dec 16, 2022
ddf7fa3
Test matrix
degray Dec 16, 2022
411747e
Fix matrix test
degray Dec 16, 2022
84cef3f
github action update
degray Dec 16, 2022
d6c1c7a
Test to ensure masking of token with fake token
degray Dec 16, 2022
3b13307
Test masking with fake token
degray Dec 16, 2022
01d8609
Switch role and test masking with fake key
degray Dec 16, 2022
a1c4765
Fix env name and test with fake token
degray Dec 16, 2022
a9ddb2b
Passing test_api_token
degray Dec 16, 2022
112cb5b
First full e2e test with fake token
degray Dec 16, 2022
6149074
sanitize dist and update cache key
degray Dec 16, 2022
112801e
pass dist to vagrant env
degray Dec 16, 2022
70f41c9
change cache key
degray Dec 16, 2022
412072a
Tail logs during 45s wait
degray Dec 16, 2022
f307e74
Trap exits
degray Dec 16, 2022
bf5e9dc
Trap exits
degray Dec 16, 2022
ec346d5
kill journalctl tail
degray Dec 16, 2022
c63d5e5
Remove background journalctl job / restore mem/cpu
degray Dec 16, 2022
b2f352a
sleep required
degray Dec 16, 2022
a9cb3f6
journalctl required only once
degray Dec 16, 2022
4d64470
Add schedule. 5pm UTC every day
degray Dec 16, 2022
19ee622
split steps
degray Dec 16, 2022
72cee71
consistent casing for vars
degray Dec 19, 2022
141a622
Test CI build
Dec 20, 2022
46612b4
Removed on push gh action trigger
Dec 20, 2022
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
76 changes: 76 additions & 0 deletions .github/workflows/dist-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on:
schedule:
- cron: '0 17 * * *' # every day at 5pm UTC

jobs:
setup:
runs-on: ubuntu-latest
outputs:
all-dists: ${{ steps.get-all-dists.outputs.dists }}
steps:
- uses: actions/checkout@v3
- id: get-all-dists
name: Get all distributions
run: |
cd dist
echo "dists=$(ls -ld */* | grep ^d | awk '{print $9}' | jq -cnMR '[inputs | select(length>0)]')" >> $GITHUB_OUTPUT
e2e:
# We use this runner because it is currently the only runner that supports nested virtualization.
# See https://github.com/actions/virtual-environments/issues/433 for more
# information
runs-on: macos-12
timeout-minutes: 30 # If something hangs, timeout the job in 30 so we aren't billed for 6h * distributions * 10 (mac-os minute multiplier)
needs:
- setup
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
dist: ${{ fromJSON(needs.setup.outputs.all-dists) }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::147803588724:role/github-action
aws-region: us-west-2

- name: Import e2e API TOKEN
run: |
e2e_api_token=$(aws secretsmanager get-secret-value --secret-id /prod/gh-actions/orchestrator-e2e-token --region us-west-2 | jq -r '.SecretString')
echo "::add-mask::${e2e_api_token}"
echo "TEST_API_TOKEN=${e2e_api_token}" >> $GITHUB_ENV

- name: Cache Vagrant box
# Caches that are not accessed within the last week will be evicted
# If any or all of the vagrant files change a lot in a short period of time
# the cache may hit its 10GB limit at which point it will just start trimming
# cached items in order of oldest to newest. Worst case it will re-download a vagrant box
# (see https://github.com/actions/cache#cache-limits)
uses: actions/cache@v3
with:
path: ~/.vagrant.d/boxes
key: ${{ runner.os }}-vagrant-${{ matrix.dist }}-${{ hashFiles('**/Vagrantfile') }}

- name: Provision e2e environment
run: |
cd ./dist/${{ matrix.dist }}
vagrant box update
vagrant up --provision

- name: Run e2e
env:
DIST: ${{ matrix.dist }}
run: |
cd ./dist/${{ matrix.dist }}
vagrant upload ../../e2e.sh
vagrant ssh -c "TEST_API_TOKEN=$TEST_API_TOKEN DIST=$DIST /bin/bash /home/vagrant/e2e.sh"

- name: Destroy e2e environment
run: |
cd ./dist/${{ matrix.dist }}
vagrant destroy -f
2 changes: 1 addition & 1 deletion dist/amazon-linux/2/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vagrant.configure("2") do |config|
# commercial use we need to sort out first.
config.vm.provider "libvirt" do |vm|
vm.memory = "8192"
vm.cpus = 8
vm.cpus = 2
vm.memorybacking :access, :mode => "shared"
end
config.vm.synced_folder "../../../", "/vagrant" #, type: "virtiofs"
Expand Down
54 changes: 54 additions & 0 deletions dist/e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# This script is primarily intended to be used with the Vagrant definitions in each dist folder
# A monitor should be setup in the account for which $TEST_API_TOKEN belongs to (testsignal is a good option)
#

# Oddly enough even after yum remove or apt remove the orchestrator is still running. Clean that up
StopAndDisableOrchestrator() {
sudo systemctl stop metrist-orchestrator
sudo systemctl disable metrist-orchestrator
sudo systemctl daemon-reload
}

RemoveOrchestrator(){
StopAndDisableOrchestrator

if type apt >/dev/null; then
sudo apt purge -y metrist-orchestrator
elif type yum >/dev/null; then
sudo yum remove -y metrist-orchestrator
fi
}

Main() {

# Sanitize DIST env var before using it for instance id - remove forward slashes, hyphens, and periods
DIST=${DIST//[\/\.\-]/}

curl https://dist.metrist.io/install.sh >/tmp/install.sh

cat <<EOF | bash /tmp/install.sh
$TEST_API_TOKEN
e2e_test_$DIST
EOF

sleep 45

LOGS=$(sudo journalctl --unit metrist-orchestrator --since "1m ago" --no-pager)
echo "$LOGS"
SUCCESS_COUNT=$(echo "$LOGS" | grep -c "All steps done, asking monitor to exit")

if [ $SUCCESS_COUNT -gt 0 ]; then
RemoveOrchestrator
echo "e2e successful"
exit 0
else
RemoveOrchestrator
echo "Error during e2e, can't find 'All steps done'"
exit 1
fi

}

Main
2 changes: 1 addition & 1 deletion dist/interactive/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ InstallYum() {
cd /tmp
latest=$($CURL https://dist.metrist.io/orchestrator/$OS/$VERSION.$ARCH.latest.txt)
$CURL "https://dist.metrist.io/orchestrator/$OS/$latest" >$latest
$SUDO yum localinstall ./$latest
$SUDO yum localinstall -y ./$latest
cat <<EOF | $SUDO tee -a /etc/default/metrist-orchestrator >/dev/null

# Added by installation script.
Expand Down
2 changes: 1 addition & 1 deletion dist/ubuntu/20.04/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vagrant.configure("2") do |config|
# commercial use we need to sort out first.
config.vm.provider "libvirt" do |vm|
vm.memory = "8192"
vm.cpus = 8
vm.cpus = 2
vm.memorybacking :access, :mode => "shared"
end
config.vm.synced_folder "../../../", "/vagrant" #, type: "virtiofs"
Expand Down
2 changes: 1 addition & 1 deletion dist/ubuntu/22.04/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vagrant.configure("2") do |config|
# commercial use we need to sort out first.
config.vm.provider "libvirt" do |vm|
vm.memory = "8192"
vm.cpus = 8
vm.cpus = 2
vm.memorybacking :access, :mode => "shared"
end
config.vm.synced_folder "../../../", "/vagrant" #, type: "virtiofs"
Expand Down