rv_build_install.py 11.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
"""
rv_build_install.py - Builds and installs packages specified
                      using the build_install.py script

Requires: connected binaries remote-viewer, Xorg, gnome session, git

"""
import logging
import os
import time
import re
from autotest.client.shared import error
13
from virttest.aexpect import ShellCmdError
14
from virttest import utils_misc, utils_spice, data_dir
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33


def connect_to_vm(vm_name, env, params):
    """
    Connects to VM and powers it on and gets session information

    :param vm_name: name of VM to connect to
    :param params: Dictionary with test parameters.
    :param env: Test environment.
    """

    vm = env.get_vm(params[vm_name + "_vm"])
    vm.verify_alive()
    vm_root_session = vm.wait_for_login(
        timeout=int(params.get("login_timeout", 360)),
        username="root", password="123456")
    logging.info("VM %s is up and running" % vm_name)
    return (vm, vm_root_session)

34

35
def install_req_pkgs(pkgsRequired, vm_root_session, params):
36
    """
C
Chris Evich 已提交
37
    Checks to see if packages are installed and if not, installs the package
38 39 40 41 42 43 44

    :params rpms_to_install: List of packages to check
    :params vm_root_session: Session object of VM
    :param params: Dictionary with test parameters.
    """

    for pkgName in pkgsRequired:
45 46 47 48 49
        logging.info("Checking to see if %s is installed" % pkgName)
        try:
            vm_root_session.cmd("rpm -q %s" % pkgName)
        except ShellCmdError:
            rpm = params.get(re.sub("-", "_", pkgName) + "_url")
50
            logging.info("Installing %s from %s" % (pkgName, rpm))
51
            try:
52 53
                vm_root_session.cmd("yum -y localinstall %s" % rpm,
                                    timeout=300)
54 55
            except ShellCmdError:
                logging.info("Could not install %s" % pkgName)
56

57

58 59 60 61 62 63 64 65 66
def build_install_spiceprotocol(vm_root_session, vm_script_path, params):
    """
    Build and install spice-protocol in the VM

    :param vm_root_session:  VM Session object.
    :param vm_script_path: path where to find build_install.py script
    :param params: Dictionary with test parameters.
    """

67 68 69 70 71 72 73 74 75 76 77 78 79
    utils_spice.deploy_epel_repo(vm_root_session, params)

    # In RHEL6, pyparsing is in EPEL but in RHEL7, it's part of
    # the main product repo
    if "release 6" in vm_root_session.cmd("cat /etc/redhat-release"):
        try:
            cmd = "yum --disablerepo=\"*\" " + \
                  "--enablerepo=\"epel\" -y install pyparsing"
            output = vm_root_session.cmd(cmd, timeout=300)
            logging.info(output)
        except ShellCmdError:
            logging.error("Not able to install pyparsing!")

80 81 82 83 84 85
    output = vm_root_session.cmd("%s -p spice-protocol" % (vm_script_path))
    logging.info(output)
    if re.search("Return code", output):
        raise error.TestFail("spice-protocol was not installed properly")


86 87 88 89 90 91 92 93 94
def build_install_qxl(vm_root_session, vm_script_path, params):
    """
    Build and install QXL in the VM

    :param vm_root_session:  VM Session object.
    :param vm_script_path: path where to find build_install.py script
    :param params: Dictionary with test parameters.
    """

95
    # Checking to see if required packages exist and if not, install them
96
    pkgsRequired = ["libpciaccess-devel", "xorg-x11-util-macros",
97 98
                    "xorg-x11-server-devel", "libfontenc-devel",
                    "libXfont-devel"]
99
    install_req_pkgs(pkgsRequired, vm_root_session, params)
100

101 102
    output = vm_root_session.cmd("%s -p xf86-video-qxl" % (vm_script_path),
                                 timeout=600)
103 104 105 106
    logging.info(output)
    if re.search("Return code", output):
        raise error.TestFail("qxl was not installed properly")

107

S
swapnakrishnan2k 已提交
108 109 110 111 112 113 114 115 116
def build_install_virtviewer(vm_root_session, vm_script_path, params):
    """
    Build and install virt-viewer in the VM

    :param vm_root_session:  VM Session object.
    :param vm_script_path: path where to find build_install.py script
    :param params: Dictionary with test parameters.
    """

117 118 119
    # Building spice-gtk from tarball before building virt-viewer
    build_install_spicegtk(vm_root_session, vm_script_path, params)

S
swapnakrishnan2k 已提交
120 121 122 123 124 125
    try:
        output = vm_root_session.cmd("killall remote-viewer")
        logging.info(output)
    except ShellCmdError, err:
        logging.error("Could not kill remote-viewer " + err.output)

S
swapnakrishnan2k 已提交
126
    try:
127
        output = vm_root_session.cmd("yum -y remove virt-viewer", timeout=120)
S
swapnakrishnan2k 已提交
128
        logging.info(output)
S
swapnakrishnan2k 已提交
129 130
    except ShellCmdError, err:
        logging.error("virt-viewer package couldn't be removed! " + err.output)
S
swapnakrishnan2k 已提交
131

132
    if "release 7" in vm_root_session.cmd("cat /etc/redhat-release"):
133
        pkgsRequired = ["libogg-devel", "celt051-devel",
134 135
                        "spice-glib-devel", "spice-gtk3-devel"]
    else:
136
        pkgsRequired = ["libogg-devel", "celt051-devel"]
137

S
swapnakrishnan2k 已提交
138 139 140 141 142 143 144 145 146 147 148 149
    install_req_pkgs(pkgsRequired, vm_root_session, params)

    output = vm_root_session.cmd("%s -p virt-viewer" % (vm_script_path),
                                 timeout=600)
    logging.info(output)
    if re.search("Return code", output):
        raise error.TestFail("virt-viewer was not installed properly")

    # Get version of remote-viewer after install
    try:
        output = vm_root_session.cmd("which remote-viewer")
        logging.info(output)
S
swapnakrishnan2k 已提交
150 151
    except ShellCmdError, err:
        raise error.TestFail("Could not find remote-viewer")
S
swapnakrishnan2k 已提交
152 153

    try:
154
        output = vm_root_session.cmd("LD_LIBRARY_PATH=/usr/local/lib remote-viewer --version")
S
swapnakrishnan2k 已提交
155
        logging.info(output)
S
swapnakrishnan2k 已提交
156 157
    except ShellCmdError, err:
        logging.error("Can't get version number!" + err.output)
S
swapnakrishnan2k 已提交
158 159


160 161 162 163 164 165 166 167 168 169
def build_install_spicegtk(vm_root_session, vm_script_path, params):
    """
    Build and install spice-gtk in the VM

    :param vm_root_session:  VM Session object.
    :param vm_script_path: path where to find build_install.py script
    :param params: Dictionary with test parameters.
    """

    # Get version of spice-gtk before install
170
    try:
171 172
        output = vm_root_session.cmd("LD_LIBRARY_PATH=/usr/local/lib"
                                     " remote-viewer --spice-gtk-version")
173
        logging.info(output)
174 175
    except ShellCmdError:
        logging.error(output)
176

177 178 179 180 181 182
    if "release 7" in vm_root_session.cmd("cat /etc/redhat-release"):
        pkgsRequired = ["libogg-devel", "celt051-devel", "libcacard-devel",
                        "source-highlight", "gtk-doc"]
    else:
        pkgsRequired = ["libogg-devel", "celt051-devel", "libcacard-devel"]

183
    install_req_pkgs(pkgsRequired, vm_root_session, params)
184

185
    try:
186 187 188
        cmd = "yum --disablerepo=\"*\" " + \
              "--enablerepo=\"epel\" -y install perl-Text-CSV"
        output = vm_root_session.cmd(cmd, timeout=300)
189 190 191
        logging.info(output)
    except ShellCmdError:
        logging.error(output)
192

193 194 195
    # spice-gtk needs to built from tarball before building virt-viewer on RHEL6
    pkgName = params.get("build_install_pkg")
    if pkgName != "spice-gtk":
196
        tarballLocation = "http://www.spice-space.org/download/gtk/spice-gtk-0.29.tar.bz2"
197 198 199 200 201 202 203 204 205 206 207 208 209 210
        cmd = "%s -p spice-gtk --tarball %s" % (vm_script_path, tarballLocation)
        output = vm_root_session.cmd(cmd, timeout=600)
        logging.info(output)
        if re.search("Return code", output):
            raise error.TestFail("spice-gtk was not installed properly")
        else:
            logging.info("spice-gtk was installed")

    else:
        output = vm_root_session.cmd("%s -p spice-gtk" % (vm_script_path),
                                     timeout=600)
        logging.info(output)
        if re.search("Return code", output):
            raise error.TestFail("spice-gtk was not installed properly")
211 212

    # Get version of spice-gtk after install
213
    try:
214 215
        output = vm_root_session.cmd("LD_LIBRARY_PATH=/usr/local/lib"
                                     " remote-viewer --spice-gtk-version")
216
        logging.info(output)
217 218
    except ShellCmdError:
        logging.error(output)
219

220

221 222 223 224 225 226 227 228 229 230
def build_install_vdagent(vm_root_session, vm_script_path, params):
    """
    Build and install spice-vdagent in the VM

    :param vm_root_session: VM Session object.
    :param vm_script_path: path where to find build_install.py script
    :param params: Dictionary with test parameters.
    """

    # Get current version of spice-vdagent
231 232 233 234 235
    try:
        output = vm_root_session.cmd("spice-vdagent -h")
        logging.info(output)
    except ShellCmdError:
        logging.error(output)
236 237

    pkgsRequired = ["libpciaccess-devel"]
238
    install_req_pkgs(pkgsRequired, vm_root_session, params)
239

240 241
    output = vm_root_session.cmd("%s -p spice-vd-agent" % (vm_script_path),
                                 timeout=600)
242 243 244 245 246
    logging.info(output)
    if re.search("Return code", output):
        raise error.TestFail("spice-vd-agent was not installed properly")

    # Restart vdagent
247 248 249 250 251 252
    try:
        output = vm_root_session.cmd("service spice-vdagentd restart")
        logging.info(output)
        if re.search("fail", output, re.IGNORECASE):
            raise error.TestFail("spice-vd-agent was not started properly")
    except ShellCmdError:
253 254 255
        raise error.TestFail("spice-vd-agent was not started properly")

    # Get version number of spice-vdagent
256 257 258 259 260
    try:
        output = vm_root_session.cmd("spice-vdagent -h")
        logging.info(output)
    except ShellCmdError:
        logging.error(output)
261

262

263
def run(test, params, env):
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    """
    Build and install packages from git on the client or guest VM

    Supported configurations:
    build_install_pkg: name of the package to get from git, build and install

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """

    # Collect test parameters
    pkgName = params.get("build_install_pkg")
    script = params.get("script")
    vm_name = params.get("vm_name")
    dst_dir = params.get("dst_dir")

    # Path of the script on the VM
    vm_script_path = os.path.join(dst_dir, script)

    # Get root session for the VM
    (vm, vm_root_session) = connect_to_vm(vm_name, env, params)

    # location of the script on the host
288
    host_script_path = os.path.join(data_dir.get_deps_dir(), "spice", script)
289 290 291 292 293 294 295 296

    logging.info("Transferring the script to %s,"
                 "destination directory: %s, source script location: %s",
                 vm_name, vm_script_path, host_script_path)

    vm.copy_files_to(host_script_path, vm_script_path, timeout=60)
    time.sleep(5)

297 298 299
    # All packages require spice-protocol
    build_install_spiceprotocol(vm_root_session, vm_script_path, params)

300 301 302 303 304 305 306
    # Run build_install.py script
    if pkgName == "xf86-video-qxl":
        build_install_qxl(vm_root_session, vm_script_path, params)
    elif pkgName == "spice-vd-agent":
        build_install_vdagent(vm_root_session, vm_script_path, params)
    elif pkgName == "spice-gtk":
        build_install_spicegtk(vm_root_session, vm_script_path, params)
S
swapnakrishnan2k 已提交
307 308
    elif pkgName == "virt-viewer":
        build_install_virtviewer(vm_root_session, vm_script_path, params)
309 310 311 312
    else:
        logging.info("Not supported right now")
        raise error.TestFail("Incorrect Test_Setup")

313
    utils_spice.clear_interface(vm)