CLOUDSTACK-702: Added tests for alias ip verifications on VR 1. Moved vm deployment code to setup and vm deletion code teadDown methods 2. Added two tests which would verify alias removal after last vm expunge in CIDR and alias status after VR reboot

CLOUDSTACK-702: Test for verifying ip alias after VR stop start
     1.Deploy vm in new cidr which will create ip alias on existing VR
	Stop,start VR and verify ip alias

Conflicts:

	test/integration/component/maint/test_multiple_ip_ranges.py

Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
sanjeevneelarapu 2013-10-21 20:21:11 +05:30 committed by SrikanteswaraRao Talluri
parent a77435dab5
commit 2103068816

View File

@ -24,7 +24,6 @@ from marvin.integration.lib.base import *
from marvin.integration.lib.common import * from marvin.integration.lib.common import *
# from netaddr import * # from netaddr import *
import netaddr import netaddr
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
class Services: class Services:
@ -147,7 +146,11 @@ class TestMultipleIpRanges(cloudstackTestCase):
cls.services["vlan_ip_range"]["zoneid"] = cls.zone.id cls.services["vlan_ip_range"]["zoneid"] = cls.zone.id
cls.services["vlan_ip_range"]["podid"] = cls.pod.id cls.services["vlan_ip_range"]["podid"] = cls.pod.id
# create new vlan ip range # create new vlan ip range
# Before creating ip range check the zone's network type
if cls.zone.networktype == 'Basic':
cls.new_vlan = PublicIpRange.create(cls.api_client, cls.services["vlan_ip_range"]) cls.new_vlan = PublicIpRange.create(cls.api_client, cls.services["vlan_ip_range"])
else:
raise unittest.SkipTest("These tests can be run only on basic zone. So skipping the tests")
# Deploy vm in existing subnet if VR is not present # Deploy vm in existing subnet if VR is not present
if cls.vr_state is False : if cls.vr_state is False :
cls.vm_res = VirtualMachine.create( cls.vm_res = VirtualMachine.create(
@ -173,6 +176,9 @@ class TestMultipleIpRanges(cloudstackTestCase):
cls.dbclient.execute( cls.dbclient.execute(
"update user_ip_address set allocated=default where id = '%s';" % str(id) "update user_ip_address set allocated=default where id = '%s';" % str(id)
) )
# Wait for expunge interval to cleanup VMs
wait_for_cleanup(cls.api_client, ["expunge.delay", "expunge.interval"])
time.sleep(30)
# 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:
@ -183,6 +189,48 @@ class TestMultipleIpRanges(cloudstackTestCase):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection() self.dbclient = self.testClient.getDbConnection()
self.cleanup = [ ] self.cleanup = [ ]
# 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;"
)
self.alias_ip = str(ip_alias[0][0])
self.debug("alias ip : %s" % self.alias_ip)
self.assertNotEqual(
self.alias_ip,
None,
"Error in creating ip alias. Please check MS logs"
)
self.cleanup.append(self.virtual_machine)
return return
def tearDown(self): def tearDown(self):
@ -233,29 +281,6 @@ class TestMultipleIpRanges(cloudstackTestCase):
1.Deploy guest vm 1.Deploy guest vm
2.Verify vm gets the ip address from new cidr 2.Verify vm gets the ip address from new cidr
""" """
#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.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))
@ -264,64 +289,14 @@ class TestMultipleIpRanges(cloudstackTestCase):
self.ip_range, self.ip_range,
"VM did not get the ip address from the new ip range" "VM did not get the ip address from the new ip range"
) )
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 return
@attr(tags=["sg"]) @attr(tags=["sg"])
def test_02_deploy_vm_in_new_cidr(self): def test_02_dns_service_on_alias_ip(self):
"""Deploy guest vm in new CIDR and verify """Deploy guest vm in new CIDR and verify dns service on alias ip
1.Deploy guest vm in new cidr 1.Deploy guest vm in new cidr
2.Verify dns service listens on alias ip in VR 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( list_router_response = list_routers(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
@ -352,7 +327,7 @@ class TestMultipleIpRanges(cloudstackTestCase):
'Running', 'Running',
"Check list router response for router state" "Check list router response for router state"
) )
proc = alias_ip+":53" proc = self.alias_ip + ":53"
result = get_process_status( result = get_process_status(
host.ipaddress, host.ipaddress,
self.services['host']["publicport"], self.services['host']["publicport"],
@ -368,20 +343,6 @@ class TestMultipleIpRanges(cloudstackTestCase):
- 1, - 1,
"dnsmasq service is not running on alias ip" "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 return
@attr(tags=["sg"]) @attr(tags=["sg"])
@ -390,42 +351,6 @@ class TestMultipleIpRanges(cloudstackTestCase):
1.Deploy guest vm in new cidr 1.Deploy guest vm in new cidr
2.Verify password service(socat) listens on alias ip in VR 2.Verify password service(socat) 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( list_router_response = list_routers(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
@ -468,24 +393,10 @@ class TestMultipleIpRanges(cloudstackTestCase):
res = str(result) res = str(result)
self.debug("password process status on VR: %s" % res) self.debug("password process status on VR: %s" % res)
self.assertNotEqual( self.assertNotEqual(
res.find(alias_ip) res.find(self.alias_ip)
- 1, - 1,
"password service is not running on alias ip" "password 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 return
@attr(tags=["sg"]) @attr(tags=["sg"])
@ -494,42 +405,6 @@ class TestMultipleIpRanges(cloudstackTestCase):
1.Deploy guest vm in new cidr 1.Deploy guest vm in new cidr
2.Verify userdata service(apache2) listens on alias ip in VR 2.Verify userdata service(apache2) 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( list_router_response = list_routers(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
@ -572,10 +447,66 @@ class TestMultipleIpRanges(cloudstackTestCase):
res = str(result) res = str(result)
self.debug("userdata process status on VR: %s" % res) self.debug("userdata process status on VR: %s" % res)
self.assertNotEqual( self.assertNotEqual(
res.find(alias_ip+":80 ") res.find(self.alias_ip + ":80 ")
- 1, - 1,
"password service is not running on alias ip" "password service is not running on alias ip"
) )
return
@attr(tags=["sg"])
def test_05_del_cidr_verify_alias_removal(self):
"""Destroy lastvm in the CIDR and verifly alias removal
1.Deploy guest vm in new cidr
2.Verify ip alias creation
3.Destroy vm and wait for it to expunge
4.Verify ip alias removal after vm expunge
"""
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 = "ip addr show eth0"
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.debug("ip alias configuration on VR: %s" % res)
self.assertNotEqual(
res.find(self.alias_ip)
- 1,
"ip alias is not created on VR eth0"
)
self.virtual_machine.delete(self.apiclient) self.virtual_machine.delete(self.apiclient)
expunge_del = Configurations.list( expunge_del = Configurations.list(
self.apiclient, self.apiclient,
@ -586,8 +517,226 @@ class TestMultipleIpRanges(cloudstackTestCase):
name='expunge.interval' name='expunge.interval'
) )
wait_time = int(expunge_del[0].value) + int(expunge_int[0].value) + int(30) 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)) self.debug("Waiting for {} seconds for the vm to expunge".format(wait_time))
# wait for the vm to expunge # wait for the vm to expunge
time.sleep(wait_time) time.sleep(wait_time)
self.debug("Verify that expunging the last vm in the CIDR should delete the ip alias from VR")
ip_alias2 = self.dbclient.execute(
"select ip4_address from nic_ip_alias;"
)
self.assertEqual(
isinstance(ip_alias2, list),
True,
"Error in sql query"
)
self.assertEqual(
len(ip_alias2),
0,
"Failure in clearing ip alias entry from cloud db"
)
proc = "ip addr show eth0"
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.assertEqual(
res.find(self.alias_ip),
- 1,
"Failed to clean up ip alias from VR even after last vm expunge in the CIDR"
)
self.debug("IP alias got deleted from VR successfully.")
self.cleanup.remove(self.virtual_machine)
return
@attr(tags=["sg"])
def test_06_reboot_VR_verify_ip_alias(self):
"""Reboot VR and verify ip alias
1.Deploy guest vm in new cidr
2.Verify ip alias creation
3.Reboot VR
4.Verify ip alias on VR
"""
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 = "ip addr show eth0"
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.debug("ip alias configuration on VR: %s" % res)
self.assertNotEqual(
res.find(self.alias_ip)
- 1,
"ip alias is not created on VR eth0"
)
resp = Router.reboot(
self.apiclient,
router.id
)
self.debug("Reboot router api response: %s" % resp)
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]
self.assertEqual(
router.state,
'Running',
"Router is not in running state after reboot"
)
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.assertNotEqual(
res.find(self.alias_ip),
- 1,
"IP alias not present on VR after VR reboot"
)
return
@attr(tags=["sg"])
def test_07_stop_start_VR_verify_ip_alias(self):
"""Reboot VR and verify ip alias
1.Deploy guest vm in new cidr
2.Verify ip alias creation
3.Stop and Start VR
4.Verify ip alias on VR
"""
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 = "ip addr show eth0"
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.debug("ip alias configuration on VR: %s" % res)
self.assertNotEqual(
res.find(self.alias_ip)
- 1,
"ip alias is not created on VR eth0"
)
self.debug("Stopping VR")
stop_res = Router.stop(
self.apiclient,
router.id,
)
self.debug("Starting VR")
start_res = Router.start(
self.apiclient,
router.id
)
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]
self.assertEqual(
router.state,
'Running',
"Router is not in running state after reboot"
)
self.debug("VR is up and Running")
result = get_process_status(
host.ipaddress,
self.services['host']["publicport"],
self.services['host']["username"],
self.services['host']["password"],
router.linklocalip,
proc
)
res = str(result)
self.assertNotEqual(
res.find(self.alias_ip),
- 1,
"IP alias not present on VR after VR stop and start"
)
return return