forked from canonical/operator-libs-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tox.ini
143 lines (129 loc) · 4.63 KB
/
tox.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, unit
[vars]
src_dir = {toxinidir}/src/
tst_dir = {toxinidir}/tests/
itst_dir = {toxinidir}/tests/integration
lib_dir = {toxinidir}/lib/charms/operator_libs_linux/
all_dir = {[vars]src_dir} {[vars]tst_dir} {[vars]lib_dir}
lxd_ubuntu = ops-libs-test-ubuntu
lxd_centos = ops-libs-test-centos
wait = 5
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_dir}
PYTHONBREAKPOINT=pdb.set_trace
PY_COLORS=1
passenv =
PYTHONPATH
CHARM_BUILD_DIR
MODEL_SETTINGS
[testenv:fmt]
description = Apply coding style standards to code
deps =
black
ruff
commands =
ruff check --fix {[vars]all_dir}
black {[vars]all_dir}
[testenv:lint]
description = Check code against coding style standards
deps =
black
ruff
codespell
commands =
codespell {toxinidir}
ruff check {[vars]all_dir}
black --check --diff {[vars]all_dir}
[testenv:unit]
description = Run unit tests
deps =
pytest
coverage[toml]
-r{toxinidir}/requirements.txt
pyfakefs==5.5.0
dbus-fast==1.90.2
commands =
coverage run --source={[vars]lib_dir} \
-m pytest \
--ignore={[vars]tst_dir}integration \
--tb native \
-v \
{posargs}
coverage report
[testenv:integration]
description = Build a LXD container for integration tests then run the tests
allowlist_externals =
lxc
bash
commands =
# Create a LXD containers for Ubuntu and CentOS with necessary packages installed.
# Note (rgildein): running integration tests on a VM because the grub library could not be used on containers
bash -c 'lxc launch --vm -qe ubuntu:focal {[vars]lxd_ubuntu} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
bash -c 'lxc launch --vm -qe images:centos/9-Stream/cloud {[vars]lxd_centos} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
bash -c 'while !(lxc exec {[vars]lxd_ubuntu} -- bash -c "echo ready"); do sleep {[vars]wait}; done'
bash -c 'while !(lxc exec {[vars]lxd_centos} -- bash -c "echo ready"); do sleep {[vars]wait}; done'
# Wait for the cloud-init process to finish in both Ubuntu and CentOS image
lxc exec {[vars]lxd_ubuntu} -- bash -c "cloud-init status -w >/dev/null 2>&1"
lxc exec {[vars]lxd_centos} -- bash -c "cloud-init status -w >/dev/null 2>&1"
# Make sure the latest snapd is available
lxc exec {[vars]lxd_ubuntu} -- bash -c "snap refresh snapd"
lxc exec {[vars]lxd_ubuntu} -- bash -c "systemctl restart snapd"
# Copy all the files needed for integration testing into instances.
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_centos}/{[vars]lxd_centos}/
# Run the tests.
lxc exec {[vars]lxd_ubuntu} -- tox -c /{[vars]lxd_ubuntu}/tox.ini -e integration-ubuntu {posargs}
lxc exec {[vars]lxd_centos} -- tox -c /{[vars]lxd_centos}/tox.ini -e integration-centos {posargs}
commands_post =
-lxc stop {[vars]lxd_ubuntu} {[vars]lxd_centos}
[testenv:integration-ubuntu]
description = Run integration tests for Ubuntu instance.
deps =
pytest
commands =
pytest --ignore={[vars]tst_dir}unit \
--ignore={[vars]tst_dir}integration/test_dnf.py \
--ignore={[vars]tst_dir}integration/juju_systemd_notices \
--log-cli-level=INFO \
--tb native \
-v \
-s \
{posargs}
[testenv:integration-centos]
description = Run integration tests for CentOS instance.
deps =
pytest
commands =
pytest --log-cli-level=INFO \
--tb native \
-v \
-s \
{[vars]tst_dir}integration/test_dnf.py \
{posargs}
[testenv:integration-juju-systemd-notices]
description = Run juju systemd notices integration tests.
deps =
pytest
pytest-operator
pytest-order
juju
-r {toxinidir}/requirements.txt
commands =
pytest -v \
-s \
--tb native \
--log-cli-level=INFO \
{[vars]tst_dir}integration/juju_systemd_notices
{posargs}