def downloadDockerMachineBinary(self): xenrt.TEC().logverbose("Download %r" % self.DOCKER_MACHINE_URL) self.command = xenrt.TEC().getFile(self.DOCKER_MACHINE_URL) try: xenrt.checkFileExists(self.command) except: raise xenrt.XRTFailure("Download %r to %r error" % (self.DOCKER_MACHINE_URL, self.command)) cmd = 'chmod +x %s' % self.command if 0 != xenrt.command(cmd, retval="code"): raise xenrt.XRTFailure("Failed to %r" % cmd) xenrt.TEC().logverbose("Download %r OK" % self.DOCKER_MACHINE_URL)
def getCD(self): # Check and lookup variables and files if not self.host.cd: imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", 'main.iso') xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) imagePath = xenrt.TEC().lookup("CD_PATH_%s" % self.host.productVersion.upper(), xenrt.TEC().lookup('CD_PATH', 'xe-phase-1')) self.host.cd = xenrt.TEC().getFile(os.path.join(imagePath, imageName), imageName) if not self.host.cd: raise xenrt.XRTError("No CD image supplied.") xenrt.checkFileExists(self.host.cd)
def prepare(self, arglist): self.host = self.getDefaultHost() # install the xen-test-framework which is a prerequisite for running tests. step("install xen-test-framework RPM and copy other pre-requisites") moduleRpm = xenrt.TEC().getFile( "/usr/groups/build/trunk-ring0/latest/binary-packages/RPMS/domain0/RPMS/x86_64/xen-test-framework-*.rpm" ) try: xenrt.checkFileExists(moduleRpm) except xenrt.XRTException, e: raise xenrt.XRTError(e.reason)
def installBorehamwoodSuppPack(self): """Installs Borehamwood Supplemental Pack""" xenrt.TEC().logverbose("Installing Borehamwood Supplemental Pack ...") # Retrieve Borehamwood Supplemental Pack bwdSuppPack = xenrt.TEC().getFile( "xe-phase-2/%s" % (self.BWD_SUPP_PACK), self.BWD_SUPP_PACK) try: xenrt.checkFileExists(bwdSuppPack) except: raise xenrt.XRTError( "Borehamwood Supplemental Pack: %s is not found in xe-phase-2" % self.BWD_SUPP_PACK) # Copy Borehamwood Supplemental Pack to Controller. hostPath = "/tmp/%s" % (self.BWD_SUPP_PACK) sh = self.host.sftpClient() try: sh.copyTo(bwdSuppPack, hostPath) finally: sh.close() # Install Borehamwood Supplemental Pack. try: self.host.execdom0("xe-install-supplemental-pack /tmp/%s" % (self.BWD_SUPP_PACK)) except: raise xenrt.XRTFailure( "Could not install Borehamwood Supplemental Pack: %s on host %s " % (self.BWD_SUPP_PACK, self.host)) # Verify Borehamwood Supplemental Pack is installed. if self.BWD_RPM_REPO not in self.host.execdom0( "ls /etc/xensource/installed-repos/"): raise xenrt.XRTFailure( "Borehamwood RPM package %s is not installed on the host %s" % (self.BWD_RPM_REPO, self.host)) # Restart Xapi xenrt.TEC().logverbose( "Restarting Xapi after installing Borehamwood Supplemental Pack ..." ) self.host.execdom0("/opt/xensource/bin/xe-toolstack-restart") self.host.waitForXapi( 900, desc= "Waiting for Xapi response after installing Borehamwood Supplemental Pack ..." )
def prepare(self, arglist): self.host = self.getDefaultHost() # Install test modules from build output step("Install test-ring0-modules RPM") modules_path = "/tmp/test-ring0-modules.rpm" modules_rpm = xenrt.TEC().getFile("binary-packages/RPMS/domain0/RPMS/x86_64/test-ring0-modules-*.rpm") try: xenrt.checkFileExists(modules_rpm) except: raise xenrt.XRTError("test-ring0-modules rpm file is not present in the build") sh = self.host.sftpClient() try: sh.copyTo(modules_rpm, modules_path) finally: sh.close() self.host.execdom0("rpm --force -Uvh %s" % (modules_path))
def installBorehamwoodSuppPack(self): """Installs Borehamwood Supplemental Pack""" xenrt.TEC().logverbose("Installing Borehamwood Supplemental Pack ...") # Retrieve Borehamwood Supplemental Pack bwdSuppPack = xenrt.TEC().getFile("xe-phase-2/%s" % (self.BWD_SUPP_PACK), self.BWD_SUPP_PACK) try: xenrt.checkFileExists(bwdSuppPack) except: raise xenrt.XRTError("Borehamwood Supplemental Pack: %s is not found in xe-phase-2" % self.BWD_SUPP_PACK) # Copy Borehamwood Supplemental Pack to Controller. hostPath = "/tmp/%s" % (self.BWD_SUPP_PACK) sh = self.host.sftpClient() try: sh.copyTo(bwdSuppPack, hostPath) finally: sh.close() # Install Borehamwood Supplemental Pack. try: self.host.execdom0("xe-install-supplemental-pack /tmp/%s" % (self.BWD_SUPP_PACK)) except: raise xenrt.XRTFailure( "Could not install Borehamwood Supplemental Pack: %s on host %s " % (self.BWD_SUPP_PACK, self.host) ) # Verify Borehamwood Supplemental Pack is installed. if self.BWD_RPM_REPO not in self.host.execdom0("ls /etc/xensource/installed-repos/"): raise xenrt.XRTFailure( "Borehamwood RPM package %s is not installed on the host %s" % (self.BWD_RPM_REPO, self.host) ) # Restart Xapi xenrt.TEC().logverbose("Restarting Xapi after installing Borehamwood Supplemental Pack ...") self.host.execdom0("/opt/xensource/bin/xe-toolstack-restart") self.host.waitForXapi(900, desc="Waiting for Xapi response after installing Borehamwood Supplemental Pack ...")
def prepare(self, arglist): self.host = self.getDefaultHost() # Install test modules from build output step("Install test-ring0-modules RPM") modules_path = "/tmp/test-ring0-modules.rpm" modules_rpm = xenrt.TEC().getFile( "binary-packages/RPMS/domain0/RPMS/x86_64/test-ring0-modules-*.rpm" ) try: xenrt.checkFileExists(modules_rpm) except: raise xenrt.XRTError( "test-ring0-modules rpm file is not present in the build") sh = self.host.sftpClient() try: sh.copyTo(modules_rpm, modules_path) finally: sh.close() self.host.execdom0("rpm --force -Uvh %s" % (modules_path))
def prepare(self, arglist): tar_ball = xenrt.TEC().getFile(self.TAR, self.TAR2) if tar_ball is None: raise xenrt.XRTError("Couldn't find %s in build output" % (self.TAR)) self.temp_dir = xenrt.TEC().tempDir() xenrt.command("tar -C %s -xvf %s" % (self.temp_dir, tar_ball)) self.output = "%s/%s" % (self.temp_dir, self.OUTPUT_ZIP) imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", "main.iso") xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) cd = xenrt.TEC().getFile("xe-phase-1/%s" % (imageName), imageName) if not cd: raise xenrt.XRTError("No main CD image supplied.") xenrt.checkFileExists(cd) self.maincd = cd cd = None cd = xenrt.TEC().getFile("linux.iso", "xe-phase-1/linux.iso") if not cd: raise xenrt.XRTError("No linux CD image supplied.") xenrt.checkFileExists(cd) self.linuxcd = cd
def prepare(self, arglist): tar_ball = xenrt.TEC().getFile(self.TAR, self.TAR2) if tar_ball is None: raise xenrt.XRTError("Couldn't find %s in build output" % (self.TAR)) self.temp_dir = xenrt.TEC().tempDir() xenrt.command("tar -C %s -xvf %s" % (self.temp_dir, tar_ball)) self.output = "%s/%s" % (self.temp_dir, self.OUTPUT_ZIP) imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", 'main.iso') xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) cd = xenrt.TEC().getFile("xe-phase-1/%s" % (imageName), imageName) if not cd: raise xenrt.XRTError("No main CD image supplied.") xenrt.checkFileExists(cd) self.maincd = cd cd = None cd = xenrt.TEC().getFile("linux.iso", "xe-phase-1/linux.iso") if not cd: raise xenrt.XRTError("No linux CD image supplied.") xenrt.checkFileExists(cd) self.linuxcd = cd
def run(self, arglist=[]): """Do testing tasks in run""" # Read/initialize variables. args = xenrt.util.strlistToDict(arglist) iterations = args.get("iterations") or "0" logperiteration = args.get("logperiteration") or "1000" timeout = args.get("timeout") or "180" timeout = int(timeout) seed = args.get("seed") or "%x" % random.randint(0, 0xffffffff) modifier = xenrt.TEC().lookup("timeout", None) if modifier and modifier > 0: timeout = int(modifier) log("Using timeout from given submit command.") modifier = xenrt.TEC().lookup("seed", None) if modifier and modifier != "": seed = modifier log("Using seed from given submit command.") log("Create an empty guest with Windows 7 template") name = xenrt.randomGuestName() template = xenrt.lib.xenserver.getTemplate(self.host, "win7sp1") guest = self.host.guestFactory()(name, template, self.host) guest.setVCPUs(2) guest.setMemory(2048) guest.createGuestFromTemplate(template, None) log("Assign VGPU to the guest.") # Get a VGPU type vgputypes = self.host.minimalList("vgpu-type-list") vgputype = None for type in vgputypes: if self.host.genParamGet("vgpu-type", type, "model-name") != "passthrough": vgputype = type break if not vgputype: raise xenrt.XRTError("Cannot find relavant VGPU type.") log("VGPU type: %s" + vgputype) # Get a GPU Group. groups = self.host.minimalList("gpu-group-list") group = None for g in groups: if vgputype in self.host.genParamGet("gpu-group", g, "enabled-VGPU-types"): group = g break if not group: raise xenrt.XRTError("Cannot find a proper GPU group.") # Assign VGPU to the guest. cli = self.host.getCLIInstance() cli.execute("vgpu-create gpu-group-uuid=%s vgpu-type-uuid=%s vm-uuid=%s" % (group, vgputype, guest.getUUID())) log("Prepare Fuzzer") #Fetch File url = xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP", "") + "/demufuzzer/demufuzzer-v1" remotepath = xenrt.TEC().getFile(url) try: xenrt.checkFileExists(remotepath) except: raise xenrt.XRTError("Failed to find demu fuzzer.") localpath = "/tmp/demufuzzer" sh = self.host.sftpClient() try: sh.copyTo(remotepath, localpath) finally: sh.close() # Replace HVM Loader with DEMU fuzzer. ret = self.host.execdom0("mv /usr/lib/xen/boot/hvmloader /usr/lib/xen/boot/hvmloader_orig") ret = self.host.execdom0("mv /tmp/demufuzzer /usr/lib/xen/boot/hvmloader") log("Setting up test variables.") log("iterations: %s" % iterations) log("log per iterations: %s" % logperiteration) log("Timeout: %d mins" % timeout) self.host.xenstoreWrite("demufuzzer/iterations", iterations) # 0 (infinity) is default. self.host.xenstoreWrite("demufuzzer/logperiteration", logperiteration) # 1000 is default. #self.host.xenstoreWrite("demufuzzer/logtoqemu", "1") # 1 is default. log("Start fuzzer!") self.startFuzzing(guest, seed) # capture DMESG self.host.execdom0("xl dmesg -c > /tmp/dmesg") self.host.addExtraLogFile("/tmp/dmesg") log("Wait for given time (%d mins) or until find a new issue" % timeout) targettime = xenrt.util.timenow() + timeout * 60 while (xenrt.util.timenow() < targettime): self.host.execdom0("xl dmesg -c >> /tmp/dmesg") if not self.isDEMUAlive(): log("DEMU is crashed.") try: self.host.checkHealth() except xenrt.XRTException as e: log("%s: %s happend." % (e, e.data)) raise xenrt.XRTFailure("Host is unhealty.") # If it is not a host crash, it is not security issue. Restarting. self.stopFuzzing(guest) self.startFuzzing(guest) else: xenrt.sleep(30) log("DEMU fuzzer ran for %d mins without Dom0 crash." % timeout)
def run(self, arglist): xenrt.command( "sudo %s/build-fi-image.sh -o %s %s %s %s" % (self.temp_dir, self.output, self.maincd, self.linuxcd, " ".join(self.spcds)) ) xenrt.checkFileExists(self.output, level=xenrt.RC_FAIL)
def __init__(self, machine, username="******", password=None, cd=None, cached=False): self.username = username if password: self.password = password elif machine.host: self.password = machine.host.password else: self.password = None self.machine = machine self.cached = cached self.dir = None self.tempDir = None self.winguest = None self.debug_on_fail = False if not self.password: self.password = xenrt.TEC().lookup("ROOT_PASSWORD") if xenrt.TEC().registry.read("/xenrt/cli/windows"): self.winguest = xenrt.TEC().registry.read(\ "/xenrt/cli/windows_guest") if not self.winguest: raise xenrt.XRTError("Could not find guest in registry.") # Install xe.exe self.winguest.installCarbonWindowsCLI() else: if xenrt.command("which xe", retval="code") == 0 and not xenrt.TEC().lookup("OPTION_USE_XE_FROM_XS", False, boolean=True): # Use the version in the distro self.dir = os.path.dirname(xenrt.command("which xe")) else: self.tempDir = xenrt.TempDirectory() self.dir = self.tempDir.path() mount = None # Places we'll look for the CLI binary. cds = [] if cd: cds.append(cd) else: imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", 'main.iso') xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) try: cd = xenrt.TEC().getFile("xe-phase-1/%s" % (imageName), imageName) if cd: cds.append(cd) except: pass if machine.host: ecds = machine.host.getDefaultAdditionalCDList() if ecds: for ecd in string.split(ecds, ","): if os.path.exists(ecd): cds.append(ecd) else: try: cd = xenrt.TEC().getFile("xe-phase-1/%s" % (os.path.basename(ecd)), os.path.basename(ecd)) if cd: cds.append(cd) except: pass else: try: cd = xenrt.TEC().getFile("xe-phase-1/linux.iso", "linux.iso") if cd: cds.append(cd) except: pass # Get a CLI binary from the CD. rpm = None localarch = xenrt.command("uname -m").strip() remotearch = machine.getHost().execdom0("uname -m").strip() if remotearch == "x86_64" and localarch != "x86_64": xenrt.TEC().logverbose("Using local CLI binary") rpm = "%s/tests/xe/xe-cli.i686.rpm" % xenrt.TEC().lookup("XENRT_BASE") else: for cd in cds: xenrt.checkFileExists(cd) mount = xenrt.MountISO(cd) mountpoint = mount.getMount() fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) if len(fl) != 0: xenrt.TEC().logverbose("Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break if localarch == "x86_64": fl = glob.glob("%s/client_install/xe-cli-[0-9]*x86_64.rpm" % (mountpoint)) else: fl = glob.glob("%s/client_install/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) fl.extend(glob.glob("%s/client_install/xenenterprise-cli-[0-9]*i?86.rpm" % (mountpoint))) if len(fl) != 0: xenrt.TEC().logverbose("Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break mount.unmount() mount = None # Try a client_install subdir next to the main ISO. if not rpm: if len(cds) > 0: cd = cds[0] p = "%s/client_install" % (os.path.dirname(cd)) if os.path.exists(p): fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (p)) if len(fl) != 0: xenrt.TEC().logverbose("Using CLI binary from " "split directory") rpm = fl[-1] if not rpm: # Fallback is to copy the binary from the dom0. h = machine.getHost() if not h: raise xenrt.XRTError("No host associate with %s, " "cannot get CLI" % (machine.name)) xenrt.TEC().logverbose("Copying CLI binary from host") sftp = h.sftpClient() sftp.copyFrom("/opt/xensource/bin/xe", "%s/xe" % (self.tempDir.path())) sftp.close() else: xenrt.TEC().logverbose("Using CLI RPM %s" % (os.path.basename(rpm))) if xenrt.command("cd %s && rpm2cpio %s | cpio -idv" % (self.tempDir.path(), rpm), retval="code") != 0: raise xenrt.XRTError("Error extracting CLI binary from %s" % (rpm)) if xenrt.command("mv %s/opt/xensource/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") == 0: pass elif xenrt.command("mv %s/usr/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") != 0: raise xenrt.XRTError("Couldn't find xe in RPM") xenrt.TEC().logverbose("Test whether xe supports --debug-on-fail") if mount: mount.unmount() if xenrt.command("%s/xe --debug-on-fail" % self.dir, retval="code", level=xenrt.RC_OK) == 0: self.debug_on_fail = True xenrt.TEC().logverbose("xe supports --debug-on-fail, now available " "for use in any cli calls.") else: xenrt.TEC().logverbose("xe doesn't support --debug-on-fail")
def run(self, arglist=[]): """Do testing tasks in run""" # Read/initialize variables. args = xenrt.util.strlistToDict(arglist) iterations = args.get("iterations") or "0" logperiteration = args.get("logperiteration") or "1000" timeout = args.get("timeout") or "180" timeout = int(timeout) seed = args.get("seed") or "%x" % random.randint(0, 0xffffffff) modifier = xenrt.TEC().lookup("timeout", None) if modifier and modifier > 0: timeout = int(modifier) log("Using timeout from given submit command.") modifier = xenrt.TEC().lookup("seed", None) if modifier and modifier != "": seed = modifier log("Using seed from given submit command.") log("Create an empty guest with Windows 7 template") name = xenrt.randomGuestName() template = xenrt.lib.xenserver.getTemplate(self.host, "win7sp1") guest = self.host.guestFactory()(name, template, self.host) guest.setVCPUs(2) guest.setMemory(2048) guest.createGuestFromTemplate(template, None) log("Assign VGPU to the guest.") # Get a VGPU type vgputypes = self.host.minimalList("vgpu-type-list") vgputype = None for type in vgputypes: if self.host.genParamGet("vgpu-type", type, "model-name") != "passthrough": vgputype = type break if not vgputype: raise xenrt.XRTError("Cannot find relavant VGPU type.") log("VGPU type: %s" + vgputype) # Get a GPU Group. groups = self.host.minimalList("gpu-group-list") group = None for g in groups: if vgputype in self.host.genParamGet("gpu-group", g, "enabled-VGPU-types"): group = g break if not group: raise xenrt.XRTError("Cannot find a proper GPU group.") # Assign VGPU to the guest. cli = self.host.getCLIInstance() cli.execute( "vgpu-create gpu-group-uuid=%s vgpu-type-uuid=%s vm-uuid=%s" % (group, vgputype, guest.getUUID())) log("Prepare Fuzzer") #Fetch File url = xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP", "") + "/demufuzzer/demufuzzer-v1" remotepath = xenrt.TEC().getFile(url) try: xenrt.checkFileExists(remotepath) except: raise xenrt.XRTError("Failed to find demu fuzzer.") localpath = "/tmp/demufuzzer" sh = self.host.sftpClient() try: sh.copyTo(remotepath, localpath) finally: sh.close() # Replace HVM Loader with DEMU fuzzer. ret = self.host.execdom0( "mv /usr/lib/xen/boot/hvmloader /usr/lib/xen/boot/hvmloader_orig") ret = self.host.execdom0( "mv /tmp/demufuzzer /usr/lib/xen/boot/hvmloader") log("Setting up test variables.") log("iterations: %s" % iterations) log("log per iterations: %s" % logperiteration) log("Timeout: %d mins" % timeout) self.host.xenstoreWrite("demufuzzer/iterations", iterations) # 0 (infinity) is default. self.host.xenstoreWrite("demufuzzer/logperiteration", logperiteration) # 1000 is default. #self.host.xenstoreWrite("demufuzzer/logtoqemu", "1") # 1 is default. log("Start fuzzer!") self.startFuzzing(guest, seed) # capture DMESG self.host.execdom0("xl dmesg -c > /tmp/dmesg") self.host.addExtraLogFile("/tmp/dmesg") log("Wait for given time (%d mins) or until find a new issue" % timeout) targettime = xenrt.util.timenow() + timeout * 60 while (xenrt.util.timenow() < targettime): self.host.execdom0("xl dmesg -c >> /tmp/dmesg") if not self.isDEMUAlive(): log("DEMU is crashed.") try: self.host.checkHealth() except xenrt.XRTException as e: log("%s: %s happend." % (e, e.data)) raise xenrt.XRTFailure("Host is unhealty.") # If it is not a host crash, it is not security issue. Restarting. self.stopFuzzing(guest) self.startFuzzing(guest) else: xenrt.sleep(30) log("DEMU fuzzer ran for %d mins without Dom0 crash." % timeout)
def run(self, arglist): xenrt.command("sudo %s/build-fi-image.sh -o %s %s %s %s" % (self.temp_dir, self.output, self.maincd, self.linuxcd, " ".join(self.spcds))) xenrt.checkFileExists(self.output, level=xenrt.RC_FAIL)
def installXSStorageCertKit(self,host): """Installs the storage XenCert Kit""" rpmInstalled = False xenrt.TEC().logverbose("Checking whether XenServer Storage Cert Kit RPMs are installed or not") for rpm in self.XENCERT_RPMS: rpmCheck = self.checkXSStorageCertKitRPMS(host,rpm) if not rpmCheck: rpmInstalled = True break reposFound = False xenrt.TEC().logverbose("Checking whether XenServer Storage Cert Kit REPOs are found or not") for rpmRepo in self.XENCERT_RPM_REPOS: rpmRepoCheck = self.checkInstalledXSStorageCertKitRepos(host,rpmRepo) if not rpmRepoCheck: reposFound = True break if (rpmInstalled == False and reposFound == False): xenrt.TEC().logverbose("XenServer Storage Cert Kit is already installed in the host.") return updatedXenCertLoc = xenrt.TEC().lookup("XENCERT_LOCATION", None) if updatedXenCertLoc != None and len(updatedXenCertLoc) > 0: storageCertKitISO = xenrt.TEC().getFile(updatedXenCertLoc) else: storageCertKitISO = xenrt.TEC().getFile("xe-phase-2/%s" % (self.XENCERT_ISO),self.XENCERT_ISO, "../xe-phase-2/%s" % (self.XENCERT_ISO)) try: xenrt.checkFileExists(storageCertKitISO) except: raise xenrt.XRTError("XenServer Storage Cert Kit ISO not found in xe-phase-2") hostPath = "/tmp/%s" % (self.XENCERT_ISO) # Copy ISO from the controller to host in test sh = host.sftpClient() try: sh.copyTo(storageCertKitISO,hostPath) finally: sh.close() try: host.execdom0("xe-install-supplemental-pack /tmp/%s" % (self.XENCERT_ISO)) except: xenrt.TEC().logverbose("Unable to install XenServer Storage Cert Kit") ignoreVersion = xenrt.TEC().lookup("IGNORE_XENCERT_VERSION", None) if ignoreVersion != None: xenrt.TEC().logverbose("XenCert version check purposely ignored") else: for rpm in self.XENCERT_RPMS: rpmInstalled = self.checkXSStorageCertKitRPMS(host,rpm) if not rpmInstalled: raise xenrt.XRTFailure("XenServer Storage Cert Kit RPM package " "%s is not installed" % (rpm)) for rpmRepo in self.XENCERT_RPM_REPOS: rpmReposInstalled = self.checkInstalledXSStorageCertKitRepos(host,rpmRepo) if not rpmReposInstalled: raise xenrt.XRTFailure("XenServer Storage Cert Kit entries " "not found under installed-repos: %s" % (rpm))
def installXSAutoCertKit(self, host): rpmInstalled = False xenrt.TEC().logverbose( "Checking whether XenServer Auto Cert Kit RPMs are installed or not" ) for rpm in self.rpms: rpmCheck = self.checkXSAutoCertKitRPMS(host, rpm) if not rpmCheck: rpmInstalled = True break reposFound = False xenrt.TEC().logverbose( "Checking whether XenServer Auto Cert Kit REPOs are found or not") for rpmRepo in self.rpmRepos: rpmRepoCheck = self.checkInstalledXSAutoCertKitRepos(host, rpmRepo) if not rpmRepoCheck: reposFound = True break if (rpmInstalled == False and reposFound == False): xenrt.TEC().logverbose( "XenServer Auto Cert Kit is already installed in the host.") return acklocation = xenrt.TEC().lookup("ACK_LOCATION", None) if not acklocation: if isinstance(host, xenrt.lib.xenserver.DundeeHost): branch = "trunk-autocertkit" elif "x86_64" in host.execdom0("uname -a"): branch = "creedence-autocertkit" else: branch = "clearwater-sp1-lcm-autocertkit" build = xenrt.util.getHTTP( "https://xenbuilder.uk.xensource.com/search?query=latest&format=number&product=carbon&branch=%s&site=cam&job=sdk&action=xe-phase-2-build&status=succeeded" % (branch, )).strip() acklocation = "/usr/groups/xen/carbon/%s/%s/xe-phase-2/xs-auto-cert-kit.iso" % ( branch, build) autoCertKitISO = xenrt.TEC().getFile(acklocation) try: xenrt.checkFileExists(autoCertKitISO) except: raise xenrt.XRTError( "XenServer Auto Cert Kit ISO not found in xe-phase-2") hostPath = "/tmp/%s" % (self.pack) # Copy ISO from the controller to host in test sh = host.sftpClient() try: sh.copyTo(autoCertKitISO, hostPath) finally: sh.close() try: host.execdom0("xe-install-supplemental-pack /tmp/%s" % (self.pack)) except: xenrt.TEC().logverbose("Unable to install XenServer Auto Cert Kit") for rpm in self.rpms: rpmInstalled = self.checkXSAutoCertKitRPMS(host, rpm) if not rpmInstalled: raise xenrt.XRTFailure( "XenServer Auto Cert Kit RPM package %s is not installed" % (rpm)) for rpmRepo in self.rpmRepos: rpmReposInstalled = self.checkInstalledXSAutoCertKitRepos( host, rpmRepo) if not rpmReposInstalled: raise xenrt.XRTFailure( "XenServer Auto Cert Kit entries not found under installed-repos: %s" % (rpm))
def installXSAutoCertKit(self, host): rpmInstalled = False xenrt.TEC().logverbose("Checking whether XenServer Auto Cert Kit RPMs are installed or not") for rpm in self.rpms: rpmCheck = self.checkXSAutoCertKitRPMS(host, rpm) if not rpmCheck: rpmInstalled = True break reposFound = False xenrt.TEC().logverbose("Checking whether XenServer Auto Cert Kit REPOs are found or not") for rpmRepo in self.rpmRepos: rpmRepoCheck = self.checkInstalledXSAutoCertKitRepos(host, rpmRepo) if not rpmRepoCheck: reposFound = True break if rpmInstalled == False and reposFound == False: xenrt.TEC().logverbose("XenServer Auto Cert Kit is already installed in the host.") return acklocation = xenrt.TEC().lookup("ACK_LOCATION", None) if not acklocation: if isinstance(host, xenrt.lib.xenserver.DundeeHost): branch = "trunk-autocertkit" elif "x86_64" in host.execdom0("uname -a"): branch = "creedence-autocertkit" else: branch = "clearwater-sp1-lcm-autocertkit" build = xenrt.util.getHTTP( "https://xenbuilder.uk.xensource.com/search?query=latest&format=number&product=carbon&branch=%s&site=cam&job=sdk&action=xe-phase-2-build&status=succeeded" % (branch,) ).strip() acklocation = "/usr/groups/xen/carbon/%s/%s/xe-phase-2/xs-auto-cert-kit.iso" % (branch, build) autoCertKitISO = xenrt.TEC().getFile(acklocation) try: xenrt.checkFileExists(autoCertKitISO) except: raise xenrt.XRTError("XenServer Auto Cert Kit ISO not found in xe-phase-2") hostPath = "/tmp/%s" % (self.pack) # Copy ISO from the controller to host in test sh = host.sftpClient() try: sh.copyTo(autoCertKitISO, hostPath) finally: sh.close() try: host.execdom0("xe-install-supplemental-pack /tmp/%s" % (self.pack)) except: xenrt.TEC().logverbose("Unable to install XenServer Auto Cert Kit") for rpm in self.rpms: rpmInstalled = self.checkXSAutoCertKitRPMS(host, rpm) if not rpmInstalled: raise xenrt.XRTFailure("XenServer Auto Cert Kit RPM package %s is not installed" % (rpm)) for rpmRepo in self.rpmRepos: rpmReposInstalled = self.checkInstalledXSAutoCertKitRepos(host, rpmRepo) if not rpmReposInstalled: raise xenrt.XRTFailure("XenServer Auto Cert Kit entries not found under installed-repos: %s" % (rpm))
def __init__(self, machine, username="******", password=None, cd=None, cached=False): self.username = username if password: self.password = password elif machine.host: self.password = machine.host.password else: self.password = None self.machine = machine self.cached = cached self.dir = None self.tempDir = None self.winguest = None self.debug_on_fail = False if not self.password: self.password = xenrt.TEC().lookup("ROOT_PASSWORD") if xenrt.TEC().registry.read("/xenrt/cli/windows"): self.winguest = xenrt.TEC().registry.read(\ "/xenrt/cli/windows_guest") if not self.winguest: raise xenrt.XRTError("Could not find guest in registry.") # Install xe.exe self.winguest.installCarbonWindowsCLI() else: if xenrt.command("which xe", retval="code") == 0 and not xenrt.TEC().lookup( "OPTION_USE_XE_FROM_XS", False, boolean=True): # Use the version in the distro self.dir = os.path.dirname(xenrt.command("which xe")) else: self.tempDir = xenrt.TempDirectory() self.dir = self.tempDir.path() mount = None # Places we'll look for the CLI binary. cds = [] if cd: cds.append(cd) else: imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", 'main.iso') xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) try: cd = xenrt.TEC().getFile("xe-phase-1/%s" % (imageName), imageName) if cd: cds.append(cd) except: pass if machine.host: ecds = machine.host.getDefaultAdditionalCDList() if ecds: for ecd in string.split(ecds, ","): if os.path.exists(ecd): cds.append(ecd) else: try: cd = xenrt.TEC().getFile( "xe-phase-1/%s" % (os.path.basename(ecd)), os.path.basename(ecd)) if cd: cds.append(cd) except: pass else: try: cd = xenrt.TEC().getFile("xe-phase-1/linux.iso", "linux.iso") if cd: cds.append(cd) except: pass # Get a CLI binary from the CD. rpm = None localarch = xenrt.command("uname -m").strip() remotearch = machine.getHost().execdom0("uname -m").strip() if remotearch == "x86_64" and localarch != "x86_64": xenrt.TEC().logverbose("Using local CLI binary") rpm = "%s/tests/xe/xe-cli.i686.rpm" % xenrt.TEC().lookup( "XENRT_BASE") else: for cd in cds: xenrt.checkFileExists(cd) mount = xenrt.MountISO(cd) mountpoint = mount.getMount() fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break if localarch == "x86_64": fl = glob.glob( "%s/client_install/xe-cli-[0-9]*x86_64.rpm" % (mountpoint)) else: fl = glob.glob( "%s/client_install/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) fl.extend( glob.glob( "%s/client_install/xenenterprise-cli-[0-9]*i?86.rpm" % (mountpoint))) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break mount.unmount() mount = None # Try a client_install subdir next to the main ISO. if not rpm: if len(cds) > 0: cd = cds[0] p = "%s/client_install" % (os.path.dirname(cd)) if os.path.exists(p): fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (p)) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from " "split directory") rpm = fl[-1] if not rpm: # Fallback is to copy the binary from the dom0. h = machine.getHost() if not h: raise xenrt.XRTError("No host associate with %s, " "cannot get CLI" % (machine.name)) xenrt.TEC().logverbose("Copying CLI binary from host") sftp = h.sftpClient() sftp.copyFrom("/opt/xensource/bin/xe", "%s/xe" % (self.tempDir.path())) sftp.close() else: xenrt.TEC().logverbose("Using CLI RPM %s" % (os.path.basename(rpm))) if xenrt.command("cd %s && rpm2cpio %s | cpio -idv" % (self.tempDir.path(), rpm), retval="code") != 0: raise xenrt.XRTError( "Error extracting CLI binary from %s" % (rpm)) if xenrt.command( "mv %s/opt/xensource/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") == 0: pass elif xenrt.command( "mv %s/usr/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") != 0: raise xenrt.XRTError("Couldn't find xe in RPM") xenrt.TEC().logverbose( "Test whether xe supports --debug-on-fail") if mount: mount.unmount() if xenrt.command("%s/xe --debug-on-fail" % self.dir, retval="code", level=xenrt.RC_OK) == 0: self.debug_on_fail = True xenrt.TEC().logverbose( "xe supports --debug-on-fail, now available " "for use in any cli calls.") else: xenrt.TEC().logverbose("xe doesn't support --debug-on-fail")