Skip to content

Commit 74fbe0c

Browse files
author
Satheesh Rajendran
committed
Added support Libvirt package build test
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>
1 parent ea1b4b8 commit 74fbe0c

File tree

5 files changed

+185
-5
lines changed

5 files changed

+185
-5
lines changed

shared/cfg/base.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,9 @@ libvirtd_debug_file = ""
660660
enable_host_sosreport = "no"
661661
enable_remote_host_sosreport = "no"
662662

663+
# libvirt installer default options
664+
rpmbuild_path = "/root/rpmbuild/"
665+
663666
Linux:
664667
# param for stress tests
665668
stress_args = '--cpu 4 --io 4 --vm 2 --vm-bytes 256M'

virttest/base_installer.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self, mode, name, test=None, params=None):
7474
self.mode = mode
7575
self.name = name
7676
self.params = params
77+
self.test = test
7778
self.param_key_prefix = '%s_%s' % (self.mode,
7879
self.name)
7980

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

87-
def _set_test_dirs(self, test):
88+
def _set_test_dirs(self, test, params=None):
8889
"""
8990
Save common test directories paths as class attributes
9091
@@ -107,8 +108,12 @@ def _set_test_dirs(self, test):
107108
* resultsdir = results/<job>/kvm.<other_variant_names>.build/results
108109
"""
109110
self.test_bindir = test.bindir
110-
self.test_workdir = test.workdir
111-
self.test_builddir = test.builddir
111+
if params.get("preserve_srcdir") == "yes":
112+
self.test_workdir = os.path.join(test.bindir, "build")
113+
self.test_builddir = os.path.join(test.bindir, "bin")
114+
else:
115+
self.test_workdir = test.workdir
116+
self.test_builddir = test.builddir
112117
self.test_resultsdir = test.resultsdir
113118

114119
#
@@ -184,7 +189,7 @@ def set_install_params(self, test=None, params=None):
184189
"""
185190
logging.info("calling set install params")
186191
if test is not None:
187-
self._set_test_dirs(test)
192+
self._set_test_dirs(test, params)
188193

189194
if params is not None:
190195
self.params = params
@@ -324,6 +329,21 @@ def _install_phase_init_verify(self):
324329
"""
325330
pass
326331

332+
def _install_phase_package(self):
333+
"""
334+
"""
335+
pass
336+
337+
def _install_phase_package_verify(self):
338+
'''
339+
Optional install phase for checking that software is packaged.
340+
341+
This should verify that the packages are actually created. Ideas for
342+
using this include:
343+
* checking /root/rpmbuild/RPMS'
344+
'''
345+
pass
346+
327347
def write_version_keyval(self, test):
328348
try:
329349
version = self.get_version()
@@ -380,7 +400,7 @@ def reload_modules_if_needed(self):
380400
self.reload_modules()
381401

382402
def install(self, cleanup=True, download=True, prepare=True,
383-
build=True, install=True, init=True):
403+
build=True, install=True, package=False, init=True):
384404
"""
385405
Performs the installation of the virtualization software
386406
@@ -404,6 +424,10 @@ def install(self, cleanup=True, download=True, prepare=True,
404424
self._install_phase_build()
405425
self._install_phase_build_verify()
406426

427+
if package:
428+
self._install_phase_package()
429+
self._install_phase_package_verify()
430+
407431
if install:
408432
self._install_phase_install()
409433
self._install_phase_install_verify()
@@ -482,6 +506,10 @@ def _install_phase_cleanup(self):
482506
packages_to_remove = " ".join(self.yum_pkgs)
483507
process.system("yum remove -y %s" % packages_to_remove)
484508

509+
def _install_phase_package(self):
510+
if self.build_helper is not None:
511+
self.build_helper.package()
512+
485513
def _install_phase_install(self):
486514
if self.yum_pkgs:
487515
os.chdir(self.test_workdir)

virttest/build_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@ def make_install(self):
688688

689689
install = make_install
690690

691+
def make_rpm(self):
692+
"""
693+
Run "make rpm"
694+
"""
695+
os.chdir(self.build_dir)
696+
process.system("make rpm")
697+
698+
package = make_rpm
699+
691700
def execute(self):
692701
"""
693702
Runs appropriate steps for *building* this source code tree

virttest/installer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from . import base_installer
1212
from . import qemu_installer
13+
from . import libvirt_installer
1314

1415
__all__ = ['InstallerRegistry', 'INSTALLER_REGISTRY', 'make_installer',
1516
'run_installers']
@@ -133,6 +134,10 @@ def get_modes(self, virt=None):
133134
qemu_installer.RemoteSourceTarInstaller,
134135
'qemu')
135136

137+
INSTALLER_REGISTRY.register('git_repo',
138+
libvirt_installer.GitRepoInstaller,
139+
'libvirt')
140+
136141

137142
def installer_name_split(fullname, virt=None):
138143
"""

virttest/libvirt_installer.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
"""
2+
Installer code that implement KVM specific bits.
3+
4+
See BaseInstaller class in base_installer.py for interface details.
5+
"""
6+
7+
import os
8+
import platform
9+
import logging
10+
11+
from avocado.utils import process
12+
from virttest import base_installer
13+
14+
15+
__all__ = ['GitRepoInstaller', 'LocalSourceDirInstaller',
16+
'LocalSourceTarInstaller', 'RemoteSourceTarInstaller']
17+
18+
19+
class LIBVIRTBaseInstaller(base_installer.BaseInstaller):
20+
21+
'''
22+
Base class for libvirt installations
23+
'''
24+
25+
def _set_install_prefix(self):
26+
"""
27+
Prefix for installation of application built from source
28+
29+
When installing virtualization software from *source*, this is where
30+
the resulting binaries will be installed. Usually this is the value
31+
passed to the configure script, ie: ./configure --prefix=<value>
32+
"""
33+
prefix = self.test_builddir
34+
self.install_prefix = os.path.abspath(prefix)
35+
36+
def _install_phase_package(self):
37+
"""
38+
Create libvirt package
39+
"""
40+
self.rpmbuild_path = self.params.get("rpmbuild_path", "/root/rpmbuild/")
41+
if os.path.isdir(self.rpmbuild_path):
42+
process.system("rm -rf %s/*" % self.rpmbuild_path)
43+
logging.debug("Build libvirt rpms")
44+
process.system("make rpm", allow_output_check="combined")
45+
46+
def _install_phase_package_verify(self):
47+
"""
48+
Check if rpms are generated
49+
"""
50+
logging.debug("Check for libvirt rpms")
51+
found = False
52+
for fl in os.listdir('%s/RPMS/%s/' % (self.rpmbuild_path,
53+
platform.machine())):
54+
if fl.endswith('.rpm'):
55+
found = True
56+
if not found:
57+
self.test.fail("Failed to build rpms")
58+
59+
def _install_phase_install(self):
60+
"""
61+
Install libvirt package
62+
"""
63+
logging.debug("Install libvirt rpms")
64+
package_install_cmd = "rpm -Uvh --nodeps --replacepkgs"
65+
package_install_cmd += " --replacefiles --oldpackage"
66+
package_install_cmd += " %s/RPMS/%s/libvirt*" % (self.rpmbuild_path,
67+
platform.machine())
68+
process.system(package_install_cmd, allow_output_check="combined")
69+
70+
def _install_phase_init(self):
71+
"""
72+
Initializes the built and installed software
73+
74+
:return: None
75+
"""
76+
logging.debug("Initialize installed libvirt package")
77+
process.system("service libvirtd restart", allow_output_check="combined")
78+
79+
def _install_phase_init_verify(self):
80+
"""
81+
Check if package install is success
82+
83+
:return: None
84+
"""
85+
logging.debug("Check libvirt package install")
86+
process.system("service libvirtd status", allow_output_check="combined")
87+
process.system("virsh capabilities", allow_output_check="combined")
88+
89+
def uninstall(self):
90+
'''
91+
Performs the uninstallation of KVM userspace component
92+
93+
:return: None
94+
'''
95+
self._cleanup_links()
96+
super(LIBVIRTBaseInstaller, self).uninstall()
97+
98+
def install(self):
99+
super(LIBVIRTBaseInstaller, self).install(package=True)
100+
101+
102+
class GitRepoInstaller(LIBVIRTBaseInstaller,
103+
base_installer.GitRepoInstaller):
104+
105+
'''
106+
Installer that deals with source code on Git repositories
107+
'''
108+
pass
109+
110+
111+
class LocalSourceDirInstaller(LIBVIRTBaseInstaller,
112+
base_installer.LocalSourceDirInstaller):
113+
114+
"""
115+
Installer that deals with source code on local directories
116+
"""
117+
pass
118+
119+
120+
class LocalSourceTarInstaller(LIBVIRTBaseInstaller,
121+
base_installer.LocalSourceTarInstaller):
122+
123+
"""
124+
Installer that deals with source code on local tarballs
125+
"""
126+
pass
127+
128+
129+
class RemoteSourceTarInstaller(LIBVIRTBaseInstaller,
130+
base_installer.RemoteSourceTarInstaller):
131+
132+
"""
133+
Installer that deals with source code on remote tarballs
134+
"""
135+
pass

0 commit comments

Comments
 (0)