Add "boot_linux" acceptance test
v4 cover Add "boot_linux" acceptance test
Some hopefully useful pointers for reviewers:
=============================================
Git Info:
- URI: https://github.com/clebergnu/qemu/tree/sent/test_boot_linux_v4
- Remote: https://github.com/clebergnu/qemu
- Branch: sent/test_boot_linux_v4
Travis CI Info:
- https://travis-ci.org/clebergnu/qemu/builds/490166797
Previous version:
- v3: https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg01677.html
- v2: https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg04318.html
- v1: http://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02530.html
Changes from v3:
================
* New patch "Acceptance tests: depend on qemu-img"
Known Issues on v3 (no longer applicable):
==========================================
* A recent TCG performance regression[1] affects this test in a number of ways:
- The test execution may timeout by itself
- The generation of SSH host keys in the guest's first boot is also affected (possibly also a timeout)
- The cloud-init "phone home" feature attempts to read the host keys and fails, causing the test to timeout and fail
These are not observed anymore once the fix[2] is applied.
[1] - https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00338.html
[2] - https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg01129.html
Changes from v2:
================
* Updated the tag to include the "arch:" key, in a similar fashion as to the tests in the "Acceptance Tests: target architecture support":
- https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00369.html
* Renamed the test method name to test_x86_64_pc, again, similarly to the boot_linux_console.py tests in the series mentioned before.
* Set the machine type explicitly, again similarly to the boot_linux_console.py tests in the series mentioned before.
* Added messages after the launch of the VM, to let test runners know the test know waits for a boot confirmation from the the guest (Eduardo).
* Updated commit message to reflect the fact that this version does not allow for parameterization of the guest OS, version, etc.
* Dropped the RFC prefix on patch "RFC: Acceptance tests: add the build directory to the system PATH"
* Changed the comments on "RFC: Acceptance tests: add the build directory to the system PATH" to make it clear the addition of a the build directory to the PATH may influence other utility code.
Changes from v1:
================
* The commit message was adjusted, removing the reference to the avocado.utils.vmimage encoding issue on previous Avocado versions (<= 64.0) and the fix that would (and was) included in Avocado version 65.0.
* Effectively added pycdlib==1.6.0 to the requirements.txt file, added on a56931eef3, and adjusted the commit message was also to reflect that.
* Updated the default version of the guest OS, from Fedora 28 to 29. Besides possible improvements in the (virtual) hardware coverage, it brings a performance improvement in the order of 20% to the test.
* Removed all direct parameters usage. Because some parameters and its default values implemented in the test would prevent it from running on some environments. Example: the "accel" parameter had a default value of "kvm", which would prevent this test, that boots a x86_64 OS, from running on a host arch different than x86_64. I recognize that it's desirable to make tests reusable and parameterized (that was the reason for the first version doing so), but the mechanism to be used to define the architectures that a given test should support is still an open issue, and has been discussed in other threads. I'll follow up those discussions with a proposal, and until then, removing those aspects from this test implementation seemed to be the best option. A caveat: this test currently adds the same tag (x86_64) and follows other assumptions made on "boot_linux_console.py", that is, that a x86_64 target binary will be used to run it. If a user is in an environment that does not have a x86_64 target binary, it could filter those tests out with: "avocado run --filter-by-tags='-x86_64' tests/acceptance".
* Removed most arguments to the QEMU command line for pretty much the same reasons described above, and by following the general perception that I could grasp from other discussions that QEMU defaults should preferrably be used. This test, as well as others, can and should be extended later to allow for different test scenarios by passing well documented parameter values. That is, they should respect well-known parameters such as "accel" mentioned above, so that the same test can run with KVM or TCG.
* Changed the value of the memory argument to 1024, which based on my experimentations and observations is the minimum amount of RAM for the Fedora 29 cloud image to sucessfully boot on QEMU. I know there's no such thing as a "one size fits all", specially for QEMU, but this makes me wonder wether a x86_64 machine type shouldn't have its default_ram_size bumped to a number practical enough to run modern operating systems.
* Added a new patch "RFC: Acceptance tests: add the build directory to the system PATH", which is supposed to gather feedback on how to enable the use of built binaries, such as qemu-img, to code used by the test code. The specific situation here is that the vmimage, part of the avocado.utils libraries, makes use of qemu-img to create snapshot files. Even though we could require qemu-img to be installed as a dependency of tests, system wide, it actually goes against the goal of testing all QEMU things from the source/build tree. This became aparent with tests running on environments such as Travis CI, which don't necessarily have qemu-img available elsewhere.
Cleber Rosa (3):
Acceptance tests: add the build directory to the system PATH Acceptance tests: depend on qemu-img
Add "boot_linux" acceptance test for x86_64 and pc machine type
tests/Makefile.include | 2 +- tests/acceptance/avocado_qemu/__init__.py | 7 ++++ tests/acceptance/boot_linux.py | 51 +++++++++++++++++++++++ tests/requirements.txt | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/boot_linux.py
Signature · 1 line
2.20.1
PATCH v4 1/3 Acceptance tests: add the build directory to the system PATH
So that when binaries such as qemu-img are searched for, those in the build tree will be favored. As a clarification, SRC_ROOT_DIR is dependent on the location from where tests are executed, so they are equal to the build directory if one is being used.
The original motivation is that Avocado libraries such as avocado.utils.vmimage.get() may use the matching binaries, but it may also apply to any other binary that test code may eventually attempt to execute.
--- tests/acceptance/avocado_qemu/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+)
tests/acceptance/avocado_qemu/__init__.py +7 -0
@@ -42,6 +42,13 @@ def pick_default_qemu_bin(): class Test(avocado.Test): def setUp(self): + # Some utility code uses binaries from the system's PATH. For + # instance, avocado.utils.vmimage.get() uses qemu-img, to + # create a snapshot image. This is a transparent way of + # making sure those utilities find and use binaries on the + # build tree by default. + os.environ['PATH'] = '%s:%s' % (SRC_ROOT_DIR, os.environ['PATH']) + self.vm = None self.qemu_bin = self.params.get('qemu_bin', default=pick_default_qemu_bin())
Signature · 1 line
2.20.1
PATCH v4 2/3 Acceptance tests: depend on qemu-img
In reply to Cleber RosaTests using the avocado.utils.vmimage library make use of qemu-img, and because it makes sense to use the version matching the rest of the source code, let's make sure it gets built.
Its selection, instead of a possible qemu-img binary installed system wide, is already dealt with by the change that adds the build dir to the PATH during the test execution.
This is based on the same work for qemu-iotests, and suggested by its author:
- https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00951.html
--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile.include +1 -1
@@ -1111,7 +1111,7 @@ $(TESTS_RESULTS_DIR): check-venv: $(TESTS_VENV_DIR) -check-acceptance: check-venv $(TESTS_RESULTS_DIR) +check-acceptance: check-venv $(TESTS_RESULTS_DIR) qemu-img$(EXESUF) $(call quiet-command, \ $(TESTS_VENV_DIR)/bin/python -m avocado \ --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 2/3] Acceptance tests: depend on qemu-img
FWIW, Cc'ing qemu-img maintainers.
Quoted 8 lines · Cleber Rosa
Tests using the avocado.utils.vmimage library make use of qemu-img, and because it makes sense to use the version matching the rest of the source code, let's make sure it gets built.
Its selection, instead of a possible qemu-img binary installed system wide, is already dealt with by the change that adds the build dir to the PATH during the test execution.
Quoted 7 lines
This is based on the same work for qemu-iotests, and suggested by its author:
- https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00951.html
CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by Cleber Rosa <[email protected]>
Quoted 18 lines
--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/Makefile.include +1
-1@@ -1111,7 +1111,7 @@ $(TESTS_RESULTS_DIR): check-venv: $(TESTS_VENV_DIR) -check-acceptance: check-venv $(TESTS_RESULTS_DIR) +check-acceptance: check-venv $(TESTS_RESULTS_DIR) qemu-img$(EXESUF) $(call quiet-command, \ $(TESTS_VENV_DIR)/bin/python -m avocado \ --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \
PATCH v4 3/3 Add "boot_linux" acceptance test for x86_64 and pc machine type
In reply to Cleber RosaThis acceptance test, validates that a full blown Linux guest can successfully boot in QEMU. In this specific case, the guest chosen is Fedora version 29.
The method for checking the successful boot is based on "cloudinit" and its "phone home" feature. The guest is given an ISO image with the location of the phone home server, and the information to post (the instance ID). Upon receiving the correct information, from the guest, the test is considered to have PASSed.
This test is currently limited to user mode networking only, and instructs the guest to connect to the "router" address that is hard coded in QEMU.
To create the cloudinit ISO image that will be used to configure the guest, the pycdlib library is also required and has been added as requirement to the virtual environment created by "check-venv".
--- tests/acceptance/boot_linux.py | 51 ++++++++++++++++++++++++++++++++++ tests/requirements.txt | 1 + 2 files changed, 52 insertions(+) create mode 100644 tests/acceptance/boot_linux.py
tests/acceptance/boot_linux.py new file +51 -0
@@ -0,0 +1,51 @@ +# Functional test that boots a complete Linux system via a cloud image +# +# Copyright (c) 2018-2019 Red Hat, Inc. +# +# Author: +# Cleber Rosa <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import os + +from avocado_qemu import Test + +from avocado.utils import cloudinit +from avocado.utils import network +from avocado.utils import vmimage + + +class BootLinux(Test): + """ + Boots a Linux system, checking for a successful initialization + + :avocado: enable + """ + + timeout = 600 + + def test_x86_64_pc(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + """ + self.vm.set_machine('pc') + self.vm.add_args('-m', '1024') + boot = vmimage.get('fedora', arch='x86_64', version='29', + cache_dir=self.cache_dirs[0], + snapshot_dir=self.workdir) + self.vm.add_args('-drive', 'file=%s' % boot.path) + + cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') + phone_home_port = network.find_free_port() + cloudinit.iso(cloudinit_iso, self.name, + # QEMU's hard coded usermode router address + phone_home_host='10.0.2.2', + phone_home_port=phone_home_port) + self.vm.add_args('-drive', 'file=%s' % cloudinit_iso) + + self.vm.launch() + self.log.info('VM launched, waiting for boot confirmation from guest') + cloudinit.wait_for_phone_home(('0.0.0.0', phone_home_port), self.name)
tests/requirements.txt +1 -0
@@ -2,3 +2,4 @@ # in the tests/venv Python virtual environment. For more info, # refer to: https://pip.pypa.io/en/stable/user_guide/#id1 avocado-framework==65.0 +pycdlib==1.6.0
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 3/3] Add "boot_linux" acceptance test for x86_64 and pc machine type
Quoted 33 lines · On Thu, 7 Feb 2019 13:00:12 -0500 Cleber Rosa <[email protected]> wrote:
tests/acceptance/boot_linux.py new file +27
-0@@ -0,0 +1,51 @@ +# Functional test that boots a complete Linux system via a cloud image +# +# Copyright (c) 2018-2019 Red Hat, Inc. +# +# Author: +# Cleber Rosa <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import os + +from avocado_qemu import Test + +from avocado.utils import cloudinit +from avocado.utils import network +from avocado.utils import vmimage + + +class BootLinux(Test): + """ + Boots a Linux system, checking for a successful initialization + + :avocado: enable + """ + + timeout = 600
tests/acceptance/boot_linux.py line 37
Quoted 10 lines
tests/acceptance/boot_linux.py new file +10
-0+ + def test_x86_64_pc(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + """ + self.vm.set_machine('pc') + self.vm.add_args('-m', '1024') + boot = vmimage.get('fedora', arch='x86_64', version='29', + cache_dir=self.cache_dirs[0],
Somewhat related: I looked at
https://avocado-framework.readthedocs.io/en/67.0/api/utils/avocado.utils.html#module-avocado.utils.vmimage
to find out how caching works, but could not find it... does it match the checksum?
I think we want to make this benign for people on a slow and/or data-capped network connection. 'make check-acceptance' downloading tons of stuff might come as a bad surprise, and it's probably best to avoid doing more of that than strictly necessary.
Quoted 14 lines
tests/acceptance/boot_linux.py new file +14
-0+ snapshot_dir=self.workdir) + self.vm.add_args('-drive', 'file=%s' % boot.path) + + cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') + phone_home_port = network.find_free_port() + cloudinit.iso(cloudinit_iso, self.name, + # QEMU's hard coded usermode router address + phone_home_host='10.0.2.2', + phone_home_port=phone_home_port) + self.vm.add_args('-drive', 'file=%s' % cloudinit_iso) + + self.vm.launch() + self.log.info('VM launched, waiting for boot confirmation from guest') + cloudinit.wait_for_phone_home(('0.0.0.0', phone_home_port), self.name)