Skip to content
6 changes: 4 additions & 2 deletions docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ def test_dynflow_service_instances(server, instance):

## Where to add new tests

The directory `tests/feature` is special. Any subdirectory automatically applies the feature marker. `tests/feature/foreman/api_test.py` is equivalent to `tests/foreman_api_test.py` with `pytestmark = pytest.mark.feature("foreman")`.

| What you're testing | File |
| --- | --- |
| A new service (container or systemd unit) | `tests/<service>_test.py` |
| Foreman API behavior | `tests/foreman_api_test.py` (or a new file for larger areas) |
| A new service (container or systemd unit) | `tests/feature/<feature>/<service>_test.py` |
| Foreman API behavior | `tests/feature/foreman/api_test.py` (or a new file for larger areas) |
| Client registration or content workflows | `tests/client_test.py` |
| CLI flags, playbooks, or feature management | `tests/features_test.py` or `tests/playbooks_test.py` |
| A standalone script (no deployment needed) | `tests/unit/<name>_test.py` |
Expand Down
50 changes: 40 additions & 10 deletions src/playbooks/deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,44 @@
- "../../vars/foreman.yml"
- "../../vars/base.yaml"
pre_tasks:
- name: Add iop databases
- name: Determine databases
when:
- "'iop' in enabled_features"
- database_mode == 'internal'
block:
- name: Include iop databases
ansible.builtin.include_vars:
file: "../../vars/database_iop.yml"
- name: Configure Candlepin database
ansible.builtin.set_fact:
postgresql_databases: "{{ postgresql_databases + postgresql_databases_candlepin }}"
postgresql_users: "{{ postgresql_users + postgresql_users_candlepin }}"
when:
- "'foreman' in enabled_features"
- "'katello' in enabled_features"

- name: Configure Foreman database
ansible.builtin.set_fact:
postgresql_databases: "{{ postgresql_databases + postgresql_databases_foreman }}"
postgresql_users: "{{ postgresql_users + postgresql_users_foreman }}"
when:
- "'foreman' in enabled_features"

- name: Combine lists
- name: Configure Pulp database
ansible.builtin.set_fact:
postgresql_databases: "{{ postgresql_databases + iop_postgresql_databases }}"
postgresql_users: "{{ postgresql_users + iop_postgresql_users }}"
postgresql_databases: "{{ postgresql_databases + postgresql_databases_pulp }}"
postgresql_users: "{{ postgresql_users + postgresql_users_pulp }}"
when:
- "'katello' in enabled_features"

- name: Add iop databases
when:
- "'iop' in enabled_features"
block:
- name: Include iop databases
ansible.builtin.include_vars:
file: "../../vars/database_iop.yml"

- name: Combine lists
ansible.builtin.set_fact:
postgresql_databases: "{{ postgresql_databases + iop_postgresql_databases }}"
postgresql_users: "{{ postgresql_users + iop_postgresql_users }}"
roles:
- role: pre_install
- role: checks
Expand All @@ -40,9 +65,14 @@
when:
- database_mode == 'internal'
- redis
- candlepin
- role: candlepin
when:
- "'foreman' in enabled_features"
- "'katello' in enabled_features"
- httpd
- pulp
- role: pulp
when:
- "'katello' in enabled_features"
- foreman
- role: systemd_target
- role: iop_core
Expand Down
2 changes: 2 additions & 0 deletions src/roles/foreman/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,5 @@
oauth1_consumer_key: "{{ foreman_oauth_consumer_key }}"
oauth1_consumer_secret: "{{ foreman_oauth_consumer_secret }}"
ca_path: "{{ foreman_ca_certificate }}"
when:
- "'katello' in enabled_features"
16 changes: 14 additions & 2 deletions src/vars/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,29 @@ foreman_database_port: "{{ database_port }}"
foreman_database_ssl_mode: "{{ database_ssl_mode }}"
foreman_database_ssl_ca: "{{ database_ssl_ca }}"

postgresql_databases:
postgresql_databases_candlepin:
- name: "{{ candlepin_database_name }}"
owner: "{{ candlepin_database_user }}"

postgresql_databases_foreman:
- name: "{{ foreman_database_name }}"
owner: "{{ foreman_database_user }}"

postgresql_databases_pulp:
- name: "{{ pulp_database_name }}"
owner: "{{ pulp_database_user }}"
postgresql_users:

postgresql_users_candlepin:
- name: "{{ candlepin_database_user }}"
password: "{{ candlepin_database_password }}"

postgresql_users_foreman:
- name: "{{ foreman_database_user }}"
password: "{{ foreman_database_password }}"

postgresql_users_pulp:
- name: "{{ pulp_database_user }}"
password: "{{ pulp_database_password }}"

postgresql_databases: []
postgresql_users: []
3 changes: 3 additions & 0 deletions src/vars/flavors/foreman.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
flavor_features:
- foreman
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import uuid
from functools import cached_property
from pathlib import Path

import apypie
import paramiko
Expand Down Expand Up @@ -144,6 +145,10 @@
api._session.headers['Host'] = server_fqdn
return api

@pytest.fixture

Check failure on line 148 in tests/conftest.py

View workflow job for this annotation

GitHub Actions / Python Lint

ruff (E302)

tests/conftest.py:148:1: E302 Expected 2 blank lines, found 1 help: Add missing blank line(s)
def features(pytestconfig):
return pytestconfig.user_parameters.features


@pytest.fixture
def organization(foremanapi):
Expand Down Expand Up @@ -242,6 +247,19 @@
config.user_parameters = UserParameters(config)


def pytest_collection_modifyitems(config, items):
feature_dir = config.rootdir / 'tests' / 'feature'
for item in items:
try:
rel_path = Path(item.fspath).relative_to(feature_dir)
except ValueError:
# Not in the features directory
pass
else:
feature = rel_path.parts[0]
item.add_marker(pytest.mark.feature(feature))


def pytest_runtest_setup(item):
feature_markers = set(mark.args[0] for mark in item.iter_markers(name="feature"))
if feature_markers:
Expand Down
Empty file added tests/feature/__init__.py
Empty file.
Empty file.
File renamed without changes.
Empty file.
10 changes: 10 additions & 0 deletions tests/feature/foreman/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_foreman_organization(organization):
assert organization


def test_foreman_initial_organization(foremanapi):
assert foremanapi.list('organizations', search='name="Foreman CI"')


def test_foreman_initial_location(foremanapi):
assert foremanapi.list('locations', search='name="Internet"')
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_foreman_status_cache(foreman_status):
assert foreman_status['results']['foreman']['cache']['servers'][0]['status'] == 'ok'


@pytest.mark.feature('katello')
@pytest.mark.parametrize("katello_service", ['candlepin', 'candlepin_auth', 'foreman_tasks', 'katello_events', 'pulp3', 'pulp3_content'])
def test_katello_services_status(foreman_status, katello_service):
assert foreman_status['results']['katello']['services'][katello_service]['status'] == 'ok'
Expand Down
25 changes: 25 additions & 0 deletions tests/feature/foreman/compute_resources_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest


# TODO: Foreman really should have a dedicated API endpoint to expose this info
@pytest.fixture
def provider_description(foremanapi):
create = foremanapi.resource('compute_resources').action('create')
compute_resource_param = [param for param in create.params if param.name == 'compute_resource'][0]
provider = [param for param in compute_resource_param.params if param.name == 'provider'][0]
return provider.description


@pytest.mark.parametrize("compute_resource", ['EC2', 'Libvirt', 'Openstack', 'Vmware'])
def test_foreman_compute_resources_built_in(provider_description, compute_resource):
assert compute_resource in provider_description


@pytest.mark.feature('azure-rm')
def test_foreman_compute_resources_azure_rm(provider_description):
assert 'AzureRm' in provider_description


@pytest.mark.feature('google')
def test_foreman_compute_resources_google(provider_description):
assert 'GCE' in provider_description
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def test_foreman_organization(organization):
assert organization
import pytest

pytestmark = pytest.mark.feature('katello')


def test_foreman_product(product):
Expand Down Expand Up @@ -49,11 +50,3 @@ def test_foreman_manifest(organization, foremanapi, fixture_dir):
files = {'content': (str(manifest_path), manifest_file, 'application/zip')}
params = {'organization_id': organization['id']}
foremanapi.resource_action('subscriptions', 'upload', params, files=files)


def test_foreman_initial_organization(foremanapi):
assert foremanapi.list('organizations', search='name="Foreman CI"')


def test_foreman_initial_location(foremanapi):
assert foremanapi.list('locations', search='name="Internet"')
16 changes: 16 additions & 0 deletions tests/feature/foreman/plugins_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


@pytest.fixture
def foreman_plugins(foremanapi):
return [plugin['name'] for plugin in foremanapi.list('plugins')]


@pytest.mark.feature('azure-rm')
def test_foreman_compute_resources_azure_rm(foreman_plugins):
assert 'foreman_azure_rm' in foreman_plugins


@pytest.mark.feature('google')
def test_foreman_compute_resources_google(foreman_plugins):
assert 'foreman_google' in foreman_plugins
Empty file.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_advisor_backend_api_service(server):
service = server.service("iop-service-advisor-backend-api")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_advisor_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/advisor")
assert assets_dir.exists
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_cvemap_download_script(server):
script = server.file("/usr/local/bin/iop-cvemap-download.sh")
assert script.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_engine.py → tests/feature/iop/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_engine_service(server):
service = server.service("iop-core-engine")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_gateway_service(server):
service = server.service("iop-core-gateway")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_ingress_service(server):
service = server.service("iop-core-ingress")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_iop_core_kafka_service(server):
service = server.service("iop-core-kafka")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_inventory_migrate_service(server):
service = server.service("iop-core-host-inventory-migrate")
assert service.is_enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_inventory_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/inventory")
assert assets_dir.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_kafka.py → tests/feature/iop/test_kafka.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_kafka_service(server):
service = server.service("iop-core-kafka")
assert service.is_running
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_puptoo.py → tests/feature/iop/test_puptoo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_puptoo_service(server):
service = server.service("iop-core-puptoo")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_remediation_api_service(server):
service = server.service("iop-service-remediations-api")
assert service.is_running
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_vmaas.py → tests/feature/iop/test_vmaas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vmaas_reposcan_service(server):
service = server.service("iop-service-vmaas-reposcan")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vulnerability_manager_service(server):
service = server.service("iop-service-vuln-manager")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vulnerability_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/vulnerability")
assert assets_dir.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_yuptoo.py → tests/feature/iop/test_yuptoo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_yuptoo_service(server):
service = server.service("iop-core-yuptoo")
assert service.is_running
Expand Down
Empty file.
Loading
Loading