本文整理汇总了Python中marvin.lib.base.Template.create_from_snapshot方法的典型用法代码示例。如果您正苦于以下问题:Python Template.create_from_snapshot方法的具体用法?Python Template.create_from_snapshot怎么用?Python Template.create_from_snapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marvin.lib.base.Template
的用法示例。
在下文中一共展示了Template.create_from_snapshot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_02_create_template_snapshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [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
示例2: test_04_template_from_snapshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_04_template_from_snapshot(self):
"""Create Template from snapshot
"""
# Validate the following
# 2. Snapshot the Root disk
# 3. Create Template from snapshot
# 4. Deploy Virtual machine using this template
# 5. VM should be in running state
userapiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain)
volumes = Volume.list(userapiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True)
volume = volumes[0]
self.debug("Creating a snapshot from volume: %s" % volume.id)
# Create a snapshot of volume
snapshot = Snapshot.create(userapiclient, volume.id, account=self.account.name, domainid=self.account.domainid)
self.debug("Creating a template from snapshot: %s" % snapshot.id)
# Generate template from the snapshot
template = Template.create_from_snapshot(userapiclient, snapshot, self.services["template"])
self.cleanup.append(template)
# Verify created template
templates = Template.list(
userapiclient, templatefilter=self.services["template"]["templatefilter"], id=template.id
)
self.assertNotEqual(templates, None, "Check if result exists in list item call")
self.assertEqual(templates[0].id, template.id, "Check new template id in list resources call")
self.debug("Deploying a VM from template: %s" % template.id)
# Deploy new virtual machine using template
virtual_machine = VirtualMachine.create(
userapiclient,
self.services["virtual_machine"],
templateid=template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.cleanup.append(virtual_machine)
vm_response = VirtualMachine.list(
userapiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid
)
self.assertEqual(isinstance(vm_response, list), True, "Check for list VM response return valid list")
# Verify VM response to check whether VM deployment was successful
self.assertNotEqual(len(vm_response), 0, "Check VMs available in List VMs response")
vm = vm_response[0]
self.assertEqual(vm.state, "Running", "Check the state of VM created from Template")
return
示例3: test_03_reuse_template_name
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_03_reuse_template_name(self):
"""TS_BUG_011-Test Reusing deleted template name
"""
# Validate the following
# 1. Deploy VM using default template, small service offering
# and small data disk offering.
# 2. Perform snapshot on the root disk of this VM.
# 3. Create a template from snapshot.
# 4. Delete the template and create a new template with same name
# 5. Template should be created succesfully
# Create a snapshot from the ROOTDISK
snapshot = Snapshot.create(
self.apiclient,
self.volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.debug("Created snapshot with ID: %s" % snapshot.id)
snapshots = Snapshot.list(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list snapshots call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check snapshot id in list resources call"
)
# Generate template from the snapshot
template = Template.create_from_snapshot(
self.apiclient,
snapshot,
self.services["template"],
random_name=False
)
self.debug("Created template from snapshot: %s" % template.id)
templates = Template.list(
self.apiclient,
templatefilter=\
self.services["template"]["templatefilter"],
id=template.id
)
self.assertEqual(
isinstance(templates, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
templates,
None,
"Check if result exists in list item call"
)
self.assertEqual(
templates[0].isready,
True,
"Check new template state in list templates call"
)
self.debug("Deleting template: %s" % template.id)
template.delete(self.apiclient)
# Wait for some time to ensure template state is reflected in other calls
time.sleep(self.services["sleep"])
# Generate template from the snapshot
self.debug("Creating template from snapshot: %s with same name" %
template.id)
template = Template.create_from_snapshot(
self.apiclient,
snapshot,
self.services["template"],
random_name=False
)
templates = Template.list(
self.apiclient,
templatefilter=\
self.services["template"]["templatefilter"],
id=template.id
)
self.assertEqual(
isinstance(templates, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
#.........这里部分代码省略.........
示例4: test_02_check_size_snapshotTemplate
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_02_check_size_snapshotTemplate(self):
"""TS_BUG_010-Test check size of snapshot and template
"""
# Validate the following
# 1. Deploy VM using default template, small service offering
# and small data disk offering.
# 2. Perform snapshot on the root disk of this VM.
# 3. Create a template from snapshot.
# 4. Check the size of snapshot and template
# Create a snapshot from the ROOTDISK
snapshot = Snapshot.create(
self.apiclient,
self.volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.debug("Created snapshot with ID: %s" % snapshot.id)
snapshots = Snapshot.list(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list snapshots call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check snapshot id in list resources call"
)
# Generate template from the snapshot
template = Template.create_from_snapshot(
self.apiclient,
snapshot,
self.services["template"]
)
self.cleanup.append(template)
self.debug("Created template from snapshot with ID: %s" % template.id)
templates = Template.list(
self.apiclient,
templatefilter=\
self.services["template"]["templatefilter"],
id=template.id
)
self.assertEqual(
isinstance(templates, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
templates,
None,
"Check if result exists in list item call"
)
self.assertEqual(
templates[0].isready,
True,
"Check new template state in list templates call"
)
# check size of template with that of snapshot
self.assertEqual(
templates[0].size,
self.volume.size,
"Derived template size (%s) does not match snapshot size (%s)" % (templates[0].size, self.volume.size)
)
return
示例5: test_01_volume_snapshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
#.........这里部分代码省略.........
qresult.count('SNAPSHOT.CREATE') > 0,
True,
"Check SNAPSHOT.CREATE event in events table"
)
#Usage_Event
qresultset = self.dbclient.execute(
"select * from usage_event where type='SNAPSHOT.CREATE' AND \
resource_name='%s'" %
root_vol_snap.name)
usage_event_validation_result = validateList(qresultset)
self.assertEqual(
usage_event_validation_result[0],
PASS,
"event list validation failed due to %s" %
usage_event_validation_result[2])
self.assertNotEqual(
len(qresultset),
0,
"Check DB Query result set"
)
self.assertEqual(
self.dbclient.execute("select size from usage_event where type='SNAPSHOT.CREATE' AND \
resource_name='%s'" %
root_vol_snap.name)[0][0],
root_vol_snap.physicalsize)
# Step 3
# create template from snapshot root_vol_snap
templateFromSnapshot = Template.create_from_snapshot(
self.apiclient,
root_vol_snap,
self.testdata["template_2"])
self.assertNotEqual(
templateFromSnapshot,
None,
"Check if result exists in list item call"
)
vm_from_temp = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=templateFromSnapshot.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
mode=self.zone.networktype
)
self.assertNotEqual(
vm_from_temp,
None,
"Check if result exists in list item call"
)
compareChecksum(
self.apiclient,
service=self.testdata,
original_checksum=ckecksum_random_root_cluster,
disk_type="rootdiskdevice",
示例6: test_02_host_maintenance_mode_with_activities
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
#.........这里部分代码省略.........
self.debug(
"Root volume of VM(%s): %s" % (
virtual_machine.name,
volume.name
))
# Create a snapshot from the ROOTDISK
self.debug("Creating snapshot on ROOT volume: %s" % volume.name)
snapshot = Snapshot.create(self.apiclient, volumes[0].id)
self.debug("Snapshot created: ID - %s" % snapshot.id)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id,
listall=True
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list snapshots call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check snapshot id in list resources call"
)
# Generate template from the snapshot
self.debug("Generating template from snapshot: %s" % snapshot.name)
template = Template.create_from_snapshot(
self.apiclient,
snapshot,
self.services["templates"]
)
self.debug("Created template from snapshot: %s" % template.id)
templates = list_templates(
self.apiclient,
templatefilter=self.services["templates"]["templatefilter"],
id=template.id
)
self.assertEqual(
isinstance(templates, list),
True,
"List template call should return the newly created template"
)
self.assertEqual(
templates[0].isready,
True,
"The newly created template should be in ready state"
)
first_host = vm.hostid
self.debug("Enabling maintenance mode for host %s" % vm.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = first_host
self.apiclient.prepareHostForMaintenance(cmd)
self.debug("Waiting for SSVMs to come up")
wait_for_ssvms(
示例7: test_07_template_from_snapshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_07_template_from_snapshot(self):
"""Create Template from snapshot
"""
# 1. Login to machine; create temp/test directories on data volume
# 2. Snapshot the Volume
# 3. Create Template from snapshot
# 4. Deploy Virtual machine using this template
# 5. Login to newly created virtual machine
# 6. Compare data in the root disk with the one that was written on the
# volume, it should match
if self.hypervisor.lower() in ['hyperv']:
self.skipTest("Snapshots feature is not supported on Hyper-V")
userapiclient = self.testClient.getUserApiClient(
UserName=self.account.name,
DomainName=self.account.domain)
random_data_0 = random_gen(size=100)
random_data_1 = random_gen(size=100)
try:
# Login to virtual machine
ssh_client = self.virtual_machine.get_ssh_client()
cmds = [
"mkdir -p %s" % self.services["paths"]["mount_dir"],
"mount %s1 %s" % (
self.services["volume"][self.hypervisor]["rootdiskdevice"],
self.services["paths"]["mount_dir"]
),
"mkdir -p %s/%s/{%s,%s} " % (
self.services["paths"]["mount_dir"],
self.services["paths"]["sub_dir"],
self.services["paths"]["sub_lvl_dir1"],
self.services["paths"]["sub_lvl_dir2"]
),
"echo %s > %s/%s/%s/%s" % (
random_data_0,
self.services["paths"]["mount_dir"],
self.services["paths"]["sub_dir"],
self.services["paths"]["sub_lvl_dir1"],
self.services["paths"]["random_data"]
),
"echo %s > %s/%s/%s/%s" % (
random_data_1,
self.services["paths"]["mount_dir"],
self.services["paths"]["sub_dir"],
self.services["paths"]["sub_lvl_dir2"],
self.services["paths"]["random_data"]
),
"sync",
]
for c in cmds:
self.debug(c)
result = ssh_client.execute(c)
self.debug(result)
except Exception as e:
self.fail("SSH failed for VM with IP address: %s" %
self.virtual_machine.ipaddress)
# Unmount the Volume
cmds = [
"umount %s" % (self.services["paths"]["mount_dir"]),
]
for c in cmds:
self.debug(c)
ssh_client.execute(c)
volumes = list_volumes(
userapiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
self.assertEqual(
isinstance(volumes, list),
True,
"Check list response returns a valid list"
)
volume = volumes[0]
# Create a snapshot of volume
snapshot = Snapshot.create(
userapiclient,
volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.debug("Snapshot created from volume ID: %s" % volume.id)
# Generate template from the snapshot
template = Template.create_from_snapshot(
userapiclient,
snapshot,
self.services["templates"]
#.........这里部分代码省略.........
示例8: test_02_template_permissions
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
#.........这里部分代码省略.........
user_vm_created = VirtualMachine.create(
self.user_api_client,
self.testdata["virtual_machine"],
accountid=user_account.name,
domainid=user_account.domainid,
serviceofferingid=self.service_offering.id,
)
self.assertIsNotNone(user_vm_created,
"VM creation failed"
)
# Get the Root disk of VM
volume = list_volumes(
self.user_api_client,
virtualmachineid=user_vm_created.id,
type='ROOT',
listall=True
)
snapshot_created = Snapshot.create(
self.user_api_client,
volume[0].id,
account=user_account.name,
domainid=user_account.domainid
)
self.assertIsNotNone(
snapshot_created,
"Snapshot creation failed"
)
self.debug("Creating a template from snapshot: %s" % snapshot_created.id)
#
# Generate public template from the snapshot
self.testdata["template"]["ispublic"] = True
try:
user_template = Template.create_from_snapshot(
self.user_api_client,
snapshot_created,
self.testdata["template"]
)
self.updateConfigurAndRestart("allow.public.user.templates", "true")
self.fail("Template creation passed from snapshot for domain user")
except CloudstackAPIException as e:
self.assertRaises("Exception Raised : %s" % e)
VirtualMachine.stop(user_vm_created, self.user_api_client)
list_stopped_vms_after = VirtualMachine.list(
self.user_api_client,
listall=self.testdata["listall"],
domainid=user_account.domainid,
state="Stopped")
status = validateList(list_stopped_vms_after)
self.assertEquals(
PASS,
status[0],
"Stopped VM is not in Stopped state"
)
try:
user_template = Template.create(
self.user_api_client, self.testdata["template"],
volume[0].id
)
self.updateConfigurAndRestart("allow.public.user.templates", "true")
self.fail("Template creation passed from volume for domain user")
except CloudstackAPIException as e:
self.assertRaises("Exception Raised : %s" % e)
admin_vm_created = VirtualMachine.create(
示例9: test_01_disable_enable_zone
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_01_disable_enable_zone(self):
"""disable enable zone
1. Disable zone and verify following things:
For admin user:
1. Should be create to start/stop exsiting vms
2. Should be create to deploy new vm, snapshot,volume,
template,iso in the same zone
For Non-admin user:
1. Should be create to start/stop exsiting vms
2. Should not be create to deploy new vm, snapshot,volume,
template,iso in the same zone
2. Enable the above disabled zone and verify that:
-All users should be create to deploy new vm,
snapshot,volume,template,iso in the same zone
3. Try to delete the zone and it should fail with error message:
-"The zone is not deletable because there are
servers running in this zone"
"""
# Step 1
vm_user = VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id
)
vm_root = 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
)
cmd = updateZone.updateZoneCmd()
cmd.id = self.zone.id
cmd.allocationstate = DISABLED
self.apiclient.updateZone(cmd)
zoneList = Zone.list(self.apiclient, id=self.zone.id)
self.assertEqual(zoneList[0].allocationstate,
DISABLED,
"Check if the zone is in disabled state"
)
# Both user and admin vms shoul be running
self.assertEqual(vm_user.state,
RUNNING,
"Verify that the user vm is running")
self.assertEqual(vm_root.state,
RUNNING,
"Verify that the admin vm is running")
vm_root.stop(self.apiclient)
vm_user.stop(self.apiclient)
root_state = self.dbclient.execute(
"select state from vm_instance where name='%s'" %
vm_root.name)[0][0]
user_state = self.dbclient.execute(
"select state from vm_instance where name='%s'" %
vm_user.name)[0][0]
self.assertEqual(root_state,
STOPPED,
"verify that vm is Stopped")
self.assertEqual(user_state,
STOPPED,
"verify that vm is stopped")
root_volume = list_volumes(
self.userapiclient,
virtualmachineid=vm_root.id,
type='ROOT',
listall=True
)
snap = Snapshot.create(
self.apiclient,
root_volume[0].id)
self.assertNotEqual(snap,
None,
"Verify that admin should be \
able to create snapshot")
snapshots = list_snapshots(
self.apiclient,
volumeid=root_volume[0].id,
listall=True)
template_from_snapshot = Template.create_from_snapshot(
#.........这里部分代码省略.........
示例10: test_01_createVM_snapshotTemplate
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_01_createVM_snapshotTemplate(self):
"""Test create VM, Snapshot and Template
"""
# Validate the following
# 1. Deploy VM using default template, small service offering
# and small data disk offering.
# 2. Perform snapshot on the root disk of this VM.
# 3. Create a template from snapshot.
# 4. Create a instance from above created template.
# 5. listSnapshots should list the snapshot that was created.
# 6. verify that secondary storage NFS share contains the reqd
# volume under /secondary/snapshots/$accountid/
# $volumeid/$snapshot_uuid
# 7. verify backup_snap_id was non null in the `snapshots` table
# 8. listTemplates() should return the newly created Template,
# and check for template state as READY"
# 9. listVirtualMachines() command should return the deployed VM.
# State of this VM should be Running.
# Create Virtual Machine
if self.hypervisor.lower() in ['hyperv']:
self.skipTest("Snapshots feature is not supported on Hyper-V")
userapiclient = self.testClient.getUserApiClient(
UserName=self.account.name,
DomainName=self.account.domain)
self.virtual_machine = VirtualMachine.create(
userapiclient,
self.services["server"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id
)
self.debug("Created VM with ID: %s" % self.virtual_machine.id)
# Get the Root disk of VM
volumes = list_volumes(
userapiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
volume = volumes[0]
# Create a snapshot from the ROOTDISK
snapshot = Snapshot.create(userapiclient, volume.id)
self.debug("Snapshot created: ID - %s" % snapshot.id)
self.cleanup.append(snapshot)
snapshots = list_snapshots(
userapiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list snapshots call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check snapshot id in list resources call"
)
self.debug(
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" %
snapshot.id)
snapshot_uuid = snapshot.id
# Generate template from the snapshot
template = Template.create_from_snapshot(
userapiclient,
snapshot,
self.services["templates"]
)
self.debug("Created template from snapshot: %s" % template.id)
self.cleanup.append(template)
templates = list_templates(
userapiclient,
templatefilter=self.services["templates"]["templatefilter"],
id=template.id
)
self.assertNotEqual(
templates,
None,
"Check if result exists in list item call"
)
self.assertEqual(
templates[0].isready,
True,
"Check new template state in list templates call"
#.........这里部分代码省略.........
示例11: test_01_create_template_snampshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
#.........这里部分代码省略.........
self.assertNotEqual(
len(vm_response),
0,
"Check VMs available in List VMs response"
)
vm = vm_response[0]
self.assertEqual(
vm.state,
'Running',
"Check the state of VM created from Template"
)
volumes = list_volumes(
self.apiclient,
virtualmachineid=vm.id,
type='ROOT',
listall=True
)
snapshot = Snapshot.create(
self.apiclient,
volumes[0].id,
account=self.account.name,
domainid=self.account.domainid
)
time.sleep(self.services["sleep"])
self.cleanup.append(snapshot)
self.debug("Snapshot created: ID - %s" % snapshot.id)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
self.assertEqual(
isinstance(snapshots, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
snapshots,
None,
"Check if result exists in list item call"
)
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check resource id in list resources call"
)
virtual_machine.delete(self.apiclient, expunge=False)
list_vm_response = VirtualMachine.list(
self.apiclient,
id=virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_vm_response),
0,
"Check VM avaliable in List Virtual Machines"
)
template = Template.create_from_snapshot(
self.apiclient,
snapshot,
self.services["template"]
)
self.cleanup.append(template)
# Verify created template
templates = Template.list(
self.apiclient ,
templatefilter=self.services["template"]["templatefilter"],
id=template.id
)
self.assertNotEqual(
templates,
None,
"Check if result exists in list item call"
)
self.assertEqual(
templates[0].id,
template.id,
"Check new template id in list resources call"
)
self.assertIsNotNone(
templates[0].details,
"Template details is %s" % template_response.details
)
return
示例12: checkIntegrityOfSnapshot
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def checkIntegrityOfSnapshot(
self, snapshotsToRestore, checksumToCompare, disk_type=ROOT):
"""
Check integrity of snapshot created of ROOT or DATA Disk:
If ROOT Disk: Deploy a Vm from a template created from the snapshot
and checking the contents of the ROOT disk.
If DATA Disk: Users can create a volume from the snapshot.
The volume can then be mounted to a VM and files
recovered as needed.
Inputs:
1. snapshotsToRestore: Snapshots whose integrity is
to be checked.
2. checksumToCompare: The contents of ROOT Disk to be compared.
3. disk_type: The type of disk - ROOT or DATA Disk
of which snapshot was created.
"""
if disk_type == ROOT:
# Create template from snapshot
template_from_snapshot = Template.create_from_snapshot(
self.apiclient,
snapshotsToRestore,
self.testdata["template_2"])
self.assertNotEqual(
template_from_snapshot,
None,
"Check if result exists in list item call"
)
# Deploy VM
vm_from_temp = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=template_from_snapshot.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
mode=self.zone.networktype
)
self.assertNotEqual(
vm_from_temp,
None,
"Check if result exists in list item call"
)
# Verify contents of ROOT disk match with snapshot
compareChecksum(
self.apiclient,
service=self.testdata,
original_checksum=checksumToCompare,
disk_type="rootdiskdevice",
virt_machine=vm_from_temp
)
vm_from_temp.delete(self.apiclient)
template_from_snapshot.delete(self.apiclient)
else:
volumeFormSnap = Volume.create_from_snapshot(
self.apiclient,
snapshotsToRestore.id,
self.testdata["volume"],
account=self.account.name,
domainid=self.account.domainid,
zoneid=self.zone.id
)
temp_vm = 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,
mode=self.zone.networktype
)
temp_vm.attach_volume(
self.apiclient,
volumeFormSnap
)
temp_vm.reboot(self.apiclient)
compareChecksum(
self.apiclient,
self.testdata,
checksumToCompare,
"datadiskdevice_1",
temp_vm
)
temp_vm.delete(self.apiclient)
#.........这里部分代码省略.........
示例13: test_01_disable_enable_cluster
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_01_disable_enable_cluster(self):
"""disable enable cluster
1. Disable cluster and verify following things:
For admin user:
--Should be able to create new vm, snapshot,
volume,template,iso in the same cluster
For Non-admin user:
--Should not be able create new vm, snapshot,
volume,template,iso in the same cluster
2. Enable the above disabled cluster and verify that:
-All users should be create to deploy new vm, snapshot,
volume,template,iso in the same cluster
3. Disable the managestate of the cluster and verify that:
--Host in the cluster should get disconnected
--VM's in the cluster are ping-able and ssh to
--Creation of new VM in the cluster should fail
4. Enable the managestate of the cluster and verify that:
--Hosts in the cluster get connected
--VM's in the cluster are accessible
5. Try to delete the cluster and it should fail with error message:
-"The cluster is not deletable because there are
servers running in this cluster"
"""
# Step 1
vm_user = VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
mode=self.zone.networktype,
)
self.vm_list.append(vm_user)
vm_root = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
mode=self.zone.networktype,
)
self.vm_list.append(vm_root)
cmd = updateCluster.updateClusterCmd()
cmd.id = self.cluster.id
cmd.allocationstate = DISABLED
self.apiclient.updateCluster(cmd)
clusterList = Cluster.list(self.apiclient, id=self.cluster.id)
self.assertEqual(clusterList[0].allocationstate, DISABLED, "Check if the cluster is in disabled state")
# Verify the existing vms should be running
self.assertEqual(vm_user.state.lower(), "running", "Verify that the user vm is running")
self.assertEqual(vm_root.state.lower(), "running", "Verify that the root vm is running")
VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
root_volume = list_volumes(self.apiclient, virtualmachineid=vm_root.id, type="ROOT", listall=True)
self.assertEqual(
validateList(root_volume)[0], PASS, "list root volume response is empty for volume id %s" % vm_root.id
)
if self.snapshotSupported:
Snapshot.create(self.apiclient, root_volume[0].id)
snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True)
self.assertEqual(
validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id
)
Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"])
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
self.testdata["privatetemplate"]["url"] = builtin_info[0]
self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1]
self.testdata["privatetemplate"]["format"] = builtin_info[2]
Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id)
Volume.create(
self.apiclient,
self.testdata["volume"],
#.........这里部分代码省略.........
示例14: test_01_disable_enable_pod
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_01_disable_enable_pod(self):
"""disable enable Pod
1. Disable pod and verify following things:
For admin user:
-- Should be able to create new vm, snapshot,
volume,template,iso in the same pod
For Non-admin user:
-- Should not be able to create new vm, snapshot,
volume,template,iso in the same pod
2. Enable the above disabled pod and verify that:
-All users should be able to create new vm, snapshot,
volume,template,iso in the same pod
3. Try to delete the pod and it should fail with error message:
- "The pod is not deletable because there are servers
running in this pod"
"""
# Step 1
vm_user = VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
vm_root = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
cmd = updatePod.updatePodCmd()
cmd.id = self.pod.id
cmd.allocationstate = DISABLED
self.apiclient.updatePod(cmd)
podList = Pod.list(self.apiclient, id=self.pod.id)
self.assertEqual(podList[0].allocationstate, DISABLED, "Check if the pod is in disabled state")
self.assertEqual(vm_user.state.lower(), "running", "Verify that the user vm is running")
self.assertEqual(vm_root.state.lower(), "running", "Verify that the admin vm is running")
VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
root_volume = list_volumes(self.apiclient, virtualmachineid=vm_root.id, type="ROOT", listall=True)
self.assertEqual(validateList(root_volume)[0], PASS, "list snapshot is empty for volume id %s" % vm_root.id)
if self.snapshotSupported:
Snapshot.create(self.apiclient, root_volume[0].id)
snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True)
self.assertEqual(
validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id
)
Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"])
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
self.testdata["privatetemplate"]["url"] = builtin_info[0]
self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1]
self.testdata["privatetemplate"]["format"] = builtin_info[2]
Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id)
Volume.create(
self.apiclient,
self.testdata["volume"],
zoneid=self.zone.id,
account=self.admin_account.name,
domainid=self.admin_account.domainid,
diskofferingid=self.disk_offering.id,
)
Iso.create(
self.apiclient,
self.testdata["iso2"],
zoneid=self.zone.id,
account=self.admin_account.name,
domainid=self.admin_account.domainid,
)
with self.assertRaises(Exception):
VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
#.........这里部分代码省略.........
示例15: test_01_disable_enable_zone
# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create_from_snapshot [as 别名]
def test_01_disable_enable_zone(self):
"""disable enable zone
1. Disable zone and verify following things:
For admin user:
1. Should be create to start/stop exsiting vms
2. Should be create to deploy new vm, snapshot,volume,
template,iso in the same zone
For Non-admin user:
1. Should be create to start/stop exsiting vms
2. Should not be create to deploy new vm, snapshot,volume,
template,iso in the same zone
2. Enable the above disabled zone and verify that:
-All users should be create to deploy new vm,
snapshot,volume,template,iso in the same zone
3. Try to delete the zone and it should fail with error message:
-"The zone is not deletable because there are
servers running in this zone"
"""
# Step 1
vm_user = VirtualMachine.create(
self.userapiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
vm_root = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
cmd = updateZone.updateZoneCmd()
cmd.id = self.zone.id
cmd.allocationstate = DISABLED
self.apiclient.updateZone(cmd)
zoneList = Zone.list(self.apiclient, id=self.zone.id)
self.assertEqual(zoneList[0].allocationstate, DISABLED, "Check if the zone is in disabled state")
# Both user and admin vms shoul be running
self.assertEqual(vm_user.state.lower(), "running", "Verify that the user vm is running")
self.assertEqual(vm_root.state.lower(), "running", "Verify that the admin vm is running")
vm_root.stop(self.apiclient)
vm_user.stop(self.apiclient)
root_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_root.name)[0][0]
user_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_user.name)[0][0]
self.assertEqual(root_state.lower(), "stopped", "verify that vm is Stopped")
self.assertEqual(user_state.lower(), "stopped", "verify that vm is stopped")
root_volume = list_volumes(self.apiclient, virtualmachineid=vm_root.id, type="ROOT", listall=True)
self.assertEqual(validateList(root_volume)[0], PASS, "list volume is empty for vmid %s" % vm_root.id)
root_vm_new = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
templateid=self.template.id,
accountid=self.admin_account.name,
domainid=self.admin_account.domainid,
serviceofferingid=self.service_offering.id,
zoneid=self.zone.id,
)
self.assertEqual(root_vm_new.state.lower(), "running", "Verify that admin should create new VM")
if self.snapshotSupported:
Snapshot.create(self.apiclient, root_volume[0].id)
snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True)
self.assertEqual(
validateList(snapshots)[0], PASS, "list snapshot is empty for volume id %s" % root_volume[0].id
)
Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"])
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
self.testdata["privatetemplate"]["url"] = builtin_info[0]
self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1]
self.testdata["privatetemplate"]["format"] = builtin_info[2]
"""
//commenting it for now will uncomment once expected behaviour is known
Template.register(
self.apiclient,
self.testdata["privatetemplate"],
zoneid=self.zone.id)
"""
#.........这里部分代码省略.........