-
Notifications
You must be signed in to change notification settings - Fork 39
Do not use sudo FQDN lookups #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
basak-qcom
wants to merge
5
commits into
qualcomm-linux:main
Choose a base branch
from
basak-qcom:sudo-fqdn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52829d7
qemu_test: factor out vm fixture
basak-qcom ba629bb
qemu_test: re-use the same qemu vm fixture
basak-qcom 8ec93a6
ci: add and integrate qemu_guest_test.py
basak-qcom d8a43b6
qemu_guest_test: add test for sudo fqdn issue
basak-qcom deddc35
Do not use sudo FQDN lookups
basak-qcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """qemu-based tests that are copied into the guest and run there""" | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| # These tests are run inside the qemu guest as root using its own pytest runner | ||
| # invocation. | ||
|
|
||
| import pytest | ||
|
|
||
| # Mark this module so that the main test runner can skip it when running from | ||
| # the host. However, the guest test runner does not use this mark but instead | ||
| # explicitly calls this file. Marks require test collection, and the guest test | ||
| # runner isn't going to have dependencies installed that are only needed for | ||
| # host tests, causing guest test collection to fail otherwise. | ||
| pytestmark = pytest.mark.guest | ||
|
|
||
|
|
||
| def test_empty(): | ||
| # The empty test. This is nevertheless useful as its presence ensures that | ||
| # the host is calling the guest test suite in this module correctly. | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,12 @@ | |
| import pexpect | ||
| import pytest | ||
|
|
||
| # Since the first test checks for the mandatory password reset functionality | ||
| # that also prepares the VM for shell-based access, we make the additional | ||
| # optimisation that the fixture for a logged in VM re-uses that VM, so the | ||
| # ordering of [plain VM fixture, password reset test, logged-in VM fixture] | ||
| # matters here. | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def vm(): | ||
|
|
@@ -58,10 +64,14 @@ def vm(): | |
| "-nographic", | ||
| "-bios", | ||
| "/usr/share/AAVMF/AAVMF_CODE.fd", | ||
| "-fsdev", | ||
| f"local,id=fsdev0,path={os.getcwd()},security_model=none", | ||
| "-device", | ||
| "virtio-9p-pci,fsdev=fsdev0,mount_tag=qcom-deb-images", | ||
| ], | ||
| ) | ||
| spawn.logfile = sys.stdout.buffer | ||
| yield types.SimpleNamespace(spawn=spawn) | ||
| yield types.SimpleNamespace(spawn=spawn, logged_in=False) | ||
|
|
||
| # No need to be nice; that would take time | ||
| spawn.kill(signal.SIGKILL) | ||
|
|
@@ -89,3 +99,42 @@ def test_password_reset_required(vm): | |
| vm.spawn.expect_exact("Retype new password:") | ||
| vm.spawn.send("new password\r\n") | ||
| vm.spawn.expect_exact("debian@debian:~$") | ||
|
|
||
| vm.logged_in = True | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def logged_in_vm(vm): | ||
| if not vm.logged_in: | ||
| pytest.skip("Password reset test did not run or failed") | ||
| return vm | ||
|
|
||
|
|
||
| def test_using_guest_tests(logged_in_vm): | ||
| """Run the tests in qemu_guest_test.py inside the qemu guest""" | ||
| # Statement of test success and failure that are unlikely to appear by | ||
| # accident | ||
| SUCCESS_NOTICE = "All ci/qemu_guest_test.py tests passed" | ||
| FAILURE_NOTICE = "Some ci/qemu_guest_test.py tests failed" | ||
| # We use apt-get -U here and the apt_dependencies fixture in | ||
| # qemu_guest_test.py relies on this. | ||
| SCRIPT = f"""sudo -i sh <<EOT | ||
| apt-get install -Uy --no-install-recommends python3-pytest | ||
| mkdir qcom-deb-images | ||
| mount -t 9p qcom-deb-images qcom-deb-images | ||
| cd qcom-deb-images | ||
| py.test-3 -vvm guest ci/qemu_guest_test.py && echo "{SUCCESS_NOTICE}" || echo "{FAILURE_NOTICE}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm tests running as root; I guess we can revisit this when we need a non-root test |
||
| EOT | ||
| """ | ||
| logged_in_vm.spawn.send(SCRIPT.replace("\r", "\r\n")) | ||
|
|
||
| # Match a known string for when pytest starts. Otherwise we catch the echo | ||
| # of our own printing of SUCCESS_NOTICE and FAILURE_NOTICE that appears | ||
| # before, causing us to falsely believe that it was done. The timeout is | ||
| # required to give enough time for the installation of python3-pytest to | ||
| # finish. | ||
| logged_in_vm.spawn.expect_exact("test session starts", timeout=120) | ||
| match = logged_in_vm.spawn.expect_exact( | ||
| [SUCCESS_NOTICE, FAILURE_NOTICE], timeout=120 | ||
| ) | ||
| assert match == 0, "ci/qemu_guest_test.py tests failed" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [tool.pytest.ini_options] | ||
| # See ci/qemu_test.py and ci/qemu_test_guest.py for details on arrangements for | ||
| # guest tests. | ||
| addopts = "-m 'not guest'" | ||
| markers = [ | ||
| "guest: Tests that run from inside a built image" | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite unfortunate to introduce a network dependency :-(
I also don't like that we're changing the rootfs, but I guess we need to bring the tests somehow.
Should we just add this test runner to the image?