BUG-ID:CLOUDSTACK-9829:update the smoketest for rootvolume to implement full clone logic

This commit is contained in:
cloudsadhu 2017-03-23 17:42:44 +05:30
parent 871f21af35
commit 9cc66a3609
1 changed files with 190 additions and 140 deletions

View File

@ -19,92 +19,112 @@
#All tests inherit from cloudstackTestCase
from marvin.cloudstackTestCase import cloudstackTestCase
#Import Integration Libraries
#base - contains all resources as entities and defines create, delete, list operations on them
from marvin.lib.base import Account, VirtualMachine, ServiceOffering, Configurations
from marvin.lib.base import Account, VirtualMachine, ServiceOffering, Configurations,StoragePool
#utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources
#common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_template, list_volumes
from marvin.codes import FAILED
from marvin.lib.utils import cleanup_resources,validateList
from marvin.lib.common import get_zone, get_domain, get_template,\
list_volumes,list_storage_pools,list_configurations
from marvin.codes import FAILED,INVALID_INPUT
from nose.plugins.attrib import attr
import re
class TestData(object):
"""Test data object that is required to create resources
"""
def __init__(self):
self.testdata = {
#data to create an account
"account": {
"email": "test@test.com",
"firstname": "Test",
"lastname": "User",
"username": "test",
"password": "password",
},
#data reqd for virtual machine creation
"virtual_machine" : {
"name" : "testvm",
"displayname" : "Test VM",
},
#small service offering
"service_offering": {
"small": {
"name": "Small Instance",
"displaytext": "Small Instance",
"cpunumber": 1,
"cpuspeed": 100,
"memory": 256,
},
},
"ostype": 'CentOS 5.3 (64-bit)',
}
class TestDeployVM(cloudstackTestCase):
class TestDeployVmRootSize(cloudstackTestCase):
"""Test deploy a VM into a user account
"""
def setUp(self):
self.testdata = TestData().testdata
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
@classmethod
def setUpClass(cls):
cls.cloudstacktestclient = super(TestDeployVmRootSize,
cls).getClsTestClient()
cls.api_client = cls.cloudstacktestclient.getApiClient()
cls.hypervisor = cls.cloudstacktestclient.getHypervisorInfo().lower()
#cls.hypervisor="vmware"
# Get Zone, Domain and Default Built-in template
self.domain = get_domain(self.apiclient)
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.testdata["mode"] = self.zone.networktype
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
if self.template == FAILED:
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client,
cls.cloudstacktestclient.getZoneForTests())
cls.services = cls.testClient.getParsedTestDataConfig()
cls.services["mode"] = cls.zone.networktype
cls._cleanup = []
cls.updateclone = False
cls.template = get_template(cls.api_client, cls.zone.id)
if cls.template == FAILED:
assert False, "get_template() failed to return template "
# for testing with specific template
# self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"], templatetype='USER', services = {"template":'31f52a4d-5681-43f7-8651-ad4aaf823618'})
#create a user account
self.account = Account.create(
self.apiclient,
self.testdata["account"],
domainid=self.domain.id
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
list_pool_resp = list_storage_pools(cls.api_client,
account=cls.account.name,
domainid=cls.domain.id)
#Identify the storage pool type and set vmware fullclone to true if storage is VMFS
if cls.hypervisor == 'vmware':
for strpool in list_pool_resp:
if strpool.type.lower() == "vmfs" or strpool.type.lower()== "networkfilesystem":
list_config_storage_response = list_configurations(
cls.api_client
, name=
"vmware.create.full.clone",storageid=strpool.id)
res = validateList(list_config_storage_response)
if res[2]== INVALID_INPUT:
raise Exception("Failed to list configurations ")
if list_config_storage_response[0].value == "false":
Configurations.update(cls.api_client,
"vmware.create.full.clone",
value="true",storageid=strpool.id)
cls.updateclone = True
StoragePool.update(cls.api_client,id=strpool.id,
tags="scsi")
cls.storageID = strpool.id
break
#create a service offering
self.service_offering = ServiceOffering.create(
self.apiclient,
self.testdata["service_offering"]["small"]
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
#build cleanup list
self.cleanup = [
self.service_offering,
self.account
]
cls.services_offering_vmware=ServiceOffering.create(
cls.api_client,cls.services["service_offering"],tags="scsi")
cls._cleanup.extend([cls.service_offering,cls.services_offering_vmware])
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
if cls.updateclone:
Configurations.update(cls.api_client,
"vmware.create.full.clone",
value="false",storageid=cls.storageID)
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.cloudstacktestclient.getApiClient()
self.cleanup = []
return
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags = ['advanced', 'basic', 'sg'], required_hardware="true")
def test_00_deploy_vm_root_resize(self):
"""Test deploy virtual machine with root resize
@ -114,42 +134,46 @@ class TestDeployVM(cloudstackTestCase):
# 2. root disk has new size per listVolumes
# 3. Rejects non-supported hypervisor types
"""
full_clone_config = Configurations.list(self.apiclient,
name="vmware.create.full.clone")[0].value
if full_clone_config == 'false' and self.hypervisor.lower() == 'vmware':
self.skipTest("root disk resize is not supported "+
"when vmware.create.full.clone is %s" % full_clone_config)
if(self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'xenserver' or self.hypervisor.lower() == 'vmware'):
newrootsize = (self.template.size >> 30) + 2
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
newrootsize = (self.template.size >> 30) + 2
if(self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() ==
'xenserver'or self.hypervisor.lower() == 'vmware' ):
if self.hypervisor=="vmware":
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.services_offering_vmware.id,
templateid=self.template.id
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s"\
"Verify listVirtualMachines response for virtual machine: %s" \
% self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vms, list),
True,
"List VM response was not a valid list"
)
self.assertNotEqual(
len(list_vms),
0,
"List VM response was empty"
)
res=validateList(list_vms)
self.assertNotEqual(res[2],INVALID_INPUT," Invalid list VM "
"response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
@ -170,25 +194,27 @@ class TestDeployVM(cloudstackTestCase):
# get root vol from created vm, verify it is correct size
list_volume_response = list_volumes(
self.apiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
self.apiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
res=validateList(list_volume_response)
self.assertNotEqual(res[2],INVALID_INPUT," Invalid list VM "
"response")
rootvolume = list_volume_response[0]
success = False
if rootvolume is not None and rootvolume.size == (newrootsize << 30):
success = True
self.assertEqual(
success,
True,
"Check if the root volume resized appropriately"
)
success,
True,
"Check if the root volume resized appropriately"
)
else:
self.debug("hypervisor %s unsupported for test 00, verifying it errors properly" % self.hypervisor)
newrootsize = (self.template.size >> 30) + 2
success = False
try:
@ -214,60 +240,84 @@ class TestDeployVM(cloudstackTestCase):
def test_01_deploy_vm_root_resize(self):
"""Test proper failure to deploy virtual machine with rootdisksize of 0
"""
if (self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'xenserver' or self.hypervisor.lower() == 'vmware'):
newrootsize = 0
success = False
newrootsize=0
success=False
if(self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() ==
'xenserver'or self.hypervisor.lower() == 'vmware' ):
try:
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
if self.hypervisor=="vmware":
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.services_offering_vmware.id,
templateid=self.template.id
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
)
except Exception as ex:
if "rootdisk size should be a non zero number" in str(ex):
success = True
else:
self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex));
self.assertEqual(success, True, "Check if passing 0 as rootdisksize fails appropriately")
else:
self.debug("test 01 does not support hypervisor type " + self.hypervisor);
self.debug("test 01 does not support hypervisor type " + self.hypervisor)
@attr(tags = ['advanced', 'basic', 'sg'], required_hardware="true", BugId="CLOUDSTACK-6984")
def test_02_deploy_vm_root_resize(self):
"""Test proper failure to deploy virtual machine with rootdisksize less than template size
"""
if (self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'xenserver' or self.hypervisor.lower() == 'vmware'):
newrootsize = (self.template.size >> 30) - 1
newrootsize = (self.template.size >> 30) - 1
success=False
self.assertEqual(newrootsize > 0, True, "Provided template is less than 1G in size, cannot run test")
self.assertEqual(newrootsize > 0, True, "Provided template is less than 1G in size, cannot run test")
success = False
if(self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() ==
'xenserver'or self.hypervisor.lower() == 'vmware' ):
try:
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
if self.hypervisor=="vmware":
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.services_offering_vmware.id,
templateid=self.template.id
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
)
except Exception as ex:
if "rootdisksize override is smaller than template size" in str(ex):
success = True
else:
self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex));
if "rootdisksize override is smaller than template size" in str(ex):
success = True
else:
self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex));
self.assertEqual(success, True, "Check if passing rootdisksize < templatesize fails appropriately")
else:
self.debug("test 01 does not support hypervisor type " + self.hypervisor);
self.debug("test 01 does not support hypervisor type " + self.hypervisor)
def tearDown(self):
try: