Add ComputeClient for cleanup

In compute clients, there is a lot of duplicated code for setting
CONF. This patch adds ComputeClient for removing them.

Change-Id: I47908c426177be301bb9b963224c6a6afbb24ed1
diff --git a/tempest/services/compute/json/agents_client.py b/tempest/services/compute/json/agents_client.py
index 5b76a56..eacd367 100644
--- a/tempest/services/compute/json/agents_client.py
+++ b/tempest/services/compute/json/agents_client.py
@@ -17,21 +17,14 @@
 
 from tempest.api_schema.response.compute import agents as common_schema
 from tempest.api_schema.response.compute.v2 import agents as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class AgentsClientJSON(rest_client.RestClient):
+class AgentsClientJSON(base.ComputeClient):
     """
     Tests Agents API
     """
 
-    def __init__(self, auth_provider):
-        super(AgentsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
-
     def list_agents(self, params=None):
         """List all agent builds."""
         url = 'os-agents'
diff --git a/tempest/services/compute/json/aggregates_client.py b/tempest/services/compute/json/aggregates_client.py
index 09927d3..1539259 100644
--- a/tempest/services/compute/json/aggregates_client.py
+++ b/tempest/services/compute/json/aggregates_client.py
@@ -17,18 +17,11 @@
 
 from tempest.api_schema.response.compute import aggregates as schema
 from tempest.api_schema.response.compute.v2 import aggregates as v2_schema
-from tempest.common import rest_client
-from tempest import config
 from tempest import exceptions
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class AggregatesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(AggregatesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class AggregatesClientJSON(base.ComputeClient):
 
     def list_aggregates(self):
         """Get aggregate list."""
diff --git a/tempest/services/compute/json/availability_zone_client.py b/tempest/services/compute/json/availability_zone_client.py
index 00f8330..b8bda68 100644
--- a/tempest/services/compute/json/availability_zone_client.py
+++ b/tempest/services/compute/json/availability_zone_client.py
@@ -16,18 +16,10 @@
 import json
 
 from tempest.api_schema.response.compute.v2 import availability_zone as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class AvailabilityZoneClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(AvailabilityZoneClientJSON, self).__init__(
-            auth_provider)
-        self.service = CONF.compute.catalog_type
+class AvailabilityZoneClientJSON(base.ComputeClient):
 
     def get_availability_zone_list(self):
         resp, body = self.get('os-availability-zone')
diff --git a/tempest/services/compute/json/base.py b/tempest/services/compute/json/base.py
new file mode 100644
index 0000000..b712452
--- /dev/null
+++ b/tempest/services/compute/json/base.py
@@ -0,0 +1,36 @@
+# 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.
+
+from tempest.common import rest_client
+from tempest import config
+
+CONF = config.CONF
+
+
+class ComputeClient(rest_client.RestClient):
+    """
+    Base compute client class
+    """
+
+    def __init__(self, auth_provider,
+                 build_interval=None, build_timeout=None):
+        if build_interval is None:
+            build_interval = CONF.compute.build_interval
+        if build_timeout is None:
+            build_timeout = CONF.compute.build_timeout
+
+        super(ComputeClient, self).__init__(auth_provider)
+        self.service = CONF.compute.catalog_type
+        self.build_interval = build_interval
+        self.build_timeout = build_timeout
diff --git a/tempest/services/compute/json/certificates_client.py b/tempest/services/compute/json/certificates_client.py
index 356ded2..123f0b9 100644
--- a/tempest/services/compute/json/certificates_client.py
+++ b/tempest/services/compute/json/certificates_client.py
@@ -17,17 +17,10 @@
 
 from tempest.api_schema.response.compute import certificates as schema
 from tempest.api_schema.response.compute.v2 import certificates as v2schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class CertificatesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(CertificatesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class CertificatesClientJSON(base.ComputeClient):
 
     def get_certificate(self, id):
         url = "os-certificates/%s" % (id)
diff --git a/tempest/services/compute/json/extensions_client.py b/tempest/services/compute/json/extensions_client.py
index 41d1c4e..69ad7c0 100644
--- a/tempest/services/compute/json/extensions_client.py
+++ b/tempest/services/compute/json/extensions_client.py
@@ -16,17 +16,10 @@
 import json
 
 from tempest.api_schema.response.compute.v2 import extensions as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class ExtensionsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(ExtensionsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class ExtensionsClientJSON(base.ComputeClient):
 
     def list_extensions(self):
         url = 'extensions'
diff --git a/tempest/services/compute/json/fixed_ips_client.py b/tempest/services/compute/json/fixed_ips_client.py
index 5903334..8fd24b6 100644
--- a/tempest/services/compute/json/fixed_ips_client.py
+++ b/tempest/services/compute/json/fixed_ips_client.py
@@ -16,17 +16,10 @@
 import json
 
 from tempest.api_schema.response.compute.v2 import fixed_ips as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class FixedIPsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(FixedIPsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class FixedIPsClientJSON(base.ComputeClient):
 
     def get_fixed_ip_details(self, fixed_ip):
         url = "os-fixed-ips/%s" % (fixed_ip)
diff --git a/tempest/services/compute/json/flavors_client.py b/tempest/services/compute/json/flavors_client.py
index 8faf8a7..6276d3c 100644
--- a/tempest/services/compute/json/flavors_client.py
+++ b/tempest/services/compute/json/flavors_client.py
@@ -21,17 +21,10 @@
 from tempest.api_schema.response.compute import flavors_extra_specs \
     as schema_extra_specs
 from tempest.api_schema.response.compute.v2 import flavors as v2schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class FlavorsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(FlavorsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class FlavorsClientJSON(base.ComputeClient):
 
     def list_flavors(self, params=None):
         url = 'flavors'
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index 0ed1720..788b4d2 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -17,17 +17,11 @@
 import urllib
 
 from tempest.api_schema.response.compute.v2 import floating_ips as schema
-from tempest.common import rest_client
-from tempest import config
 from tempest import exceptions
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class FloatingIPsClientJSON(rest_client.RestClient):
-    def __init__(self, auth_provider):
-        super(FloatingIPsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class FloatingIPsClientJSON(base.ComputeClient):
 
     def list_floating_ips(self, params=None):
         """Returns a list of all floating IPs filtered by any parameters."""
diff --git a/tempest/services/compute/json/hosts_client.py b/tempest/services/compute/json/hosts_client.py
index 8644173..5d306f9 100644
--- a/tempest/services/compute/json/hosts_client.py
+++ b/tempest/services/compute/json/hosts_client.py
@@ -17,17 +17,10 @@
 
 from tempest.api_schema.response.compute import hosts as schema
 from tempest.api_schema.response.compute.v2 import hosts as v2_schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class HostsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(HostsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class HostsClientJSON(base.ComputeClient):
 
     def list_hosts(self, params=None):
         """Lists all hosts."""
diff --git a/tempest/services/compute/json/hypervisor_client.py b/tempest/services/compute/json/hypervisor_client.py
index 8eacf61..52b50c8 100644
--- a/tempest/services/compute/json/hypervisor_client.py
+++ b/tempest/services/compute/json/hypervisor_client.py
@@ -17,17 +17,10 @@
 
 from tempest.api_schema.response.compute import hypervisors as common_schema
 from tempest.api_schema.response.compute.v2 import hypervisors as v2schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class HypervisorClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(HypervisorClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class HypervisorClientJSON(base.ComputeClient):
 
     def get_hypervisor_list(self):
         """List hypervisors information."""
diff --git a/tempest/services/compute/json/images_client.py b/tempest/services/compute/json/images_client.py
index 079a91e..a4cfe57 100644
--- a/tempest/services/compute/json/images_client.py
+++ b/tempest/services/compute/json/images_client.py
@@ -17,21 +17,12 @@
 import urllib
 
 from tempest.api_schema.response.compute.v2 import images as schema
-from tempest.common import rest_client
 from tempest.common import waiters
-from tempest import config
 from tempest import exceptions
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class ImagesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(ImagesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
-        self.build_interval = CONF.compute.build_interval
-        self.build_timeout = CONF.compute.build_timeout
+class ImagesClientJSON(base.ComputeClient):
 
     def create_image(self, server_id, name, meta=None):
         """Creates an image of the original server."""
diff --git a/tempest/services/compute/json/instance_usage_audit_log_client.py b/tempest/services/compute/json/instance_usage_audit_log_client.py
index 4b0362b..f79c3de 100644
--- a/tempest/services/compute/json/instance_usage_audit_log_client.py
+++ b/tempest/services/compute/json/instance_usage_audit_log_client.py
@@ -17,18 +17,10 @@
 
 from tempest.api_schema.response.compute.v2 import instance_usage_audit_logs \
     as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class InstanceUsagesAuditLogClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(InstanceUsagesAuditLogClientJSON, self).__init__(
-            auth_provider)
-        self.service = CONF.compute.catalog_type
+class InstanceUsagesAuditLogClientJSON(base.ComputeClient):
 
     def list_instance_usage_audit_logs(self):
         url = 'os-instance_usage_audit_log'
diff --git a/tempest/services/compute/json/interfaces_client.py b/tempest/services/compute/json/interfaces_client.py
index 620ed68..f1e2660 100644
--- a/tempest/services/compute/json/interfaces_client.py
+++ b/tempest/services/compute/json/interfaces_client.py
@@ -19,18 +19,11 @@
 from tempest.api_schema.response.compute import interfaces as common_schema
 from tempest.api_schema.response.compute import servers as servers_schema
 from tempest.api_schema.response.compute.v2 import interfaces as schema
-from tempest.common import rest_client
-from tempest import config
 from tempest import exceptions
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class InterfacesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(InterfacesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class InterfacesClientJSON(base.ComputeClient):
 
     def list_interfaces(self, server):
         resp, body = self.get('servers/%s/os-interface' % server)
diff --git a/tempest/services/compute/json/keypairs_client.py b/tempest/services/compute/json/keypairs_client.py
index 31c42a5..c4406f5 100644
--- a/tempest/services/compute/json/keypairs_client.py
+++ b/tempest/services/compute/json/keypairs_client.py
@@ -17,17 +17,10 @@
 
 from tempest.api_schema.response.compute import keypairs as common_schema
 from tempest.api_schema.response.compute.v2 import keypairs as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class KeyPairsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(KeyPairsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class KeyPairsClientJSON(base.ComputeClient):
 
     def list_keypairs(self):
         resp, body = self.get("os-keypairs")
diff --git a/tempest/services/compute/json/limits_client.py b/tempest/services/compute/json/limits_client.py
index 81c602b..66a0649 100644
--- a/tempest/services/compute/json/limits_client.py
+++ b/tempest/services/compute/json/limits_client.py
@@ -16,17 +16,10 @@
 import json
 
 from tempest.api_schema.response.compute.v2 import limits as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class LimitsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(LimitsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class LimitsClientJSON(base.ComputeClient):
 
     def get_absolute_limits(self):
         resp, body = self.get("limits")
diff --git a/tempest/services/compute/json/migrations_client.py b/tempest/services/compute/json/migrations_client.py
index f4abbb2..de183f1 100644
--- a/tempest/services/compute/json/migrations_client.py
+++ b/tempest/services/compute/json/migrations_client.py
@@ -16,17 +16,10 @@
 import urllib
 
 from tempest.api_schema.response.compute import migrations as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class MigrationsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(MigrationsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class MigrationsClientJSON(base.ComputeClient):
 
     def list_migrations(self, params=None):
         """Lists all migrations."""
diff --git a/tempest/services/compute/json/networks_client.py b/tempest/services/compute/json/networks_client.py
index 40eb1a6..5a2744d 100644
--- a/tempest/services/compute/json/networks_client.py
+++ b/tempest/services/compute/json/networks_client.py
@@ -15,17 +15,10 @@
 
 import json
 
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class NetworksClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(NetworksClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class NetworksClientJSON(base.ComputeClient):
 
     def list_networks(self):
         resp, body = self.get("os-networks")
diff --git a/tempest/services/compute/json/quotas_client.py b/tempest/services/compute/json/quotas_client.py
index b691529..0fee57a 100644
--- a/tempest/services/compute/json/quotas_client.py
+++ b/tempest/services/compute/json/quotas_client.py
@@ -18,17 +18,10 @@
 from tempest.api_schema.response.compute.v2\
     import quota_classes as classes_schema
 from tempest.api_schema.response.compute.v2 import quotas as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class QuotasClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(QuotasClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class QuotasClientJSON(base.ComputeClient):
 
     def get_quota_set(self, tenant_id, user_id=None):
         """List the quota set for a tenant."""
@@ -122,11 +115,7 @@
         return resp, body
 
 
-class QuotaClassesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(QuotaClassesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class QuotaClassesClientJSON(base.ComputeClient):
 
     def get_quota_class_set(self, quota_class_id):
         """List the quota class set for a quota class."""
diff --git a/tempest/services/compute/json/security_group_default_rules_client.py b/tempest/services/compute/json/security_group_default_rules_client.py
index 7743f9c..efaf329 100644
--- a/tempest/services/compute/json/security_group_default_rules_client.py
+++ b/tempest/services/compute/json/security_group_default_rules_client.py
@@ -17,18 +17,10 @@
 
 from tempest.api_schema.response.compute.v2 import \
     security_group_default_rule as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class SecurityGroupDefaultRulesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(SecurityGroupDefaultRulesClientJSON,
-              self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class SecurityGroupDefaultRulesClientJSON(base.ComputeClient):
 
     def create_security_default_group_rule(self, ip_protocol, from_port,
                                            to_port, **kwargs):
diff --git a/tempest/services/compute/json/security_groups_client.py b/tempest/services/compute/json/security_groups_client.py
index 733a50b..a301a0f 100644
--- a/tempest/services/compute/json/security_groups_client.py
+++ b/tempest/services/compute/json/security_groups_client.py
@@ -17,18 +17,11 @@
 import urllib
 
 from tempest.api_schema.response.compute.v2 import security_groups as schema
-from tempest.common import rest_client
-from tempest import config
 from tempest import exceptions
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class SecurityGroupsClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(SecurityGroupsClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class SecurityGroupsClientJSON(base.ComputeClient):
 
     def list_security_groups(self, params=None):
         """List all security groups for a user."""
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index 4268b1a..400f9a7 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -20,20 +20,15 @@
 
 from tempest.api_schema.response.compute import servers as common_schema
 from tempest.api_schema.response.compute.v2 import servers as schema
-from tempest.common import rest_client
 from tempest.common import waiters
 from tempest import config
 from tempest import exceptions
+from tempest.services.compute.json import base
 
 CONF = config.CONF
 
 
-class ServersClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(ServersClientJSON, self).__init__(auth_provider)
-
-        self.service = CONF.compute.catalog_type
+class ServersClientJSON(base.ComputeClient):
 
     def create_server(self, name, image_ref, flavor_ref, **kwargs):
         """
diff --git a/tempest/services/compute/json/services_client.py b/tempest/services/compute/json/services_client.py
index e56263c..8d73c37 100644
--- a/tempest/services/compute/json/services_client.py
+++ b/tempest/services/compute/json/services_client.py
@@ -18,17 +18,10 @@
 import urllib
 
 from tempest.api_schema.response.compute import services as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class ServicesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(ServicesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class ServicesClientJSON(base.ComputeClient):
 
     def list_services(self, params=None):
         url = 'os-services'
diff --git a/tempest/services/compute/json/tenant_usages_client.py b/tempest/services/compute/json/tenant_usages_client.py
index a0b9b4a..eac23bb 100644
--- a/tempest/services/compute/json/tenant_usages_client.py
+++ b/tempest/services/compute/json/tenant_usages_client.py
@@ -17,17 +17,10 @@
 import urllib
 
 from tempest.api_schema.response.compute.v2 import tenant_usages as schema
-from tempest.common import rest_client
-from tempest import config
-
-CONF = config.CONF
+from tempest.services.compute.json import base
 
 
-class TenantUsagesClientJSON(rest_client.RestClient):
-
-    def __init__(self, auth_provider):
-        super(TenantUsagesClientJSON, self).__init__(auth_provider)
-        self.service = CONF.compute.catalog_type
+class TenantUsagesClientJSON(base.ComputeClient):
 
     def list_tenant_usages(self, params=None):
         url = 'os-simple-tenant-usage'
diff --git a/tempest/services/compute/json/volumes_extensions_client.py b/tempest/services/compute/json/volumes_extensions_client.py
index afa6937..69b9bea 100644
--- a/tempest/services/compute/json/volumes_extensions_client.py
+++ b/tempest/services/compute/json/volumes_extensions_client.py
@@ -18,21 +18,20 @@
 import urllib
 
 from tempest.api_schema.response.compute.v2 import volumes as schema
-from tempest.common import rest_client
 from tempest import config
 from tempest import exceptions
+from tempest.services.compute.json import base
 
 CONF = config.CONF
 
 
-class VolumesExtensionsClientJSON(rest_client.RestClient):
+class VolumesExtensionsClientJSON(base.ComputeClient):
 
     def __init__(self, auth_provider):
         super(VolumesExtensionsClientJSON, self).__init__(
-            auth_provider)
-        self.service = CONF.compute.catalog_type
-        self.build_interval = CONF.volume.build_interval
-        self.build_timeout = CONF.volume.build_timeout
+            auth_provider,
+            build_interval=CONF.volume.build_interval,
+            build_timeout=CONF.volume.build_timeout)
 
     def list_volumes(self, params=None):
         """List all the volumes created."""