Fix glance_http HTTPS response issues

This commit is a dual of python-glanceclient change:
I3a973da3b962c7572ae0f61f6996bdd1f0048339

Also, a bad file descriptor error is caused by the socket being closed
to soon. This commit adds overloads close() for the
VerifiedHTTPSConnection subclass which will remove the reference to
socket before making the call in the base HTTPConnection.close(). This
will avoid socket being closed before the response body is read. The
socket will close when the response close is called.

Closes-Bug: #1272828

Change-Id: Ia30058bc4752489107b998bd44d38c27901cfe63
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index e72cd9e..2ce05ee 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -218,6 +218,8 @@
         return getattr(self.connection, name)
 
     def makefile(self, *args, **kwargs):
+        # Ensure the socket is closed when this file is closed
+        kwargs['close'] = True
         return socket._fileobject(self.connection, *args, **kwargs)
 
 
@@ -345,6 +347,15 @@
         self.sock = OpenSSLConnectionDelegator(self.context, sock)
         self.sock.connect((self.host, self.port))
 
+    def close(self):
+        if self.sock:
+            # Remove the reference to the socket but don't close it yet.
+            # Response close will close both socket and associated
+            # file. Closing socket too soon will cause response
+            # reads to fail with socket IO error 'Bad file descriptor'.
+            self.sock = None
+        super(VerifiedHTTPSConnection, self).close()
+
 
 class ResponseBodyIterator(object):
     """A class that acts as an iterator over an HTTP response."""