Add ou to security service tests

This patch complements I70fd4e0ea7898e85dff59a927b3cb086d5e408ac
by adding tests for ou parameter at security services with new
microversion 2.44.

Depends-On: I70fd4e0ea7898e85dff59a927b3cb086d5e408ac
Change-Id: I77d87c8e6f98054f2f02bc4202c14314ff321964
Partial-Bug: #1696669
diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py
index 4e6c99b..e737cb4 100644
--- a/manila_tempest_tests/config.py
+++ b/manila_tempest_tests/config.py
@@ -30,7 +30,7 @@
                help="The minimum api microversion is configured to be the "
                     "value of the minimum microversion supported by Manila."),
     cfg.StrOpt("max_api_microversion",
-               default="2.42",
+               default="2.44",
                help="The maximum api microversion is configured to be the "
                     "value of the latest microversion supported by Manila."),
     cfg.StrOpt("region",
diff --git a/manila_tempest_tests/services/share/v2/json/shares_client.py b/manila_tempest_tests/services/share/v2/json/shares_client.py
index 115aab3..3f1c8a1 100644
--- a/manila_tempest_tests/services/share/v2/json/shares_client.py
+++ b/manila_tempest_tests/services/share/v2/json/shares_client.py
@@ -1734,3 +1734,54 @@
                            ' the required time (%s s).' %
                            (resource_id, self.build_timeout))
                 raise exceptions.TimeoutException(message)
+
+###############
+
+    def create_security_service(self, ss_type="ldap",
+                                version=LATEST_MICROVERSION, **kwargs):
+        """Creates Security Service.
+
+        :param ss_type: ldap, kerberos, active_directory
+        :param version: microversion string
+        :param kwargs: name, description, dns_ip, server, ou, domain, user,
+        :param kwargs: password
+        """
+        post_body = {"type": ss_type}
+        post_body.update(kwargs)
+        body = json.dumps({"security_service": post_body})
+        resp, body = self.post("security-services", body, version=version)
+        self.expected_success(200, resp.status)
+        return self._parse_resp(body)
+
+    def update_security_service(self, ss_id, version=LATEST_MICROVERSION,
+                                **kwargs):
+        """Updates Security Service.
+
+        :param ss_id: id of security-service entity
+        :param version: microversion string
+        :param kwargs: dns_ip, server, ou, domain, user, password, name,
+        :param kwargs: description
+        :param kwargs: for 'active' status can be changed
+        :param kwargs: only 'name' and 'description' fields
+        """
+        body = json.dumps({"security_service": kwargs})
+        resp, body = self.put("security-services/%s" % ss_id, body,
+                              version=version)
+        self.expected_success(200, resp.status)
+        return self._parse_resp(body)
+
+    def get_security_service(self, ss_id, version=LATEST_MICROVERSION):
+        resp, body = self.get("security-services/%s" % ss_id, version=version)
+        self.expected_success(200, resp.status)
+        return self._parse_resp(body)
+
+    def list_security_services(self, detailed=False, params=None,
+                               version=LATEST_MICROVERSION):
+        uri = "security-services"
+        if detailed:
+            uri += '/detail'
+        if params:
+            uri += "?%s" % urlparse.urlencode(params)
+        resp, body = self.get(uri, version=version)
+        self.expected_success(200, resp.status)
+        return self._parse_resp(body)
diff --git a/manila_tempest_tests/tests/api/base.py b/manila_tempest_tests/tests/api/base.py
index d8bd45a..5fa187a 100644
--- a/manila_tempest_tests/tests/api/base.py
+++ b/manila_tempest_tests/tests/api/base.py
@@ -1030,7 +1030,7 @@
         return data
 
     @classmethod
-    def generate_security_service_data(self):
+    def generate_security_service_data(self, set_ou=False):
         data = {
             "name": data_utils.rand_name("ss-name"),
             "description": data_utils.rand_name("ss-desc"),
@@ -1040,6 +1040,9 @@
             "user": data_utils.rand_name("ss-user"),
             "password": data_utils.rand_name("ss-password"),
         }
+        if set_ou:
+            data["ou"] = data_utils.rand_name("ss-ou")
+
         return data
 
     # Useful assertions
diff --git a/manila_tempest_tests/tests/api/test_security_services.py b/manila_tempest_tests/tests/api/test_security_services.py
index 30cf6a9..78350a0 100644
--- a/manila_tempest_tests/tests/api/test_security_services.py
+++ b/manila_tempest_tests/tests/api/test_security_services.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import ddt
 from oslo_log import log
 import six
 from tempest import config
@@ -20,11 +21,14 @@
 from testtools import testcase as tc
 
 from manila_tempest_tests.tests.api import base
+from manila_tempest_tests import utils
 
 CONF = config.CONF
+LATEST_MICROVERSION = CONF.share.max_api_microversion
 LOG = log.getLogger(__name__)
 
 
+@ddt.ddt
 class SecurityServiceListMixin(object):
 
     @tc.attr(base.TAG_POSITIVE, base.TAG_API)
@@ -39,8 +43,15 @@
         [self.assertIn(key, s_s.keys()) for s_s in listed for key in keys]
 
     @tc.attr(base.TAG_POSITIVE, base.TAG_API)
-    def test_list_security_services_with_detail(self):
-        listed = self.shares_client.list_security_services(detailed=True)
+    @ddt.data(*set(['1.0', '2.42', '2.44', LATEST_MICROVERSION]))
+    def test_list_security_services_with_detail(self, version):
+        with_ou = True if utils.is_microversion_ge(version, '2.44') else False
+        if utils.is_microversion_ge(version, '2.0'):
+            listed = self.shares_v2_client.list_security_services(
+                detailed=True, version=version)
+        else:
+            listed = self.shares_client.list_security_services(detailed=True)
+
         self.assertTrue(any(self.ss_ldap['id'] == ss['id'] for ss in listed))
         self.assertTrue(any(self.ss_kerberos['id'] == ss['id']
                             for ss in listed))
@@ -53,6 +64,9 @@
         ]
         [self.assertIn(key, s_s.keys()) for s_s in listed for key in keys]
 
+        for ss in listed:
+            self.assertEqual(with_ou, 'ou' in ss.keys())
+
     @tc.attr(base.TAG_POSITIVE, base.TAG_API)
     @testtools.skipIf(
         not CONF.share.multitenancy_enabled, "Only for multitenancy.")
@@ -98,6 +112,7 @@
                                 in search_opts.items()))
 
 
+@ddt.ddt
 class SecurityServicesTest(base.BaseSharesTest,
                            SecurityServiceListMixin):
     def setUp(self):
@@ -110,6 +125,8 @@
             'user': 'fake_user',
             'password': 'pass',
         }
+        if utils.is_microversion_ge(CONF.share.max_api_microversion, '2.44'):
+            ss_ldap_data['ou'] = 'OU=fake_unit_1'
         ss_kerberos_data = {
             'name': 'ss_kerberos',
             'dns_ip': '2.2.2.2',
@@ -118,6 +135,8 @@
             'user': 'test_user',
             'password': 'word',
         }
+        if utils.is_microversion_ge(CONF.share.max_api_microversion, '2.44'):
+            ss_kerberos_data['ou'] = 'OU=fake_unit_2'
         self.ss_ldap = self.create_security_service('ldap', **ss_ldap_data)
         self.ss_kerberos = self.create_security_service(
             'kerberos', **ss_kerberos_data)
@@ -133,13 +152,24 @@
             self.shares_client.delete_security_service(ss["id"])
 
     @tc.attr(base.TAG_POSITIVE, base.TAG_API)
-    def test_get_security_service(self):
-        data = self.generate_security_service_data()
-        ss = self.create_security_service(**data)
-        self.assertDictContainsSubset(data, ss)
+    @ddt.data(*set(['1.0', '2.43', '2.44', LATEST_MICROVERSION]))
+    def test_get_security_service(self, version):
+        with_ou = True if utils.is_microversion_ge(version, '2.44') else False
+        data = self.generate_security_service_data(set_ou=with_ou)
 
-        get = self.shares_client.get_security_service(ss["id"])
+        if utils.is_microversion_ge(version, '2.0'):
+            ss = self.create_security_service(
+                client=self.shares_v2_client, version=version, **data)
+            get = self.shares_v2_client.get_security_service(
+                ss["id"], version=version)
+        else:
+            ss = self.create_security_service(**data)
+            get = self.shares_client.get_security_service(ss["id"])
+
+        self.assertDictContainsSubset(data, ss)
+        self.assertEqual(with_ou, 'ou' in ss)
         self.assertDictContainsSubset(data, get)
+        self.assertEqual(with_ou, 'ou' in get)
 
     @tc.attr(base.TAG_POSITIVE, base.TAG_API)
     def test_update_security_service(self):
@@ -155,6 +185,16 @@
         self.assertDictContainsSubset(upd_data, updated)
         self.assertDictContainsSubset(upd_data, get)
 
+        if utils.is_microversion_ge(CONF.share.max_api_microversion, '2.44'):
+            # update again with ou
+            upd_data_ou = self.generate_security_service_data(set_ou=True)
+            updated_ou = self.shares_v2_client.update_security_service(
+                ss["id"], **upd_data_ou)
+
+            get_ou = self.shares_v2_client.get_security_service(ss["id"])
+            self.assertDictContainsSubset(upd_data_ou, updated_ou)
+            self.assertDictContainsSubset(upd_data_ou, get_ou)
+
     @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipIf(
         not CONF.share.multitenancy_enabled, "Only for multitenancy.")