Merge "Use the idempotent id and tooling from tempest-lib"
diff --git a/tempest/api_schema/response/compute/v2_1/agents.py b/tempest/api_schema/response/compute/v2_1/agents.py
deleted file mode 100644
index da38198..0000000
--- a/tempest/api_schema/response/compute/v2_1/agents.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright 2014 NEC Corporation.  All rights reserved.
-#
-#    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.
-
-common_agent_info = {
-    'type': 'object',
-    'properties': {
-        'agent_id': {'type': ['integer', 'string']},
-        'hypervisor': {'type': 'string'},
-        'os': {'type': 'string'},
-        'architecture': {'type': 'string'},
-        'version': {'type': 'string'},
-        'url': {'type': 'string', 'format': 'uri'},
-        'md5hash': {'type': 'string'}
-    },
-    'additionalProperties': False,
-    'required': ['agent_id', 'hypervisor', 'os', 'architecture',
-                 'version', 'url', 'md5hash']
-}
-
-list_agents = {
-    'status_code': [200],
-    'response_body': {
-        'type': 'object',
-        'properties': {
-            'agents': {
-                'type': 'array',
-                'items': common_agent_info
-            }
-        },
-        'additionalProperties': False,
-        'required': ['agents']
-    }
-}
-
-create_agent = {
-    'status_code': [200],
-    'response_body': {
-        'type': 'object',
-        'properties': {
-            'agent': common_agent_info
-        },
-        'additionalProperties': False,
-        'required': ['agent']
-    }
-}
-
-delete_agent = {
-    'status_code': [200]
-}
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index e5431a0..800e977 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -24,12 +24,10 @@
 
 import OpenSSL
 from oslo_log import log as logging
-from oslo_serialization import jsonutils as json
 import six
 from six import moves
 from six.moves import http_client as httplib
 from six.moves.urllib import parse as urlparse
-from tempest_lib import exceptions as lib_exc
 
 from tempest import exceptions as exc
 
@@ -51,19 +49,20 @@
         self.endpoint_port = endpoint_parts.port
         self.endpoint_path = endpoint_parts.path
 
-        self.connection_class = self.get_connection_class(self.endpoint_scheme)
-        self.connection_kwargs = self.get_connection_kwargs(
+        self.connection_class = self._get_connection_class(
+            self.endpoint_scheme)
+        self.connection_kwargs = self._get_connection_kwargs(
             self.endpoint_scheme, **kwargs)
 
     @staticmethod
-    def get_connection_class(scheme):
+    def _get_connection_class(scheme):
         if scheme == 'https':
             return VerifiedHTTPSConnection
         else:
             return httplib.HTTPConnection
 
     @staticmethod
-    def get_connection_kwargs(scheme, **kwargs):
+    def _get_connection_kwargs(scheme, **kwargs):
         _kwargs = {'timeout': float(kwargs.get('timeout', 600))}
 
         if scheme == 'https':
@@ -75,7 +74,7 @@
 
         return _kwargs
 
-    def get_connection(self):
+    def _get_connection(self):
         _class = self.connection_class
         try:
             return _class(self.endpoint_hostname, self.endpoint_port,
@@ -95,7 +94,7 @@
 
         self._log_request(method, url, kwargs['headers'])
 
-        conn = self.get_connection()
+        conn = self._get_connection()
 
         try:
             url_parts = urlparse.urlparse(url)
@@ -159,30 +158,6 @@
                 self.LOG.debug("Large body (%d) md5 summary: %s", length,
                                hashlib.md5(str_body).hexdigest())
 
-    def json_request(self, method, url, **kwargs):
-        kwargs.setdefault('headers', {})
-        kwargs['headers'].setdefault('Content-Type', 'application/json')
-        if kwargs['headers']['Content-Type'] != 'application/json':
-            msg = "Only application/json content-type is supported."
-            raise lib_exc.InvalidContentType(msg)
-
-        if 'body' in kwargs:
-            kwargs['body'] = json.dumps(kwargs['body'])
-
-        resp, body_iter = self._http_request(url, method, **kwargs)
-
-        if 'application/json' in resp.getheader('content-type', ''):
-            body = ''.join([chunk for chunk in body_iter])
-            try:
-                body = json.loads(body)
-            except ValueError:
-                LOG.error('Could not decode response body as JSON')
-        else:
-            msg = "Only json/application content-type is supported."
-            raise lib_exc.InvalidContentType(msg)
-
-        return resp, body
-
     def raw_request(self, method, url, **kwargs):
         kwargs.setdefault('headers', {})
         kwargs['headers'].setdefault('Content-Type',
diff --git a/tempest/tests/test_glance_http.py b/tempest/tests/test_glance_http.py
index 105caec..ed886da 100644
--- a/tempest/tests/test_glance_http.py
+++ b/tempest/tests/test_glance_http.py
@@ -13,14 +13,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import socket
-
 import mock
-from oslo_serialization import jsonutils as json
 from oslotest import mockpatch
 import six
 from six.moves import http_client as httplib
-from tempest_lib import exceptions as lib_exc
 
 from tempest.common import glance_http
 from tempest import exceptions
@@ -56,60 +52,6 @@
                         'getresponse', return_value=resp))
         return resp
 
-    def test_json_request_without_content_type_header_in_response(self):
-        self._set_response_fixture({}, 200, 'fake_response_body')
-        self.assertRaises(lib_exc.InvalidContentType,
-                          self.client.json_request, 'GET', '/images')
-
-    def test_json_request_with_xml_content_type_header_in_request(self):
-        self.assertRaises(lib_exc.InvalidContentType,
-                          self.client.json_request, 'GET', '/images',
-                          headers={'Content-Type': 'application/xml'})
-
-    def test_json_request_with_xml_content_type_header_in_response(self):
-        self._set_response_fixture({'content-type': 'application/xml'},
-                                   200, 'fake_response_body')
-        self.assertRaises(lib_exc.InvalidContentType,
-                          self.client.json_request, 'GET', '/images')
-
-    def test_json_request_with_json_content_type_header_only_in_resp(self):
-        self._set_response_fixture({'content-type': 'application/json'},
-                                   200, 'fake_response_body')
-        resp, body = self.client.json_request('GET', '/images')
-        self.assertEqual(200, resp.status)
-        self.assertEqual('fake_response_body', body)
-
-    def test_json_request_with_json_content_type_header_in_req_and_resp(self):
-        self._set_response_fixture({'content-type': 'application/json'},
-                                   200, 'fake_response_body')
-        resp, body = self.client.json_request('GET', '/images', headers={
-            'Content-Type': 'application/json'})
-        self.assertEqual(200, resp.status)
-        self.assertEqual('fake_response_body', body)
-
-    def test_json_request_fails_to_json_loads(self):
-        self._set_response_fixture({'content-type': 'application/json'},
-                                   200, 'fake_response_body')
-        self.useFixture(mockpatch.PatchObject(json, 'loads',
-                        side_effect=ValueError()))
-        resp, body = self.client.json_request('GET', '/images')
-        self.assertEqual(200, resp.status)
-        self.assertEqual(body, 'fake_response_body')
-
-    def test_json_request_socket_timeout(self):
-        self.useFixture(mockpatch.PatchObject(httplib.HTTPConnection,
-                                              'request',
-                                              side_effect=socket.timeout()))
-        self.assertRaises(exceptions.TimeoutException,
-                          self.client.json_request, 'GET', '/images')
-
-    def test_json_request_endpoint_not_found(self):
-        self.useFixture(mockpatch.PatchObject(httplib.HTTPConnection,
-                                              'request',
-                                              side_effect=socket.gaierror()))
-        self.assertRaises(exceptions.EndpointNotFound,
-                          self.client.json_request, 'GET', '/images')
-
     def test_raw_request(self):
         self._set_response_fixture({}, 200, 'fake_response_body')
         resp, body = self.client.raw_request('GET', '/images')
@@ -141,22 +83,22 @@
         self.assertEqual(call_count - 1, req_body.tell())
 
     def test_get_connection_class_for_https(self):
-        conn_class = self.client.get_connection_class('https')
+        conn_class = self.client._get_connection_class('https')
         self.assertEqual(glance_http.VerifiedHTTPSConnection, conn_class)
 
     def test_get_connection_class_for_http(self):
-        conn_class = (self.client.get_connection_class('http'))
+        conn_class = (self.client._get_connection_class('http'))
         self.assertEqual(httplib.HTTPConnection, conn_class)
 
     def test_get_connection_http(self):
-        self.assertTrue(isinstance(self.client.get_connection(),
+        self.assertTrue(isinstance(self.client._get_connection(),
                                    httplib.HTTPConnection))
 
     def test_get_connection_https(self):
         endpoint = 'https://fake_url.com'
         self.fake_auth.base_url = mock.MagicMock(return_value=endpoint)
         self.client = glance_http.HTTPClient(self.fake_auth, {})
-        self.assertTrue(isinstance(self.client.get_connection(),
+        self.assertTrue(isinstance(self.client._get_connection(),
                                    glance_http.VerifiedHTTPSConnection))
 
     def test_get_connection_url_not_fount(self):
@@ -164,22 +106,22 @@
                                               side_effect=httplib.InvalidURL()
                                               ))
         self.assertRaises(exceptions.EndpointNotFound,
-                          self.client.get_connection)
+                          self.client._get_connection)
 
     def test_get_connection_kwargs_default_for_http(self):
-        kwargs = self.client.get_connection_kwargs('http')
+        kwargs = self.client._get_connection_kwargs('http')
         self.assertEqual(600, kwargs['timeout'])
         self.assertEqual(1, len(kwargs.keys()))
 
     def test_get_connection_kwargs_set_timeout_for_http(self):
-        kwargs = self.client.get_connection_kwargs('http', timeout=10,
-                                                   ca_certs='foo')
+        kwargs = self.client._get_connection_kwargs('http', timeout=10,
+                                                    ca_certs='foo')
         self.assertEqual(10, kwargs['timeout'])
         # nothing more than timeout is evaluated for http connections
         self.assertEqual(1, len(kwargs.keys()))
 
     def test_get_connection_kwargs_default_for_https(self):
-        kwargs = self.client.get_connection_kwargs('https')
+        kwargs = self.client._get_connection_kwargs('https')
         self.assertEqual(600, kwargs['timeout'])
         self.assertEqual(None, kwargs['ca_certs'])
         self.assertEqual(None, kwargs['cert_file'])
@@ -189,12 +131,12 @@
         self.assertEqual(6, len(kwargs.keys()))
 
     def test_get_connection_kwargs_set_params_for_https(self):
-        kwargs = self.client.get_connection_kwargs('https', timeout=10,
-                                                   ca_certs='foo',
-                                                   cert_file='/foo/bar.cert',
-                                                   key_file='/foo/key.pem',
-                                                   insecure=True,
-                                                   ssl_compression=False)
+        kwargs = self.client._get_connection_kwargs('https', timeout=10,
+                                                    ca_certs='foo',
+                                                    cert_file='/foo/bar.cert',
+                                                    key_file='/foo/key.pem',
+                                                    insecure=True,
+                                                    ssl_compression=False)
         self.assertEqual(10, kwargs['timeout'])
         self.assertEqual('foo', kwargs['ca_certs'])
         self.assertEqual('/foo/bar.cert', kwargs['cert_file'])