From 648946a171a398d30ed5525535e63e4499f27480 Mon Sep 17 00:00:00 2001 From: Andrew Scribner Date: Thu, 18 Jan 2024 08:47:38 -0500 Subject: [PATCH 1/5] Add tox.ini file to implement rocks stanity tests --- dex/tests/test_rock.py | 41 ++++++++++++++++++++++++++++ dex/tox.ini | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 dex/tests/test_rock.py create mode 100644 dex/tox.ini diff --git a/dex/tests/test_rock.py b/dex/tests/test_rock.py new file mode 100644 index 0000000..e62145a --- /dev/null +++ b/dex/tests/test_rock.py @@ -0,0 +1,41 @@ +# Copyright 2022 Canonical Ltd. +# See LICENSE file for licensing details. +# +# + +from pathlib import Path + +import os +import logging +import random +import pytest +import string +import subprocess +import yaml + +from charmed_kubeflow_chisme.rock import CheckRock + +@pytest.fixture() +def rock_test_env(tmpdir): + """Yields a temporary directory and random docker container name, then cleans them up after.""" + container_name = "".join([str(i) for i in random.choices(string.ascii_lowercase, k=8)]) + yield tmpdir, container_name + + try: + subprocess.run(["docker", "rm", container_name]) + except Exception: + pass + # tmpdir fixture we use here should clean up the other files for us + +@pytest.mark.abort_on_fail +def test_rock(rock_test_env): + """Test rock.""" + temp_dir, container_name = rock_test_env + check_rock = CheckRock("rockcraft.yaml") + rock_image = check_rock.get_name() + rock_version = check_rock.get_version() + LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}" + + # create ROCK filesystem + subprocess.run(["docker", "run", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/usr/local/bin/docker-entrypoint"], check=True) + subprocess.run(["docker", "run", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/usr/local/bin/dex"], check=True) \ No newline at end of file diff --git a/dex/tox.ini b/dex/tox.ini new file mode 100644 index 0000000..cd6c592 --- /dev/null +++ b/dex/tox.ini @@ -0,0 +1,62 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. +[tox] +skipsdist = True +skip_missing_interpreters = True +envlist = unit, sanity, integration + +[testenv] +setenv = + PYTHONPATH={toxinidir} + PYTHONBREAKPOINT=ipdb.set_trace + +[testenv:pack] +passenv = * +allowlist_externals = + rockcraft +commands = + rockcraft pack + +[testenv:export-to-docker] +passenv = * +allowlist_externals = + bash + skopeo + yq +commands = + # export already packed rock to docker + bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \ + VERSION=$(yq eval .version rockcraft.yaml) && \ + ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \ + ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \ + DOCKER_IMAGE=$NAME:$VERSION && \\ + echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \ + skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE' + +[testenv:sanity] +passenv = * +deps = + pytest + charmed-kubeflow-chisme +allowlist_externals = + echo +commands = + # run rock tests + pytest -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests + + +[testenv:integration] +passenv = * +allowlist_externals = + echo + bash + git + rm + tox +deps = + juju<4.0 + pytest + pytest-operator + ops +commands = + echo "WARNING: This is a placeholder test - no test is implemented here." From da825200bfa33a35d38120d18fdfdfa4becbe069 Mon Sep 17 00:00:00 2001 From: Andrew Scribner Date: Thu, 18 Jan 2024 10:02:09 -0500 Subject: [PATCH 2/5] pin versions in rock ci workflows --- .github/workflows/on_pull_request.yaml | 5 +++++ .github/workflows/on_push.yaml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 54d0180..1c73053 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -11,3 +11,8 @@ jobs: permissions: pull-requests: read secrets: inherit + with: + rockcraft-channel: latest/edge + microk8s-channel: 1.26/stable + juju-channel: 3.1/stable + python-version: "3.8" diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml index 9704e46..9608e12 100644 --- a/.github/workflows/on_push.yaml +++ b/.github/workflows/on_push.yaml @@ -14,3 +14,8 @@ jobs: permissions: pull-requests: read secrets: inherit + with: + rockcraft-channel: latest/edge + microk8s-channel: 1.26/stable + juju-channel: 3.1/stable + python-version: "3.8" From 14dbfa41e6e4018245f429a056204ad52e6aef49 Mon Sep 17 00:00:00 2001 From: Andrew Scribner Date: Thu, 18 Jan 2024 10:48:33 -0500 Subject: [PATCH 3/5] update ci to pin to 1.26-strict/stable --- .github/workflows/on_pull_request.yaml | 2 +- .github/workflows/on_push.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 1c73053..22ed3a3 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -13,6 +13,6 @@ jobs: secrets: inherit with: rockcraft-channel: latest/edge - microk8s-channel: 1.26/stable + microk8s-channel: 1.26-strict/stable juju-channel: 3.1/stable python-version: "3.8" diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml index 9608e12..31b2519 100644 --- a/.github/workflows/on_push.yaml +++ b/.github/workflows/on_push.yaml @@ -16,6 +16,6 @@ jobs: secrets: inherit with: rockcraft-channel: latest/edge - microk8s-channel: 1.26/stable + microk8s-channel: 1.26-strict/stable juju-channel: 3.1/stable python-version: "3.8" From e9772d60a1e2c593bccc2875749410ed3f0f2137 Mon Sep 17 00:00:00 2001 From: Andrew Scribner Date: Thu, 18 Jan 2024 11:47:51 -0500 Subject: [PATCH 4/5] fix incorrect envlist in dex/tox.ini --- dex/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dex/tox.ini b/dex/tox.ini index cd6c592..c51e20b 100644 --- a/dex/tox.ini +++ b/dex/tox.ini @@ -3,7 +3,7 @@ [tox] skipsdist = True skip_missing_interpreters = True -envlist = unit, sanity, integration +envlist = pack, export-to-docker, sanity, integration [testenv] setenv = From c48a4030a9e3dde682321ebe0676d293db93217c Mon Sep 17 00:00:00 2001 From: Andrew Scribner Date: Thu, 18 Jan 2024 11:49:53 -0500 Subject: [PATCH 5/5] pin ci rockcraft-channel to latest/stable from /edge --- .github/workflows/on_pull_request.yaml | 2 +- .github/workflows/on_push.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 22ed3a3..9b24ff0 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -12,7 +12,7 @@ jobs: pull-requests: read secrets: inherit with: - rockcraft-channel: latest/edge + rockcraft-channel: latest/stable microk8s-channel: 1.26-strict/stable juju-channel: 3.1/stable python-version: "3.8" diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml index 31b2519..99b1416 100644 --- a/.github/workflows/on_push.yaml +++ b/.github/workflows/on_push.yaml @@ -15,7 +15,7 @@ jobs: pull-requests: read secrets: inherit with: - rockcraft-channel: latest/edge + rockcraft-channel: latest/stable microk8s-channel: 1.26-strict/stable juju-channel: 3.1/stable python-version: "3.8"