Updated Branches: refs/heads/master e6ae66d59 -> 70c936bb8
CLOUDSTACK-702: Tests for Multiple IP Ranges 1.Deleting IP Range from the existing CIDR 2.Add non-contiguous guest IP range in new CIDR 3.Add overlapped guest IP range in existing CIDR Signed-off-by: sanjeevneelarapu <sanjeev.neelar...@citrix.com> Signed-off-by: Prasanna Santhanam <t...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/70c936bb Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/70c936bb Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/70c936bb Branch: refs/heads/master Commit: 70c936bb852cac885ab20ffc7276515215c08026 Parents: e6ae66d Author: sanjeevneelarapu <sanjeev.neelar...@citrix.com> Authored: Tue Apr 30 20:09:46 2013 +0530 Committer: Prasanna Santhanam <t...@apache.org> Committed: Mon May 6 14:28:32 2013 +0530 ---------------------------------------------------------------------- .../component/test_multiple_ip_ranges.py | 172 +++++++++++++-- 1 files changed, 152 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70c936bb/test/integration/component/test_multiple_ip_ranges.py ---------------------------------------------------------------------- diff --git a/test/integration/component/test_multiple_ip_ranges.py b/test/integration/component/test_multiple_ip_ranges.py index 489e7ca..29942bd 100644 --- a/test/integration/component/test_multiple_ip_ranges.py +++ b/test/integration/component/test_multiple_ip_ranges.py @@ -18,6 +18,7 @@ """ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * +from marvin.cloudstackException import cloudstackAPIException from marvin.integration.lib.utils import * from marvin.integration.lib.base import * from marvin.integration.lib.common import * @@ -88,7 +89,7 @@ class TestMultipleIpRanges(cloudstackTestCase): cls.services["account"], domainid=cls.domain.id ) - cls.services["account"] = cls.account.account.name + cls.services["account"] = cls.account.name cls._cleanup = [ cls.account, ] @@ -144,23 +145,23 @@ class TestMultipleIpRanges(cloudstackTestCase): "check list vlan response" ) self.assertEqual( - vlan[0].startip, - services["startip"], + str(vlan[0].startip), + str(services["startip"]), "Start IP in vlan ip range is not matched with the configured start ip" ) self.assertEqual( - vlan[0].endip, - services["endip"], + str(vlan[0].endip), + str(services["endip"]), "End IP in vlan ip range is not matched with the configured end ip" ) self.assertEqual( - vlan[0].gateway, - services["gateway"], + str(vlan[0].gateway), + str(services["gateway"]), "gateway in vlan ip range is not matched with the configured gateway" ) self.assertEqual( - vlan[0].netmask, - services["netmask"], + str(vlan[0].netmask), + str(services["netmask"]), "netmask in vlan ip range is not matched with the configured netmask" ) return @@ -172,12 +173,13 @@ class TestMultipleIpRanges(cloudstackTestCase): #call increment_cidr function to get exiting cidr from the setup and increment it ip2 = self.increment_cidr() test_nw = ip2.network + ip = IPAddress(test_nw) #Add IP range(5 IPs) in the new CIDR - test_gateway = test_nw+1 - test_startIp = test_nw+2 - test_endIp = test_startIp+5 - test_startIp2= test_endIp+5 - test_endIp2 = test_startIp2+5 + test_gateway = ip.__add__(1) + test_startIp = ip.__add__(3) + test_endIp = ip.__add__(10) + test_startIp2= ip.__add__(11) + test_endIp2 = ip.__add__(15) #Populating services with new IP range self.services["vlan_ip_range"]["startip"] = test_startIp self.services["vlan_ip_range"]["endip"] = test_endIp @@ -189,7 +191,7 @@ class TestMultipleIpRanges(cloudstackTestCase): new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) self.cleanup.append(new_vlan) - new_vlan_res = new_vlan.list(self.apiclient,new_vlan.id) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) #Compare list output with configured values self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) #Add few more ips in the same CIDR @@ -199,7 +201,7 @@ class TestMultipleIpRanges(cloudstackTestCase): self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp2,test_endIp2)) self.cleanup.append(new_vlan2) #list new vlan ip range - new_vlan2_res = new_vlan2.list(self.apiclient,new_vlan2.id) + new_vlan2_res = new_vlan2.list(self.apiclient,id=new_vlan2.vlan.id) #Compare list output with configured values self.verify_vlan_range(new_vlan2_res,self.services["vlan_ip_range"]) return @@ -215,10 +217,11 @@ class TestMultipleIpRanges(cloudstackTestCase): #call increment_cidr function to get exiting cidr from the setup and increment it ip2 = self.increment_cidr() test_nw = ip2.network + ip = IPAddress(test_nw) #Add IP range(5 IPs) in the new CIDR - test_gateway = test_nw+1 - test_startIp = test_nw+2 - test_endIp = test_startIp+5 + test_gateway = ip.__add__(1) + test_startIp = ip.__add__(3) + test_endIp = ip.__add__(10) #Populating services with new IP range self.services["vlan_ip_range"]["startip"] = test_startIp self.services["vlan_ip_range"]["endip"] = test_endIp @@ -230,9 +233,138 @@ class TestMultipleIpRanges(cloudstackTestCase): new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) self.cleanup.append(new_vlan) - new_vlan_res = new_vlan.list(self.apiclient,new_vlan.id) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) #Compare list output with configured values self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) return + @attr(tags=["advanced-sg", "sg"]) + def test_03_del_ip_range(self): + """Test delete ip range + Steps: + 1.Add ip range in same/new cidr + 2.delete the ip range added at step1 + 3.Verify the ip range deletion using list APIs + """ + #call increment_cidr function to get exiting cidr from the setup and increment it + ip2 = self.increment_cidr() + test_nw = ip2.network + ip = IPAddress(test_nw) + #Add IP range(5 IPs) in the new CIDR + test_gateway = ip.__add__(1) + test_startIp = ip.__add__(3) + test_endIp = ip.__add__(10) + #Populating services with new IP range + self.services["vlan_ip_range"]["startip"] = test_startIp + self.services["vlan_ip_range"]["endip"] = test_endIp + self.services["vlan_ip_range"]["gateway"] = test_gateway + self.services["vlan_ip_range"]["netmask"] = self.netmask + self.services["vlan_ip_range"]["zoneid"] = self.zone.id + self.services["vlan_ip_range"]["podid"] = self.pod.id + #create new vlan ip range + new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) + self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) + #Compare list output with configured values + self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) + #Delete the above IP range + new_vlan.delete(self.apiclient) + #listing vlan ip ranges with the id should through exception , if not mark the test case as failed + try: + new_vlan.list(self.apiclient, id=new_vlan.vlan.id) + except cloudstackAPIException as cs: + self.debug(cs.errorMsg) + self.assertTrue(cs.errorMsg.find("entity does not exist")>0, msg="Failed to delete IP range") + return + + @attr(tags=["advanced-sg", "sg"]) + def test_04_add_noncontiguous_ip_range(self): + """Test adding non-contiguous ip range in existing cidr + + 1.Add ip range in new cidr + 1.Add non-contigous ip range in cidr added at step1 + 2.Verify the ip range using list APIs + """ + #call increment_cidr function to get exiting cidr from the setup and increment it + ip2 = self.increment_cidr() + test_nw = ip2.network + ip = IPAddress(test_nw) + #Add IP range(5 IPs) in the new CIDR + test_gateway = ip.__add__(1) + test_startIp = ip.__add__(50) + test_endIp = ip.__add__(60) + #Populating services with new IP range + self.services["vlan_ip_range"]["startip"] = test_startIp + self.services["vlan_ip_range"]["endip"] = test_endIp + self.services["vlan_ip_range"]["gateway"] = test_gateway + self.services["vlan_ip_range"]["netmask"] = self.netmask + self.services["vlan_ip_range"]["zoneid"] = self.zone.id + self.services["vlan_ip_range"]["podid"] = self.pod.id + #create new vlan ip range + new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) + self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) + self.cleanup.append(new_vlan) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) + #Compare list output with configured values + self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) + #Add non-contiguous ip range in exiting cidr + test_startIp2 = ip.__add__(10) + test_endIp2 = ip.__add__(20) + #Populating services with new IP range + self.services["vlan_ip_range"]["startip"] = test_startIp2 + self.services["vlan_ip_range"]["endip"] = test_endIp2 + #create new vlan ip range + new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) + self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) + self.cleanup.append(new_vlan) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) + #Compare list output with configured values + self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) + return + + @attr(tags=["advanced-sg", "sg"]) + def test_05_add_overlapped_ip_range(self): + """Test adding overlapped ip range in existing cidr + + 1.Add ip range in new cidr e.g:10.147.40.10-10.147.40.100 + 2.Add ip range overlapped with the ip range in step1 e.g.10.147.40.90-150 + """ + #call increment_cidr function to get exiting cidr from the setup and increment it + ip2 = self.increment_cidr() + test_nw = ip2.network + ip = IPAddress(test_nw) + #Add IP range in the new CIDR + test_gateway = ip.__add__(1) + test_startIp = ip.__add__(10) + test_endIp = ip.__add__(100) + test_startIp2 = ip.__add__(90) + test_endIp2 = ip.__add__(150) + #Populating services with new IP range + self.services["vlan_ip_range"]["startip"] = test_startIp + self.services["vlan_ip_range"]["endip"] = test_endIp + self.services["vlan_ip_range"]["gateway"] = test_gateway + self.services["vlan_ip_range"]["netmask"] = self.netmask + self.services["vlan_ip_range"]["zoneid"] = self.zone.id + self.services["vlan_ip_range"]["podid"] = self.pod.id + #create new vlan ip range + new_vlan = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) + self.debug("Created new vlan range with startip:%s and endip:%s" %(test_startIp,test_endIp)) + self.cleanup.append(new_vlan) + new_vlan_res = new_vlan.list(self.apiclient,id=new_vlan.vlan.id) + #Compare list output with configured values + self.verify_vlan_range(new_vlan_res,self.services["vlan_ip_range"]) + #Add overlapped ip range + #Populating services with new IP range + self.services["vlan_ip_range"]["startip"] = test_startIp2 + self.services["vlan_ip_range"]["endip"] = test_endIp2 + #Try to create ip range overlapped with exiting ip range + try: + PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) + except cloudstackAPIException as cs: + self.debug(cs.errorMsg) + self.assertTrue(cs.errorMsg.find("already has IPs that overlap with the new range")>0, msg="Fail:CS allowed adding overlapped ip ranges in guest cidr") + return + #Test will reach here there is a bug in overlap ip range checking + self.fail("CS should not accept overlapped ip ranges in guest traffic, but it allowed") + return