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

Add tox.ini file to implement rocks stanity tests #9

Merged
merged 5 commits into from
Jan 18, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ jobs:
permissions:
pull-requests: read
secrets: inherit
with:
rockcraft-channel: latest/stable
microk8s-channel: 1.26-strict/stable
juju-channel: 3.1/stable
python-version: "3.8"
5 changes: 5 additions & 0 deletions .github/workflows/on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ jobs:
permissions:
pull-requests: read
secrets: inherit
with:
rockcraft-channel: latest/stable
microk8s-channel: 1.26-strict/stable
juju-channel: 3.1/stable
python-version: "3.8"
41 changes: 41 additions & 0 deletions dex/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -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)
62 changes: 62 additions & 0 deletions dex/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = pack, export-to-docker, 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."
Loading