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

Trivial interface test fails when the charms don't have a requirements.txt file #216

Open
theoctober19th opened this issue Jan 20, 2025 · 1 comment

Comments

@theoctober19th
Copy link
Member

When writing interface tests for a new interface azure_storage, even a very trivial interface test failed; and I traced the reason to be due to unavailability of requirements.txt file in the charm being downloaded.

Steps to reproduce:
I followed these instructions to write a trivial integration test for the interface: https://github.com/canonical/charm-relation-interfaces/blob/main/README_INTERFACE_TESTS.md

  1. Clone https://github.com/theoctober19th/charm-relation-interfaces/tree/azure-storage-credentials and checkout to branch azure-storage-credentials.

  2. Verify that the tests are specified correctly:

interface_tester discover --include azure_storage
  1. Run the test.
python run_matrix.py --include azure_storage

Observation
The command fails with the following error logs:

INFO:root:Running tests for interface: azure_storage
INFO:root:Running tests for version: v0
INFO:root:Running tests for role: provider
INFO:root:No tests specified for azure_storage/provider; skipping...
INFO:root:Running tests for role: requirer
INFO:root:Running 1 azure_storage interface tests on: ['spark-integration-hub-k8s', 'spark-history-server-k8s']...
INFO:root:Running tests for azure_storage
INFO:root:Running tests for charm: spark-integration-hub-k8s
INFO:root:Preparing testing environment for: spark-integration-hub-k8s
INFO:root:Cloning: spark-integration-hub-k8s from (https://github.com/canonical/spark-integration-hub-k8s-operator@main)
INFO:root:Preparing venv for /tmp/charm-relation-interfaces-tests/spark-integration-hub-k8s
INFO:root:Installing dependencies in venv for /tmp/charm-relation-interfaces-tests/spark-integration-hub-k8s
WARNING:root:test setup failed for spark-integration-hub-k8s azure_storage requirer
Traceback (most recent call last):
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 179, in _setup_venv
    subprocess.check_call(
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '.interface-venv/bin/python -m pip install -r requirements.txt' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 218, in _test_charm
    charm_path, test_path = _prepare_repo(
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 90, in _prepare_repo
    _setup_venv(charm_path)
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 188, in _setup_venv
    raise SetupError("venv setup failed") from e
SetupError: venv setup failed
INFO:root:Result: FAILED
INFO:root:Running tests for charm: spark-history-server-k8s
INFO:root:Preparing testing environment for: spark-history-server-k8s
INFO:root:Cloning: spark-history-server-k8s from (https://github.com/canonical/spark-history-server-k8s-operator@main)
INFO:root:Preparing venv for /tmp/charm-relation-interfaces-tests/spark-history-server-k8s
INFO:root:Installing dependencies in venv for /tmp/charm-relation-interfaces-tests/spark-history-server-k8s
WARNING:root:test setup failed for spark-history-server-k8s azure_storage requirer
Traceback (most recent call last):
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 179, in _setup_venv
    subprocess.check_call(
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '.interface-venv/bin/python -m pip install -r requirements.txt' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 218, in _test_charm
    charm_path, test_path = _prepare_repo(
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 90, in _prepare_repo
    _setup_venv(charm_path)
  File "/home/ubuntu/charm-relation-interfaces/run_matrix.py", line 188, in _setup_venv
    raise SetupError("venv setup failed") from e
SetupError: venv setup failed
INFO:root:Result: FAILED
+++ Results +++
{
  "azure_storage": {
    "v0": {
      "provider": {},
      "requirer": {
        "spark-integration-hub-k8s": false,
        "spark-history-server-k8s": false
      }
    }
  }
}
@PietroPasotti
Copy link
Contributor

This is because the interface test runner requires an interface.txt file in order to know how to set up a venv to test the charm.
Now more charms are using uv and lockfiles, and therefore omitting a requirements.txt file, we should consider adding support for this (e.g. a way to configure the test runner to run something other than pip install -r requirements.txt to set up the env; for example uv ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants