def test_01_ldap(self):
        """Check the linkDomainToLdap functionality"""
        self.domain1 = Domain.create(
            self.apiclient,
            services=self.services["domain"],
            parentdomainid=self.domain.id)

        self.ldaplink4 = linkDomainToLdap.linkDomainToLdapCmd()
        self.ldaplink4.domainid = self.domain1.id
        self.ldaplink4.accounttype = self.services[
            "configurableData"]["link_ldap_details"]["accounttype"]
        self.ldaplink4.name = self.services[
            "configurableData"]["link_ldap_details"]["name"]
        self.ldaplink4.type = self.services[
            "configurableData"]["link_ldap_details"]["type"]
        if self.services["configurableData"][
            "link_ldap_details"]["admin"] is not None:
            self.ldaplink4.admin = self.services[
                "configurableData"]["link_ldap_details"]["admin"]

        try:
            self.ldaplinkRes4 = self.apiClient.linkDomainToLdap(self.ldaplink4)

        except Exception as e:
            raise Exception(
                "Linking LDAP failed,please check the configuration")

        try:
            self.domain1.delete(self.apiclient)
        except Exception as e:
            raise Exception(
                "Warning: Exception during deletion of domain : %s" % e)
    def setUp(self):
        self.user = self.services["configurableData"]["link_ldap_details"]["linkLdapUsername"]
        self.password = self.services["configurableData"]["link_ldap_details"]["linkLdapPassword"]
        self.delflag1 = 0
        self.delflag2 = 0
        self.delflag3 = 0
        self.delflag4 = 0

        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.cleanup = []

        self.parent_domain = Domain.create(
            self.apiclient,
            services=self.services["domain"],
            parentdomainid=self.domain.id)

        self.ldaplink = linkDomainToLdap.linkDomainToLdapCmd()
        self.ldaplink.domainid = self.parent_domain.id
        self.ldaplink.accounttype = self.services[
            "configurableData"]["link_ldap_details"]["accounttype"]
        self.ldaplink.name = self.services[
            "configurableData"]["link_ldap_details"]["name"]
        self.ldaplink.type = self.services[
            "configurableData"]["link_ldap_details"]["type"]
        if self.services["configurableData"][
            "link_ldap_details"]["admin"] is not None:
            self.ldaplink.admin = self.services[
                "configurableData"]["link_ldap_details"]["admin"]

        if self.ldaplink.domainid == "" or self.ldaplink.accounttype == "" \
                or self.ldaplink.name == "" \
                or self.ldaplink.type == "":
            self.debug(
                "Please rerun the test by providing "
                "values in link_ldap configuration user details")
            self.skipTest(
                "Please rerun the test by providing "
                "proper values in configuration file(link ldap)")
        else:
            self.delflag1 = 1
            self.ldaplinkRes = self.apiClient.linkDomainToLdap(self.ldaplink)
        self.assertEquals(
            self.delflag1,
            1,
            "Linking LDAP failed,please check the configuration")
        loginRes = checklogin(self,
                              self.user, self.password,
                              self.parent_domain.name,
                              method="POST")
        self.debug(loginRes)
        self.assertEquals(loginRes, 1, self.reason)

        lsap_user = Account.list(self.api_client,
                                 domainid=self.parent_domain.id,
                                 name=self.user
                                 )
        self.ldapacctID = lsap_user[0].id
    def test_08_ldap(self):
        """Create different domains and link all of them to LDAP. Check
                        login in each domain --> login should be successful"""
        try:
            loginRes = checklogin(
                self,
                self.user,
                self.password,
                self.parent_domain.name,
                method="POST")
            self.debug(loginRes)
            self.assertEquals(loginRes, 1, self.reason)

            self.domain2 = Domain.create(
                self.apiclient,
                services=self.services["domain"],
                parentdomainid=self.domain.id)

            # here link ldap to domain
            self.ldaplink2 = linkDomainToLdap.linkDomainToLdapCmd()
            self.ldaplink2.domainid = self.domain2.id
            self.ldaplink2.accounttype = self.services[
                "configurableData"]["link_ldap_details"]["accounttype"]
            self.ldaplink2.name = self.services[
                "configurableData"]["link_ldap_details"]["name"]
            self.ldaplink2.type = self.services[
                "configurableData"]["link_ldap_details"]["type"]

            if self.services["configurableData"][
                "link_ldap_details"]["admin"] is not None:
                self.ldaplink2.admin = self.services[
                    "configurableData"]["link_ldap_details"]["admin"]

            if self.ldaplink2.domainid == "" \
                    or self.ldaplink2.accounttype == "" \
                    or self.ldaplink2.name == "" \
                    or self.ldaplink2.type == "":
                self.debug(
                    "Please rerun the test by providing"
                    " values in link_ldap configuration user details")
                self.skipTest(
                    "Please rerun the test by providing "
                    "proper values in configuration file(link ldap)")

            else:
                self.delflag2 = 1
                self.ldaplinkRes2 = self.apiClient.linkDomainToLdap(
                    self.ldaplink2)
            self.assertEquals(
                self.delflag2,
                1,
                "Linking LDAP failed,please check the configuration")

            loginRes = checklogin(
                self,
                self.user,
                self.password,
                self.domain2.name,
                method="POST")
            self.debug(loginRes)
            self.assertEquals(loginRes, 1, self.reason)

            self.domain3 = Domain.create(
                self.apiclient,
                services=self.services["domain"],
                parentdomainid=self.domain.id)
            # here link ldap to domain
            self.ldaplink3 = linkDomainToLdap.linkDomainToLdapCmd()
            self.ldaplink3.domainid = self.domain3.id
            self.ldaplink3.accounttype = self.services[
                "configurableData"]["link_ldap_details"]["accounttype"]
            self.ldaplink3.name = self.services[
                "configurableData"]["link_ldap_details"]["name"]
            self.ldaplink3.type = self.services[
                "configurableData"]["link_ldap_details"]["type"]
            if self.services["configurableData"][
                "link_ldap_details"]["admin"] is not None:
                self.ldaplink3.admin = self.services[
                    "configurableData"]["link_ldap_details"]["admin"]

            if self.ldaplink3.domainid == "" \
                    or self.ldaplink3.accounttype == "" \
                    or self.ldaplink3.name == "" \
                    or self.ldaplink3.type == "":
                self.debug(
                    "Please rerun the test by providing"
                    " values in link_ldap configuration user details")
                self.skipTest(
                    "Please rerun the test by providing "
                    "proper values in configuration file(link ldap)")
            else:
                self.delflag3 = 1
                self.ldaplinkRes3 = self.apiClient.linkDomainToLdap(
                    self.ldaplink3)
            self.assertEquals(
                self.delflag3,
                1,
                "Linking LDAP failed,please check the configuration")
            loginRes = checklogin(
                self,
                self.user,
                self.password,
                self.domain2.name,
                method="POST")
            self.debug(loginRes)
            self.assertEquals(loginRes, 1, self.reason)

        finally:
            try:
                self.domain2.delete(self.apiclient, cleanup=True)
            except Exception as e:
                raise Exception(
                    "Warning: Exception during deletion of domain : %s" % e)

            try:
                self.domain3.delete(self.apiclient, cleanup=True)
            except Exception as e:
                raise Exception(
                    "Warning: Exception during deletion of domain : %s" % e)

        return