CLOUDSTACK-702: 1. Moved common code to setupClass method 2. Added a test to deply vm in new CIDR and verify dns service on alias IP

Conflicts:

	test/integration/component/maint/test_multiple_ip_ranges.py

Signed-off-by: sanjeevneelarapu <sanjeev.neelarapu@citrix.com>
Signed-off-by: venkataswamybabu budumuru <venkataswamybabu.budumuru@citrix.com>
(cherry picked from commit 1efd544ee27fd0c7c9eac4649568647c0dcbc85b)
This commit is contained in:
sanjeevneelarapu 2013-10-03 22:34:55 +05:30 committed by venkataswamybabu budumuru
parent 6e80bb001c
commit f6c6f03fad

View File

@ -59,11 +59,11 @@ class Services:
"ostype": "CentOS 5.3 (64-bit)", "ostype": "CentOS 5.3 (64-bit)",
"templatefilter": 'self', "templatefilter": 'self',
}, },
"vlan_ip_range": { "vlan_ip_range": {
"startip": "", "startip": "10.147.43.130",
"endip": "", "endip": "10.147.43.135",
"netmask": "", "netmask": "255.255.255.192",
"gateway": "", "gateway": "10.147.43.129",
"forvirtualnetwork": "false", "forvirtualnetwork": "false",
"vlan": "untagged", "vlan": "untagged",
}, },
@ -73,14 +73,12 @@ class Services:
"password": "password", "password": "password",
"hypervisor": 'XenServer', "hypervisor": 'XenServer',
}, },
"cidr": { "host": {
"name": "cidr1 -Test", "publicport": 22,
"gateway" :"10.147.43.1", "username": "root", # Host creds for SSH
"netmask" :"255.255.255.128", "password": "password",
"startip" :"10.147.43.3",
"endip" :"10.147.43.10",
}, },
"ostype": "CentOS 5.3 (64-bit)", "ostype": "CentOS 5.3 (64-bit)",
"sleep": 60, "sleep": 60,
"timeout": 10, "timeout": 10,
} }
@ -88,11 +86,10 @@ class Services:
class TestMultipleIpRanges(cloudstackTestCase): class TestMultipleIpRanges(cloudstackTestCase):
"""Test Multiple IP Ranges for guest network """Test Multiple IP Ranges for guest network
""" """
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.api_client = super(TestMultipleIpRanges, cls).getClsTestClient().getApiClient() cls.api_client = super(TestMultipleIpRanges, cls).getClsTestClient().getApiClient()
cls.dbclient = super(TestMultipleIpRanges, cls).getClsTestClient().getDbConnection()
cls.services = Services().services cls.services = Services().services
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client, cls.services) cls.domain = get_domain(cls.api_client, cls.services)
@ -122,7 +119,49 @@ class TestMultipleIpRanges(cloudstackTestCase):
) )
cls.services["templates"]["ostypeid"] = cls.template.ostypeid cls.services["templates"]["ostypeid"] = cls.template.ostypeid
cls.services["diskoffering"] = cls.disk_offering.id cls.services["diskoffering"] = cls.disk_offering.id
cls.dc_id = cls.dbclient.execute(
"select id from data_center where uuid = '%s';" % str(cls.services["zoneid"])
)
cls.dc_id = cls.dc_id[0][0]
cls.ids = cls.dbclient.execute(
"select id from user_ip_address where allocated is null and data_center_id = '%s';" % str(cls.dc_id)
)
cls.id_list = []
for i in range(len(cls.ids)):
cls.id_list.append(cls.ids[i][0])
#Check if VR is already present in the setup
vr_list = Router.list(cls.api_client, listall='true')
cls.debug("vr list {}".format(vr_list))
if isinstance(vr_list, list) and len(vr_list) > 0:
cls.debug("VR is running in the setup")
cls.vr_state = True
else:
cls.debug("VR is not present in the setup")
cls.vr_state = False
cls.id_list = cls.id_list[:-2]
for id in cls.id_list:
cls.dbclient.execute(
"update user_ip_address set allocated=now() where id = '%s';" % str(id)
)
#Add IP range in the new CIDR
cls.services["vlan_ip_range"]["zoneid"] = cls.zone.id
cls.services["vlan_ip_range"]["podid"] = cls.pod.id
#create new vlan ip range
cls.new_vlan = PublicIpRange.create(cls.api_client, cls.services["vlan_ip_range"])
#Deploy vm in existing subnet if VR is not present
if cls.vr_state is False :
cls.vm_res = VirtualMachine.create(
cls.api_client,
cls.services["server_without_disk"],
templateid = cls.template.id,
accountid = cls.account.name,
domainid = cls.services["domainid"],
zoneid = cls.services["zoneid"],
serviceofferingid = cls.service_offering.id,
mode = cls.services["mode"],
)
cls._cleanup = [ cls._cleanup = [
cls.new_vlan,
cls.account, cls.account,
] ]
return return
@ -130,6 +169,10 @@ class TestMultipleIpRanges(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
for id in cls.id_list:
cls.dbclient.execute(
"update user_ip_address set allocated=default where id = '%s';" % str(id)
)
#Cleanup resources used #Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup) cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
@ -184,104 +227,12 @@ class TestMultipleIpRanges(cloudstackTestCase):
) )
return return
def list_Routers(self): @attr(tags=["sg"])
"""Check if any VR is already present in the setup
Will return True if yes else return False
"""
list_zone = Zone.list(self.apiclient)
network_type = list_zone[0].networktype
sg_enabled = list_zone[0].securitygroupsenabled
if network_type == "Basic":
vr_list = Router.list(self.apiclient, listall='true')
self.debug("vr list {}".format(vr_list))
if isinstance(vr_list,list) and len(vr_list) > 0:
self.debug("VR is running in the setup")
return True
else:
self.debug("VR is not present in the setup")
return False
elif network_type == "Advanced" and sg_enabled == True:
nw_list = Network.list(
self.apiclient,
supportedservices='SecurityGroup',
)
nw_id = nw_list[0].id
vr_list = Router.list(
self.apiclient,
networkid = nw_id,
listall = 'true',
)
if isinstance(vr_list, list) and len(vr_list) > 0:
self.debug("VR is present in the setup")
return True
else :
self.debug("VR is not present in the setup")
return False
else :
self.debug("Network type is not shared")
return None
def test_01_deploy_vm_in_new_cidr(self): def test_01_deploy_vm_in_new_cidr(self):
"""Deploy guest vm after adding guest IP range in new CIDR """Deploy guest vm after adding guest IP range in new CIDR
1.Deploy guest vm
1.Add IP range in new CIDR 2.Verify vm gets the ip address from new cidr
2.Deploy guest vm
""" """
dc_id = self.dbclient.execute(
"select id from data_center where uuid = '%s';" % str(self.services["zoneid"])
)
dc_id = dc_id[0][0]
id_list = self.dbclient.execute(
"select id from user_ip_address where allocated is null and data_center_id = '%s';" % str(dc_id)
)
ip_list = []
for i in range(len(id_list)):
ip_list.append(id_list[i][0])
#Check if VR is already present in the setup
vr_state = self.list_Routers();
if vr_state is True :
for id in ip_list:
self.dbclient.execute(
"update user_ip_address set allocated=now() where id = '%s';" % str(id)
)
else :
ip_list = ip_list[:-2]
for id in ip_list:
self.dbclient.execute(
"update user_ip_address set allocated=now() where id = '%s';" % str(id)
)
#Add IP range in the new CIDR
test_gateway = self.services["cidr"]["gateway"]
test_startIp = self.services["cidr"]["startip"]
test_endIp = self.services["cidr"]["endip"]
test_netmask = self.services["cidr"]["netmask"]
#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"] = test_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"])
#Deploy vm in existing subnet if VR is not present
if vr_state is False :
vm_res = VirtualMachine.create(
self.apiclient,
self.services["server_without_disk"],
templateid = self.template.id,
accountid = self.account.name,
domainid = self.services["domainid"],
zoneid = self.services["zoneid"],
serviceofferingid = self.service_offering.id,
mode = self.services["mode"],
)
self.cleanup.append(vm_res)
#Deploy guest vm #Deploy guest vm
try : try :
self.virtual_machine = VirtualMachine.create( self.virtual_machine = VirtualMachine.create(
@ -296,12 +247,6 @@ class TestMultipleIpRanges(cloudstackTestCase):
) )
except Exception as e : except Exception as e :
raise Exception("Warning: Exception during vm deployment: {}".format(e)) raise Exception("Warning: Exception during vm deployment: {}".format(e))
finally :
#Mark ip_Adddresses allocated state to Null which were marked as allocated at the beginning of the test
for id in ip_list :
self.dbclient.execute(
"update user_ip_address set allocated=default where id = '%s';" % str(id)
)
self.vm_response = VirtualMachine.list( self.vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id = self.virtual_machine.id id = self.virtual_machine.id
@ -311,7 +256,7 @@ class TestMultipleIpRanges(cloudstackTestCase):
True, True,
"Check VM list response returned a valid list" "Check VM list response returned a valid list"
) )
self.ip_range = list(netaddr.iter_iprange(unicode(self.services["cidr"]["startip"]), unicode(self.services["cidr"]["endip"]))) self.ip_range = list(netaddr.iter_iprange(unicode(self.services["vlan_ip_range"]["startip"]), unicode(self.services["vlan_ip_range"]["endip"])))
self.nic_ip = netaddr.IPAddress(unicode(self.vm_response[0].nic[0].ipaddress)) self.nic_ip = netaddr.IPAddress(unicode(self.vm_response[0].nic[0].ipaddress))
self.debug("vm got {} as ip address".format(self.nic_ip)) self.debug("vm got {} as ip address".format(self.nic_ip))
self.assertIn( self.assertIn(
@ -335,3 +280,107 @@ class TestMultipleIpRanges(cloudstackTestCase):
time.sleep(wait_time) time.sleep(wait_time)
return return
@attr(tags=["sg"])
def test_02_deploy_vm_in_new_cidr(self):
"""Deploy guest vm in new CIDR and verify
1.Deploy guest vm in new cidr
2.Verify dns service listens on alias ip in VR
"""
#Deploy guest vm
try :
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["server_without_disk"],
templateid = self.template.id,
accountid = self.account.name,
domainid = self.services["domainid"],
zoneid = self.services["zoneid"],
serviceofferingid = self.service_offering.id,
mode = self.services["mode"],
)
except Exception as e :
raise Exception("Warning: Exception during vm deployment: {}".format(e))
self.vm_response = VirtualMachine.list(
self.apiclient,
id = self.virtual_machine.id
)
self.assertEqual(
isinstance(self.vm_response, list),
True,
"Check VM list response returned a valid list"
)
self.ip_range = list(netaddr.iter_iprange(unicode(self.services["vlan_ip_range"]["startip"]), unicode(self.services["vlan_ip_range"]["endip"])))
self.nic_ip = netaddr.IPAddress(unicode(self.vm_response[0].nic[0].ipaddress))
self.debug("vm got {} as ip address".format(self.nic_ip))
self.assertIn(
self.nic_ip,
self.ip_range,
"VM did not get the ip address from the new ip range"
)
ip_alias = self.dbclient.execute(
"select ip4_address from nic_ip_alias;"
)
alias_ip = str(ip_alias[0][0])
self.debug("alias ip : %s" % alias_ip)
list_router_response = list_routers(
self.apiclient,
zoneid=self.zone.id,
listall=True
)
self.assertEqual(
isinstance(list_router_response, list),
True,
"Check list response returns a valid list"
)
router = list_router_response[0]
hosts = list_hosts(
self.apiclient,
zoneid=router.zoneid,
type='Routing',
state='Up',
id=router.hostid
)
self.assertEqual(
isinstance(hosts, list),
True,
"Check list host returns a valid list"
)
host = hosts[0]
self.debug("Router ID: %s, state: %s" % (router.id, router.state))
self.assertEqual(
router.state,
'Running',
"Check list router response for router state"
)
proc = alias_ip+":53"
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
"netstat -atnp | grep %s" % proc
)
res = str(result)
self.debug("Dns process status on alias ip: %s" % res)
self.assertNotEqual(
res.find(proc)
-1,
"dnsmasq service is not running on alias ip"
)
self.virtual_machine.delete(self.apiclient)
expunge_del = Configurations.list(
self.apiclient,
name = 'expunge.delay'
)
expunge_int = Configurations.list(
self.apiclient,
name = 'expunge.interval'
)
wait_time = int(expunge_del[0].value) + int(expunge_int[0].value) + int(30)
self.debug("Waiting for {} seconds for the vm to expunge".format(wait_time))
#wait for the vm to expunge
time.sleep(wait_time)
return