Skip to content
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
95 changes: 56 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@

Test suite for RHOS Lightspeed in RHOSO environments.

## Setup
## Installation

Python 3.12 is required. Install from a cloned repo:

```bash
uv venv
uv sync
source .venv/bin/activate
```

## Configuration

Configure the service in `config/default.yaml`. For Goose API tests, set
`goose.model` to the value of the Goose container's `LIGHTSPEED_MODEL`:
Or install the standalone command directly from GitHub:

```yaml
rhos_lightspeed:
base_url: "http://localhost:8080"
timeout: 30
```bash
uv tool install --python 3.12 git+https://github.com/openstack-k8s-operators/lightspeed-tests.git
```

query:
default_question: "What is OpenStack?"
The package includes the tests and their default configuration. Once installed,
`lightspeed-tests` works from any directory. `lightspeed-test` is also available
as an alias.

goose:
model: "<same value as Goose LIGHTSPEED_MODEL>"
```
## Configuration

Supply the bearer token through the environment:
The tests load the default config from `src/rhos_lightspeed_tests/default.yaml`.
Configure the service through environment variables:

```bash
export RHOS_LIGHTSPEED_URL="https://localhost:8443"
export RHOS_LIGHTSPEED_TOKEN="<Lightspeed bearer token>"
export RHOS_LIGHTSPEED_MODEL="<same value as Goose LIGHTSPEED_MODEL>"
```

`RHOS_LIGHTSPEED_URL` and `RHOS_LIGHTSPEED_MODEL` can override the URL and model
from the config file. Use a service origin without `/v1`. With the test-operator
playbook, supply `lightspeed_model`.
from the default config. Use a service origin without `/v1`. With the test-operator
playbook, supply `lightspeed_model`. For Goose API tests, set the model to the Goose
container's `LIGHTSPEED_MODEL` value.

If you run the tests outside of OpenShift, you need to have a running port forward
for the `lightspeed-app-server` service. For example:
Expand All @@ -45,29 +46,44 @@ oc port-forward -n openstack-lightspeed svc/lightspeed-app-server 8443:8443

## Running tests

The command accepts pytest options and returns pytest's exit status. In a uv
checkout, prefix the commands below with `uv run`.

```bash
# Run all tests
uv run pytest
lightspeed-tests

# Run integration tests only
uv run pytest tests/integration/
lightspeed-tests -k integration

# Run one installed test module
lightspeed-tests rhos_lightspeed_tests.tests.integration.test_query_endpoint

# Run one test file from a checkout
lightspeed-tests src/rhos_lightspeed_tests/tests/integration/test_query_endpoint.py

# Run Goose API tests
uv run pytest tests/integration/test_goose_responses.py
lightspeed-tests -k goose

# Skip Goose tests that require a real LLM's answer content
uv run pytest tests/integration/test_goose_responses.py -m "not llm_dependent"
lightspeed-tests -k goose -m "not llm_dependent"

# Generate JUnit XML (automatic via pyproject.toml config)
uv run pytest # outputs test-results.xml
# Verify test discovery without contacting a service
lightspeed-tests --collect-only

# Choose a different JUnit XML report path
lightspeed-tests --junitxml=results.xml
```

Integration tests require a deployed Lightspeed service. Goose tests also
require a configured model.

## Adding tests

1. Create test file in appropriate directory:
- `tests/unit/` - Fast, isolated tests
- `tests/integration/` - Tests requiring deployed service
- `tests/e2e/` - Full end-to-end scenarios
- `src/rhos_lightspeed_tests/tests/unit/` - Fast, isolated suite tests
- `src/rhos_lightspeed_tests/tests/integration/` - Tests requiring deployed service
- `src/rhos_lightspeed_tests/tests/e2e/` - Full end-to-end scenarios

2. Use the shared fixtures from `conftest.py`:
```python
Expand All @@ -77,24 +93,25 @@ uv run pytest # outputs test-results.xml
assert response.status_code == 200
```

3. Run: `uv run pytest tests/integration/test_my_feature.py`
3. Run: `uv run lightspeed-tests -k test_my_feature`

Build a source distribution and wheel with `uv build`.

## Project structure

```
rhos-lightspeed-tests/
├── config/
│ └── default.yaml # Default test configuration
├── src/rhos_lightspeed_tests/ # Shared utilities
│ ├── __init__.py
├── src/rhos_lightspeed_tests/ # Installed package
│ ├── __init__.py # lightspeed-tests entry point
│ ├── client.py # API client (query, health)
│ └── config.py # Reads default.yaml, env var overrides
├── tests/
│ ├── conftest.py # Shared fixtures (config, client)
│ ├── unit/
│ ├── integration/
│ │ └── test_query_endpoint.py # First test: /query endpoint
│ └── e2e/
│ ├── config.py # Loads defaults and environment overrides
│ ├── default.yaml # Bundled default configuration
│ ├── pytest.ini # Bundled pytest settings and default suite
│ └── tests/
│ ├── conftest.py # Shared fixtures (config, client)
│ ├── unit/
│ ├── integration/
│ └── e2e/
├── pyproject.toml
└── README.md
```
4 changes: 2 additions & 2 deletions playbooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Ansible playbooks to run the test suite.

## `run_lightspeed_tests.yaml`

Executes the RHOS Lightspeed test suite using pytest. The playbook:
Executes the RHOS Lightspeed test suite using `lightspeed-tests`. The playbook:

1. Installs the [uv](https://astral.sh/uv) package manager if not already available
2. Installs Python 3.12 using uv
3. Verifies the test suite directory exists (cloned by test-operator)
4. Reads the Kubernetes service account token for authentication
5. Installs Python dependencies using uv
6. Runs the pytest test suite with configurable arguments
6. Runs `lightspeed-tests` with configurable pytest arguments
7. Generates JUnit XML test results for reporting

Test results are stored in the location specified by `junit_xml_path`, which the test-operator can consume for reporting.
Expand Down
4 changes: 2 additions & 2 deletions playbooks/run_lightspeed_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@
PYTHONUNBUFFERED: "1"
PATH: "{{ ansible_env.HOME }}/.local/bin:{{ ansible_env.PATH }}"

- name: Run pytest tests
- name: Run Lightspeed tests
ansible.builtin.command:
cmd: >
{{ ansible_env.HOME }}/.local/bin/uv run pytest
{{ ansible_env.HOME }}/.local/bin/uv run lightspeed-tests
{{ pytest_args }}
--junitxml={{ junit_xml_path }}
chdir: "{{ test_suite_path }}"
Expand Down
15 changes: 5 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ dependencies = [
"pyyaml>=6.0.0",
]

[project.scripts]
lightspeed-tests = "rhos_lightspeed_tests:main"
lightspeed-test = "rhos_lightspeed_tests:main"

[dependency-groups]
dev = [
"ruff>=0.16.1",
Expand All @@ -24,15 +28,6 @@ dev = [
requires = ["uv_build>=0.12.3,<0.13"]
build-backend = "uv_build"

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--verbose --junitxml=test-results.xml"
python_files = "test_*.py"
python_functions = "test_*"
markers = [
"llm_dependent: requires generated answer content from a real LLM",
]

[tool.ruff]
line-length = 88
target-version = "py312"
Expand All @@ -41,4 +36,4 @@ target-version = "py312"
extend-select = ["S"]

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101"]
"src/rhos_lightspeed_tests/tests/**/*.py" = ["S101"]
22 changes: 21 additions & 1 deletion src/rhos_lightspeed_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
"""RHOS Lightspeed test utilities."""
"""RHOS Lightspeed test suite and shared utilities."""

import sys
from pathlib import Path

import pytest


def main() -> int:
"""Run selected tests or the bundled suite, returning pytest's exit status."""
return pytest.main(
[
"-c",
str(Path(__file__).with_name("pytest.ini")),
# Apply testpaths from any working directory and keep the cache there.
"--rootdir",
str(Path.cwd()),
"--pyargs",
*sys.argv[1:],
]
)
4 changes: 1 addition & 3 deletions src/rhos_lightspeed_tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import yaml

DEFAULT_CONFIG_PATH = (
Path(__file__).resolve().parent.parent.parent / "config" / "default.yaml"
)
DEFAULT_CONFIG_PATH = Path(__file__).with_name("default.yaml")


def load_config(config_path: str | None = None) -> dict:
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/rhos_lightspeed_tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
# Used only when no test path, module or node ID is supplied on the command line.
testpaths = rhos_lightspeed_tests.tests
addopts = --verbose --junitxml=test-results.xml
python_files = test_*.py
python_functions = test_*
markers =
llm_dependent: requires generated answer content from a real LLM
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
repeating it in the follow-up. This requires generated answer content and is
marked llm_dependent. Select the other two scenarios with:
pytest tests/integration/test_goose_responses.py -m "not llm_dependent"
lightspeed-tests -k goose -m "not llm_dependent"
This selection still requires a deployed Lightspeed service and a configured
LLM backend, which can be real or mocked. It does not configure the mock.
Expand Down
Empty file removed tests/unit/__init__.py
Empty file.
Loading