Skip to content

Commit 7d53256

Browse files
authored
Merge pull request #311 from AdamWill/fix-tests-py3
Fix oz with recent Python, fix a major bug with `useuefi` arg, fix up some issues in the tests, add support for running tests in containers, add a Github Action workflow for CI
2 parents 88700f3 + c59c341 commit 7d53256

21 files changed

+298
-156
lines changed

.github/workflows/ci.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Run CI checks
3+
4+
on: [pull_request]
5+
6+
jobs:
7+
unittests-fedora:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout the repo
11+
uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- name: Install make and docker
15+
run: apt-get install make docker docker.io
16+
- name: Run the tests
17+
run: make container-unittests-fedora
18+
unittests-el7:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout the repo
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Install make and docker
26+
run: apt-get install make docker
27+
- name: Run the tests
28+
run: make container-unittests-el7
29+
lint:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout the repo
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
- name: Install make, pylint and flake8
37+
run: apt-get install make pylint flake8
38+
- name: Run pylint
39+
run: make pylint
40+
- name: Run flake8
41+
run: make flake8

.travis.yml

-33
This file was deleted.

Containerfile.tests.el7

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# this container definition is intended *only* for running the oz test suite, it is not
2+
# a general-purpose oz container definition!
3+
4+
FROM quay.io/centos/centos:7
5+
RUN set -exo pipefail \
6+
&& yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
7+
&& yum install -y python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic libvirt \
8+
&& yum clean all \
9+
&& rm -rf /var/cache/* /var/log/yum*
10+
11+
COPY ./ /oz
12+
# the XML generation tests are inherently unreliable before Python 3.8,
13+
# as there was no consistent ordering of XML element attributes. See
14+
# https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring
15+
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npy.test -vv -k 'not test_xml_generation and not modify_libvirt_xml_for_serial' tests/" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
16+
CMD /usr/local/bin/runtests.sh

Containerfile.tests.fedora

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# this container definition is intended *only* for running the oz test suite, it is not
2+
# a general-purpose oz container definition!
3+
4+
FROM quay.io/fedora/fedora:latest
5+
RUN set -exo pipefail \
6+
&& dnf install -y --setopt install_weak_deps=false --nodocs \
7+
python3-requests python3-m2crypto python3-setuptools python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-monotonic \
8+
libvirt-daemon libvirt-daemon-kvm libvirt-daemon-qemu libvirt-daemon-config-network systemd \
9+
&& dnf clean all \
10+
&& rm -rf /var/cache/* /var/log/dnf*
11+
12+
COPY ./ /oz
13+
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npy.test -vv tests/" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
14+
CMD /usr/local/bin/runtests.sh

Makefile

+20-3
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,35 @@ unittests:
4646

4747
tests: unittests
4848

49+
container-unittests-fedora:
50+
docker rm -f oz-tests-fedora
51+
docker build -f Containerfile.tests.fedora -t oz-tests-fedora-image .
52+
docker run --name oz-tests-fedora oz-tests-fedora-image
53+
54+
container-unittests-el7:
55+
docker rm -f oz-tests-el7
56+
docker build -f Containerfile.tests.el7 -t oz-tests-el7-image .
57+
docker run --name oz-tests-el7 oz-tests-el7-image
58+
59+
container-unittests: container-unittests-fedora container-unittests-el7
60+
4961
test-coverage:
5062
python-coverage run --source oz /usr/bin/py.test --verbose tests
5163
python-coverage html
5264
xdg-open htmlcov/index.html
5365

5466
pylint:
55-
pylint-3 --rcfile=pylint.conf oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
67+
pylint --rcfile=pylint.conf oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
5668

5769
flake8:
58-
flake8-3 --ignore=E501 oz
70+
flake8 --ignore=E501 oz
71+
72+
container-clean:
73+
docker rm -f oz-tests-fedora
74+
docker rm -f oz-tests-el7
75+
docker image rm -f -i oz-tests-fedora-image oz-tests-el7-image
5976

6077
clean:
6178
rm -rf MANIFEST build dist usr *~ oz.spec *.pyc oz/*~ oz/*.pyc examples/*~ oz/auto/*~ man/*~ docs/*~ man/*.html $(VENV_DIR) tests/tdl/*~ tests/factory/*~ tests/results.xml htmlcov
6279

63-
.PHONY: sdist oz.spec signed-tarball signed-rpm rpm srpm deb release man2html virtualenv unittests tests test-coverage pylint clean
80+
.PHONY: sdist oz.spec signed-tarball signed-rpm rpm srpm deb release man2html virtualenv unittests container-unittests-fedora container-unittests-el7 container-unittests tests test-coverage pylint clean container-clean

README

+33
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,40 @@ images containing an operating systems and, optionally, programs.
44

55
The best way to install it is to make an RPM out of it by running "make rpm"
66
or "make srpm", and then installing the resulting RPM on the target machine.
7+
This will probably only work on Fedora or on RHEL 8 or later.
78

89
Once you have the RPM installed, you will need to build up TDL files to feed
910
as input into the building process. Please see the examples directory to get
1011
an idea of what a TDL file looks like.
12+
13+
You can run the oz unit tests in containers by installing make and docker
14+
(or podman-docker), then running:
15+
16+
make container-unittests
17+
18+
You can clean up the containers and images by running:
19+
20+
make container-clean
21+
22+
Otherwise, you can try running the tests directly on your host, but oz uses the
23+
guestfs Python module, which is not available from pypi, and needs a running
24+
libvirtd for most of the tests to run. To install all the test requirements on
25+
Fedora:
26+
27+
dnf install python3-requests python3-m2crypto python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-monotonic
28+
29+
If you wish to test on EL 7, make that:
30+
31+
yum install python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic
32+
33+
then run the tests:
34+
35+
py.test tests/
36+
37+
You can try `make virtualenv` then `make unittests` to run the tests in a
38+
virtualenv if you like, but this still requires at least the libguestfs library
39+
installed on the host, and a running libvirtd. You may also want to install
40+
m2crypto and libvirt libraries on the host, as otherwise pip will have to
41+
compile them, and you'll need their build dependencies.
42+
43+
You can use `make pylint` and `make flake8` to run lint checks.

oz.spec.in

+19-22
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
Summary: Library and utilities for automated guest OS installs
2-
Name: oz
1+
Name: oz
32
Version: @VERSION@
43
Release: @RELEASE@%{?dist}
4+
Summary: Library and utilities for automated guest OS installs
55
License: LGPLv2
6-
Group: Development/Libraries
7-
URL: http://github.com/clalancette/oz
8-
Source0: http://github.com/clalancette/%{name}/archive/%{name}-%{version}.tar.gz
6+
URL: http://github.com/clalancette/oz
7+
8+
Source0: https://github.com/clalancette/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz
9+
910
BuildArch: noarch
11+
12+
BuildRequires: python3
13+
BuildRequires: python3-devel
14+
BuildRequires: python3-setuptools
1015
Requires: python3
11-
Requires: python3-libguestfs >= 1.18
1216
Requires: python3-lxml
17+
Requires: python3-libguestfs >= 1.18
1318
Requires: python3-libvirt
19+
Requires: python3-m2crypto
20+
Requires: python3-monotonic
21+
Requires: python3-requests
1422
# in theory, oz doesn't really require libvirtd to be local to operate
1523
# properly. However, because of the libguestfs manipulations, in practice
1624
# it really does. Make it depend on libvirt (so we get libvirtd) for now,
1725
# unless/until we are able to make it really be remote.
18-
%if 0%{?fedora} >= 17
1926
Requires: libvirt-daemon-kvm
2027
Requires: libvirt-daemon-qemu
2128
Requires: libvirt-daemon-config-network
22-
%else
23-
Requires: libvirt >= 0.9.7
24-
%endif
25-
Requires: python3-requests
2629
Requires: genisoimage
2730
Requires: mtools
28-
%if 0%{?fedora} < 26 or 0%{?rhel} < 8
29-
Requires: python-uuid
30-
%endif
3131
Requires: openssh-clients
32-
Requires: python3-m2crypto
33-
Requires: python3-monotonic
34-
35-
BuildRequires: python3
3632

3733
%description
3834
Oz is a set of libraries and utilities for doing automated guest OS
3935
installations, with minimal input from the user.
4036

4137
%prep
42-
%setup -q
38+
%autosetup -p1
4339

4440
%build
4541
%py3_build
@@ -66,7 +62,8 @@ if [ ! -f %{_sysconfdir}/oz/id_rsa-icicle-gen ]; then
6662
fi
6763

6864
%files
69-
%doc README COPYING examples
65+
%license COPYING
66+
%doc README examples
7067
%dir %attr(0755, root, root) %{_sysconfdir}/oz/
7168
%config(noreplace) %{_sysconfdir}/oz/oz.cfg
7269
%dir %attr(0755, root, root) %{_localstatedir}/lib/oz/
@@ -78,13 +75,13 @@ fi
7875
%dir %attr(0755, root, root) %{_localstatedir}/lib/oz/jeos/
7976
%dir %attr(0755, root, root) %{_localstatedir}/lib/oz/kernels/
8077
%dir %attr(0755, root, root) %{_localstatedir}/lib/oz/screenshots/
81-
%{python3_sitelib}/oz
8278
%{_bindir}/oz-install
8379
%{_bindir}/oz-generate-icicle
8480
%{_bindir}/oz-customize
8581
%{_bindir}/oz-cleanup-cache
86-
%{python3_sitelib}/%{name}-%{version}-py%{python3_version}.egg-info
8782
%{_mandir}/man1/*
83+
%{python3_sitelib}/oz
84+
%{python3_sitelib}/%{name}*.egg-info
8885

8986
%changelog
9087
* Sat Feb 5 2022 Peter Robinson <[email protected]> - 0.18.0-1

oz/Fedora.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class FedoraGuest(oz.RedHat.RedHatLinuxCDYumGuest):
248248
# ignored now; we leave it in place for backwards API compatibility.
249249
def __init__(self, tdl, config, auto, nicmodel, haverepo, diskbus, # pylint: disable=unused-argument
250250
brokenisomethod, output_disk=None, macaddress=None, # pylint: disable=unused-argument
251-
assumed_update=None, useuefi=False):
251+
assumed_update=None):
252252
if int(tdl.update) < 31:
253253
self.config = version_to_config[tdl.update]
254254
else:
@@ -263,8 +263,7 @@ def __init__(self, tdl, config, auto, nicmodel, haverepo, diskbus, # pylint: di
263263
oz.RedHat.RedHatLinuxCDYumGuest.__init__(self, tdl, config, auto,
264264
output_disk, nicmodel, diskbus,
265265
True, True, self.config.directkernel,
266-
macaddress, self.config.use_yum,
267-
self.config.useuefi)
266+
macaddress, self.config.use_yum)
268267

269268
if self.assumed_update is not None:
270269
self.log.warning("==== WARN: TDL contains Fedora update %s, which is newer than Oz knows about; pretending this is Fedora %s, but this may fail ====", tdl.update, assumed_update)

oz/Guest.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _libvirt_error_handler(ctxt, err):
129129
self._discover_libvirt_type()
130130

131131
def __init__(self, tdl, config, auto, output_disk, nicmodel, clockoffset,
132-
mousetype, diskbus, iso_allowed, url_allowed, macaddress, useuefi):
132+
mousetype, diskbus, iso_allowed, url_allowed, macaddress):
133133
self.tdl = tdl
134134

135135
# for backwards compatibility
@@ -502,7 +502,7 @@ def _generate_xml(self, bootdev, installdev, kernel=None, initrd=None,
502502
oz.ozutil.lxml_subelement(osNode, "loader", loader, {'readonly': 'yes', 'type': 'pflash'})
503503
oz.ozutil.lxml_subelement(osNode, "nvram", None, {'template': nvram})
504504
# x86_64 has legacy requirements so we check for defaults as well as for edk2
505-
if self.tdl.arch in ["x86_64"] and self.config.useuefi == True:
505+
if self.tdl.arch == "x86_64" and hasattr(self.config, "useuefi") and self.config.useuefi is True:
506506
loader, nvram = oz.ozutil.find_uefi_firmware(self.tdl.arch)
507507
oz.ozutil.lxml_subelement(osNode, "loader", loader, {'readonly': 'yes', 'type': 'pflash'})
508508
oz.ozutil.lxml_subelement(osNode, "nvram", None, {'template': nvram})
@@ -1333,10 +1333,10 @@ def __init__(self, version, sysid, volid, space_size, set_size, seqnum):
13331333
self.seqnum = seqnum
13341334

13351335
def __init__(self, tdl, config, auto, output_disk, nicmodel, clockoffset,
1336-
mousetype, diskbus, iso_allowed, url_allowed, macaddress, useuefi):
1336+
mousetype, diskbus, iso_allowed, url_allowed, macaddress):
13371337
Guest.__init__(self, tdl, config, auto, output_disk, nicmodel,
13381338
clockoffset, mousetype, diskbus, iso_allowed,
1339-
url_allowed, macaddress, useuefi)
1339+
url_allowed, macaddress)
13401340

13411341
self.orig_iso = os.path.join(self.data_dir, "isos",
13421342
self.tdl.distro + self.tdl.update + self.tdl.arch + "-" + self.tdl.installtype + ".iso")
@@ -1801,9 +1801,9 @@ class FDGuest(Guest):
18011801
Class for guest installation via floppy disk.
18021802
"""
18031803
def __init__(self, tdl, config, auto, output_disk, nicmodel, clockoffset,
1804-
mousetype, diskbus, macaddress, useuefi):
1804+
mousetype, diskbus, macaddress):
18051805
Guest.__init__(self, tdl, config, auto, output_disk, nicmodel,
1806-
clockoffset, mousetype, diskbus, False, True, macaddress, useuefi)
1806+
clockoffset, mousetype, diskbus, False, True, macaddress)
18071807
self.orig_floppy = os.path.join(self.data_dir, "floppies",
18081808
self.tdl.distro + self.tdl.update + self.tdl.arch + ".img")
18091809
self.modified_floppy_cache = os.path.join(self.data_dir, "floppies",

oz/Linux.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class LinuxCDGuest(oz.Guest.CDGuest):
3333
Class for Linux installation.
3434
"""
3535
def __init__(self, tdl, config, auto, output_disk, nicmodel, diskbus,
36-
iso_allowed, url_allowed, macaddress, useuefi):
36+
iso_allowed, url_allowed, macaddress):
3737
oz.Guest.CDGuest.__init__(self, tdl, config, auto, output_disk,
3838
nicmodel, None, None, diskbus, iso_allowed,
39-
url_allowed, macaddress, useuefi)
39+
url_allowed, macaddress)
4040

4141
def _test_ssh_connection(self, guestaddr):
4242
"""

oz/RHEL_8.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class RHEL8Guest(oz.RedHat.RedHatLinuxCDYumGuest):
3131
Class for RHEL-8 installation
3232
"""
3333
def __init__(self, tdl, config, auto, output_disk=None, netdev=None,
34-
diskbus=None, macaddress=None, useuefi=True):
34+
diskbus=None, macaddress=None):
3535
# dnf distro
3636
oz.RedHat.RedHatLinuxCDYumGuest.__init__(self, tdl, config, auto,
3737
output_disk, netdev, diskbus,
3838
True, True, "cpio", macaddress,
39-
False, useuefi)
39+
False)
4040
self.virtio_channel_name = 'org.fedoraproject.anaconda.log.0'
4141

4242
def _modify_iso(self):

oz/RHEL_9.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class RHEL9Guest(oz.RHEL_8.RHEL8Guest):
3131
Class for RHEL-9 installation
3232
"""
3333
def __init__(self, tdl, config, auto, output_disk=None, netdev=None,
34-
diskbus=None, macaddress=None, useuefi=True):
34+
diskbus=None, macaddress=None):
3535
# dnf distro
3636
oz.RHEL_8.RHEL8Guest.__init__(self, tdl, config, auto,
3737
output_disk, netdev, diskbus,
38-
macaddress, useuefi)
38+
macaddress)
3939

4040
# method and ks options were dropped
4141
self.cmdline = "inst.repo=" + self.url + " inst.ks=file:/ks.cfg"

0 commit comments

Comments
 (0)