def check_lb_rules(self, lb_rule_id, vm_ids): """ Check Loadbalancer rules :param lb_rule_id: Load balancer uuid :param vm_ids: List of VM uuid's :return: """ lb_instance_rules = list_lb_instances(self.apiclient, id=lb_rule_id) self.assertEqual(isinstance(lb_instance_rules, list), True, "Check list response returns a valid list") self.assertNotEqual(len(lb_instance_rules), 0, "Check Load Balancer instances Rule in its List") self.logger.debug("lb_instance_rules Ids: %s, %s" % (lb_instance_rules[0].id, lb_instance_rules[1].id)) self.logger.debug("VM ids: %s" % ", ".join(vm_ids)) self.assertIn( lb_instance_rules[0].id, vm_ids, "Check List Load Balancer instances Rules returns valid VM ID") self.assertIn( lb_instance_rules[1].id, vm_ids, "Check List Load Balancer instances Rules returns valid VM ID")
def test_02_create_lb_rule_non_nat(self): """Test to create Load balancing rule with non source NAT""" # Validate the Following: # 1. listLoadBalancerRules should return the added rule # 2. attempt to ssh twice on the load balanced IP # 3. verify using the UNAME of the VM that # round robin is indeed happening as expected # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], self.non_src_nat_ip.ipaddress.id, accountid=self.account.name, vpcid=self.vpc1.id, networkid=self.network1.id ) self.cleanup.append(lb_rule) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) lb_rules = list_lb_rules( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_rules, list), True, "Check list response returns a valid list" ) # verify listLoadBalancerRules lists the added load balancing rule self.assertNotEqual( len(lb_rules), 0, "Check Load Balancer Rule in its List" ) self.assertEqual( lb_rules[0].id, lb_rule.id, "Check List Load Balancer Rules returns valid Rule" ) # listLoadBalancerRuleInstances should list # all instances associated with that LB rule lb_instance_rules = list_lb_instances( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_instance_rules, list), True, "Check list response returns a valid list" ) self.assertNotEqual( len(lb_instance_rules), 0, "Check Load Balancer instances Rule in its List" ) self.assertIn( lb_instance_rules[0].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID" ) self.assertIn( lb_instance_rules[1].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID" ) try: unameResults = [] self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.logger.debug("UNAME: %s" % str(unameResults)) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server1" ) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server2" ) # SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) self.logger.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % ( self.non_src_nat_ip.ipaddress.ipaddress, self.vm_2.id )) # Making host list empty unameResults[:] = [] self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server1" ) self.logger.debug("UNAME after removing VM2: %s" % str(unameResults)) except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, self.non_src_nat_ip.ipaddress.ipaddress)) lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): self.logger.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % ( self.non_src_nat_ip.ipaddress.ipaddress, self.vm_1.id )) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) return
def test_01_create_lb_rule_src_nat(self): """Test to create Load balancing rule with source NAT""" # Validate the Following: # 1. listLoadBalancerRules should return the added rule # 2. attempt to ssh twice on the load balanced IP # 3. verify using the UNAME of the VM # that round robin is indeed happening as expected src_nat_ip_addrs = PublicIPAddress.list( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(src_nat_ip_addrs, list), True, "Check list response returns a valid list" ) src_nat_ip_addr = src_nat_ip_addrs[0] # Check if VM is in Running state before creating LB rule vm_response = VirtualMachine.list( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(vm_response, list), True, "Check list VM returns a valid list" ) self.assertNotEqual( len(vm_response), 0, "Check Port Forwarding Rule is created" ) for vm in vm_response: self.assertEqual( vm.state, 'Running', "VM state should be Running before creating a NAT rule." ) # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], src_nat_ip_addr.id, accountid=self.account.name, vpcid=self.vpc1.id, networkid=self.network1.id ) self.cleanup.append(lb_rule) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) lb_rules = list_lb_rules( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_rules, list), True, "Check list response returns a valid list" ) # verify listLoadBalancerRules lists the added load balancing rule self.assertNotEqual( len(lb_rules), 0, "Check Load Balancer Rule in its List" ) self.assertEqual( lb_rules[0].id, lb_rule.id, "Check List Load Balancer Rules returns valid Rule" ) # listLoadBalancerRuleInstances should list all # instances associated with that LB rule lb_instance_rules = list_lb_instances( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_instance_rules, list), True, "Check list response returns a valid list" ) self.assertNotEqual( len(lb_instance_rules), 0, "Check Load Balancer instances Rule in its List" ) self.logger.debug("lb_instance_rules Ids: %s, %s" % ( lb_instance_rules[0].id, lb_instance_rules[1].id )) self.logger.debug("VM ids: %s, %s" % (self.vm_1.id, self.vm_2.id)) self.assertIn( lb_instance_rules[0].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID" ) self.assertIn( lb_instance_rules[1].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID" ) unameResults = [] self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.logger.debug("UNAME: %s" % str(unameResults)) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server1" ) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server2" ) # SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) # making unameResultss list empty unameResults[:] = [] try: self.logger.debug("SSHing into IP address: %s after removing VM (ID: %s)" % ( src_nat_ip_addr.ipaddress, self.vm_2.id )) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.assertIn( "Linux", unameResults, "Check if ssh succeeded for server1" ) except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, src_nat_ip_addr.ipaddress)) lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): self.logger.debug("Removed all VMs, trying to SSH") self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) return
def test_02_create_lb_rule_non_nat(self): """Test to create Load balancing rule with non source NAT""" # Validate the Following: # 1. listLoadBalancerRules should return the added rule # 2. attempt to ssh twice on the load balanced IP # 3. verify using the UNAME of the VM that # round robin is indeed happening as expected # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], self.non_src_nat_ip.ipaddress.id, accountid=self.account.name, vpcid=self.vpc1.id, networkid=self.network1.id) self.cleanup.append(lb_rule) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) lb_rules = list_lb_rules(self.apiclient, id=lb_rule.id) self.assertEqual(isinstance(lb_rules, list), True, "Check list response returns a valid list") # verify listLoadBalancerRules lists the added load balancing rule self.assertNotEqual(len(lb_rules), 0, "Check Load Balancer Rule in its List") self.assertEqual(lb_rules[0].id, lb_rule.id, "Check List Load Balancer Rules returns valid Rule") # listLoadBalancerRuleInstances should list # all instances associated with that LB rule lb_instance_rules = list_lb_instances(self.apiclient, id=lb_rule.id) self.assertEqual(isinstance(lb_instance_rules, list), True, "Check list response returns a valid list") self.assertNotEqual(len(lb_instance_rules), 0, "Check Load Balancer instances Rule in its List") self.assertIn( lb_instance_rules[0].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID") self.assertIn( lb_instance_rules[1].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID") try: unameResults = [] self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.logger.debug("UNAME: %s" % str(unameResults)) self.assertIn("Linux", unameResults, "Check if ssh succeeded for server1") self.assertIn("Linux", unameResults, "Check if ssh succeeded for server2") # SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) self.logger.debug( "SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % (self.non_src_nat_ip.ipaddress.ipaddress, self.vm_2.id)) # Making host list empty unameResults[:] = [] self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) self.assertIn("Linux", unameResults, "Check if ssh succeeded for server1") self.logger.debug("UNAME after removing VM2: %s" % str(unameResults)) except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, self.non_src_nat_ip.ipaddress.ipaddress)) lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): self.logger.debug( "SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % (self.non_src_nat_ip.ipaddress.ipaddress, self.vm_1.id)) self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults) return
def test_01_create_lb_rule_src_nat(self): """Test to create Load balancing rule with source NAT""" # Validate the Following: # 1. listLoadBalancerRules should return the added rule # 2. attempt to ssh twice on the load balanced IP # 3. verify using the UNAME of the VM # that round robin is indeed happening as expected src_nat_ip_addrs = PublicIPAddress.list(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(src_nat_ip_addrs, list), True, "Check list response returns a valid list") src_nat_ip_addr = src_nat_ip_addrs[0] # Check if VM is in Running state before creating LB rule vm_response = VirtualMachine.list(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(vm_response, list), True, "Check list VM returns a valid list") self.assertNotEqual(len(vm_response), 0, "Check Port Forwarding Rule is created") for vm in vm_response: self.assertEqual( vm.state, 'Running', "VM state should be Running before creating a NAT rule.") # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], src_nat_ip_addr.id, accountid=self.account.name, vpcid=self.vpc1.id, networkid=self.network1.id) self.cleanup.append(lb_rule) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) lb_rules = list_lb_rules(self.apiclient, id=lb_rule.id) self.assertEqual(isinstance(lb_rules, list), True, "Check list response returns a valid list") # verify listLoadBalancerRules lists the added load balancing rule self.assertNotEqual(len(lb_rules), 0, "Check Load Balancer Rule in its List") self.assertEqual(lb_rules[0].id, lb_rule.id, "Check List Load Balancer Rules returns valid Rule") # listLoadBalancerRuleInstances should list all # instances associated with that LB rule lb_instance_rules = list_lb_instances(self.apiclient, id=lb_rule.id) self.assertEqual(isinstance(lb_instance_rules, list), True, "Check list response returns a valid list") self.assertNotEqual(len(lb_instance_rules), 0, "Check Load Balancer instances Rule in its List") self.logger.debug("lb_instance_rules Ids: %s, %s" % (lb_instance_rules[0].id, lb_instance_rules[1].id)) self.logger.debug("VM ids: %s, %s" % (self.vm_1.id, self.vm_2.id)) self.assertIn( lb_instance_rules[0].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID") self.assertIn( lb_instance_rules[1].id, [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID") unameResults = [] self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.logger.debug("UNAME: %s" % str(unameResults)) self.assertIn("Linux", unameResults, "Check if ssh succeeded for server1") self.assertIn("Linux", unameResults, "Check if ssh succeeded for server2") # SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) # making unameResultss list empty unameResults[:] = [] try: self.logger.debug( "SSHing into IP address: %s after removing VM (ID: %s)" % (src_nat_ip_addr.ipaddress, self.vm_2.id)) self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) self.assertIn("Linux", unameResults, "Check if ssh succeeded for server1") except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, src_nat_ip_addr.ipaddress)) lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): self.logger.debug("Removed all VMs, trying to SSH") self.try_ssh(src_nat_ip_addr.ipaddress, unameResults) return