>From f7b700da9e12b877cdb0d2eb24a3c0978c730ddb Mon Sep 17 00:00:00 2001
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Date: Tue, 29 Sep 2015 20:46:06 +0300
Subject: [PATCH 5/7] intg: Reduce sssd.conf duplication in test_ldap.py

Use a function to generate basic sssd.conf in test_ldap.py to reduce
code duplication.
---
 src/tests/intg/ldap_test.py | 145 ++++++++++++++------------------------------
 1 file changed, 47 insertions(+), 98 deletions(-)

diff --git a/src/tests/intg/ldap_test.py b/src/tests/intg/ldap_test.py
index d68a890..a29f701 100644
--- a/src/tests/intg/ldap_test.py
+++ b/src/tests/intg/ldap_test.py
@@ -91,6 +91,42 @@ def create_ldap_fixture(request, ldap_conn, ent_list = None):
     create_ldap_cleanup(request, ldap_conn, ent_list)
 
 
+def format_basic_conf(ldap_conn, bis, enum):
+    """Format a basic SSSD configuration"""
+    if bis:
+        schema_conf = unindent("""\
+            ldap_schema             = rfc2307bis
+            ldap_group_object_class = groupOfNames
+        """)
+    else:
+        schema_conf = unindent("""\
+            ldap_schema             = rfc2307
+        """)
+    return unindent("""\
+        [sssd]
+        debug_level         = 0xffff
+        domains             = LDAP
+        services            = nss, pam
+
+        [nss]
+        debug_level         = 0xffff
+        memcache_timeout    = 0
+
+        [pam]
+        debug_level         = 0xffff
+
+        [domain/LDAP]
+        ldap_auth_disable_tls_never_use_in_production = true
+        debug_level         = 0xffff
+        enumerate           = {enum}
+        {schema_conf}
+        id_provider         = ldap
+        auth_provider       = ldap
+        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
+        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
+    """).format(**locals())
+
+
 def create_conf_file(contents):
     """Create sssd.conf with specified contents"""
     conf = open(config.CONF_PATH, "w")
@@ -172,31 +208,7 @@ def sanity(request, ldap_conn):
     ent_list.add_group("two_user_group", 2012, ["user1", "user2"])
     create_ldap_fixture(request, ldap_conn, ent_list)
 
-    conf = unindent("""\
-        [sssd]
-        debug_level         = 0xffff
-        domains             = LDAP
-        services            = nss, pam
-
-        [nss]
-        debug_level         = 0xffff
-        memcache_timeout    = 0
-
-        [pam]
-        debug_level         = 0xffff
-
-        [domain/LDAP]
-        ldap_auth_disable_tls_never_use_in_production = true
-        debug_level         = 0xffff
-        enumerate           = true
-        ldap_schema         = rfc2307
-        id_provider         = ldap
-        auth_provider       = ldap
-        sudo_provider       = ldap
-        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
-        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
-    """).format(**locals())
-    create_conf_fixture(request, conf)
+    create_conf_fixture(request, format_basic_conf(ldap_conn, False, True))
     create_sssd_fixture(request)
     return None
 
@@ -206,28 +218,8 @@ def simple(request, ldap_conn):
     ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
     ent_list.add_user('usr\\\\001', 181818, 181818)
     ent_list.add_group("group1", 181818)
-
     create_ldap_fixture(request, ldap_conn, ent_list)
-
-    conf = unindent("""\
-        [sssd]
-        config_file_version = 2
-        domains             = LDAP
-        services            = nss, pam
-
-        [nss]
-
-        [pam]
-
-        [domain/LDAP]
-        ldap_auth_disable_tls_never_use_in_production = true
-        ldap_schema         = rfc2307
-        id_provider         = ldap
-        auth_provider       = ldap
-        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
-        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
-    """).format(**locals())
-    create_conf_fixture(request, conf)
+    create_conf_fixture(request, format_basic_conf(ldap_conn, False, False))
     create_sssd_fixture(request)
     return None
 
@@ -260,33 +252,7 @@ def sanity_bis(request, ldap_conn):
                            [], ["one_user_group1", "one_user_group2"])
 
     create_ldap_fixture(request, ldap_conn, ent_list)
-
-    conf = unindent("""\
-        [sssd]
-        debug_level             = 0xffff
-        domains                 = LDAP
-        services                = nss, pam
-
-        [nss]
-        debug_level             = 0xffff
-        memcache_timeout        = 0
-
-        [pam]
-        debug_level             = 0xffff
-
-        [domain/LDAP]
-        ldap_auth_disable_tls_never_use_in_production = true
-        debug_level             = 0xffff
-        enumerate               = true
-        ldap_schema             = rfc2307bis
-        ldap_group_object_class = groupOfNames
-        id_provider             = ldap
-        auth_provider           = ldap
-        sudo_provider           = ldap
-        ldap_uri                = {ldap_conn.ds_inst.ldap_url}
-        ldap_search_base        = {ldap_conn.ds_inst.base_dn}
-    """).format(**locals())
-    create_conf_fixture(request, conf)
+    create_conf_fixture(request, format_basic_conf(ldap_conn, True, True))
     create_sssd_fixture(request)
     return None
 
@@ -370,31 +336,14 @@ def refresh_after_cleanup_task(request, ldap_conn):
 
     create_ldap_fixture(request, ldap_conn, ent_list)
 
-    conf = unindent("""\
-        [sssd]
-        config_file_version     = 2
-        domains                 = LDAP
-        services                = nss
-
-        [nss]
-        memcache_timeout        = 0
-
-        [domain/LDAP]
-        ldap_auth_disable_tls_never_use_in_production = true
-        debug_level             = 0xffff
-        ldap_schema             = rfc2307bis
-        ldap_group_object_class = groupOfNames
-        id_provider             = ldap
-        auth_provider           = ldap
-        sudo_provider           = ldap
-        ldap_uri                = {ldap_conn.ds_inst.ldap_url}
-        ldap_search_base        = {ldap_conn.ds_inst.base_dn}
-
-        entry_cache_user_timeout = 1
-        entry_cache_group_timeout = 5000
-        ldap_purge_cache_timeout = 3
-
-    """).format(**locals())
+    conf = \
+        format_basic_conf(ldap_conn, True, False) + \
+        unindent("""
+            [domain/LDAP]
+            entry_cache_user_timeout = 1
+            entry_cache_group_timeout = 5000
+            ldap_purge_cache_timeout = 3
+        """).format(**locals())
     create_conf_fixture(request, conf)
     create_sssd_fixture(request)
     return None
-- 
2.5.1

