Merge remote-tracking branch 'origin/master' into merge-branch

Change-Id: I9c29ad9564671ae5a2db35835bc4a30e75482cb2
diff --git a/neutron/tests/tempest/common/glance_http.py b/neutron/tests/tempest/common/glance_http.py
index 0a6f985..3d8c8aa 100644
--- a/neutron/tests/tempest/common/glance_http.py
+++ b/neutron/tests/tempest/common/glance_http.py
@@ -17,7 +17,6 @@
 
 import copy
 import hashlib
-import json
 import posixpath
 import re
 import socket
@@ -28,6 +27,7 @@
 
 import OpenSSL
 from oslo_log import log as logging
+from oslo_serialization import jsonutils as json
 from six import moves
 from six.moves import http_client as httplib
 from tempest_lib import exceptions as lib_exc
diff --git a/neutron/tests/tempest/config.py b/neutron/tests/tempest/config.py
index c459d76..200b247 100644
--- a/neutron/tests/tempest/config.py
+++ b/neutron/tests/tempest/config.py
@@ -15,7 +15,6 @@
 
 from __future__ import print_function
 
-import logging as std_logging
 import os
 
 from oslo_config import cfg
@@ -1191,7 +1190,7 @@
         register_opts()
         self._set_attrs()
         if parse_conf:
-            cfg.CONF.log_opt_values(LOG, std_logging.DEBUG)
+            cfg.CONF.log_opt_values(LOG, logging.DEBUG)
 
 
 class TempestConfigProxy(object):
@@ -1199,15 +1198,15 @@
     _path = None
 
     _extra_log_defaults = [
-        ('keystoneclient.session', std_logging.INFO),
-        ('paramiko.transport', std_logging.INFO),
-        ('requests.packages.urllib3.connectionpool', std_logging.WARN),
+        ('keystoneclient.session', logging.INFO),
+        ('paramiko.transport', logging.INFO),
+        ('requests.packages.urllib3.connectionpool', logging.WARN),
     ]
 
     def _fix_log_levels(self):
         """Tweak the oslo log defaults."""
         for name, level in self._extra_log_defaults:
-            std_logging.getLogger(name).setLevel(level)
+            logging.getLogger(name).logger.setLevel(level)
 
     def __getattr__(self, attr):
         if not self._config:
diff --git a/neutron/tests/tempest/services/identity/v2/json/identity_client.py b/neutron/tests/tempest/services/identity/v2/json/identity_client.py
index 7efda1f..46e8f87 100644
--- a/neutron/tests/tempest/services/identity/v2/json/identity_client.py
+++ b/neutron/tests/tempest/services/identity/v2/json/identity_client.py
@@ -10,7 +10,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 from tempest_lib import exceptions as lib_exc
 
 from neutron.tests.tempest.common import service_client
diff --git a/neutron/tests/tempest/services/identity/v2/json/token_client.py b/neutron/tests/tempest/services/identity/v2/json/token_client.py
index 51d9db0..e8b33ea 100644
--- a/neutron/tests/tempest/services/identity/v2/json/token_client.py
+++ b/neutron/tests/tempest/services/identity/v2/json/token_client.py
@@ -12,7 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 from tempest_lib.common import rest_client
 from tempest_lib import exceptions as lib_exc
 
diff --git a/neutron/tests/tempest/services/identity/v3/json/credentials_client.py b/neutron/tests/tempest/services/identity/v3/json/credentials_client.py
index 4300c0f..07e230a 100644
--- a/neutron/tests/tempest/services/identity/v3/json/credentials_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/credentials_client.py
@@ -13,7 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 
 from neutron.tests.tempest.common import service_client
 
diff --git a/neutron/tests/tempest/services/identity/v3/json/endpoints_client.py b/neutron/tests/tempest/services/identity/v3/json/endpoints_client.py
index b60dd26..27ac3e5 100644
--- a/neutron/tests/tempest/services/identity/v3/json/endpoints_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/endpoints_client.py
@@ -13,7 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 
 from neutron.tests.tempest.common import service_client
 
diff --git a/neutron/tests/tempest/services/identity/v3/json/identity_client.py b/neutron/tests/tempest/services/identity/v3/json/identity_client.py
index a7db46a..a090acf 100644
--- a/neutron/tests/tempest/services/identity/v3/json/identity_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/identity_client.py
@@ -13,8 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
-
+from oslo_serialization import jsonutils as json
 from six.moves.urllib import parse
 
 from neutron.tests.tempest.common import service_client
diff --git a/neutron/tests/tempest/services/identity/v3/json/policy_client.py b/neutron/tests/tempest/services/identity/v3/json/policy_client.py
index 2e44185..2d247af 100644
--- a/neutron/tests/tempest/services/identity/v3/json/policy_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/policy_client.py
@@ -13,7 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 
 from neutron.tests.tempest.common import service_client
 
diff --git a/neutron/tests/tempest/services/identity/v3/json/region_client.py b/neutron/tests/tempest/services/identity/v3/json/region_client.py
index d2fa53b..0effae8 100644
--- a/neutron/tests/tempest/services/identity/v3/json/region_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/region_client.py
@@ -13,8 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
-
+from oslo_serialization import jsonutils as json
 from six.moves.urllib import parse
 
 from neutron.tests.tempest.common import service_client
diff --git a/neutron/tests/tempest/services/identity/v3/json/service_client.py b/neutron/tests/tempest/services/identity/v3/json/service_client.py
index 529693e..75a5cf8 100644
--- a/neutron/tests/tempest/services/identity/v3/json/service_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/service_client.py
@@ -13,7 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 
 from neutron.tests.tempest.common import service_client
 
diff --git a/neutron/tests/tempest/services/identity/v3/json/token_client.py b/neutron/tests/tempest/services/identity/v3/json/token_client.py
index c60b24c..77ecf84 100644
--- a/neutron/tests/tempest/services/identity/v3/json/token_client.py
+++ b/neutron/tests/tempest/services/identity/v3/json/token_client.py
@@ -12,7 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
+from oslo_serialization import jsonutils as json
 from tempest_lib.common import rest_client
 from tempest_lib import exceptions as lib_exc
 
diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py
index 4958bc5..25400ca 100644
--- a/neutron/tests/tempest/services/network/json/network_client.py
+++ b/neutron/tests/tempest/services/network/json/network_client.py
@@ -10,9 +10,11 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import json
 import time
+import urllib
 
+
+from oslo_serialization import jsonutils as json
 from six.moves.urllib import parse
 from tempest_lib.common.utils import misc
 from tempest_lib import exceptions as lib_exc
@@ -65,7 +67,11 @@
             'metering_label_rules': 'metering',
             'firewall_rules': 'fw',
             'firewall_policies': 'fw',
-            'firewalls': 'fw'
+            'firewalls': 'fw',
+            'policies': 'qos',
+            'bandwidth_limit_rules': 'qos',
+            'rule_types': 'qos',
+            'rbac-policies': '',
         }
         service_prefix = service_resource_prefix_map.get(
             plural_name)
@@ -90,7 +96,9 @@
             'ikepolicy': 'ikepolicies',
             'ipsec_site_connection': 'ipsec-site-connections',
             'quotas': 'quotas',
-            'firewall_policy': 'firewall_policies'
+            'firewall_policy': 'firewall_policies',
+            'qos_policy': 'policies',
+            'rbac_policy': 'rbac_policies',
         }
         return resource_plural_map.get(resource_name, resource_name + 's')
 
@@ -620,3 +628,88 @@
         self.expected_success(200, resp.status)
         body = json.loads(body)
         return service_client.ResponseBody(resp, body)
+
+    def list_qos_policies(self, **filters):
+        if filters:
+            uri = '%s/qos/policies?%s' % (self.uri_prefix,
+                                          urllib.urlencode(filters))
+        else:
+            uri = '%s/qos/policies' % self.uri_prefix
+        resp, body = self.get(uri)
+        self.expected_success(200, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
+
+    def create_qos_policy(self, name, description, shared, tenant_id=None):
+        uri = '%s/qos/policies' % self.uri_prefix
+        post_data = {'policy': {
+                'name': name,
+                'description': description,
+                'shared': shared
+            }}
+        if tenant_id is not None:
+            post_data['policy']['tenant_id'] = tenant_id
+        resp, body = self.post(uri, self.serialize(post_data))
+        body = self.deserialize_single(body)
+        self.expected_success(201, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def update_qos_policy(self, policy_id, **kwargs):
+        uri = '%s/qos/policies/%s' % (self.uri_prefix, policy_id)
+        post_data = self.serialize({'policy': kwargs})
+        resp, body = self.put(uri, post_data)
+        body = self.deserialize_single(body)
+        self.expected_success(200, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def create_bandwidth_limit_rule(self, policy_id, max_kbps, max_burst_kbps):
+        uri = '%s/qos/policies/%s/bandwidth_limit_rules' % (
+            self.uri_prefix, policy_id)
+        post_data = self.serialize(
+            {'bandwidth_limit_rule': {
+                'max_kbps': max_kbps,
+                'max_burst_kbps': max_burst_kbps}
+            })
+        resp, body = self.post(uri, post_data)
+        self.expected_success(201, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
+
+    def list_bandwidth_limit_rules(self, policy_id):
+        uri = '%s/qos/policies/%s/bandwidth_limit_rules' % (
+            self.uri_prefix, policy_id)
+        resp, body = self.get(uri)
+        body = self.deserialize_single(body)
+        self.expected_success(200, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def show_bandwidth_limit_rule(self, policy_id, rule_id):
+        uri = '%s/qos/policies/%s/bandwidth_limit_rules/%s' % (
+            self.uri_prefix, policy_id, rule_id)
+        resp, body = self.get(uri)
+        body = self.deserialize_single(body)
+        self.expected_success(200, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def update_bandwidth_limit_rule(self, policy_id, rule_id, **kwargs):
+        uri = '%s/qos/policies/%s/bandwidth_limit_rules/%s' % (
+            self.uri_prefix, policy_id, rule_id)
+        post_data = {'bandwidth_limit_rule': kwargs}
+        resp, body = self.put(uri, json.dumps(post_data))
+        body = self.deserialize_single(body)
+        self.expected_success(200, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def delete_bandwidth_limit_rule(self, policy_id, rule_id):
+        uri = '%s/qos/policies/%s/bandwidth_limit_rules/%s' % (
+            self.uri_prefix, policy_id, rule_id)
+        resp, body = self.delete(uri)
+        self.expected_success(204, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def list_qos_rule_types(self):
+        uri = '%s/qos/rule-types' % self.uri_prefix
+        resp, body = self.get(uri)
+        self.expected_success(200, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
diff --git a/neutron/tests/tempest/test.py b/neutron/tests/tempest/test.py
index d95174b..3abf826 100644
--- a/neutron/tests/tempest/test.py
+++ b/neutron/tests/tempest/test.py
@@ -15,7 +15,6 @@
 
 import atexit
 import functools
-import json
 import os
 import re
 import sys
@@ -24,6 +23,7 @@
 
 import fixtures
 from oslo_log import log as logging
+from oslo_serialization import jsonutils as json
 from oslo_utils import importutils
 import six
 from six.moves.urllib import parse