diff --git a/fuel_ccp_tests/fixtures/k8s_fixtures.py b/fuel_ccp_tests/fixtures/k8s_fixtures.py index 3bcf0b0..0cb57a1 100644 --- a/fuel_ccp_tests/fixtures/k8s_fixtures.py +++ b/fuel_ccp_tests/fixtures/k8s_fixtures.py @@ -12,13 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. +from operator import attrgetter import os import pytest -from fuel_ccp_tests import logger from fuel_ccp_tests.helpers import ext -from fuel_ccp_tests import settings +from fuel_ccp_tests import logger from fuel_ccp_tests.managers import k8smanager +from fuel_ccp_tests import settings LOG = logger.logger @@ -94,12 +95,17 @@ def check_files_missing(request): @pytest.fixture(scope='class') -def check_settings_missing(request): +def check_settings_missing(request, config): + def get_attr(attr, obj): + try: + return attrgetter(attr)(obj) + except Exception: + return None LOG.info("Required settings: {}".format(request.cls.required_settings)) - settings_missing = [s for s in request.cls.required_settings - if not getattr(settings, s, None)] - assert len(settings_missing) == 0, \ - "Following env variables are not set {}". format(settings_missing) + missing = [s for s in request.cls.required_settings + if not (getattr(settings, s, None) or get_attr(s, config))] + assert len(missing) == 0, \ + "Following env variables are not set {}". format(missing) @pytest.fixture(scope='class') diff --git a/fuel_ccp_tests/managers/k8smanager.py b/fuel_ccp_tests/managers/k8smanager.py index 0cb3e1f..b46985f 100644 --- a/fuel_ccp_tests/managers/k8smanager.py +++ b/fuel_ccp_tests/managers/k8smanager.py @@ -18,12 +18,12 @@ import yaml from devops.helpers import helpers -from fuel_ccp_tests.helpers import exceptions from fuel_ccp_tests.helpers import _subprocess_runner +from fuel_ccp_tests.helpers import exceptions from fuel_ccp_tests.helpers import post_install_k8s_checks from fuel_ccp_tests import logger -from fuel_ccp_tests import settings from fuel_ccp_tests.managers.k8s import cluster +from fuel_ccp_tests import settings LOG = logger.logger diff --git a/fuel_ccp_tests/settings_oslo.py b/fuel_ccp_tests/settings_oslo.py index 276499d..eb88c7d 100644 --- a/fuel_ccp_tests/settings_oslo.py +++ b/fuel_ccp_tests/settings_oslo.py @@ -84,6 +84,10 @@ k8s_deploy_opts = [ help="", default=None), ct.Cfg('kube_settings', ct.JSONDict(), help="", default={}), + ct.Cfg('e2e_conformance_image', ct.String(), + help="", default=''), + ct.Cfg('e2e_conformance_timeout', ct.Integer(), + help="", default=3600), ] # Access credentials to a ready K8S cluster diff --git a/fuel_ccp_tests/tests/component/k8s/test_conformance.py b/fuel_ccp_tests/tests/component/k8s/test_conformance.py new file mode 100644 index 0000000..10ea0a6 --- /dev/null +++ b/fuel_ccp_tests/tests/component/k8s/test_conformance.py @@ -0,0 +1,71 @@ +# Copyright 2016 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import pytest + +from fuel_ccp_tests.helpers import _subprocess_runner +from fuel_ccp_tests.helpers import exceptions +from fuel_ccp_tests import logger + +LOG = logger.logger + + +@pytest.mark.k8s_conformance +@pytest.mark.component_k8s +class TestK8sConformance(object): + + required_settings = [ + 'k8s_deploy.e2e_conformance_image', + ] + + @pytest.mark.fail_snapshot + @pytest.mark.dashboard_exists + @pytest.mark.usefixtures("check_settings_missing", "k8scluster") + def test_k8s_conformance(self, underlay, config): + """Run k8s conformance tests. + + Requires path to the image to be set via environment variable + E2E_CONFORMANCE_IMAGE + + Scenario: + 1. Get or deploy k8s environment. + 2. Run conformance tests + """ + LOG.info("Running e2e conformance tests") + remote = underlay.remote(host=config.k8s.kube_host) + cmd = 'docker run --rm --net=host ' \ + '-e API_SERVER="http://127.0.0.1:8080" ' \ + '{image} >> e2e-conformance.log'.format( + image=config.k8s_deploy.e2e_conformance_image + ) + result = remote.execute( + cmd, + timeout=config.k8s_deploy.e2e_conformance_timeout, + verbose=True) + + cmd = "mkdir -p logs" + + # FIXME Use Subprocess.execute instead of Subprocess.check_call until + # check_call is not fixed (fuel-devops3.0.2) + _subprocess_runner.Subprocess.execute(cmd, verbose=True) + + remote.download('/home/vagrant/e2e-conformance.log', 'logs/') + + expected_ec = [0] + if result.exit_code not in expected_ec: + raise exceptions.UnexpectedExitCode( + cmd, + result.exit_code, + expected_ec, + stdout=result.stdout_brief, + stderr=result.stdout_brief)