From 11d59fda895d240ee798df60bab9c3eb50403738 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 27 May 2020 06:59:11 +0100 Subject: [PATCH] Test bootstrapped Salt and Python versions are the intended ones --- .kitchen.yml | 2 +- tests/conftest.py | 20 ++++++++++++++++++++ tests/integration/test_connection.py | 7 ------- tests/integration/test_installation.py | 24 ++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 8 deletions(-) delete mode 100644 tests/integration/test_connection.py create mode 100644 tests/integration/test_installation.py diff --git a/.kitchen.yml b/.kitchen.yml index 9aeec24..ecc3a6f 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -232,4 +232,4 @@ suites: verifier: name: shell remote_exec: false - command: pytest --cache-clear -v tests/integration/ + command: pytest --cache-clear -v -s -ra --log-cli-level=info tests/integration/ diff --git a/tests/conftest.py b/tests/conftest.py index 07c2ab9..36abec1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,10 @@ import os +import pprint import pytest import testinfra +import logging + +log = logging.getLogger(__name__) @pytest.fixture(scope='session') @@ -14,3 +18,19 @@ def host(): 'paramiko://{KITCHEN_USERNAME}@{KITCHEN_HOSTNAME}:{KITCHEN_PORT}'.format(**os.environ), ssh_identity_file=os.environ.get('KITCHEN_SSH_KEY')) return testinfra.get_host('docker://{KITCHEN_USERNAME}@{KITCHEN_CONTAINER_ID}'.format(**os.environ)) + + +@pytest.fixture(scope='session') +def target_python_version(): + target_python = os.environ["KITCHEN_SUITE"].split("-", 1)[0] + if target_python == "latest": + pytest.skip("Unable to get target python from {}".format(os.environ["KITCHEN_SUITE"])) + return int(target_python.replace("py", "")) + + +@pytest.fixture(scope='session') +def target_salt_version(): + target_salt = os.environ["KITCHEN_SUITE"].split("-", 2)[-1].replace("-", ".") + if target_salt in ("latest", "master"): + pytest.skip("Don't have a specific salt version to test against") + return target_salt diff --git a/tests/integration/test_connection.py b/tests/integration/test_connection.py deleted file mode 100644 index c32f88f..0000000 --- a/tests/integration/test_connection.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -import pytest - - -def test_ping(host): - with host.sudo(): - assert host.salt('test.ping', '--timeout=120') diff --git a/tests/integration/test_installation.py b/tests/integration/test_installation.py new file mode 100644 index 0000000..07112e0 --- /dev/null +++ b/tests/integration/test_installation.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +import json +import pytest +import logging +import pprint + +log = logging.getLogger(__name__) + + +def test_ping(host): + with host.sudo(): + assert host.salt('test.ping', '--timeout=120') + + +def test_target_python_version(host, target_python_version): + with host.sudo(): + ret = host.salt('grains.item', 'pythonversion', '--timeout=120') + assert ret["pythonversion"][0] == target_python_version + + +def test_target_salt_version(host, target_salt_version): + with host.sudo(): + ret = host.salt('grains.item', 'saltversion', '--timeout=120') + assert ret["saltversion"].startswith(target_salt_version)