def test_04_delete_lb_rule(self): """Test LB rule before/after stickiness policy creation""" # Validate the following # 1. Create a LB rule with roundrobin, leastconn and source. # listLoadBalancerRules should show newly created load balancer rule # 2. Delete the loadbalancer rule. Delete loadbalancer rule should be # successful # 3. Configure the Source based, app cookie and lb cookie based policy # with custom parameters listLBStickinessPolicies should show newly # created stickiness # 4. Delete load balancer rule. Delete should be successful lb_methods = ["roundrobin", "leastconn", "source"] configs = {"SourceBased": {"tablesize": '100k'}, "AppCookie": {"request-learn": "true"}, "LBCookie": {"nocache": "true"}} for lb_method in lb_methods: for method, params in configs.items(): self.debug("Creating load balancing rule on IP %s & algo %s" % (self.public_ip.ipaddress.ipaddress, lb_method)) services = self.services["lbrule"] services["alg"] = lb_method lb_rule = self.create_LB_Rule(self.public_ip, network=self.get_Network(self.account), vmarray=[self.virtual_machine, self.virtual_machine_2], services=services) self.debug( "Deleting the LB rule before stickiness policy creation") lb_rule.delete(self.apiclient) with self.assertRaises(Exception): LoadBalancerRule.list(self.apiclient, id=lb_rule.id, listall=True) lb_rule = self.create_LB_Rule(self.public_ip, network=self.get_Network(self.account), vmarray=[self.virtual_machine, self.virtual_machine_2], services=services) self.debug("Creating stickiness policy for the LB rule: %s" % lb_rule.id) policies = self.configure_Stickiness_Policy(lb_rule, method=method, paramDict=params) policy = policies.stickinesspolicy[0] self.debug("Policy: %s" % str(policy)) self.debug("Validating the stickiness policy") self.validate_Stickiness_Policy(lb_rule, method, self.public_ip.ipaddress.ipaddress) self.debug("Deleting the LB rule: %s" % lb_rule.name) lb_rule.delete(self.apiclient) with self.assertRaises(Exception): LoadBalancerRule.list(self.apiclient, id=lb_rule.id) return
def test_05_error_alerts_after_create(self): """Test error/alerts after creating stickiness policy""" # Validate the following # 1. Create a LB rule with round Robin/Least connections/Source # listLoadBalancerRules should show newly created load balancer rule # 2. Configure the Stickiness policy to above created LB rule. # listLBStickinessPolicies Api should show newly created stickiness # 3. update & delete stickiness policy see error related to stickiness # 4. No errors should be shown in the logs and alerts lb_methods = ["roundrobin", "leastconn", "source"] #TODO: Add code to check the AppCookie and LbCookie Stickiness policies configs = {"SourceBased": {"tablesize": '100k'}} for lb_method in lb_methods: for method, params in list(configs.items()): self.debug("Creating load balancing rule on IP %s & algo %s" % (self.public_ip.ipaddress.ipaddress, lb_method)) services = self.services["lbrule"] services["alg"] = lb_method lb_rule = self.create_LB_Rule( self.public_ip, network=self.get_Network(self.account), vmarray=[self.virtual_machine, self.virtual_machine_2], services=services) self.debug("Creating stickiness policy for the LB rule: %s" % lb_rule.id) policies = self.configure_Stickiness_Policy(lb_rule, method=method, paramDict=params) policy = policies.stickinesspolicy[0] self.debug("Policy: %s" % str(policy)) self.debug("Validating the stickiness policy") self.validate_Stickiness_Policy( lb_rule, method, self.public_ip.ipaddress.ipaddress) self.debug("Deleting the LB rule: %s" % lb_rule.name) lb_rule.delete(self.apiclient) with self.assertRaises(Exception): LoadBalancerRule.list(self.apiclient, id=lb_rule.id, listall=True) alerts = Alert.list(self.apiclient, keyword="stickiness", listall=True) self.debug( "Create/update/delete should not produce any alert/error") self.assertEqual( alerts, None, "Create/update/delete should not produce any alert/error") return
def test_05_error_alerts_after_create(self): """Test error/alerts after creating stickiness policy""" # Validate the following # 1. Create a LB rule with round Robin/Least connections/Source # listLoadBalancerRules should show newly created load balancer rule # 2. Configure the Stickiness policy to above created LB rule. # listLBStickinessPolicies Api should show newly created stickiness # 3. update & delete stickiness policy see error related to stickiness # 4. No errors should be shown in the logs and alerts lb_methods = ["roundrobin", "leastconn", "source"] configs = {"SourceBased": {"tablesize": '100k'}, "AppCookie": {"request-learn": "true"}, "LBCookie": {"nocache": "true"}} for lb_method in lb_methods: for method, params in configs.items(): self.debug("Creating load balancing rule on IP %s & algo %s" % (self.public_ip.ipaddress.ipaddress, lb_method)) services = self.services["lbrule"] services["alg"] = lb_method lb_rule = self.create_LB_Rule(self.public_ip, network=self.get_Network(self.account), vmarray=[self.virtual_machine, self.virtual_machine_2], services=services) self.debug("Creating stickiness policy for the LB rule: %s" % lb_rule.id) policies = self.configure_Stickiness_Policy(lb_rule, method=method, paramDict=params) policy = policies.stickinesspolicy[0] self.debug("Policy: %s" % str(policy)) self.debug("Validating the stickiness policy") self.validate_Stickiness_Policy(lb_rule, method, self.public_ip.ipaddress.ipaddress) self.debug("Deleting the LB rule: %s" % lb_rule.name) lb_rule.delete(self.apiclient) with self.assertRaises(Exception): LoadBalancerRule.list(self.apiclient, id=lb_rule.id, listall=True) alerts = Alert.list(self.apiclient, keyword="stickiness", listall=True) self.debug( "Create/update/delete should not produce any alert/error") self.assertEqual(alerts, None, "Create/update/delete should not produce any alert/error") return
def test_15_VPC_ReleaseIPForLBRuleCreated(self): """ Test release Ip address that has a LB rule assigned to it. # Validate the following # 1. Create a VPC1 with cidr - 10.1.1.1/16 # 2. Create a Network offering - NO1 with all supported services # 3. Add network1(10.1.1.1/24) using N01 to this VPC1. # 2. Create a Network offering - NO1 with all supported services # 5. Deploy vm1 and vm2 in network1 and network 2 primary host. # 6. aquire public ip address # 6. Create a StaticNat Rule rule for vm1 # 7. Use the Create LB rule for vm1 and vm2 in network1. # 8. LB rule creation should fail """ network_1 = self.create_network(self.services["network_offering"]) vm_1 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1) public_ip_1 = self.acquire_Public_IP(network_1) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_2, vm_1]) public_ip_1.delete(self.apiclient) self.cleanup.remove(public_ip_1) with self.assertRaises(Exception): lb_rules = LoadBalancerRule.list(self.apiclient, id=lb_rule.id, listall=True) return
def test_15_VPC_ReleaseIPForLBRuleCreated(self): """ Test release Ip address that has a LB rule assigned to it. """ # Validate the following # 1. Create a VPC1 with cidr - 10.1.1.1/16 # 2. Create a Network offering - NO1 with all supported services # 3. Add network1(10.1.1.1/24) using N01 to this VPC1. # 2. Create a Network offering - NO1 with all supported services # 5. Deploy vm1 and vm2 in network1 and network 2 primary host. # 6. aquire public ip address # 6. Create a StaticNat Rule rule for vm1 # 7. Use the Create LB rule for vm1 and vm2 in network1. # 8. LB rule creation should fail network_1 = self.create_Network(self.services["network_offering"]) vm_1 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1) public_ip_1 = self.acquire_Public_IP(network_1) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_2, vm_1]) public_ip_1.delete(self.apiclient) with self.assertRaises(Exception): lb_rules = LoadBalancerRule.list(self.apiclient, id=lb_rule.id, listall=True ) return
def test_01_VPC_LBRulesListing(self): """ Test case no 210 and 227: List Load Balancing Rules belonging to a VPC """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Create a Network offering - NO1 with all supported services # 3. Add network1(10.1.1.1/24) using N01 to this VPC. # 4. Add network2(10.1.2.1/24) using N01 to this VPC. # 5. Deploy vm1 and vm2 in network1. # 6. Deploy vm3 and vm4 in network2. # 7. Use the Create LB rule for vm1 and vm2 in network1. # 8. Use the Create LB rule for vm3 amd vm4 in network2, should fail # because it's no_lb offering # 9. List LB rule network_1 = self.create_Network(self.services["network_offering"]) network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') self.debug("deploying VMs in network: %s" % network_2.name) vm_1 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_2) vm_4 = self.create_VM_in_Network(network_2) public_ip_1 = self.acquire_Public_IP(network_1) lb_rule1 = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2]) # public_ip_2 = self.acquire_Public_IP(network_2) with self.assertRaises(Exception): self.create_LB_Rule(public_ip_2, network_2, [vm_3, vm_4]) lb_rules = LoadBalancerRule.list(self.apiclient, id=lb_rule1.id, listall=True ) self.failIfEqual(lb_rules, None, "Failed to list the LB Rule" ) vms = VirtualMachine.list(self.apiclient, networkid=network_1.id, listall=True ) self.failIfEqual(vms, None, "Failed to list the VMs in network=%s" % network_1.name ) return
def test_02_shared_another_network(self): # Create network self.debug("Creating network with network offering: %s" % 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.debug("Created network: %s" % self.network.id) self.debug("Trying VM deploy with network created on account: %s" % self.account.name) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, networkids=self.network.id, zoneid=self.zone.id, serviceofferingid=self.service_offering_shared.id ) self.debug("Deployed VM in network: %s" % self.network.id) list_vm_response = VirtualMachine.list( self.apiclient, id=self.virtual_machine.id ) self.debug( "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") vm_response = list_vm_response[0] self.assertEqual( vm_response.state, "Running", "VM state should be running after deployment" ) self.debug("Aquiring 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.debug( "Creating LB rule for IP address: %s with round robin algo" % 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 ) lb_rules = LoadBalancerRule.list( 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" ) self.debug("Adding %s to the LB rule %s" % ( self.virtual_machine.name, lb_rule.name )) lb_rule.assign(self.apiclient, [self.virtual_machine]) return
def test_01_dedicated_first_network(self): # Create network self.debug("Creating network with network offering: %s" % 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.debug("Created network: %s" % self.network.id) self.debug("Trying VM deploy with network created on account: %s" % self.account.name) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id, networkids=self.network.id, serviceofferingid=self.service_offering.id) self.debug("Deployed VM in network: %s" % self.network.id) list_vm_response = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "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") vm_response = list_vm_response[0] self.assertEqual(vm_response.state, "Running", "VM state should be running after deployment") self.debug("Aquiring 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.debug( "Creating LB rule for IP address: %s with round robin algo" % 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) lb_rules = LoadBalancerRule.list(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") self.debug("Adding %s to the LB rule %s" % (self.virtual_machine.name, lb_rule.name)) lb_rule.assign(self.apiclient, [self.virtual_machine])
def test_02_network_off_with_conserve_mode(self): """Test Network offering with Conserve mode ON and VR - All services """ # Validate the following # 1. Create a Network from the above network offering and deploy a VM. # 2. On source NAT ipaddress, we should be allowed to add a LB rules # 3. On source NAT ipaddress, we should be allowed to add a PF rules # 4. On source NAT ipaddress, we should be allowed to add a Firewall # rules # 5. On an ipaddress that has Lb rules, we should be allowed to # program PF rules. # 6. We should be allowed to program multiple PF rules on the same Ip # address on different public ports. # 7. We should be allowed to program multiple LB rules on the same Ip # address for different public port ranges. # 8. On source NAT ipaddress, we should be allowed to Enable VPN # access. # Create a network offering with all virtual router services enabled self.debug( "Creating n/w offering with all services in VR & conserve mode:off" ) self.network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=True ) self.cleanup.append(self.network_offering) self.debug("Created n/w offering with ID: %s" % self.network_offering.id) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') # Creating network using the network offering created self.debug("Creating network with network offering: %s" % self.network_offering.id) self.network = Network.create( self.apiclient, self.services["network"], accountid=self.account.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 = 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.debug("Deployed VM in network: %s" % self.network.id) src_nat_list = PublicIPAddress.list( 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" ) self.assertNotEqual( 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) # Create Load Balancer rule with source NAT lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], ipaddressid=src_nat.id, accountid=self.account.name ) self.debug("Created LB rule on source NAT: %s" % src_nat.ipaddress) lb_rules = LoadBalancerRule.list( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_rules, list), True, "List lb rules should return a valid lb rules" ) self.assertNotEqual( len(lb_rules), 0, "Length of response from listLbRules should not be 0" ) self.debug( "Trying to create a port forwarding rule in source NAT: %s" % src_nat.ipaddress) #Create NAT rule nat_rule = NATRule.create( self.apiclient, virtual_machine, self.services["natrule"], ipaddressid=src_nat.id ) self.debug("Created PF rule on source NAT: %s" % src_nat.ipaddress) nat_rules = NATRule.list( self.apiclient, id=nat_rule.id ) self.assertEqual( isinstance(nat_rules, list), True, "List NAT should return a valid port forwarding rules" ) self.assertNotEqual( len(nat_rules), 0, "Length of response from listLbRules should not be 0" ) self.debug("Creating firewall rule on source NAT: %s" % src_nat.ipaddress) #Create Firewall rule on source NAT fw_rule = FireWallRule.create( self.apiclient, ipaddressid=src_nat.id, protocol='TCP', cidrlist=[self.services["fw_rule"]["cidr"]], startport=self.services["fw_rule"]["startport"], endport=self.services["fw_rule"]["endport"] ) self.debug("Created firewall rule: %s" % fw_rule.id) fw_rules = FireWallRule.list( self.apiclient, id=fw_rule.id ) self.assertEqual( isinstance(fw_rules, list), True, "List fw rules should return a valid firewall rules" ) self.assertNotEqual( len(fw_rules), 0, "Length of fw rules response should not be zero" ) self.debug("Associating 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.debug("Associated %s with network %s" % ( public_ip.ipaddress, self.network.id )) self.debug("Creating PF rule for IP address: %s" % public_ip.ipaddress) NATRule.create( self.apiclient, virtual_machine, self.services["natrule"], ipaddressid=public_ip.ipaddress.id ) self.debug("Trying to create LB rule on IP with NAT: %s" % public_ip.ipaddress) # Create Load Balancer rule on IP already having NAT rule lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], ipaddressid=public_ip.ipaddress.id, accountid=self.account.name ) self.debug("Creating PF rule with public port: 66") nat_rule = NATRule.create( self.apiclient, virtual_machine, self.services["natrule_port_66"], ipaddressid=public_ip.ipaddress.id ) # Check if NAT rule created successfully nat_rules = NATRule.list( self.apiclient, id=nat_rule.id ) self.assertEqual( isinstance(nat_rules, list), True, "List NAT rules should return valid list" ) self.debug("Creating LB rule with public port: 2221") lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule_port_2221"], ipaddressid=public_ip.ipaddress.id, accountid=self.account.name ) # Check if NAT rule created successfully lb_rules = LoadBalancerRule.list( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_rules, list), True, "List LB rules should return valid list" ) # User should be able to enable VPN on source NAT self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress) # Assign VPN to source NAT Vpn.create( self.apiclient, src_nat.id, account=self.account.name, domainid=self.account.domainid ) vpns = Vpn.list( self.apiclient, publicipid=src_nat.id, listall=True, ) self.assertEqual( isinstance(vpns, list), True, "List VPNs should return a valid VPN list" ) self.assertNotEqual( len(vpns), 0, "Length of list VPN response should not be zero" ) return