summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.zuul.yaml3
-rw-r--r--releasenotes/source/index.rst1
-rw-r--r--releasenotes/source/victoria.rst6
-rw-r--r--swiftclient/exceptions.py12
-rwxr-xr-xswiftclient/shell.py3
-rw-r--r--test/functional/__init__.py5
-rw-r--r--test/functional/test_openstacksdk.py1
-rw-r--r--test/functional/test_swiftclient.py6
-rw-r--r--test/sample.conf5
-rw-r--r--test/unit/test_swiftclient.py17
10 files changed, 54 insertions, 5 deletions
diff --git a/.zuul.yaml b/.zuul.yaml
index 87ac54b..480c1a8 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -27,6 +27,7 @@
- job:
name: swiftclient-functional-py2
parent: swiftclient-functional
+ nodeset: openstack-single-node-bionic
description: |
Run functional tests of python-swiftclient under Python 2
vars:
@@ -38,7 +39,7 @@
- lib-forward-testing-python3
- openstack-lower-constraints-jobs
- openstack-python-jobs
- - openstack-python3-victoria-jobs
+ - openstack-python3-wallaby-jobs
- publish-openstack-docs-pti
- release-notes-jobs-python3
check:
diff --git a/releasenotes/source/index.rst b/releasenotes/source/index.rst
index d46593b..a63715f 100644
--- a/releasenotes/source/index.rst
+++ b/releasenotes/source/index.rst
@@ -6,6 +6,7 @@
:maxdepth: 1
current
+ victoria
ussuri
train
stein
diff --git a/releasenotes/source/victoria.rst b/releasenotes/source/victoria.rst
new file mode 100644
index 0000000..4efc7b6
--- /dev/null
+++ b/releasenotes/source/victoria.rst
@@ -0,0 +1,6 @@
+=============================
+Victoria Series Release Notes
+=============================
+
+.. release-notes::
+ :branch: stable/victoria
diff --git a/swiftclient/exceptions.py b/swiftclient/exceptions.py
index da70379..a9b993c 100644
--- a/swiftclient/exceptions.py
+++ b/swiftclient/exceptions.py
@@ -35,6 +35,13 @@ class ClientException(Exception):
self.http_response_content = http_response_content
self.http_response_headers = http_response_headers
+ self.transaction_id = None
+ if self.http_response_headers:
+ for header in ('X-Trans-Id', 'X-Openstack-Request-Id'):
+ if header in self.http_response_headers:
+ self.transaction_id = self.http_response_headers[header]
+ break
+
@classmethod
def from_response(cls, resp, msg=None, body=None):
msg = msg or '%s %s' % (resp.status_code, resp.reason)
@@ -78,4 +85,7 @@ class ClientException(Exception):
else:
b += ' [first 60 chars of response] %s' \
% self.http_response_content[:60]
- return b and '%s: %s' % (a, b) or a
+ c = ''
+ if self.transaction_id:
+ c = ' (txn: %s)' % self.transaction_id
+ return b and '%s: %s%s' % (a, b, c) or (a + c)
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index b129d63..dbcd437 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -2058,8 +2058,9 @@ Examples:
try:
globals()['st_%s' % args[0]](parser, argv[1:], output)
except ClientException as err:
+ trans_id = err.transaction_id
+ err.transaction_id = None # clear it so we aren't overly noisy
output.error(str(err))
- trans_id = (err.http_response_headers or {}).get('X-Trans-Id')
if trans_id:
output.error("Failed Transaction ID: %s",
parse_header_string(trans_id))
diff --git a/test/functional/__init__.py b/test/functional/__init__.py
index 248875a..f0fea3b 100644
--- a/test/functional/__init__.py
+++ b/test/functional/__init__.py
@@ -58,6 +58,11 @@ def _load_config(force_reload=False):
conf['auth_url'] = auth_url
try:
+ conf['cacert'] = parser.get('func_test', 'cacert')
+ except configparser.NoOptionError:
+ conf['cacert'] = None
+
+ try:
conf['account_username'] = parser.get('func_test',
'account_username')
except configparser.NoOptionError:
diff --git a/test/functional/test_openstacksdk.py b/test/functional/test_openstacksdk.py
index cee7f4e..e51773a 100644
--- a/test/functional/test_openstacksdk.py
+++ b/test/functional/test_openstacksdk.py
@@ -35,6 +35,7 @@ class TestOpenStackSDK(unittest.TestCase):
auth_url=TEST_CONFIG['auth_url'],
username=TEST_CONFIG['account_username'],
password=TEST_CONFIG['password'],
+ cacert=TEST_CONFIG['cacert'],
)
cls.object_store = cls.conn.object_store
diff --git a/test/functional/test_swiftclient.py b/test/functional/test_swiftclient.py
index 54c514d..aaade87 100644
--- a/test/functional/test_swiftclient.py
+++ b/test/functional/test_swiftclient.py
@@ -42,6 +42,7 @@ class TestFunctional(unittest.TestCase):
def _get_config(self):
self.auth_url = TEST_CONFIG['auth_url']
+ self.cacert = TEST_CONFIG['cacert']
self.auth_version = TEST_CONFIG['auth_version']
self.account_username = TEST_CONFIG['account_username']
self.password = TEST_CONFIG['password']
@@ -52,7 +53,7 @@ class TestFunctional(unittest.TestCase):
"""
return swiftclient.Connection(
self.auth_url, self.account_username, self.password,
- auth_version=self.auth_version)
+ auth_version=self.auth_version, cacert=self.cacert)
def setUp(self):
super(TestFunctional, self).setUp()
@@ -486,7 +487,7 @@ class TestUsingKeystone(TestFunctional):
return swiftclient.Connection(
self.auth_url, username, self.password,
- auth_version=self.auth_version,
+ auth_version=self.auth_version, cacert=self.cacert,
os_options={'tenant_name': account})
@@ -515,4 +516,5 @@ class TestUsingKeystoneV3(TestFunctional):
'user_domain_name': user_domain}
return swiftclient.Connection(self.auth_url, username, password,
auth_version=self.auth_version,
+ cacert=self.cacert,
os_options=os_options)
diff --git a/test/sample.conf b/test/sample.conf
index 49bca90..04dfdd9 100644
--- a/test/sample.conf
+++ b/test/sample.conf
@@ -6,6 +6,11 @@ auth_uri = http://127.0.0.1:8080/auth/v1.0/
#auth_version = 2
#auth_uri = http://localhost:5000/v2.0/
+# You may want to run tests against endpoints that use development certs
+# without installing the CA system-wide. Use this to trust an extra set
+# of certificates.
+#cacert = /path/to/trusted-ca.crt
+
# Primary functional test account (needs admin access to the account).
# By default the tests use a swiftclient.client.Connection instance with user
# attribute set to 'account:username' based on the options 'account' and
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py
index dfd79c7..2644e33 100644
--- a/test/unit/test_swiftclient.py
+++ b/test/unit/test_swiftclient.py
@@ -84,6 +84,23 @@ class TestClientException(unittest.TestCase):
self.assertIs(True, hasattr(exc, key))
self.assertEqual(getattr(exc, key), value)
+ def test_transaction_id_from_headers(self):
+ exc = c.ClientException('test')
+ self.assertIsNone(exc.transaction_id)
+
+ exc = c.ClientException('test', http_response_headers={})
+ self.assertIsNone(exc.transaction_id)
+
+ exc = c.ClientException('test', http_response_headers={
+ 'X-Trans-Id': 'some-id'})
+ self.assertEqual(exc.transaction_id, 'some-id')
+ self.assertIn('(txn: some-id)', str(exc))
+
+ exc = c.ClientException('test', http_response_headers={
+ 'X-Openstack-Request-Id': 'some-other-id'})
+ self.assertEqual(exc.transaction_id, 'some-other-id')
+ self.assertIn('(txn: some-other-id)', str(exc))
+
class MockHttpResponse(object):
def __init__(self, status=0, headers=None, verify=False):