Ejemplo n.º 1
0
    def prepare(self, arglist):
        self.host = self.getDefaultHost()
        self.guest = self.getGuest("vm")

        webDir = xenrt.WebDirectory()
        webDir.copyIn(xenrt.TEC().getFile(
            "/usr/groups/xenrt/v6/v6vpx11-12-1_unzipped.xva"))
        self.guest.execguest("cd / && wget %s" %
                             webDir.getURL("v6vpx11-12-1_unzipped.xva"))

        # install NFS server on guest
        self.guest.execguest(
            "apt-get install -y --force-yes nfs-kernel-server nfs-common portmap"
        )
        self.guest.execguest(
            "echo '/ *(ro,sync,no_root_squash,insecure,subtree_check)' > /etc/exports"
        )
        self.guest.execguest(
            "/etc/init.d/portmap start || /etc/init.d/rpcbind start")
        self.guest.execguest("/etc/init.d/nfs-common start || true")
        self.guest.execguest("/etc/init.d/nfs-kernel-server start || true")

        # connect host to VM's nfs
        self.host.execdom0("mkdir /mnt/nfs")
        self.host.execdom0("mount %s:/ /mnt/nfs" % self.guest.getIP())

        # slow VIF down to a crawl
        self.guest.setVIFRate("eth0", 1)
        self.guest.unplugVIF("eth0")
        self.guest.plugVIF("eth0")
Ejemplo n.º 2
0
    def _createInstancePV(self, instance, startOn):

        kernel, initrd = instance.os.installerKernelAndInitRD
        webdir = xenrt.WebDirectory()
        bootArgs = instance.os.generateAnswerfile(webdir)
        host = self.hosts[0]  # TODO: Use startOn
        uuid = instance.toolstackId

        # Copy the kernel and initrd to the host
        host.execSSH("mkdir -p /tmp/installers/%s" % (uuid))
        host.execSSH("wget -O /tmp/installers/%s/kernel %s" % (uuid, kernel))
        host.execSSH("wget -O /tmp/installers/%s/initrd %s" % (uuid, initrd))

        # Create rootdisk
        self._createDisk(instance, "root", instance.rootdisk, host)

        # Build an XL configuration
        xlcfg = self.generateXLConfig(
            instance,
            kernel="/tmp/installers/%s/kernel" % (uuid),
            initrd="/tmp/installers/%s/initrd" % (uuid),
            args=bootArgs)
        domid = host.createInstance(xlcfg, uuid)
        self.residentOn[instance.toolstackId] = host
        host.updateConfig(domid, self.generateXLConfig(
            instance))  # Reset the boot config to normal for the reboot

        instance.os.waitForInstallCompleteAndFirstBoot()
Ejemplo n.º 3
0
    def installCloudPlatformManagementServer(self):
        for m in self.allManagementServers:
            self.__isCCP = True
            if m.arch != 'x86-64':
                raise xenrt.XRTError(
                    'Cloud Management Server requires a 64-bit guest')

            manSvrInputDir = self.getCCPInputs()
            if not manSvrInputDir:
                raise xenrt.XRTError(
                    'Location of management server build not specified')

            manSvrFile = xenrt.TEC().getFile(manSvrInputDir)
            if manSvrFile is None:
                raise xenrt.XRTError("Couldn't find CCP build")
            webdir = xenrt.WebDirectory()
            webdir.copyIn(manSvrFile)
            manSvrUrl = webdir.getURL(os.path.basename(manSvrFile))

            m.execcmd('wget %s -O cp.tar.gz' % (manSvrUrl))
            webdir.remove()

            if m.distro == "rhel7" or m.distro == "centos7":
                fname = "ws-commons-util-1.0.1-29.el7.noarch.rpm"
                wscommons = xenrt.TEC().getFile(
                    "/usr/groups/xenrt/cloud/rpms/%s" % fname)
                webdir = xenrt.WebDirectory()
                webdir.copyIn(wscommons)
                wscommonsurl = webdir.getURL(fname)
                m.execcmd("wget %s -O /root/%s" % (wscommonsurl, fname))
                m.execcmd("yum install -y /root/%s" % fname)
                webdir.remove()

            m.execcmd('mkdir cloudplatform')
            m.execcmd('tar -zxvf cp.tar.gz -C /root/cloudplatform')
            self.installDir = os.path.dirname(
                m.execcmd('find cloudplatform/ -type f -name install.sh'))
            m.execcmd('cd %s && ./install.sh -m' % (self.installDir),
                      timeout=600)
Ejemplo n.º 4
0
    def installXen(self):
        # First install dependencies
        self.execdom0(
            "apt-get install -y libyajl2 libglib2.0-0 libssh2-1 libcurl3 libpng12-0 libjpeg8 libsdl1.2debian libaio1 libpixman-1-0 bridge-utils tcpdump"
        )

        # Find and install the .deb
        webdir = xenrt.WebDirectory()
        xendeb = xenrt.TEC().getFile("xen.deb")
        if not xendeb:
            raise xenrt.XRTError("Unable to find Xen deb package")

        webdir.copyIn(xendeb, "xen.deb")
        self.execdom0("wget -q -O /tmp/xen.deb %s" %
                      (webdir.getURL("xen.deb")))
        self.execdom0("dpkg -i /tmp/xen.deb")

        # Update libraries
        self.execdom0("/sbin/ldconfig")

        # Sort out grub
        self.execdom0(
            "sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=2/' /etc/default/grub")
        self.execdom0("/usr/sbin/update-grub")

        # Enable Xen services
        self.execdom0("/usr/sbin/update-rc.d xencommons defaults")

        # Prepare the network config
        self.execdom0(
            "sed -i 's/iface eth0 inet dhcp/iface eth0 inet manual/' /etc/network/interfaces"
        )
        self.execdom0(
            "sed -i 's/iface eth0 inet6 auto/iface eth0 inet6 manual/' /etc/network/interfaces"
        )
        self.execdom0(
            "echo 'auto xenbr0\niface xenbr0 inet dhcp\n  bridge_ports eth0\n' >> /etc/network/interfaces"
        )

        # Create a directory to store VM disks in
        self.execdom0("mkdir -p /data")

        # Reboot
        self.reboot()

        self.xenInstalled = True

        # Check we have a working Xen installation
        self.check()
Ejemplo n.º 5
0
 def getRpmToDom0(self, host, var, specVar, dest):
     # Get an RPM to dom0 from a URL
     rpm = xenrt.TEC().lookup(var, None)
     if not rpm:
         return False
     if rpm.endswith(".rpm"):
         f = xenrt.TEC().getFile(rpm)
     else:
         spec = requests.get(xenrt.filemanager.FileNameResolver(rpm).url).json()
         f = xenrt.TEC().getFile(spec[specVar])
     if not f:
         return False
     d = xenrt.WebDirectory()
     d.copyIn(f)
     host.execdom0("wget -O %s %s" % (dest, d.getURL(os.path.basename(f))))
     return True
Ejemplo n.º 6
0
def getACSArtifacts(place, artifactsStart, artifactsEnd=[]):
    if xenrt.TEC().lookup("CLOUDRPMTAR", None) is not None:
        return getArtifactsFromTar(place, artifactsStart)

    buildUrl = xenrt.TEC().lookup("ACS_BUILD", None)
    if not buildUrl:
        buildUrl = findACSBuild(place)

    # Load the JSON data for this build
    data = json.loads(urllib.urlopen("%s/api/json" % (buildUrl)).read())
    artifactsDict = {}
    for a in data['artifacts']:
        artifactsDict[a['fileName']] = a['relativePath']

    artifactKeys = filter(
        lambda x: any(map(lambda a: x.startswith(a), artifactsStart)),
        artifactsDict.keys())
    artifactKeys.extend(
        filter(lambda x: any(map(lambda a: x.endswith(a), artifactsEnd)),
               artifactsDict.keys()))

    # Copy artifacts into the temp directory
    localFiles = [
        xenrt.TEC().getFile(
            os.path.join(buildUrl, "artifact", artifactsDict[x]))
        for x in artifactKeys
    ]

    if not place:
        return localFiles

    placeArtifactDir = '/tmp/csartifacts'
    place.execcmd('mkdir %s' % (placeArtifactDir))

    webdir = xenrt.WebDirectory()
    for f in localFiles:
        webdir.copyIn(f)
        place.execcmd('wget %s -P %s' %
                      (webdir.getURL(os.path.basename(f)), placeArtifactDir))

    webdir.remove()

    return placeArtifactDir
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
    def installWindows(self, version, build, arch):
        self.windows = True

        if not os.path.exists(
                "%s/%s/%s/autoinstall-%s.zip" %
            (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)):
            if not os.path.exists(
                    "%s/%s/%s/autoinstall-%s.tar" %
                (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)):
                raise xenrt.XRTError("No install files found for %s build %s" %
                                     (version, build))

        if version == "longhorn" or version[0:7] == "vistaee":
            method = "longhorn"
        else:
            method = "normal"
        self.distro = version

        xenrt.TEC().progress("Preparing TFTP...")
        tftp = "%s/xenrt/native" % (xenrt.TEC().lookup("TFTP_BASE"))
        if not os.path.exists(tftp):
            xenrt.sudo("mkdir -p %s" % (tftp))
        xenrt.getTestTarball("native", extract=True)
        xenrt.sudo("rsync -avxl %s/winpe32.wim %s/winpe.wim" %
                   (xenrt.TEC().lookup("IMAGES_ROOT"), tftp))

        # Get a PXE directory to put boot files in.
        xenrt.TEC().progress("Preparing PXE...")
        serport = xenrt.TEC().lookup("SERIAL_CONSOLE_PORT", "0")
        serbaud = xenrt.TEC().lookup("SERIAL_CONSOLE_BAUD", "115200")
        pxe = xenrt.PXEBoot()
        pxe.copyIn("%s/native/pxe/pxeboot.0" % (xenrt.TEC().getWorkdir()))
        xenrt.sudo("rsync -avxl %s/native/pxe/32/BCD %s/BCD" %
                   (xenrt.TEC().getWorkdir(), tftp))
        xenrt.sudo("rsync -avxl %s/native/pxe/boot.sdi %s/boot.sdi" %
                   (xenrt.TEC().getWorkdir(), tftp))
        xenrt.sudo("rsync -avxl %s/native/pxe/bootmgr.exe %s/bootmgr.exe" %
                   (xenrt.TEC().getWorkdir(), tftp))

        # Set the boot files and options for PXE
        pxe.setSerial(serport, serbaud)
        pxe.addEntry("local", boot="local")
        pxecfg = pxe.addEntry("winpe", default=1, boot="linux")
        pxecfg.linuxSetKernel("pxeboot.0")

        xenrt.TEC().progress("Preparing web directory")
        w = xenrt.WebDirectory()

        f = file("%s/native/pe/perun.cmd" % (xenrt.TEC().getWorkdir()), "r")
        perun = f.read()
        f.close()

        if method == "longhorn":
            t = xenrt.TempDirectory()

            xenrt.command("tar xf %s/%s/%s/autoinstall-%s.tar -C %s" %
                          (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))

            w.copyIn("%s/install/unattend.xml" % (t.path()))
            perun += "wget %FILES%/unattend.xml\n"

            # Count the number of install.wim fragments.
            catcmd = "cat "
            partpath = "%s/install/install.part" % (t.path())
            numparts = len(glob.glob("%s*" % (partpath)))
            for i in range(1, numparts + 1):
                # Download install.wim fragment.
                perun += "wget %%FILES%%/%s%d\n" % (os.path.basename(partpath),
                                                    i)
                # Make sure fragments get recombined.
                catcmd += "%s%d " % (os.path.basename(partpath), i)
                # Make fragment available over the network.
                w.copyIn("%s%d" % (partpath, i))
            catcmd += "> c:\\win\\sources\\install.wim\n"
            perun += catcmd
            w.copyIn("%s/install/install.zip" % (t.path()), target="win.zip")

            t.remove()

            # 32-bit installs just require the one stage.
            if arch == "x86-32":
                perun += "c:\\win\\sources\\setup.exe /unattend:c:\\unattend.xml"
        else:
            t = xenrt.TempDirectory()

            xenrt.command(
                "unzip %s/%s/%s/autoinstall-%s.zip unattend.txt -d %s" %
                (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch,
                 t.path()))
            try:
                xenrt.command(
                    "unzip %s/%s/%s/autoinstall-%s.zip runonce.cmd -d %s" %
                    (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch,
                     t.path()))
            except:
                try:
                    xenrt.command(
                        "unzip %s/%s/%s/autoinstall-%s.zip win/i386/runonce.cmd -d %s"
                        % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))
                except:
                    xenrt.command(
                        "unzip %s/%s/%s/autoinstall-%s.zip win/I386/runonce.cmd -d %s"
                        % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))
                xenrt.command("mv %s/win/?386/runonce.cmd %s/runonce.cmd" %
                              (t.path(), t.path()))
            xenrt.command("chmod a+rwx %s/runonce.cmd" % (t.path()))

            perun += """
wget %FILES%/runonce.cmd
wget %FILES%/unattend.txt
bootsect /nt52 c: /force
c:\win\i386\winnt32.exe /makelocalsource /syspart:c: /s:c:\win\i386 /unattend:c:\unattend.txt /cmd:c:\runonce.cmd
wpeutil reboot
"""
            f = file("%s/runonce.cmd" % (t.path()), "r")
            data = f.read()
            f.close()
            # HACK to support Broadcom NICs on those machines that have them.
            if xenrt.TEC().lookup("BROADCOM_POSTINSTALL", False, boolean=True):
                data = string.replace(data, "EXIT", "")
                data = data + 'REG ADD %KEY%\\050 /VE /D "Broadcom Driver" /f\n'
                data = data + 'REG ADD %KEY%\\050 /V 1 /D ' \
                       '"%systemdrive%\\win\\post\\Broadcom\\setup.exe ' \
                       '/s /v/qn" /f\n'
                data = data + "EXIT\n"

            xenrt.TEC().copyToLogDir("%s/runonce.cmd" % (t.path()))
            f = file("%s/runonce.cmd" % (t.path()), "w")
            f.write(data)
            f.close()
            w.copyIn("%s/unattend.txt" % (t.path()))
            w.copyIn("%s/runonce.cmd" % (t.path()))
            w.copyIn("%s/%s/%s/autoinstall-%s.zip" %
                     (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch),
                     target="win.zip")
            t.remove()

        # Copy common files.
        w.copyIn("%s/native/pe/makepart.txt" % (xenrt.TEC().getWorkdir()))

        perun_dir = os.path.dirname(xenrt.TEC().lookup("WINPE_START_FILE"))
        if not os.path.exists(perun_dir):
            xenrt.sudo("mkdir -p %s" % (perun_dir))
        # Replace variables in perun.cmd.
        perun = string.replace(perun, "%FILES%", "%s" % (w.getURL("/")))
        f = file("%s/perun.cmd" % (xenrt.TEC().getWorkdir()), "w")
        f.write(perun)
        f.close()
        xenrt.TEC().copyToLogDir("%s/perun.cmd" % (xenrt.TEC().getWorkdir()))
        # Put perun.cmd where WinPE expects it.
        lock = xenrt.resources.CentralResource()
        for i in range(10):
            try:
                lock.acquire("WINPE_START_FILE")
                break
            except:
                if i == 9:
                    raise xenrt.XRTError("Couldn't get lock on WINPE "
                                         "bootstrap file.")
                xenrt.sleep(60)
        xenrt.sudo(
            "cp %s/perun.cmd %s" %
            (xenrt.TEC().getWorkdir(), xenrt.TEC().lookup("WINPE_START_FILE")))

        # Start install.
        xenrt.TEC().progress("Starting installation")
        pxefile = pxe.writeOut(self.machine)
        pfname = os.path.basename(pxefile)
        xenrt.TEC().copyToLogDir(pxefile, target="%s.pxe.txt" % (pfname))
        self.machine.powerctl.cycle()
        xenrt.TEC().progress("Rebooted host to start installation.")

        xenrt.sleep(120)

        lock.release()

        # 64-bit requires a two-stage installation.
        if arch == "x86-64":
            # Wait for first stage to complete.
            xenrt.sleep(360)
            xenrt.TEC().progress("Preparing TFTP for second stage.")
            xenrt.sudo("rsync -avxl %s/native/pxe/64/ %s/" %
                       (xenrt.TEC().getWorkdir(), tftp))
            xenrt.sudo("rsync -avxl %s/winpe64.wim %s/winpe.wim" %
                       (xenrt.TEC().lookup("IMAGES_ROOT"), tftp))
            self.machine.powerctl.cycle()
            xenrt.TEC().progress(
                "Rebooted host into second installation stage.")

        # Wait for PXE boot.
        xenrt.sleep(120)
        pxe.setDefault("local")
        pxe.writeOut(self.machine)

        # Wait for Windows to boot.
        xenrt.TEC().progress("Waiting for host to boot")
        self.waitforxmlrpc(7200)

        w.remove()

        if method == "longhorn":
            self.winRegAdd(
                "HKLM", "SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
                "fDenyTSConnections", "DWORD", 0)
            self.winRegAdd("HKLM", "SYSTEM\\CurrentControlSet\\Control\\Lsa",
                           "LMCompatibilityLevel", "DWORD", 1)

        if not method == "longhorn":
            bootini = self.xmlrpcReadFile("c:\\boot.ini").strip()
            if self.memory:
                bootini += " /MAXMEM=%d" % (self.memory)
            if self.vcpus:
                bootini += " /NUMPROC=%d" % (self.vcpus)
            self.xmlrpcRemoveFile("c:\\boot.ini")
            self.xmlrpcCreateFile("c:\\boot.ini", xmlrpclib.Binary(bootini))
            self.xmlrpcReboot()
            xenrt.sleep(180)
            self.waitforxmlrpc(300)

            self.tailor()