From 17978438eed3272a8f757f85dce34444554290a6 Mon Sep 17 00:00:00 2001 From: Chirag Jog Date: Wed, 13 Jun 2012 20:34:14 +0530 Subject: [PATCH] Adding Netscaler test cases and fixing bugs in HA test suite. --- .../component/test_high_availability.py | 29 +- .../component/test_netscaler_configs.py | 77 +- .../component/test_netscaler_lb.py | 1 - .../component/test_netscaler_lb_algo.py | 1564 ++++------- .../component/test_netscaler_lb_sticky.py | 4 +- .../component/test_netscaler_nw_off.py | 2346 +++++++++++++++++ test/integration/lib/base.py | 107 +- 7 files changed, 2998 insertions(+), 1130 deletions(-) create mode 100644 test/integration/component/test_netscaler_nw_off.py diff --git a/test/integration/component/test_high_availability.py b/test/integration/component/test_high_availability.py index 10281615cc3..02463f0e0b8 100644 --- a/test/integration/component/test_high_availability.py +++ b/test/integration/component/test_high_availability.py @@ -21,7 +21,7 @@ from marvin.cloudstackAPI import * from integration.lib.utils import * from integration.lib.base import * from integration.lib.common import * -from marvin.remoteSSHClient import remoteSSHClient +from marvin import remoteSSHClient import datetime @@ -80,7 +80,7 @@ class Services: "templates": { "displaytext": "Public Template", "name": "Public template", - "ostypeid": '946b031b-0e10-4f4a-a3fc-d212ae2ea07f', + "ostypeid": '1d4a6dce-8db1-4c08-8752-e88b360d8287', "url": "http://download.cloud.com/releases/2.0.0/UbuntuServer-10-04-64bit.vhd.bz2", "hypervisor": 'XenServer', "format" : 'VHD', @@ -89,7 +89,7 @@ class Services: "isextractable": True, "templatefilter": 'self', }, - "ostypeid": '946b031b-0e10-4f4a-a3fc-d212ae2ea07f', + "ostypeid": '1d4a6dce-8db1-4c08-8752-e88b360d8287', # Cent OS 5.3 (64 bit) "sleep": 60, "timeout": 100, @@ -198,7 +198,7 @@ class TestHighAvailability(cloudstackTestCase): True, "List hosts should return valid host response" ) - self.assertEqual( + self.assertGreaterEqual( len(hosts), 2, "There must be two hosts present in a cluster" @@ -277,15 +277,6 @@ class TestHighAvailability(cloudstackTestCase): self.debug("Creating LB rule on IP with NAT: %s" % public_ip.ipaddress.ipaddress) - # Open up firewall port for SSH - fw_rule = FireWallRule.create( - self.apiclient, - ipaddressid=public_ip.ipaddress.id, - protocol=self.services["natrule"]["protocol"], - cidrlist=['0.0.0.0/0'], - startport=self.services["natrule"]["publicport"], - endport=self.services["natrule"]["publicport"] - ) # Create Load Balancer rule on IP already having NAT rule lb_rule = LoadBalancerRule.create( self.apiclient, @@ -600,7 +591,7 @@ class TestHighAvailability(cloudstackTestCase): True, "List hosts should return valid host response" ) - self.assertEqual( + self.assertGreaterEqual( len(hosts), 2, "There must be two hosts present in a cluster" @@ -676,16 +667,6 @@ class TestHighAvailability(cloudstackTestCase): ipaddressid=public_ip.ipaddress.id ) - # Open up firewall port for SSH - fw_rule = FireWallRule.create( - self.apiclient, - ipaddressid=public_ip.ipaddress.id, - protocol=self.services["natrule"]["protocol"], - cidrlist=['0.0.0.0/0'], - startport=self.services["natrule"]["publicport"], - endport=self.services["natrule"]["publicport"] - ) - self.debug("Creating LB rule on IP with NAT: %s" % public_ip.ipaddress.ipaddress) diff --git a/test/integration/component/test_netscaler_configs.py b/test/integration/component/test_netscaler_configs.py index a76a19b8b2e..99f356a8ee9 100644 --- a/test/integration/component/test_netscaler_configs.py +++ b/test/integration/component/test_netscaler_configs.py @@ -63,12 +63,23 @@ class Services: "password": 'nsroot', "networkdevicetype": 'NetscalerVPXLoadBalancer', "publicinterface": '1/1', - "privateinterface": '0/1', + "privateinterface": '1/1', "numretries": 2, "lbdevicededicated": False, "lbdevicecapacity": 50, "port": 22, }, + "netscaler_dedicated": { + "ipaddress": '192.168.100.213', + "username": 'nsroot', + "password": 'nsroot', + "networkdevicetype": 'NetscalerVPXLoadBalancer', + "publicinterface": '1/1', + "privateinterface": '1/1', + "numretries": 2, + "lbdevicededicated": True, + "port": 22, + }, "network_offering_dedicated": { "name": 'Netscaler', "displaytext": 'Netscaler', @@ -262,6 +273,7 @@ class TestAddNetScaler(cloudstackTestCase): return + class TestInvalidParametersNetscaler(cloudstackTestCase): @classmethod @@ -502,7 +514,7 @@ class TestInvalidParametersNetscaler(cloudstackTestCase): ) return -@unittest.skip("Issue- Unable to validate user credentials while creating nw offering") + class TestNetScalerDedicated(cloudstackTestCase): @classmethod @@ -528,10 +540,9 @@ class TestNetScalerDedicated(cloudstackTestCase): if isinstance(physical_networks, list): physical_network = physical_networks[0] - cls.services["netscaler"]["lbdevicededicated"] = True cls.netscaler = NetScaler.add( cls.api_client, - cls.services["netscaler"], + cls.services["netscaler_dedicated"], physicalnetworkid=physical_network.id ) @@ -702,8 +713,8 @@ class TestNetScalerDedicated(cloudstackTestCase): # Creating network using the network offering created self.debug("Trying to create network with network offering: %s" % self.network_offering.id) - with self.assertRaises(Exception): - Network.create( + + Network.create( self.apiclient, self.services["network"], accountid=self.account_2.account.name, @@ -711,9 +722,21 @@ class TestNetScalerDedicated(cloudstackTestCase): networkofferingid=self.network_offering.id, zoneid=self.zone.id ) + self.debug("Deploying an instance in account: %s" % self.account_2.account.name) + with self.assertRaises(Exception): + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network.id)] + ) + self.debug("Deply instacne in dedicated Network offering mode failed") return + class TestNetScalerShared(cloudstackTestCase): @classmethod @@ -827,12 +850,12 @@ class TestNetScalerShared(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - def test_netscaler_dedicated_mode(self): - """Test netscaler device in dedicated mode + def test_netscaler_shared_mode(self): + """Test netscaler device in shared mode """ # Validate the following - # 1. Add Netscaler device in dedicated mode. + # 1. Add Netscaler device in shared mode. # 2. Netscaler should be configured successfully.It should be able to # service only 1 account. @@ -955,6 +978,7 @@ class TestNetScalerShared(cloudstackTestCase): return + class TestNetScalerCustomCapacity(cloudstackTestCase): @classmethod @@ -1074,14 +1098,14 @@ class TestNetScalerCustomCapacity(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - def test_netscaler_dedicated_mode(self): - """Test netscaler device in dedicated mode + def test_netscaler_custom_capacity(self): + """Test netscaler device with custom capacity """ # Validate the following - # 1. Add Netscaler device in dedicated mode. + # 1. Add Netscaler device in shared mode with capacity 3 # 2. Netscaler should be configured successfully.It should be able to - # service only 1 account. + # service only 3 accounts. ns_list = NetScaler.list( self.apiclient, @@ -1226,6 +1250,7 @@ class TestNetScalerCustomCapacity(cloudstackTestCase): return + class TestNetScalerNoCapacity(cloudstackTestCase): @classmethod @@ -1250,7 +1275,7 @@ class TestNetScalerNoCapacity(cloudstackTestCase): ) if isinstance(physical_networks, list): physical_network = physical_networks[0] - + cls.services["netscaler"]["lbdevicecapacity"] = 2 cls.netscaler = NetScaler.add( cls.api_client, cls.services["netscaler"], @@ -1345,14 +1370,15 @@ class TestNetScalerNoCapacity(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - def test_netscaler_dedicated_mode(self): - """Test netscaler device in dedicated mode + def test_netscaler_no_capacity(self): + """Test netscaler device with no capacity remaining """ # Validate the following - # 1. Add Netscaler device in dedicated mode. + # 1. Add Netscaler device in shared mode with capacity 2 # 2. Netscaler should be configured successfully.It should be able to - # service only 1 account. + # service only 2 accounts. + # 3. Deploy instance for account 3 should fail ns_list = NetScaler.list( self.apiclient, @@ -1497,6 +1523,7 @@ class TestNetScalerNoCapacity(cloudstackTestCase): return + class TestGuestNetworkWithNetScaler(cloudstackTestCase): @classmethod @@ -2049,6 +2076,7 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase): return + class TestGuestNetworkShutDown(cloudstackTestCase): @classmethod @@ -2209,7 +2237,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): name='network.gc.wait' ) # Sleep to ensure that all resources are deleted - time.sleep((int(interval[0].value) + int(wait[0].value))*2) + time.sleep((int(interval[0].value) + int(wait[0].value)) * 2) self.debug("SSH into netscaler: %s" % self.services["netscaler"]["ipaddress"]) @@ -2459,6 +2487,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): return + class TestServiceProvider(cloudstackTestCase): @classmethod @@ -2750,8 +2779,15 @@ class TestServiceProvider(cloudstackTestCase): id=self.netscaler_provider.id, state='Disabled' ) - self.debug("Deploying VM in the network: %s" % self.network.id) with self.assertRaises(Exception): + self.debug("Deploying VM in the network: %s" % self.network.id) + LoadBalancerRule.create( + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.account.name, + networkid=self.network.id + ) VirtualMachine.create( self.apiclient, self.services["virtual_machine"], @@ -2763,6 +2799,7 @@ class TestServiceProvider(cloudstackTestCase): return + class TestDeleteNetscaler(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py index 6b1e517df98..59ac84f3f69 100644 --- a/test/integration/component/test_netscaler_lb.py +++ b/test/integration/component/test_netscaler_lb.py @@ -1571,7 +1571,6 @@ class TestMultipleLbRules(cloudstackTestCase): return - class TestMultipleLbRulesSameIp(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_netscaler_lb_algo.py b/test/integration/component/test_netscaler_lb_algo.py index 7248405001b..bcff75fb4a9 100644 --- a/test/integration/component/test_netscaler_lb_algo.py +++ b/test/integration/component/test_netscaler_lb_algo.py @@ -58,7 +58,7 @@ class Services: "protocol": 'TCP', }, "netscaler": { - "ipaddress": '10.147.40.100', + "ipaddress": '192.168.100.213', "username": 'nsroot', "password": 'nsroot', "networkdevicetype": 'NetscalerVPXLoadBalancer', @@ -67,35 +67,7 @@ class Services: "numretries": 2, "lbdevicededicated": False, "lbdevicecapacity": 50, - }, - "network_offering_dedicated": { - "name": 'Netscaler', - "displaytext": 'Netscaler', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', - "traffictype": 'GUEST', - "availability": 'Optional', - "specifyVlan": False, - "specifyIpRanges": False, - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - "Vpn": 'VirtualRouter', - "Firewall": 'VirtualRouter', - "Lb": 'Netscaler', - "UserData": 'VirtualRouter', - "StaticNat": 'VirtualRouter', - }, - "servicecapabilitylist": { - "SourceNat": { - "SupportedSourceNatTypes": "peraccount" - }, - "lb": { - "SupportedLbIsolation": "dedicated" - }, - }, + "port": 22, }, "network_offering": { "name": 'Netscaler', @@ -128,12 +100,7 @@ class Services: "publicport": 22, "openfirewall": False, }, - "natrule": { - "privateport": 22, - "publicport": 22, - "protocol": "TCP" - }, - "ostypeid": '2b58909b-7d9e-45d9-80d8-e58d0bbcbf07', + "ostypeid": '946b031b-0e10-4f4a-a3fc-d212ae2ea07f', # Cent OS 5.3 (64 bit) "sleep": 60, "timeout": 10, @@ -166,6 +133,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id @@ -174,8 +142,8 @@ class TestLbWithRoundRobin(cloudstackTestCase): cls.services["service_offering"] ) cls._cleanup = [ - cls.service_offering, cls.network_offering, + cls.service_offering ] return @@ -248,7 +216,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.debug("Deploying VM in account: %s" % self.account.account.name) # Spawn an instance in that network - virtual_machine_1 = VirtualMachine.create( + self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.account.name, @@ -259,12 +227,12 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.debug("Deployed VM in network: %s" % self.network.id) list_vm_response = VirtualMachine.list( self.apiclient, - id=virtual_machine_1.id + id=self.virtual_machine.id ) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id + % self.virtual_machine.id ) self.assertEqual( @@ -280,41 +248,6 @@ class TestLbWithRoundRobin(cloudstackTestCase): "VM state should be running after deployment" ) - self.debug("Deploying another VM in account: %s" % - self.account.account.name) - - # Spawn an instance in that network - virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.account.name, - domainid=self.account.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) - self.debug("Deployed VM in network: %s" % self.network.id) - list_vm_response = VirtualMachine.list( - self.apiclient, - id=virtual_machine_2.id - ) - - self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) - - self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) - vm_response = list_vm_response[0] - - self.assertEqual( - vm_response.state, - "Running", - "VM state should be running after deployment" - ) self.debug("Associating public IP for network: %s" % self.network.id) ip_with_lb_rule = PublicIPAddress.create( @@ -341,9 +274,6 @@ class TestLbWithRoundRobin(cloudstackTestCase): networkid=self.network.id ) - self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) - lb_rules = LoadBalancerRule.list( self.apiclient, id=lb_rule.id, @@ -354,60 +284,39 @@ class TestLbWithRoundRobin(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) - self.debug("Adding %s, %s to the LB rule %s" % ( - virtual_machine_1.name, - virtual_machine_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [virtual_machine_1, virtual_machine_2]) - - try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress) - self.debug("Command: hostname") - result = ssh.execute("hostname") + self.debug("Adding %s to the LB rule %s" % ( + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) + try: + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( + ip_with_lb_rule.ipaddress.ipaddress, + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) self.debug("Output: %s" % result) - hostnames.append(result) - - ssh = virtual_machine_2.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.assertNotEqual( - hostnames[0], - hostnames[1], - "Hostnames must not be same if round robin algo is used" - ) - - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) self.assertEqual( - hostnames[0], - hostnames[2], - "Alternate Hostnames must be same if roundrobin algo is used" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - e)) - return + result.count("Configured Method: ROUNDROBIN"), + 1, + "'ROUNDROBIN' algorithm should be configured on NS" + ) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + return class TestLbWithLeastConn(cloudstackTestCase): @@ -435,6 +344,7 @@ class TestLbWithLeastConn(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id @@ -442,9 +352,10 @@ class TestLbWithLeastConn(cloudstackTestCase): cls.api_client, cls.services["service_offering"] ) + cls._cleanup = [ - cls.service_offering, cls.network_offering, + cls.service_offering ] return @@ -517,7 +428,7 @@ class TestLbWithLeastConn(cloudstackTestCase): self.debug("Deploying VM in account: %s" % self.account.account.name) # Spawn an instance in that network - virtual_machine_1 = VirtualMachine.create( + self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.account.name, @@ -528,12 +439,12 @@ class TestLbWithLeastConn(cloudstackTestCase): self.debug("Deployed VM in network: %s" % self.network.id) list_vm_response = VirtualMachine.list( self.apiclient, - id=virtual_machine_1.id + id=self.virtual_machine.id ) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id + % self.virtual_machine.id ) self.assertEqual( @@ -549,43 +460,15 @@ class TestLbWithLeastConn(cloudstackTestCase): "VM state should be running after deployment" ) - self.debug("Deploying another VM in account: %s" % - self.account.account.name) - - # Spawn an instance in that network - virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.account.name, - domainid=self.account.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) - self.debug("Deployed VM in network: %s" % self.network.id) - list_vm_response = VirtualMachine.list( - self.apiclient, - id=virtual_machine_2.id - ) - - self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) - - self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) - vm_response = list_vm_response[0] - - self.assertEqual( - vm_response.state, - "Running", - "VM state should be running after deployment" - ) self.debug("Associating public IP for network: %s" % self.network.id) + PublicIPAddress.create( + self.apiclient, + accountid=self.account.account.name, + zoneid=self.zone.id, + domainid=self.account.account.domainid, + networkid=self.network.id + ) ip_with_lb_rule = PublicIPAddress.create( self.apiclient, accountid=self.account.account.name, @@ -610,9 +493,6 @@ class TestLbWithLeastConn(cloudstackTestCase): networkid=self.network.id ) - self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) - lb_rules = LoadBalancerRule.list( self.apiclient, id=lb_rule.id, @@ -624,60 +504,42 @@ class TestLbWithLeastConn(cloudstackTestCase): "List LB rules should return a newly created LB rule" ) self.debug("Adding %s to the LB rule %s" % ( - virtual_machine_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [virtual_machine_1]) - self.debug("Creating a firewall rule to open up SSH ports..") + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.debug("Adding %s to the LB rule %s" % ( - virtual_machine_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [virtual_machine_2]) - - ssh = virtual_machine_2.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - self.assertNotEqual( - res.count(virtual_machine_2.name), - 1, - "SSH request should go to second VM(having least connections)" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( ip_with_lb_rule.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'LEASTCONNECTION' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbWithSourceIp(cloudstackTestCase): @classmethod @@ -711,8 +573,8 @@ class TestLbWithSourceIp(cloudstackTestCase): cls.services["service_offering"] ) cls._cleanup = [ - cls.service_offering, cls.network_offering, + cls.service_offering ] return @@ -785,7 +647,7 @@ class TestLbWithSourceIp(cloudstackTestCase): self.debug("Deploying VM in account: %s" % self.account.account.name) # Spawn an instance in that network - virtual_machine_1 = VirtualMachine.create( + self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.account.name, @@ -796,12 +658,12 @@ class TestLbWithSourceIp(cloudstackTestCase): self.debug("Deployed VM in network: %s" % self.network.id) list_vm_response = VirtualMachine.list( self.apiclient, - id=virtual_machine_1.id + id=self.virtual_machine.id ) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id + % self.virtual_machine.id ) self.assertEqual( @@ -817,41 +679,6 @@ class TestLbWithSourceIp(cloudstackTestCase): "VM state should be running after deployment" ) - self.debug("Deploying another VM in account: %s" % - self.account.account.name) - - # Spawn an instance in that network - virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.account.name, - domainid=self.account.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) - self.debug("Deployed VM in network: %s" % self.network.id) - list_vm_response = VirtualMachine.list( - self.apiclient, - id=virtual_machine_2.id - ) - - self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) - - self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) - vm_response = list_vm_response[0] - - self.assertEqual( - vm_response.state, - "Running", - "VM state should be running after deployment" - ) self.debug("Associating public IP for network: %s" % self.network.id) ip_with_lb_rule = PublicIPAddress.create( @@ -878,9 +705,6 @@ class TestLbWithSourceIp(cloudstackTestCase): networkid=self.network.id ) - self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) - lb_rules = LoadBalancerRule.list( self.apiclient, id=lb_rule.id, @@ -891,76 +715,43 @@ class TestLbWithSourceIp(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) + self.debug("Adding %s to the LB rule %s" % ( - virtual_machine_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [virtual_machine_1]) - + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - res = str(result) - - self.assertEqual( - res.count(virtual_machine_1.name), - 1, - "Request should be sent only to the first VM" - ) - - self.debug("Adding %s to the LB rule %s" % ( - virtual_machine_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [virtual_machine_2]) - - ssh = virtual_machine_1.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - res = str(result) - - self.assertEqual( - res.count(virtual_machine_1.name), - 1, - "Request should be sent only to the first VM" - ) - - ssh = virtual_machine_2.get_ssh_client( - ipaddress=ip_with_lb_rule.ipaddress.ipaddress - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - - self.assertEqual( - res.count(virtual_machine_1.name), - 1, - "Request should be sent only to the first VM" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( ip_with_lb_rule.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCEIPHASH' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoRrLc(cloudstackTestCase): @classmethod @@ -985,13 +776,6 @@ class TestLbAlgoRrLc(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -1006,17 +790,16 @@ class TestLbAlgoRrLc(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -1032,8 +815,8 @@ class TestLbAlgoRrLc(cloudstackTestCase): networkid=cls.network.id ) cls._cleanup = [ - cls.service_offering, - cls.account + cls.account, + cls.service_offering ] return @@ -1100,8 +883,6 @@ class TestLbAlgoRrLc(cloudstackTestCase): networkid=self.network.id ) self.cleanup.append(lb_rule) - self.debug("Trying to create PF rule on IP with LB rule: %s" % - self.public_ip.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( self.apiclient, @@ -1113,119 +894,76 @@ class TestLbAlgoRrLc(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) - self.debug("Adding %s, %s to the LB rule %s" % ( - self.vm_1.name, - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) + self.debug("Adding %s to the LB rule %s" % ( + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the roundrobin algo used by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( + self.public_ip.ipaddress.ipaddress, + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_2 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.assertNotEqual( - hostnames[0], - hostnames[1], - "Hostnames must not be same if round robin algo is used" - ) - - ssh_3 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) self.assertEqual( - hostnames[0], - hostnames[2], - "Alternate Hostnames must be same if roundrobin algo is used" - ) + result.count("Configured Method: ROUNDROBIN"), + 1, + "'ROUNDROBIN' algorithm should be configured on NS" + ) except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip.ipaddress.ipaddress, - e)) + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'leastconn')) lb_rule.update(self.apiclient, algorithm='leastconn') - self.debug( - "Removing virtual machine: %s to test least connection algo" % - self.vm_2.name) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_4 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_5 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - self.assertNotEqual( - res.count(self.vm_2.name), - 1, - "SSH request should go to second VM(having least connections)" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'LEASTCONNECTION' algorithm should be configured on NS" + ) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoLcRr(cloudstackTestCase): @classmethod @@ -1250,13 +988,6 @@ class TestLbAlgoLcRr(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -1271,17 +1002,16 @@ class TestLbAlgoLcRr(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -1297,8 +1027,8 @@ class TestLbAlgoLcRr(cloudstackTestCase): networkid=cls.network.id ) cls._cleanup = [ - cls.service_offering, - cls.account + cls.account, + cls.service_offering ] return @@ -1377,113 +1107,72 @@ class TestLbAlgoLcRr(cloudstackTestCase): "List LB rules should return a newly created LB rule" ) self.debug("Adding %s to the LB rule %s" % ( - self.vm_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1]) - + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the leastconn algo used by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_2 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_3 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - self.assertNotEqual( - res.count(self.vm_2.name), - 1, - "SSH request should go to second VM(having least connections)" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'LEASTCONNECTION' algorithm should be configured on NS" + ) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'roundrobin')) lb_rule.update(self.apiclient, algorithm='roundrobin') + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the roundrobin algo used by SSHing into instances") - hostnames = [] - ssh_4 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( + self.public_ip.ipaddress.ipaddress, + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_5 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.assertNotEqual( - hostnames[0], - hostnames[1], - "Hostnames must not be same if round robin algo is used" - ) - - ssh_6 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_6.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) self.assertEqual( - hostnames[0], - hostnames[2], - "Alternate Hostnames must be same if roundrobin algo is used" - ) + result.count("Configured Method: ROUNDROBIN"), + 1, + "'ROUNDROBIN' algorithm should be configured on NS" + ) except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip.ipaddress.ipaddress, - e)) + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoRrSb(cloudstackTestCase): @classmethod @@ -1508,13 +1197,6 @@ class TestLbAlgoRrSb(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -1529,17 +1211,16 @@ class TestLbAlgoRrSb(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -1547,6 +1228,7 @@ class TestLbAlgoRrSb(cloudstackTestCase): serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) + cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.account.account.name, @@ -1555,8 +1237,8 @@ class TestLbAlgoRrSb(cloudstackTestCase): networkid=cls.network.id ) cls._cleanup = [ - cls.service_offering, - cls.account + cls.account, + cls.service_offering ] return @@ -1623,8 +1305,6 @@ class TestLbAlgoRrSb(cloudstackTestCase): networkid=self.network.id ) self.cleanup.append(lb_rule) - self.debug("Trying to create PF rule on IP with LB rule: %s" % - self.public_ip.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( self.apiclient, @@ -1636,135 +1316,75 @@ class TestLbAlgoRrSb(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) - self.debug("Adding %s, %s to the LB rule %s" % ( - self.vm_1.name, - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) - + self.debug("Adding %s to the LB rule %s" % ( + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the roundrobin algo used by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( + self.public_ip.ipaddress.ipaddress, + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_2 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.assertNotEqual( - hostnames[0], - hostnames[1], - "Hostnames must not be same if round robin algo is used" - ) - - ssh_3 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) self.assertEqual( - hostnames[0], - hostnames[2], - "Alternate Hostnames must be same if roundrobin algo is used" - ) + result.count("Configured Method: ROUNDROBIN"), + 1, + "'ROUNDROBIN' algorithm should be configured on NS" + ) except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip.ipaddress.ipaddress, - e)) + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'source')) lb_rule.update(self.apiclient, algorithm='source') - self.debug( - "Removing virtual machine: %s to test source algo" % - self.vm_2.name) - lb_rule.remove(self.apiclient, [self.vm_2]) - + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_4 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_5 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - ssh_6 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_6.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCEIPHASH' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoSbRr(cloudstackTestCase): @classmethod @@ -1789,13 +1409,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -1810,17 +1424,16 @@ class TestLbAlgoSbRr(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -1828,6 +1441,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) + cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.account.account.name, @@ -1836,7 +1450,6 @@ class TestLbAlgoSbRr(cloudstackTestCase): networkid=cls.network.id ) cls._cleanup = [ - cls.service_offering, cls.account ] return @@ -1915,132 +1528,77 @@ class TestLbAlgoSbRr(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) + self.debug("Adding %s to the LB rule %s" % ( - self.vm_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1]) + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_2 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - ssh_3 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCEIPHASH' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'roundrobin')) lb_rule.update(self.apiclient, algorithm='roundrobin') + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the roundrobin algo used by SSHing into instances") - hostnames = [] - ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh.execute("hostname") + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( + self.public_ip.ipaddress.ipaddress, + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_4 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.assertNotEqual( - hostnames[0], - hostnames[1], - "Hostnames must not be same if round robin algo is used" - ) - - ssh_5 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) self.assertEqual( - hostnames[0], - hostnames[2], - "Alternate Hostnames must be same if roundrobin algo is used" - ) + result.count("Configured Method: ROUNDROBIN"), + 1, + "'ROUNDROBIN' algorithm should be configured on NS" + ) except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip.ipaddress.ipaddress, - e)) + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoSbLc(cloudstackTestCase): @classmethod @@ -2065,13 +1623,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -2086,17 +1638,16 @@ class TestLbAlgoSbLc(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -2104,6 +1655,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) + cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.account.account.name, @@ -2191,136 +1743,76 @@ class TestLbAlgoSbLc(cloudstackTestCase): True, "List LB rules should return a newly created LB rule" ) + self.debug("Adding %s to the LB rule %s" % ( - self.vm_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1]) + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_2 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - ssh_3 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCEIPHASH' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'leastconn')) lb_rule.update(self.apiclient, algorithm='leastconn') - self.debug( - "Removing virtual machine: %s to test least connection algo" % - self.vm_2.name) - lb_rule.remove(self.apiclient, [self.vm_2]) + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_4 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_5 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_6 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_6.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - self.assertNotEqual( - res.count(self.vm_2.name), - 1, - "SSH request should go to second VM(having least connections)" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'LEASTCONNECTION' algorithm should be configured on NS" + ) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return + class TestLbAlgoLcSb(cloudstackTestCase): @classmethod @@ -2345,13 +1837,7 @@ class TestLbAlgoLcSb(cloudstackTestCase): ) # Enable Network offering cls.network_offering.update(cls.api_client, state='Enabled') - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) cls.account = Account.create( cls.api_client, cls.services["account"], @@ -2366,17 +1852,16 @@ class TestLbAlgoLcSb(cloudstackTestCase): networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.account.name, - domainid=cls.account.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.account.name, @@ -2392,8 +1877,8 @@ class TestLbAlgoLcSb(cloudstackTestCase): networkid=cls.network.id ) cls._cleanup = [ - cls.service_offering, - cls.account + cls.account, + cls.service_offering ] return @@ -2472,130 +1957,69 @@ class TestLbAlgoLcSb(cloudstackTestCase): "List LB rules should return a newly created LB rule" ) self.debug("Adding %s to the LB rule %s" % ( - self.vm_1.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_1]) - + self.virtual_machine.name, + lb_rule.name + )) + lb_rule.assign(self.apiclient, [self.virtual_machine]) + + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_1.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - ssh_2 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_2.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_3 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_3.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - self.assertNotEqual( - res.count(self.vm_2.name), - 1, - "SSH request should go to second VM(having least connections)" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'LEASTCONNECTION' algorithm should be configured on NS" + ) + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) + self.debug( "Updating LB rule: %s with new algorithm: %s" % ( lb_rule.name, 'source')) lb_rule.update(self.apiclient, algorithm='source') - self.debug( - "Removing virtual machine: %s to test source algo" % - self.vm_2.name) - lb_rule.remove(self.apiclient, [self.vm_2]) - + self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug("SSH into netscaler: %s" % + self.services["netscaler"]["ipaddress"]) try: - self.debug( - "Verifying the algorithm used for LB by SSHing into instances") - hostnames = [] - ssh_4 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress) - self.debug("Command: hostname") - result = ssh_4.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - self.debug("Adding %s to the LB rule %s" % ( - self.vm_2.name, - lb_rule.name - )) - lb_rule.assign(self.apiclient, [self.vm_2]) - - ssh_5 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_5.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - self.debug("Hostnames: %s" % str(hostnames)) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - - ssh_6 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip.ipaddress.ipaddress, - reconnect=True - ) - self.debug("Command: hostname") - result = ssh_6.execute("hostname") - self.debug("Output: %s" % result) - hostnames.append(result) - - res = str(result) - - self.assertEqual( - res.count(self.vm_1.name), - 1, - "Request should be sent only to the first VM" - ) - except Exception as e: - self.fail("Exception occured during SSH: %s - %s" % ( + ssh_client = remoteSSHClient( + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) + cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % ( self.public_ip.ipaddress.ipaddress, - e)) + lb_rule.publicport) + self.debug("command: %s" % cmd) + res = ssh_client.execute(cmd) + result = str(res) + self.debug("Output: %s" % result) + + self.assertEqual( + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCEIPHASH' algorithm should be configured on NS" + ) + + except Exception as e: + self.fail("SSH Access failed for %s: %s" % \ + (self.services["netscaler"]["ipaddress"], e)) return diff --git a/test/integration/component/test_netscaler_lb_sticky.py b/test/integration/component/test_netscaler_lb_sticky.py index 75647951c8c..47f5cd1743d 100644 --- a/test/integration/component/test_netscaler_lb_sticky.py +++ b/test/integration/component/test_netscaler_lb_sticky.py @@ -58,7 +58,7 @@ class Services: "protocol": 'TCP', }, "netscaler": { - "ipaddress": '10.147.40.100', + "ipaddress": '192.168.100.213', "username": 'nsroot', "password": 'nsroot', "networkdevicetype": 'NetscalerVPXLoadBalancer', @@ -100,7 +100,7 @@ class Services: "publicport": 22, "openfirewall": False, }, - "ostypeid": '2b58909b-7d9e-45d9-80d8-e58d0bbcbf07', + "ostypeid": '946b031b-0e10-4f4a-a3fc-d212ae2ea07f', # Cent OS 5.3 (64 bit) "sleep": 60, "timeout": 10, diff --git a/test/integration/component/test_netscaler_nw_off.py b/test/integration/component/test_netscaler_nw_off.py new file mode 100644 index 00000000000..d130ed540fa --- /dev/null +++ b/test/integration/component/test_netscaler_nw_off.py @@ -0,0 +1,2346 @@ +# -*- encoding: utf-8 -*- +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 + +""" P1 tests for multiple netscaler instances +""" +#Import Local Modules +import marvin +from marvin.cloudstackTestCase import * +from marvin.cloudstackAPI import * +from integration.lib.utils import * +from integration.lib.base import * +from integration.lib.common import * +from marvin.remoteSSHClient import remoteSSHClient +import datetime + + +class Services: + """Test netscaler Services + """ + + def __init__(self): + self.services = { + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "fr3sca", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, # in MHz + "memory": 128, # In MBs + }, + "virtual_machine": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "netscaler_1": { + "ipaddress": '192.168.100.213', + "username": 'nsroot', + "password": 'nsroot', + "networkdevicetype": 'NetscalerVPXLoadBalancer', + "publicinterface": '1/1', + "privateinterface": '1/1', + "numretries": 2, + "lbdevicededicated": False, + "lbdevicecapacity": 50, + "port": 22, + }, + "netscaler_2": { + "ipaddress": '192.168.100.100', + "username": 'nsroot', + "password": 'nsroot', + "networkdevicetype": 'NetscalerVPXLoadBalancer', + "publicinterface": '1/1', + "privateinterface": '1/1', + "numretries": 2, + "lbdevicededicated": False, + "lbdevicecapacity": 50, + "port": 22, + }, + "netscaler_3": { + "ipaddress": '192.168.100.101', + "username": 'nsroot', + "password": 'nsroot', + "networkdevicetype": 'NetscalerVPXLoadBalancer', + "publicinterface": '1/1', + "privateinterface": '1/1', + "numretries": 2, + "lbdevicededicated": False, + "lbdevicecapacity": 50, + "port": 22, + }, + "network_offering_dedicated": { + "name": 'Netscaler', + "displaytext": 'Netscaler', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "availability": 'Optional', + "specifyVlan": False, + "specifyIpRanges": False, + "serviceProviderList" : { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + "Vpn": 'VirtualRouter', + "Firewall": 'VirtualRouter', + "Lb": 'Netscaler', + "UserData": 'VirtualRouter', + "StaticNat": 'VirtualRouter', + }, + "servicecapabilitylist": { + "SourceNat": { + "SupportedSourceNatTypes": "peraccount" + }, + "lb": { + "SupportedLbIsolation": "dedicated" + }, + }, + }, + "network_offering": { + "name": 'Netscaler', + "displaytext": 'Netscaler', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "availability": 'Optional', + "serviceProviderList" : { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + "Vpn": 'VirtualRouter', + "Firewall": 'VirtualRouter', + "Lb": 'Netscaler', + "UserData": 'VirtualRouter', + "StaticNat": 'VirtualRouter', + }, + }, + "network": { + "name": "Netscaler", + "displaytext": "Netscaler", + }, + "lbrule": { + "name": "SSH", + "alg": "roundrobin", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 22, + "openfirewall": False, + }, + "ostypeid": '946b031b-0e10-4f4a-a3fc-d212ae2ea07f', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + "mode":'advanced' + } + + + +class TestAddMultipleNetScaler(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestAddMultipleNetScaler, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls._cleanup = [] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_add_netscaler_device(self): + """Test add netscaler device + """ + + # Validate the following + # 1. Add multiple instances of netscaler + # 2. Netscaler should be configured successfully. + + physical_networks = PhysicalNetwork.list( + self.apiclient, + zoneid=self.zone.id + ) + self.assertEqual( + isinstance(physical_networks, list), + True, + "There should be atleast one physical network for advanced zone" + ) + physical_network = physical_networks[0] + self.debug("Adding netscaler device: %s" % + self.services["netscaler_1"]["ipaddress"]) + netscaler_1 = NetScaler.add( + self.apiclient, + self.services["netscaler_1"], + physicalnetworkid=physical_network.id + ) + self.cleanup.append(netscaler_1) + self.debug("Checking if Netscaler network service provider is enabled?") + + nw_service_providers = NetworkServiceProvider.list( + self.apiclient, + name='Netscaler', + physicalnetworkid=physical_network.id + ) + self.assertEqual( + isinstance(nw_service_providers, list), + True, + "Network service providers list should not be empty" + ) + netscaler_provider = nw_service_providers[0] + if netscaler_provider.state != 'Enabled': + self.debug("Netscaler provider is not enabled. Enabling it..") + response = NetworkServiceProvider.update( + self.apiclient, + id=netscaler_provider.id, + state='Enabled' + ) + self.assertEqual( + response.state, + "Enabled", + "Network service provider should be in enabled state" + ) + else: + self.debug("Netscaler service provider is already enabled.") + + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=netscaler_1.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + self.assertEqual( + ns.physicalnetworkid, + physical_network.id, + "Physical network id should match with the network in which device is configured" + ) + + self.debug("Adding netscaler device: %s" % + self.services["netscaler_2"]["ipaddress"]) + netscaler_2 = NetScaler.add( + self.apiclient, + self.services["netscaler_2"], + physicalnetworkid=physical_network.id + ) + self.cleanup.append(netscaler_2) + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=netscaler_1.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + self.assertEqual( + ns.physicalnetworkid, + physical_network.id, + "Physical network id should match with the network in which device is configured" + ) + self.debug("Another Netscaler device is added!") + return + + +class TestAddMultipleNSDiffZone(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestAddMultipleNSDiffZone, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + cls._cleanup = [] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_add_mul_netscaler_diff_zone(self): + """Test add netscaler devices in different zones + """ + + # Validate the following + # 1. Add multiple instances of Netscaler in different zones + # 2. Netscaler should be configured successfully. + + # Check if there are multiple zones present in the given setup + zones = Zone.list(self.apiclient, listall=True) + self.assertEqual( + isinstance(zones, list), + True, + "List Zones API should return a valid list" + ) + + # Find the number of zones configured in advanced mode + zone_list = [] + for zone in zones: + if zone.networktype == 'Advanced': + zone_list.append(zone) + + self.assertGreater( + len(zone_list), + 1, + "Atleast 2 advanced mode zones should be present for this test" + ) + + physical_networks = PhysicalNetwork.list( + self.apiclient, + zoneid=zone_list[0].id + ) + self.assertEqual( + isinstance(physical_networks, list), + True, + "There should be atleast one physical network for advanced zone" + ) + physical_network = physical_networks[0] + self.debug("Adding netscaler device: %s" % + self.services["netscaler_1"]["ipaddress"]) + netscaler = NetScaler.add( + self.apiclient, + self.services["netscaler_1"], + physicalnetworkid=physical_network.id + ) + self.cleanup.append(netscaler_1) + self.debug("Checking if Netscaler network service provider is enabled?") + + nw_service_providers = NetworkServiceProvider.list( + self.apiclient, + name='Netscaler', + physicalnetworkid=physical_network.id + ) + self.assertEqual( + isinstance(nw_service_providers, list), + True, + "Network service providers list should not be empty" + ) + netscaler_provider = nw_service_providers[0] + if netscaler_provider.state != 'Enabled': + self.debug("Netscaler provider is not enabled. Enabling it..") + response = NetworkServiceProvider.update( + self.apiclient, + id=netscaler_provider.id, + state='Enabled' + ) + self.assertEqual( + response.state, + "Enabled", + "Network service provider should be in enabled state" + ) + else: + self.debug("Netscaler service provider is already enabled.") + + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=netscaler_1.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + self.assertEqual( + ns.physicalnetworkid, + physical_network.id, + "Physical network id should match with the network in which device is configured" + ) + + physical_networks = PhysicalNetwork.list( + self.apiclient, + zoneid=zone_list[1].id + ) + self.assertEqual( + isinstance(physical_networks, list), + True, + "There should be atleast one physical network for advanced zone" + ) + physical_network = physical_networks[0] + + self.debug("Adding netscaler device: %s" % + self.services["netscaler_2"]["ipaddress"]) + netscaler_2 = NetScaler.add( + self.apiclient, + self.services["netscaler_2"], + physicalnetworkid=physical_network.id + ) + self.cleanup.append(netscaler_2) + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=netscaler_2.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + self.assertEqual( + ns.physicalnetworkid, + physical_network.id, + "Physical network id should match with the network in which device is configured" + ) + self.debug("Another Netscaler device is added!") + return + + +class TestNetScalerSharedMode(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestNetScalerSharedMode, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + physical_networks = PhysicalNetwork.list( + cls.api_client, + zoneid=cls.zone.id + ) + if isinstance(physical_networks, list): + cls.physical_network = physical_networks[0] + cls.services["netscaler_1"]["lbdevicecapacity"] = 2 + cls.netscaler_1 = NetScaler.add( + cls.api_client, + cls.services["netscaler_1"], + physicalnetworkid=cls.physical_network.id + ) + + nw_service_providers = NetworkServiceProvider.list( + cls.api_client, + name='Netscaler', + physicalnetworkid=cls.physical_network.id + ) + if isinstance(nw_service_providers, list): + netscaler_provider = nw_service_providers[0] + + if netscaler_provider.state != 'Enabled': + response = NetworkServiceProvider.update( + cls.api_client, + id=netscaler_provider.id, + state='Enabled' + ) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.account_1 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls.account_2 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls.account_3 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls.account_4 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls.account_5 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup = [ + cls.service_offering, + cls.network_offering, + cls.account_1, + cls.account_2, + cls.account_3, + cls.account_5 + ] + cls.cleanup_devices = [cls.netscaler_1] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + interval = list_configurations( + cls.api_client, + name='network.gc.interval' + ) + wait = list_configurations( + cls.api_client, + name='network.gc.wait' + ) + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + cleanup_resources(cls.api_client, cls.cleanup_devices) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_01_netscaler_shared_mode(self): + """Test netscaler device in shared mode + """ + + # Validate the following + # 1. Add Netscaler device in shared mode with capacity 3 + # 2. Netscaler should be configured successfully.It should be able to + # service only 3 account. + + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=self.netscaler_1.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + # Creating network using the network offering created + self.debug("Creating network with network offering: %s" % + self.network_offering.id) + self.network_1 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_1.id) + + self.debug("Deploying VM in account: %s" % self.account_1.account.name) + + # Spawn an instance in that network + virtual_machine_1 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_1.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_1.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + self.network_2 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_2.id) + + self.debug("Deploying VM in account: %s" % self.account_2.account.name) + + # Spawn an instance in that network + virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_2.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_2.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + self.network_3 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_3.id) + self.debug("Deploying VM in account: %s" % self.account_3.account.name) + + with self.assertRaises(Exception): + # Spawn an instance in that network + virtual_machine_3 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_3.id)] + ) + + self.debug("Deploy VM failed as Netscaler device capacity is full!") + return + + def test_02_multiple_netscaler_capacilty(self): + """Test multiple netscaler devices with limited capacity + """ + + # Validate the following + # 1. Add another netscaler device and spawn a new VM again + # 2. VM deployement should be successful + + self.debug("Adding another netscaler device: %s" % + self.services["netscaler_2"]["ipaddress"]) + self.services["netscaler_2"]["lbdevicecapacity"] = 2 + netscaler_2 = NetScaler.add( + self.apiclient, + self.services["netscaler_2"], + physicalnetworkid=self.physical_network.id + ) + self.cleanup_devices.append(netscaler_2) + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=netscaler_2.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + self.assertEqual( + ns.physicalnetworkid, + self.physical_network.id, + "Physical network id should match with the network in which device is configured" + ) + self.debug("Another Netscaler device is added!") + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + networks = Network.list( + self.apiclient, + account=self.account_3.account.name, + domainid=self.account_3.account.domainid, + zoneid=self.zone.id, + listall=True + ) + self.assertEqual( + isinstance(networks, list), + True, + "Network should be present for the account: %s" % + self.account_3.account.name + ) + self.network_3 = networks[0] + self.debug("Created network with ID: %s" % self.network_3.id) + + self.debug("Deploying VM in account: %s" % self.account_3.account.name) + + # Spawn an instance in that network + virtual_machine_3 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_3.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_3.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + return + + def test_03_multiple_netscaler_full_capacilty(self): + """Test netscaler device with full capacity + """ + + # Validate the following + # 1. Spawn multiple instances for utilizing full capacity of Netscaler + # 2. Deploy VM should fail after capacity full in netscaler device + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + self.network_4 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_4.account.name, + domainid=self.account_4.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_4.id) + + self.debug("Deploying VM in account: %s" % self.account_4.account.name) + + # Spawn an instance in that network + virtual_machine_4 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_4.account.name, + domainid=self.account_4.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_4.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_4.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_4.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_4.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + self.network_5 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_5.account.name, + domainid=self.account_5.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_5.id) + + self.debug("Deploying VM in account: %s" % self.account_5.account.name) + + with self.assertRaises(Exception): + # Spawn an instance in that network + virtual_machine_5 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_5.account.name, + domainid=self.account_5.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_5.id)] + ) + self.debug("Deploy VM failed as Netscaler device capacity is full!") + return + + def test_04_delete_account_after_capacity_full(self): + """Test delete and add resouces after netscaler device capacity is full + """ + + # Validate the following + # 1. Delete one of the account. Wait till Network.gc.wait & + # network.gc.interval time + # 2. Create an instance from another account + # 3. Deploy instance should succeed + + self.debug("Delete account: %s" % self.account_4.account.name) + self.account_4.delete(self.apiclient) + self.debug("Account: %s is deleted" % self.account_4.account.name) + + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + self.debug("Sleeping for: network.gc.interval + network.gc.wait") + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering.id) + self.network_5 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_5.account.name, + domainid=self.account_5.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_5.id) + + self.debug("Deploying VM in account: %s" % self.account_5.account.name) + + # Spawn an instance in that network + virtual_machine_5 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_5.account.name, + domainid=self.account_5.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_5.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_5.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_5.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_5.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + return + + +class TestNwOffDedicatedNetscaler(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestNwOffDedicatedNetscaler, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + physical_networks = PhysicalNetwork.list( + cls.api_client, + zoneid=cls.zone.id + ) + if isinstance(physical_networks, list): + physical_network = physical_networks[0] + cls.services["netscaler_1"]["lbdevicecapacity"] = 3 + cls.netscaler = NetScaler.add( + cls.api_client, + cls.services["netscaler_1"], + physicalnetworkid=physical_network.id + ) + + nw_service_providers = NetworkServiceProvider.list( + cls.api_client, + name='Netscaler', + physicalnetworkid=physical_network.id + ) + if isinstance(nw_service_providers, list): + netscaler_provider = nw_service_providers[0] + + if netscaler_provider.state != 'Enabled': + response = NetworkServiceProvider.update( + cls.api_client, + id=netscaler_provider.id, + state='Enabled' + ) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering_dedicated"], + conservemode=True + ) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.network_offering, + cls.netscaler, + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.account_1 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.cleanup = [self.account_1] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_nw_off_dedicated_mode(self): + """Test network offering in dedicated mode device + """ + + # Validate the following + # 1. Add Netscaler device in shared mode + # 2. Create a network offering in dedicated mode. + # 3. Try to implemenent network with that network offering. Network + # craetion should fail. + + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=self.netscaler.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + # Creating network using the network offering created + self.debug("Creating network with network offering: %s" % + self.network_offering.id) + + self.network_1 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Deploy Instance with network: %s" % self.network_1.name) + with self.assertRaises(Exception): + # Spawn an instance in that network + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_1.id)] + ) + self.debug("Created instance failed!") + return + + +class TestNwOffNetscaler(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestNwOffNetscaler, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + physical_networks = PhysicalNetwork.list( + cls.api_client, + zoneid=cls.zone.id + ) + if isinstance(physical_networks, list): + physical_network = physical_networks[0] + cls.services["netscaler_1"]["lbdevicecapacity"] = 3 + cls.netscaler_1 = NetScaler.add( + cls.api_client, + cls.services["netscaler_1"], + physicalnetworkid=physical_network.id + ) + + cls.services["netscaler_2"].pop("lbdevicecapacity") + cls.services["netscaler_2"]["lbdevicededicated"] = True + cls.netscaler_2 = NetScaler.add( + cls.api_client, + cls.services["netscaler_2"], + physicalnetworkid=physical_network.id + ) + nw_service_providers = NetworkServiceProvider.list( + cls.api_client, + name='Netscaler', + physicalnetworkid=physical_network.id + ) + if isinstance(nw_service_providers, list): + netscaler_provider = nw_service_providers[0] + + if netscaler_provider.state != 'Enabled': + response = NetworkServiceProvider.update( + cls.api_client, + id=netscaler_provider.id, + state='Enabled' + ) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering_dedicated"], + conservemode=True + ) + cls.network_offering_shared = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.network_offering_shared.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.network_offering, + cls.network_offering_shared, + cls.netscaler_1, + cls.netscaler_2, + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.account_1 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_2 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_3 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.cleanup = [self.account_2, self.account_3] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_ns_shared_nw_dedicated(self): + """Test netscaler device in shared mode with network offering in dedicated mode + """ + + # Validate the following + # 1. Add Netscaler device in shared mode + # 2. Create a network offering in dedicated mode. + # 3. Try to implemenent network with that network offering. Network + # craetion should fail. + + ns_list = NetScaler.list( + self.apiclient, + lbdeviceid=self.netscaler_1.lbdeviceid + ) + self.assertEqual( + isinstance(ns_list, list), + True, + "NetScaler list should not be empty" + ) + ns = ns_list[0] + + self.assertEqual( + ns.lbdevicededicated, + False, + "NetScaler device is configured in shared mode" + ) + self.assertEqual( + ns.lbdevicestate, + "Enabled", + "NetScaler device state should be enabled" + ) + # Creating network using the network offering created + self.debug("Creating network with network offering: %s" % + self.network_offering.id) + self.network = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Deploying VM in account: %s" % self.account_1.account.name) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network.id)] + ) + # Creating network using the network offering created + self.debug("Creating different network with network offering: %s" % + self.network_offering.id) + + self.network_2 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_2.id) + with self.assertRaises(Exception): + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_2.id)] + ) + self.debug( + "Attempt to create second network with dedicated network offering failed!") + self.debug("Deleting account: %s" % self.account_1.account.name) + self.account_1.delete(self.apiclient) + self.debug("Account: %s deleted!" % self.account_1.account.name) + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + self.debug("Sleeping for: network.gc.interval + network.gc.wait") + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + + self.debug("Deploying VM in account: %s" % self.account_2.account.name) + + # Spawn an instance in that network + virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_2.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_2.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering_shared.id) + self.network_3 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + networkofferingid=self.network_offering_shared.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_3.id) + + self.debug("Deploying VM in account: %s" % self.account_3.account.name) + + # Spawn an instance in that network + virtual_machine_3 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_3.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_3.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + return + + +class TestNwOffSToDUpgrade(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestNwOffSToDUpgrade, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + physical_networks = PhysicalNetwork.list( + cls.api_client, + zoneid=cls.zone.id + ) + if isinstance(physical_networks, list): + cls.physical_network = physical_networks[0] + cls.services["netscaler_1"]["lbdevicecapacity"] = 3 + cls.netscaler_1 = NetScaler.add( + cls.api_client, + cls.services["netscaler_1"], + physicalnetworkid=cls.physical_network.id + ) + + cls.services["netscaler_2"].pop("lbdevicecapacity") + cls.services["netscaler_2"]["lbdevicededicated"] = True + cls.netscaler_2 = NetScaler.add( + cls.api_client, + cls.services["netscaler_2"], + physicalnetworkid=cls.physical_network.id + ) + + nw_service_providers = NetworkServiceProvider.list( + cls.api_client, + name='Netscaler', + physicalnetworkid=cls.physical_network.id + ) + if isinstance(nw_service_providers, list): + netscaler_provider = nw_service_providers[0] + + if netscaler_provider.state != 'Enabled': + response = NetworkServiceProvider.update( + cls.api_client, + id=netscaler_provider.id, + state='Enabled' + ) + cls.network_offering_dedicated = NetworkOffering.create( + cls.api_client, + cls.services["network_offering_dedicated"], + conservemode=True + ) + cls.network_offering_shared = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + # Enable Network offering + cls.network_offering_dedicated.update(cls.api_client, state='Enabled') + cls.network_offering_shared.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.network_offering_dedicated, + cls.network_offering_shared, + cls.netscaler_1, + cls.netscaler_2, + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.account_1 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_2 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_3 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.cleanup = [self.account_1, self.account_2, self.account_3] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_shared_to_dedicated_upgrade(self): + """Test upgrade from shared LB isolation to dedicated LB isolation""" + + # Validate the following + # 1. Create a dedicated and shared network offering + # 2. Configure 2 instances of Netscaler one with dedicated and other + # shared mode + # 3. Deploy instance with shared network offering in account 1. create + # LB rules + # 4. Deploy instance with shared network offering in account 2. create + # LB rules + # 5. Deploy instance with dedicated network offering in account 3. + # Create Lb rules. + # 6. Configure another instace of netscaler in dedicated mode + # 7. upgrade networkj for user 1 to dedicated network offering. + # Create LB rules. LB rule creation should be successful + + # Creating network using the network offering created + self.debug("Creating network with network offering: %s" % + self.network_offering_shared.id) + self.network_1 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + networkofferingid=self.network_offering_shared.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_1.id) + + self.debug("Deploying VM in account: %s" % self.account_1.account.name) + + # Spawn an instance in that network + virtual_machine_1 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_1.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_1.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering_shared.id) + self.network_2 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + networkofferingid=self.network_offering_shared.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_2.id) + + self.debug("Deploying VM in account: %s" % self.account_2.account.name) + + # Spawn an instance in that network + virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_2.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_2.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering_dedicated.id) + self.network_3 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + networkofferingid=self.network_offering_dedicated.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_3.id) + self.debug("Deploying VM in account: %s" % self.account_3.account.name) + + # Spawn an instance in that network + virtual_machine_3 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_3.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_3.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + self.debug("Configuring another Netscaler device in dedicated mode") + + self.services["netscaler_3"].pop("lbdevicecapacity") + self.services["netscaler_3"]["lbdevicededicated"] = True + self.netscaler_3 = NetScaler.add( + self.apiclient, + self.services["netscaler_3"], + physicalnetworkid=self.physical_network.id + ) + + self.debug("Stopping All VMs before upgrading network for account: %s" % + self.account_1.account.name) + virtual_machine_1.stop(self.apiclient) + + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM state should be running after deployment" + ) + self.debug("All Vms are in stopped state") + self.debug("Upgrading the network: %s" % self.network_1.id) + self.network_1.update( + self.apiclient, + networkofferingid=self.network_offering_dedicated.id, + changecidr=True + ) + networks = Network.list( + self.apiclient, + id=self.network_1.id, + listall=True + ) + self.assertEqual( + isinstance(networks, list), + True, + "List Networks should return a valid list for given network ID" + ) + self.assertNotEqual( + len(networks), + 0, + "Length of list networks should not be 0" + ) + network = networks[0] + self.assertEqual( + network.networkofferingid, + self.network_offering_dedicated.id, + "Network offering ID should match with new offering ID" + ) + + self.debug("Starting All VMs after upgrading network for account: %s" % + self.account_1.account.name) + virtual_machine_1.start(self.apiclient) + + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + self.debug("All Vms are in running state") + try: + self.debug( + "Associating public Ip to the network: %s" % + self.network_1.name) + + public_ip = PublicIPAddress.create( + self.apiclient, + accountid=self.account_1.account.name, + zoneid=self.zone.id, + domainid=self.account_1.account.domainid, + networkid=self.network_1.id + ) + self.debug( + "Creating LB rule for IP address: %s with round robin algo" % + public_ip.ipaddress.ipaddress) + + lb_rule = LoadBalancerRule.create( + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account_1.account.name, + networkid=self.network_1.id + ) + self.debug("Created the load balancing rule for public IP: %s" % + public_ip.ipaddress.ipaddress) + except Exception as e: + self.fail("Failed to create load balancing rule - %s" % e) + return + + +class TestNwOffDToSUpgrade(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.api_client = super( + TestNwOffDToSUpgrade, + cls + ).getClsTestClient().getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.services) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostypeid"] + ) + + physical_networks = PhysicalNetwork.list( + cls.api_client, + zoneid=cls.zone.id + ) + if isinstance(physical_networks, list): + cls.physical_network = physical_networks[0] + cls.services["netscaler_1"]["lbdevicecapacity"] = 3 + cls.netscaler_1 = NetScaler.add( + cls.api_client, + cls.services["netscaler_1"], + physicalnetworkid=cls.physical_network.id + ) + + cls.services["netscaler_2"].pop("lbdevicecapacity") + cls.services["netscaler_2"]["lbdevicededicated"] = True + cls.netscaler_2 = NetScaler.add( + cls.api_client, + cls.services["netscaler_2"], + physicalnetworkid=cls.physical_network.id + ) + + nw_service_providers = NetworkServiceProvider.list( + cls.api_client, + name='Netscaler', + physicalnetworkid=cls.physical_network.id + ) + if isinstance(nw_service_providers, list): + netscaler_provider = nw_service_providers[0] + + if netscaler_provider.state != 'Enabled': + response = NetworkServiceProvider.update( + cls.api_client, + id=netscaler_provider.id, + state='Enabled' + ) + cls.network_offering_dedicated = NetworkOffering.create( + cls.api_client, + cls.services["network_offering_dedicated"], + conservemode=True + ) + cls.network_offering_shared = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + # Enable Network offering + cls.network_offering_dedicated.update(cls.api_client, state='Enabled') + cls.network_offering_shared.update(cls.api_client, state='Enabled') + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [ + cls.service_offering, + cls.network_offering_dedicated, + cls.network_offering_shared, + cls.netscaler_1, + cls.netscaler_2, + ] + return + + @classmethod + def tearDownClass(cls): + try: + #Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.account_1 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_2 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.account_3 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + self.cleanup = [self.account_1, self.account_2, self.account_3] + return + + def tearDown(self): + try: + self.debug("Cleaning up the resources") + #Clean up, terminate the created network offerings + cleanup_resources(self.apiclient, self.cleanup) + interval = list_configurations( + self.apiclient, + name='network.gc.interval' + ) + wait = list_configurations( + self.apiclient, + name='network.gc.wait' + ) + # Sleep to ensure that all resources are deleted + time.sleep(int(interval[0].value) + int(wait[0].value)) + self.debug("Cleanup complete!") + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def test_shared_to_dedicated_upgrade(self): + """Test upgrade from shared LB isolation to dedicated LB isolation""" + + # Validate the following + # 1. Create a dedicated and shared network offering + # 2. Configure 2 instances of Netscaler one with dedicated and other + # shared mode + # 3. Deploy instance with shared network offering in account 1. create + # LB rules + # 4. Deploy instance with shared network offering in account 2. create + # LB rules + # 5. Deploy instance with dedicated network offering in account 3. + # Create Lb rules. + # 6. Configure another instace of netscaler in dedicated mode + # 7. upgrade networkj for user 1 to dedicated network offering. + # Create LB rules. LB rule creation should be successful + + # Creating network using the network offering created + self.debug("Creating network with network offering: %s" % + self.network_offering_shared.id) + self.network_1 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + networkofferingid=self.network_offering_shared.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_1.id) + + self.debug("Deploying VM in account: %s" % self.account_1.account.name) + + # Spawn an instance in that network + virtual_machine_1 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_1.account.name, + domainid=self.account_1.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_1.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_1.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_1.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_1.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering_shared.id) + self.network_2 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + networkofferingid=self.network_offering_shared.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_2.id) + + self.debug("Deploying VM in account: %s" % self.account_2.account.name) + + # Spawn an instance in that network + virtual_machine_2 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_2.account.name, + domainid=self.account_2.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_2.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_2.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_2.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_2.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + # Creating network using the network offering created + self.debug("Trying to create network with network offering: %s" % + self.network_offering_dedicated.id) + self.network_3 = Network.create( + self.apiclient, + self.services["network"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + networkofferingid=self.network_offering_dedicated.id, + zoneid=self.zone.id + ) + self.debug("Created network with ID: %s" % self.network_3.id) + self.debug("Deploying VM in account: %s" % self.account_3.account.name) + + # Spawn an instance in that network + virtual_machine_3 = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + accountid=self.account_3.account.name, + domainid=self.account_3.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(self.network_3.id)] + ) + self.debug("Deployed VM in network: %s" % self.network_3.id) + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + + self.debug("Stopping all VMs in account: %s" % self.account_3.account.name) + virtual_machine_3.stop(self.apiclient) + + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Stopped", + "VM state should be stopped" + ) + self.debug("All user VMs stopped") + self.debug("Upgrading the network: %s" % self.network_3.id) + self.network_3.update( + self.apiclient, + networkofferingid=self.network_offering_shared.id, + changecidr=True + ) + networks = Network.list( + self.apiclient, + id=self.network_3.id, + listall=True + ) + self.assertEqual( + isinstance(networks, list), + True, + "List Networks should return a valid list for given network ID" + ) + self.assertNotEqual( + len(networks), + 0, + "Length of list networks should not be 0" + ) + network = networks[0] + self.assertEqual( + network.networkofferingid, + self.network_offering_shared.id, + "Network offering ID should match with new offering ID" + ) + self.debug("Starting instances in account: %s" % self.account_3.account.name) + virtual_machine_3.start(self.apiclient) + + list_vm_response = VirtualMachine.list( + self.apiclient, + id=virtual_machine_3.id + ) + + self.debug( + "Verify listVirtualMachines response for virtual machine: %s" \ + % virtual_machine_3.id + ) + + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + + self.assertEqual( + vm_response.state, + "Running", + "VM state should be running after deployment" + ) + try: + self.debug( + "Associating public Ip to the network: %s" % + self.network_3.name) + + public_ip = PublicIPAddress.create( + self.apiclient, + accountid=self.account_3.account.name, + zoneid=self.zone.id, + domainid=self.account_3.account.domainid, + networkid=self.network_3.id + ) + self.debug( + "Creating LB rule for IP address: %s with round robin algo" % + public_ip.ipaddress.ipaddress) + + lb_rule = LoadBalancerRule.create( + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account_3.account.name, + networkid=self.network_3.id + ) + self.debug("Created the load balancing rule for public IP: %s" % + public_ip.ipaddress.ipaddress) + except Exception as e: + self.fail("Failed to create load balancing rule - %s" % e) + return diff --git a/test/integration/lib/base.py b/test/integration/lib/base.py index 04adbc9a030..336a453c546 100644 --- a/test/integration/lib/base.py +++ b/test/integration/lib/base.py @@ -171,7 +171,8 @@ class VirtualMachine: @classmethod def create(cls, apiclient, services, templateid=None, accountid=None, domainid=None, networkids=None, serviceofferingid=None, - securitygroupids=None, projectid=None, mode='basic'): + securitygroupids=None, projectid=None, startvm=None, + diskofferingid=None, mode='basic'): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -204,7 +205,9 @@ class VirtualMachine: elif "template" in services: cmd.templateid = services["template"] - if "diskoffering" in services: + if diskofferingid: + cmd.diskofferingid = diskofferingid + elif "diskoffering" in services: cmd.diskofferingid = services["diskoffering"] if securitygroupids: @@ -216,8 +219,16 @@ class VirtualMachine: if projectid: cmd.projectid = projectid + if startvm is not None: + cmd.startvm = startvm + virtual_machine = apiclient.deployVirtualMachine(cmd) + if startvm == False: + virtual_machine.ssh_ip = virtual_machine.nic[0].ipaddress + virtual_machine.public_ip = virtual_machine.nic[0].ipaddress + return VirtualMachine(virtual_machine.__dict__, services) + # VM should be in Running state after deploy timeout = 10 while True: @@ -328,6 +339,26 @@ class VirtualMachine: cmd.id = volume.id return apiclient.detachVolume(cmd) + def attach_iso(self, apiclient, iso): + """Attach ISO to instance""" + cmd = attachIso.attachIsoCmd() + cmd.id = iso.id + cmd.virtualmachineid = self.id + return apiclient.attachIso(cmd) + + def detach_iso(self, apiclient): + """Detach ISO to instance""" + cmd = detachIso.detachIsoCmd() + cmd.id = self.id + return apiclient.detachIso(cmd) + + def change_service_offering(self, apiclient, serviceOfferingId): + """Change service offering of the instance""" + cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() + cmd.id = self.id + cmd.serviceofferingid = serviceOfferingId + return apiclient.changeServiceForVirtualMachine(cmd) + @classmethod def list(cls, apiclient, **kwargs): """List all VMs matching criteria""" @@ -343,10 +374,8 @@ class VirtualMachine: cmd.id = self.id try: response = apiclient.resetPasswordForVirtualMachine(cmd) - print response except Exception as e: raise Exception("Reset Password failed! - %s" % e) - print type(response) if isinstance(response, list): return response[0].password @@ -685,7 +714,6 @@ class Iso: response = iso_response[0] # Again initialize timeout to avoid listISO failure timeout = 5 - print response.status # Check whether download is in progress(for Ex:10% Downloaded) # or ISO is 'Successfully Installed' if response.status == 'Successfully Installed': @@ -1006,10 +1034,10 @@ class NetworkOffering: 'provider': provider }) if "servicecapabilitylist" in services: - cmd.servicecapabilitylist = [] + cmd.serviceCapabilityList = [] for service, capability in services["servicecapabilitylist"].items(): for ctype, value in capability.items(): - cmd.servicecapabilitylist.append({ + cmd.serviceCapabilityList.append({ 'service': service, 'capabilitytype': ctype, 'capabilityvalue': value @@ -1018,6 +1046,7 @@ class NetworkOffering: cmd.specifyVlan = services["specifyVlan"] if "specifyIpRanges" in services: cmd.specifyIpRanges = services["specifyIpRanges"] + cmd.availability = 'Optional' [setattr(cmd, k, v) for k, v in kwargs.items()] @@ -1172,19 +1201,19 @@ class LoadBalancerRule: for name, value in param.items(): cmd.param.append({'name': name, 'value': value}) return apiclient.createLBStickinessPolicy(cmd) - + def deleteSticky(self, apiclient, id): """Deletes stickyness policy""" - + cmd = deleteLBStickinessPolicy.deleteLBStickinessPolicyCmd() cmd.id = id return apiclient.deleteLBStickinessPolicy(cmd) - + @classmethod def listStickyPolicies(cls, apiclient, lbruleid, **kwargs): """Lists stickiness policies for load balancing rule""" - - cmd= listLBStickinessPolicies.listLBStickinessPoliciesCmd() + + cmd = listLBStickinessPolicies.listLBStickinessPoliciesCmd() cmd.lbruleid = lbruleid [setattr(cmd, k, v) for k, v in kwargs.items()] return apiclient.listLBStickinessPolicies(cmd) @@ -1443,7 +1472,7 @@ class Network: cmd = restartNetwork.restartNetworkCmd() cmd.id = self.id if cleanup: - cmd.cleanup = cleanup + cmd.cleanup = cleanup return(apiclient.restartNetwork(cmd)) @classmethod @@ -2090,3 +2119,55 @@ class NetworkServiceProvider: cmd = listNetworkServiceProviders.listNetworkServiceProvidersCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listNetworkServiceProviders(cmd)) + +class Router: + """Manage router life cycle""" + + def __init__(self, items): + self.__dict__.update(items) + + @classmethod + def start(cls, apiclient, id): + """Starts the router""" + cmd = startRouter.startRouterCmd() + cmd.id = id + return apiclient.startRouter(cmd) + + @classmethod + def stop(cls, apiclient, id, forced=None): + """Stops the router""" + cmd = stopRouter.stopRouterCmd() + cmd.id = id + if forced: + cmd.forced = forced + return apiclient.stopRouter(cmd) + + @classmethod + def reboot(cls, apiclient, id): + """Reboots the router""" + cmd = rebootRouter.rebootRouterCmd() + cmd.id = id + return apiclient.rebootRouter(cmd) + + @classmethod + def destroy(cls, apiclient, id): + """Destroy the router""" + cmd = destroyRouter.destroyRouterCmd() + cmd.id = id + return apiclient.destroyRouter(cmd) + + @classmethod + def change_service_offering(cls, apiclient, id, serviceofferingid): + """Change service offering of the router""" + cmd = changeServiceForRouter.changeServiceForRouterCmd() + cmd.id = id + cmd.serviceofferingid = serviceofferingid + return apiclient.changeServiceForRouter(cmd) + + @classmethod + def list(cls, apiclient, **kwargs): + """List routers""" + + cmd = listRouters.listRoutersCmd() + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.listRouters(cmd))