Skip to content

Commit

Permalink
Added support Libvirt package build test
Browse files Browse the repository at this point in the history
The patch implements the build capability for avocado-vt for libvirt sources
from the git repository. The implemention is to get libvirt git repo and make
binaries and build rpms and install as part of the build test.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>
  • Loading branch information
Satheesh Rajendran committed Oct 4, 2018
1 parent ea1b4b8 commit 74fbe0c
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 5 deletions.
3 changes: 3 additions & 0 deletions shared/cfg/base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ libvirtd_debug_file = ""
enable_host_sosreport = "no"
enable_remote_host_sosreport = "no"

# libvirt installer default options
rpmbuild_path = "/root/rpmbuild/"

Linux:
# param for stress tests
stress_args = '--cpu 4 --io 4 --vm 2 --vm-bytes 256M'
Expand Down
38 changes: 33 additions & 5 deletions virttest/base_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, mode, name, test=None, params=None):
self.mode = mode
self.name = name
self.params = params
self.test = test
self.param_key_prefix = '%s_%s' % (self.mode,
self.name)

Expand All @@ -84,7 +85,7 @@ def __init__(self, mode, name, test=None, params=None):
if test and params:
self.set_install_params(test, params)

def _set_test_dirs(self, test):
def _set_test_dirs(self, test, params=None):
"""
Save common test directories paths as class attributes
Expand All @@ -107,8 +108,12 @@ def _set_test_dirs(self, test):
* resultsdir = results/<job>/kvm.<other_variant_names>.build/results
"""
self.test_bindir = test.bindir
self.test_workdir = test.workdir
self.test_builddir = test.builddir
if params.get("preserve_srcdir") == "yes":
self.test_workdir = os.path.join(test.bindir, "build")
self.test_builddir = os.path.join(test.bindir, "bin")
else:
self.test_workdir = test.workdir
self.test_builddir = test.builddir
self.test_resultsdir = test.resultsdir

#
Expand Down Expand Up @@ -184,7 +189,7 @@ def set_install_params(self, test=None, params=None):
"""
logging.info("calling set install params")
if test is not None:
self._set_test_dirs(test)
self._set_test_dirs(test, params)

if params is not None:
self.params = params
Expand Down Expand Up @@ -324,6 +329,21 @@ def _install_phase_init_verify(self):
"""
pass

def _install_phase_package(self):
"""
"""
pass

def _install_phase_package_verify(self):
'''
Optional install phase for checking that software is packaged.
This should verify that the packages are actually created. Ideas for
using this include:
* checking /root/rpmbuild/RPMS'
'''
pass

def write_version_keyval(self, test):
try:
version = self.get_version()
Expand Down Expand Up @@ -380,7 +400,7 @@ def reload_modules_if_needed(self):
self.reload_modules()

def install(self, cleanup=True, download=True, prepare=True,
build=True, install=True, init=True):
build=True, install=True, package=False, init=True):
"""
Performs the installation of the virtualization software
Expand All @@ -404,6 +424,10 @@ def install(self, cleanup=True, download=True, prepare=True,
self._install_phase_build()
self._install_phase_build_verify()

if package:
self._install_phase_package()
self._install_phase_package_verify()

if install:
self._install_phase_install()
self._install_phase_install_verify()
Expand Down Expand Up @@ -482,6 +506,10 @@ def _install_phase_cleanup(self):
packages_to_remove = " ".join(self.yum_pkgs)
process.system("yum remove -y %s" % packages_to_remove)

def _install_phase_package(self):
if self.build_helper is not None:
self.build_helper.package()

def _install_phase_install(self):
if self.yum_pkgs:
os.chdir(self.test_workdir)
Expand Down
9 changes: 9 additions & 0 deletions virttest/build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,15 @@ def make_install(self):

install = make_install

def make_rpm(self):
"""
Run "make rpm"
"""
os.chdir(self.build_dir)
process.system("make rpm")

package = make_rpm

def execute(self):
"""
Runs appropriate steps for *building* this source code tree
Expand Down
5 changes: 5 additions & 0 deletions virttest/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from . import base_installer
from . import qemu_installer
from . import libvirt_installer

__all__ = ['InstallerRegistry', 'INSTALLER_REGISTRY', 'make_installer',
'run_installers']
Expand Down Expand Up @@ -133,6 +134,10 @@ def get_modes(self, virt=None):
qemu_installer.RemoteSourceTarInstaller,
'qemu')

INSTALLER_REGISTRY.register('git_repo',
libvirt_installer.GitRepoInstaller,
'libvirt')


def installer_name_split(fullname, virt=None):
"""
Expand Down
135 changes: 135 additions & 0 deletions virttest/libvirt_installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"""
Installer code that implement KVM specific bits.
See BaseInstaller class in base_installer.py for interface details.
"""

import os
import platform
import logging

from avocado.utils import process
from virttest import base_installer


__all__ = ['GitRepoInstaller', 'LocalSourceDirInstaller',
'LocalSourceTarInstaller', 'RemoteSourceTarInstaller']


class LIBVIRTBaseInstaller(base_installer.BaseInstaller):

'''
Base class for libvirt installations
'''

def _set_install_prefix(self):
"""
Prefix for installation of application built from source
When installing virtualization software from *source*, this is where
the resulting binaries will be installed. Usually this is the value
passed to the configure script, ie: ./configure --prefix=<value>
"""
prefix = self.test_builddir
self.install_prefix = os.path.abspath(prefix)

def _install_phase_package(self):
"""
Create libvirt package
"""
self.rpmbuild_path = self.params.get("rpmbuild_path", "/root/rpmbuild/")
if os.path.isdir(self.rpmbuild_path):
process.system("rm -rf %s/*" % self.rpmbuild_path)
logging.debug("Build libvirt rpms")
process.system("make rpm", allow_output_check="combined")

def _install_phase_package_verify(self):
"""
Check if rpms are generated
"""
logging.debug("Check for libvirt rpms")
found = False
for fl in os.listdir('%s/RPMS/%s/' % (self.rpmbuild_path,
platform.machine())):
if fl.endswith('.rpm'):
found = True
if not found:
self.test.fail("Failed to build rpms")

def _install_phase_install(self):
"""
Install libvirt package
"""
logging.debug("Install libvirt rpms")
package_install_cmd = "rpm -Uvh --nodeps --replacepkgs"
package_install_cmd += " --replacefiles --oldpackage"
package_install_cmd += " %s/RPMS/%s/libvirt*" % (self.rpmbuild_path,
platform.machine())
process.system(package_install_cmd, allow_output_check="combined")

def _install_phase_init(self):
"""
Initializes the built and installed software
:return: None
"""
logging.debug("Initialize installed libvirt package")
process.system("service libvirtd restart", allow_output_check="combined")

def _install_phase_init_verify(self):
"""
Check if package install is success
:return: None
"""
logging.debug("Check libvirt package install")
process.system("service libvirtd status", allow_output_check="combined")
process.system("virsh capabilities", allow_output_check="combined")

def uninstall(self):
'''
Performs the uninstallation of KVM userspace component
:return: None
'''
self._cleanup_links()
super(LIBVIRTBaseInstaller, self).uninstall()

def install(self):
super(LIBVIRTBaseInstaller, self).install(package=True)


class GitRepoInstaller(LIBVIRTBaseInstaller,
base_installer.GitRepoInstaller):

'''
Installer that deals with source code on Git repositories
'''
pass


class LocalSourceDirInstaller(LIBVIRTBaseInstaller,
base_installer.LocalSourceDirInstaller):

"""
Installer that deals with source code on local directories
"""
pass


class LocalSourceTarInstaller(LIBVIRTBaseInstaller,
base_installer.LocalSourceTarInstaller):

"""
Installer that deals with source code on local tarballs
"""
pass


class RemoteSourceTarInstaller(LIBVIRTBaseInstaller,
base_installer.RemoteSourceTarInstaller):

"""
Installer that deals with source code on remote tarballs
"""
pass

0 comments on commit 74fbe0c

Please sign in to comment.