diff --git a/test/integration/component/test_lb_secondary_ip.py b/test/integration/component/test_lb_secondary_ip.py index 23ff1eee537..b4f6ed09e32 100644 --- a/test/integration/component/test_lb_secondary_ip.py +++ b/test/integration/component/test_lb_secondary_ip.py @@ -49,7 +49,8 @@ from marvin.lib.common import (get_domain, get_template, verifyNetworkState, wait_for_cleanup, - add_netscaler + add_netscaler, + GetNetscalerInfoFromConfig ) from marvin.lib.utils import (validateList, @@ -1775,11 +1776,18 @@ class TestExternalLoadBalancer(cloudstackTestCase): cls.testdata["virtual_machine"]["template"] = template.id cls._cleanup = [] + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.testdata["netscaler"] = response[0] + cls.testdata["netscaler"]["lbdevicededicated"] = False + try: cls.netscaler = add_netscaler( cls.api_client, cls.zone.id, - cls.testdata["netscaler_VPX"]) + cls.testdata["netscaler"]) cls._cleanup.append(cls.netscaler) except Exception as e: raise unittest.SkipTest("Failed to add netscaler device: %s" % e) diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py index 4c99aa36d43..e3d65bbb4e2 100644 --- a/test/integration/component/test_netscaler_lb.py +++ b/test/integration/component/test_netscaler_lb.py @@ -17,7 +17,7 @@ """ P1 tests for netscaler load balancing """ -#Import Local Modules +# Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackAPI import migrateVirtualMachine @@ -36,126 +36,117 @@ from marvin.lib.base import (Account, from marvin.lib.common import (get_domain, get_zone, get_template, + GetNetscalerInfoFromConfig, add_netscaler) from marvin.sshClient import SshClient import time 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": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "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": { - "ipaddress": '10.147.40.100', - "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, - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "protocol": "TCP" - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - "mode": 'advanced' - } + }, + "virtual_machine": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "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, + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "protocol": "TCP" + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + "mode": 'advanced' + } + class TestLbSourceNat(cloudstackTestCase): @@ -170,35 +161,43 @@ class TestLbSourceNat(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -208,27 +207,27 @@ class TestLbSourceNat(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -236,12 +235,11 @@ class TestLbSourceNat(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_add_lb_on_source_nat(self): """Test Create LB rule for sourceNat IP address """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -251,120 +249,121 @@ class TestLbSourceNat(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) src_nat_list = PublicIPAddress.list( - self.apiclient, - associatednetworkid=self.network.id, - account=self.account.name, - domainid=self.account.domainid, - listall=True, - issourcenat=True, - ) + self.apiclient, + associatednetworkid=self.network.id, + account=self.account.name, + domainid=self.account.domainid, + listall=True, + issourcenat=True, + ) self.assertEqual( - isinstance(src_nat_list, list), - True, - "List Public IP should return a valid source NAT" - ) + isinstance(src_nat_list, list), + True, + "List Public IP should return a valid source NAT" + ) self.assertNotEqual( - len(src_nat_list), - 0, - "Length of response from listPublicIp should not be 0" - ) + len(src_nat_list), + 0, + "Length of response from listPublicIp should not be 0" + ) src_nat = src_nat_list[0] self.debug("Trying to create LB rule on source NAT IP: %s" % - src_nat.ipaddress) + src_nat.ipaddress) # Create Load Balancer rule with source NAT with self.assertRaises(Exception): LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=src_nat.id, - accountid=self.account.name - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=src_nat.id, + accountid=self.account.name + ) return + class TestLbOnIpWithPf(cloudstackTestCase): @classmethod @@ -378,36 +377,44 @@ class TestLbOnIpWithPf(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -417,27 +424,27 @@ class TestLbOnIpWithPf(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -445,12 +452,11 @@ class TestLbOnIpWithPf(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_on_ip_with_pf(self): """Test Create LB rule for sourceNat IP address """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -460,120 +466,120 @@ class TestLbOnIpWithPf(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Associating public IP for network: %s" % self.network.id) ip_with_nat_rule = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_nat_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_nat_rule.ipaddress.ipaddress, + self.network.id + )) self.debug("Creating PF rule for IP address: %s" % - ip_with_nat_rule.ipaddress.ipaddress) + ip_with_nat_rule.ipaddress.ipaddress) NATRule.create( - self.apiclient, - virtual_machine_1, - self.services["natrule"], - ipaddressid=ip_with_nat_rule.ipaddress.id - ) + self.apiclient, + virtual_machine_1, + self.services["natrule"], + ipaddressid=ip_with_nat_rule.ipaddress.id + ) self.debug("Trying to create LB rule on IP with NAT: %s" % - ip_with_nat_rule.ipaddress.ipaddress) + ip_with_nat_rule.ipaddress.ipaddress) # Create Load Balancer rule on IP already having NAT rule with self.assertRaises(Exception): - LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_nat_rule.ipaddress.id, - accountid=self.account.name - ) + LoadBalancerRule.create( + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_nat_rule.ipaddress.id, + accountid=self.account.name + ) return @@ -590,36 +596,44 @@ class TestPfOnIpWithLb(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -629,27 +643,27 @@ class TestPfOnIpWithLb(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -657,12 +671,12 @@ class TestPfOnIpWithLb(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_pf_on_ip_with_lb(self): - """Test Create a port forwarding rule on an Ip address that already has a LB rule. + """Test Create a port forwarding rule on an Ip address + that already has a LB rule. """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -672,121 +686,121 @@ class TestPfOnIpWithLb(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + 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( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug("Creating LB rule for IP address: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) with self.assertRaises(Exception): NATRule.create( - self.apiclient, - virtual_machine_1, - self.services["natrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id - ) + self.apiclient, + virtual_machine_1, + self.services["natrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id + ) return @@ -803,36 +817,44 @@ class TestLbOnNonSourceNat(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - cls.network_offering = NetworkOffering.create( - cls.api_client, - cls.services["network_offering"], - conservemode=False - ) - # 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=False + ) + # 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -842,27 +864,27 @@ class TestLbOnNonSourceNat(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -870,12 +892,11 @@ class TestLbOnNonSourceNat(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_on_non_source_nat(self): """Test Create LB rule for non-sourceNat IP address """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -885,124 +906,124 @@ class TestLbOnNonSourceNat(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + 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( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug("Creating LB rule for IP address: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) return @@ -1019,36 +1040,44 @@ class TestAddMultipleVmsLb(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1058,27 +1087,27 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -1086,12 +1115,11 @@ class TestAddMultipleVmsLb(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_add_multiple_vms_lb(self): """Test Add multiple Vms to an existing LB rule. """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -1106,151 +1134,151 @@ class TestAddMultipleVmsLb(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + 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( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug("Creating LB rule for IP address: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Trying to create PF rule on IP with LB rule: %s" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Assigning virtual machines to LB rule") lb_rule.assign(self.apiclient, [virtual_machine_1, virtual_machine_2]) self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - 22, - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + 22, + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) self.debug("command: show server") res = ssh_client.execute("show server") result = str(res) self.debug("Output: %s" % result) self.assertEqual( - result.count(virtual_machine_1.ipaddress), - 2, - "Server must be configured for virtual machines" - ) + result.count(virtual_machine_1.ipaddress), + 2, + "Server must be configured for virtual machines" + ) self.assertEqual( - result.count(virtual_machine_2.ipaddress), - 2, - "Server must be configured for virtual machines" - ) + result.count(virtual_machine_2.ipaddress), + 2, + "Server must be configured for virtual machines" + ) self.debug("Command:show service") res = ssh_client.execute("show service") @@ -1259,15 +1287,15 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(virtual_machine_1.ipaddress), - 3, - "Service must be configured for virtual machines" - ) + result.count(virtual_machine_1.ipaddress), + 3, + "Service must be configured for virtual machines" + ) self.assertEqual( - result.count(virtual_machine_2.ipaddress), - 3, - "Service must be configured for virtual machines" - ) + result.count(virtual_machine_2.ipaddress), + 3, + "Service must be configured for virtual machines" + ) self.debug("Command:show lb vserver") res = ssh_client.execute("show lb vserver") @@ -1275,15 +1303,16 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(ip_with_lb_rule.ipaddress.ipaddress), - 2, - "virtual server must be configured for public IP address" - ) + result.count(ip_with_lb_rule.ipaddress.ipaddress), + 2, + "virtual server must be configured for public IP address" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return + class TestMultipleLbRules(cloudstackTestCase): @classmethod @@ -1297,37 +1326,45 @@ class TestMultipleLbRules(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1337,27 +1374,27 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -1365,12 +1402,11 @@ class TestMultipleLbRules(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_multiple_lb_publicip(self): """Test Create multiple LB rules using different public Ips acquired """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -1381,188 +1417,188 @@ class TestMultipleLbRules(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug( - "Associating first public IP for network: %s" % - self.network.id) + "Associating first public IP for network: %s" % + self.network.id) public_ip_1 = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - public_ip_1.ipaddress.ipaddress, - self.network.id - )) + public_ip_1.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - public_ip_1.ipaddress.ipaddress) + public_ip_1.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip_1.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip_1.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + 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 - )) + virtual_machine_1.name, + virtual_machine_2.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [virtual_machine_1, virtual_machine_2]) self.debug( - "Associating second public IP for network: %s" % - self.network.id) + "Associating second public IP for network: %s" % + self.network.id) public_ip_2 = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - public_ip_2.ipaddress.ipaddress, - self.network.id - )) + public_ip_2.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - public_ip_2.ipaddress.ipaddress) + public_ip_2.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip_2.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip_2.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Trying to create PF rule on IP with LB rule: %s" % - public_ip_2.ipaddress.ipaddress) + public_ip_2.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + 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 - )) + 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 VMs are accessible with different public Ips") + "Verifying VMs are accessible with different public Ips") hostnames = [] ssh = virtual_machine_1.get_ssh_client( - ipaddress=public_ip_1.ipaddress.ipaddress) + ipaddress=public_ip_1.ipaddress.ipaddress) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -1573,16 +1609,16 @@ class TestMultipleLbRules(cloudstackTestCase): res, [virtual_machine_1.name, virtual_machine_2.name], "The hostname should match with atleast one of instance name" - ) + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - public_ip_1.ipaddress.ipaddress, - e)) + public_ip_1.ipaddress.ipaddress, + e)) try: ssh = virtual_machine_1.get_ssh_client( - ipaddress=public_ip_2.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=public_ip_2.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -1594,11 +1630,11 @@ class TestMultipleLbRules(cloudstackTestCase): res, [virtual_machine_1.name, virtual_machine_2.name], "The hostname should match with atleast one of instance name" - ) + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - public_ip_2.ipaddress.ipaddress, - e)) + public_ip_2.ipaddress.ipaddress, + e)) return @@ -1607,7 +1643,9 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.testClient = super(TestMultipleLbRulesSameIp, cls).getClsTestClient() + cls.testClient = super( + TestMultipleLbRulesSameIp, + cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services @@ -1615,37 +1653,44 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1655,27 +1700,27 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = Configurations.list( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = Configurations.list( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -1683,12 +1728,11 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_multiple_lb_same_publicip(self): """Test Create multiple LB rules using same public Ips on diff ports """ - # Validate the following # 1. Deploy the first VM using a network from the above created # Network offering. @@ -1700,192 +1744,192 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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_1.id - ) + self.apiclient, + id=virtual_machine_1.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_1.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug("Deploying another VM in account: %s" % - self.account.name) + self.account.name) # Spawn an instance in that network virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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.apiclient, + id=virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % virtual_machine_2.id - ) + "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" - ) + 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" - ) + vm_response.state, + "Running", + "VM state should be running after deployment" + ) self.debug( - "Associating first public IP for network: %s" % - self.network.id) + "Associating first public IP for network: %s" % + self.network.id) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - public_ip.ipaddress.ipaddress, - self.network.id - )) + public_ip.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule_1 = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Trying to create PF rule on IP with LB rule: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule_1.id, - listall=True - ) + self.apiclient, + id=lb_rule_1.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + 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_1.name - )) + virtual_machine_1.name, + virtual_machine_2.name, + lb_rule_1.name + )) lb_rule_1.assign(self.apiclient, [ - virtual_machine_1, - virtual_machine_2 - ]) + virtual_machine_1, + virtual_machine_2 + ]) self.debug( "Trying to create LB rule on IP: %s with on same ports" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) with self.assertRaises(Exception): LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.debug("Create LB rule on same port failed!") self.debug("Creating LB rule on IP: %s & public port: %s" % ( - public_ip.ipaddress.ipaddress, - str(2222))) + public_ip.ipaddress.ipaddress, + str(2222))) self.services["lbrule"]["alg"] = 'roundrobin' self.services["lbrule"]["publicport"] = 2222 self.services["lbrule"]["name"] = 'SSH2' lb_rule_2 = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule_2.id, - listall=True - ) + self.apiclient, + id=lb_rule_2.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + 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_2.name - )) + virtual_machine_1.name, + virtual_machine_2.name, + lb_rule_2.name + )) lb_rule_2.assign(self.apiclient, [ - virtual_machine_1, - virtual_machine_2 - ]) + virtual_machine_1, + virtual_machine_2 + ]) try: self.debug("Verifying VMs are accessible on all LB rules") hostnames = [] ssh = virtual_machine_1.get_ssh_client( - ipaddress=public_ip.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=public_ip.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -1896,17 +1940,17 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): res, [virtual_machine_1.name, virtual_machine_2.name], "The hostname should match with atleast one of instance name" - ) + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - public_ip.ipaddress.ipaddress, - e)) + public_ip.ipaddress.ipaddress, + e)) try: ssh = virtual_machine_1.get_ssh_client( - ipaddress=public_ip.ipaddress.ipaddress, - reconnect=True, - port=self.services["lbrule"]["publicport"] - ) + ipaddress=public_ip.ipaddress.ipaddress, + reconnect=True, + port=self.services["lbrule"]["publicport"] + ) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -1918,11 +1962,11 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): res, [virtual_machine_1.name, virtual_machine_2.name], "The hostname should match with atleast one of instance name" - ) + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - public_ip.ipaddress.ipaddress, - e)) + public_ip.ipaddress.ipaddress, + e)) return @@ -1939,76 +1983,84 @@ class TestLoadBalancingRule(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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 = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - # Creating network using the network offering created - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.network_offering.id, - zoneid=cls.zone.id - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + # Creating network using the network offering created + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + networkofferingid=cls.network_offering.id, + zoneid=cls.zone.id + ) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) - cls.lb_rule = LoadBalancerRule.create( - cls.api_client, - cls.services["lbrule"], - ipaddressid=cls.public_ip.ipaddress.id, - accountid=cls.account.name, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) + cls.lb_rule = LoadBalancerRule.create( + cls.api_client, + cls.services["lbrule"], + ipaddressid=cls.public_ip.ipaddress.id, + accountid=cls.account.name, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -2023,19 +2075,18 @@ class TestLoadBalancingRule(cloudstackTestCase): def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # 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 - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_01_edit_name_lb_rule(self): """Test edit name of LB rule """ - # Validate the following # 1. Create an Lb rule for couple of Vms . # 2. Edit the name of the existing LB rule. When all the existing @@ -2052,46 +2103,48 @@ class TestLoadBalancingRule(cloudstackTestCase): lb_rules = LoadBalancerRule.list(self.apiclient, id=self.lb_rule.id) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB call should return a valid list" - ) + isinstance(lb_rules, list), + True, + "List LB call should return a valid list" + ) lb = lb_rules[0] self.assertEqual( - lb.name, - new_name, - "LB name should be updated with the new name" - ) + lb.name, + new_name, + "LB name should be updated with the new name" + ) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_02_edit_lb_ports(self): """Test edit public port of LB rule """ - # Validate the following # 1. Create an Lb rule for couple of Vms . # 2. Edit the public/private of the existing LB rule. When all the # existing Lbrules are listed, this should not be allowed. - self.debug("Editing public port of the LB rule: %s" % self.lb_rule.name) + self.debug( + "Editing public port of the LB rule: %s" % + self.lb_rule.name) port = 8888 with self.assertRaises(Exception): self.lb_rule.update(self.apiclient, publicport=port) - self.debug("Editing private port of the LB rule: %s" % self.lb_rule.name) + self.debug( + "Editing private port of the LB rule: %s" % + self.lb_rule.name) with self.assertRaises(Exception): self.lb_rule.update(self.apiclient, privateport=port) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_03_delete_lb_rule(self): """Test delete LB rule """ - # Validate the following # 1. Delete existing load balancing rule # 2. In netscaler service and port corresponding to LB rule should get @@ -2103,24 +2156,24 @@ class TestLoadBalancingRule(cloudstackTestCase): self.debug("SSH into Netscaler to verify other resources are deleted") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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, - self.lb_rule.publicport) + self.public_ip.ipaddress.ipaddress, + self.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("ERROR: No such resource"), - 1, - "Virtual server should get deleted after removing LB rule" - ) + result.count("ERROR: No such resource"), + 1, + "Virtual server should get deleted after removing LB rule" + ) cmd = "show ip" self.debug("command: %s" % cmd) @@ -2129,12 +2182,12 @@ class TestLoadBalancingRule(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(self.public_ip.ipaddress.ipaddress), - 0, - "Virtual server should get deleted after removing LB rule" - ) + result.count(self.public_ip.ipaddress.ipaddress), + 0, + "Virtual server should get deleted after removing LB rule" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -2152,68 +2205,76 @@ class TestDeleteCreateLBRule(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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 = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - # Creating network using the network offering created - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.network_offering.id, - zoneid=cls.zone.id - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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 = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + # Creating network using the network offering created + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + networkofferingid=cls.network_offering.id, + zoneid=cls.zone.id + ) + + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -2223,30 +2284,29 @@ class TestDeleteCreateLBRule(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup = [] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # 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 - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_01_create_with_same_public_port(self): """Test create LB rule with same public port after deleting rule""" - # Validate the following # 1. Delete existing rule and create exactly same rule with different # public port @@ -2259,12 +2319,12 @@ class TestDeleteCreateLBRule(cloudstackTestCase): self.debug("Create a new LB rule with different public port") self.services["lbrule"]["publicport"] = 23 LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) class TestVmWithLb(cloudstackTestCase): @@ -2280,98 +2340,106 @@ class TestVmWithLb(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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 = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - # Creating network using the network offering created - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.network_offering.id, - zoneid=cls.zone.id - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + # Creating network using the network offering created + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + networkofferingid=cls.network_offering.id, + zoneid=cls.zone.id + ) - # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.vm_2 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip_1 = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) - cls.lb_rule_1 = LoadBalancerRule.create( - cls.api_client, - cls.services["lbrule"], - ipaddressid=cls.public_ip_1.ipaddress.id, - accountid=cls.account.name, - networkid=cls.network.id - ) - cls.public_ip_2 = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) - cls.lb_rule_2 = LoadBalancerRule.create( - cls.api_client, - cls.services["lbrule"], - ipaddressid=cls.public_ip_2.ipaddress.id, - accountid=cls.account.name, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.vm_1 = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.vm_2 = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip_1 = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) + cls.lb_rule_1 = LoadBalancerRule.create( + cls.api_client, + cls.services["lbrule"], + ipaddressid=cls.public_ip_1.ipaddress.id, + accountid=cls.account.name, + networkid=cls.network.id + ) + cls.public_ip_2 = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) + cls.lb_rule_2 = LoadBalancerRule.create( + cls.api_client, + cls.services["lbrule"], + ipaddressid=cls.public_ip_2.ipaddress.id, + accountid=cls.account.name, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -2386,18 +2454,17 @@ class TestVmWithLb(cloudstackTestCase): def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # 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 - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_01_delete_public_ip(self): """Test delete one public Ip with LB rules""" - # Validate the following # 1. Associate 2 public Ips and create load balancing rules in it # 2. Delete one of the public Ip @@ -2407,44 +2474,44 @@ class TestVmWithLb(cloudstackTestCase): # 5. All servers and services service to that public Ip get deleted self.debug("Deleting public IP: %s from network: %s" % ( - self.public_ip_2.ipaddress.ipaddress, - self.network.name - )) + self.public_ip_2.ipaddress.ipaddress, + self.network.name + )) self.public_ip_2.delete(self.apiclient) self.debug( - "Public Ip: %s is deleted!" % - self.public_ip_2.ipaddress.ipaddress) + "Public Ip: %s is deleted!" % + self.public_ip_2.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - publicipid=self.public_ip_2.ipaddress.id, - listall=True, - ) + self.apiclient, + publicipid=self.public_ip_2.ipaddress.id, + listall=True, + ) self.assertEqual( - lb_rules, - None, - "LB rules associated with the public Ip should get deleted" - ) + lb_rules, + None, + "LB rules associated with the public Ip should get deleted" + ) self.debug("SSH into Netscaler to verify other resources are deleted") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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_2.ipaddress.ipaddress, - self.lb_rule_2.publicport) + self.public_ip_2.ipaddress.ipaddress, + self.lb_rule_2.publicport) self.debug("command: %s" % cmd) res = ssh_client.execute(cmd) result = str(res) self.debug("Output: %s" % result) self.assertEqual( - result.count("ERROR: No such resource"), - 1, - "Virtual server should get deleted after removing LB rule" - ) + result.count("ERROR: No such resource"), + 1, + "Virtual server should get deleted after removing LB rule" + ) cmd = "show ip" self.debug("command: %s" % cmd) @@ -2453,20 +2520,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(self.public_ip_2.ipaddress.ipaddress), - 0, - "Virtual server should get deleted after removing LB rule" - ) + result.count(self.public_ip_2.ipaddress.ipaddress), + 0, + "Virtual server should get deleted after removing LB rule" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_02_stop_user_vm(self): """Test stop user VM with LB""" - # Validate the following # 1. Create 2 instances and add these two for load balancing # 2. Stop one of the user VM @@ -2485,16 +2551,16 @@ class TestVmWithLb(cloudstackTestCase): "Verifying request served by only running instances") hostnames = [] ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) + ipaddress=self.public_ip_1.ipaddress.ipaddress) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) hostnames.append(result) ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -2502,22 +2568,22 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Hostnames: %s" % str(hostnames)) self.assertEqual( - hostnames[0], - hostnames[1], - "Hostnames must be same as another VM is stopped" - ) + hostnames[0], + hostnames[1], + "Hostnames must be same as another VM is stopped" + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip_1.ipaddress.ipaddress, - e)) + self.public_ip_1.ipaddress.ipaddress, + e)) self.debug("SSH into Netscaler to rules still persist") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) cmd = "show server" self.debug("command: %s" % cmd) @@ -2526,20 +2592,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertNotEqual( - result.count(self.vm_2.ipaddress), - 0, - "The server should be present in netscaler after VM stop" - ) + result.count(self.vm_2.ipaddress), + 0, + "The server should be present in netscaler after VM stop" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_03_start_user_vm(self): """Test start user VM with LB""" - # Validate the following # 1. Create 2 instances and add these two for load balancing # 2. Stop one of the user VM @@ -2551,23 +2616,23 @@ class TestVmWithLb(cloudstackTestCase): self.vm_2.start(self.apiclient) self.debug("Starting VM: %s" % self.vm_2.name) self.debug("Sleeping for netscaler to recognize service is up") - time.sleep( 120 ) + time.sleep(120) try: self.debug( "Verifying request served by only running instances") hostnames = [] ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) + ipaddress=self.public_ip_1.ipaddress.ipaddress) self.debug("Command: hostname") result = ssh_1.execute("hostname") self.debug("Output: %s" % result) hostnames.append(result) ssh_2 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh_2.execute("hostname") self.debug("Output: %s" % result) @@ -2575,22 +2640,22 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Hostnames: %s" % str(hostnames)) self.assertNotEqual( - hostnames[0], - hostnames[1], - "Both request should be served by different instances" - ) + hostnames[0], + hostnames[1], + "Both request should be served by different instances" + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip_1.ipaddress.ipaddress, - e)) + self.public_ip_1.ipaddress.ipaddress, + e)) self.debug("SSH into Netscaler to rules still persist") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) cmd = "show server" self.debug("command: %s" % cmd) @@ -2599,20 +2664,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertNotEqual( - result.count(self.vm_2.ipaddress), - 0, - "The server should be present in netscaler after VM stop" - ) + result.count(self.vm_2.ipaddress), + 0, + "The server should be present in netscaler after VM stop" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns", "multihost"]) + @attr(tags=["advancedns", "multihost"]) def test_04_migrate_user_vm(self): """Test migrate user VM with LB""" - # Validate the following # 1. Create 2 instances and add these two for load balancing # 2. migrate one Vm to another host. @@ -2620,21 +2684,21 @@ class TestVmWithLb(cloudstackTestCase): # 4. In netscaler, the LB rules are still configured. hosts = Host.list( - self.apiclient, - zoneid=self.vm_2.zoneid, - type='Routing' - ) + self.apiclient, + zoneid=self.vm_2.zoneid, + type='Routing' + ) self.assertEqual( - isinstance(hosts, list), - True, - "Check the number of hosts in the zone" - ) + isinstance(hosts, list), + True, + "Check the number of hosts in the zone" + ) self.assertGreaterEqual( - len(hosts), - 2, - "Atleast 2 hosts should be present in a zone for VM migration" - ) + len(hosts), + 2, + "Atleast 2 hosts should be present in a zone for VM migration" + ) # Remove the host of current VM from the hosts list hosts[:] = [host for host in hosts if host.id != self.vm_2.hostid] @@ -2648,39 +2712,39 @@ class TestVmWithLb(cloudstackTestCase): self.apiclient.migrateVirtualMachine(cmd) list_vm_response = VirtualMachine.list( - self.apiclient, - id=self.vm_2.id - ) + self.apiclient, + id=self.vm_2.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) vm_response = list_vm_response[0] self.assertEqual( - vm_response.hostid, - host.id, - "Check destination hostID of migrated VM" - ) + vm_response.hostid, + host.id, + "Check destination hostID of migrated VM" + ) self.debug("Migrated VM-ID: %s to Host: %s" % (self.vm_2.id, host.id)) try: self.debug( "Verifying request served by only running instances") hostnames = [] ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.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_2.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh_2.execute("hostname") self.debug("Output: %s" % result) @@ -2688,22 +2752,22 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Hostnames: %s" % str(hostnames)) self.assertNotEqual( - hostnames[0], - hostnames[1], - "Both request should be served by different instances" - ) + hostnames[0], + hostnames[1], + "Both request should be served by different instances" + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip_1.ipaddress.ipaddress, - e)) + self.public_ip_1.ipaddress.ipaddress, + e)) self.debug("SSH into Netscaler to rules still persist") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) cmd = "show server" self.debug("command: %s" % cmd) @@ -2712,20 +2776,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertNotEqual( - result.count(self.vm_2.ipaddress), - 0, - "The server should be present in netscaler after migrate" - ) + result.count(self.vm_2.ipaddress), + 0, + "The server should be present in netscaler after migrate" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_05_reboot_user_vm(self): """Test reboot user VM with LB""" - # Validate the following # 1. Create 2 instances and add these two for load balancing # 2. Reboot one of the user VM @@ -2736,23 +2799,23 @@ class TestVmWithLb(cloudstackTestCase): self.vm_2.reboot(self.apiclient) self.debug("Rebooting VM: %s" % self.vm_2.name) self.debug("Waiting for Netscaler to get the service up") - time.sleep( 120 ) + time.sleep(120) try: self.debug( "Verifying request served by only running instances") hostnames = [] ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) + ipaddress=self.public_ip_1.ipaddress.ipaddress) self.debug("Command: hostname") result = ssh_1.execute("hostname") self.debug("Output: %s" % result) hostnames.append(result) ssh_2 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh_2.execute("hostname") self.debug("Output: %s" % result) @@ -2761,9 +2824,9 @@ class TestVmWithLb(cloudstackTestCase): if hostnames[0] == hostnames[1]: ssh_3 = self.vm_2.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh_3.execute("hostname") self.debug("Output: %s" % result) @@ -2775,23 +2838,23 @@ class TestVmWithLb(cloudstackTestCase): "Both request should be served by different instances" ) else: - self.assertNotEqual( + self.assertNotEqual( hostnames[0], hostnames[1], "Both request should be served by different instances" - ) + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip_1.ipaddress.ipaddress, - e)) + self.public_ip_1.ipaddress.ipaddress, + e)) self.debug("SSH into Netscaler to rules still persist") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) cmd = "show server" self.debug("command: %s" % cmd) @@ -2800,20 +2863,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertNotEqual( - result.count(self.vm_2.ipaddress), - 0, - "The server should be present in netscaler after reboot" - ) + result.count(self.vm_2.ipaddress), + 0, + "The server should be present in netscaler after reboot" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_06_destroy_user_vm(self): """Test destroy user VM with LB""" - # Validate the following # 1. Create 2 instances and add these two for load balancing # 2. Destroy one of the user VM @@ -2832,16 +2894,16 @@ class TestVmWithLb(cloudstackTestCase): "Verifying request served by only running instances") hostnames = [] ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) + ipaddress=self.public_ip_1.ipaddress.ipaddress) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) hostnames.append(result) ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress, - reconnect=True - ) + ipaddress=self.public_ip_1.ipaddress.ipaddress, + reconnect=True + ) self.debug("Command: hostname") result = ssh.execute("hostname") self.debug("Output: %s" % result) @@ -2849,32 +2911,32 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Hostnames: %s" % str(hostnames)) self.assertEqual( - hostnames[0], - hostnames[1], - "Both request should be served by same instance" - ) + hostnames[0], + hostnames[1], + "Both request should be served by same instance" + ) except Exception as e: self.fail("Exception occured during SSH: %s - %s" % ( - self.public_ip_1.ipaddress.ipaddress, - e)) + self.public_ip_1.ipaddress.ipaddress, + e)) delay = Configurations.list( - self.apiclient, - name='expunge.delay' - ) + self.apiclient, + name='expunge.delay' + ) wait = Configurations.list( - self.apiclient, - name='expunge.interval' - ) + self.apiclient, + name='expunge.interval' + ) # Sleep to ensure that all resources are deleted time.sleep(int(delay[0].value) + int(wait[0].value)) self.debug("SSH into Netscaler to rules still persist") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + self.services["netscaler"]["ipaddress"], + self.services["netscaler"]["port"], + self.services["netscaler"]["username"], + self.services["netscaler"]["password"], + ) cmd = "show server" self.debug("command: %s" % cmd) @@ -2883,20 +2945,19 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(self.vm_2.ipaddress), - 0, - "The server should not be present in netscaler after destroy" - ) + result.count(self.vm_2.ipaddress), + 0, + "The server should not be present in netscaler after destroy" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_07_delete_all_public_ip(self): """Test delete all public Ip with LB rules""" - # Validate the following # 1. Associate 2 public Ips and create load balancing rules in it # 2. Delete all of the public Ip @@ -2906,44 +2967,44 @@ class TestVmWithLb(cloudstackTestCase): # 5. All servers and services service to that public Ip get deleted self.debug("Deleting public IP: %s from network: %s" % ( - self.public_ip_1.ipaddress.ipaddress, - self.network.name - )) + self.public_ip_1.ipaddress.ipaddress, + self.network.name + )) self.public_ip_1.delete(self.apiclient) self.debug( - "Public Ip: %s is deleted!" % - self.public_ip_1.ipaddress.ipaddress) + "Public Ip: %s is deleted!" % + self.public_ip_1.ipaddress.ipaddress) lb_rules = LoadBalancerRule.list( - self.apiclient, - publicipid=self.public_ip_1.ipaddress.id, - listall=True, - ) + self.apiclient, + publicipid=self.public_ip_1.ipaddress.id, + listall=True, + ) self.assertEqual( - lb_rules, - None, - "LB rules associated with the public Ip should get deleted" - ) + lb_rules, + None, + "LB rules associated with the public Ip should get deleted" + ) self.debug("SSH into Netscaler to verify other resources are deleted") try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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_1.ipaddress.ipaddress, - self.lb_rule_1.publicport) + self.public_ip_1.ipaddress.ipaddress, + self.lb_rule_1.publicport) self.debug("command: %s" % cmd) res = ssh_client.execute(cmd) result = str(res) self.debug("Output: %s" % result) self.assertEqual( - result.count("ERROR: No such resource"), - 1, - "Virtual server should get deleted after removing LB rule" - ) + result.count("ERROR: No such resource"), + 1, + "Virtual server should get deleted after removing LB rule" + ) cmd = "show ip" self.debug("command: %s" % cmd) @@ -2952,11 +3013,11 @@ class TestVmWithLb(cloudstackTestCase): self.debug("Output: %s" % result) self.assertEqual( - result.count(self.public_ip_1.ipaddress.ipaddress), - 0, - "Virtual server should get deleted after removing LB rule" - ) + result.count(self.public_ip_1.ipaddress.ipaddress), + 0, + "Virtual server should get deleted after removing LB rule" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return diff --git a/test/integration/component/test_netscaler_lb_algo.py b/test/integration/component/test_netscaler_lb_algo.py index 6eda9a3f401..0d571b4608f 100644 --- a/test/integration/component/test_netscaler_lb_algo.py +++ b/test/integration/component/test_netscaler_lb_algo.py @@ -17,98 +17,97 @@ """ P1 tests for netscaler load balancing """ -#Import Local Modules -import marvin +# Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.lib.utils import * -from marvin.lib.base import * -from marvin.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import (cleanup_resources) +from marvin.lib.base import (Account, + Network, + VirtualMachine, + ServiceOffering, + NetworkOffering, + PublicIPAddress, + LoadBalancerRule) +from marvin.lib.common import (get_zone, + get_domain, + get_template, + list_configurations, + GetNetscalerInfoFromConfig, + add_netscaler) from marvin.sshClient import SshClient +import time 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": "password", - }, - "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": { - "ipaddress": '10.147.60.27', - "username": 'nsroot', - "password": 'nsroot', - "networkdevicetype": 'NetscalerVPXLoadBalancer', - "publicinterface": '1/1', - "privateinterface": '1/1', - "numretries": 2, - "lbdevicededicated": False, - "lbdevicecapacity": 50, - "port": 22, - }, - "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": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 22, - "openfirewall": False, - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - "mode": 'advanced' - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "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', + }, + "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": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 22, + "openfirewall": False, + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + "mode": 'advanced' + } class TestLbWithRoundRobin(cloudstackTestCase): @@ -124,36 +123,45 @@ class TestLbWithRoundRobin(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + cls._cleanup = [] + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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"] + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -163,27 +171,27 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = list_configurations( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = list_configurations( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -191,7 +199,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_with_round_robin(self): """Test Create LB rule with round robin algorithm """ @@ -206,119 +214,120 @@ class TestLbWithRoundRobin(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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=self.virtual_machine.id - ) + self.apiclient, + id=self.virtual_machine.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % self.virtual_machine.id - ) + "Verify listVirtualMachines response for virtual machine: %s" + % self.virtual_machine.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + 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" - ) + 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( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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) + 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) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -336,38 +345,48 @@ class TestLbWithLeastConn(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # 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.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.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -377,27 +396,27 @@ class TestLbWithLeastConn(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = list_configurations( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = list_configurations( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -405,7 +424,7 @@ class TestLbWithLeastConn(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_with_least_conn(self): """Test Create LB rule with least connection algorithm """ @@ -420,127 +439,128 @@ class TestLbWithLeastConn(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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=self.virtual_machine.id - ) + self.apiclient, + id=self.virtual_machine.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % self.virtual_machine.id - ) + "Verify listVirtualMachines response for virtual machine: %s" + % self.virtual_machine.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + 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" - ) + 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.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) ip_with_lb_rule = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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) + 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) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'LEASTCONNECTION' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -557,38 +577,47 @@ class TestLbWithSourceIp(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup = [ - cls.netscaler - ] - 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + + cls._cleanup = [] + try: + cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # 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.append(cls.service_offering) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -598,27 +627,27 @@ class TestLbWithSourceIp(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [self.account] return def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) interval = list_configurations( - self.apiclient, - name='network.gc.interval' - ) + self.apiclient, + name='network.gc.interval' + ) wait = list_configurations( - self.apiclient, - name='network.gc.wait' - ) + 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!") @@ -626,7 +655,7 @@ class TestLbWithSourceIp(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_with_source_ip(self): """Test Create LB rule with source Ip algorithm """ @@ -641,120 +670,121 @@ class TestLbWithSourceIp(cloudstackTestCase): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) self.network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id + ) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(self.network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.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=self.virtual_machine.id - ) + self.apiclient, + id=self.virtual_machine.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % self.virtual_machine.id - ) + "Verify listVirtualMachines response for virtual machine: %s" + % self.virtual_machine.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + 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" - ) + 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( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=self.network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=self.network.id + ) self.debug("Associated %s with network %s" % ( - ip_with_lb_rule.ipaddress.ipaddress, - self.network.id - )) + ip_with_lb_rule.ipaddress.ipaddress, + self.network.id + )) self.debug( "Creating LB rule for IP address: %s with round robin algo" % - ip_with_lb_rule.ipaddress.ipaddress) + ip_with_lb_rule.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=ip_with_lb_rule.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=ip_with_lb_rule.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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) + 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) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCEIPHASH' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -772,62 +802,72 @@ class TestLbAlgoRrLc(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -855,7 +895,7 @@ class TestLbAlgoRrLc(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_round_robin_to_least_conn(self): """Test edit LB rule from round robin to least connection algo """ @@ -872,93 +912,95 @@ class TestLbAlgoRrLc(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with round robin algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.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')) + "Updating LB rule: %s with new algorithm: %s" % ( + lb_rule.name, + 'leastconn')) lb_rule.update(self.apiclient, algorithm='leastconn') - self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug( + "SSH into Netscaler to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'LEASTCONNECTION' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -976,62 +1018,72 @@ class TestLbAlgoLcRr(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -1059,7 +1111,7 @@ class TestLbAlgoLcRr(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_least_conn_to_round_robin(self): """Test edit LB rule from least conn to round robin algo """ @@ -1076,90 +1128,92 @@ class TestLbAlgoLcRr(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with least conn algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'LEASTCONNECTION' algorithm should be configured on NS" - ) + 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.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')) + "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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -1177,63 +1231,73 @@ class TestLbAlgoRrSb(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -1261,7 +1325,7 @@ class TestLbAlgoRrSb(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_round_robin_to_source(self): """Test edit LB rule from round robin to source algo """ @@ -1278,92 +1342,94 @@ class TestLbAlgoRrSb(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with round robin algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.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')) + "Updating LB rule: %s with new algorithm: %s" % ( + lb_rule.name, + 'source')) lb_rule.update(self.apiclient, algorithm='source') - self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug( + "SSH into Netscaler to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCEIPHASH' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -1381,64 +1447,74 @@ class TestLbAlgoSbRr(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') - cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -1466,7 +1542,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_source_to_round_robin(self): """Test edit LB rule from source to round robin algo """ @@ -1483,94 +1559,96 @@ class TestLbAlgoSbRr(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with source algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCEIPHASH' algorithm should be configured on NS" - ) + 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.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')) + "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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -1588,64 +1666,74 @@ class TestLbAlgoSbLc(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') - cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -1673,7 +1761,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_source_to_least_conn(self): """Test edit LB rule from source to least conn algo """ @@ -1690,93 +1778,95 @@ class TestLbAlgoSbLc(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with source algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCEIPHASH' algorithm should be configured on NS" - ) + 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.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')) + "Updating LB rule: %s with new algorithm: %s" % ( + lb_rule.name, + 'leastconn')) lb_rule.update(self.apiclient, algorithm='leastconn') - self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug( + "SSH into Netscaler to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'LEASTCONNECTION' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return @@ -1794,63 +1884,73 @@ class TestLbAlgoLcSb(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + cls.network_offering = NetworkOffering.create( + cls.api_client, + cls.services["network_offering"], + conservemode=True + ) + cls._cleanup.append(cls.network_offering) + # Enable Network offering + cls.network_offering.update(cls.api_client, state='Enabled') - cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - 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.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + 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"] - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup.append(cls.service_offering) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod @@ -1878,7 +1978,7 @@ class TestLbAlgoLcSb(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_lb_leastconn_to_source(self): """Test edit LB rule from round robin to source algo """ @@ -1895,92 +1995,94 @@ class TestLbAlgoLcSb(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with leastconn algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id, - listall=True - ) + self.apiclient, + id=lb_rule.id, + listall=True + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return a newly created LB rule" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return a newly created LB rule" + ) self.debug("Adding %s to the LB rule %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + 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 to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'LEASTCONNECTION' algorithm should be configured on NS" - ) + 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.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')) + "Updating LB rule: %s with new algorithm: %s" % ( + lb_rule.name, + 'source')) lb_rule.update(self.apiclient, algorithm='source') - self.debug("SSH into Netscaler to check whether algorithm is configured properly or not?") + self.debug( + "SSH into Netscaler to check whether algorithm is configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCEIPHASH' algorithm should be configured on NS" - ) + 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.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 c333f60c68f..a5f55a8f25d 100644 --- a/test/integration/component/test_netscaler_lb_sticky.py +++ b/test/integration/component/test_netscaler_lb_sticky.py @@ -17,99 +17,95 @@ """ P1 tests for netscaler load balancing sticky policy """ -#Import Local Modules -import marvin +# Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.lib.utils import * -from marvin.lib.base import * -from marvin.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import (Account, + LoadBalancerRule, + PublicIPAddress, + Network, + NetworkOffering, + ServiceOffering, + VirtualMachine) +from marvin.lib.common import (get_domain, + get_zone, + get_template, + add_netscaler, + GetNetscalerInfoFromConfig) from marvin.sshClient import SshClient -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": "password", - }, - "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": { - "ipaddress": '10.147.60.27', - "username": 'nsroot', - "password": 'nsroot', - "networkdevicetype": 'NetscalerVPXLoadBalancer', - "publicinterface": '1/1', - "privateinterface": '1/1', - "numretries": 2, - "lbdevicededicated": False, - "lbdevicecapacity": 50, - "port": 22, - }, - "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, - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - "mode":'advanced' - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "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', + }, + "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, + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + "mode": 'advanced' + } class TestLbStickyPolicy(cloudstackTestCase): @@ -125,69 +121,80 @@ class TestLbStickyPolicy(cloudstackTestCase): cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + try: - cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"]) - cls._cleanup.append(cls.netscaler) - 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.netscaler = add_netscaler( + cls.api_client, + cls.zone.id, + cls.services["netscaler"]) + cls._cleanup.append(cls.netscaler) + 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 = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - cls._cleanup.insert(0,cls.account) - # Creating network using the network offering created - cls.network = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.network_offering.id, - zoneid=cls.zone.id - ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.insert(0, cls.account) + # Creating network using the network offering created + cls.network = Network.create( + cls.api_client, + cls.services["network"], + accountid=cls.account.name, + domainid=cls.account.domainid, + networkofferingid=cls.network_offering.id, + zoneid=cls.zone.id + ) - # Spawn an instance in that network - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network.id)] - ) - cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network.id - ) + # Spawn an instance in that network + cls.virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + networkids=[str(cls.network.id)] + ) + cls.public_ip = PublicIPAddress.create( + cls.api_client, + accountid=cls.account.name, + zoneid=cls.zone.id, + domainid=cls.account.domainid, + networkid=cls.network.id + ) except Exception as e: - cls.tearDownClass() - raise Exception ("Warning: Exception in setUpClass: %s" % e) + cls.tearDownClass() + raise Exception("Warning: Exception in setUpClass: %s" % e) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -202,16 +209,17 @@ class TestLbStickyPolicy(cloudstackTestCase): def tearDown(self): try: self.debug("Cleaning up the resources") - #Clean up, terminate the created network offerings + # 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 - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_01_source_based_roundrobin(self): - """Test Create a "SourceBased" stick policy for a Lb rule with "RoundRobin" algorithm + """Test Create a "SourceBased" stick policy for a Lb rule with + "RoundRobin" algorithm """ # Validate the following @@ -226,80 +234,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with round robin algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='SourceBased', - name='SourceBasedRR', - param={"holdtime": 20} - ) + self.apiclient, + methodname='SourceBased', + name='SourceBasedRR', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy configured\ + properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: SOURCEIP"), - 1, - "'SourceBased' sticky policy should be configured on NS" - ) + result.count("Persistence: SOURCEIP"), + 1, + "'SourceBased' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_02_source_based_source_algo(self): - """Test Create a "SourceBased" stick policy for a Lb rule with "Source" algorithm + """Test Create a "SourceBased" stick policy for a Lb rule + with "Source" algorithm """ # Validate the following @@ -314,79 +325,81 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with source algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='SourceBased', - name='SourceBasedSource', - param={"holdtime": 20} - ) + self.apiclient, + methodname='SourceBased', + name='SourceBasedSource', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: SOURCEIP"), - 1, - "'SourceBased' sticky policy should be configured on NS" - ) + result.count("Persistence: SOURCEIP"), + 1, + "'SourceBased' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCE' algorithm should be configured on NS" - ) + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCE' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_03_source_based_leastconn(self): """Test Create a "SourceBased" stick policy for a Lb rule with leastconn algo """ @@ -403,79 +416,81 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with leastconn algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='SourceBased', - name='SourceBasedLeast', - param={"holdtime": 20} - ) + self.apiclient, + methodname='SourceBased', + name='SourceBasedLeast', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy configured\ + properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: SOURCEIP"), - 1, - "'SourceBased' sticky policy should be configured on NS" - ) + result.count("Persistence: SOURCEIP"), + 1, + "'SourceBased' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'leastconn' algorithm should be configured on NS" - ) + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'leastconn' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_04_lbcookie_based_roundrobin(self): """Test Create a "LBCookie" stick policy for a Lb rule with roundrobin algo """ @@ -492,81 +507,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with roundrobin algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='LbCookie', - name='LbCookieRR', - param={"holdtime": 20} - ) + self.apiclient, + methodname='LbCookie', + name='LbCookieRR', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: COOKIEINSERT"), - 1, - "'LBCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: COOKIEINSERT"), + 1, + "'LBCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_05_lbcookie_source_algo(self): """Test Create a "LBCookie" stick policy for a Lb rule with "Source" algorithm """ @@ -583,81 +600,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with source algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='LbCookie', - name='LbCookieSource', - param={"holdtime": 20} - ) + self.apiclient, + methodname='LbCookie', + name='LbCookieSource', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: COOKIEINSERT"), - 1, - "'LbCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: COOKIEINSERT"), + 1, + "'LbCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCE' algorithm should be configured on NS" - ) + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCE' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_06_lbcookie_leastconn(self): """Test Create a "LBCookie" stick policy for a Lb rule with leastconn algo """ @@ -674,81 +693,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with leastconn algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='LBCookie', - name='LbcookieLeastConn', - param={"holdtime": 20} - ) + self.apiclient, + methodname='LBCookie', + name='LbcookieLeastConn', + param={"holdtime": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: COOKIEINSERT"), - 1, - "'LbCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: COOKIEINSERT"), + 1, + "'LbCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'leastconn' algorithm should be configured on NS" - ) + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'leastconn' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_07_appcookie_based_roundrobin(self): """Test Create a "AppCookie" stick policy for a Lb rule with roundrobin algo """ @@ -765,81 +786,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with roundrobin algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'roundrobin' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='AppCookie', - name='AppCookieRR', - param={"name": 20} - ) + self.apiclient, + methodname='AppCookie', + name='AppCookieRR', + param={"name": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: RULE"), - 1, - "'AppCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: RULE"), + 1, + "'AppCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: ROUNDROBIN"), - 1, - "'ROUNDROBIN' algorithm should be configured on NS" - ) + 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.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_08_appcookie_source_algo(self): """Test Create a "AppCookie" stick policy for a Lb rule with "Source" """ @@ -856,81 +879,83 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with source algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'source' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='AppCookie', - name='AppCookieSource', - param={"name": 20} - ) + self.apiclient, + methodname='AppCookie', + name='AppCookieSource', + param={"name": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: RULE"), - 1, - "'AppCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: RULE"), + 1, + "'AppCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: SOURCEIPHASH"), - 1, - "'SOURCE' algorithm should be configured on NS" - ) + result.count("Configured Method: SOURCEIPHASH"), + 1, + "'SOURCE' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return - @attr(tags = ["advancedns"]) + @attr(tags=["advancedns"]) def test_09_appcookie_leastconn(self): """Test Create a "AppCookie" stick policy for a Lb rule with leastconn """ @@ -947,76 +972,78 @@ class TestLbStickyPolicy(cloudstackTestCase): self.debug( "Creating LB rule for IP address: %s with leastconn algo" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.services["lbrule"]["alg"] = 'leastconn' self.services["lbrule"]["publicport"] = 80 self.services["lbrule"]["privateport"] = 80 lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=self.public_ip.ipaddress.id, - accountid=self.account.name, - networkid=self.network.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=self.public_ip.ipaddress.id, + accountid=self.account.name, + networkid=self.network.id + ) self.cleanup.append(lb_rule) self.debug("Created the load balancing rule for public IP: %s" % - self.public_ip.ipaddress.ipaddress) + self.public_ip.ipaddress.ipaddress) self.debug("Assigning VM instance: %s to LB rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) lb_rule.assign(self.apiclient, [self.virtual_machine]) self.debug("Assigned VM instance: %s to lb rule: %s" % ( - self.virtual_machine.name, - lb_rule.name - )) + self.virtual_machine.name, + lb_rule.name + )) self.debug( "Configuring 'SourceBased' Sticky policy on lb rule: %s" % - lb_rule.name) + lb_rule.name) try: result = lb_rule.createSticky( - self.apiclient, - methodname='AppCookie', - name='AppCookieLeastConn', - param={"name": 20} - ) + self.apiclient, + methodname='AppCookie', + name='AppCookieLeastConn', + param={"name": 20} + ) self.debug("Response: %s" % result) except Exception as e: self.fail("Configure sticky policy failed with exception: %s" % e) - self.debug("SSH into Netscaler to check whether sticky policy configured properly or not?") + self.debug( + "SSH into Netscaler to check whether sticky policy\ + configured properly or not?") self.debug("SSH into netscaler: %s" % - self.services["netscaler"]["ipaddress"]) + self.services["netscaler"]["ipaddress"]) try: ssh_client = SshClient( - self.services["netscaler"]["ipaddress"], - self.services["netscaler"]["port"], - self.services["netscaler"]["username"], - self.services["netscaler"]["password"], - ) + 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.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) self.assertEqual( - result.count("Persistence: RULE"), - 1, - "'AppCookie' sticky policy should be configured on NS" - ) + result.count("Persistence: RULE"), + 1, + "'AppCookie' sticky policy should be configured on NS" + ) self.assertEqual( - result.count("Configured Method: LEASTCONNECTION"), - 1, - "'leastconn' algorithm should be configured on NS" - ) + result.count("Configured Method: LEASTCONNECTION"), + 1, + "'leastconn' algorithm should be configured on NS" + ) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (self.services["netscaler"]["ipaddress"], e)) return diff --git a/test/integration/component/test_persistent_networks.py b/test/integration/component/test_persistent_networks.py index 65b109f2f87..8bebd8d3c62 100644 --- a/test/integration/component/test_persistent_networks.py +++ b/test/integration/component/test_persistent_networks.py @@ -40,7 +40,8 @@ from marvin.lib.common import (get_domain, get_template, verifyNetworkState, add_netscaler, - wait_for_cleanup) + wait_for_cleanup, + GetNetscalerInfoFromConfig) from nose.plugins.attrib import attr from marvin.codes import PASS, FAIL, FAILED from marvin.sshClient import SshClient @@ -97,6 +98,13 @@ class TestPersistentNetworks(cloudstackTestCase): cls.isolated_network_offering_netscaler = cls.createNetworkOffering( "nw_off_isolated_netscaler") + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that # Netscaler tests are executed @@ -105,7 +113,7 @@ class TestPersistentNetworks(cloudstackTestCase): cls.netscaler = add_netscaler( cls.api_client, cls.zone.id, - cls.services["netscaler_VPX"]) + cls.services["netscaler"]) cls._cleanup.append(cls.netscaler) cls.ns_configured = True except Exception: @@ -1500,6 +1508,13 @@ class TestAssignVirtualMachine(cloudstackTestCase): cls.persistent_network_offering_netscaler = cls.createNetworkOffering( "nw_off_isolated_persistent_netscaler") + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that # Netscaler tests are executed @@ -1508,7 +1523,7 @@ class TestAssignVirtualMachine(cloudstackTestCase): cls.netscaler = add_netscaler( cls.api_client, cls.zone.id, - cls.services["netscaler_VPX"]) + cls.services["netscaler"]) cls._cleanup.append(cls.netscaler) cls.ns_configured = True except Exception: @@ -1964,6 +1979,13 @@ class TestRestartPersistentNetwork(cloudstackTestCase): cls.api_client, state="enabled") + response = GetNetscalerInfoFromConfig( + cls.config + ) + assert response[0] is not None, response[1] + cls.services["netscaler"] = response[0] + cls.services["netscaler"]["lbdevicededicated"] = False + # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that # Netscaler tests are executed @@ -1972,7 +1994,7 @@ class TestRestartPersistentNetwork(cloudstackTestCase): cls.netscaler = add_netscaler( cls.api_client, cls.zone.id, - cls.services["netscaler_VPX"]) + cls.services["netscaler"]) cls._cleanup.append(cls.netscaler) cls.ns_configured = True except Exception: diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py index 9e3d40cdbc8..63662b96880 100644 --- a/tools/marvin/marvin/lib/common.py +++ b/tools/marvin/marvin/lib/common.py @@ -1376,3 +1376,21 @@ def isNetworkDeleted(apiclient, networkid, timeout=600): time.sleep(60) #end while return networkDeleted + +def GetNetscalerInfoFromConfig(config): + """ Read netscaler data from config file and + return it + + Input: Config + Output: [netscalerInfoDict, isExceptionOccured] + """ + try: + netscalerInfo = config.__dict__[ + "netscalerDevice"].__dict__ + return [netscalerInfo, None] + except KeyError: + exceptionMessage = "Please make sure you have included netscalerDevice\ + dict in your config file" + return [None, exceptionMessage] + except Exception as e: + return [None, e]