コード例 #1
0
ファイル: agent.py プロジェクト: thomassa/xenrt
    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")
コード例 #2
0
    def installCloudAgent(self, msi):
        ad = xenrt.getADConfig()

        if msi.endswith(".msi"):
            self.xmlrpcSendFile(msi, "c:\\hypervagent.msi")
            self.xmlrpcExec(
                "msiexec /i c:\\hypervagent.msi /quiet /qn /norestart /log c:\\cloudagent-install.log SERVICE_USERNAME=%s\\%s SERVICE_PASSWORD=%s"
                % (ad.domainName, ad.adminUser, ad.adminPassword))
        elif msi.endswith(".zip"):
            tempDir = xenrt.TEC().tempDir()
            xenrt.command("unzip %s -d %s" % (msi, tempDir))
            self.xmlrpcCreateDir("c:\\cshyperv")
            self.xmlrpcSendRecursive(tempDir, "c:\\cshyperv")
            self.xmlrpcExec(
                "c:\\cshyperv\\AgentShell.exe --install -u %s\\%s -p %s" %
                (ad.domainName, ad.adminUser, ad.adminPassword))
            data = self.hypervCmd(
                "New-SelfSignedCertificate -DnsName apachecloudstack -CertStoreLocation Cert:\\LocalMachine\\My | Format-Wide -Property Thumbprint -autosize"
            ).strip()
            thumbprint = data.splitlines()[-1]
            self.xmlrpcExec(
                "netsh http add sslcert ipport=0.0.0.0:8250 certhash=%s appid=\"{727beb1c-6e7c-49b2-8fbd-f03dbe481b08}\""
                % thumbprint)
        else:
            raise xenrt.XRTError("Unknown cloud agent file %s" %
                                 os.path.basename(msi))
コード例 #3
0
ファイル: vcenter.py プロジェクト: thomassa/xenrt
    def _installVCenter(self):
        isoUrl = xenrt.TEC().lookup(
            ["VCENTER", "ISO",
             "_%s" % self.vCenterVersion.upper()])
        isoName = isoUrl.rsplit("/", 1)[1]
        if isoName not in self.guest.host.findISOs():
            srPath = None
            isoPath = xenrt.TEC().getFile(isoUrl)
            isoPath = xenrt.command("readlink -f %s" % isoPath).strip()
            if xenrt.command("stat --file-system --format=%%T %s" %
                             isoPath).strip() == "nfs":
                nfsMountInfo = xenrt.command(
                    "df %s" % isoPath).strip().split("\n")[-1].split(" ")
                # nfsMountInfo will look like ['10.220.254.45:/vol/xenrtdata/cache', '2147483648', '1678503168', '468980480', '', '79%', '/misc/cache_nfs']
                srPath = isoPath.rsplit("/",
                                        1)[0].replace(nfsMountInfo[-1],
                                                      nfsMountInfo[0])
            else:
                ip = xenrt.command(
                    "/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}'"
                ).strip()
                srPath = ip + ":" + isoPath.rsplit("/", 1)[0]
            self.guest.host.createISOSR(srPath)

        self.guest.changeCD(isoName)
        xenrt.sleep(30)

        if "ws12" in self.guest.distro and "5.5" in self.vCenterVersion:
            self._installVCenter55onWs12()
        else:
            raise xenrt.XRTError("Unimplemented")
        self.guest.changeCD(None)

        self._installpowerCLI()
コード例 #4
0
ファイル: tools.py プロジェクト: johnmdilley/xenrt
def generateLabCostPerTechArea(suiteId, outputDir=None, clearOutputDirContent=False):
    if outputDir and xenrt.TEC().lookup("GENERATE_STATS_BASEDIR").rstrip("/") not in outputDir:
        # this part will ensure we only modify dir falling under base dir for stats. 
        raise xenrt.XRTError("permission denied [ dir not under base stat dir] '%s'" % outputDir)
    if clearOutputDirContent and outputDir:
        shutil.rmtree("%s" % outputDir.rstrip("/"))
    elif suiteId:
        if outputDir:
            outputDir=outputDir.rstrip("/")
            if os.path.exists("%s/%s.generating" % (outputDir,suiteId)):
                raise xenrt.XRTError("Another process is already generating data")
            else:
                if not os.path.exists(outputDir):
                    os.makedirs(outputDir)
                with open("%s/%s.generating" % (outputDir,suiteId), "w") as f:
                    f.write(str(xenrt.GEC().jobid()) or "nojob")
        try:
            cls = xenrt.generatestats.LabCostPerTechArea(suiteId, nbrOfSuiteRunsToCheck=10)
            data, tcMissingData = cls.generate()
            tempDir = xenrt.TEC().tempDir()
            with open("%s/%s.json" % (tempDir,suiteId), "w") as f:
                f.write(json.dumps(data, indent=2))
            with open("%s/%s_tcs_missing_run_history.json" % (tempDir,suiteId), "w") as f:
                f.write(json.dumps(tcMissingData, indent=2))
            if outputDir:
                xenrt.command("cp -f -r %s/* %s" % (tempDir,outputDir))
            print "Data saved in directory '%s'" % (outputDir if outputDir else tempDir)
        except Exception, e:
            errorLogDir = "%s/logs" % outputDir
            if not os.path.exists(errorLogDir):
                os.makedirs(errorLogDir)
            with open("%s/%s.error" % (errorLogDir,suiteId), "w") as f:
                f.write("[%s] %s" % (str(xenrt.GEC().jobid()) or "nojob", e))
        finally:
コード例 #5
0
ファイル: sles.py プロジェクト: thomassa/xenrt
    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))
コード例 #6
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
class TC10663(xenrt.TestCase):
    """Download the XenCenter msi file from the host"""
    def run(self, arglist=None):
        host = self.getDefaultHost()
        url = "http://%s/" % (host.getIP())
        localtemp = xenrt.TEC().tempFile()

        # Check whether XenCenter.msi or XenCenterSetup.exe exists
        try:
            xenrt.command("curl '%s' -o %s" % (url, localtemp))
        except Exception, e:
            raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                   str(e))

        page = xenrt.command("cat %s" % (localtemp))

        m = re.search(
            "<body>.*<a href=\"(XenCenter.msi|XenCenterSetup.exe)\">", page,
            re.DOTALL)
        if m:
            url = "http://%s/%s" % (host.getIP(), m.group(1))
        else:
            xenrt.XRTFailure(
                "Unable to retrieve XenCenter.msi or XenCenterSetup.exe files")

        temp = xenrt.TEC().tempFile()
        try:
            page = xenrt.command("curl '%s' -o %s" % (url, temp))
        except Exception, e:
            raise xenrt.XRTFailure(
                "Unable to download XenCenter msi file from "
                "the host", str(e))
コード例 #7
0
ファイル: rhel.py プロジェクト: thomassa/xenrt
    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))
コード例 #8
0
ファイル: vcenter.py プロジェクト: johnmdilley/xenrt
    def _installVCenter(self):
        isoUrl=xenrt.TEC().lookup(["VCENTER","ISO","_%s" % self.vCenterVersion.upper()])
        isoName = isoUrl.rsplit("/",1)[1]
        if isoName not in self.guest.host.findISOs():
            srPath = None
            isoPath=xenrt.TEC().getFile(isoUrl)
            isoPath = xenrt.command("readlink -f %s" % isoPath).strip()
            if xenrt.command("stat --file-system --format=%%T %s" % isoPath).strip()=="nfs":
                nfsMountInfo=xenrt.command("df %s" % isoPath).strip().split("\n")[-1].split(" ")
                # nfsMountInfo will look like ['10.220.254.45:/vol/xenrtdata/cache', '2147483648', '1678503168', '468980480', '', '79%', '/misc/cache_nfs']
                srPath=isoPath.rsplit("/",1)[0].replace(nfsMountInfo[-1], nfsMountInfo[0])
            else:
                ip=xenrt.command("/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}'" ).strip()
                srPath=ip+":"+isoPath.rsplit("/",1)[0]
            self.guest.host.createISOSR(srPath)

        self.guest.changeCD(isoName)
        xenrt.sleep(30)

        if "ws12" in self.guest.distro and "5.5" in self.vCenterVersion:
            self._installVCenter55onWs12()
        else:
            raise xenrt.XRTError("Unimplemented")
        self.guest.changeCD(None)

        self._installpowerCLI()
コード例 #9
0
ファイル: regression.py プロジェクト: thomassa/xenrt
    def run(self, arglist=[]):

        # Upload from localhost
        cmd = self.gencmd(self.vdi_img_host, "localhost")
        timeout = self.VDISIZE / xenrt.MEGA
        xenrt.TEC().progress(
            "Start to upload the image from local host and verify")
        try:
            self.runAsync(self.host, [cmd], timeout=timeout)
        finally:
            self.host.execdom0("killall curl || true")
        if not self.findKey(self.vdi_to):
            raise xenrt.XRTFailure("Secret key was not found on the VDI")
        xenrt.TEC().logverbose(
            "Suceeded in verifying import_raw_vdi http call from its own host")

        # Upload from scheduler
        cmd = self.gencmd(self.vdi_img_controller, self.host.getIP())
        timeout = self.VDISIZE / xenrt.MEGA * 10
        xenrt.TEC().progress(
            "Start to upload the image from controller and verify")
        xenrt.command(cmd, timeout=timeout)
        if not self.findKey(self.vdi_to):
            raise xenrt.XRTFailure("Secret key was not found on the VDI")
        xenrt.TEC().logverbose(
            "Suceeded in verifying import_raw_vdi http call from the controller"
        )
コード例 #10
0
ファイル: func.py プロジェクト: thomassa/xenrt
    def hwClock(self):
        """XRT-75: Check hwclock and date both advance at the same rate
        (Bugzilla 630)"""
        hwclock1 = self.place.execcmd("/sbin/hwclock | "
                                      "sed -re's/ *[-0-9\.]+ seconds$//'")
        # SLES10 hwclock doesn't return anything
        if string.strip(hwclock1) == "":
            return
        if string.find(hwclock1, "Cannot access the Hardware Clock") > -1:
            return
        date1 = self.place.execcmd("date")
        time.sleep(60)
        hwclock2 = self.place.execcmd("/sbin/hwclock | "
                                      "sed -re's/ *[-0-9\.]+ seconds$//'")
        date2 = self.place.execcmd("date")

        # Parse
        hwclock1p = int(xenrt.command("date +%%s -d '%s'" % (hwclock1)))
        hwclock2p = int(xenrt.command("date +%%s -d '%s'" % (hwclock2)))
        date1p = int(xenrt.command("date +%%s -d '%s'" % (date1)))
        date2p = int(xenrt.command("date +%%s -d '%s'" % (date2)))

        elapsedhw = hwclock2p - hwclock1p
        elapseddate = date2p - date1p
        diff = elapsedhw - elapseddate
        if abs(diff) > 2:
            raise xenrt.XRTFailure("Elapsed hwclock (%u) and date (%u) differ"
                                   % (elapsedhw, elapseddate))
コード例 #11
0
ファイル: agent.py プロジェクト: johnmdilley/xenrt
    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")
コード例 #12
0
    def getHyperVMsi(self):
        if xenrt.TEC().lookup("HYPERV_AGENT", None):
            self.hyperVMsi = xenrt.TEC().getFile(
                xenrt.TEC().lookup("HYPERV_AGENT"))
        elif xenrt.TEC().lookup("ACS_BUILD", None):
            artifacts = xenrt.lib.cloud.getACSArtifacts(
                None, [], ["hypervagent.zip"])
            if len(artifacts) > 0:
                self.hyperVMsi = artifacts[0]

        if not self.hyperVMsi:
            # Install CloudPlatform packages
            cloudInputDir = self.marvin.mgtSvr.getCCPInputs()
            if not cloudInputDir:
                raise xenrt.XRTError("No CLOUDINPUTDIR specified")
            xenrt.TEC().logverbose("Downloading %s" % cloudInputDir)
            ccpTar = xenrt.TEC().getFile(cloudInputDir)
            xenrt.TEC().logverbose("Got %s" % ccpTar)
            t = xenrt.TempDirectory()
            xenrt.command("tar -xvzf %s -C %s" % (ccpTar, t.path()))
            self.hyperVMsi = xenrt.command(
                "find %s -type f -name *hypervagent.msi" % t.path()).strip()
        if not self.hyperVMsi:
            self.hyperVMsi = xenrt.TEC().getFile(xenrt.TEC().lookup(
                "HYPERV_AGENT_FALLBACK",
                "http://repo-ccp.citrix.com/releases/ASF/hyperv/ccp-4.5/CloudPlatform-4.5.0.0-19-hypervagent.msi"
            ))
        if not self.hyperVMsi:
            raise xenrt.XRTError("Could not find Hyper-V agent in build")
コード例 #13
0
ファイル: rhel.py プロジェクト: johnmdilley/xenrt
    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))
コード例 #14
0
ファイル: dockermachine.py プロジェクト: thomassa/xenrt
 def lifeCycleCreate(self):
     host_ip = self.host.getIP()
     cmd = '%s create --driver xenserver --xenserver-boot2docker-url "%s" --xenserver-server %s --xenserver-username root --xenserver-password xenroot %s 2>&1' % (
         self.command, self.BOOT2DOCKER_URL, host_ip, self.vmname)
     xenrt.command(cmd, timeout=1800)
     if self.vmname not in self.host.listGuests(running=True):
         raise xenrt.XRTFailure("VM(%r) not running at XenServer %s" %
                                (self.vmname, host_ip))
コード例 #15
0
ファイル: suppacks.py プロジェクト: johnmdilley/xenrt
 def run(self, arglist=None):
     host = self.getDefaultHost()
     url = "http://%s/" % (host.getIP())
     localtemp = xenrt.TEC().tempFile()
     try:
         xenrt.command("curl '%s' -o %s" % (url, localtemp))
     except Exception, e:
         raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                str(e))
コード例 #16
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
 def run(self, arglist=None):
     host = self.getDefaultHost()
     url = "http://%s/" % (host.getIP())
     localtemp = xenrt.TEC().tempFile()
     try:
         xenrt.command("curl '%s' -o %s" % (url, localtemp))
     except Exception, e:
         raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                str(e))
コード例 #17
0
ファイル: marvinwrapper.py プロジェクト: johnmdilley/xenrt
    def copySystemTemplatesToSecondaryStorage(self, storagePath, provider):
        # Load templates for this version
        templates = self.mgtSvr.lookup("SYSTEM_TEMPLATES", None)
        if not templates:
            raise xenrt.XRTError('Failed to find system templates')

        # Check if any non-default system templates have been specified
        # These should be added in the form -D CLOUD_TMPLT/hypervisor=url
        sysTemplates = xenrt.TEC().lookup("CLOUD_TMPLT", {})
        for s in sysTemplates:
            templates[s] = sysTemplates[s]

        # Legacy XenServer template support
        sysTemplateSrcLocation = xenrt.TEC().lookup("CLOUD_SYS_TEMPLATE", None)
        if sysTemplateSrcLocation:
            xenrt.TEC().warning("Use of CLOUD_SYS_TEMPLATE is deprecated, use CLOUD_SYS_TEMPLATES/xenserver instead")
            templates['xenserver'] = sysTemplateSrcLocation

        hvlist = xenrt.TEC().lookup("CLOUD_REQ_SYS_TMPLS", None)
        if hvlist:
            hvlist = hvlist.split(",")
        else:
            hvlist = []
        for t in templates.keys():
            if t not in hvlist:
                del templates[t]
        
        xenrt.TEC().logverbose('Using System Templates: %s' % (templates))
        webdir = xenrt.WebDirectory()
        if provider == 'NFS':
            self.mgtSvr.primaryManagementServer.execcmd('mount -t nfs -o nfsvers=3 %s /media' % (storagePath))
        elif provider == 'SMB':
            ad = xenrt.getADConfig()
            self.mgtSvr.primaryManagementServer.execcmd('mount -t cifs %s /media -o user=%s,password=%s,domain=%s' % (storagePath, ad.adminUser, ad.adminPassword, ad.domainName))
        installSysTmpltLoc = self.mgtSvr.primaryManagementServer.execcmd('find / -name *install-sys-tmplt -ignore_readdir_race 2> /dev/null || true').strip()
        for hv in templates:
            templateFile = xenrt.TEC().getFile(templates[hv])
            xenrt.TEC().logverbose("Using %s system VM template %s (md5sum: %s)" % (hv, templates[hv], xenrt.command("md5sum %s" % templateFile)))
            if templateFile.endswith(".zip") and xenrt.TEC().lookup("WORKAROUND_CS22839", False, boolean=True):
                xenrt.TEC().warning("Using CS-22839 workaround")
                tempDir = xenrt.TEC().tempDir()
                xenrt.command("cd %s && unzip %s" % (tempDir, templateFile))
                dirContents = glob.glob("%s/*" % tempDir)
                if len(dirContents) != 1:
                    raise xenrt.XRTError("Unexpected contents of system template ZIP file")
                templateFile = dirContents[0]
            webdir.copyIn(templateFile) 
            templateUrl = webdir.getURL(os.path.basename(templateFile))

            if provider in ('NFS', 'SMB'):
                self.mgtSvr.primaryManagementServer.execcmd('%s -m /media -u %s -h %s -F' % (installSysTmpltLoc, templateUrl, hv), timeout=60*60)

        if provider in ('NFS', 'SMB'):
            self.mgtSvr.primaryManagementServer.execcmd('umount /media')
        webdir.remove()
コード例 #18
0
def createHotfixSymlinks():
    hotfixpath = xenrt.TEC().lookup("HOTFIX_BASE_PATH")

    hfs = xenrt.TEC().lookup("HOTFIXES")

    hfdict = {}

    for r in hfs.keys():
        for v in hfs[r].keys():
            hfdict.update(dict(hfs[r][v].items()))

    for h in hfdict.keys():
        xenrt.command("ln -sf %s %s/%s.xsupdate" % (hfdict[h], hotfixpath, h))
コード例 #19
0
ファイル: sslutils.py プロジェクト: johnmdilley/xenrt
    def createPEM(self, hostname, password, cn=None, sanlist=[], expired=False):
        if self.issuedCertificates.has_key((cn,",".join(sanlist))):
            xenrt.TEC().logverbose("Returning existing certiicate")
            return self.issuedCertificates[(cn,",".join(sanlist))]
        path        = self.location + "/%s-ssl.conf" % (hostname)
        privatekey  = self.location + "/%s-key.pem" % (hostname)
        request     = self.location + "/%s-csr.pem" % (hostname)
        certificate = self.location + "/%s-cert.pem" % (hostname)
        pem         = self.location + "/%s.pem" % (hostname)

        self._createConfiguration(path, cn, sanlist, expired)

        xenrt.TEC().logverbose("Creating PEM for %s with SANs %s and CN %s." %
                               (hostname, sanlist, cn))

        xenrt.command("openssl req -batch -config %s -passout pass:%s "
                      "-newkey rsa:2048 -keyout %s -keyform PEM -out %s "
                      "-outform PEM" %
                      (path, password, privatekey, request))
        xenrt.command("openssl ca -batch -config %s -in %s -outdir %s "
                      "-out %s" %
                      (path, request, self.location, certificate))
        xenrt.command("openssl rsa -passin pass:%s -in %s -out %s" %
                      (password, privatekey, pem))
        xenrt.command("openssl x509 -in %s >> %s" % (certificate, pem))
        self.issuedCertificates[(cn,",".join(sanlist))] = pem
        return pem
コード例 #20
0
ファイル: sslutils.py プロジェクト: thomassa/xenrt
    def __init__(self, expired=False):
        try:
            xenrt.command("which openssl")
        except:
            raise xenrt.XRTError("OpenSSL must be present on the controller.")

        self.expired = expired

        self._directory = xenrt.resources.TempDirectory()
        self.location = self._directory.path()
        self.configuration = self.location + "/ca-ssl.conf"
        self.privatekey = self.location + "/ca-key.pem"
        self.certificate = self.location + "/ca-cert.pem"
        self.random = self.location + "/.rnd"
        self.serial = self.location + "/serial"
        self.index = self.location + "/index"
        self.issuedCertificates = {}

        self._createConfiguration(self.configuration,
                                  "CA",
                                  expired=self.expired)
        xenrt.command("openssl req -nodes -config %s -x509 -newkey rsa:2048 "
                      "-out %s -outform PEM -keyout %s -outform PEM" %
                      (self.configuration, self.certificate, self.privatekey))
        xenrt.command("touch %s" % (self.index))
        xenrt.command("echo '01' > %s" % (self.serial))
コード例 #21
0
ファイル: tools.py プロジェクト: johnmdilley/xenrt
def createHotfixSymlinks():
    hotfixpath = xenrt.TEC().lookup("HOTFIX_BASE_PATH")

    hfs = xenrt.TEC().lookup("HOTFIXES")

    hfdict = {}

    for r in hfs.keys():
        for v in hfs[r].keys():
            hfdict.update(dict(hfs[r][v].items()))


    for h in hfdict.keys():
        xenrt.command("ln -sf %s %s/%s.xsupdate" % (hfdict[h], hotfixpath, h))
コード例 #22
0
ファイル: sslutils.py プロジェクト: thomassa/xenrt
    def createPEM(self,
                  hostname,
                  password,
                  cn=None,
                  sanlist=[],
                  expired=False):
        if self.issuedCertificates.has_key((cn, ",".join(sanlist))):
            xenrt.TEC().logverbose("Returning existing certiicate")
            return self.issuedCertificates[(cn, ",".join(sanlist))]
        path = self.location + "/%s-ssl.conf" % (hostname)
        privatekey = self.location + "/%s-key.pem" % (hostname)
        request = self.location + "/%s-csr.pem" % (hostname)
        certificate = self.location + "/%s-cert.pem" % (hostname)
        pem = self.location + "/%s.pem" % (hostname)

        self._createConfiguration(path, cn, sanlist, expired)

        xenrt.TEC().logverbose("Creating PEM for %s with SANs %s and CN %s." %
                               (hostname, sanlist, cn))

        xenrt.command("openssl req -batch -config %s -passout pass:%s "
                      "-newkey rsa:2048 -keyout %s -keyform PEM -out %s "
                      "-outform PEM" % (path, password, privatekey, request))
        xenrt.command("openssl ca -batch -config %s -in %s -outdir %s "
                      "-out %s" % (path, request, self.location, certificate))
        xenrt.command("openssl rsa -passin pass:%s -in %s -out %s" %
                      (password, privatekey, pem))
        xenrt.command("openssl x509 -in %s >> %s" % (certificate, pem))
        self.issuedCertificates[(cn, ",".join(sanlist))] = pem
        return pem
コード例 #23
0
ファイル: suppacks.py プロジェクト: johnmdilley/xenrt
    def run(self, arglist=None):
        # Backup the original index.html
        self.host.execdom0("cp /opt/xensource/www/index.html /tmp/")

        # Install the supplemental pack
        _SupplementalPacksPostInstall.run(self, arglist)

        # Check the contents of the new web page
        url = "http://%s/" % (self.host.getIP())
        localtemp = xenrt.TEC().tempFile()
        try:
            xenrt.command("curl '%s' -o %s" % (url, localtemp))
        except Exception, e:
            raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                   str(e))
コード例 #24
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
    def run(self, arglist=None):
        # Backup the original index.html
        self.host.execdom0("cp /opt/xensource/www/index.html /tmp/")

        # Install the supplemental pack
        _SupplementalPacksPostInstall.run(self, arglist)

        # Check the contents of the new web page
        url = "http://%s/" % (self.host.getIP())
        localtemp = xenrt.TEC().tempFile()
        try:
            xenrt.command("curl '%s' -o %s" % (url, localtemp))
        except Exception, e:
            raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                   str(e))
コード例 #25
0
    def run(self, arglist=None):
        gname = None

        for arg in arglist:
            l = string.split(arg, "=", 1)
            if l[0] == "guest":
                gname = l[1]
            elif l[0] == "config":
                matching = xenrt.TEC().registry.guestLookup(\
                            **xenrt.util.parseXMLConfigString(l[1]))
                for n in matching:
                    xenrt.TEC().comment("Found matching guest(s): %s" %
                                        (matching))
                if matching:
                    gname = matching[0]

        if not gname:
            raise xenrt.XRTError("No guest name specified")
        guest = self.getGuest(gname)
        self.getLogsFrom(guest.host)
        guest.start()
        if not guest.windows:
            try:
                guestts = int(guest.execguest("date +%s"))
                localts = int(xenrt.command("date +%s"))
                xenrt.TEC().comment("Guest time delta from controller is %d "
                                    "seconds" % (guestts - localts))
            except:
                pass
コード例 #26
0
ファイル: xencert.py プロジェクト: johnmdilley/xenrt
    def setStorageType(self, srType):
        """Sets the required SR type for the test."""

        if srType == "nfs":
            self.SR_PARAM.append("-b nfs")

            nfs = xenrt.resources.NFSDirectory()
            nfsdir = xenrt.command("mktemp -d %s/nfsXXXX" % (nfs.path()), strip = True)
            server, path = nfs.getHostAndPath(os.path.basename(nfsdir))

            self.SR_PARAM.append("-n %s" % server)
            self.SR_PARAM.append("-e %s" % path)

        if srType == "lvmoiscsi":
            self.SR_PARAM.append("-b lvmoiscsi")

            self.lun = xenrt.ISCSILun()
            self.SR_PARAM.append("-t %s" %(self.lun.getServer()))
            self.SR_PARAM.append("-q %s" %(self.lun.getTargetName()))
            self.SR_PARAM.append("-s %s" %(self.lun.getID()))
            if self.lun.chap:
                i, u, s = self.lun.chap
                self.SR_PARAM.append("-x %s" %(u))
                self.SR_PARAM.append("-w %s" %(s))
            self.pool.master.setIQN(self.lun.getInitiatorName(allocate=True))
            self.pool.master.setIQN(self.lun.getInitiatorName(allocate=True))

        if srType == "lvmohba":
            self.SR_PARAM.append("-b lvmohba")

        # if not set, default 100 iterations wil be carried out by the script.
        self.SR_PARAM.append("-g %s" % (self.ITERATIONS))
コード例 #27
0
ファイル: basic.py プロジェクト: johnmdilley/xenrt
    def run(self, arglist=None):
        gname = None

        for arg in arglist:
            l = string.split(arg, "=", 1)
            if l[0] == "guest":
                gname = l[1]
            elif l[0] == "config":
                matching = xenrt.TEC().registry.guestLookup(**xenrt.util.parseXMLConfigString(l[1]))
                for n in matching:
                    xenrt.TEC().comment("Found matching guest(s): %s" % (matching))
                if matching:
                    gname = matching[0]

        if not gname:
            raise xenrt.XRTError("No guest name specified")
        guest = self.getGuest(gname)
        self.getLogsFrom(guest.host)
        guest.start()
        if not guest.windows:
            try:
                guestts = int(guest.execguest("date +%s"))
                localts = int(xenrt.command("date +%s"))
                xenrt.TEC().comment("Guest time delta from controller is %d " "seconds" % (guestts - localts))
            except:
                pass
コード例 #28
0
 def run(self, arglist):
     nfs = xenrt.resources.NFSDirectory()
     nfsDir = xenrt.command("mktemp -d %s/nfsXXXX" % (nfs.path()),
                            strip=True)
     nfsSR = xenrt.lib.xenserver.NFSStorageRepository(
         self.host, "nfs-sr-on-different-subnet-as-boot-disk")
     server, path = nfs.getHostAndPath(os.path.basename(nfsDir))
     nfsSR.create(server, path)
コード例 #29
0
ファイル: host.py プロジェクト: johnmdilley/xenrt
 def installCloudAgent(self, msi):
     ad = xenrt.getADConfig()
     
     if msi.endswith(".msi"):
         self.xmlrpcSendFile(msi, "c:\\hypervagent.msi")
         self.xmlrpcExec("msiexec /i c:\\hypervagent.msi /quiet /qn /norestart /log c:\\cloudagent-install.log SERVICE_USERNAME=%s\\%s SERVICE_PASSWORD=%s" % (ad.domainName, ad.adminUser, ad.adminPassword))
     elif msi.endswith(".zip"):
         tempDir = xenrt.TEC().tempDir()
         xenrt.command("unzip %s -d %s" % (msi, tempDir))
         self.xmlrpcCreateDir("c:\\cshyperv")
         self.xmlrpcSendRecursive(tempDir, "c:\\cshyperv")
         self.xmlrpcExec("c:\\cshyperv\\AgentShell.exe --install -u %s\\%s -p %s" % (ad.domainName, ad.adminUser, ad.adminPassword))
         data = self.hypervCmd("New-SelfSignedCertificate -DnsName apachecloudstack -CertStoreLocation Cert:\\LocalMachine\\My | Format-Wide -Property Thumbprint -autosize").strip()
         thumbprint = data.splitlines()[-1]
         self.xmlrpcExec("netsh http add sslcert ipport=0.0.0.0:8250 certhash=%s appid=\"{727beb1c-6e7c-49b2-8fbd-f03dbe481b08}\"" % thumbprint)
     else:
         raise xenrt.XRTError("Unknown cloud agent file %s" % os.path.basename(msi))
コード例 #30
0
    def importVM(self, host, file, sr=None, vifs=[]):
        """
        file is be an absolute path on site controller of type *.ovf or *.ova, which is to be imported.
        """
        _removeHostFromVCenter = False
        if not host.datacenter:
            _removeHostFromVCenter = True
            host.addToVCenter()
        ovftoolVersion = xenrt.command("ovftool --version", level=xenrt.RC_OK)
        if ovftoolVersion == 1:
            raise xenrt.XRTError("ovftool is required for vm import on esx")
        if not sr:
            sr = host.getDefaultDatastore()
        ovfInfo = xenrt.command("ovftool --machineOutput %s" % file)
        ovfInfoDict = xmltodict.parse(
            "<data" + ovfInfo.split("probeResult")[1].replace("\n+", "") +
            "data>")
        ovfNetworkList = ovfInfoDict["data"]["networks"]["network"]
        brs = host.getBridges()

        command = 'ovftool --noSSLVerify '
        command += '-n="%s" ' % self.name
        command += '-ds="%s" ' % sr
        for net in ovfNetworkList:
            if net["name"].strip() in brs:
                command += '--net:"%s"="%s" ' % (net["name"].strip(),
                                                 net["name"].strip())
            else:
                command += '--net:"%s"="%s" ' % (net["name"].strip(),
                                                 host.getPrimaryBridge())
        command += '%s vi://%s:%s@%s/' % (file, "root", host.password,
                                          host.getIP())
        xenrt.command(command)
        xenrt.sleep(15)
        self.existing(host)

        if not vifs:
            self.reparseVIFs()
            self.vifs.sort()
        else:
            self.vifs = vifs
        self.recreateVIFs(newMACs=True)

        if _removeHostFromVCenter:
            host.removeFromVCenter()
コード例 #31
0
ファイル: dellfactory.py プロジェクト: johnmdilley/xenrt
    def run(self, arglist=None):
        # Perform host installation
        productVersion = xenrt.TEC().lookup("PRODUCT_VERSION")
        inputDir = xenrt.TEC().lookup("INPUTDIR")
        self.host = xenrt.lib.xenserver.createHost(
            id=0, version=inputDir, productVersion=productVersion, installSRType="lvm", addToLogCollectionList=True
        )

        # Get a copy of the MBR from the host after installation
        self.host.execdom0("dd if=/dev/sda of=/tmp/mbr2 bs=512 count=1")
        sftp = self.host.sftpClient()
        sftp.copyFrom("/tmp/mbr2", "%s/mbr2" % (self.workdir))

        # Check the MBR is preserved after installation
        try:
            xenrt.command("diff %s/mbr1 %s/mbr2" % (self.workdir, self.workdir))
        except Exception, e:
            raise xenrt.XRTFailure("MBR was not preserved after installation")
コード例 #32
0
ファイル: suppacks.py プロジェクト: johnmdilley/xenrt
 def run(self, arglist=None):
     host = self.getDefaultHost()
     url = "http://%s/XenCenter.iso" % (host.getIP())
     localtemp = xenrt.TEC().tempFile()
     try:
         page = xenrt.command("curl '%s' -o %s" % (url, localtemp))
     except Exception, e:
         raise xenrt.XRTFailure("Unable to download XenCenter ISO file from "
                                "the host", str(e))
コード例 #33
0
ファイル: debian.py プロジェクト: johnmdilley/xenrt
 def generateIsoAnswerfile(self):
     preseedfile = "preseed-%s.cfg" % (self.parent._osParent_name)
     filename = "%s/%s" % (xenrt.TEC().getLogdir(), preseedfile)
     ps = DebianPreseedFile(self.distro,
                            xenrt.getLinuxRepo(self.distro, self.arch, "HTTP"),
                            filename,
                            arch=self.arch)
     ps.generate()
     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/preseed.stamp" % path)
     shutil.copyfile(filename, "%s/preseed" % (path))
コード例 #34
0
def generateLabCostPerTechArea(suiteId,
                               outputDir=None,
                               clearOutputDirContent=False):
    if outputDir and xenrt.TEC().lookup("GENERATE_STATS_BASEDIR").rstrip(
            "/") not in outputDir:
        # this part will ensure we only modify dir falling under base dir for stats.
        raise xenrt.XRTError(
            "permission denied [ dir not under base stat dir] '%s'" %
            outputDir)
    if clearOutputDirContent and outputDir:
        shutil.rmtree("%s" % outputDir.rstrip("/"))
    elif suiteId:
        if outputDir:
            outputDir = outputDir.rstrip("/")
            if os.path.exists("%s/%s.generating" % (outputDir, suiteId)):
                raise xenrt.XRTError(
                    "Another process is already generating data")
            else:
                if not os.path.exists(outputDir):
                    os.makedirs(outputDir)
                with open("%s/%s.generating" % (outputDir, suiteId), "w") as f:
                    f.write(str(xenrt.GEC().jobid()) or "nojob")
        try:
            cls = xenrt.generatestats.LabCostPerTechArea(
                suiteId, nbrOfSuiteRunsToCheck=10)
            data, tcMissingData = cls.generate()
            tempDir = xenrt.TEC().tempDir()
            with open("%s/%s.json" % (tempDir, suiteId), "w") as f:
                f.write(json.dumps(data, indent=2))
            with open(
                    "%s/%s_tcs_missing_run_history.json" % (tempDir, suiteId),
                    "w") as f:
                f.write(json.dumps(tcMissingData, indent=2))
            if outputDir:
                xenrt.command("cp -f -r %s/* %s" % (tempDir, outputDir))
            print "Data saved in directory '%s'" % (outputDir
                                                    if outputDir else tempDir)
        except Exception, e:
            errorLogDir = "%s/logs" % outputDir
            if not os.path.exists(errorLogDir):
                os.makedirs(errorLogDir)
            with open("%s/%s.error" % (errorLogDir, suiteId), "w") as f:
                f.write("[%s] %s" % (str(xenrt.GEC().jobid()) or "nojob", e))
        finally:
コード例 #35
0
 def pingGuest(self, ip6):
     try:
         # ping a guest on its IPv6 address from the controller 
         command = "ping6 -c 3 -w 10 -s 2000 %s"
         retCode = xenrt.command((command % ip6), retval="code")
         if retCode != 0:
             raise xenrt.XRTFailure('Command "%s" returned code %s' % (command, retCode) )
     except Exception, e:
         log('Exception encountered: \n%s\n' % e)
         raise xenrt.XRTFailure('Sending a large ping packet to %s failed' % ip6)
コード例 #36
0
ファイル: debian.py プロジェクト: thomassa/xenrt
 def generateIsoAnswerfile(self):
     preseedfile = "preseed-%s.cfg" % (self.parent._osParent_name)
     filename = "%s/%s" % (xenrt.TEC().getLogdir(), preseedfile)
     ps = DebianPreseedFile(self.distro,
                            xenrt.getLinuxRepo(self.distro, self.arch,
                                               "HTTP"),
                            filename,
                            arch=self.arch)
     ps.generate()
     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/preseed.stamp" % path)
     shutil.copyfile(filename, "%s/preseed" % (path))
コード例 #37
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
 def run(self, arglist=None):
     host = self.getDefaultHost()
     url = "http://%s/XenCenter.iso" % (host.getIP())
     localtemp = xenrt.TEC().tempFile()
     try:
         page = xenrt.command("curl '%s' -o %s" % (url, localtemp))
     except Exception, e:
         raise xenrt.XRTFailure(
             "Unable to download XenCenter ISO file from "
             "the host", str(e))
コード例 #38
0
ファイル: dockermachine.py プロジェクト: johnmdilley/xenrt
 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)
コード例 #39
0
ファイル: regression.py プロジェクト: johnmdilley/xenrt
    def run(self, arglist=[]):

        # Upload from localhost
        cmd = self.gencmd(self.vdi_img_host, "localhost")
        timeout = self.VDISIZE / xenrt.MEGA
        xenrt.TEC().progress("Start to upload the image from local host and verify")
        try:
            self.runAsync(self.host, [cmd], timeout=timeout)
        finally:
            self.host.execdom0("killall curl || true")
        if not self.findKey(self.vdi_to): raise xenrt.XRTFailure("Secret key was not found on the VDI")
        xenrt.TEC().logverbose("Suceeded in verifying import_raw_vdi http call from its own host")

        # Upload from scheduler
        cmd = self.gencmd(self.vdi_img_controller, self.host.getIP())
        timeout = self.VDISIZE / xenrt.MEGA * 10
        xenrt.TEC().progress("Start to upload the image from controller and verify")
        xenrt.command(cmd, timeout=timeout)
        if not self.findKey(self.vdi_to): raise xenrt.XRTFailure("Secret key was not found on the VDI")
        xenrt.TEC().logverbose("Suceeded in verifying import_raw_vdi http call from the controller")
コード例 #40
0
ファイル: dellfactory.py プロジェクト: thomassa/xenrt
    def run(self, arglist=None):
        # Perform host installation
        productVersion = xenrt.TEC().lookup("PRODUCT_VERSION")
        inputDir = xenrt.TEC().lookup("INPUTDIR")
        self.host = xenrt.lib.xenserver.createHost(id=0,
                                                   version=inputDir,
                                                   productVersion=productVersion,
                                                   installSRType="lvm",
                                                   addToLogCollectionList=True)

        # Get a copy of the MBR from the host after installation
        self.host.execdom0("dd if=/dev/sda of=/tmp/mbr2 bs=512 count=1")
        sftp = self.host.sftpClient()
        sftp.copyFrom("/tmp/mbr2", "%s/mbr2" % (self.workdir))

        # Check the MBR is preserved after installation
        try:
            xenrt.command("diff %s/mbr1 %s/mbr2" %
                          (self.workdir, self.workdir))
        except Exception, e:
            raise xenrt.XRTFailure("MBR was not preserved after installation")
コード例 #41
0
ファイル: dockermachine.py プロジェクト: thomassa/xenrt
 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)
コード例 #42
0
ファイル: guest.py プロジェクト: johnmdilley/xenrt
    def importVM(self, host, file, sr=None, vifs=[]):
        """
        file is be an absolute path on site controller of type *.ovf or *.ova, which is to be imported.
        """
        _removeHostFromVCenter = False
        if not host.datacenter:
            _removeHostFromVCenter = True
            host.addToVCenter()
        ovftoolVersion = xenrt.command("ovftool --version", level=xenrt.RC_OK)
        if ovftoolVersion==1:
            raise xenrt.XRTError("ovftool is required for vm import on esx")
        if not sr:
            sr=host.getDefaultDatastore()
        ovfInfo=xenrt.command("ovftool --machineOutput %s" % file)
        ovfInfoDict=xmltodict.parse("<data"+ovfInfo.split("probeResult")[1].replace("\n+","")+"data>")
        ovfNetworkList=ovfInfoDict["data"]["networks"]["network"]
        brs = host.getBridges()

        command ='ovftool --noSSLVerify '
        command+='-n="%s" ' % self.name
        command+='-ds="%s" ' % sr
        for net in ovfNetworkList:
            if net["name"].strip() in brs:
                command+='--net:"%s"="%s" ' % (net["name"].strip(),net["name"].strip())
            else:
                command+='--net:"%s"="%s" ' % (net["name"].strip(),host.getPrimaryBridge())
        command+='%s vi://%s:%s@%s/' % (file, "root", host.password, host.getIP())
        xenrt.command(command)
        xenrt.sleep(15)
        self.existing(host)

        if not vifs:
            self.reparseVIFs()
            self.vifs.sort()
        else:
            self.vifs = vifs
        self.recreateVIFs(newMACs=True)

        if _removeHostFromVCenter:
            host.removeFromVCenter()
コード例 #43
0
ファイル: filemanager.py プロジェクト: thomassa/xenrt
 def _externalCacheLocation(self, filename, ignoreError=False):
     try:
         cachedir=xenrt.TEC().lookup("FILE_MANAGER_CACHE_NFS")
         if os.path.exists(cachedir) and xenrt.command("stat -f -c %%T %s" % cachedir, nolog=True).strip() == "nfs":
             dirname = "%s/%s" % (cachedir, hashlib.sha256(filename).hexdigest())
             if not os.path.exists(dirname):
                 os.makedirs(dirname)
             return "%s/%s" % (dirname, self._filename(filename))
         elif os.path.exists(cachedir):
             raise xenrt.XRTError("External cache directory exists but is not external storage.")
     except Exception, e:
         if not ignoreError:
             raise xenrt.XRTError("_externalCacheLocation: %s" % str(e))
コード例 #44
0
ファイル: dellfactory.py プロジェクト: johnmdilley/xenrt
    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
コード例 #45
0
ファイル: dellfactory.py プロジェクト: thomassa/xenrt
    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
コード例 #46
0
ファイル: deploy.py プロジェクト: johnmdilley/xenrt
    def getHyperVMsi(self):
        if xenrt.TEC().lookup("HYPERV_AGENT", None):
            self.hyperVMsi = xenrt.TEC().getFile(xenrt.TEC().lookup("HYPERV_AGENT"))
        elif xenrt.TEC().lookup("ACS_BUILD", None):
            artifacts = xenrt.lib.cloud.getACSArtifacts(None, [], ["hypervagent.zip"])
            if len(artifacts) > 0:
                self.hyperVMsi = artifacts[0]

        if not self.hyperVMsi:
            # Install CloudPlatform packages
            cloudInputDir = self.marvin.mgtSvr.getCCPInputs()
            if not cloudInputDir:
                raise xenrt.XRTError("No CLOUDINPUTDIR specified")
            xenrt.TEC().logverbose("Downloading %s" % cloudInputDir)
            ccpTar = xenrt.TEC().getFile(cloudInputDir)
            xenrt.TEC().logverbose("Got %s" % ccpTar)
            t = xenrt.TempDirectory()
            xenrt.command("tar -xvzf %s -C %s" % (ccpTar, t.path()))
            self.hyperVMsi = xenrt.command("find %s -type f -name *hypervagent.msi" % t.path()).strip()
        if not self.hyperVMsi:
            self.hyperVMsi = xenrt.TEC().getFile(xenrt.TEC().lookup("HYPERV_AGENT_FALLBACK", "http://repo-ccp.citrix.com/releases/ASF/hyperv/ccp-4.5/CloudPlatform-4.5.0.0-19-hypervagent.msi"))
        if not self.hyperVMsi:
            raise xenrt.XRTError("Could not find Hyper-V agent in build")
コード例 #47
0
    def _ucs(self, op):
        fabric = self.machine.host.lookup("UCS_FABRIC_ADDRESS")
        user = self.machine.host.lookup("UCS_USERNAME")
        password = self.machine.host.lookup("UCS_PASSWORD")
        sp = self.machine.host.lookup("UCS_SERVICE_PROFILE", self.machine.name)
        root = self.machine.host.lookup("UCS_ROOT_ORG", "org-root")

        xenrt.TEC().logverbose("Sending %s to %s/%s/%s/%s/%s" %
                               (op, fabric, user, password, root, sp))

        text = xenrt.command("%s/ucspower %s %s %s %s %s %s" %
                             (xenrt.TEC().lookup("LOCAL_SCRIPTDIR"), fabric,
                              user, password, sp, root, op))
        if self.verbose:
            sys.stderr.write(text)
コード例 #48
0
ファイル: powerctl.py プロジェクト: johnmdilley/xenrt
    def _ucs(self, op):
        fabric = self.machine.host.lookup("UCS_FABRIC_ADDRESS")
        user = self.machine.host.lookup("UCS_USERNAME")
        password = self.machine.host.lookup("UCS_PASSWORD")
        sp = self.machine.host.lookup("UCS_SERVICE_PROFILE", self.machine.name)
        root = self.machine.host.lookup("UCS_ROOT_ORG", "org-root")

        xenrt.TEC().logverbose("Sending %s to %s/%s/%s/%s/%s" % (op, fabric, user, password, root, sp))

        text = xenrt.command("%s/ucspower %s %s %s %s %s %s" % (
                                xenrt.TEC().lookup("LOCAL_SCRIPTDIR"),
                                fabric,
                                user,
                                password,
                                sp,
                                root,
                                op))
        if self.verbose:
            sys.stderr.write(text)
コード例 #49
0
ファイル: sslutils.py プロジェクト: johnmdilley/xenrt
    def __init__(self, expired=False):
        try: xenrt.command("which openssl")
        except: raise xenrt.XRTError("OpenSSL must be present on the controller.")

        self.expired = expired

        self._directory = xenrt.resources.TempDirectory()
        self.location = self._directory.path()
        self.configuration  = self.location + "/ca-ssl.conf"
        self.privatekey     = self.location + "/ca-key.pem"
        self.certificate    = self.location + "/ca-cert.pem"
        self.random         = self.location + "/.rnd"
        self.serial         = self.location + "/serial"
        self.index          = self.location + "/index"
        self.issuedCertificates = {}

        self._createConfiguration(self.configuration, "CA", expired=self.expired)
        xenrt.command("openssl req -nodes -config %s -x509 -newkey rsa:2048 "
                      "-out %s -outform PEM -keyout %s -outform PEM" %
                     (self.configuration, self.certificate, self.privatekey))
        xenrt.command("touch %s" % (self.index))
        xenrt.command("echo '01' > %s" % (self.serial))
コード例 #50
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
class TC10665(_SupplementalPacksPostInstall):
    """Install a supplemental pack that includes a customized web page"""

    PACKS = [{"name": "webpage", "iso": "webpage.iso", "rpms": ["webpage"]}]

    FILE_CONTENTS = """<html>
  <title>My Custom Web Page</title>
<head>
</head>
<body>
  <p/>My Custom Web Page - Citrix Systems, Inc. XenServer 5.5.900
  <p/><a href="XenCenter.msi">XenCenter installer</a>
</body>
</html>
"""

    def run(self, arglist=None):
        # Backup the original index.html
        self.host.execdom0("cp /opt/xensource/www/index.html /tmp/")

        # Install the supplemental pack
        _SupplementalPacksPostInstall.run(self, arglist)

        # Check the contents of the new web page
        url = "http://%s/" % (self.host.getIP())
        localtemp = xenrt.TEC().tempFile()
        try:
            xenrt.command("curl '%s' -o %s" % (url, localtemp))
        except Exception, e:
            raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                   str(e))

        page = xenrt.command("cat %s" % (localtemp))

        if page != self.FILE_CONTENTS:
            raise xenrt.XRTFailure(
                "Unexpected web page found on the host", "Expected: \n%s"
                "Actual: \n%s" % (self.FILE_CONTENTS, page))
コード例 #51
0
ファイル: suppacks.py プロジェクト: thomassa/xenrt
class TC10662(xenrt.TestCase):
    """Download the web page from the host on port 80 and verify its contents"""
    def run(self, arglist=None):
        host = self.getDefaultHost()
        url = "http://%s/" % (host.getIP())
        localtemp = xenrt.TEC().tempFile()
        try:
            xenrt.command("curl '%s' -o %s" % (url, localtemp))
        except Exception, e:
            raise xenrt.XRTFailure("Unable to retrieve web page from the host",
                                   str(e))

        page = xenrt.command("cat %s" % (localtemp))

        # Check the page contents
        if not re.search("<body>.*XenServer", page, re.DOTALL):
            raise xenrt.XRTFailure(
                "Web page does not contain the product name", page)

        if not re.search("<body>.*XenServer [0-9]+\.[0-9]+", page, re.DOTALL):
            raise xenrt.XRTFailure(
                "Web page does not contain the product "
                "version", page)

        if not re.search(
                "<body>.*<a href=\"(XenCenter.msi|XenCenterSetup.exe)\">",
                page, re.DOTALL):
            raise xenrt.XRTFailure(
                "Web page does not contain a link to the "
                "XenCenter msi or exe file", page)

        if not re.search("<body>.*<a href=\"XenCenter.iso\">", page,
                         re.DOTALL):
            raise xenrt.XRTFailure(
                "Web page does not contain a link to the "
                "XenCenter iso file", page)
コード例 #52
0
ファイル: dellfactory.py プロジェクト: johnmdilley/xenrt
 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)
コード例 #53
0
    def copySystemTemplatesToSecondaryStorage(self, storagePath, provider):
        # Load templates for this version
        templates = self.mgtSvr.lookup("SYSTEM_TEMPLATES", None)
        if not templates:
            raise xenrt.XRTError('Failed to find system templates')

        # Check if any non-default system templates have been specified
        # These should be added in the form -D CLOUD_TMPLT/hypervisor=url
        sysTemplates = xenrt.TEC().lookup("CLOUD_TMPLT", {})
        for s in sysTemplates:
            templates[s] = sysTemplates[s]

        # Legacy XenServer template support
        sysTemplateSrcLocation = xenrt.TEC().lookup("CLOUD_SYS_TEMPLATE", None)
        if sysTemplateSrcLocation:
            xenrt.TEC().warning(
                "Use of CLOUD_SYS_TEMPLATE is deprecated, use CLOUD_SYS_TEMPLATES/xenserver instead"
            )
            templates['xenserver'] = sysTemplateSrcLocation

        hvlist = xenrt.TEC().lookup("CLOUD_REQ_SYS_TMPLS", None)
        if hvlist:
            hvlist = hvlist.split(",")
        else:
            hvlist = []
        for t in templates.keys():
            if t not in hvlist:
                del templates[t]

        xenrt.TEC().logverbose('Using System Templates: %s' % (templates))
        webdir = xenrt.WebDirectory()
        if provider == 'NFS':
            self.mgtSvr.primaryManagementServer.execcmd(
                'mount -t nfs -o nfsvers=3 %s /media' % (storagePath))
        elif provider == 'SMB':
            ad = xenrt.getADConfig()
            self.mgtSvr.primaryManagementServer.execcmd(
                'mount -t cifs %s /media -o user=%s,password=%s,domain=%s' %
                (storagePath, ad.adminUser, ad.adminPassword, ad.domainName))
        installSysTmpltLoc = self.mgtSvr.primaryManagementServer.execcmd(
            'find / -name *install-sys-tmplt -ignore_readdir_race 2> /dev/null || true'
        ).strip()
        for hv in templates:
            templateFile = xenrt.TEC().getFile(templates[hv])
            xenrt.TEC().logverbose(
                "Using %s system VM template %s (md5sum: %s)" %
                (hv, templates[hv], xenrt.command("md5sum %s" % templateFile)))
            if templateFile.endswith(".zip") and xenrt.TEC().lookup(
                    "WORKAROUND_CS22839", False, boolean=True):
                xenrt.TEC().warning("Using CS-22839 workaround")
                tempDir = xenrt.TEC().tempDir()
                xenrt.command("cd %s && unzip %s" % (tempDir, templateFile))
                dirContents = glob.glob("%s/*" % tempDir)
                if len(dirContents) != 1:
                    raise xenrt.XRTError(
                        "Unexpected contents of system template ZIP file")
                templateFile = dirContents[0]
            webdir.copyIn(templateFile)
            templateUrl = webdir.getURL(os.path.basename(templateFile))

            if provider in ('NFS', 'SMB'):
                self.mgtSvr.primaryManagementServer.execcmd(
                    '%s -m /media -u %s -h %s -F' %
                    (installSysTmpltLoc, templateUrl, hv),
                    timeout=60 * 60)

        if provider in ('NFS', 'SMB'):
            self.mgtSvr.primaryManagementServer.execcmd('umount /media')
        webdir.remove()
コード例 #54
0
ファイル: basic.py プロジェクト: johnmdilley/xenrt
    def run(self, arglist=None):

        again = False
        uninstall = False
        fin = False
        gname = None
        mustdo = False
        fromguest = False
        resident_on = None

        # Mandatory args.
        for arg in arglist:
            l = string.split(arg, "=", 1)
            if l[0] == "again":
                again = True
            if l[0] == "guest":
                gname = l[1]
            elif l[0] == "uninstall":
                uninstall = True
            elif l[0] == "finally":
                fin = True
                again = True
            elif l[0] == "mustdo":
                mustdo = True
            elif l[0] == "fromguest":
                fromguest = True
            elif l[0] == "config":
                matching = xenrt.TEC().registry.guestLookup(**xenrt.util.parseXMLConfigString(l[1]))
                for n in matching:
                    xenrt.TEC().comment("Found matching guest(s): %s" % (matching))
                if matching:
                    gname = matching[0]
            elif l[0] == "resident_on":
                resident_on = l[1]

        if not gname:
            raise xenrt.XRTError("No guest name specified")

        guest = None
        if resident_on:
            host = self.getHost(resident_on)
            guest = host.getGuest(gname)
        else:
            guest = self.getGuest(gname)

        if not guest:
            raise xenrt.XRTError("Could not find guest %s in registry" % (gname))
        if guest.getState() == "DOWN":
            if not fin:
                xenrt.TEC().skip("Guest already down")
                return
            if mustdo:
                guest.start()
        else:
            try:
                if not guest.windows:
                    guestts = int(guest.execguest("date +%s"))
                    localts = int(xenrt.command("date +%s"))
                    xenrt.TEC().comment("Guest time delta from controller is " "%d seconds" % (guestts - localts))
            except:
                pass
            self.getLogsFrom(guest.host)
            try:
                if fromguest:
                    guest.unenlightenedShutdown()
                    guest.poll("DOWN")
                else:
                    guest.shutdown(again=again)
            except Exception, e:
                if not fin:
                    raise e
コード例 #55
0
ファイル: rootops.py プロジェクト: johnmdilley/xenrt
def mountStaticISO(distro, arch=None, filename=None):
    """Mount a static ISO globally for the controller"""

    isolock = xenrt.resources.CentralResource()
    if filename:
        iso = filename
        mountpoint = "/winmedia/%s" % os.path.basename(filename)
        check = None
    else:
        if os.path.exists("%s/%s.iso" % (xenrt.TEC().lookup("EXPORT_ISO_LOCAL"), distro)):
            iso = "%s/%s.iso" % (xenrt.TEC().lookup("EXPORT_ISO_LOCAL"), distro)
            check = "Autounattend.xml"
            mountpoint = "/winmedia/%s" % distro
        else:
            stem = "%s/%s_%s" % (
                xenrt.TEC().lookup("EXPORT_ISO_LOCAL_STATIC"),
                xenrt.TEC().lookup(["OS_INSTALL_ISO", distro], distro),
                arch,
            )
            if not os.path.exists("%s.iso" % stem):
                stem = "%s_xenrtinst" % stem
            iso = "%s.iso" % stem
            if distro.startswith("sle"):
                check = "README"
            elif distro.startswith("sol"):
                check = "Copyright"
            else:
                check = "isolinux/isolinux.cfg"
            mountpoint = "/linmedia/%s_%s" % (distro, arch)
        attempts = 0
        while True:
            try:
                isolock.acquire("STATIC_ISO_%s" % distro)
                break
            except:
                xenrt.sleep(10)
                attempts += 1
                if attempts > 6:
                    raise xenrt.XRTError("Couldn't get Windows ISO lock.")
    try:
        # Check the ISO isn't directly mounted and there's no loopback mount for that ISO
        mounts = xenrt.command("mount")
        loops = xenrt.command("sudo losetup -a")

        def loDeviceOfISO(iso, line):
            if iso in line:
                return line.split(":")[0]
            else:
                return None

        loopDevs = filter(lambda x: not x is None, map(lambda line: loDeviceOfISO(iso, line), loops.split("\n")))

        if not "%s on %s" % (iso, mountpoint) in mounts and (
            len(loopDevs) == 0 or (not "%s on %s" % (loopDevs[0], mountpoint))
        ):
            sudo("mkdir -p %s" % mountpoint)
            sudo("mount -o loop %s %s" % (iso, mountpoint))
        elif check:
            # Check whether the loop mount has gone bad, and if it has then remount
            try:
                f = open("%s/%s" % (mountpoint, check))
                f.read()
            except:
                f.close()
                sudo("umount -f %s" % mountpoint)
                sudo("mkdir -p %s" % mountpoint)
                sudo("mount -o loop %s %s" % (iso, mountpoint))
            else:
                f.close()
        return mountpoint
    finally:
        isolock.release()
コード例 #56
0
ファイル: sdk.py プロジェクト: johnmdilley/xenrt
    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()