Add update tests for policies and rules

This patch adds tests for 'update' for both policies and rules. This
completes the CRUD tests and leaves the association/disassociation for
a later patch. Note that deleting a rule isn't tested explicitly
because of a bug with the rule delete logic on the server side. Once
that code is fixed, the test should be added.

to_dict() for policies should also convert any rules inside rule lists
to dicts too, otherwise API layer receives rule object __repr__ strings
instead of actual dicts. This patch introduces a fix to the existing
to_dict() code to properly support policies.

This patch also modifies the base infra to create policies and rules for
admins and not for tenant.

Partially-Implements: blueprint quantum-qos-api
Change-Id: I13870680d7756be9dd020135bc8e91d1c12f728d
Co-Authored-By: Ihar Hrachyshka <ihrachys@redhat.com>
diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py
index b17fa48..bc8eaa2 100644
--- a/neutron/tests/tempest/services/network/json/network_client.py
+++ b/neutron/tests/tempest/services/network/json/network_client.py
@@ -645,6 +645,14 @@
         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 get_qos_policy(self, policy_id):
         uri = '%s/qos/policies/%s' % (self.uri_prefix, policy_id)
         resp, body = self.get(uri)
@@ -681,19 +689,22 @@
         self.expected_success(200, resp.status)
         return service_client.ResponseBody(resp, body)
 
-    def update_bandwidth_limit_rule(self, policy_id, rule_id,
-                                    max_kbps, max_burst_kbps):
+    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': {
-                'max_kbps': max_kbps,
-                'max_burst_kbps': max_burst_kbps}
-            }
+        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)