Skip to content

Commit

Permalink
tests: run integration test on macos as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Dec 5, 2023
1 parent 925b4a9 commit 5ef9791
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,33 @@ jobs:
# XDG_RUNTIME_DIR is set.
# TODO: figure out what exactly podman needs
sudo -E XDG_RUNTIME_DIR= pytest-3 -s -vv
integration-macos:
name: "Integration macos"
# needed to get latest cpu
runs-on: macos-13
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup up python
uses: actions/setup-python@v4
- name: Setup up podman
run: |
sysctl -a
brew install podman
# need to map only a subset of /var/tmp into the bootc tests
sudo mkdir -p /var/tmp/bootc-tests
# TODO: this is "security_model=mapped" is needed or the build
# will not be able to be copied back to the host dir with an
# "cp: failed to preserve ownership for '/output/qcow2/./disk.qcow2': Operation not permited
podman machine init --rootful -v /var/tmp/bootc-tests:/var/tmp/bootc-tests:security_model=mapped
podman machine start
# debug only
podman info
- name: Install test dependencies
run: |
sudo pip install pytest flake8
- name: Run tests
run: |
sudo pytest -s -vv
37 changes: 29 additions & 8 deletions test/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pathlib
import subprocess
import tempfile

import pytest

Expand All @@ -10,10 +11,23 @@


@pytest.fixture(name="output_path")
def output_path_fixture(tmp_path):
output_path = tmp_path / "output"
output_path.mkdir(exist_ok=True)
return output_path
def output_path_fixture():
# quirky setup to workaround macos weirdness:
# 1. we need a dir shared between "podman machine" and host to inspect
# the output image
# 2. *but* just sharing /var/tmp will result in errors because inside
# podman things like lchown in /var/tmp that happen during the container
# build will affect the host and cause "operation not permitted" errors
base_tmp = pathlib.Path("/var/tmp/bootc-tests")
base_tmp.mkdir(exist_ok=True, mode=0o700)
with tempfile.TemporaryDirectory(dir=base_tmp) as tmp_dir:
# HACKKKKKK: macos keeps giving "permission denied" in podman
# without this - however given that the parent is 0700 we should be ok
os.chmod(tmp_dir, 0o777)
tmp_path = pathlib.Path(tmp_dir)
output_path = tmp_path / "output"
output_path.mkdir(exist_ok=True)
yield tmp_path


@pytest.fixture(name="config_json")
Expand All @@ -36,16 +50,22 @@ def config_json_fixture(output_path):
return config_json_path


@pytest.fixture(name="journal_cursor")
def journal_cursor_fixture():
if not testutil.has_executable("journalctl"):
return None
return testutil.journal_cursor()


@pytest.mark.skipif(os.getuid() != 0, reason="needs root")
@pytest.mark.skipif(not testutil.has_executable("podman"), reason="need podman")
def test_smoke(output_path, config_json):
def test_smoke(output_path, journal_cursor, config_json):
# build local container
subprocess.check_call([
"podman", "build",
"-f", "Containerfile",
"-t", "osbuild-deploy-container-test",
])
cursor = testutil.journal_cursor()
# and run container to deploy an image into output/disk.qcow2
subprocess.check_call([
"podman", "run", "--rm",
Expand All @@ -59,8 +79,9 @@ def test_smoke(output_path, config_json):
# check that there are no denials
# TODO: actually check this once https://github.com/osbuild/images/pull/287
# is merged
journal_output = testutil.journal_after_cursor(cursor)
assert journal_output != ""
if journal_cursor:
journal_output = testutil.journal_after_cursor(journal_cursor)
assert journal_output != ""
generated_img = pathlib.Path(output_path) / "qcow2/disk.qcow2"
assert generated_img.exists(), f"output file missing, dir content: {os.listdir(os.fspath(output_path))}"
# TODO: boot and do basic checks, see
Expand Down

0 comments on commit 5ef9791

Please sign in to comment.