Refactor share metadata tests

1) Use the shares_v2_client to make metadata API requests.
This allows us to test v1 proxies as well where appropriate,
and actually test the supported version of the API instead
of the deprecated version

2) Verify key in GET /v2/shares/<share>/metadata/{key} API

the client's _parse_body helper strips out the top
level key allowing us to miss bugs associated with
any key changes from the server [1]. Allow for opt-in
verification of the key and add this verification
to the affected API.

[1] https://bugs.launchpad.net/manila/+bug/1968069

Depends-On: Ib5a62599b84ba55617071f8bcd8e2a1a11b2537b
Change-Id: I7b1af957f08328c642a74ff123deb78e193bbe3a
Related-Bug: #1968069
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
diff --git a/manila_tempest_tests/utils.py b/manila_tempest_tests/utils.py
index 5ecfb36..29d6096 100644
--- a/manila_tempest_tests/utils.py
+++ b/manila_tempest_tests/utils.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 from collections import OrderedDict
+import json
 import random
 import re
 
@@ -225,3 +226,43 @@
         headers = EXPERIMENTAL
         extra_headers = True
     return headers, extra_headers
+
+
+def _parse_resp(body, verify_top_key=None):
+    try:
+        body = json.loads(body)
+    except ValueError:
+        return body
+
+    # We assume, that if the first value of the deserialized body's
+    # item set is a dict or a list, that we just return the first value
+    # of deserialized body.
+    # Essentially "cutting out" the first placeholder element in a body
+    # that looks like this:
+    #
+    #  {
+    #    "users": [
+    #      ...
+    #    ]
+    #  }
+    try:
+        # Ensure there are not more than one top-level keys
+        # NOTE(freerunner): Ensure, that JSON is not nullable to
+        # to prevent StopIteration Exception
+        if not hasattr(body, "keys") or len(body.keys()) != 1:
+            return body
+        # Just return the "wrapped" element
+        first_key, first_item = tuple(body.items())[0]
+        if isinstance(first_item, (dict, list)):
+            if verify_top_key is not None:
+                assert_msg = (
+                    "The expected top level key is '%(top_key)s' but we "
+                    "found '%(actual_key)s'." % {
+                        'top_key': verify_top_key,
+                        'actual_key': first_key
+                    })
+                assert verify_top_key == first_key, assert_msg
+            return first_item
+    except (ValueError, IndexError):
+        pass
+    return body