CLOUDSTACK-8218:added missing scenrio and additional checks for betterdebugging

Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
sadhu 2015-02-19 17:00:22 +05:30 committed by SrikanteswaraRao Talluri
parent 2de12b50f8
commit 26123dd079
1 changed files with 68 additions and 21 deletions

View File

@ -27,9 +27,10 @@ from marvin.cloudstackAPI import (updateConfiguration,
addLdapConfiguration,
deleteLdapConfiguration)
from marvin.cloudstackAPI import login
from marvin.lib.utils import cleanup_resources
from marvin.lib.utils import cleanup_resources,validateList
from nose.plugins.attrib import attr
import telnetlib
import sys
class TestLdap(cloudstackTestCase):
@ -44,6 +45,8 @@ class TestLdap(cloudstackTestCase):
cls.api_client = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig()
cls._cleanup = []
cls.delflag=0
cls.reason=""
@classmethod
def tearDownClass(cls):
@ -57,7 +60,6 @@ class TestLdap(cloudstackTestCase):
def setUp(self):
self.apiClient = self.testClient.getApiClient()
self.acct = createAccount.createAccountCmd()
self.acct.accounttype = 0
self.acct.firstname = self.services[
@ -73,39 +75,43 @@ class TestLdap(cloudstackTestCase):
self.acct.account = self.services[
"configurableData"]["ldap_account"]["username"]
self.acct.domainid = 1
self.acctRes = self.apiClient.createAccount(self.acct)
if self.acct.firstname == ""or self.acct.lastname == "" or self.acct.password == "" or self.acct.username == "" or \
self.acct.username == ""or self.acct.account=="":
self.debug("Please rerun the test by providing values in ldap configiration user details")
else:
self.delflag=1
self.acctRes = self.apiClient.createAccount(self.acct)
self.assertEquals(self.delflag,1,"LDAP account details are not provided,please check the configuration")
return
def tearDown(self):
try:
deleteAcct = deleteAccount.deleteAccountCmd()
deleteAcct.id = self.acctRes.id
acct_name = self.acctRes.name
deleteAcct = deleteAccount.deleteAccountCmd()
deleteAcct.id = self.acctRes.id
acct_name = self.acctRes.name
self.apiClient.deleteAccount(deleteAcct)
self.apiClient.deleteAccount(deleteAcct)
self.debug(
"Deleted the the following account name %s:" %
acct_name)
self.debug(
"Deleted the the following account name %s:" %
acct_name)
if(self.ldapconfRes == 1):
self._deleteLdapConfiguration(
self.services["configurableData"]["ldap_configuration"])
if(self.ldapconfRes == 1):
self._deleteLdapConfiguration(
self.services["configurableData"]["ldap_configuration"])
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_01_addLdapConfiguration(self):
"""
This test configures LDAP and attempts to authenticate as a user.
"""
self.debug("start test")
self.ldapconfRes = self._addLdapConfiguration(
@ -128,19 +134,35 @@ class TestLdap(cloudstackTestCase):
self.assertEquals(
self.ldapconfRes,
1,
"addLdapConfiguration failed")
self.reason)
self.debug("end test")
def test_02_validateLdapSecurityPatch(self):
self.debug("start test")
self.ldapconfRes = self._addLdapConfiguration(
self.services["configurableData"]["ldap_configuration"])
self.assertEqual(self.ldapconfRes,1,"Ldap Configuration failed")
loginRes = self._checkLogin(
self.services["configurableData"]["ldap_configuration"]["ldapUsername"],"")
self.assertNotEqual(loginRes,1,"login API Successful with empty password")
self.debug("end test")
def _addLdapConfiguration(self, ldapConfiguration):
"""
:param ldapConfiguration
"""
self.chkConfig=self._checkLdapConfiguration(ldapConfiguration)
if self.chkConfig==False:
return 0
# Setup Global settings
updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
updateConfigurationCmd.name = "ldap.basedn"
updateConfigurationCmd.value = ldapConfiguration['basedn']
@ -193,9 +215,32 @@ class TestLdap(cloudstackTestCase):
self.debug("addLdapConfiguration was successful")
return 1
except Exception as e:
self.debug("addLdapConfiguration failed %s" % e)
self.debug("addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e)
self.reason="addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e
return 0
def _checkLdapConfiguration(self,ldapConfiguration):
""""
This function checks the ldapconfiguration values
"""""
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")
self.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:
self.debug(" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" %((ldapConfiguration['hostname']), e))
self.reason=" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" %((ldapConfiguration['hostname']), e)
return flag
def _deleteLdapConfiguration(self, ldapConfiguration):
"""
@ -234,8 +279,10 @@ class TestLdap(cloudstackTestCase):
return 0
else:
self.debug("login successful")
#self.reason="Login Successful"
return 1
except Exception as p:
self.debug("login operation failed %s" % p)
#self.reason="Login operation Failed %s" %p
self.debug("end of Login")