def run(self, arglist=None): stresstime = 300 workloads = ["Prime95", "SQLIOSim"] versions = ["w2k3eesp2", "w2k3eesp2-x64", "vistaee"] h0 = self.getHost("RESOURCE_HOST_0") h1 = self.getHost("RESOURCE_HOST_1") for version in versions: # Test both directions. for direction in [(h0, h1), (h1, h0)]: g = { "host": direction[0], "guestname": xenrt.util.randomGuestName(), "distro": version, "vifs": [(0, None, xenrt.randomMAC(), None)] } guest = xenrt.lib.xenserver.guest.createVM(**g) guest.installDrivers() guest.suspend() guest.resume(on=direction[1]) # Run some stress tests. work = guest.startWorkloads(workloads) time.sleep(stresstime) guest.stopWorkloads(work) for w in work: w.check() guest.shutdown()
def createVif(self, network_uuid, device): guest_uuid = self.guest.getUUID() vif_uuid = self.host.execdom0( "xe vif-create network-uuid=%s vm-uuid=%s device=%s mac=%s" % (network_uuid, guest_uuid, device, xenrt.randomMAC())).strip() self._vif_uuid_to_remove.append(vif_uuid) return vif_uuid
def __init__(self, toolstack, name, distro, vcpus, memory, vifs=None, rootdisk=None, extraConfig={}): self.toolstack = xenrt.interfaces.Toolstack(toolstack) self.toolstackId = None self.name = name self.distro = distro self.extraConfig = extraConfig self.mainip = None self.inboundmap = {} self.inboundip = None self.outboundip = None self.os = xenrt.lib.opsys.osFactory(self.distro, self) self.rootdisk = rootdisk or self.os.defaultRootdisk self.vcpus = vcpus or self.os.defaultVcpus self.memory = memory or self.os.defaultMemory self.vifs = vifs or [ ("%s0" % (self.os.vifStem), None, xenrt.randomMAC(), None) ] self.special = {}
def createVif(self, bridge, device): network_uuid = self.host.execdom0( "xe network-list bridge=%s params=uuid --minimal" % bridge).strip() guest_uuid = self.guest.getUUID() vif_uuid = self.host.execdom0( "xe vif-create network-uuid=%s vm-uuid=%s device=%s mac=%s" % (network_uuid, guest_uuid, device, xenrt.randomMAC())).strip() return vif_uuid
def createGuest(self, host, distro=None, arch=None, srtype=None, disksize=None): """Create a guest to be exported, return the guest object""" sr = None if srtype: srs = host.getSRs(type=srtype) if not srs: raise xenrt.XRTError("No %s SR found on host." % (srtype)) sr = srs[0] if not distro: if disksize: raise xenrt.XRTError("TC does not support override of " "disk size for default distro") guest = host.createGenericLinuxGuest(arch=arch, sr=sr) self.getLogsFrom(guest) guest.preCloneTailor() return guest elif distro in ["debian", "sarge", "etch"]: if disksize: raise xenrt.XRTError("TC does not support override of " "disk size for legacy Debian VMs") guest = host.guestFactory()( xenrt.randomGuestName(), host.getTemplate(distro), password=xenrt.TEC().lookup("ROOT_PASSWORD_DEBIAN")) self.getLogsFrom(guest) guest.install(host, distro=distro, sr=sr) guest.check() return guest else: if not arch: if re.search(r"64$", distro): arch = "x86-64" else: arch = "x86-32" disks = [] if disksize: disks.append(("0", disksize, False)) guest = xenrt.lib.xenserver.guest.createVM( host, xenrt.randomGuestName(), distro, arch=arch, sr=sr, vifs=[("0", host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=disks) self.getLogsFrom(guest) if guest.windows: guest.installDrivers() return guest
def snapshotVM(self): preVmGenId = self.guest.retreiveVmGenId() vifUUID = self.guest.getVIFUUID("eth0") mac = self.host0.genParamGet("vif", vifUUID, "MAC") netuuid = self.host0.genParamGet("vif", vifUUID, "network-uuid") self.guest.shutdown() self.snapshot = self.guest.snapshot("snapshot") self.guest.start() self.guest.waitForAgent(180) self.guest.reboot() newVmGenId = self.guest.retreiveVmGenId() if preVmGenId == newVmGenId: xenrt.TEC().logverbose( "VmGenID remains same after taking snapshot of original VM as expected" ) else: raise xenrt.XRTFailure( "VM Gen Verification failed after Snapshot operation is performed" ) cli = self.host0.getCLIInstance() temp_uuid = cli.execute( 'snapshot-clone', 'uuid=%s new-name-label=%s' % (self.snapshot, self.vmName + "_snapshot_template")).strip() snapshotVM = self.host0.guestFactory()(self.vmName + "_snapshot", template=self.vmName + "_snapshot_template", host=self.host0) snapshotVM.createGuestFromTemplate(snapshotVM.template, self.defaultSR) self.uninstallOnCleanup(snapshotVM) snapshotVM.removeVIF("eth0") snapshotVM.createVIF("eth0", bridge=netuuid, mac=xenrt.randomMAC()) snapshotVM.enlightenedDrivers = True snapshotVM.windows = True snapshotVM.tailored = True snapshotVM.start() self.vmlifecycle(snapshotVM) newVmGenId = snapshotVM.retreiveVmGenId() if preVmGenId != newVmGenId: xenrt.TEC().logverbose( "VmGenID of a snapshot VM is different from Base VM as expected " ) else: raise xenrt.XRTFailure( "VM Gen Verification failed for VM Snapshot") self.removeTemplateOnCleanup(self.host0, temp_uuid) self.guest.removeSnapshot(self.snapshot)
def prepare(self, arglist): self.host = self.getDefaultHost() self.testmac = xenrt.randomMAC() self.testguest = self.host.guestFactory()(xenrt.randomGuestName()) self.testguest.host = self.host self.testguest.createGuestFromTemplate("Other install media", self.host.getLocalSR()) self.testguest.enablePXE() self.testguest.createVIF(mac=self.testmac, bridge=self.host.getPrimaryBridge()) sftp = self.host.sftpClient() sftp.copyFrom("/usr/lib/syslinux/xentest/%s.c32" % (self.TEST), "%s/%s.c32" % (xenrt.TEC().getWorkdir(), self.TEST))
def createGuest(self, host, distro=None, arch=None, srtype=None, disksize=None): """Create a guest to be exported, return the guest object""" sr = None if srtype: srs = host.getSRs(type=srtype) if not srs: raise xenrt.XRTError("No %s SR found on host." % (srtype)) sr = srs[0] if not distro: if disksize: raise xenrt.XRTError("TC does not support override of " "disk size for default distro") guest = host.createGenericLinuxGuest(arch=arch, sr=sr) self.getLogsFrom(guest) guest.preCloneTailor() return guest elif distro in ["debian","sarge","etch"]: if disksize: raise xenrt.XRTError("TC does not support override of " "disk size for legacy Debian VMs") guest = host.guestFactory()(xenrt.randomGuestName(), host.getTemplate(distro), password=xenrt.TEC().lookup("ROOT_PASSWORD_DEBIAN")) self.getLogsFrom(guest) guest.install(host, distro=distro, sr=sr) guest.check() return guest else: if not arch: if re.search(r"64$", distro): arch = "x86-64" else: arch = "x86-32" disks = [] if disksize: disks.append(("0", disksize, False)) guest = xenrt.lib.xenserver.guest.createVM(host, xenrt.randomGuestName(), distro, arch=arch, sr=sr, vifs=[("0", host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=disks) self.getLogsFrom(guest) if guest.windows: guest.installDrivers() return guest
def prepare(self, arglist=None): # Parse generic args self.parseArgs(arglist) # Parse args relating to this test for arg in arglist: l = string.split(arg, "=", 1) if l[0] == "numothervms": self.numothervms = int(l[1]) elif l[0] == "numiters": self.numiters = int(l[1]) elif l[0] == "measureresponsiveness": self.measureResponsiveness = True elif l[0] == "installfromscratch": self.installFromScratch = True self.initialiseHostList() self.configureAllHosts() if self.goldimagesruuid is None: # Normally we use a very fast NFS server (NetApp machine, e.g. telti) # to put the VM on, but in this case we use local storage: self.goldimagesruuid = self.host.execdom0( """xe sr-list name-label=Local\ storage --minimal""").strip() if not self.installFromScratch: xenrt.TEC().logverbose("Importing VM") self.goldvm = self.importGoldVM(self.goldimagesruuid, self.desktopimage, self.desktopvmname, self.desktopvmnetwork) else: xenrt.TEC().logverbose("Creating VM from scratch") # Create and install the VM self.goldvm = xenrt.lib.xenserver.guest.createVM( self.host, xenrt.randomGuestName(), "ws08-x86", vcpus=4, memory=16384, # MB arch="x86-64", sr=self.goldimagesruuid, vifs=[("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0", 1, False)]) # Shut the VM down, so its start-time is ready to be measured xenrt.TEC().logverbose("Shutting VM down...") self.goldvm.shutdown()
def installGuest(self): if self.DISTRO: vifs = [("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None)] g = xenrt.lib.xenserver.guest.createVM(self.host, xenrt.randomGuestName(), self.DISTRO, vifs=vifs) else: g = self.host.createGenericLinuxGuest() self.uninstallOnCleanup(g) if g.windows: g.installDrivers() return g
def prepare(self, arglist=None): self.host = self.getDefaultHost() self.guests = [] self.hosts = [self.host] # Create the initial VM guest = xenrt.lib.xenserver.guest.createVM(self.host, xenrt.randomGuestName(), self.DISTRO, arch="x86-32", memory=self.MEMORY, vifs=[("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0",1,False)], postinstall=self.POSTINSTALL) self.guests.append(guest) guest.preCloneTailor() # XRT-4854 disable crond on the VM if not guest.windows: try: guest.execguest("/sbin/chkconfig crond off") except: pass guest.shutdown() # Do a clone loop if self.TESTMODE: max = 3 else: max = int(self.host.lookup("MAX_CONCURRENT_VMS")) count = 0 while count < (max - 1): try: if count > 0 and count % 20 == 0: # CA-19617 Perform a vm-copy every 20 clones g = guest.copyVM() guest = g else: g = guest.cloneVM() self.guests.append(g) g.start() g.shutdown() except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to start VM %u: %s" % (count+1,e)) break count += 1
def prepare(self, arglist=None): self.host = self.getDefaultHost() self.guests = [] self.hosts = [self.host] # Create the initial VM guest = xenrt.lib.xenserver.guest.createVM( self.host, xenrt.randomGuestName(), self.DISTRO, arch="x86-32", memory=self.MEMORY, vifs=[("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None) ], disks=[("0", 1, False)], postinstall=self.POSTINSTALL) self.guests.append(guest) guest.preCloneTailor() # XRT-4854 disable crond on the VM if not guest.windows: try: guest.execguest("/sbin/chkconfig crond off") except: pass guest.shutdown() # Do a clone loop if self.TESTMODE: max = 3 else: max = int(self.host.lookup("MAX_CONCURRENT_VMS")) count = 0 while count < (max - 1): try: if count > 0 and count % 20 == 0: # CA-19617 Perform a vm-copy every 20 clones g = guest.copyVM() guest = g else: g = guest.cloneVM() self.guests.append(g) g.start() g.shutdown() except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to start VM %u: %s" % (count + 1, e)) break count += 1
def prepare(self, arglist=None): self.hosts = [] for i in range(self.HOSTS): self.hosts.append(self.getHost("RESOURCE_HOST_%u" % (i))) self.guests = [] self.originals = [] # Create the initial VMs for host in self.hosts: guest = xenrt.lib.xenserver.guest.createVM(host, xenrt.randomGuestName(), self.DISTRO, arch="x86-32", memory=128, vifs=[("0", host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0",1,False)]) self.guests.append(guest) self.originals.append(guest) guest.preCloneTailor() guest.shutdown() # Do a clone loop if self.TESTMODE: max = 3 else: max = int(self.hosts[0].lookup("MAX_CONCURRENT_VMS")) if max > self.HOSTVMCAP: max = self.HOSTVMCAP for guest in self.originals: count = 0 while count < (max - 1): try: g = guest.cloneVM() self.guests.append(g) g.start() g.shutdown() except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to start VM %u: %s" % (count+1,e)) break count += 1
def prepare(self, arglist=None): # Parse generic args self.parseArgs(arglist) # Parse args relating to this test for arg in arglist: l = string.split(arg, "=", 1) if l[0] == "numothervms": self.numothervms = int(l[1]) elif l[0] == "numiters": self.numiters = int(l[1]) elif l[0] == "measureresponsiveness": self.measureResponsiveness = True elif l[0] == "installfromscratch": self.installFromScratch = True self.initialiseHostList() self.configureAllHosts() if self.goldimagesruuid is None: # Normally we use a very fast NFS server (NetApp machine, e.g. telti) # to put the VM on, but in this case we use local storage: self.goldimagesruuid = self.host.execdom0("""xe sr-list name-label=Local\ storage --minimal""").strip() if not self.installFromScratch: xenrt.TEC().logverbose("Importing VM") self.goldvm = self.importGoldVM(self.goldimagesruuid, self.desktopimage, self.desktopvmname, self.desktopvmnetwork) else: xenrt.TEC().logverbose("Creating VM from scratch") # Create and install the VM self.goldvm = xenrt.lib.xenserver.guest.createVM(self.host, xenrt.randomGuestName(), "ws08-x86", vcpus=4, memory=16384, # MB arch="x86-64", sr=self.goldimagesruuid, vifs=[("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0",1,False)]) # Shut the VM down, so its start-time is ready to be measured xenrt.TEC().logverbose("Shutting VM down...") self.goldvm.shutdown()
def createSingleVLAN(self, i): durs = [] # Create a network self.networks[i] = self.execCommandMeasureTime( durs, "xe network-create name-label=vlan-net-%d" % i).strip() xenrt.TEC().logverbose("self.networks[%d] = %s" % (i, self.networks[i])) # On each host in the pool, create a VLAN and plug it for h in self.normalHosts: if not h in self.hostvlans: self.hostvlans[h] = {} self.hostvlans[h][i] = self.execCommandMeasureTime( durs, "xe vlan-create vlan=%d network-uuid=%s pif-uuid=%s" % (i, self.networks[i], self.hosteth0pif[h])).strip() xenrt.TEC().logverbose("self.hostvlans[%s][%d] = %s" % (h, i, self.hostvlans[h][i])) self.execCommandMeasureTime( durs, "xe pif-plug uuid=%s" % self.hostvlans[h][i]) # Create a VIF on the test VM and plug it. (This checks that xapi isn't cheating in VLAN.create!) self.vif = self.execCommandMeasureTime( durs, "xe vif-create network-uuid=%s vm-uuid=%s device=%d mac=%s" % (self.networks[i], self.testVM.uuid, 2, xenrt.randomMAC())).strip() xenrt.TEC().logverbose("self.vif = %s" % (self.vif)) self.execCommandMeasureTime(durs, "xe vif-plug uuid=%s" % self.vif) # Destroy the VIF (because the VM can only handle so many before crashing...) self.host.execdom0("xe vif-unplug uuid=%s" % self.vif) self.host.execdom0("xe vif-destroy uuid=%s" % self.vif) # Compute the total control-plane time for this operation s = sum(durs) self.log(self.createLog, "%d %s %f" % (i, ",".join(map(str, durs)), s)) return s
def prepare(self, arglist=None): self.hosts = [] for i in range(self.HOSTS): self.hosts.append(self.getHost("RESOURCE_HOST_%u" % (i))) self.guests = [] self.originals = [] # Create the initial VMs for host in self.hosts: guest = xenrt.lib.xenserver.guest.createVM( host, xenrt.randomGuestName(), self.DISTRO, arch="x86-32", memory=128, vifs=[("0", host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0", 1, False)]) self.guests.append(guest) self.originals.append(guest) guest.preCloneTailor() guest.shutdown() # Do a clone loop if self.TESTMODE: max = 3 else: max = int(self.hosts[0].lookup("MAX_CONCURRENT_VMS")) if max > self.HOSTVMCAP: max = self.HOSTVMCAP for guest in self.originals: count = 0 while count < (max - 1): try: g = guest.cloneVM() self.guests.append(g) g.start() g.shutdown() except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to start VM %u: %s" % (count + 1, e)) break count += 1
def prepare(self, arglist): postInstall = [] self.host = self.getDefaultHost() if self.PVDRIVER: postInstall = ["installDrivers"] self.vm = xenrt.lib.xenserver.guest.createVM(self.host, xenrt.randomGuestName(), "win7-x86", arch="x86-32", memory=2048, vifs=[("0", self.host.getPrimaryBridge(), xenrt.randomMAC(), None)], disks=[("0",1,False)], postinstall=postInstall, use_ipv6=True) self.getLogsFrom(self.vm) self.uninstallOnCleanup(self.vm)
def snapshotVM(self): preVmGenId = self.guest.retreiveVmGenId() vifUUID = self.guest.getVIFUUID("eth0") mac = self.host0.genParamGet("vif", vifUUID, "MAC") netuuid = self.host0.genParamGet("vif", vifUUID, "network-uuid") self.guest.shutdown() self.snapshot= self.guest.snapshot("snapshot") self.guest.start() self.guest.waitForAgent(180) self.guest.reboot() newVmGenId = self.guest.retreiveVmGenId() if preVmGenId == newVmGenId : xenrt.TEC().logverbose("VmGenID remains same after taking snapshot of original VM as expected") else: raise xenrt.XRTFailure("VM Gen Verification failed after Snapshot operation is performed") cli = self.host0.getCLIInstance() temp_uuid=cli.execute('snapshot-clone','uuid=%s new-name-label=%s' % (self.snapshot,self.vmName +"_snapshot_template")).strip() snapshotVM = self.host0.guestFactory()( self.vmName + "_snapshot", template=self.vmName +"_snapshot_template", host=self.host0) snapshotVM.createGuestFromTemplate(snapshotVM.template ,self.defaultSR ) self.uninstallOnCleanup(snapshotVM) snapshotVM.removeVIF("eth0") snapshotVM.createVIF("eth0", bridge=netuuid, mac=xenrt.randomMAC()) snapshotVM.enlightenedDrivers = True snapshotVM.windows = True snapshotVM.tailored = True snapshotVM.start() self.vmlifecycle(snapshotVM) newVmGenId = snapshotVM.retreiveVmGenId() if preVmGenId != newVmGenId : xenrt.TEC().logverbose("VmGenID of a snapshot VM is different from Base VM as expected ") else : raise xenrt.XRTFailure("VM Gen Verification failed for VM Snapshot") self.removeTemplateOnCleanup(self.host0, temp_uuid) self.guest.removeSnapshot(self.snapshot)
def __init__(self, toolstack, name, distro, vcpus, memory, vifs=None, rootdisk=None, extraConfig={}): self.toolstack = xenrt.interfaces.Toolstack(toolstack) self.toolstackId = None self.name = name self.distro = distro self.extraConfig = extraConfig self.mainip = None self.inboundmap = {} self.inboundip = None self.outboundip = None self.os = xenrt.lib.opsys.osFactory(self.distro, self) self.rootdisk = rootdisk or self.os.defaultRootdisk self.vcpus = vcpus or self.os.defaultVcpus self.memory = memory or self.os.defaultMemory self.vifs = vifs or [("%s0" % (self.os.vifStem), None, xenrt.randomMAC(), None)] self.special = {}
class VLANsPerHost(xenrt.TestCase): """Base class for maximum VLANS per Host test""" MAX = 800 vport = 1745 #for linux bridge no limit, CA-106021-vswitch have limited vports host = "" guest = {} networks = {} hosteth0pif = {} hostvlans = {} BRIDGE_TYPE = "LINUX" guests = [] vif = {} def prepare(self, arglist=None): # Get a host to install on self.host = self.getHost("RESOURCE_HOST_0") # Change network bridge type if self.BRIDGE_TYPE == "LINUX": self.host.disablevswitch() else: self.host.enablevswitch() self.MAX = int(xenrt.TEC().lookup([ "VERSION_CONFIG", xenrt.TEC().lookup("PRODUCT_VERSION"), "MAX_VLANS_PER_HOST_%s" % (self.BRIDGE_TYPE) ])) # Install the VM xenrt.TEC().logverbose("Installing VM...") self.guest[0] = self.host.createGenericLinuxGuest() self.uninstallOnCleanup(self.guest[0]) xenrt.TEC().logverbose("...VM installed successfully") def run(self, arglist=None): vportCount = 0 guest = self.guest[0] guest.shutdown() # Find out the eth0 PIFs on each host self.hosteth0pif = self.host.execdom0( "xe pif-list device=eth0 host-uuid=%s params=uuid --minimal" % self.host.getMyHostUUID()) # Create network for i in range(1, self.MAX + 1): # Create a network self.networks[i] = self.host.execdom0( "xe network-create name-label=vlan-net-%d" % i) xenrt.TEC().logverbose("self.networks[%d] = %s" % (i, self.networks[i])) # Create VLANs for i in range(1, self.MAX + 1): self.hostvlans[i] = self.host.execdom0( "xe vlan-create vlan=%d network-uuid=%s pif-uuid=%s" % (i, self.networks[i].strip('\n'), self.hosteth0pif.strip('\n'))) xenrt.TEC().logverbose("self.hostvlans[%d] = %s" % (i, self.hostvlans[i])) self.host.execdom0("xe pif-plug uuid=%s" % self.hostvlans[i].strip('\n')) vportCount = vportCount + 1 numberOfVMs = (self.vport - self.MAX) / 7 #create VMs vmCount = 0 while vmCount < numberOfVMs: try: if vmCount > 0 and vmCount % 20 == 0: # CA-19617 Perform a vm-copy every 20 clones guest = self.guest[0].copyVM() vportCount = vportCount + 1 self.uninstallOnCleanup(guest) g = guest.cloneVM() vportCount = vportCount + 1 self.guests.append(g) self.uninstallOnCleanup(g) g.start() vmCount += 1 except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to create VM %u: %s" % (vmCount + 1, e)) break # Start adding VIFs, once all vms are full delete existing vif s and add new vifCount = 0 vmCount = 0 # Determine how many VIFs we can add to the guest vifdevices = self.host.genParamGet("vm", self.guest[0].getUUID(), "allowed-VIF-devices").split("; ") vifsToAdd = len(vifdevices) while vifCount < self.MAX: initialCount = vifCount for i in range(0, numberOfVMs): g = self.guests[i] try: for j in range(vifsToAdd): # Create a VIF on the test VM and plug it. (This checks that xapi isn't cheating in VLAN.create!) self.vif[vifCount] = self.host.execdom0( "xe vif-create network-uuid=%s vm-uuid=%s device=%d mac=%s" % (self.networks[vifCount + 1].strip('\n'), g.getUUID(), j + 1, xenrt.randomMAC())) self.host.execdom0("xe vif-plug uuid=%s" % self.vif[vifCount].strip('\n')) vifCount += 1 if vifCount == self.MAX: break except xenrt.XRTFailure, e: xenrt.TEC().comment("Failed to add VIF %u to VM %u: %s" % (vifCount + 1, vmCount, e)) break if vifCount == self.MAX: break #destroy vifs for i in range(initialCount, vifCount): self.host.execdom0("xe vif-unplug uuid=%s" % self.vif[i].strip('\n')) self.host.execdom0("xe vif-destroy uuid=%s" % self.vif[i].strip('\n')) if vifCount == self.MAX: break
def createVif(self, bridge, device): network_uuid = self.host.execdom0("xe network-list bridge=%s params=uuid --minimal" % bridge).strip() guest_uuid = self.guest.getUUID() vif_uuid = self.host.execdom0("xe vif-create network-uuid=%s vm-uuid=%s device=%s mac=%s" % (network_uuid, guest_uuid, device, xenrt.randomMAC())).strip() return vif_uuid
def createTestGuest(self, host): guest = host.templateVM.cloneVM(name=xenrt.randomGuestName()) guest.setHost(host) host.execdom0('xe vif-create vm-uuid=%s network-uuid=%s device=1 mac=%s' % (guest.getUUID(), self.ipv6_net, xenrt.randomMAC())) guest.start() self.getLogsFrom(guest) guest.NICs = guest.getVIFs() self.guests.append(guest) return guest
def install(self, host, start=True, isoname=None, vifs=DEFAULT, repository=None, kickstart="standard", distro=None, guestparams=[], method="HTTP", rootdisk=DEFAULT, pxe=True, sr=None, extrapackages=None, notools=False, extradisks=None, bridge=None, use_ipv6=False): self.setHost(host) # Hack to use correct kickstart for rhel6 if distro and kickstart == "standard": if distro.startswith("rhel6") or distro.startswith("rhelw6"): kickstart = "rhel6" if distro.startswith("oel6"): kickstart = "oel6" if distro.startswith("centos6"): kickstart = "centos6" if distro.startswith("sl6"): kickstart = "sl6" # Have we been asked to choose an ISO automatically? if isoname == xenrt.DEFAULT: if not distro: raise xenrt.XRTError("Cannot choose ISO automatically without " "specifying a distro") if self.arch: arch = self.arch else: arch = "x86-32" isostem = host.lookup(["OS_INSTALL_ISO", distro], distro) trylist = ["%s_xenrtinst.iso" % (isostem), "%s.iso" % (isostem)] if distro == "w2k3eesp2pae": trylist.append("w2k3eesp2.iso") if arch: trylist.append("%s_%s.iso" % (isostem, arch)) if distro.startswith("win") or distro.startswith("ws"): if arch in ["x86-64", "x64", "64"]: winarch = "x64" else: winarch = "x86" trylist.append("%s-%s.iso" % (distro, winarch)) isoname = None for tryit in trylist: isoname = self.host.getCDPath(tryit) if isoname: break if not isoname: raise xenrt.XRTError("Could not find a suitable ISO for %s " "(arch %s)" % (distro, arch)) self.isoname = isoname if distro: self.distro = distro host.addGuest(self) if use_ipv6: # if this was set to True, override the global flag. self.use_ipv6 = True # IPv6 support for w2k3 and winxp is flakey if distro and re.search("w2k|xp", distro) and use_ipv6: xenrt.TEC().logverbose("For windows guests, IPv6 is supported from Vista onwards.") raise xenrt.XRTFailure("IPv6 is not supported for the distro %s" % distro) if vifs: self.vifs = vifs if pxe: self.vifstem = self.VIFSTEMHVM self.enlightenedDrivers = False # Prepare VIFs if type(vifs) == type(self.DEFAULT): if bridge: br = bridge else: br = host.getPrimaryBridge() if not br: raise xenrt.XRTError("Host has no bridge") self.vifs = [("%s0" % (self.vifstem), br, xenrt.randomMAC(), None)] # if not vifs == self.DEFAULT: # nwuuid = host.createNetwork() # bridge = host.genParamGet("network", nwuuid, "bridge") # for i in range(vifs - 1): # self.vifs.append(("%s%d" % (self.vifstem, i + 1), bridge, xenrt.randomMAC(), None)) self.legacyVif = self.requiresLegacyNIC() if self.windows: if len(self.vifs) == 0: raise xenrt.XRTError("Need at least one VIF to install Windows") if repository: self.legacyVif = True if len(self.vifs) == 0: raise xenrt.XRTError("Need at least one VIF to install with " "vendor installer") # Choose a storage respository if not sr: srpath = self.chooseSR() else: srpath = sr try: self.host.xmlrpcExec("mkdir %s" % srpath) except: pass memory_min_limit = xenrt.TEC().lookup(["GUEST_LIMITATIONS", distro, "MINMEMORY"], None) memory_max_limit = xenrt.TEC().lookup(["GUEST_LIMITATIONS", distro, "MAXMEMORY"], None) if memory_min_limit: memory_min_limit = int(memory_min_limit) if self.memory < memory_min_limit: self.memory = memory_min_limit if memory_max_limit: memory_max_limit = int(memory_max_limit) if self.memory > memory_max_limit: self.memory = memory_max_limit self._preInstall() self.host.hypervCmd("New-VM -Name \"%s\" -MemoryStartupBytes %dMB -NewVHDPath %s\\%s.vhdx -NewVHDSizeBytes %d -Generation 1" % (self.name, self.memory, srpath, str(uuid.uuid4()), rootdisk)) # Delete the default network adapter self.host.hypervCmd("Remove-VMNetworkAdapter -VMName \"%s\"" % self.name) # Add VIFs for eth, bridge, mac, ip in self.vifs: self.createVIF(eth, bridge, mac) # Add any extra disks. if extradisks: for size in extradisks: self.createDisk(sizebytes=int(size)*xenrt.MEGA) # Windows needs to install from a CD if self.windows: self.installWindows(self.isoname) elif repository and not isoname: pxe = True dev = "%sa" % (self.vendorInstallDevicePrefix()) options = {"maindisk" : dev} if not pxe: options["OSS_PV_INSTALL"] = True # Install using the vendor installer. self.installVendor(distro, repository, method="HTTP", config=kickstart, pxe=pxe, extrapackages=extrapackages, options=options) self._postInstall() self.removeLegacyVifs() if start: self.start() xenrt.TEC().comment("Created %s guest named %s with %u vCPUS and " "%uMB memory." % (self.template, self.name, self.vcpus, self.memory)) ip = self.getIP() if ip: xenrt.TEC().logverbose("Guest address is %s" % (ip))
def createVM(host, guestname, distro, vcpus=None, corespersocket=None, memory=None, vifs=[], bridge=None, sr=None, guestparams=[], arch="x86-32", disks=[], postinstall=[], pxe=True, template=None, notools=False, bootparams=None, use_ipv6=False, suffix=None, ips={}, **kwargs): if not isinstance(host, xenrt.GenericHost): host = xenrt.TEC().registry.hostGet(host) if distro.startswith("generic-"): distro = distro[8:] if not vifs: # Some tests rely on getting a VIF by default for generic VMs. vifs = xenrt.lib.hyperv.Guest.DEFAULT if distro.lower() == "windows" or distro.lower() == "linux": distro = host.lookup("GENERIC_" + distro.upper() + "_OS" + (arch.endswith("64") and "_64" or ""), distro) # Create the guest object. g = host.guestFactory()(guestname, template, password=xenrt.TEC().lookup("DEFAULT_PASSWORD")) g.arch = arch if re.search("[vw]", distro): g.windows = True g.vifstem = g.VIFSTEMHVM g.hasSSH = False else: g.windows = False g.vifstem = g.VIFSTEMPV g.hasSSH = True if vifs == xenrt.lib.hyperv.Guest.DEFAULT: vifs = [("0", host.getPrimaryBridge(), xenrt.randomMAC(), None)] update = [] for v in vifs: device, bridge, mac, ip = v device = "%s%s" % (g.vifstem, device) if not bridge: bridge = host.getPrimaryBridge() if not bridge: raise xenrt.XRTError("Failed to choose a bridge for createVM on " "host !%s" % (host.getName())) update.append([device, bridge, mac, ip]) vifs = update # The install method doesn't do this for us. if vcpus: g.setVCPUs(vcpus) if memory: g.setMemory(memory) # TODO: boot params # Try and determine the repository. repository = xenrt.getLinuxRepo(distro, arch, "HTTP", None) # Work out the ISO name. if not repository: isoname = xenrt.DEFAULT else: isoname = None rootdisk = xenrt.lib.hyperv.Guest.DEFAULT for disk in disks: device, size, format = disk if device == "0": rootdisk = int(size)*xenrt.GIGA # Install the guest. g.install(host, distro=distro, vifs=vifs, bridge=bridge, sr=sr, guestparams=guestparams, isoname=isoname, rootdisk=rootdisk, repository=repository, pxe=pxe, notools=notools, use_ipv6=use_ipv6) if g.windows: g.xmlrpcShutdown() else: g.execguest("/sbin/shutdown -h now") g.poll("DOWN") diskstoformat = [] for disk in disks: device, size, format = disk if str(device) != "0": d = g.createDisk(sizebytes=int(size)*xenrt.GIGA,userdevice=device) if format: diskstoformat.append(d) g.start() for d in diskstoformat: if g.windows: letter = g.xmlrpcPartition(d) g.xmlrpcFormat(letter, timeout=3600) else: # FIXME: this is probably wrong letter = g.DEVICE_DISK_PREFIX + chr(int(d)+ord('a')) g.execguest("mkfs.ext2 /dev/%s" % (letter)) g.execguest("mount /dev/%s /mnt" % (letter)) # Store the object in the registry. xenrt.TEC().registry.guestPut(guestname, g) xenrt.TEC().registry.configPut(guestname, vcpus=vcpus, memory=memory, distro=distro) for p in postinstall: if type(p) == tuple: data, format = p if format == "cmd": g.xmlrpcWriteFile("c:\\postrun.cmd", data) g.xmlrpcExec("c:\\postrun.cmd") g.xmlrpcRemoveFile("c:\\postrun.cmd") elif format == "vbs": g.xmlrpcWriteFile("c:\\postrun.vbs", data) g.xmlrpcExec("cscript //b //NoLogo c:\\postrun.vbs") g.xmlrpcRemoveFile("c:\\postrun.vbs") else: eval("g.%s()" % (p)) return g
def run(self, arglist=None): kit = "sdk" if arglist and len(arglist) > 0: machine = arglist[0] else: raise xenrt.XRTError("No machine specified for installation") host = xenrt.TEC().registry.hostGet(machine) if not host: raise xenrt.XRTError("Unable to find host %s in registry" % (machine)) self.getLogsFrom(host) # Optional arguments vcpus = None memory = None uninstall = True guestname = xenrt.randomGuestName() for arg in arglist[1:]: l = string.split(arg, "=", 1) if l[0] == "vcpus": vcpus = int(l[1]) elif l[0] == "memory": memory = int(l[1]) elif l[0] == "nouninstall": uninstall = False elif l[0] == "kit": kit = l[1] elif l[0] == "guest": guestname = l[1] g = host.guestFactory()(\ guestname, "NO_TEMPLATE", password=xenrt.TEC().lookup("ROOT_PASSWORD_SDK")) g.host = host self.guest = g if vcpus != None: g.setVCPUs(vcpus) if memory != None: g.setMemory(memory) # Perform the import sdkzip = None sdkiso = xenrt.TEC().lookup("SDK_CD_IMAGE", None) if not sdkiso: sdkzip = xenrt.TEC().getFile("xe-phase-2/%s.zip" % (kit), "%s.zip" % (kit)) if not sdkiso and not sdkzip: sdkiso = xenrt.TEC().getFile("xe-phase-2/%s.iso" % (kit), "%s.iso" % (kit)) if not sdkiso and not sdkzip: raise xenrt.XRTError("No SDK ISO/ZIP file given") try: if sdkiso: mount = xenrt.MountISO(sdkiso) mountpoint = mount.getMount() if sdkzip: # XXX Make this a tempDir once we've moved them out of /tmp tmp = xenrt.NFSDirectory() mountpoint = tmp.path() xenrt.command("unzip %s -d %s" % (sdkzip, mountpoint)) g.importVM(host, "%s/%s" % (mountpoint, kit)) br = host.getPrimaryBridge() if not br: raise xenrt.XRTError("Host has no bridge") g.vifs = [("eth0", br, xenrt.randomMAC(), None)] for v in g.vifs: eth, bridge, mac, ip = v g.createVIF(eth, bridge, mac) finally: try: if sdkiso: mount.unmount() if sdkzip: tmp.remove() except: pass g.memset(g.memory) g.cpuset(g.vcpus) xenrt.TEC().registry.guestPut(guestname, g) # Make sure we can boot it g.makeNonInteractive() g.tailored = True g.start() time.sleep(120) g.shutdown() # Uninstall if uninstall: g.uninstall()
def createVif(self, network_uuid, device): guest_uuid = self.guest.getUUID() vif_uuid = self.host.execdom0("xe vif-create network-uuid=%s vm-uuid=%s device=%s mac=%s" % (network_uuid, guest_uuid, device, xenrt.randomMAC())).strip() self._vif_uuid_to_remove.append(vif_uuid) return vif_uuid
def run(self, arglist=None): # Install a BIOS-customized VM self.pool = self.getDefaultPool() self.guest = self.pool.master.installRamdiskLinuxGuest(memory=self.MEMORY, biosHostUUID=self.pool.master.getMyHostUUID(), ramdisk_size=self.RAMDISK_SIZE) self.uninstallOnCleanup(self.guest) # Check the BIOS status of the VM is reported as customized cli = self.pool.getCLIInstance() guestBiosStatus = cli.execute("vm-is-bios-customized", "vm=%s" % (self.guest.getName()), strip=True) if guestBiosStatus != CUSTOM_BIOS_STATUS: raise xenrt.XRTFailure("The VM is not BIOS-customized") # Get the SMBIOS Strings of the VM that will be used as a template templatexsBIOS = self.getXenStoreBIOS(self.guest.getDomid(), self.pool.master) self.guest.shutdown() self.guest.removeVIF("eth0") self.guest.paramSet("is-a-template", "true") template = self.guest # Install a new VM from the BIOS-customized template vm = self.pool.master.guestFactory()(xenrt.randomGuestName(), template=template.getName(), host=self.pool.master) vm.createGuestFromTemplate(vm.template, sruuid=None) self.uninstallOnCleanup(vm) mac = xenrt.randomMAC() vm.createVIF(bridge=self.pool.master.getPrimaryBridge(), mac=mac) vm.enlightenedDrivers = False # Create PXE file for the new VM so that it can boot self.createPXEFileForMac(mac) vm.start() if not vm.mainip: raise xenrt.XRTError("Could not find ramdisk guest IP address") vm.waitForSSH(600) # Check the BIOS status of the new VM is reported as customized vmBiosStatus = cli.execute("vm-is-bios-customized", "vm=%s" % (vm.getName()), strip=True) if vmBiosStatus != CUSTOM_BIOS_STATUS: raise xenrt.XRTFailure("The VM created from a BIOS-customized " "template is not BIOS-customized") # Get the new VM's SMBIOS Strings and check them against the template's vmxsBIOS = self.getXenStoreBIOS(vm.getDomid(), self.pool.master) vmdmiBIOS = self.getDMIBIOS(vm) dmiGenBIOS = self.getDMIGenericBIOS(self.pool.master.paramGet("software-version", "xen")) self.checkGuestXenStoreBIOS(vmxsBIOS, templatexsBIOS) self.checkGuestDMIBIOS(vmdmiBIOS, templatexsBIOS, dmiGenBIOS) # Allow the template to get uninstalled on cleanup template.paramSet("is-a-template", "false") # Check the affinity field is set to the master host if vm.paramGet("affinity") != self.pool.master.getMyHostUUID(): raise xenrt.XRTFailure("The VM created from a BIOS-customized " "template does not have the affinity set " "to the pool master")
def createSingleVLAN(self, i): durs = [] # Create a network self.networks[i] = self.execCommandMeasureTime(durs, "xe network-create name-label=vlan-net-%d" % i).strip() xenrt.TEC().logverbose("self.networks[%d] = %s" % (i, self.networks[i])) # On each host in the pool, create a VLAN and plug it for h in self.normalHosts: if not h in self.hostvlans: self.hostvlans[h] = {} self.hostvlans[h][i] = self.execCommandMeasureTime(durs, "xe vlan-create vlan=%d network-uuid=%s pif-uuid=%s" % (i, self.networks[i], self.hosteth0pif[h])).strip() xenrt.TEC().logverbose("self.hostvlans[%s][%d] = %s" % (h, i, self.hostvlans[h][i])) self.execCommandMeasureTime(durs, "xe pif-plug uuid=%s" % self.hostvlans[h][i]) # Create a VIF on the test VM and plug it. (This checks that xapi isn't cheating in VLAN.create!) self.vif = self.execCommandMeasureTime(durs, "xe vif-create network-uuid=%s vm-uuid=%s device=%d mac=%s" % (self.networks[i], self.testVM.uuid, 2, xenrt.randomMAC())).strip() xenrt.TEC().logverbose("self.vif = %s" % (self.vif)) self.execCommandMeasureTime(durs, "xe vif-plug uuid=%s" % self.vif) # Destroy the VIF (because the VM can only handle so many before crashing...) self.host.execdom0("xe vif-unplug uuid=%s" % self.vif) self.host.execdom0("xe vif-destroy uuid=%s" % self.vif) # Compute the total control-plane time for this operation s = sum(durs) self.log(self.createLog, "%d %s %f" % (i, ",".join(map(str, durs)), s)) return s
def run(self, arglist=None): # Install a BIOS-customized VM self.pool = self.getDefaultPool() self.guest = self.pool.master.installRamdiskLinuxGuest( memory=self.MEMORY, biosHostUUID=self.pool.master.getMyHostUUID(), ramdisk_size=self.RAMDISK_SIZE) self.uninstallOnCleanup(self.guest) # Check the BIOS status of the VM is reported as customized cli = self.pool.getCLIInstance() guestBiosStatus = cli.execute("vm-is-bios-customized", "vm=%s" % (self.guest.getName()), strip=True) if guestBiosStatus != CUSTOM_BIOS_STATUS: raise xenrt.XRTFailure("The VM is not BIOS-customized") # Get the SMBIOS Strings of the VM that will be used as a template templatexsBIOS = self.getXenStoreBIOS(self.guest.getDomid(), self.pool.master) self.guest.shutdown() self.guest.removeVIF("eth0") self.guest.paramSet("is-a-template", "true") template = self.guest # Install a new VM from the BIOS-customized template vm = self.pool.master.guestFactory()(xenrt.randomGuestName(), template=template.getName(), host=self.pool.master) vm.createGuestFromTemplate(vm.template, sruuid=None) self.uninstallOnCleanup(vm) mac = xenrt.randomMAC() vm.createVIF(bridge=self.pool.master.getPrimaryBridge(), mac=mac) vm.enlightenedDrivers = False # Create PXE file for the new VM so that it can boot self.createPXEFileForMac(mac) vm.start() if not vm.mainip: raise xenrt.XRTError("Could not find ramdisk guest IP address") vm.waitForSSH(600) # Check the BIOS status of the new VM is reported as customized vmBiosStatus = cli.execute("vm-is-bios-customized", "vm=%s" % (vm.getName()), strip=True) if vmBiosStatus != CUSTOM_BIOS_STATUS: raise xenrt.XRTFailure("The VM created from a BIOS-customized " "template is not BIOS-customized") # Get the new VM's SMBIOS Strings and check them against the template's vmxsBIOS = self.getXenStoreBIOS(vm.getDomid(), self.pool.master) vmdmiBIOS = self.getDMIBIOS(vm) dmiGenBIOS = self.getDMIGenericBIOS( self.pool.master.paramGet("software-version", "xen")) self.checkGuestXenStoreBIOS(vmxsBIOS, templatexsBIOS) self.checkGuestDMIBIOS(vmdmiBIOS, templatexsBIOS, dmiGenBIOS) # Allow the template to get uninstalled on cleanup template.paramSet("is-a-template", "false") # Check the affinity field is set to the master host if vm.paramGet("affinity") != self.pool.master.getMyHostUUID(): raise xenrt.XRTFailure("The VM created from a BIOS-customized " "template does not have the affinity set " "to the pool master")