diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3841f030..eaf83f27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/test/test_smoke.py b/test/test_smoke.py index 1f6cb6fb..49ed1e51 100644 --- a/test/test_smoke.py +++ b/test/test_smoke.py @@ -2,6 +2,7 @@ import os import pathlib import subprocess +import tempfile import pytest @@ -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") @@ -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", @@ -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