def run(self, arglist=None): sdkzip = xenrt.TEC().getFile("xe-phase-2/sdk.zip", "sdk.zip") if not sdkzip: raise xenrt.XRTError("Couldn't find xe-phase-2/sdk.zip") nfs = xenrt.NFSDirectory() xenrt.command("unzip %s -d %s" % (sdkzip, nfs.path())) self.guest = self.host.guestFactory()(\ xenrt.randomGuestName(), host=self.host, password=xenrt.TEC().lookup("ROOT_PASSWORD_SDK")) self.guest.importVM(self.host, "%s/sdk" % (nfs.path())) self.guest.paramSet("is-a-template", "true") nfs.remove() nfs = xenrt.NFSDirectory() xenrt.getTestTarball("apiperf", extract=True, directory=nfs.path()) self.host.createISOSR(nfs.getMountURL("apiperf")) self.sr = self.host.parseListForUUID( "sr-list", "name-label", "Remote ISO Library on: %s" % (nfs.getMountURL("apiperf"))) for s in self.host.getSRs(type="iso", local=True): self.host.getCLIInstance().execute("sr-scan", "uuid=%s" % (s)) time.sleep(30) self.runSubcase("test", "pool0", "Pool", "Pool0") self.runSubcase("test", "pool1", "Pool", "Pool1") self.runSubcase("test", "xendesktop", "XenDesktop", "XenDesktop")
def generateIsoAnswerfile(self): kickstartfile = "kickstart-%s.cfg" % (self.parent._osParent_name) filename = "%s/%s" % (xenrt.TEC().getLogdir(), kickstartfile) self.nfsdir = xenrt.NFSDirectory() ksf = RHELKickStartFile(self.distro, self._maindisk, self.nfsdir.getMountURL(""), repository=self.installURL, installOn=self.parent._osParent_hypervisorType, pxe=False, arch=self.arch) ks = ksf.generate() f = file(filename, "w") f.write(ks) f.close() installIP = self.getIP(trafficType="OUTBOUND", timeout=600) path = "%s/%s" % (xenrt.TEC().lookup("GUESTFILE_BASE_PATH"), installIP) self.cleanupdir = path try: os.makedirs(path) except: pass xenrt.rootops.sudo("chmod -R a+w %s" % path) xenrt.command("rm -f %s/kickstart.stamp" % path) shutil.copyfile(filename, "%s/kickstart" % (path))
def generateAnswerfile(self, webdir): """Generate an answerfile and put it in the provided webdir, returning any command line arguments needed to boot the OS""" kickstartfile = "kickstart-%s.cfg" % (self.parent._osParent_name) filename = "%s/%s" % (xenrt.TEC().getLogdir(), kickstartfile) self.nfsdir = xenrt.NFSDirectory() ksf = RHELKickStartFile(self.distro, self._maindisk, self.nfsdir.getMountURL(""), repository=self.installURL, installOn=self.parent._osParent_hypervisorType, pxe=False, arch=self.arch) ks = ksf.generate() f = file(filename, "w") f.write(ks) f.close() webdir.copyIn(filename) url = webdir.getURL(os.path.basename(filename)) # TODO: handle native where console is different, # and handle other interfaces return ["graphical", "utf8", "ks=%s" % url]
def generateIsoAnswerfile(self): autoyastfile = "autoyast-%s.cfg" % (self.parent._osParent_name) filename = "%s/%s" % (xenrt.TEC().getLogdir(), autoyastfile) xenrt.TEC().logverbose("FILENAME %s"%filename) self.nfsdir = xenrt.NFSDirectory() ayf= SLESAutoyastFile(self.distro, self.nfsdir.getMountURL(""), self._maindisk, installOn=self.parent._osParent_hypervisorType, pxe=False) # rebootAfterInstall = False) ay = ayf.generate() f = file(filename, "w") f.write(ay) f.close() installIP = self.getIP(trafficType="OUTBOUND", timeout=600) path = "%s/%s" % (xenrt.TEC().lookup("GUESTFILE_BASE_PATH"), installIP) self.cleanupdir = path try: os.makedirs(path) except: pass xenrt.rootops.sudo("chmod -R a+w %s" % path) xenrt.command("rm -f %s/autoyast.stamp" % path) shutil.copyfile(filename, "%s/autoyast" % (path))
def create(self, server=None, path=None, physical_size=0, content_type="", nosubdir=False): if not (server or path): if xenrt.TEC().lookup("FORCE_NFSSR_ON_CTRL", False, boolean=True): # Create an SR using an NFS export from the XenRT controller. # This should only be used for small and low I/O throughput # activities - VMs should never be installed on this. nfsexport = xenrt.NFSDirectory() server, path = nfsexport.getHostAndPath("") else: # Create an SR on an external NFS file server share = xenrt.ExternalNFSShare() nfs = share.getMount() r = re.search(r"([0-9\.]+):(\S+)", nfs) server = r.group(1) path = r.group(2) self.server = server self.path = path self._create("netfs", "<host name='%s'/><dir path='%s'/>" % (server, path), "")
def generateAnswerfile(self, webdir): """Generate an answerfile and put it in the provided webdir, returning any command line arguments needed to boot the OS""" autoyastfile = "autoyast-%s.cfg" % (self.parent._osParent_name) filename = "%s/%s" % (xenrt.TEC().getLogdir(), autoyastfile) xenrt.TEC().logverbose("FILENAME %s"%filename) self.nfsdir = xenrt.NFSDirectory() ayf= SLESAutoyastFile(self.distro, self.nfsdir.getMountURL(""), self._maindisk, installOn=self.parent._osParent_hypervisorType, pxe=False) # rebootAfterInstall = False) ay = ayf.generate() f = file(filename, "w") f.write(ay) f.close() webdir.copyIn(filename) url = webdir.getURL(os.path.basename(filename)) # TODO: handle native where console is different, and handle other interfaces return ["graphical", "utf8", "ks=%s" % url]
def install(self, cd=None, primarydisk=None, guestdisks=["sda"], source="url", timezone="UTC", interfaces=[(None, "yes", "dhcp", None, None, None)], ntpserver=None, nameserver=None, hostname=None, installSRType=None, bootloader=None, overlay=None, suppackcds=None): xenrt.TEC().progress("Installing ESXi %s" % self.esxiVersion) workdir = xenrt.TEC().getWorkdir() # Get a PXE directory to put boot files in pxe = xenrt.PXEBoot() # Create an NFS directory for images, signals, etc. nfsdir = xenrt.NFSDirectory() isoname = "/usr/groups/xenrt/esx/ESXi-%s.iso" % self.esxiVersion esxiso = xenrt.TEC().getFile(isoname) if not esxiso: raise xenrt.XRTError("Couldn't find ISO %s" % (isoname)) mount = xenrt.rootops.MountISO(esxiso) mountpoint = mount.getMount() pxe.copyIn("%s/*" % (mountpoint)) # create kickstart file ksname = "kickstart-%s.cfg" % (self.getName()) kspath = "%s/%s" % (workdir, ksname) ks = file(kspath, "w") kstext = """ vmaccepteula rootpw %s clearpart --alldrives --overwritevmfs install --firstdisk --overwritevmfs network --bootproto=dhcp --device=vmnic0 %%firstboot --interpreter=busybox vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 esxcli network firewall set --enabled false esxcli network vswitch standard policy security set --allow-promiscuous true -v vSwitch0 esxcli system settings advanced set -i 1 -o /Misc/LogToSerial esxcli system settings advanced set -i 115200 -o /Misc/SerialBaudRate esxcli system settings advanced set -i 1 -o /Misc/DebugLogToSerial esxcli system settings advanced set -s NONE -o /Misc/LogPort esxcli system settings advanced set -s COM1 -o /Misc/LogPort %%post --interpreter=busybox exec < /dev/console > /dev/console 2> /dev/console touch /vmfs/volumes/remote-install-location/.xenrtsuccess sleep 30 reboot """ % xenrt.TEC().lookup("ROOT_PASSWORD") ks.write(kstext) ks.close() nfsdir.copyIn(kspath) xenrt.TEC().copyToLogDir(kspath, target=ksname) # tweak mboot config file origbootcfg = file("%s/%s" % (mountpoint, "boot.cfg"), "r") bootcfgpath = "%s/%s" % (workdir, "boot.cfg") bootcfg = file(bootcfgpath, "w") bootcfgtext = origbootcfg.read() bootcfgtext = re.sub(r"/", r"", bootcfgtext) # get rid of all absolute paths... bootcfgtext += "prefix=%s" % pxe.makeBootPath( "") # ... and use our PXE path as a prefix instead bootcfgtext = re.sub( r"--- useropts\.gz", r"", bootcfgtext ) # this file seems to cause only trouble, and getting rid of it seems to have no side effects... bootcfgtext = re.sub(r"--- jumpstrt\.gz", r"", bootcfgtext) # this file (in ESXi 5.5) is similar if self.esxiVersion < "5.5": deferToolsPackInstallation = False else: bootcfgtext2 = re.sub( r"--- tools.t00", r"", bootcfgtext ) # this file is too large to get over netboot from atftpd (as used in CBGLAB01), so we will install it after host-installation deferToolsPackInstallation = (bootcfgtext2 <> bootcfgtext) bootcfgtext = bootcfgtext2 bootcfgtext = re.sub( r"(kernelopt=.*)", r"\1 debugLogToSerial=1 logPort=com1 ks=%s" % ("nfs://%s%s" % (nfsdir.getHostAndPath(ksname))), bootcfgtext) bootcfg.write(bootcfgtext) bootcfg.close() origbootcfg.close() # remove the old boot.cfg (as it is read-only, it won't let you update in place) os.remove(os.path.join(pxe.path(), "boot.cfg")) pxe.copyIn(bootcfgpath) xenrt.TEC().copyToLogDir(bootcfgpath, target="bootcfg-%s.cfg" % (self.getName())) # add boot entry # NB: we are not actually booting a linux kernel pxecfg = pxe.addEntry("esx", default=1, boot="linux") pxecfg.linuxSetKernel("mboot.c32") pxecfg.linuxArgsKernelAdd("-c %s" % pxe.makeBootPath("boot.cfg")) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") # Set up PXE for installer boot pxefile = pxe.writeOut(self.machine) pfname = os.path.basename(pxefile) xenrt.TEC().copyToLogDir(pxefile, target="%s.pxe.txt" % (pfname)) # Reboot the host into the installer self.machine.powerctl.cycle() xenrt.TEC().progress("Rebooted host to start installation.") # Monitor for installation complete xenrt.waitForFile("%s/.xenrtsuccess" % (nfsdir.path()), 1800, desc="Installer boot on !%s" % (self.getName())) # Boot the local disk - we need to update this before the machine # reboots after setting the signal flag. pxe.setDefault("local") pxe.writeOut(self.machine) xenrt.sleep(30) self.waitForSSH(900, desc="Host boot (!%s)" % (self.getName())) # If we skipped tools.t00 above due to tftp issues, install it now. It's just a .tar.gz file. if deferToolsPackInstallation: xenrt.TEC().progress("Manually installing tools.t00") toolsFile = "%s/tools.t00" % (mountpoint) # Use the first-named datastore to temporarily dump the file. (Alternatively, could use /tardisks?) firstDatastore = self.getDefaultDatastore() destFilePath = "/vmfs/volumes/%s/tools.t00" % (firstDatastore) sftp = self.sftpClient() try: sftp.copyTo(toolsFile, destFilePath) finally: sftp.close() self.execdom0("tar xvfz %s -C /locker/packages" % (destFilePath)) self.execdom0("rm -f %s" % (destFilePath)) # We're done with the ISO now mount.unmount() nfsdir.remove() self.installSRType = installSRType xenrt.TEC().progress("Completed installation of ESXi host")
def run(self, arglist=None): kit = "ddk" if arglist and len(arglist) > 0: machine = arglist[0] else: raise xenrt.XRTError("No machine specified for installation") if len(arglist) < 2: raise xenrt.XRTError("No guest name specified") guestname = arglist[1] 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 for arg in arglist[2:]: l = string.split(arg, "=", 1) if l[0] == "vcpus": vcpus = int(l[1]) elif l[0] == "memory": memory = int(l[1]) elif l[0] == "uninstall": uninstall = True elif l[0] == "kit": kit = l[1] g = host.guestFactory()(\ guestname, "NO_TEMPLATE", password=xenrt.TEC().lookup("ROOT_PASSWORD_DDK")) g.host = host self.guest = g if vcpus != None: g.setVCPUs(vcpus) if memory != None: g.setMemory(memory) # Perform the import ddkzip = None ddkiso = xenrt.TEC().lookup("DDK_CD_IMAGE", None) if not ddkiso: # Try the same directory as the ISO ddkiso = xenrt.TEC().getFile("%s.iso" % (kit), "xe-phase-2/%s.iso" % (kit)) if not ddkiso: ddkzip = xenrt.TEC().getFile("%s.zip" % (kit), "xe-phase-2/%s.zip" % (kit)) if not ddkiso and not ddkzip: raise xenrt.XRTError("No DDK ISO/ZIP file given") try: if ddkiso: mount = xenrt.MountISO(ddkiso) mountpoint = mount.getMount() if ddkzip: # 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" % (ddkzip, mountpoint)) g.importVM(host, "%s/%s" % (mountpoint, kit)) finally: try: if ddkiso: mount.unmount() if ddkzip: 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 installWindows(self): # Set up the ISO mount = xenrt.mountStaticISO(self.productVersion) nfsdir = xenrt.NFSDirectory() xenrt.command("ln -sfT %s %s/iso" % (mount, nfsdir.path())) os.makedirs("%s/custom" % nfsdir.path()) shutil.copy("%s/iso/Autounattend.xml" % nfsdir.path(), "%s/custom/Autounattend.xml" % nfsdir.path()) xenrt.command( """sed -i "s#<CommandLine>.*</CommandLine>#<CommandLine>c:\\\\\\\\install\\\\\\\\runonce.cmd</CommandLine>#" %s/custom/Autounattend.xml""" % nfsdir.path()) shutil.copytree("%s/iso/$OEM$" % nfsdir.path(), "%s/custom/oem" % nfsdir.path()) xenrt.command("chmod u+w %s/custom/oem/\\$1/install" % nfsdir.path()) with open("%s/custom/oem/$1/install/runonce.cmd" % nfsdir.path(), "w") as f: f.write("%systemdrive%\install\python\python.cmd\r\n") f.write("EXIT\r\n") # First boot into winpe winpe = WinPE(self) winpe.boot() xenrt.TEC().logverbose("WinPE booted, wiping disk") # Wipe the disks and reboot winpe.xmlrpc.write_file("x:\\diskpart.txt", "list disk\nselect disk 0\nclean\nexit") winpe.xmlrpc.exec_shell("diskpart.exe /s x:\\diskpart.txt") xenrt.TEC().logverbose("Rebooting WinPE") winpe.reboot() xenrt.TEC().logverbose("WinPE rebooted, mounting shares") winpe.xmlrpc.exec_shell("net use y: %s\\iso" % nfsdir.getCIFSPath()) winpe.xmlrpc.exec_shell("net use z: %s\\custom" % nfsdir.getCIFSPath()) xenrt.TEC().logverbose("Starting installer") # Mount the install share and start the installer winpe.xmlrpc.start_shell( "y:\\setup.exe /unattend:z:\\autounattend.xml /m:z:\\oem") # Now Construct a PXE target for local boot pxe = xenrt.PXEBoot() serport = self.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.lookup("SERIAL_CONSOLE_BAUD", "115200") pxe.setSerial(serport, serbaud) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") pxe.setDefault("local") pxe.writeOut(self.machine) # Wait for Windows to be ready self.waitForDaemon(7200) try: self.xmlrpcUpdate() except: xenrt.TEC().logverbose("Warning - could not update XML/RPC daemon") if self.xmlrpcFileExists("c:\\xenrtinstalled.stamp"): raise xenrt.XRTFailure( "Installation stamp file already exists, this must be a previous installation" ) self.xmlrpcWriteFile("c:\\xenrtinstalled.stamp", "Installed") self.xmlrpcWriteFile("c:\\onboot.cmd", "echo Booted > c:\\booted.stamp") self.winRegAdd("HKLM", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" "Run", "Booted", "SZ", "c:\\onboot.cmd") self.installAdditionalNICDrivers() # Disable NLA requirement for RDP self.xmlrpcExec( """(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\\cimv2\\terminalservices -ComputerName $env:ComputerName -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0)""", powershell=True)
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 install(self): f = xenrt.TEC().getFile("/usr/groups/xenrt/oraclevm/%s/ovm.iso" % (self.productVersion)) d = xenrt.NFSDirectory() m = xenrt.MountISO(f) d.copyIn("%s/*" % m.getMount()) m.unmount() host, path = d.getHostAndPath("") pw = crypt.crypt(xenrt.TEC().lookup("ROOT_PASSWORD"), "Xa") ksd = xenrt.NFSDirectory() ks = """lang en_US #langsupport en_US eula Accepted keyboard us #mouse genericusb timezone --utc America/Los_Angeles rootpw --iscrypted %s zerombr bootloader --location=mbr install nfs --server %s --dir %s clearpart --all part /boot --fstype ext3 --size 512 --ondisk sda part swap --size 4096 --ondisk sda part / --fstype ext3 --size 1 --grow --ondisk sda network --bootproto dhcp --device eth0 ovsagent --iscrypted %s ovsmgmntif eth0 auth --useshadow --enablemd5 firewall --disabled #Do not configure the X Window System skipx text %%packages @Everything %%pre dd if=/dev/zero of=/dev/sda bs=1024 count=1024 %%post --nochroot %%post mkdir /tmp/xenrttmpmount mount -onolock -t nfs %s /tmp/xenrttmpmount touch /tmp/xenrttmpmount/.xenrtsuccess umount /tmp/xenrttmpmount """ % (pw, host, path, pw, ksd.getMountURL("")) with open("%s/ks.cfg" % ksd.path(), "w") as f: f.write(ks) pxe = xenrt.PXEBoot() pxe.addEntry("local", boot="local") serport = self.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.lookup("SERIAL_CONSOLE_BAUD", "115200") comport = str(int(serport) + 1) if self.lookup("PXE_NO_SERIAL", False, boolean=True): pxe.setSerial(None, None) else: pxe.setSerial(serport, serbaud) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") pxe.copyIn("%s/isolinux/xen.gz" % d.path()) pxe.copyIn("%s/isolinux/vmlinuz" % d.path()) pxe.copyIn("%s/isolinux/initrd.img" % d.path()) install = pxe.addEntry("ovminstall", boot="mboot") install.mbootSetKernel("%s/xen.gz" % pxe.path()) install.mbootSetModule1("%s/vmlinuz" % pxe.path()) install.mbootSetModule2("%s/initrd.img" % pxe.path()) install.mbootArgsModule1Add("ks=nfs:%sks.cfg" % ksd.getMountURL("")) install.mbootArgsModule1Add("ksdevice=eth0") install.mbootArgsModule1Add("ip=dhcp") #install.mbootArgsKernelAdd("com%s=%s,8n1" % (comport, serbaud)) #install.mbootArgsModule1Add("console=tty0") #install.mbootArgsModule1Add("console=ttyS%s,%sn8" % (serport, serbaud)) pxe.setDefault("ovminstall") pxe.writeOut(self.machine) self.machine.powerctl.cycle() xenrt.waitForFile("%s/.xenrtsuccess" % ksd.path(), 3600, desc="Installer boot on !%s" % (self.getName())) xenrt.sleep(30) pxe.setDefault("local") pxe.writeOut(self.machine) self.machine.powerctl.cycle() self.waitForSSH(1800, desc="Host boot (!%s)" % (self.getName()))