Github user remibergsma commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/919#discussion_r41707291 --- Diff: test/integration/component/test_ldap_autoImport.py --- @@ -0,0 +1,663 @@ + +from marvin.cloudstackTestCase import cloudstackTestCase +#from marvin.cloudstackTestCase import * +from marvin.cloudstackAPI import (updateConfiguration, + createAccount, + deleteAccount, + addLdapConfiguration, + linkDomainToLdap, #temujin + deleteLdapConfiguration, createDomain, deleteDomain, lockAccount, listAccounts, + disableAccount) +from marvin.cloudstackAPI import login +from marvin.lib.utils import cleanup_resources +from nose.plugins.attrib import attr +import telnetlib +from ddt import ddt, data + + +class1 = 0 + + +def addLdapConfiguration1(cls, ldapConfiguration): + """ + + :param ldapConfiguration + + """ + cls.chkConfig = checkLdapConfiguration(cls, ldapConfiguration) + if not cls.chkConfig: + return 0 + + # Setup Global settings + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.basedn" + updateConfigurationCmd.value = ldapConfiguration['basedn'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.bind.password" + updateConfigurationCmd.value = ldapConfiguration['bindpassword'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.bind.principal" + updateConfigurationCmd.value = ldapConfiguration['principal'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.email.attribute" + updateConfigurationCmd.value = ldapConfiguration['emailAttribute'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.user.object" + updateConfigurationCmd.value = ldapConfiguration['userObject'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() + updateConfigurationCmd.name = "ldap.username.attribute" + updateConfigurationCmd.value = ldapConfiguration['usernameAttribute'] + updateConfigurationResponse = cls.apiClient.updateConfiguration( + updateConfigurationCmd) + cls.debug( + "updated the parameter %s with value %s" % + (updateConfigurationResponse.name, + updateConfigurationResponse.value)) + + cls.debug("start addLdapConfiguration test") + + ldapServer = addLdapConfiguration.addLdapConfigurationCmd() + ldapServer.hostname = ldapConfiguration['hostname'] + ldapServer.port = ldapConfiguration['port'] + + cls.debug("calling addLdapConfiguration API command") + try: + cls.apiClient.addLdapConfiguration(ldapServer) + cls.debug("addLdapConfiguration was successful") + return 1 + except Exception as e: + cls.debug("addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e) + cls.reason = "addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e + return 1 + + +def checkLdapConfiguration(cls, ldapConfiguration): + """" + This function checks the passed ldap server in the configuration is up and running or not. + """"" + + flag = False + try: + tn = telnetlib.Telnet(ldapConfiguration['hostname'], ldapConfiguration['port'], timeout=15) + if tn is not None: + tn.set_debuglevel(1) + print tn.msg("Connected to the server") + cls.debug("Ldap Server is Up and listening on the port %s" % tn.msg("Connected to the server")) + flag = True + tn.close() + except Exception as e: + cls.debug(" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" + % ((ldapConfiguration['hostname']), e)) + cls.reason = "Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" \ + % ((ldapConfiguration['hostname']), e) + + return flag + +@ddt +class TestLdap1(cloudstackTestCase): + """ + 17 test cases in this class. + """ + + @classmethod + def setUpClass(cls): + + #configure ldap + """ + + :type cls: object + """ + testClient = super(TestLdap1, cls).getClsTestClient() + cls.api_client = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + cls.cleanup = [] + cls.delflag = 0 + cls.reason = "" + + ### --- End diff -- Please remove this line.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---