CLOUDSTACK-7800: VMware - Hot plug/unplug NIC to/from VM only when vmware tools are installed, else assert for exception

Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
Gaurav Aradhye 2014-10-28 11:05:20 +05:30 committed by SrikanteswaraRao Talluri
parent 0d6a277a00
commit 070e689c4f

View File

@ -15,24 +15,27 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
""" NIC tests for VM """ """ NIC tests for VM """
import marvin from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.codes import FAILED from marvin.lib.base import (Account,
from marvin.cloudstackTestCase import * ServiceOffering,
from marvin.cloudstackAPI import * Network,
from marvin.sshClient import SshClient VirtualMachine,
from marvin.lib.utils import * NetworkOffering)
from marvin.lib.base import * from marvin.lib.common import (get_zone,
from marvin.lib.common import * get_template,
get_domain)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
import signal import signal
import sys import sys
import time import time
class TestNic(cloudstackTestCase): class TestNic(cloudstackTestCase):
def setUp(self): def setUp(self):
self.cleanup = [] self.cleanup = []
def signal_handler(signal, frame): def signal_handler(signal, frame):
self.tearDown() self.tearDown()
sys.exit(0) sys.exit(0)
@ -40,171 +43,217 @@ class TestNic(cloudstackTestCase):
# assign the signal handler immediately # assign the signal handler immediately
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
hypervisor = self.testClient.getHypervisorInfo() self.hypervisor = self.testClient.getHypervisorInfo()
if hypervisor.lower() == "hyperv": if self.hypervisor.lower() == "hyperv":
raise unittest.SkipTest("Not supported on Hyper-V") raise unittest.SkipTest("Not supported on Hyper-V")
try: try:
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection() self.dbclient = self.testClient.getDbConnection()
self.services = self.testClient.getParsedTestDataConfig() self.services = self.testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates # Get Zone, Domain and templates
domain = get_domain(self.apiclient) domain = get_domain(self.apiclient)
zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.zone = get_zone(
self.services['mode'] = zone.networktype self.apiclient,
self.testClient.getZoneForTests()
)
#if local storage is enabled, alter the offerings to use localstorage # if local storage is enabled, alter the offerings to use
#this step is needed for devcloud # localstorage
if zone.localstorageenabled == True: # this step is needed for devcloud
self.services["service_offerings"]["tiny"]["storagetype"] = 'local' if self.zone.localstorageenabled:
self.services["service_offerings"][
"tiny"]["storagetype"] = 'local'
template = get_template( template = get_template(
self.apiclient, self.apiclient,
zone.id, self.zone.id,
self.services["ostype"] self.services["ostype"]
) )
# Set Zones and disk offerings # Set Zones and disk offerings
self.services["small"]["zoneid"] = zone.id self.services["small"]["zoneid"] = self.zone.id
self.services["small"]["template"] = template.id self.services["small"]["template"] = template.id
self.services["iso1"]["zoneid"] = zone.id self.services["iso1"]["zoneid"] = self.zone.id
self.services["network"]["zoneid"] = zone.id self.services["network"]["zoneid"] = self.zone.id
# Create Account, VMs, NAT Rules etc # Create Account, VMs, NAT Rules etc
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
domainid=domain.id domainid=domain.id
) )
self.cleanup.insert(0, self.account) self.cleanup.insert(0, self.account)
self.service_offering = ServiceOffering.create( self.service_offering = ServiceOffering.create(
self.apiclient, self.apiclient,
self.services["service_offerings"]["tiny"] self.services["service_offerings"]["tiny"]
) )
self.cleanup.insert(0, self.service_offering) self.cleanup.insert(0, self.service_offering)
#################### ####################
### Network offering # Network offering
self.network_offering = NetworkOffering.create( self.network_offering = NetworkOffering.create(
self.apiclient, self.apiclient,
self.services["network_offering"], self.services["network_offering"],
) )
self.cleanup.insert(0, self.network_offering) self.cleanup.insert(0, self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled') # Enable Network offering self.network_offering.update(
self.services["network"]["networkoffering"] = self.network_offering.id self.apiclient,
state='Enabled') # Enable Network offering
self.services["network"][
"networkoffering"] = self.network_offering.id
self.network_offering_shared = NetworkOffering.create( self.network_offering_shared = NetworkOffering.create(
self.apiclient, self.apiclient,
self.services["network_offering_shared"], self.services["network_offering_shared"],
) )
self.cleanup.insert(0, self.network_offering_shared) self.cleanup.insert(0, self.network_offering_shared)
self.network_offering_shared.update(self.apiclient, state='Enabled') # Enable Network offering self.network_offering_shared.update(
self.services["network2"]["networkoffering"] = self.network_offering_shared.id self.apiclient,
state='Enabled') # Enable Network offering
self.services["network2"][
"networkoffering"] = self.network_offering_shared.id
################ ################
### Test Network # Test Network
self.test_network = Network.create( self.test_network = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
self.account.name, self.account.name,
self.account.domainid, self.account.domainid,
) )
self.cleanup.insert(0, self.test_network) self.cleanup.insert(0, self.test_network)
self.test_network2 = Network.create( self.test_network2 = Network.create(
self.apiclient, self.apiclient,
self.services["network2"], self.services["network2"],
self.account.name, self.account.name,
self.account.domainid, self.account.domainid,
zoneid=self.services["network"]["zoneid"] zoneid=self.services["network"]["zoneid"]
) )
self.cleanup.insert(0, self.test_network2) self.cleanup.insert(0, self.test_network2)
except Exception as ex: except Exception as ex:
self.debug("Exception during NIC test SETUP!: " + str(ex)) self.debug("Exception during NIC test SETUP!: " + str(ex))
@attr(tags = ["devcloud", "smoke", "advanced", "advancedns"], required_hardware="true") @attr(
tags=[
"devcloud",
"smoke",
"advanced",
"advancedns"],
required_hardware="true")
def test_01_nic(self): def test_01_nic(self):
#TODO: SIMENH: add validation # TODO: SIMENH: add validation
"""Test to add and update added nic to a virtual machine""" """Test to add and update added nic to a virtual machine"""
try: hypervisorIsVmware = False
self.virtual_machine = VirtualMachine.create( isVmwareToolInstalled = False
self.apiclient, assertForExceptionForNicOperations = False
self.services["small"], if self.hypervisor.lower() == "vmware":
accountid=self.account.name, hypervisorIsVmware = True
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
mode=self.services['mode'],
networkids=[self.test_network.id]
)
self.cleanup.insert(0, self.virtual_machine)
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.virtual_machine.id
)
self.debug( self.virtual_machine = VirtualMachine.create(
"Verify listVirtualMachines response for virtual machine: %s" \ self.apiclient,
% self.virtual_machine.id self.services["small"],
) accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[self.test_network.id],
mode=self.zone.networktype if hypervisorIsVmware else "default"
)
self.assertEqual( # If hypervisor is Vmware, then check if
isinstance(list_vm_response, list), # the vmware tools are installed and the process is running
True, # Vmware tools are necessary for add and remove nic operations
"Check list response returns a valid list" if hypervisorIsVmware:
) sshClient = self.virtual_machine.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" in result:
isVmwareToolInstalled = True
self.assertNotEqual( # If Vmware tools are not installed in case of vmware hypervisor
len(list_vm_response), # then check for exception while performing add and remove nic
0, # operations
"Check VM available in List Virtual Machines" if hypervisorIsVmware and not isVmwareToolInstalled:
) assertForExceptionForNicOperations = True
vm_response = list_vm_response[0]
self.assertEqual( self.cleanup.insert(0, self.virtual_machine)
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine.id
)
vm_response.id, self.debug(
self.virtual_machine.id, "Verify listVirtualMachines response for virtual machine: %s"
"Check virtual machine id in listVirtualMachines" % self.virtual_machine.id
) )
self.assertEqual( self.assertEqual(
vm_response.name, isinstance(list_vm_response, list),
self.virtual_machine.name, True,
"Check virtual machine name in listVirtualMachines" "Check list response returns a valid list"
) )
self.assertEqual( self.assertNotEqual(
len(vm_response.nic), len(list_vm_response),
1, 0,
"Verify we only start with one nic" "Check VM available in List Virtual Machines"
) )
vm_response = list_vm_response[0]
self.assertEqual( self.assertEqual(
vm_response.nic[0].isdefault,
True,
"Verify initial adapter is set to default"
)
existing_nic_ip = vm_response.nic[0].ipaddress
existing_nic_id = vm_response.nic[0].id
vm_response.id,
self.virtual_machine.id,
"Check virtual machine id in listVirtualMachines"
)
self.assertEqual(
vm_response.name,
self.virtual_machine.name,
"Check virtual machine name in listVirtualMachines"
)
self.assertEqual(
len(vm_response.nic),
1,
"Verify we only start with one nic"
)
self.assertEqual(
vm_response.nic[0].isdefault,
True,
"Verify initial adapter is set to default"
)
existing_nic_ip = vm_response.nic[0].ipaddress
existing_nic_id = vm_response.nic[0].id
if assertForExceptionForNicOperations:
with self.assertRaises(Exception):
self.virtual_machine.add_nic(
self.apiclient,
self.test_network2.id)
else:
# 1. add a nic # 1. add a nic
add_response = self.virtual_machine.add_nic(self.apiclient, self.test_network2.id) self.virtual_machine.add_nic(self.apiclient, self.test_network2.id)
time.sleep(5) time.sleep(5)
# now go get the vm list? # now go get the vm list?
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
self.assertEqual( self.assertEqual(
len(list_vm_response[0].nic), len(list_vm_response[0].nic),
2, 2,
"Verify we have 2 NIC's now" "Verify we have 2 NIC's now"
) )
new_nic_id = "" new_nic_id = ""
for nc in list_vm_response[0].nic: for nc in list_vm_response[0].nic:
@ -215,12 +264,13 @@ class TestNic(cloudstackTestCase):
time.sleep(5) time.sleep(5)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
# iterate as we don't know for sure what order our NIC's will be returned to us. # iterate as we don't know for sure what order our NIC's will be
# returned to us.
for nc in list_vm_response[0].nic: for nc in list_vm_response[0].nic:
if nc.ipaddress == existing_nic_ip: if nc.ipaddress == existing_nic_ip:
self.assertEqual( self.assertEqual(
@ -235,33 +285,28 @@ class TestNic(cloudstackTestCase):
"Verify second adapter is set to default" "Verify second adapter is set to default"
) )
sawException = False with self.assertRaises(Exception):
try:
self.virtual_machine.remove_nic(self.apiclient, new_nic_id) self.virtual_machine.remove_nic(self.apiclient, new_nic_id)
except Exception as ex:
sawException = True
self.assertEqual(sawException, True, "Make sure we cannot delete the default NIC") self.virtual_machine.update_default_nic(
self.virtual_machine.update_default_nic(self.apiclient, existing_nic_id) self.apiclient,
existing_nic_id)
time.sleep(5) time.sleep(5)
self.virtual_machine.remove_nic(self.apiclient, new_nic_id) self.virtual_machine.remove_nic(self.apiclient, new_nic_id)
time.sleep(5) time.sleep(5)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
self.assertEqual( self.assertEqual(
len(list_vm_response[0].nic), len(list_vm_response[0].nic),
1, 1,
"Verify we are back to a signle NIC" "Verify we are back to a signle NIC"
) )
return return
except Exception as ex:
self.debug("Exception during NIC test!: " + str(ex))
self.assertEqual(True, False, "Exception during NIC test!: " + str(ex))
def tearDown(self): def tearDown(self):
try: try:
@ -270,7 +315,10 @@ class TestNic(cloudstackTestCase):
obj.delete(self.apiclient) obj.delete(self.apiclient)
time.sleep(10) time.sleep(10)
except Exception as ex: except Exception as ex:
self.debug("Error deleting: " + str(obj) + ", exception: " + str(ex)) self.debug(
"Error deleting: " +
str(obj) +
", exception: " +
str(ex))
except Exception as e: except Exception as e:
self.debug("Warning! Exception in tearDown: %s" % e) self.debug("Warning! Exception in tearDown: %s" % e)