Skip to content

Commit

Permalink
Merge pull request #555 from simondeziel/integration
Browse files Browse the repository at this point in the history
github: Run integration tests
  • Loading branch information
tomponline committed Jul 14, 2023
2 parents 796f3f3 + a89d4cf commit 89617a6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
permissions:
pull-requests: read # for tim-actions/get-pr-commits to get list of commits from the PR
name: Signed-off-by (DCO)
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Get PR Commits
id: 'get-pr-commits'
Expand All @@ -27,7 +27,7 @@ jobs:
permissions:
contents: none
name: Branch target
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Check branch target
env:
Expand Down
75 changes: 37 additions & 38 deletions .github/workflows/ci.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
name: CI tests

name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
- push
- pull_request

jobs:
lint-python:
runs-on: ubuntu-22.04
steps:
- name: Repository checkout
uses: actions/checkout@v3
permissions:
contents: read

- name: Install dependencies
run: |
pip install --upgrade pip tox
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

- name: Lint Python files
run: |
tox -e lint
lint-shell:
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Repository checkout
Expand All @@ -32,30 +21,25 @@ jobs:
- name: Lint shell files
uses: ludeeus/action-shellcheck@master

check:
runs-on: ubuntu-20.04
steps:
- name: Repository checkout
uses: actions/checkout@v3

- name: Install dependencies
run: |
pip install --upgrade pip tox
- name: Lint Python files
run: |
tox -e lint
- name: Typecheck Python files
run: |
tox -e check
test:
tests:
name: Tests
strategy:
matrix:
python-version: ["3.8", "3.11"]
os: [ubuntu-latest]
include:
- os: ubuntu-20.04
python-version: "3.6"
python-version: ["3.8", "3.10", "3.11"]

runs-on: ${{ matrix.os }}
runs-on: ubuntu-22.04
steps:
- name: Repository checkout
uses: actions/checkout@v3
Expand All @@ -67,24 +51,39 @@ jobs:

- name: Install dependencies
run: |
set -x
sudo apt-get autopurge moby-containerd docker uidmap -y
sudo ip link delete docker0
sudo nft flush ruleset
sudo snap refresh lxd
sudo adduser "$USER" lxd
sudo lxd init --auto
pip install --upgrade pip tox codecov
- name: Test
- name: Coverage
run: |
tox -e coverage
codecov
- name: Integration
run: |
sudo -g lxd integration/run-integration-tests
publish:
runs-on: ubuntu-latest
name: Publish
runs-on: ubuntu-22.04
if: startsWith(github.event.ref, 'refs/tags')

permissions:
contents: write
steps:
- uses: actions/checkout@v3

- name: Create Release
uses: ncipollo/release-action@v1
if: startsWith(github.event.ref, 'refs/tags')
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: Release ${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ Integration testing requires a running LXD system. They can be tested locally
in LXD container with nesting support; ``tox -e integration-in-lxd``.

.. _Github: https://github.com/canonical/pylxd
.. _Tox: https://documentation.ubuntu.com/lxd/en/latest/clustering/
.. _Tox: https://tox.wiki/en/latest/
.. _Multipass: https://github.com/canonical/multipass
29 changes: 22 additions & 7 deletions integration/run-integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ sudo apt-get install -y --no-install-recommends \
python3-dev \
tox

# Fail if lxc command isn't available
if ! command -v lxc; then
echo "lxc command not available, aborting (hint: snap install lxd)" >&2
exit 1
fi

# Make sure a client.{crt,key} exist by trying to add a bogus remote
lxc remote add foo 127.0.0.1:1234 2>/dev/null || true

lxc config set core.trust_password password
lxc config set core.https_address "[::]"
lxc config set core.https_address 127.0.0.1

if ! lxc storage show default >/dev/null 2>&1; then
lxc storage create default dir
Expand All @@ -21,16 +30,22 @@ fi
if [ -e /var/snap/lxd/common/lxd/server.crt ]; then
mkdir -p ~/snap/lxd/common/config/servercerts
cp /var/snap/lxd/common/lxd/server.crt ~/snap/lxd/common/config/servercerts/127.0.0.1.crt

# Old snap
if [ -d ~/snap/lxd/current/.config/lxc ]; then
mkdir -p ~/snap/lxd/current/.config/lxc/servercerts
cp /var/snap/lxd/common/lxd/server.crt ~/snap/lxd/current/.config/lxc/servercerts/127.0.0.1.crt
fi
fi

# Save the list of trusted certs
OLD_TRUST_LIST="$(mktemp)"
lxc config trust list --format csv | awk -F, '{print $4}' | sort > "${OLD_TRUST_LIST}"

# finally run the integration tests
tox -e integration

# Remove any cert added to the trusted list by the integration tests
NEW_TRUST_LIST="$(mktemp)"
lxc config trust list --format csv | awk -F, '{print $4}' | sort > "${NEW_TRUST_LIST}"
for cert in $(comm -13 "${OLD_TRUST_LIST}" "${NEW_TRUST_LIST}"); do
lxc config trust remove "${cert}"
done
rm -f "${OLD_TRUST_LIST}" "${NEW_TRUST_LIST}"

lxc config unset core.trust_password || true
lxc config unset core.https_address || true
3 changes: 0 additions & 3 deletions pylxd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
requests_unixsocket.monkeypatch()

SNAP_ROOT = os.path.expanduser("~/snap/lxd/common/config/")
SNAP_OLD_ROOT = os.path.expanduser("~/snap/lxd/current/.config/lxc")
APT_ROOT = os.path.expanduser("~/.config/lxc/")
CERT_FILE_NAME = "client.crt"
KEY_FILE_NAME = "client.key"
# check that the cert file and key file exist at the appropriate path
if os.path.exists(os.path.join(SNAP_ROOT, CERT_FILE_NAME)): # pragma: no cover
CERTS_PATH = SNAP_ROOT # pragma: no cover
elif os.path.exists(os.path.join(SNAP_OLD_ROOT, CERT_FILE_NAME)): # pragma: no cover
CERTS_PATH = SNAP_OLD_ROOT # pragma: no cover
else: # pragma: no cover
CERTS_PATH = APT_ROOT # pragma: no cover

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifier =
Programming Language :: Python :: 3

[options]
python_requires = >= 3.6
python_requires = >= 3.8
packages = find:
install_requires =
cryptography >= 3.2
Expand Down

0 comments on commit 89617a6

Please sign in to comment.