from XmTestLib.XenAPIDomain import XmTestAPIDomain from XmTestLib import * from xen.xend import XendAPIConstants import commands import os try: # XmTestAPIDomain tries to establish a connection to XenD domain = XmTestAPIDomain() except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm_uuid = domain.get_uuid() session = xapi.connect() domain.start(startpaused=True) res = session.xenapi.VM.get_power_state(vm_uuid) if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]: FAIL("VM was not started in 'paused' state") res = session.xenapi.VM.unpause(vm_uuid) res = session.xenapi.VM.get_power_state(vm_uuid) if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]: FAIL("VM could not be put into 'running' state") console = domain.getConsole()
# Create another domain try: # XmTestAPIDomain tries to establish a connection to XenD domain = XmTestAPIDomain(extraConfig={'security_label': vm_label_blue}) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm_uuid = domain.get_uuid() res = session.xenapi.VM.get_security_label(vm_uuid) if res != vm_label_blue: FAIL("VM has security label '%s', expected is '%s'" % (res, vm_label_blue)) try: domain.start(noConsole=True) except: FAIL("Could not create domain") # Attempt to relabel the running domain ssidref = session.xenapi.VM.set_security_label(vm_uuid, vm_label_red, vm_label_blue) if int(ssidref) <= 0: FAIL("Could not relabel running domain to '%s'." % vm_label_red) # user domain is 'red', dom0 is current 'SystemManagement'. # Try to move domain-0 to 'red' first, then to 'blue'. # Moving domain-0 to 'red' should work ssidref = session.xenapi.VM.set_security_label(DOM0_UUID, vm_label_red, vm_label_sys)
try: # XmTestAPIDomain tries to establish a connection to XenD domain = XmTestAPIDomain(extraConfig={ 'security_label' : vm_label_blue }) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm_uuid = domain.get_uuid() res = session.xenapi.VM.get_security_label(vm_uuid) if res != vm_label_blue: FAIL("VM has security label '%s', expected is '%s'" % (res, vm_label_blue)) try: domain.start(noConsole=True) except: FAIL("Could not create domain") # Attempt to relabel the running domain ssidref = session.xenapi.VM.set_security_label(vm_uuid, vm_label_red, vm_label_blue) if int(ssidref) <= 0: FAIL("Could not relabel running domain to '%s'." % vm_label_red) # user domain is 'red', dom0 is current 'SystemManagement'. # Try to move domain-0 to 'red' first, then to 'blue'. # Moving domain-0 to 'red' should work
if res != vdi_ref: session.xenapi.VDI.destroy(vdi_ref) FAIL("VBD_get_VDI returned wrong result") res = session.xenapi.VBD.get_device(vbd_ref) print "VBD device: %s" % res if res != vbd_rec['device']: session.xenapi.VDI.destroy(vdi_ref) FAIL("VBD_get_device returned wrong result") res = session.xenapi.VM.get_VBDs(vm_uuid) if vbd_ref not in res: session.xenapi.VDI.destroy(vdi_ref) FAIL("VM_get_VBDS does not show created VBD") rc = domain.start() console = domain.getConsole() try: run = console.runCmd("cat /proc/interrupts") except ConsoleError, e: saveLog(console.getHistory()) session.xenapi.VDI.destroy(vdi_ref) FAIL("Could not access proc-filesystem") domain.stop() domain.destroy() session.xenapi.VDI.destroy(vdi_ref)
default_gateway = "172.16.77.72" default_netmask = "255.255.255.0" @staticmethod def remove_network(guest): nw = guest.session.xenapi.network.get_all() for n in nw: name = guest.session.xenapi.network.get_name_label(n) if name == TCConfig.network_name: guest.session.xenapi.network.destroy(n) # Create two domains (default XmTestDomain, with our ramdisk) try: guest1 = XmTestAPIDomain() console1 = guest1.start() # guest1.newDevice(XenNetDevice, "eth0") # guest1_netdev = guest1.getDevice("eth0") guest2 = XmTestAPIDomain() console2 = guest2.start() except DomainError, e: if verbose: print("Failed to create test domain because: %s" % e.extra) FAIL(str(e)) # Clean up relicts TCConfig.remove_network(guest1) # Create a network network = guest1.session.xenapi.network.create( {
session.xenapi.VDI.destroy(vdi_ref) FAIL("VBD_get_VDI returned wrong result") res = session.xenapi.VBD.get_device(vbd_ref) print "VBD device: %s" % res if res != vbd_rec['device']+":disk": session.xenapi.VDI.destroy(vdi_ref) FAIL("VBD_get_device returned wrong result") res = session.xenapi.VM.get_VBDs(vm_uuid) if vbd_ref not in res: session.xenapi.VDI.destroy(vdi_ref) FAIL("VM_get_VBDS does not show created VBD") rc = domain.start() console = domain.getConsole() try: run = console.runCmd("cat /proc/interrupts") except ConsoleError, e: saveLog(console.getHistory()) session.xenapi.VDI.destroy(vdi_ref) FAIL("Could not access proc-filesystem") domain.stop() domain.destroy() session.xenapi.VDI.destroy(vdi_ref)
vtpm_ref = session.xenapi.VTPM.get_by_uuid(vtpm_uuid) if vtpm_ref != vtpm_uuid: FAIL("vTPM from VTPM.get_by_uuid different (%s) than expected (%s)." % (vtpm_ref, vtpm_uuid)) vm_vtpms = session.xenapi.VM.get_VTPMs(vm_uuid) if len(vm_vtpms) != 1: FAIL("Number of vTPMs from get_VTPMs is (%d) not what was expected (%d)" % (len(vm_vtpms), 1)) if vtpm_uuid not in vm_vtpms: FAIL("Other vTPM uuid (%s) returned from VM.get_VTPMs than expected (%s)" % (vm_vtpms[0], vtpm_uuid)) try: console = domain.start() except DomainError, e: FAIL("Unable to create domain.") try: console.sendInput("input") except ConsoleError, e: saveLog(console.getHistory()) FAIL(str(e)) try: run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") except ConsoleError, e: saveLog(console.getHistory()) FAIL("1. No result from dumping the PCRs")
policystate = session.xenapi.XSPolicy.get_xspolicy() # # Create two non-conflicting domains and start them # try: # XmTestAPIDomain tries to establish a connection to XenD domain1 = XmTestAPIDomain(extraConfig={ 'security_label' : vm_label_red }) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm1_uuid = domain1.get_uuid() try: domain1.start(noConsole=True) except: FAIL("Could not start domain1") print "Domain 1 started" try: # XmTestAPIDomain tries to establish a connection to XenD domain2 = XmTestAPIDomain(extraConfig={'security_label': vm_label_green }) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm2_uuid = domain2.get_uuid() try: domain2.start(noConsole=True)
ramdisk_orig_uri = arch.configDefaults['ramdisk'] kernel_data_uri = scheme_data.create_from_file(kernel_orig_uri) ramdisk_data_uri = scheme_data.create_from_file(ramdisk_orig_uri) kernel_file_uri = scheme_file.encode(kernel_orig_uri) ramdisk_file_uri = scheme_file.encode(ramdisk_orig_uri) config = copy.copy(arch.configDefaults) for kernel in (kernel_orig_uri, kernel_data_uri, kernel_file_uri): for ramdisk in (ramdisk_orig_uri, ramdisk_data_uri, ramdisk_file_uri): config['kernel'] = kernel config['ramdisk'] = ramdisk print("Using kernel='%s' ramdisk='%s'" % (kernel[:100], ramdisk[:100])) try: guest = XmTestAPIDomain(baseConfig = config) console = guest.start() except DomainError, e: if verbose: print("Failed to create test domain because: %s" % e.extra) FAIL(str(e)) try: run = console.runCmd("ls /") if run['return'] > 0: FAIL("Could not start host") except ConsoleError, e: saveLog(console.getHistory()) FAIL(str(e)) guest.closeConsole() guest.stop()
from XmTestLib.XenAPIDomain import XmTestAPIDomain from XmTestLib import * from xen.xend import XendAPIConstants import commands import os try: # XmTestAPIDomain tries to establish a connection to XenD domain = XmTestAPIDomain() except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm_uuid = domain.get_uuid() session = xapi.connect() domain.start(startpaused=True) res = session.xenapi.VM.get_power_state(vm_uuid) if res != XendAPIConstants.XEN_API_VM_POWER_STATE[ XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]: FAIL("VM was not started in 'paused' state") res = session.xenapi.VM.unpause(vm_uuid) res = session.xenapi.VM.get_power_state(vm_uuid) if res != XendAPIConstants.XEN_API_VM_POWER_STATE[ XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]: FAIL("VM could not be put into 'running' state")
ramdisk_orig_uri = arch.configDefaults['ramdisk'] kernel_data_uri = scheme_data.create_from_file(kernel_orig_uri) ramdisk_data_uri = scheme_data.create_from_file(ramdisk_orig_uri) kernel_file_uri = scheme_file.encode(kernel_orig_uri) ramdisk_file_uri = scheme_file.encode(ramdisk_orig_uri) config = copy.copy(arch.configDefaults) for kernel in (kernel_orig_uri, kernel_data_uri, kernel_file_uri): for ramdisk in (ramdisk_orig_uri, ramdisk_data_uri, ramdisk_file_uri): config['kernel'] = kernel config['ramdisk'] = ramdisk print("Using kernel='%s' ramdisk='%s'" % (kernel[:100], ramdisk[:100])) try: guest = XmTestAPIDomain(baseConfig=config) console = guest.start() except DomainError, e: if verbose: print("Failed to create test domain because: %s" % e.extra) FAIL(str(e)) try: run = console.runCmd("ls /") if run['return'] > 0: FAIL("Could not start host") except ConsoleError, e: saveLog(console.getHistory()) FAIL(str(e)) guest.closeConsole() guest.stop()
vtpm_ref = session.xenapi.VTPM.get_by_uuid(vtpm_uuid) if vtpm_ref != vtpm_uuid: FAIL("vTPM from VTPM.get_by_uuid different (%s) than expected (%s)." % (vtpm_ref, vtpm_uuid)) vm_vtpms = session.xenapi.VM.get_VTPMs(vm_uuid) if len(vm_vtpms) != 1: FAIL("Number of vTPMs from get_VTPMs is (%d) not what was expected (%d)" % (len(vm_vtpms), 1)) if vtpm_uuid not in vm_vtpms: FAIL("Other vTPM uuid (%s) returned from VM.get_VTPMs than expected (%s)" % (vm_vtpms[0], vtpm_uuid)) try: console = domain.start() except DomainError, e: FAIL("Unable to create domain.") try: console.sendInput("input") except ConsoleError, e: saveLog(console.getHistory()) FAIL(str(e)) try: run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") except ConsoleError, e: saveLog(console.getHistory()) FAIL("1. No result from dumping the PCRs")
policystate = session.xenapi.XSPolicy.get_xspolicy() # # Create two non-conflicting domains and start them # try: # XmTestAPIDomain tries to establish a connection to XenD domain1 = XmTestAPIDomain(extraConfig={'security_label': vm_label_red}) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm1_uuid = domain1.get_uuid() try: domain1.start(noConsole=True) except: FAIL("Could not start domain1") print "Domain 1 started" try: # XmTestAPIDomain tries to establish a connection to XenD domain2 = XmTestAPIDomain(extraConfig={'security_label': vm_label_green}) except Exception, e: SKIP("Skipping test. Error: %s" % str(e)) vm2_uuid = domain2.get_uuid() try: domain2.start(noConsole=True)