Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ jobs:
ansible-playbook playbooks/deploy.yaml
- name: Run tests
run: ./run_tests
- name: Upload logs
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: logs
path: logs.tar.gz
retention-days: 5
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest-testinfra
paramiko
apypie @ git+https://github.com/Apipie/apypie.git@foreman
2 changes: 1 addition & 1 deletion roles/foreman/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
foreman_container_image: "quay.io/evgeni/foreman-rpm"
foreman_container_tag: "3.12"
foreman_container_tag: "nightly"
6 changes: 6 additions & 0 deletions roles/pulp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
port: 24817
timeout: 300

- name: Wait for Pulp API service to be accessible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate chunk of code now, this is handled on line 146.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to review #43 instead? This (and #50) were just there to try out things while other PRs were ongoing

ansible.builtin.wait_for:
host: "{{ ansible_hostname }}"
port: 24817
timeout: 300

- name: Start the Pulp Content services
ansible.builtin.systemd:
name: pulp-content
Expand Down
2 changes: 1 addition & 1 deletion run_tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

vagrant ssh-config > .vagrant/ssh-config
py.test --hosts=quadlet --sudo --ssh-config=.vagrant/ssh-config tests/*_test.py
py.test -vv --hosts=quadlet --sudo --ssh-config=.vagrant/ssh-config tests/*_test.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was just merged and can be dropped from the PR.

45 changes: 45 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import uuid

import apypie
import paramiko
import pytest


@pytest.fixture(scope="module")
def ssh_config():
config = paramiko.SSHConfig.from_path('./.vagrant/ssh-config')
return config.lookup('quadlet')


@pytest.fixture(scope="module")
def foremanapi(ssh_config):
return apypie.ForemanApi(
uri=f'https://{ssh_config['hostname']}',
username='admin',
password='changeme',
verify_ssl=False,
)

@pytest.fixture
def organization(foremanapi):
org = foremanapi.create('organizations', {'name': str(uuid.uuid4())})
yield org
foremanapi.delete('organizations', org)

@pytest.fixture
def product(organization, foremanapi):
prod = foremanapi.create('products', {'name': str(uuid.uuid4()), 'organization_id': organization['id']})
yield prod
foremanapi.delete('products', prod)

@pytest.fixture
def yum_repository(product, organization, foremanapi):
repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'yum', 'url': 'https://fixtures.pulpproject.org/rpm-no-comps/'})
yield repo
foremanapi.delete('repositories', repo)

@pytest.fixture
def file_repository(product, organization, foremanapi):
repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'file', 'url': 'https://fixtures.pulpproject.org/file/'})
yield repo
foremanapi.delete('repositories', repo)
28 changes: 28 additions & 0 deletions tests/foreman_api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import urllib.parse

import requests


def _repo_url(repo, ssh_config):
return urllib.parse.urlunparse(urllib.parse.urlparse(repo['full_path'])._replace(netloc=ssh_config['hostname']))


def test_foreman_organization(organization):
assert organization

def test_foreman_product(product):
assert product

def test_foreman_yum_repository(yum_repository, foremanapi, ssh_config):
assert yum_repository
foremanapi.resource_action('repositories', 'sync', {'id': yum_repository['id']})
repo_url = _repo_url(yum_repository, ssh_config)
assert requests.get(f'{repo_url}/repodata/repomd.xml', verify=False)
assert requests.get(f'{repo_url}/Packages/b/bear-4.1-1.noarch.rpm', verify=False)


def test_foreman_file_repository(file_repository, foremanapi, ssh_config):
assert file_repository
foremanapi.resource_action('repositories', 'sync', {'id': file_repository['id']})
repo_url = _repo_url(file_repository, ssh_config)
assert requests.get(f'{repo_url}/1.iso', verify=False)
8 changes: 8 additions & 0 deletions tests/zzz_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def test_collect_report(host):
host.run('mkdir -p logs')
for container, filename in [('foreman', '/var/log/foreman/production.log')]:
localfile = filename.replace('/', '_')
host.run(f'podman cp {container}:{filename} logs/{container}-{localfile}')
host.run('tar caf logs.tar.gz logs/')
with open('logs.tar.gz', 'wb') as logstar:
logstar.write(host.file('logs.tar.gz').content)