From 0ae7dda223ad6110ee0cc512d4eb4695bb06726e Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Thu, 12 Apr 2018 18:33:32 +0300 Subject: [PATCH 1/2] sdk-tests: Update the test's images - We have a new image of el7.4 - fc25 is obsolete Signed-off-by: gbenhaim --- tests/functional-sdk/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional-sdk/conftest.py b/tests/functional-sdk/conftest.py index fb6b5fde..8316bdcf 100644 --- a/tests/functional-sdk/conftest.py +++ b/tests/functional-sdk/conftest.py @@ -10,8 +10,8 @@ { 'images': [ - 'el7.4-base', 'el6-base', 'fc25-base', 'fc26-base', - 'fc27-base', 'ubuntu16.04-base', 'debian8-base' + 'el7.4-base-1', 'el6-base', 'fc26-base', 'fc27-base', + 'ubuntu16.04-base', 'debian8-base' ] } # noqa: E123 } From cb3a4e722d44524f1e1ebde157329358966cc883 Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Thu, 12 Apr 2018 17:53:06 +0300 Subject: [PATCH 2/2] sdk-tests: Move Lago's fixtures to an external module This way Lago's fixtures can be shared across different test modules. Signed-off-by: gbenhaim --- tests/functional-sdk/conftest.py | 10 ++-- tests/functional-sdk/lago_fixtures.py | 73 +++++++++++++++++++++++++ tests/functional-sdk/test_sdk_sanity.py | 63 --------------------- 3 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 tests/functional-sdk/lago_fixtures.py diff --git a/tests/functional-sdk/conftest.py b/tests/functional-sdk/conftest.py index 8316bdcf..ad87de83 100644 --- a/tests/functional-sdk/conftest.py +++ b/tests/functional-sdk/conftest.py @@ -1,6 +1,10 @@ import os import pytest import shutil +from lago_fixtures import ( # noqa: F401 + tmp_workdir, init_dict, init_fname, test_results, + external_log, env, vms, nets +) _local_config = { 'check_patch': { @@ -61,9 +65,3 @@ def global_test_results(): shutil.rmtree(workdir) os.makedirs(workdir) return str(workdir) - - -@pytest.fixture(scope='module') -def tmp_workdir(tmpdir_factory): - env_workdir = tmpdir_factory.mktemp('env') - return env_workdir diff --git a/tests/functional-sdk/lago_fixtures.py b/tests/functional-sdk/lago_fixtures.py new file mode 100644 index 00000000..1f396300 --- /dev/null +++ b/tests/functional-sdk/lago_fixtures.py @@ -0,0 +1,73 @@ +import logging +import os +import shutil +import tempfile +import pytest +import yaml +from lago import sdk + + +@pytest.fixture(scope='module') +def tmp_workdir(tmpdir_factory): + env_workdir = tmpdir_factory.mktemp('env') + return env_workdir + + +@pytest.fixture(scope='module') +def init_dict(init_str): + return yaml.load(init_str) + + +@pytest.fixture(scope='module') +def init_fname(init_str): + with tempfile.NamedTemporaryFile(delete=False) as f: + f.write(init_str) + return f.name + + +@pytest.fixture(scope='module') +def test_results(request, global_test_results): + results_path = os.path.join( + global_test_results, str(request.module.__name__) + ) + os.makedirs(results_path) + return results_path + + +@pytest.fixture(scope='module') +def external_log(tmpdir_factory): + return tmpdir_factory.mktemp('external_log').join('custom_log.log') + + +@pytest.fixture(scope='module', autouse=True) +def env(request, init_fname, test_results, tmp_workdir, external_log): + workdir = os.path.join(str(tmp_workdir), 'lago') + env = sdk.init( + init_fname, + workdir=workdir, + logfile=str(external_log), + loglevel=logging.DEBUG, + ) + env.start() + try: + yield env + collect_path = os.path.join(test_results, 'collect') + env.collect_artifacts(output_dir=collect_path, ignore_nopath=True) + shutil.copytree( + workdir, + os.path.join(test_results, 'workdir'), + ignore=shutil.ignore_patterns('*images*') + ) + finally: + env.stop() + env.destroy() + + +@pytest.fixture(scope='module') +def vms(env): + return env.get_vms() + + +@pytest.fixture(scope='module') +def nets(env): + return env.get_nets() diff --git a/tests/functional-sdk/test_sdk_sanity.py b/tests/functional-sdk/test_sdk_sanity.py index 26534e6e..1618a626 100644 --- a/tests/functional-sdk/test_sdk_sanity.py +++ b/tests/functional-sdk/test_sdk_sanity.py @@ -1,9 +1,7 @@ import pytest -import yaml import textwrap import tempfile import os -import shutil import logging import uuid import filecmp @@ -11,7 +9,6 @@ from lago import sdk from lago.utils import run_command from lago.plugins.vm import ExtractPathNoPathError - from utils import RandomizedDir @@ -69,66 +66,6 @@ def init_str(images): return template.render(images=images) -@pytest.fixture(scope='module') -def init_dict(init_str): - return yaml.load(init_str) - - -@pytest.fixture(scope='module') -def init_fname(init_str): - with tempfile.NamedTemporaryFile(delete=False) as f: - f.write(init_str) - return f.name - - -@pytest.fixture(scope='module') -def test_results(request, global_test_results): - results_path = os.path.join( - global_test_results, str(request.module.__name__) - ) - os.makedirs(results_path) - return results_path - - -@pytest.fixture(scope='module') -def external_log(tmpdir_factory): - return tmpdir_factory.mktemp('external_log').join('custom_log.log') - - -@pytest.fixture(scope='module', autouse=True) -def env(request, init_fname, test_results, tmp_workdir, external_log): - workdir = os.path.join(str(tmp_workdir), 'lago') - env = sdk.init( - init_fname, - workdir=workdir, - logfile=str(external_log), - loglevel=logging.DEBUG, - ) - env.start() - try: - yield env - collect_path = os.path.join(test_results, 'collect') - env.collect_artifacts(output_dir=collect_path, ignore_nopath=True) - shutil.copytree( - workdir, - os.path.join(test_results, 'workdir'), - ignore=shutil.ignore_patterns('*images*') - ) - finally: - env.stop() - env.destroy() - - -@pytest.fixture(scope='module') -def vms(env): - return env.get_vms() - - -@pytest.fixture(scope='module') -def nets(env): - return env.get_nets() - - @pytest.fixture def randomized_dir(tmpdir): randomized_path = os.path.join(str(tmpdir), 'random')