Skip to content
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

tests: actually log into the generated disk image #42

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
uses: actions/setup-python@v4
- name: Install test dependencies
run: |
sudo apt install -y podman python3-pytest flake8 qemu-system-x86
sudo apt install -y podman python3-pytest python3-paramiko flake8 qemu-system-x86
- name: Run tests
run: |
# podman needs (parts of) the environment but will break when
Expand Down
1 change: 1 addition & 0 deletions plans/all.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ prepare:
- podman
- pytest
- python3-flake8
- python3-paramiko
- qemu-kvm
execute:
how: tmt
Expand Down
8 changes: 5 additions & 3 deletions test/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def test_smoke(output_path, config_json):
print("WARNING: selinux not enabled, cannot check for denials")

with VM(generated_img) as test_vm:
# TODO: replace with 'test_vm.run("true")' once user creation via
# blueprints works
test_vm.wait_ssh_ready()
exit_status, _ = test_vm.run("true", user="test", password="password")
assert exit_status == 0
exit_status, output = test_vm.run("echo hello", user="test", password="password")
assert exit_status == 0
assert "hello" in output
26 changes: 26 additions & 0 deletions test/vm.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import pathlib
import subprocess
import sys
from io import StringIO

from testutil import get_free_port, wait_ssh_ready


from paramiko.client import AutoAddPolicy, SSHClient


class VM:
MEM = "2000"
QEMU = "qemu-system-x86_64"
Expand Down Expand Up @@ -64,3 +68,25 @@ def __enter__(self):

def __exit__(self, type, value, tb):
self.force_stop()

def run(self, cmd, user, password):
if not self._qemu_p:
self.start()
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy)
client.connect(
"localhost", self._ssh_port, user, password,
allow_agent=False, look_for_keys=False)
chan = client.get_transport().open_session()
chan.get_pty()
chan.exec_command(cmd)
stdout_f = chan.makefile()
output = StringIO()
while True:
out = stdout_f.readline()
if not out:
break
self._log(out)
output.write(out)
exit_status = stdout_f.channel.recv_exit_status()
return exit_status, output.getvalue()
Loading