Browse Source

Allow to execute OpenStack integration tests only

using:

    tests/run-tests.sh tox -e py3 -- -m openstack_integration tests/

Tested with:

    $ time PYTEST_ADDOPTS='-m "not openstack_integration" --collect-only' tests/run-tests.sh
    [...]
    collected 100 items / 23 deselected / 77 selected
    [...]
    py3: commands succeeded
    flake8: commands succeeded
    docs: commands succeeded
    congratulations :)

    real    1m33.293s
    user    0m0.967s
    sys 0m0.384s
keep-around/2cc48f672e4c79cf237811813e56b2119797ce1c
Pierre-Louis Bonicoli 5 months ago
parent
commit
2cc48f672e
No known key found for this signature in database GPG Key ID: 6914C4A5EDAA6DD
  1. 2
      .gitlab-ci.yml
  2. 2
      docs/community/contribute.rst
  3. 3
      tests/enough/common/conftest.py
  4. 3
      tests/enough/common/test_common_service.py
  5. 4
      tests/enough/common/test_common_ssh.py
  6. 33
      tests/enough/common/test_init.py
  7. 30
      tests/enough/common/test_openstack.py
  8. 7
      tests/run-tests.sh
  9. 1
      tox.ini

2
.gitlab-ci.yml

@ -1,3 +1,3 @@
---
jobs:
script: SKIP_OPENSTACK_INTEGRATION_TESTS=true tests/run-tests.sh
script: tests/run-tests.sh

2
docs/community/contribute.rst

@ -64,7 +64,7 @@ Running tests that do not require OpenStack
There is no need to have OpenStack credentials to run these tests.
* ``SKIP_OPENSTACK_INTEGRATION_TESTS=true tests/run-tests.sh``
* ``PYTEST_ADDOPTS='-m "not openstack_integration"' tests/run-tests.sh``
Running tests that require OpenStack

3
tests/enough/common/conftest.py

@ -0,0 +1,3 @@
def pytest_configure(config):
config.addinivalue_line("markers", "openstack_integration: mark tests "
"which require OpenStack credentials")

3
tests/enough/common/test_common_service.py

@ -8,8 +8,7 @@ from enough.common import openstack
from enough.common import service
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_openstack_create_or_update(tmpdir, requests_mock):
try:
shutil.copy('infrastructure_key', f'{tmpdir}/infrastructure_key')

4
tests/enough/common/test_common_ssh.py

@ -1,4 +1,3 @@
import os
import pytest
from enough import settings
@ -6,8 +5,7 @@ from enough.common.openstack import Stack
from enough.common.ssh import SSH
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_ssh(openstack_name):
d = {
'name': openstack_name,

33
tests/enough/common/test_init.py

@ -10,8 +10,7 @@ from enough.common import Enough
from enough.common.openstack import OpenStackBase, OpenStack
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_clone_and_destroy(tmpdir):
test_clouds = 'inventory/group_vars/all/clouds.yml'
@ -101,8 +100,7 @@ def create_and_clone_server_and_volume(tmpdir):
return (original, clone)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_clone_create_service(tmpdir):
try:
(original, clone) = create_and_clone_server_and_volume(tmpdir)
@ -117,8 +115,7 @@ def test_clone_create_service(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_create_copy_host(tmpdir):
try:
enough = create_enough(tmpdir, 'copy')
@ -137,8 +134,7 @@ def test_create_copy_host(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_create_volume_from_snapshot(tmpdir):
try:
e = create_enough(tmpdir, 'backup')
@ -159,8 +155,7 @@ def test_create_volume_from_snapshot(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_clone_volume_from_snapshot(tmpdir):
try:
original = create_enough(tmpdir, 'backup')
@ -201,8 +196,7 @@ def test_clone_volume_from_snapshot(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_create_service_matching_snapshot(tmpdir):
try:
enough = create_enough(tmpdir, 'backup')
@ -216,8 +210,7 @@ def test_create_service_matching_snapshot(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_restore_remote(tmpdir):
try:
original = create_enough(tmpdir, 'backup')
@ -246,8 +239,7 @@ def test_restore_remote(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_restore_local(tmpdir):
try:
e = create_enough(tmpdir, 'backup')
@ -276,8 +268,7 @@ def test_restore_local(tmpdir):
o.destroy_everything(None)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_create_missings(tmpdir):
try:
enough = create_enough(tmpdir, 'create-missings')
@ -324,8 +315,7 @@ def test_host_from_snapshot(tmpdir):
assert e.host_from_snapshot(snapshot) == host
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_volume_resize(tmpdir):
try:
enough = create_enough(tmpdir, 'resize')
@ -346,8 +336,7 @@ def test_volume_resize(tmpdir):
#
# Host
#
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_host_create_or_update(tmpdir, openstack_name):
try:
enough = create_enough(tmpdir, 'host')

30
tests/enough/common/test_openstack.py

@ -15,8 +15,7 @@ from enough.common.openstack import Stack, Heat, OpenStack
#
# Stack
#
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_stack_create_or_update(openstack_name):
name = openstack_name
network = openstack_name
@ -113,8 +112,7 @@ def test_server_ip_in_network_none(mocker):
assert o.server_ip_in_network('server', 'network') is None
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_network(openstack_name):
o = OpenStack(settings.CONFIG_DIR)
o.network_and_subnet_create(openstack_name, '10.11.12.0/24')
@ -127,8 +125,7 @@ def test_network(openstack_name):
assert r.strip() == f"['{dns_ip}']"
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_backup_create_with_name(openstack_name, caplog):
o = OpenStack(settings.CONFIG_DIR)
o.o.volume.create('--size=1', openstack_name)
@ -140,8 +137,7 @@ def test_backup_create_with_name(openstack_name, caplog):
assert o.backup_prune(0) == 0
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_volume_prune(openstack_name, caplog):
o = OpenStack(settings.CONFIG_DIR)
@ -172,8 +168,7 @@ def test_volume_prune(openstack_name, caplog):
'recent': [recent_volume]}
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_backup_create_no_names(openstack_name, caplog):
o = OpenStack(settings.CONFIG_DIR)
o.o.volume.create('--size=1', openstack_name)
@ -182,8 +177,7 @@ def test_backup_create_no_names(openstack_name, caplog):
assert available_snapshot in caplog.text
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_openstack_replace_volume(openstack_name):
d = {
'name': openstack_name,
@ -224,8 +218,7 @@ def test_openstack_replace_volume(openstack_name):
'-f=value', '-c=Name', '--name', openstack_name).strip() == openstack_name
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_openstack_volume_resize_ok(openstack_name):
size = 1
d = {
@ -263,8 +256,7 @@ def test_openstack_volume_resize_ok(openstack_name):
o.volume_resize(openstack_name, openstack_name, 1)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_openstack_volume_resize_no_volume(openstack_name):
d = {
'name': openstack_name,
@ -281,8 +273,7 @@ def test_openstack_volume_resize_no_volume(openstack_name):
o.volume_resize(openstack_name, openstack_name, 1)
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_openstack_security_group(openstack_name):
o = OpenStack(settings.CONFIG_DIR)
o.o.security.group.create(openstack_name)
@ -290,8 +281,7 @@ def test_openstack_security_group(openstack_name):
assert o.delete_security_group(openstack_name) is False
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
@pytest.mark.openstack_integration
def test_destroy_volumes_with_same_name():
prefix = 'enough_test_' + str(int(time.time()))
volume_name = f'{prefix}-test-destroy-volume'

7
tests/run-tests.sh

@ -118,12 +118,9 @@ function run_tests() {
prepare_repository
find $d \( -name '*.pyc' -o -name '*.pyo' -o -name __pycache__ \) -delete
skip=""
if test "$SKIP_OPENSTACK_INTEGRATION_TESTS" ; then
skip+="-e SKIP_OPENSTACK_INTEGRATION_TESTS=true "
fi
if test "$GITLAB_CI" ; then
args="--workdir /opt"
: ${PYTEST_ADDOPTS=-m \"not openstack_integration\"}
else
args="--volume ${d}:${d} --workdir ${d} --volume $HOME/.enough:$HOME/.enough --volume $HOME/.ansible:$HOME/.ansible -e HOME=$HOME"
# handle git worktree
@ -133,7 +130,7 @@ function run_tests() {
args="$args --volume ${git_common_dir}:${git_common_dir}"
fi
fi
docker run --rm --device=/dev/net/tun --name $name --user "${USER:-root}" -e ENOUGH_API_TOKEN=$ENOUGH_API_TOKEN $skip --cap-add=NET_ADMIN $args --volume /var/run/docker.sock:/var/run/docker.sock $name "${@:-tox}"
docker run --rm --device=/dev/net/tun --name $name --user "${USER:-root}" -e PYTEST_ADDOPTS="${PYTEST_ADDOPTS-}" -e ENOUGH_API_TOKEN=$ENOUGH_API_TOKEN --cap-add=NET_ADMIN $args --volume /var/run/docker.sock:/var/run/docker.sock $name "${@:-tox}"
}
function main() {

1
tox.ini

@ -6,7 +6,6 @@ setenv =
VIRTUAL_ENV={envdir}
DJANGO_SETTINGS_MODULE=enough.settings
passenv =
SKIP_OPENSTACK_INTEGRATION_TESTS
SKIP_NETWORK_OPENSTACK_INTEGRATION_TESTS
PYTEST_ADDOPTS
HOME

Loading…
Cancel
Save