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 workflow to run e2e tests from lxd-ui #14035

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
225 changes: 225 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,231 @@ jobs:
name: lxd-clients-${{ runner.os }}
path: bin/

ui:
Copy link
Member

Choose a reason for hiding this comment

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

please can you move this as part of the system-tests: workflow and make it a step after name: "Run system tests (${{ matrix.suite }}, ${{ matrix.backend }})" and before name: Upload coverage data

Then we can re-use the dependency install deps, and by ensuring LXD is run with the code coverage env var, we can collect coverage data from the UI tests too.

Copy link
Contributor Author

@edlerd edlerd Nov 14, 2024

Choose a reason for hiding this comment

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

This will slow down LXD test runtime. With current changes from this PR, the UI tests run in parallel to the system tests, which will not affect your total runtime. Because system tests take longer than the UI tests. I think a better option is to also record coverage in the UI step and download both coverage reports in the TICS step.

name: UI e2e tests
runs-on: ubuntu-latest
needs: [code-tests, documentation]
if: "!startsWith(github.ref, 'refs/heads/stable-')"
env:
LXD_DIR: "/var/lib/lxd"
LXD_OIDC_CLIENT_ID: "gxj297yfAjmklILK5WqPWDSbtVBAeSQm"
Copy link
Member

Choose a reason for hiding this comment

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

Is this a secret key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as the password over there

LXD_OIDC_ISSUER: "https://dev-xjrvvfikbsv4jxn7.us.auth0.com/"
Copy link
Member

Choose a reason for hiding this comment

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

Can we use our mini oidc service that we use for testing oidc in LXD? cc @markylaing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good hint, I'll check how to adopt it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the mini OIDC implementation is not trivial. It is only implementing the device flow, which is incompatible with the web flow.

Copy link
Member

Choose a reason for hiding this comment

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

OK so we can stick with the external service, but all identifiers should be GH secrets.

LXD_OIDC_AUDIENCE: "https://dev-xjrvvfikbsv4jxn7.us.auth0.com/api/v2/"
LXD_OIDC_USER: "[email protected]"
LXD_OIDC_PASSWORD: "lxd-ui-e2e-password"
Copy link
Member

Choose a reason for hiding this comment

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

This shouldnt be hardcoded into the test file, as it references an external service, and thus is a real password.

We should now change this password to something else and then securely transfer it to me so we can set it up as a GH secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a dedicated free account, specially created for e2e tests. It is expected to be public. I don't see a reason for this to be kept secret.

Though once we start using the local OIDC service, we can remove this.

Copy link
Member

Choose a reason for hiding this comment

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

Hrm, yeah, but we shouldnt be making the credentials public

LXD_OIDC_GROUPS_CLAIM: "lxd-idp-groups"
steps:
- name: Checkout code
uses: actions/checkout@v4
edlerd marked this conversation as resolved.
Show resolved Hide resolved

- name: Tune disk performance
uses: ./.github/actions/tune-disk-performance

- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version-file: 'go.mod'

- name: Install dependencies
run: |
set -eux
sudo add-apt-repository ppa:ubuntu-lxc/daily -y --no-update
sudo add-apt-repository ppa:dqlite/dev -y --no-update
sudo apt-get update

sudo systemctl mask lxc.service lxc-net.service

sudo apt-get install --no-install-recommends -y \
curl \
git \
libacl1-dev \
libcap-dev \
libdbus-1-dev \
libdqlite-dev \
liblxc-dev \
libseccomp-dev \
libselinux-dev \
libsqlite3-dev \
libtool \
libudev-dev \
make \
pkg-config\
acl \
attr \
bind9-dnsutils \
btrfs-progs \
busybox-static \
dnsmasq-base \
easy-rsa \
gettext \
jq \
lxc-utils \
lvm2 \
nftables \
quota \
rsync \
s3cmd \
socat \
sqlite3 \
squashfs-tools \
tar \
tcl \
thin-provisioning-tools \
uuid-runtime \
xfsprogs \
xz-utils \
zfsutils-linux

mkdir -p "$(go env GOPATH)/bin"
curl -sSfL https://dl.min.io/server/minio/release/linux-amd64/minio --output "$(go env GOPATH)/bin/minio"
chmod +x "$(go env GOPATH)/bin/minio"

# Also grab the latest minio client to maintain compatibility with the server.
curl -sSfL https://dl.min.io/client/mc/release/linux-amd64/mc --output "$(go env GOPATH)/bin/mc"
chmod +x "$(go env GOPATH)/bin/mc"

- name: Download system test dependencies
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin

- name: Set exec perms on LXD binaries
run: |
set -eux
ls -lR /home/runner/go/bin/
chmod uog+x /home/runner/go/bin/*

- name: Download docs (for the objects.inv.txt file to be available for the e2e tests)
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: documentation
merge-multiple: true
path: doc/_build

- name: Run LXD daemon
run: |
set -eux
echo "root:1000000:1000000000" | sudo tee /etc/subuid /etc/subgid
export CGO_CFLAGS="-I/home/runner/work/lxd/lxd-test/vendor/dqlite/include/"
export CGO_LDFLAGS="-L/home/runner/work/lxd/lxd-test/vendor/dqlite/.libs/"
export LD_LIBRARY_PATH="/home/runner/work/lxd/lxd-test/vendor/dqlite/.libs/"
export LXD_DOCUMENTATION="/home/runner/work/lxd/lxd/doc/_build/"
export PATH="/home/runner/go/bin:$PATH"
sudo rm -rf /var/lib/lxd
sudo -E PATH=${PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} $(go env GOPATH)/bin/lxd --group sudo &

- name: Setup LXD
shell: bash
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH"
sudo -E LXD_DIR=/var/lib/lxd lxc storage create default zfs
sudo -E LXD_DIR=/var/lib/lxd lxc profile device add default root disk path=/ pool=default
sudo -E LXD_DIR=/var/lib/lxd lxc network create local-network
sudo -E LXD_DIR=/var/lib/lxd lxc profile device add default eth0 nic network=local-network
sudo -E LXD_DIR=/var/lib/lxd lxc config set core.https_address "[::]:8443"
sudo -E LXD_DIR=/var/lib/lxd lxc config set cluster.https_address "127.0.0.1"
sudo -E LXD_DIR=/var/lib/lxd lxc cluster enable local
sudo -E LXD_DIR=/var/lib/lxd lxc config set user.show_permissions=true

- name: Checkout LXD-UI
uses: actions/checkout@v4
with:
repository: 'canonical/lxd-ui'
ref: main
path: lxd-ui

- name: Install Dotrun
run: sudo pip3 install dotrun

- name: Restore cached keys
edlerd marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/cache/restore@v3
with:
path: lxd-ui/keys
key: keys-folder

- name: Install LXD-UI dependencies
run: |
set -eux
sudo chmod 0777 ./lxd-ui
cd lxd-ui
dotrun install

- name: Run LXD-UI
env:
ENVIRONMENT: devel
PORT: 8407
LXD_UI_BACKEND_IP: 172.17.0.1
Copy link
Member

Choose a reason for hiding this comment

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

Could that be one of the loopback IPs instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ui is is running in a container, so we need to use this to reach out from the container that is running the ui. Loopback would be inside the container and not reach lxd which runs on the host.

run: |
set -eux
cd lxd-ui
dotrun &
curl --head --fail --retry-delay 2 --retry 100 --retry-connrefused --insecure https://localhost:8407
edlerd marked this conversation as resolved.
Show resolved Hide resolved

- name: Set keys permissions
run: |
set -eux
sudo chmod -R 0666 lxd-ui/keys
sudo chmod 0777 lxd-ui/keys

- name: Save keys
uses: actions/cache/save@v3
with:
path: lxd-ui/keys
key: keys-folder

- name: Allow LXD-UI keys
shell: bash
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH"
sudo -E LXD_DIR=/var/lib/lxd lxc config trust add lxd-ui/keys/lxd-ui.crt

- name: Create a custom image
shell: bash
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH"
sudo -E LXD_DIR=/var/lib/lxd lxc launch ubuntu-minimal:22.04 my-instance
Copy link
Member

Choose a reason for hiding this comment

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

No need to launch, init will do. Also, we tend to use minimal-daily elsewhere:

Suggested change
sudo -E LXD_DIR=/var/lib/lxd lxc launch ubuntu-minimal:22.04 my-instance
sudo -E LXD_DIR=/var/lib/lxd lxc init ubuntu-minimal-daily:22.04 my-instance

But if you don't actually need a full fledged instance, we have a simple busybox testimage. See test/includes/setup.sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a workaround to generate an image from an instance, before this was not possible in the UI. I think by now we can generate the image directly in our e2e test. So we might be able to get rid of this preparation step completely. I need to double-check if we can evolve our test, but I am optimistic it will work. Will keep this open for now.

sudo -E LXD_DIR=/var/lib/lxd lxc publish my-instance --alias my-custom-image --force
sudo -E LXD_DIR=/var/lib/lxd lxc delete my-instance --force

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Playwright Browsers
run: |
set -eux
cd lxd-ui
npx playwright install --with-deps chromium

- name: Setup for LXD-UI tests
shell: bash
run: |
set -eux
sudo -E LXD_DIR=/var/lib/lxd PATH=/home/runner/go/bin:$PATH ./lxd-ui/tests/scripts/setup_test

- name: Run Playwright tests
run: |
set -eux
cd lxd-ui
sudo chown $USER -R /home/runner/.config
sudo chown $USER /var/lib/lxd/unix.socket
CI=true DISABLE_VM_TESTS=true LXD_DIR=/var/lib/lxd PATH=/home/runner/go/bin:$PATH npx playwright test --project chromium:lxd-latest-edge
#npx playwright test --project chromium:lxd-5.21-edge
#npx playwright test --project lxd-5.0-edge

- name: Upload lxd-ui test artifacts
edlerd marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: always()
with:
name: lxd-ui-test-report
path: lxd-ui/blob-report
retention-days: 14

documentation:
name: Documentation
runs-on: ubuntu-latest
Expand Down