From ad163f0ecf19e6b66b7c7c240af14371753ca110 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Fri, 26 Sep 2014 20:41:04 +0400 Subject: [PATCH] Add script to run functional CLI and client tests locally Change-Id: Ic6f3e96d037b9096ea9e0689cb4f66b4cb05fb8e --- mistralclient/tests/functional/cli/base.py | 35 +++++++++++++ .../tests/functional/cli/v1/cli_tests.py | 22 +++----- .../tests/functional/cli/v2/cli_tests_v2.py | 23 +++------ .../tests/functional/client/v1/base.py | 15 ++++-- .../tests/functional/client/v1/tests.py | 11 ++-- run_functional_tests.sh | 50 +++++++++++++++++++ 6 files changed, 120 insertions(+), 36 deletions(-) create mode 100644 mistralclient/tests/functional/cli/base.py create mode 100755 run_functional_tests.sh diff --git a/mistralclient/tests/functional/cli/base.py b/mistralclient/tests/functional/cli/base.py new file mode 100644 index 00000000..60c66668 --- /dev/null +++ b/mistralclient/tests/functional/cli/base.py @@ -0,0 +1,35 @@ +# Copyright (c) 2014 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 os + +from tempest import cli + + +class MistralCLIAuth(cli.ClientTestBase): + + _mistral_url = None + + def mistral(self, action, flags='', params='', admin=True, fail_ok=False, + keystone_version=3): + """Executes Mistral command.""" + mistral_url_op = "--os-mistral-url %s" % self._mistral_url + + if 'WITHOUT_AUTH' in os.environ: + return cli.execute( + 'mistral %s' % mistral_url_op, action, flags, params) + else: + return self.cmd_with_auth( + 'mistral %s' % mistral_url_op, action, flags, params, admin, + fail_ok, keystone_version) diff --git a/mistralclient/tests/functional/cli/v1/cli_tests.py b/mistralclient/tests/functional/cli/v1/cli_tests.py index 386b1a5b..78c9277b 100644 --- a/mistralclient/tests/functional/cli/v1/cli_tests.py +++ b/mistralclient/tests/functional/cli/v1/cli_tests.py @@ -14,27 +14,19 @@ import os -from tempest import cli from tempest import exceptions +from mistralclient.tests.functional.cli import base + MISTRAL_URL = "http://localhost:8989/v1" -class MistralCLIAuth(cli.ClientTestBase): - - def mistral(self, action, flags='', params='', admin=True, fail_ok=False, - keystone_version=3): - """Executes Mistral command.""" - mistral_url_op = "--os-mistral-url %s" % MISTRAL_URL - return self.cmd_with_auth( - 'mistral %s' % mistral_url_op, action, flags, params, admin, - fail_ok, keystone_version) - - -class SimpleMistralCLITests(MistralCLIAuth): +class SimpleMistralCLITests(base.MistralCLIAuth): """Basic tests, check '-list', '-help' commands.""" + _mistral_url = MISTRAL_URL + @classmethod def setUpClass(cls): super(SimpleMistralCLITests, cls).setUpClass() @@ -58,7 +50,9 @@ class SimpleMistralCLITests(MistralCLIAuth): 'Description', 'State', 'Tags']) -class ClientTestBase(MistralCLIAuth): +class ClientTestBase(base.MistralCLIAuth): + + _mistral_url = MISTRAL_URL @classmethod def setUpClass(cls): diff --git a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py index 8ea71f51..3db1bfb4 100644 --- a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py +++ b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py @@ -14,28 +14,19 @@ import os -from tempest import cli from tempest import exceptions +from mistralclient.tests.functional.cli import base + MISTRAL_URL = "http://localhost:8989/v2" -class MistralCLIAuth(cli.ClientTestBase): - - def mistral(self, action, flags='', params='', admin=True, fail_ok=False, - keystone_version=3): - """Executes Mistral command.""" - mistral_url_op = "--os-mistral-url %s" % MISTRAL_URL - - return self.cmd_with_auth( - 'mistral %s' % mistral_url_op, action, flags, params, admin, - fail_ok, keystone_version) - - -class SimpleMistralCLITests(MistralCLIAuth): +class SimpleMistralCLITests(base.MistralCLIAuth): """Basic tests, check '-list', '-help' commands.""" + _mistral_url = MISTRAL_URL + @classmethod def setUpClass(cls): super(SimpleMistralCLITests, cls).setUpClass() @@ -66,7 +57,9 @@ class SimpleMistralCLITests(MistralCLIAuth): 'State']) -class ClientTestBase(MistralCLIAuth): +class ClientTestBase(base.MistralCLIAuth): + + _mistral_url = MISTRAL_URL @classmethod def setUpClass(cls): diff --git a/mistralclient/tests/functional/client/v1/base.py b/mistralclient/tests/functional/client/v1/base.py index bbfa4892..01747d30 100644 --- a/mistralclient/tests/functional/client/v1/base.py +++ b/mistralclient/tests/functional/client/v1/base.py @@ -9,22 +9,29 @@ from mistralclient.api.v1 import client as mclient class ClientAuth(rest_client.RestClient): - def __init__(self, auth_provider): + def __init__(self, auth_provider, url): super(ClientAuth, self).__init__(auth_provider) self.mistral_client = mclient.Client( auth_token=self.auth_provider.get_token(), - mistral_url="http://localhost:8989/v1") + mistral_url=url) class MistralBase(testtools.TestCase): + _mistral_url = None + @classmethod def setUpClass(cls): super(MistralBase, cls).setUpClass() - mgr = clients.Manager() - cls.mistral_client = ClientAuth(mgr.auth_provider).mistral_client + if 'WITHOUT_AUTH' in os.environ: + cls.mistral_client = mclient.Client( + mistral_url=cls._mistral_url) + else: + mgr = clients.Manager() + cls.mistral_client = ClientAuth( + mgr.auth_provider, cls._mistral_url).mistral_client cls.definition = open(os.path.relpath( 'functionaltests/resources/v1/wb_v1.yaml', diff --git a/mistralclient/tests/functional/client/v1/tests.py b/mistralclient/tests/functional/client/v1/tests.py index 48afd4fc..882d3dba 100644 --- a/mistralclient/tests/functional/client/v1/tests.py +++ b/mistralclient/tests/functional/client/v1/tests.py @@ -1,7 +1,12 @@ from base import MistralBase -class Workbooks(MistralBase): +class MistralURLDefine(MistralBase): + + _mistral_url = "http://localhost:8989/v1" + + +class Workbooks(MistralURLDefine): def test_get_workbook_list(self): wbs = self.mistral_client.workbooks.list() @@ -36,7 +41,7 @@ class Workbooks(MistralBase): self.assertEqual(self.definition, received_definition) -class Executions(MistralBase): +class Executions(MistralURLDefine): def test_create_execution(self): execution = self.create_execution() @@ -69,7 +74,7 @@ class Executions(MistralBase): self.assertEqual(execution.id, received_exec.id) -class Tasks(MistralBase): +class Tasks(MistralURLDefine): def test_list_tasks(self): execution = self.create_execution() diff --git a/run_functional_tests.sh b/run_functional_tests.sh new file mode 100755 index 00000000..90d9488b --- /dev/null +++ b/run_functional_tests.sh @@ -0,0 +1,50 @@ +#! /usr/bin/env bash + +ARG=$1 + +export USER_AUTH_SETTING=$(echo $OS_AUTH_URL) + +function pre_hook() { + export WITHOUT_AUTH="True" + IS_TEMPEST=$(pip freeze | grep tempest) + if [ -z "$IS_TEMPEST" ] + then echo "$(tput setaf 4)No such module 'tempest' in the system. Before running this script please install tempest module using : pip install git+http://github.com/openstack/tempest.git$(tput sgr 0)" + fi +} + +function run_tests_by_version() { + export OS_AUTH_URL="" + echo "$(tput setaf 4)Running integration CLI and python-mistralclient tests for v$1$(tput sgr 0)" + export VERSION="v$1" + nosetests -v mistralclient/tests/functional/cli/v$1/ + nosetests -v mistralclient/tests/functional/client/v$1/ + unset VERSION +} + +function run_tests() { + if [ -z "$ARG" ] + then + run_tests_by_version 1 + run_tests_by_version 2 + elif [ "$ARG" == "v1" ] + then + run_tests_by_version 1 + elif [ "$ARG" == "v2" ] + then + run_tests_by_version 2 + fi +} + +function post_hook () { + unset LOCAL_RUN + export OS_AUTH_URL=$USER_AUTH_SETTING + unset USER_AUTH_SETTING +} +#----------main-part---------- + +echo "$(tput setaf 4)Preparation for tests running...$(tput sgr 0)" +pre_hook +echo "$(tput setaf 4)Running tests...$(tput sgr 0)" +run_tests + +post_hook