|
13 | 13 | import pexpect |
14 | 14 | import pytest |
15 | 15 |
|
| 16 | +# Since the first test checks for the mandatory password reset functionality |
| 17 | +# that also prepares the VM for shell-based access, we make the additional |
| 18 | +# optimisation that the fixture for a logged in VM re-uses that VM, so the |
| 19 | +# ordering of [plain VM fixture, password reset test, logged-in VM fixture] |
| 20 | +# matters here. |
| 21 | + |
16 | 22 |
|
17 | 23 | @pytest.fixture(scope="module") |
18 | 24 | def vm(): |
@@ -58,10 +64,14 @@ def vm(): |
58 | 64 | "-nographic", |
59 | 65 | "-bios", |
60 | 66 | "/usr/share/AAVMF/AAVMF_CODE.fd", |
| 67 | + "-fsdev", |
| 68 | + f"local,id=fsdev0,path={os.getcwd()},security_model=none", |
| 69 | + "-device", |
| 70 | + "virtio-9p-pci,fsdev=fsdev0,mount_tag=qcom-deb-images", |
61 | 71 | ], |
62 | 72 | ) |
63 | 73 | spawn.logfile = sys.stdout.buffer |
64 | | - yield types.SimpleNamespace(spawn=spawn) |
| 74 | + yield types.SimpleNamespace(spawn=spawn, logged_in=False) |
65 | 75 |
|
66 | 76 | # No need to be nice; that would take time |
67 | 77 | spawn.kill(signal.SIGKILL) |
@@ -89,3 +99,42 @@ def test_password_reset_required(vm): |
89 | 99 | vm.spawn.expect_exact("Retype new password:") |
90 | 100 | vm.spawn.send("new password\r\n") |
91 | 101 | vm.spawn.expect_exact("debian@debian:~$") |
| 102 | + |
| 103 | + vm.logged_in = True |
| 104 | + |
| 105 | + |
| 106 | +@pytest.fixture(scope="module") |
| 107 | +def logged_in_vm(vm): |
| 108 | + if not vm.logged_in: |
| 109 | + pytest.skip("Password reset test did not run or failed") |
| 110 | + return vm |
| 111 | + |
| 112 | + |
| 113 | +def test_using_guest_tests(logged_in_vm): |
| 114 | + """Run the tests in qemu_guest_test.py inside the qemu guest""" |
| 115 | + # Statement of test success and failure that are unlikely to appear by |
| 116 | + # accident |
| 117 | + SUCCESS_NOTICE = "All ci/qemu_guest_test.py tests passed" |
| 118 | + FAILURE_NOTICE = "Some ci/qemu_guest_test.py tests failed" |
| 119 | + # We use apt-get -U here and the apt_dependencies fixture in |
| 120 | + # qemu_guest_test.py relies on this. |
| 121 | + SCRIPT = f"""sudo -i sh <<EOT |
| 122 | +apt-get install -Uy --no-install-recommends python3-pytest |
| 123 | +mkdir qcom-deb-images |
| 124 | +mount -t 9p qcom-deb-images qcom-deb-images |
| 125 | +cd qcom-deb-images |
| 126 | +py.test-3 -vvm guest ci/qemu_guest_test.py && echo "{SUCCESS_NOTICE}" || echo "{FAILURE_NOTICE}" |
| 127 | +EOT |
| 128 | +""" |
| 129 | + logged_in_vm.spawn.send(SCRIPT.replace("\r", "\r\n")) |
| 130 | + |
| 131 | + # Match a known string for when pytest starts. Otherwise we catch the echo |
| 132 | + # of our own printing of SUCCESS_NOTICE and FAILURE_NOTICE that appears |
| 133 | + # before, causing us to falsely believe that it was done. The timeout is |
| 134 | + # required to give enough time for the installation of python3-pytest to |
| 135 | + # finish. |
| 136 | + logged_in_vm.spawn.expect_exact("test session starts", timeout=120) |
| 137 | + match = logged_in_vm.spawn.expect_exact( |
| 138 | + [SUCCESS_NOTICE, FAILURE_NOTICE], timeout=120 |
| 139 | + ) |
| 140 | + assert match == 0, "ci/qemu_guest_test.py tests failed" |
0 commit comments