From 2ed01afac96af59304215e384fd9b0f0be992711 Mon Sep 17 00:00:00 2001 From: Le Tian Ren Date: Mon, 6 Jan 2014 14:43:56 +0800 Subject: [PATCH] Fix glanceclient http.py string formatting error * Fix "TypeError: not all arguments converted during string formatting" * Add a UT case to cover the path where the bug is in Change-Id: I91a137c5c3a9a3cc603804bef5eaea14ae281c08 Closes-Bug: #1265730 --- glanceclient/common/http.py | 3 ++- tests/test_http.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 72710fbb..9d96342d 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -435,7 +435,8 @@ class VerifiedHTTPSConnection(HTTPSConnection): try: self.context.load_verify_locations(self.cacert) except Exception as e: - msg = 'Unable to load CA from "%s"' % (self.cacert, e) + msg = ('Unable to load CA from "%(cacert)s" %(exc)s' % + dict(cacert=self.cacert, exc=e)) raise exc.SSLConfigurationError(msg) else: self.context.set_default_verify_paths() diff --git a/tests/test_http.py b/tests/test_http.py index 6a745353..a76a9771 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -293,6 +293,23 @@ class TestHostResolutionError(testtools.TestCase): self.mock.UnsetStubs() +class TestVerifiedHTTPSConnection(testtools.TestCase): + """Test fixture for glanceclient.common.http.VerifiedHTTPSConnection.""" + + def test_setcontext_unable_to_load_cacert(self): + """Add this UT case with Bug#1265730.""" + self.assertRaises(exc.SSLConfigurationError, + http.VerifiedHTTPSConnection, + "127.0.0.1", + None, + None, + None, + "gx_cacert", + None, + False, + True) + + class TestResponseBodyIterator(testtools.TestCase): def test_iter_default_chunk_size_64k(self):