port test_hypervisor into nova v3 part2

this ports test_hypervisor into nova v3 and
corresponding hypervisor_client

Partially implements blueprint nova-v3-api-tests

Change-Id: I21a846f8fb7d662986eebde1ffd0b6b803a4b574
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index bc44a2e..7ef5466 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -236,6 +236,7 @@
         cls.extensions_client = cls.os.extensions_v3_client
         cls.availability_zone_client = cls.os.availability_zone_v3_client
         cls.interfaces_client = cls.os.interfaces_v3_client
+        cls.hypervisor_client = cls.os.hypervisor_v3_client
 
     @classmethod
     def create_image_from_server(cls, server_id, **kwargs):
@@ -298,3 +299,4 @@
         cls.services_admin_client = cls.os_adm.services_v3_client
         cls.availability_zone_admin_client = \
             cls.os_adm.availability_zone_v3_client
+        cls.hypervisor_admin_client = cls.os_adm.hypervisor_v3_client
diff --git a/tempest/api/compute/v3/admin/test_hypervisor.py b/tempest/api/compute/v3/admin/test_hypervisor.py
index ef4f51f..3da3369 100644
--- a/tempest/api/compute/v3/admin/test_hypervisor.py
+++ b/tempest/api/compute/v3/admin/test_hypervisor.py
@@ -19,7 +19,7 @@
 from tempest.test import attr
 
 
-class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest):
+class HypervisorAdminV3TestJSON(base.BaseV3ComputeAdminTest):
 
     """
     Tests Hypervisors API that require admin privileges
@@ -29,8 +29,8 @@
 
     @classmethod
     def setUpClass(cls):
-        super(HypervisorAdminTestJSON, cls).setUpClass()
-        cls.client = cls.os_adm.hypervisor_client
+        super(HypervisorAdminV3TestJSON, cls).setUpClass()
+        cls.client = cls.hypervisor_admin_client
 
     def _list_hypervisors(self):
         # List of hypervisors
@@ -70,8 +70,8 @@
         hypers = self._list_hypervisors()
         self.assertTrue(len(hypers) > 0)
 
-        hostname = hypers[0]['hypervisor_hostname']
-        resp, hypervisors = self.client.get_hypervisor_servers(hostname)
+        hypervisor_id = hypers[0]['id']
+        resp, hypervisors = self.client.get_hypervisor_servers(hypervisor_id)
         self.assertEqual(200, resp.status)
         self.assertTrue(len(hypervisors) > 0)
 
@@ -101,5 +101,5 @@
         self.assertTrue(len(hypers) > 0)
 
 
-class HypervisorAdminTestXML(HypervisorAdminTestJSON):
+class HypervisorAdminV3TestXML(HypervisorAdminV3TestJSON):
     _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_hypervisor_negative.py b/tempest/api/compute/v3/admin/test_hypervisor_negative.py
index c6455b5..847679e 100644
--- a/tempest/api/compute/v3/admin/test_hypervisor_negative.py
+++ b/tempest/api/compute/v3/admin/test_hypervisor_negative.py
@@ -23,7 +23,7 @@
 from tempest.test import attr
 
 
-class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
+class HypervisorAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
 
     """
     Tests Hypervisors API that require admin privileges
@@ -33,8 +33,8 @@
 
     @classmethod
     def setUpClass(cls):
-        super(HypervisorAdminNegativeTestJSON, cls).setUpClass()
-        cls.client = cls.os_adm.hypervisor_client
+        super(HypervisorAdminNegativeV3TestJSON, cls).setUpClass()
+        cls.client = cls.hypervisor_admin_client
         cls.non_adm_client = cls.hypervisor_client
 
     def _list_hypervisors(self):
@@ -124,10 +124,10 @@
     def test_search_nonexistent_hypervisor(self):
         nonexistent_hypervisor_name = data_utils.rand_name('test_hypervisor')
 
-        self.assertRaises(
-            exceptions.NotFound,
-            self.client.search_hypervisor,
+        resp, hypers = self.client.search_hypervisor(
             nonexistent_hypervisor_name)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(0, len(hypers))
 
     @attr(type=['negative', 'gate'])
     def test_search_hypervisor_with_non_admin_user(self):
@@ -140,5 +140,5 @@
             hypers[0]['hypervisor_hostname'])
 
 
-class HypervisorAdminNegativeTestXML(HypervisorAdminNegativeTestJSON):
+class HypervisorAdminNegativeV3TestXML(HypervisorAdminNegativeV3TestJSON):
     _interface = 'xml'
diff --git a/tempest/clients.py b/tempest/clients.py
index 3c159e1..291b946 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -54,6 +54,8 @@
     AvailabilityZoneV3ClientJSON
 from tempest.services.compute.v3.json.extensions_client import \
     ExtensionsV3ClientJSON
+from tempest.services.compute.v3.json.hypervisor_client import \
+    HypervisorV3ClientJSON
 from tempest.services.compute.v3.json.interfaces_client import \
     InterfacesV3ClientJSON
 from tempest.services.compute.v3.json.servers_client import \
@@ -64,6 +66,8 @@
     AvailabilityZoneV3ClientXML
 from tempest.services.compute.v3.xml.extensions_client import \
     ExtensionsV3ClientXML
+from tempest.services.compute.v3.xml.hypervisor_client import \
+    HypervisorV3ClientXML
 from tempest.services.compute.v3.xml.interfaces_client import \
     InterfacesV3ClientXML
 from tempest.services.compute.v3.xml.servers_client import ServersV3ClientXML
@@ -228,6 +232,7 @@
             self.services_client = ServicesClientXML(*client_args)
             self.tenant_usages_client = TenantUsagesClientXML(*client_args)
             self.policy_client = PolicyClientXML(*client_args)
+            self.hypervisor_v3_client = HypervisorV3ClientXML(*client_args)
             self.hypervisor_client = HypervisorClientXML(*client_args)
             self.token_v3_client = V3TokenClientXML(*client_args)
             self.network_client = NetworkClientXML(*client_args)
@@ -275,6 +280,7 @@
             self.services_client = ServicesClientJSON(*client_args)
             self.tenant_usages_client = TenantUsagesClientJSON(*client_args)
             self.policy_client = PolicyClientJSON(*client_args)
+            self.hypervisor_v3_client = HypervisorV3ClientJSON(*client_args)
             self.hypervisor_client = HypervisorClientJSON(*client_args)
             self.token_v3_client = V3TokenClientJSON(*client_args)
             self.network_client = NetworkClientJSON(*client_args)
diff --git a/tempest/services/compute/v3/json/hypervisor_client.py b/tempest/services/compute/v3/json/hypervisor_client.py
index fba5acb..fa1255a 100644
--- a/tempest/services/compute/v3/json/hypervisor_client.py
+++ b/tempest/services/compute/v3/json/hypervisor_client.py
@@ -20,13 +20,13 @@
 from tempest.common.rest_client import RestClient
 
 
-class HypervisorClientJSON(RestClient):
+class HypervisorV3ClientJSON(RestClient):
 
     def __init__(self, config, username, password, auth_url, tenant_name=None):
-        super(HypervisorClientJSON, self).__init__(config, username,
-                                                   password, auth_url,
-                                                   tenant_name)
-        self.service = self.config.compute.catalog_type
+        super(HypervisorV3ClientJSON, self).__init__(config, username,
+                                                     password, auth_url,
+                                                     tenant_name)
+        self.service = self.config.compute.catalog_v3_type
 
     def get_hypervisor_list(self):
         """List hypervisors information."""
@@ -50,7 +50,7 @@
         """List instances belonging to the specified hypervisor."""
         resp, body = self.get('os-hypervisors/%s/servers' % hyper_name)
         body = json.loads(body)
-        return resp, body['hypervisors']
+        return resp, body['hypervisor']
 
     def get_hypervisor_stats(self):
         """Get hypervisor statistics over all compute nodes."""
@@ -66,6 +66,6 @@
 
     def search_hypervisor(self, hyper_name):
         """Search specified hypervisor."""
-        resp, body = self.get('os-hypervisors/%s/search' % hyper_name)
+        resp, body = self.get('os-hypervisors/search?query=%s' % hyper_name)
         body = json.loads(body)
         return resp, body['hypervisors']
diff --git a/tempest/services/compute/v3/xml/hypervisor_client.py b/tempest/services/compute/v3/xml/hypervisor_client.py
index c10fed9..ce0207d 100644
--- a/tempest/services/compute/v3/xml/hypervisor_client.py
+++ b/tempest/services/compute/v3/xml/hypervisor_client.py
@@ -21,13 +21,13 @@
 from tempest.services.compute.xml.common import xml_to_json
 
 
-class HypervisorClientXML(RestClientXML):
+class HypervisorV3ClientXML(RestClientXML):
 
     def __init__(self, config, username, password, auth_url, tenant_name=None):
-        super(HypervisorClientXML, self).__init__(config, username,
-                                                  password, auth_url,
-                                                  tenant_name)
-        self.service = self.config.compute.catalog_type
+        super(HypervisorV3ClientXML, self).__init__(config, username,
+                                                    password, auth_url,
+                                                    tenant_name)
+        self.service = self.config.compute.catalog_v3_type
 
     def _parse_array(self, node):
         return [xml_to_json(x) for x in node]
@@ -73,7 +73,7 @@
 
     def search_hypervisor(self, hyper_name):
         """Search specified hypervisor."""
-        resp, body = self.get('os-hypervisors/%s/search' % hyper_name,
+        resp, body = self.get('os-hypervisors/search?query=%s' % hyper_name,
                               self.headers)
         hypervisors = self._parse_array(etree.fromstring(body))
         return resp, hypervisors