Ejemplo n.º 1
0
    def tailorForCloudStack(self, isCCP, isLXC=False, isBasic=False):
        """Tailor this host for use with ACS/CCP"""

        # Check that we haven't already tailored the host
        if self.execdom0("ls /var/lib/xenrt/cloudTailored", retval="code") == 0:
            return

        if isBasic:
            self.execdom0("echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables")
            self.execdom0("echo 1 > /proc/sys/net/bridge/bridge-nf-call-arptables")
            self.execdom0("sed -i '/net.bridge.bridge-nf-call-iptables/d' /etc/sysctl.conf")
            self.execdom0("sed -i '/net.bridge.bridge-nf-call-arptables/d' /etc/sysctl.conf")
            self.execdom0("echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.conf")
            self.execdom0("echo 'net.bridge.bridge-nf-call-arptables = 1' >> /etc/sysctl.conf")

        # Common operations
        # hostname --fqdn must give a response
        self.execdom0("echo '%s %s.%s %s' >> /etc/hosts" %
                      (self.getIP(),
                       self.getName(),
                       self.lookup("DNS_DOMAIN", "xenrt"),
                       self.getName()))

        # Start NTP
        self.execdom0("service ntpd start")
        self.execdom0("chkconfig ntpd on")

        self.addExtraLogFile("/var/log/cloudstack")

        if isCCP:
            # Citrix CloudPlatform specific operations

            self.execdom0("yum erase -y qemu-kvm")
            # Install CloudPlatform packages
            cloudInputDir = xenrt.getCCPInputs(self.distro)
            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)
            webdir = xenrt.WebDirectory()
            webdir.copyIn(ccpTar)
            ccpUrl = webdir.getURL(os.path.basename(ccpTar))
            self.execdom0('wget %s -O /tmp/cp.tar.gz' % (ccpUrl))
            webdir.remove()
            self.installJSVC()
            self.execdom0("cd /tmp && mkdir cloudplatform && tar -xvzf cp.tar.gz -C /tmp/cloudplatform")
            installDir = os.path.dirname(self.execdom0('find /tmp/cloudplatform/ -type f -name install.sh'))
            result = self.execdom0("cd %s && ./install.sh -a" % (installDir))
            # CS-20675 - install.sh can exit with 0 even if the install fails!
            if "You could try using --skip-broken to work around the problem" in result:
                raise xenrt.XRTError("Dependency failure installing CloudPlatform")

            # NFS services
            self.execdom0("service rpcbind start")
            self.execdom0("service nfs start")
            self.execdom0("chkconfig rpcbind on")
            try:
                self.execdom0("chkconfig nfs on")
            except:
                self.execdom0("systemctl enable nfs-server.service") # RHEL7
        else:
            # Apache CloudStack specific operations

            # Install cloudstack-agent
            self.installJSVC()
            self.execdom0("yum install -y ipset jna")
            artifactDir = xenrt.lib.cloud.getACSArtifacts(self, ["cloudstack-common-", "cloudstack-agent-"])
            self.execdom0("rpm -ivh %s/cloudstack-*.rpm" % artifactDir)

            # Modify /etc/libvirt/qemu.conf
            self.execdom0("sed -i 's/\\# vnc_listen = \"0.0.0.0\"/vnc_listen = \"0.0.0.0\"/' /etc/libvirt/qemu.conf")
            self.execdom0("service libvirtd restart")

            # Ensure SELinux is in permissive mode
            self.execdom0("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config")
            self.execdom0("/usr/sbin/setenforce permissive")

        if (re.search(r"rhel7", self.distro) or re.search(r"centos7", self.distro) or re.search(r"oel7", self.distro) or re.search(r"sl7", self.distro)) \
            and xenrt.TEC().lookup("WORKAROUND_CS21359", False, boolean=True):
            self.execdom0("yum install -y libcgroup-tools") # CS-21359
            self.execdom0("echo kvmclock.disable=true >> /etc/cloudstack/agent/agent.properties") # CLOUDSTACK-7472

            self.execdom0("umount /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuset /sys/fs/cgroup/memory /sys/fs/cgroup/devices /sys/fs/cgroup/freezer /sys/fs/cgroup/net_cls /sys/fs/cgroup/blkio")
            self.execdom0("rm -f /sys/fs/cgroup/cpu /sys/fs/cgroup/cpuacct")
            self.execdom0("""cat >> /etc/cgconfig.conf <<EOF
mount {
           cpuset = /sys/fs/cgroup/cpuset;
           cpu = /sys/fs/cgroup/cpu;
           cpuacct = /sys/fs/cgroup/cpuacct;
           memory = /sys/fs/cgroup/memory;
           devices = /sys/fs/cgroup/devices;
           freezer = /sys/fs/cgroup/freezer;
           net_cls = /sys/fs/cgroup/net_cls;
           blkio = /sys/fs/cgroup/blkio;
}
EOF
""")
            self.execdom0("service cgconfig stop")
            self.execdom0("service cgconfig start")

        try:
            # Set up /etc/cloudstack/agent/agent.properties
            self.execdom0("echo 'public.network.device=cloudbr0' >> /etc/cloudstack/agent/agent.properties")
            self.execdom0("echo 'private.network.device=cloudbr0' >> /etc/cloudstack/agent/agent.properties")
        except:
            self.execdom0("echo 'public.network.device=cloudbr0' >> /etc/cloud/agent/agent.properties")
            self.execdom0("echo 'private.network.device=cloudbr0' >> /etc/cloud/agent/agent.properties")

        # Log the commit
        commit = None
        try:
            commit = self.execdom0("cloudstack-sccs").strip()
            xenrt.TEC().logverbose("ACS/CCP agent was built from commit %s" % commit)
        except:
            xenrt.TEC().warning("Error when trying to identify agent version")
        if commit:
            expectedCommit = xenrt.getCCPCommit(self.distro)
            if expectedCommit and commit != expectedCommit:
                raise xenrt.XRTError("ACS/CCP agent commit %s does not match expected commit %s" % (commit, expectedCommit))

        # Ensure NFS mounts use v3 by default
        self.execdom0("echo 'Defaultvers=3' >> /etc/nfsmount.conf") 

        # Write the stamp file to record this has already been done
        self.execdom0("mkdir -p /var/lib/xenrt")
        self.execdom0("touch /var/lib/xenrt/cloudTailored")
Ejemplo n.º 2
0
    def setupManagementServer(self):
        self.primaryManagementServer.execcmd('iptables -I INPUT -p tcp --dport 8096 -j ACCEPT')
        setupMsLoc = self.primaryManagementServer.execcmd('find /usr/bin -name %s-setup-management' % (self.cmdPrefix)).strip()
        self.primaryManagementServer.execcmd(setupMsLoc)

        self.primaryManagementServer.execcmd('mysql -u cloud --password=cloud -h %s --execute="UPDATE cloud.configuration SET value=8096 WHERE name=\'integration.api.port\'"' % self.dbServer.getIP())

        if xenrt.TEC().lookup("USE_CCP_SIMULATOR", False, boolean=True) or self._simDbServer:
            # For some reason the cloud user doesn't seem to have access to the simulator DB
            self.primaryManagementServer.execcmd("""sed -i s/db.simulator.username=cloud/db.simulator.username=root/ /usr/share/cloudstack-management/conf/db.properties""")
            self.primaryManagementServer.execcmd("""sed -i s/db.simulator.password=cloud/db.simulator.password=xensource/ /usr/share/cloudstack-management/conf/db.properties""")
            self.primaryManagementServer.execcmd("""sed -i s/db.simulator.host=localhost/db.simulator.host=%s/ /usr/share/cloudstack-management/conf/db.properties""" % self.simDbServer.getIP())
                
        self.restart(checkHealth=False)
        self.checkManagementServerHealth(timeout=300)

        # We have to update templates *after* starting the management server as some templates are not introduced until DB schema updates are applied
        templateSubsts = {"http://download.cloud.com/templates/builtin/centos56-x86_64.vhd.bz2":
                            "%s/cloudTemplates/centos56-x86_64.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://download.cloud.com/releases/4.3/centos6_4_64bit.vhd.bz2":
                            "%s/cloudTemplates/centos6_4_64bit.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://nfs1.lab.vmops.com/templates/centos53-x86_64/latest/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2":
                            "%s/cloudTemplates/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://download.cloud.com/templates/builtin/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2":
                            "%s/cloudTemplates/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://download.cloud.com/releases/2.2.0/CentOS5.3-x86_64.ova":
                            "%s/cloudTemplates/CentOS5.3-x86_64.ova" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://download.cloud.com/releases/2.2.0/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2":
                            "%s/cloudTemplates/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
                           "http://download.cloud.com/templates/builtin/centos-7-x86_64.tar.gz":
                            "%s/cloudTemplates/centos-7-x86_64.tar.gz" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")}

        if xenrt.TEC().lookup("MARVIN_BUILTIN_TEMPLATES", False, boolean=True):
            templateSubsts["http://download.cloud.com/templates/builtin/centos56-x86_64.vhd.bz2"] = \
                    "%s/cloudTemplates/centos56-httpd-64bit.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")
            templateSubsts["http://download.cloud.com/releases/2.2.0/CentOS5.3-x86_64.ova"] = \
                    "%s/cloudTemplates/centos53-httpd-64bit.ova" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")
            templateSubsts["http://download.cloud.com/releases/2.2.0/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2"] = \
                    "%s/cloudTemplates/centos55-httpd-64bit.qcow2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")

        for t in templateSubsts.keys():
            self.primaryManagementServer.execcmd("""mysql -u cloud --password=cloud -h %s --execute="UPDATE cloud.vm_template SET url='%s' WHERE url='%s'" """ % (self.dbServer.getIP(), templateSubsts[t], t))

        self.restart()

        marvinApi = xenrt.lib.cloud.MarvinApi(self)

        internalMask = IPy.IP("%s/%s" % (xenrt.getNetworkParam("NPRI", "SUBNET"), xenrt.getNetworkParam("NPRI", "SUBNETMASK")))

        if xenrt.TEC().lookup("USE_CCP_SIMULATOR", False, boolean=True) or self._simDbServer:
            self.primaryManagementServer.execcmd('mysql -u root --password=xensource -h %s < /usr/share/cloudstack-management/setup/hypervisor_capabilities.simulator.sql' % self.dbServer.getIP())
            self.primaryManagementServer.execcmd('mysql -u root --password=xensource -h %s < /usr/share/cloudstack-management/setup/templates.simulator.sql' % self.dbServer.getIP())
        marvinApi.setCloudGlobalConfig("secstorage.allowed.internal.sites", internalMask.strNormal())
        if not xenrt.TEC().lookup("MARVIN_SETUP", False, boolean=True):
            marvinApi.setCloudGlobalConfig("use.external.dns", "true")
        endpoint_url = "http://%s:8096/client/api" % marvinApi.mgtSvrDetails.mgtSvrIp
        if self.additionalManagementServers:
            marvinApi.setCloudGlobalConfig("agent.lb.enabled", "true")
        marvinApi.setCloudGlobalConfig("endpointe.url", endpoint_url)
        marvinApi.setCloudGlobalConfig("check.pod.cidrs", "false", restartManagementServer=True)
        xenrt.GEC().dbconnect.jobUpdate("CLOUD_MGMT_SVR_IP", self.primaryManagementServer.getIP())
        xenrt.TEC().registry.toolstackPut("cloud", xenrt.lib.cloud.CloudStack(place=self.primaryManagementServer))
        # Create one secondary storage, to speed up deployment.
        # Additional locations will need to be created during deployment
        hvlist = xenrt.TEC().lookup("CLOUD_REQ_SYS_TMPLS", None)
        if hvlist:
            hvlist = hvlist.split(",")
        else:
            hvlist = []
        if any(map(lambda hv: hv in hvlist, ["kvm", "xenserver", "vmware", "lxc"])):
            secondaryStorage = xenrt.ExternalNFSShare()
            storagePath = secondaryStorage.getMount()
            url = 'nfs://%s' % (secondaryStorage.getMount().replace(':',''))
            marvinApi.copySystemTemplatesToSecondaryStorage(storagePath, "NFS")
            self.primaryManagementServer.special['initialNFSSecStorageUrl'] = url
        elif "hyperv" in hvlist:
            if xenrt.TEC().lookup("EXTERNAL_SMB", False, boolean=True):
                secondaryStorage = xenrt.ExternalSMBShare()
                storagePath = secondaryStorage.getMount()
                url = 'cifs://%s' % (secondaryStorage.getMount().replace(':',''))
                marvinApi.copySystemTemplatesToSecondaryStorage(storagePath, "SMB")
                self.primaryManagementServer.special['initialSMBSecStorageUrl'] = url

        if xenrt.TEC().lookup("CCP_CODE_COVERAGE", False, boolean=True):
            xenrt.TEC().logverbose("Enabling code coverage collection...")
            for m in self.allManagementServers:
                if m.execcmd("ls %s/setup_codecoverage.sh" % self.installDir, retval="code") != 0:
                    raise xenrt.XRTError("CCP_CODE_COVERAGE set but setup_codecoverage.sh not found in build")
                m.execcmd("cd %s && ./setup_codecoverage.sh" % self.installDir)
            self.restart()
            xenrt.TEC().logverbose("...done")

        commit = None
        try:
            commit = self.primaryManagementServer.execcmd("cloudstack-sccs").strip()
            xenrt.TEC().logverbose("Management server was built from commit %s" % commit)
        except:
            xenrt.TEC().warning("Error when trying to identify management server version")
        if commit:
            expectedCommit = xenrt.getCCPCommit(self.primaryManagementServer.distro)
            if expectedCommit and commit != expectedCommit:
                raise xenrt.XRTError("Management server commit %s does not match expected commit %s" % (commit, expectedCommit))
Ejemplo n.º 3
0
    def setupManagementServer(self):
        self.primaryManagementServer.execcmd(
            'iptables -I INPUT -p tcp --dport 8096 -j ACCEPT')
        setupMsLoc = self.primaryManagementServer.execcmd(
            'find /usr/bin -name %s-setup-management' %
            (self.cmdPrefix)).strip()
        self.primaryManagementServer.execcmd(setupMsLoc)

        self.primaryManagementServer.execcmd(
            'mysql -u cloud --password=cloud -h %s --execute="UPDATE cloud.configuration SET value=8096 WHERE name=\'integration.api.port\'"'
            % self.dbServer.getIP())

        if xenrt.TEC().lookup("USE_CCP_SIMULATOR", False,
                              boolean=True) or self._simDbServer:
            # For some reason the cloud user doesn't seem to have access to the simulator DB
            self.primaryManagementServer.execcmd(
                """sed -i s/db.simulator.username=cloud/db.simulator.username=root/ /usr/share/cloudstack-management/conf/db.properties"""
            )
            self.primaryManagementServer.execcmd(
                """sed -i s/db.simulator.password=cloud/db.simulator.password=xensource/ /usr/share/cloudstack-management/conf/db.properties"""
            )
            self.primaryManagementServer.execcmd(
                """sed -i s/db.simulator.host=localhost/db.simulator.host=%s/ /usr/share/cloudstack-management/conf/db.properties"""
                % self.simDbServer.getIP())

        self.restart(checkHealth=False)
        self.checkManagementServerHealth(timeout=300)

        # We have to update templates *after* starting the management server as some templates are not introduced until DB schema updates are applied
        templateSubsts = {
            "http://download.cloud.com/templates/builtin/centos56-x86_64.vhd.bz2":
            "%s/cloudTemplates/centos56-x86_64.vhd.bz2" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://download.cloud.com/releases/4.3/centos6_4_64bit.vhd.bz2":
            "%s/cloudTemplates/centos6_4_64bit.vhd.bz2" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://nfs1.lab.vmops.com/templates/centos53-x86_64/latest/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2":
            "%s/cloudTemplates/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://download.cloud.com/templates/builtin/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2":
            "%s/cloudTemplates/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://download.cloud.com/releases/2.2.0/CentOS5.3-x86_64.ova":
            "%s/cloudTemplates/CentOS5.3-x86_64.ova" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://download.cloud.com/releases/2.2.0/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2":
            "%s/cloudTemplates/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2"
            % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP"),
            "http://download.cloud.com/templates/builtin/centos-7-x86_64.tar.gz":
            "%s/cloudTemplates/centos-7-x86_64.tar.gz" %
            xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")
        }

        if xenrt.TEC().lookup("MARVIN_BUILTIN_TEMPLATES", False, boolean=True):
            templateSubsts["http://download.cloud.com/templates/builtin/centos56-x86_64.vhd.bz2"] = \
                    "%s/cloudTemplates/centos56-httpd-64bit.vhd.bz2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")
            templateSubsts["http://download.cloud.com/releases/2.2.0/CentOS5.3-x86_64.ova"] = \
                    "%s/cloudTemplates/centos53-httpd-64bit.ova" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")
            templateSubsts["http://download.cloud.com/releases/2.2.0/eec2209b-9875-3c8d-92be-c001bd8a0faf.qcow2.bz2"] = \
                    "%s/cloudTemplates/centos55-httpd-64bit.qcow2" % xenrt.TEC().lookup("EXPORT_DISTFILES_HTTP")

        for t in templateSubsts.keys():
            self.primaryManagementServer.execcmd(
                """mysql -u cloud --password=cloud -h %s --execute="UPDATE cloud.vm_template SET url='%s' WHERE url='%s'" """
                % (self.dbServer.getIP(), templateSubsts[t], t))

        self.restart()

        marvinApi = xenrt.lib.cloud.MarvinApi(self)

        internalMask = IPy.IP("%s/%s" % (xenrt.getNetworkParam(
            "NPRI", "SUBNET"), xenrt.getNetworkParam("NPRI", "SUBNETMASK")))

        if xenrt.TEC().lookup("USE_CCP_SIMULATOR", False,
                              boolean=True) or self._simDbServer:
            self.primaryManagementServer.execcmd(
                'mysql -u root --password=xensource -h %s < /usr/share/cloudstack-management/setup/hypervisor_capabilities.simulator.sql'
                % self.dbServer.getIP())
            self.primaryManagementServer.execcmd(
                'mysql -u root --password=xensource -h %s < /usr/share/cloudstack-management/setup/templates.simulator.sql'
                % self.dbServer.getIP())
        marvinApi.setCloudGlobalConfig("secstorage.allowed.internal.sites",
                                       internalMask.strNormal())
        if not xenrt.TEC().lookup("MARVIN_SETUP", False, boolean=True):
            marvinApi.setCloudGlobalConfig("use.external.dns", "true")
        endpoint_url = "http://%s:8096/client/api" % marvinApi.mgtSvrDetails.mgtSvrIp
        if self.additionalManagementServers:
            marvinApi.setCloudGlobalConfig("agent.lb.enabled", "true")
        marvinApi.setCloudGlobalConfig("endpointe.url", endpoint_url)
        marvinApi.setCloudGlobalConfig("check.pod.cidrs",
                                       "false",
                                       restartManagementServer=True)
        xenrt.GEC().dbconnect.jobUpdate("CLOUD_MGMT_SVR_IP",
                                        self.primaryManagementServer.getIP())
        xenrt.TEC().registry.toolstackPut(
            "cloud",
            xenrt.lib.cloud.CloudStack(place=self.primaryManagementServer))
        # Create one secondary storage, to speed up deployment.
        # Additional locations will need to be created during deployment
        hvlist = xenrt.TEC().lookup("CLOUD_REQ_SYS_TMPLS", None)
        if hvlist:
            hvlist = hvlist.split(",")
        else:
            hvlist = []
        if any(
                map(lambda hv: hv in hvlist,
                    ["kvm", "xenserver", "vmware", "lxc"])):
            secondaryStorage = xenrt.ExternalNFSShare()
            storagePath = secondaryStorage.getMount()
            url = 'nfs://%s' % (secondaryStorage.getMount().replace(':', ''))
            marvinApi.copySystemTemplatesToSecondaryStorage(storagePath, "NFS")
            self.primaryManagementServer.special[
                'initialNFSSecStorageUrl'] = url
        elif "hyperv" in hvlist:
            if xenrt.TEC().lookup("EXTERNAL_SMB", False, boolean=True):
                secondaryStorage = xenrt.ExternalSMBShare()
                storagePath = secondaryStorage.getMount()
                url = 'cifs://%s' % (secondaryStorage.getMount().replace(
                    ':', ''))
                marvinApi.copySystemTemplatesToSecondaryStorage(
                    storagePath, "SMB")
                self.primaryManagementServer.special[
                    'initialSMBSecStorageUrl'] = url

        if xenrt.TEC().lookup("CCP_CODE_COVERAGE", False, boolean=True):
            xenrt.TEC().logverbose("Enabling code coverage collection...")
            for m in self.allManagementServers:
                if m.execcmd("ls %s/setup_codecoverage.sh" % self.installDir,
                             retval="code") != 0:
                    raise xenrt.XRTError(
                        "CCP_CODE_COVERAGE set but setup_codecoverage.sh not found in build"
                    )
                m.execcmd("cd %s && ./setup_codecoverage.sh" % self.installDir)
            self.restart()
            xenrt.TEC().logverbose("...done")

        commit = None
        try:
            commit = self.primaryManagementServer.execcmd(
                "cloudstack-sccs").strip()
            xenrt.TEC().logverbose(
                "Management server was built from commit %s" % commit)
        except:
            xenrt.TEC().warning(
                "Error when trying to identify management server version")
        if commit:
            expectedCommit = xenrt.getCCPCommit(
                self.primaryManagementServer.distro)
            if expectedCommit and commit != expectedCommit:
                raise xenrt.XRTError(
                    "Management server commit %s does not match expected commit %s"
                    % (commit, expectedCommit))