mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
7004bdc40a
commit
ed1980c741
@ -664,6 +664,32 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
cleanup_resources(cls.api_client, cls._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"])
|
||||
def test_01_create_lb_rule_src_nat(self):
|
||||
"""Test to create Load balancing rule with source NAT"""
|
||||
@ -776,47 +802,14 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
[self.vm_1.id, self.vm_2.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:
|
||||
self.fail("%s: SSH failed for VM with IP Address: %s" %
|
||||
(e, src_nat_ip_addr.ipaddress))
|
||||
|
||||
time.sleep(self.services["lb_switch_wait"])
|
||||
|
||||
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))
|
||||
hostnames = []
|
||||
self.try_ssh(src_nat_ip_addr, hostnames)
|
||||
self.try_ssh(src_nat_ip_addr, hostnames)
|
||||
self.try_ssh(src_nat_ip_addr, hostnames)
|
||||
self.try_ssh(src_nat_ip_addr, hostnames)
|
||||
self.try_ssh(src_nat_ip_addr, hostnames)
|
||||
|
||||
self.debug("Hostnames: %s" % str(hostnames))
|
||||
self.assertIn(
|
||||
@ -832,6 +825,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
|
||||
#SSH should pass till there is a last VM associated with LB rule
|
||||
lb_rule.remove(self.apiclient, [self.vm_2])
|
||||
|
||||
# making hostnames list empty
|
||||
hostnames[:] = []
|
||||
|
||||
try:
|
||||
self.debug("SSHing into IP address: %s after removing VM (ID: %s)" %
|
||||
(
|
||||
@ -839,18 +836,7 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
self.vm_2.id
|
||||
))
|
||||
|
||||
ssh_1 = remoteSSHClient(
|
||||
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.try_ssh(src_nat_ip_addr, hostnames)
|
||||
|
||||
self.assertIn(
|
||||
self.vm_1.name,
|
||||
@ -858,6 +844,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
"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])
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
@ -967,40 +957,14 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
"Check List Load Balancer instances Rules returns valid VM ID"
|
||||
)
|
||||
try:
|
||||
self.debug("SSHing into IP address: %s after adding VMs (ID: %s , %s)" %
|
||||
(
|
||||
self.non_src_nat_ip.ipaddress.ipaddress,
|
||||
self.vm_1.id,
|
||||
self.vm_2.id
|
||||
))
|
||||
ssh_1 = remoteSSHClient(
|
||||
self.non_src_nat_ip.ipaddress.ipaddress,
|
||||
self.services['lbrule']["publicport"],
|
||||
self.vm_1.username,
|
||||
self.vm_1.password
|
||||
)
|
||||
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)
|
||||
|
||||
# If Round Robin Algorithm is chosen,
|
||||
# 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.debug("Hostnames: %s" % str(hostnames))
|
||||
self.assertIn(
|
||||
self.vm_1.name,
|
||||
hostnames,
|
||||
@ -1020,18 +984,10 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
self.non_src_nat_ip.ipaddress.ipaddress,
|
||||
self.vm_2.id
|
||||
))
|
||||
ssh_1 = remoteSSHClient(
|
||||
self.non_src_nat_ip.ipaddress.ipaddress,
|
||||
self.services['lbrule']["publicport"],
|
||||
self.vm_1.username,
|
||||
self.vm_1.password
|
||||
)
|
||||
# Making host list empty
|
||||
hostnames[:] = []
|
||||
|
||||
hostnames.append(ssh_1.execute("hostname")[0])
|
||||
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.try_ssh(self.non_src_nat_ip, hostnames)
|
||||
|
||||
self.assertIn(
|
||||
self.vm_1.name,
|
||||
@ -1039,6 +995,12 @@ class TestLoadBalancingRule(cloudstackTestCase):
|
||||
"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])
|
||||
with self.assertRaises(Exception):
|
||||
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:
|
||||
self.fail(
|
||||
"SSH Access failed for %s: %s" % \
|
||||
(self.nat_rule.ipaddress.ipaddress, e))
|
||||
(self.vm_1.ipaddress, e))
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
@ -1277,6 +1239,36 @@ class TestAssignRemoveLB(cloudstackTestCase):
|
||||
]
|
||||
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"])
|
||||
def test_assign_and_removal_lb(self):
|
||||
"""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])
|
||||
|
||||
try:
|
||||
self.debug("SSHing 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
|
||||
))
|
||||
#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)
|
||||
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.vm_1.name,
|
||||
res_1,
|
||||
hostnames,
|
||||
"Check if ssh succeeded for server1"
|
||||
)
|
||||
self.assertIn(
|
||||
self.vm_2.name,
|
||||
res_2,
|
||||
hostnames,
|
||||
"Check if ssh succeeded for server2"
|
||||
)
|
||||
|
||||
|
||||
#Removing VM and assigning another VM to LB rule
|
||||
lb_rule.remove(self.apiclient, [self.vm_2])
|
||||
|
||||
# making hostnames list empty
|
||||
hostnames[:] = []
|
||||
|
||||
try:
|
||||
self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" %
|
||||
(
|
||||
self.non_src_nat_ip.ipaddress,
|
||||
self.vm_1.id,
|
||||
))
|
||||
# Again make a SSH connection, as previous is not used after LB remove
|
||||
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.try_ssh(self.non_src_nat_ip, hostnames)
|
||||
|
||||
self.assertIn(
|
||||
self.vm_1.name,
|
||||
res_1,
|
||||
hostnames,
|
||||
"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:
|
||||
self.fail("SSH failed for VM with IP: %s" %
|
||||
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.vm_1.name,
|
||||
res_1,
|
||||
hostnames,
|
||||
"Check if ssh succeeded for server1"
|
||||
)
|
||||
self.assertIn(
|
||||
self.vm_3.name,
|
||||
res_3,
|
||||
hostnames,
|
||||
"Check if ssh succeeded for server3"
|
||||
)
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
return
|
||||
|
||||
|
||||
class TestReleaseIP(cloudstackTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user