summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tempest_lib/cli/base.py2
-rw-r--r--tempest_lib/common/rest_client.py5
-rw-r--r--tempest_lib/decorators.py42
-rw-r--r--tempest_lib/exceptions.py4
-rw-r--r--tempest_lib/tests/test_decorators.py59
-rw-r--r--tempest_lib/tests/test_rest_client.py2
6 files changed, 111 insertions, 3 deletions
diff --git a/tempest_lib/cli/base.py b/tempest_lib/cli/base.py
index 95eb499..ec966ca 100644
--- a/tempest_lib/cli/base.py
+++ b/tempest_lib/cli/base.py
@@ -76,7 +76,7 @@ class CLIClient(object):
:type tenant_name: string
:param uri: The auth uri for the OpenStack Deployment
:type uri: string
- :param cli_dir: The path where the python clien binaries are installed.
+ :param cli_dir: The path where the python client binaries are installed.
defaults to /usr/bin
:type cli_dir: string
"""
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py
index c5353ad..99dbbce 100644
--- a/tempest_lib/common/rest_client.py
+++ b/tempest_lib/common/rest_client.py
@@ -424,9 +424,12 @@ class RestClient(object):
else:
raise exceptions.InvalidContentType(str(resp.status))
- if resp.status == 401 or resp.status == 403:
+ if resp.status == 401:
raise exceptions.Unauthorized(resp_body)
+ if resp.status == 403:
+ raise exceptions.Forbidden(resp_body)
+
if resp.status == 404:
raise exceptions.NotFound(resp_body)
diff --git a/tempest_lib/decorators.py b/tempest_lib/decorators.py
new file mode 100644
index 0000000..8c1d1c9
--- /dev/null
+++ b/tempest_lib/decorators.py
@@ -0,0 +1,42 @@
+# Copyright 2015 Hewlett-Packard Development Company, L.P.
+#
+# 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 functools
+
+import testtools
+
+
+def skip_because(*args, **kwargs):
+ """A decorator useful to skip tests hitting known bugs
+
+ @param bug: bug number causing the test to skip
+ @param condition: optional condition to be True for the skip to have place
+ """
+ def decorator(f):
+ @functools.wraps(f)
+ def wrapper(self, *func_args, **func_kwargs):
+ skip = False
+ if "condition" in kwargs:
+ if kwargs["condition"] is True:
+ skip = True
+ else:
+ skip = True
+ if "bug" in kwargs and skip is True:
+ if not kwargs['bug'].isdigit():
+ raise ValueError('bug must be a valid bug number')
+ msg = "Skipped until Bug: %s is resolved." % kwargs["bug"]
+ raise testtools.TestCase.skipException(msg)
+ return f(self, *func_args, **func_kwargs)
+ return wrapper
+ return decorator
diff --git a/tempest_lib/exceptions.py b/tempest_lib/exceptions.py
index d97d158..fbf9ee0 100644
--- a/tempest_lib/exceptions.py
+++ b/tempest_lib/exceptions.py
@@ -62,6 +62,10 @@ class Unauthorized(RestClientException):
message = 'Unauthorized'
+class Forbidden(RestClientException):
+ message = "Forbidden"
+
+
class TimeoutException(RestClientException):
message = "Request timed out"
diff --git a/tempest_lib/tests/test_decorators.py b/tempest_lib/tests/test_decorators.py
new file mode 100644
index 0000000..261ffca
--- /dev/null
+++ b/tempest_lib/tests/test_decorators.py
@@ -0,0 +1,59 @@
+# Copyright 2013 IBM Corp
+# Copyright 2015 Hewlett-Packard Development Company, L.P.
+#
+# 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 testtools
+
+from tempest_lib import base as test
+from tempest_lib import decorators
+from tempest_lib.tests import base
+
+
+class TestSkipBecauseDecorator(base.TestCase):
+ def _test_skip_because_helper(self, expected_to_skip=True,
+ **decorator_args):
+ class TestFoo(test.BaseTestCase):
+ _interface = 'json'
+
+ @decorators.skip_because(**decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ if expected_to_skip:
+ self.assertRaises(testtools.TestCase.skipException, t.test_bar)
+ else:
+ # assert that test_bar returned 0
+ self.assertEqual(TestFoo('test_bar').test_bar(), 0)
+
+ def test_skip_because_bug(self):
+ self._test_skip_because_helper(bug='12345')
+
+ def test_skip_because_bug_and_condition_true(self):
+ self._test_skip_because_helper(bug='12348', condition=True)
+
+ def test_skip_because_bug_and_condition_false(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='12349', condition=False)
+
+ def test_skip_because_bug_without_bug_never_skips(self):
+ """Never skip without a bug parameter."""
+ self._test_skip_because_helper(expected_to_skip=False,
+ condition=True)
+ self._test_skip_because_helper(expected_to_skip=False)
+
+ def test_skip_because_invalid_bug_number(self):
+ """Raise ValueError if with an invalid bug number"""
+ self.assertRaises(ValueError, self._test_skip_because_helper,
+ bug='critical_bug')
diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py
index dc819d0..b48c156 100644
--- a/tempest_lib/tests/test_rest_client.py
+++ b/tempest_lib/tests/test_rest_client.py
@@ -315,7 +315,7 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
**self.set_data("401"))
def test_response_403(self):
- self.assertRaises(exceptions.Unauthorized,
+ self.assertRaises(exceptions.Forbidden,
self.rest_client._error_checker,
**self.set_data("403"))