Browse Source

Add script to run functional tests locally

- Added script that can run part of functional tests locally
- Added needed mocks in base.py file so that we don't interact with keystone
- Added small a description how to run new script

Change-Id: I1867fb93f540c8f061fd09c40a283ce1ef2c072c
tags/0.1.1
Anastasia Kuznetsova 4 years ago
parent
commit
aacdb47af3
5 changed files with 85 additions and 3 deletions
  1. 10
    1
      README.rst
  2. 27
    1
      mistral/tests/functional/base.py
  3. 1
    0
      requirements.txt
  4. 47
    0
      run_functional_tests.sh
  5. 0
    1
      test-requirements.txt

+ 10
- 1
README.rst View File

@@ -77,4 +77,13 @@ To run the examples find them in mistral-extra repository (https://github.com/st
77 77
 Tests
78 78
 -----
79 79
 
80
-Information about automated tests for Mistral can be found here: https://wiki.openstack.org/wiki/Mistral/Testing
80
+There is an ability to run part of functional tests in non-openstack mode locally. To do this:
81
+
82
+    # set *auth_enable=false* in the mistral.conf and restart Mistral
83
+    # execute:
84
+
85
+        bash run_functional_tests.sh
86
+
87
+To run tests for only one version need to specify it: bash run_functional_tests.sh v1
88
+
89
+More information about automated tests for Mistral can be found here: https://wiki.openstack.org/wiki/Mistral/Testing

+ 27
- 1
mistral/tests/functional/base.py View File

@@ -14,8 +14,11 @@
14 14
 #    under the License.
15 15
 
16 16
 import json
17
+import mock
18
+import os
17 19
 import time
18 20
 
21
+from tempest import auth
19 22
 from tempest import clients
20 23
 from tempest.common import rest_client
21 24
 from tempest import config
@@ -266,6 +269,24 @@ class MistralClientV2(MistralClientBase):
266 269
         return resp, json.loads(body)
267 270
 
268 271
 
272
+class AuthProv(auth.KeystoneV2AuthProvider):
273
+
274
+    def __init__(self):
275
+        self.alt_part = None
276
+
277
+    def auth_request(self, method, url, *args, **kwargs):
278
+        req_url, headers, body = super(AuthProv, self).auth_request(
279
+            method, url, *args, **kwargs)
280
+        return 'http://localhost:8989/{0}/{1}'.format(
281
+            os.environ['VERSION'], url), headers, body
282
+
283
+    def get_auth(self):
284
+        return 'mock_str', 'mock_str'
285
+
286
+    def base_url(self, *args, **kwargs):
287
+        return ''
288
+
289
+
269 290
 class TestCase(tempest.test.BaseTestCase):
270 291
 
271 292
     @classmethod
@@ -275,7 +296,12 @@ class TestCase(tempest.test.BaseTestCase):
275 296
         """
276 297
         super(TestCase, cls).setUpClass()
277 298
 
278
-        cls.mgr = clients.Manager()
299
+        if 'WITHOUT_AUTH' in os.environ:
300
+            cls.mgr = mock.MagicMock()
301
+            cls.mgr.auth_provider = AuthProv()
302
+        else:
303
+            cls.mgr = clients.Manager()
304
+
279 305
         if cls._version == 1:
280 306
             cls.client = MistralClientV1(cls.mgr.auth_provider)
281 307
         if cls._version == 2:

+ 1
- 0
requirements.txt View File

@@ -26,3 +26,4 @@ SQLAlchemy>=0.7.8,!=0.9.5,<=0.9.99
26 26
 stevedore>=0.14
27 27
 yaql==0.2.1 # This is not in global requirements
28 28
 jsonschema>=2.0.0,<3.0.0
29
+mock>=1.0

+ 47
- 0
run_functional_tests.sh View File

@@ -0,0 +1,47 @@
1
+#! /usr/bin/env bash
2
+
3
+ARG=$1
4
+
5
+function pre_hook() {
6
+  export WITHOUT_AUTH="True"
7
+  IS_TEMPEST=$(pip freeze | grep tempest)
8
+  if [ -z "$IS_TEMPEST" ]
9
+    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)"
10
+  exit 1
11
+  fi
12
+}
13
+
14
+function run_tests_by_version() {
15
+  echo "$(tput setaf 4)Running integration API and workflow execution tests for v$1$(tput sgr 0)"
16
+  export VERSION="v$1"
17
+  nosetests -v mistral/tests/functional/api/v$1/
18
+  unset VERSION
19
+}
20
+
21
+function run_tests() {
22
+  if [ -z "$ARG" ]
23
+  then
24
+    run_tests_by_version 1
25
+    run_tests_by_version 2
26
+  elif [ "$ARG" == "v1" ]
27
+  then
28
+    run_tests_by_version 1
29
+  elif [ "$ARG" == "v2" ]
30
+  then
31
+    run_tests_by_version 2
32
+  fi
33
+}
34
+
35
+function post_hook () {
36
+  unset LOCAL_RUN
37
+}
38
+
39
+#----------main-part----------
40
+
41
+echo "$(tput setaf 4)Preparation for tests running...$(tput sgr 0)"
42
+pre_hook
43
+echo "$(tput setaf 4)Running tests...$(tput sgr 0)"
44
+run_tests
45
+
46
+post_hook
47
+

+ 0
- 1
test-requirements.txt View File

@@ -10,7 +10,6 @@ sphinxcontrib-pecanwsme>=0.8
10 10
 sphinxcontrib-httpdomain
11 11
 docutils==0.9.1
12 12
 fixtures>=0.3.14
13
-mock>=1.0
14 13
 nose
15 14
 testrepository>=0.0.18
16 15
 testtools>=0.9.34

Loading…
Cancel
Save