Retrying the SSH connection for verifying RR load balancing

Attempt multiple-ssh connections to ensure the loadbalancing is going as
per round robin policy.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Gaurav Aradhye 2013-06-12 03:09:01 -04:00 committed by Prasanna Santhanam
parent 7004bdc40a
commit ed1980c741

View File

@ -664,6 +664,32 @@ class TestLoadBalancingRule(cloudstackTestCase):
cleanup_resources(cls.api_client, cls._cleanup) cleanup_resources(cls.api_client, cls._cleanup)
return return
def try_ssh(self, src_nat_ip_addr, hostnames):
try:
self.debug(
"SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
(self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
)
ssh_1 = remoteSSHClient(
src_nat_ip_addr.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
# If Round Robin Algorithm is chosen,
# each ssh command should alternate between VMs
# hostnames = [ssh_1.execute("hostname")[0]]
hostnames.append(ssh_1.execute("hostname")[0])
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, src_nat_ip_addr.ipaddress))
time.sleep(self.services["lb_switch_wait"])
return
@attr(tags = ["advanced", "advancedns", "smoke"]) @attr(tags = ["advanced", "advancedns", "smoke"])
def test_01_create_lb_rule_src_nat(self): def test_01_create_lb_rule_src_nat(self):
"""Test to create Load balancing rule with source NAT""" """Test to create Load balancing rule with source NAT"""
@ -776,47 +802,14 @@ class TestLoadBalancingRule(cloudstackTestCase):
[self.vm_1.id, self.vm_2.id], [self.vm_1.id, self.vm_2.id],
"Check List Load Balancer instances Rules returns valid VM ID" "Check List Load Balancer instances Rules returns valid VM ID"
) )
try:
self.debug(
"SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
(self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
)
ssh_1 = remoteSSHClient(
src_nat_ip_addr.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
# If Round Robin Algorithm is chosen,
# each ssh command should alternate between VMs
hostnames = [ssh_1.execute("hostname")[0]]
except Exception as e: hostnames = []
self.fail("%s: SSH failed for VM with IP Address: %s" % self.try_ssh(src_nat_ip_addr, hostnames)
(e, src_nat_ip_addr.ipaddress)) self.try_ssh(src_nat_ip_addr, hostnames)
self.try_ssh(src_nat_ip_addr, hostnames)
time.sleep(self.services["lb_switch_wait"]) self.try_ssh(src_nat_ip_addr, hostnames)
self.try_ssh(src_nat_ip_addr, hostnames)
try:
self.debug("SSHing into IP address: %s after adding VMs (ID: %s , %s)" %
(
src_nat_ip_addr.ipaddress,
self.vm_1.id,
self.vm_2.id
))
ssh_2 = remoteSSHClient(
src_nat_ip_addr.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
hostnames.append(ssh_2.execute("hostname")[0])
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, src_nat_ip_addr.ipaddress))
self.debug("Hostnames: %s" % str(hostnames)) self.debug("Hostnames: %s" % str(hostnames))
self.assertIn( self.assertIn(
@ -832,6 +825,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
#SSH should pass till there is a last VM associated with LB rule #SSH should pass till there is a last VM associated with LB rule
lb_rule.remove(self.apiclient, [self.vm_2]) lb_rule.remove(self.apiclient, [self.vm_2])
# making hostnames list empty
hostnames[:] = []
try: try:
self.debug("SSHing into IP address: %s after removing VM (ID: %s)" % self.debug("SSHing into IP address: %s after removing VM (ID: %s)" %
( (
@ -839,18 +836,7 @@ class TestLoadBalancingRule(cloudstackTestCase):
self.vm_2.id self.vm_2.id
)) ))
ssh_1 = remoteSSHClient( self.try_ssh(src_nat_ip_addr, hostnames)
src_nat_ip_addr.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
hostnames.append(ssh_1.execute("hostname")[0])
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, src_nat_ip_addr.ipaddress))
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
@ -858,6 +844,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
"Check if ssh succeeded for server1" "Check if ssh succeeded for server1"
) )
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, src_nat_ip_addr.ipaddress))
lb_rule.remove(self.apiclient, [self.vm_1]) lb_rule.remove(self.apiclient, [self.vm_1])
with self.assertRaises(Exception): with self.assertRaises(Exception):
@ -967,40 +957,14 @@ class TestLoadBalancingRule(cloudstackTestCase):
"Check List Load Balancer instances Rules returns valid VM ID" "Check List Load Balancer instances Rules returns valid VM ID"
) )
try: try:
self.debug("SSHing into IP address: %s after adding VMs (ID: %s , %s)" % hostnames = []
( self.try_ssh(self.non_src_nat_ip, hostnames)
self.non_src_nat_ip.ipaddress.ipaddress, self.try_ssh(self.non_src_nat_ip, hostnames)
self.vm_1.id, self.try_ssh(self.non_src_nat_ip, hostnames)
self.vm_2.id self.try_ssh(self.non_src_nat_ip, hostnames)
)) self.try_ssh(self.non_src_nat_ip, hostnames)
ssh_1 = remoteSSHClient(
self.non_src_nat_ip.ipaddress.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
# If Round Robin Algorithm is chosen, self.debug("Hostnames: %s" % str(hostnames))
# each ssh command should alternate between VMs
hostnames = [ssh_1.execute("hostname")[0]]
time.sleep(self.services["lb_switch_wait"])
self.debug("SSHing again into IP address: %s with VMs (ID: %s , %s) added to LB rule" %
(
self.non_src_nat_ip.ipaddress.ipaddress,
self.vm_1.id,
self.vm_2.id
))
ssh_2 = remoteSSHClient(
self.non_src_nat_ip.ipaddress.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
hostnames.append(ssh_2.execute("hostname")[0])
self.debug("Hostnames after adding 2 VMs to LB rule: %s" % str(hostnames))
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
hostnames, hostnames,
@ -1020,18 +984,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
self.non_src_nat_ip.ipaddress.ipaddress, self.non_src_nat_ip.ipaddress.ipaddress,
self.vm_2.id self.vm_2.id
)) ))
ssh_1 = remoteSSHClient( # Making host list empty
self.non_src_nat_ip.ipaddress.ipaddress, hostnames[:] = []
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
hostnames.append(ssh_1.execute("hostname")[0]) self.try_ssh(self.non_src_nat_ip, hostnames)
self.debug("Hostnames after removing VM2: %s" % str(hostnames))
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, self.non_src_nat_ip.ipaddress.ipaddress))
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
@ -1039,6 +995,12 @@ class TestLoadBalancingRule(cloudstackTestCase):
"Check if ssh succeeded for server1" "Check if ssh succeeded for server1"
) )
self.debug("Hostnames after removing VM2: %s" % str(hostnames))
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, self.non_src_nat_ip.ipaddress.ipaddress))
lb_rule.remove(self.apiclient, [self.vm_1]) lb_rule.remove(self.apiclient, [self.vm_1])
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
@ -1209,7 +1171,7 @@ class TestRebootRouter(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail( self.fail(
"SSH Access failed for %s: %s" % \ "SSH Access failed for %s: %s" % \
(self.nat_rule.ipaddress.ipaddress, e)) (self.vm_1.ipaddress, e))
return return
def tearDown(self): def tearDown(self):
@ -1277,6 +1239,36 @@ class TestAssignRemoveLB(cloudstackTestCase):
] ]
return return
def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup)
return
def try_ssh(self, src_nat_ip_addr, hostnames):
try:
self.debug(
"SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
(self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
)
ssh_1 = remoteSSHClient(
src_nat_ip_addr.ipaddress,
self.services['lbrule']["publicport"],
self.vm_1.username,
self.vm_1.password
)
# If Round Robin Algorithm is chosen,
# each ssh command should alternate between VMs
# hostnames = [ssh_1.execute("hostname")[0]]
hostnames.append(ssh_1.execute("hostname")[0])
except Exception as e:
self.fail("%s: SSH failed for VM with IP Address: %s" %
(e, src_nat_ip_addr.ipaddress))
time.sleep(self.services["lb_switch_wait"])
return
@attr(tags = ["advanced", "advancedns", "smoke"]) @attr(tags = ["advanced", "advancedns", "smoke"])
def test_assign_and_removal_lb(self): def test_assign_and_removal_lb(self):
"""Test for assign & removing load balancing rule""" """Test for assign & removing load balancing rule"""
@ -1344,137 +1336,74 @@ class TestAssignRemoveLB(cloudstackTestCase):
) )
lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
try: hostnames = []
self.debug("SSHing into IP address: %s with VMs (ID: %s , %s) added to LB rule" % self.try_ssh(self.non_src_nat_ip, hostnames)
( self.try_ssh(self.non_src_nat_ip, hostnames)
self.non_src_nat_ip.ipaddress, self.try_ssh(self.non_src_nat_ip, hostnames)
self.vm_1.id, self.try_ssh(self.non_src_nat_ip, hostnames)
self.vm_2.id self.try_ssh(self.non_src_nat_ip, hostnames)
))
#Create SSH client for each VM
ssh_1 = remoteSSHClient(
self.non_src_nat_ip.ipaddress,
self.services["lbrule"]["publicport"],
self.vm_1.username,
self.vm_1.password
)
except Exception as e:
self.fail("SSH failed for VM with IP: %s" %
self.non_src_nat_ip.ipaddress)
try:
self.debug("SSHing again into IP address: %s with VMs (ID: %s , %s) added to LB rule" %
(
self.non_src_nat_ip.ipaddress,
self.vm_1.id,
self.vm_2.id
))
ssh_2 = remoteSSHClient(
self.non_src_nat_ip.ipaddress,
self.services["lbrule"]["publicport"],
self.vm_2.username,
self.vm_2.password
)
# If Round Robin Algorithm is chosen,
# each ssh command should alternate between VMs
res_1 = ssh_1.execute("hostname")[0]
self.debug(res_1)
time.sleep(self.services["lb_switch_wait"])
res_2 = ssh_2.execute("hostname")[0]
self.debug(res_2)
except Exception as e:
self.fail("SSH failed for VM with IP: %s" %
self.non_src_nat_ip.ipaddress)
self.debug("Hostnames: %s" % str(hostnames))
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
res_1, hostnames,
"Check if ssh succeeded for server1" "Check if ssh succeeded for server1"
) )
self.assertIn( self.assertIn(
self.vm_2.name, self.vm_2.name,
res_2, hostnames,
"Check if ssh succeeded for server2" "Check if ssh succeeded for server2"
) )
#Removing VM and assigning another VM to LB rule #Removing VM and assigning another VM to LB rule
lb_rule.remove(self.apiclient, [self.vm_2]) lb_rule.remove(self.apiclient, [self.vm_2])
# making hostnames list empty
hostnames[:] = []
try: try:
self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" % self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" %
( (
self.non_src_nat_ip.ipaddress, self.non_src_nat_ip.ipaddress,
self.vm_1.id, self.vm_1.id,
)) ))
# Again make a SSH connection, as previous is not used after LB remove self.try_ssh(self.non_src_nat_ip, hostnames)
ssh_1 = remoteSSHClient(
self.non_src_nat_ip.ipaddress,
self.services["lbrule"]["publicport"],
self.vm_1.username,
self.vm_1.password
)
res_1 = ssh_1.execute("hostname")[0]
self.debug(res_1)
except Exception as e:
self.fail("SSH failed for VM with IP: %s" %
self.non_src_nat_ip.ipaddress)
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
res_1, hostnames,
"Check if ssh succeeded for server1" "Check if ssh succeeded for server1"
) )
lb_rule.assign(self.apiclient, [self.vm_3])
try:
ssh_1 = remoteSSHClient(
self.non_src_nat_ip.ipaddress,
self.services["lbrule"]["publicport"],
self.vm_1.username,
self.vm_1.password
)
ssh_3 = remoteSSHClient(
self.non_src_nat_ip.ipaddress,
self.services["lbrule"]["publicport"],
self.vm_3.username,
self.vm_3.password
)
res_1 = ssh_1.execute("hostname")[0]
self.debug(res_1)
time.sleep(self.services["lb_switch_wait"])
res_3 = ssh_3.execute("hostname")[0]
self.debug(res_3)
except Exception as e: except Exception as e:
self.fail("SSH failed for VM with IP: %s" % self.fail("SSH failed for VM with IP: %s" %
self.non_src_nat_ip.ipaddress) self.non_src_nat_ip.ipaddress)
lb_rule.assign(self.apiclient, [self.vm_3])
# Making hostnames list empty
hostnames[:] = []
self.try_ssh(self.non_src_nat_ip, hostnames)
self.try_ssh(self.non_src_nat_ip, hostnames)
self.try_ssh(self.non_src_nat_ip, hostnames)
self.try_ssh(self.non_src_nat_ip, hostnames)
self.try_ssh(self.non_src_nat_ip, hostnames)
self.debug("Hostnames: %s" % str(hostnames))
self.assertIn( self.assertIn(
self.vm_1.name, self.vm_1.name,
res_1, hostnames,
"Check if ssh succeeded for server1" "Check if ssh succeeded for server1"
) )
self.assertIn( self.assertIn(
self.vm_3.name, self.vm_3.name,
res_3, hostnames,
"Check if ssh succeeded for server3" "Check if ssh succeeded for server3"
) )
return return
def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup)
return
class TestReleaseIP(cloudstackTestCase): class TestReleaseIP(cloudstackTestCase):
def setUp(self): def setUp(self):