本文整理汇总了Python中marvin.lib.base.VirtualMachine.create方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachine.create方法的具体用法?Python VirtualMachine.create怎么用?Python VirtualMachine.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marvin.lib.base.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_03_vm_per_project
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_03_vm_per_project(self):
"""Test VM limit per project
"""
# Validate the following
# 1. Set max VM per project to 2
# 2. Create account and start 2 VMs. Verify VM state is Up and Running
# 3. Try to create 3rd VM instance. The appropriate error or alert
# should be raised
self.debug(
"Updating instance resource limits for project: %s" %
self.project.id)
# Set usage_vm=1 for Account 1
update_resource_limit(
self.apiclient,
0, # Instance
max=2,
projectid=self.project.id
)
self.debug("Deploying VM for project: %s" % self.project.id)
virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id
)
self.cleanup.append(virtual_machine_1)
# Verify VM state
self.assertEqual(
virtual_machine_1.state,
'Running',
"Check VM state is Running or not"
)
self.debug("Deploying VM for project: %s" % self.project.id)
virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id
)
self.cleanup.append(virtual_machine_2)
# Verify VM state
self.assertEqual(
virtual_machine_2.state,
'Running',
"Check VM state is Running or not"
)
# Exception should be raised for second instance
with self.assertRaises(Exception):
VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id
)
return
示例2: setUp
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(self.apiclient, self.services["account"], domainid=self.domain.id)
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.public_ip = PublicIPAddress.create(
self.apiclient,
self.virtual_machine.account,
self.virtual_machine.zoneid,
self.virtual_machine.domainid,
self.services["virtual_machine"],
)
NATRule.create(
self.apiclient, self.virtual_machine, self.services["natrule"], ipaddressid=self.public_ip.ipaddress.id
)
self.cleanup = [self.account]
return
示例3: createInstance
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def createInstance(self, service_off, account=None,
project=None, networks=None, api_client=None):
"""Creates an instance in account"""
if api_client is None:
api_client = self.apiclient
self.debug("Deploying instance")
try:
if account:
vm = VirtualMachine.create(
api_client,
self.testdata["virtual_machine"],
templateid=self.template.id,
accountid=account.name,
domainid=account.domainid,
networkids=networks,
serviceofferingid=service_off.id)
elif project:
vm = VirtualMachine.create(
api_client,
self.testdata["virtual_machine"],
templateid=self.template.id,
projectid=project.id,
networkids=networks,
serviceofferingid=service_off.id)
vms = VirtualMachine.list(api_client, id=vm.id, listall=True)
self.assertIsInstance(vms,
list,
"List VMs should return a valid response")
self.assertEqual(vms[0].state, "Running",
"Vm state should be running after deployment")
return vm
except Exception as e:
self.fail("Failed to deploy an instance: %s" % e)
示例4: test_deployvm_userdispersing
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_deployvm_userdispersing(self):
"""Test deploy VMs using user dispersion planner
"""
self.service_offering_userdispersing = ServiceOffering.create(
self.apiclient,
self.services["service_offerings"]["tiny"],
deploymentplanner='UserDispersingPlanner'
)
self.virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userdispersing.id,
templateid=self.template.id
)
self.virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userdispersing.id,
templateid=self.template.id
)
list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
self.assertEqual(
isinstance(list_vm_1, list),
True,
"List VM response was not a valid list"
)
self.assertEqual(
isinstance(list_vm_2, list),
True,
"List VM response was not a valid list"
)
vm1 = list_vm_1[0]
vm2 = list_vm_2[0]
self.assertEqual(
vm1.state,
"Running",
msg="VM is not in Running state"
)
self.assertEqual(
vm2.state,
"Running",
msg="VM is not in Running state"
)
vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid
vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid
if vm1clusterid == vm2clusterid:
self.debug("VMs (%s, %s) meant to be dispersed are deployed in the same cluster %s" % (
vm1.id, vm2.id, vm1clusterid))
示例5: test_01_positive_tests_usage
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_01_positive_tests_usage(self):
""" Check events in usage_events table when VM creation fails
Steps:
1. Create service offering with large resource numbers
2. Try to deploy a VM
3. VM creation should fail and VM should be in error state
4. Destroy the VM with expunge parameter True
5. Check the events for the account in usage_events table
6. There should be VM.CREATE, VM.DESTROY, VOLUME.CREATE and
VOLUME.DELETE events present in the table
"""
# Create VM in account
with self.assertRaises(Exception):
VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
vms = VirtualMachine.list(self.apiclient, account=self.account.name, domaind=self.account.domainid)
self.assertEqual(validateList(vms)[0], PASS, "Vm list validation failed")
self.assertEqual(vms[0].state.lower(), "error", "VM should be in error state")
qresultset = self.dbclient.execute("select id from account where uuid = '%s';" % self.account.id)
self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")
self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
qresult = qresultset[0]
account_id = qresult[0]
self.debug("select type from usage_event where account_id = '%s';" % account_id)
qresultset = self.dbclient.execute("select type from usage_event where account_id = '%s';" % account_id)
self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")
self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
qresult = str(qresultset)
self.debug("Query result: %s" % qresult)
# Check if VM.CREATE, VM.DESTROY events present in usage_event table
self.assertEqual(qresult.count("VM.CREATE"), 1, "Check VM.CREATE event in events table")
self.assertEqual(qresult.count("VM.DESTROY"), 1, "Check VM.DESTROY in list events")
# Check if VOLUME.CREATE, VOLUME.DELETE events present in usage_event
# table
self.assertEqual(qresult.count("VOLUME.CREATE"), 1, "Check VOLUME.CREATE in events table")
self.assertEqual(qresult.count("VOLUME.DELETE"), 1, "Check VM.DELETE in events table")
return
示例6: test_deploy_vm_start_failure
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_deploy_vm_start_failure(self):
"""Test Deploy Virtual Machine - start operation failure and retry
# Validate the following:
# 1. 1st VM creation failed
# 2. Check there were 4 failed start operation retries (mock count = (6-4) = 2)
# 3. 2nd VM creation succeeded
# 4. Check there were 2 failed start operation retries (mock count = (2-2) = 0)
# 5. ListVM returns accurate information
"""
self.virtual_machine = None
with self.assertRaises(Exception):
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine2"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
self.assertEqual(
self.mock_start_failure.count,
2,
msg="Start failure mock not executed")
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine3"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) > 0, msg="List VM response empty")
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"VM ids do not match")
self.assertEqual(
vm.name,
self.virtual_machine.name,
"VM names do not match")
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state")
self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
self.assertEqual(
self.mock_start_failure.count,
0,
msg="Start failure mock not executed")
示例7: test_05_use_private_template_in_project
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_05_use_private_template_in_project(self):
"""Test use of private template in a project
"""
# 1. Create a project
# 2. Verify that in order to use somebody's Private template for vm
# creation in the project, permission to use the template has to
# be granted to the Project (use API 'updateTemplatePermissions'
# with project id to achieve that).
try:
self.debug("Deploying VM for with public template: %s" % self.template.id)
virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id,
)
self.cleanup.append(virtual_machine_1)
# Verify VM state
self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")
virtual_machine_1.stop(self.apiclient)
# Get the Root disk of VM
volumes = list_volumes(self.apiclient, projectid=self.project.id, type="ROOT", listall=True)
self.assertEqual(isinstance(volumes, list), True, "Check for list volume response return valid data")
volume = volumes[0]
self.debug("Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK
template_1 = Template.create(self.userapiclient, self.services["template"], volumeid=volume.id)
self.cleanup.append(template_1)
# Verify Template state
self.assertEqual(template_1.isready, True, "Check Template is in ready state or not")
# Update template permissions to grant permission to project
self.debug(
"Updating template permissions:%s to grant access to project: %s" % (template_1.id, self.project.id)
)
template_1.updatePermissions(self.apiclient, op="add", projectids=self.project.id)
self.debug("Deploying VM for with privileged template: %s" % self.template.id)
virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["server"],
templateid=template_1.id,
serviceofferingid=self.service_offering.id,
projectid=self.project.id,
)
self.cleanup.append(virtual_machine_2)
# Verify VM state
self.assertEqual(virtual_machine_2.state, "Running", "Check VM state is Running or not")
except Exception as e:
self.fail("Exception occured: %s" % e)
return
示例8: test_deploy_multiple_vm
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_deploy_multiple_vm(self, value):
"""Test Deploy multiple VMs with & verify the usage
# Validate the following
# 1. Deploy multiple VMs with this service offering
# 2. Update Resource count for the root admin Primary Storage usage
# 3. Primary Storage usage should list properly
# 4. Destroy one VM among multiple VM's and verify that primary storage count
# decreases by equivalent amount
"""
response = self.setupAccount(value)
self.assertEqual(response[0], PASS, response[1])
self.virtualMachine_2 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
accountid=self.account.name, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id)
expectedCount = (self.initialResourceCount * 2) #Total 2 vms
response = matchResourceCount(
self.apiclient, expectedCount,
RESOURCE_PRIMARY_STORAGE,
accountid=self.account.id)
self.assertEqual(response[0], PASS, response[1])
self.virtualMachine_3 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
accountid=self.account.name, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id)
expectedCount = (self.initialResourceCount * 3) #Total 3 vms
response = matchResourceCount(
self.apiclient, expectedCount,
RESOURCE_PRIMARY_STORAGE,
accountid=self.account.id)
self.assertEqual(response[0], PASS, response[1])
self.debug("Destroying instance: %s" % self.virtualMachine_2.name)
try:
self.virtualMachine_2.delete(self.apiclient)
except Exception as e:
self.fail("Failed to delete instance: %s" % e)
self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id), "VM not expunged \
in allotted time")
expectedCount -= (self.template.size / (1024 ** 3))
response = matchResourceCount(
self.apiclient, expectedCount,
RESOURCE_PRIMARY_STORAGE,
accountid=self.account.id)
self.assertEqual(response[0], PASS, response[1])
return
示例9: test_01_deploy_vm_no_startvm
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_01_deploy_vm_no_startvm(self):
"""Test Deploy Virtual Machine with no startVM parameter
"""
# Validate the following:
# 1. deploy Vm without specifying the startvm parameter
# 2. Should be able to login to the VM.
# 3. listVM command should return the deployed VM.State of this VM
# should be "Running".
self.debug("Deploying instance in the account: %s" % self.account.name)
self.virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
diskofferingid=self.disk_offering.id,
startvm=False,
)
response = self.virtual_machine_1.getState(self.apiclient, VirtualMachine.STOPPED)
self.assertEqual(response[0], PASS, response[1])
self.debug("Checking the router state after VM deployment")
routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)
self.assertEqual(routers, None, "List routers should return empty response")
self.debug("Deploying another instance (startvm=true) in the account: %s" % self.account.name)
self.virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
diskofferingid=self.disk_offering.id,
startvm=True,
)
response = self.virtual_machine_2.getState(self.apiclient, VirtualMachine.RUNNING)
self.assertEqual(response[0], PASS, response[1])
self.debug("Checking the router state after VM deployment")
routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)
self.assertEqual(isinstance(routers, list), True, "List routers should not return empty response")
for router in routers:
self.debug("Router state: %s" % router.state)
self.assertEqual(
router.state, "Running", "Router should be in running state when instance is running in the account"
)
self.debug("Destroying the running VM:%s" % self.virtual_machine_2.name)
self.virtual_machine_2.delete(self.apiclient, expunge=True)
routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)
self.assertNotEqual(routers, None, "Router should get deleted after expunge delay+wait")
return
示例10: test_01_list_routers_admin
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_01_list_routers_admin(self):
"""TS_BUG_007-Check listRouters() using Admin User
"""
# Validate the following
# 1. PreReq: have rounters that are owned by other account
# 2. Create domain and create accounts in that domain
# 3. Create one VM for each account
# 4. Using Admin , run listRouters. It should return all the routers
vm_1 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id
)
self.debug("Deployed VM with ID: %s" % vm_1.id)
vm_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.user_account.name,
domainid=self.user_account.domainid,
serviceofferingid=self.service_offering.id
)
self.debug("Deployed VM with ID: %s" % vm_2.id)
routers = list_routers(
self.apiclient,
account=self.admin_account.name,
domainid=self.admin_account.domainid,
)
self.assertEqual(
isinstance(routers, list),
True,
"Check list response returns a valid list"
)
# ListRouter Should return 2 records
self.assertEqual(
len(routers),
1,
"Check list router response"
)
for router in routers:
self.assertEqual(
router.state,
'Running',
"Check list router response for router state"
)
return
示例11: setUpClass
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def setUpClass(cls):
cls.testClient = super(TestRouterServices, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
# Create an account, network, VM and IP addresses
cls.account = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls.vm_1 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
templateid=cls.template.id,
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id
)
cls.vm_2 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
templateid=cls.template.id,
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id
)
cls._cleanup = [
cls.account,
cls.service_offering
]
return
示例12: test_vms_with_same_name
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_vms_with_same_name(self):
""" Test vm deployment with same name
# 1. Deploy a VM on with perticular name from account_1
# 2. Try to deploy another vm with same name from account_2
# 3. Verify that second VM deployment fails
"""
# Step 1
# Create VM on cluster wide
configs = Configurations.list(
self.apiclient,
name="vm.instancename.flag")
orig_value = configs[0].value
if orig_value == "false":
Configurations.update(self.apiclient,
name="vm.instancename.flag",
value="true"
)
# Restart management server
self.RestartServer()
time.sleep(120)
self.testdata["small"]["displayname"]="TestName"
self.testdata["small"]["name"]="TestName"
VirtualMachine.create(
self.userapiclient_1,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account_1.name,
domainid=self.account_1.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
with self.assertRaises(Exception):
VirtualMachine.create(
self.userapiclient_2,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account_2.name,
domainid=self.account_2.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
return
示例13: create_vm_in_aff_grps
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def create_vm_in_aff_grps(self, api_client=None, ag_list=[], projectid=None):
self.debug('Creating VM in AffinityGroups=%s' % ag_list)
if api_client is None:
api_client = self.api_client
if projectid is None:
projectid = self.project.id
vm = VirtualMachine.create(
api_client,
self.services["virtual_machine"],
projectid=projectid,
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
affinitygroupnames=ag_list
)
self.debug('Created VM=%s in Affinity Group=%s' % (vm.id, tuple(ag_list)))
list_vm = list_virtual_machines(self.api_client, id=vm.id, projectid=projectid)
self.assertEqual(isinstance(list_vm, list), True,"Check list response returns an invalid list %s" % list_vm)
self.assertNotEqual(len(list_vm),0, "Check VM available in TestDeployVMAffinityGroups")
self.assertEqual(list_vm[0].id, vm.id,"Listed vm does not have the same ids")
vm_response = list_vm[0]
self.assertEqual(vm.state, 'Running',msg="VM is not in Running state")
self.assertEqual(vm.projectid, projectid,msg="VM is not in project")
self.assertNotEqual(vm_response.hostid, None, "Host id was null for vm %s" % vm_response)
return vm, vm_response.hostid
示例14: test_02_deploy_vm_root_resize
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
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'):
newrootsize = (self.template.size >> 30) - 1
self.assertEqual(newrootsize > 0, True, "Provided template is less than 1G in size, cannot run test")
success = False
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
)
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));
self.assertEqual(success, True, "Check if passing rootdisksize < templatesize fails appropriately")
else:
self.debug("test 01 does not support hypervisor type " + self.hypervisor);
示例15: test_02_create_template_snapshot
# 需要导入模块: from marvin.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.lib.base.VirtualMachine import create [as 别名]
def test_02_create_template_snapshot(self, value):
"""Test create snapshot and templates from volume
# Validate the following
1. Create root domain/child domain admin account
2. Deploy VM in the account
3. Create snapshot from the virtual machine root volume
4. Create template from the snapshot
5. Verify that the secondary storage count of the account equals
the size of the template"""
response = self.setupAccount(value)
self.assertEqual(response[0], PASS, response[1])
self.virtualMachine = VirtualMachine.create(
self.api_client,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.assertNotEqual(self.virtualMachine, FAILED, "VM deployment failed")
apiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain)
self.assertNotEqual(apiclient, FAILED, "Failed to create api client for account: %s" % self.account.name)
try:
self.virtualMachine.stop(apiclient)
except Exception as e:
self.fail("Failed to stop instance: %s" % e)
self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name)
response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id)
self.assertEqual(response[0], PASS, response[1])
snapshot = response[1]
snapshotSize = snapshot.physicalsize / (1024 ** 3)
try:
template = Template.create_from_snapshot(apiclient, snapshot=snapshot, services=self.services["template_2"])
except Exception as e:
self.fail("Failed to create template: %s" % e)
templates = Template.list(
apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id
)
self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed")
templateSize = templates[0].size / (1024 ** 3)
expectedSecondaryStorageCount = int(templateSize + snapshotSize)
response = matchResourceCount(
self.apiclient,
expectedSecondaryStorageCount,
resourceType=RESOURCE_SECONDARY_STORAGE,
accountid=self.account.id,
)
self.assertEqual(response[0], PASS, response[1])
return