Github user remibergsma commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/919#discussion_r41707292 --- 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 = "" + + ### + cls.apiClient = cls.testClient.getApiClient() + cls.acct = createAccount.createAccountCmd() + cls.acct.accounttype = 0 + cls.acct.firstname = cls.services[ + "configurableData"]["ldap_account"]["firstname"] + cls.acct.lastname = cls.services[ + "configurableData"]["ldap_account"]["lastname"] + cls.acct.password = cls.services[ + "configurableData"]["ldap_account"]["password"] + cls.acct.username = cls.services[ + "configurableData"]["ldap_account"]["username"] + cls.acct.email = cls.services[ + "configurableData"]["ldap_account"]["email"] + cls.acct.account = cls.services[ + "configurableData"]["ldap_account"]["username"] + cls.acct.domainid = 1 + + if cls.acct.firstname == "" or cls.acct.lastname == "" or cls.acct.password == "" or cls.acct.username == "" \ + or cls.services["configurableData"]["ldap_configuration"]["ldapUsername"] == "" or \ + cls.acct.account == "" or \ + cls.services["configurableData"]["ldap_configuration"]["ldapPassword"] == "": + + cls.debug("Please rerun the test by providing values in ldap configuration user details") + cls.skipTest("Please rerun the test by providing proper values in configuration file") + + else: + cls.delflag = 1 + cls.acctRes = cls.apiClient.createAccount(cls.acct) + #cls.assertEquals(cls.delflag, 1, "LDAP account details are not provided,please check the configuration") --- End diff -- Please remove code, do not comment it. It can be retrieved if necessary from Git.
--- 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. ---