Skip to content

Commit

Permalink
Remove drpm test and fix borked CI (#3323)
Browse files Browse the repository at this point in the history
* Skip test that uses DRPM fixture, for now. It's not worth maintaining the fixture, and in the future we ought to be
able to do this test without it.
* Made metadata downloading util agnostic to compression type
* Ditch all usages of http_get and http_get_headers for requests
* Fix CI after working directory adjustment in the template
  • Loading branch information
dralley authored Nov 28, 2023
1 parent 9bbdeec commit 392e74b
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/post_before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [[ "$TEST" == "upgrade" ]]; then
exit
fi

cmd_stdin_prefix bash -c "cat > /var/lib/pulp/scripts/sign-metadata.sh" < "$GITHUB_WORKSPACE"/pulp_rpm/tests/functional/sign-metadata.sh
cmd_stdin_prefix bash -c "cat > /var/lib/pulp/scripts/sign-metadata.sh" < pulp_rpm/tests/functional/sign-metadata.sh

curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-KEY-fixture-signing | cmd_stdin_prefix su pulp -c "cat > /tmp/GPG-KEY-fixture-signing"
curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-PRIVATE-KEY-fixture-signing | cmd_stdin_prefix su pulp -c "gpg --import"
Expand Down
4 changes: 3 additions & 1 deletion functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
django # TODO: test_sync.py has a dependency on date parsing functions
git+https://github.com/pulp/pulp-smash.git#egg=pulp-smash
productmd>=1.25
pytest
dictdiffer
xmltodict
pyyaml
lxml
django # TODO: test_sync.py has a dependency on date parsing functions
pyzstd
requests
12 changes: 7 additions & 5 deletions pulp_rpm/tests/functional/api/test_character_encoding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Tests for Pulp's characters encoding."""
import pytest
import uuid

import pytest
import requests

from pulpcore.tests.functional.utils import PulpTaskError
from pulp_rpm.tests.functional.constants import (
RPM_WITH_NON_ASCII_NAME,
Expand All @@ -21,11 +23,11 @@


def test_upload_non_ascii(
tmp_path, artifacts_api_client, http_get, rpm_package_api, monitor_task, delete_orphans_pre
tmp_path, artifacts_api_client, rpm_package_api, monitor_task, delete_orphans_pre
):
"""Test whether one can upload an RPM with non-ascii metadata."""
temp_file = tmp_path / str(uuid.uuid4())
temp_file.write_bytes(http_get(RPM_WITH_NON_ASCII_URL))
temp_file.write_bytes(requests.get(RPM_WITH_NON_ASCII_URL).content)
artifact = artifacts_api_client.create(temp_file)
response = rpm_package_api.create(
artifact=artifact.pulp_href,
Expand All @@ -36,11 +38,11 @@ def test_upload_non_ascii(


def test_upload_non_utf8(
tmp_path, artifacts_api_client, http_get, rpm_package_api, monitor_task, delete_orphans_pre
tmp_path, artifacts_api_client, rpm_package_api, monitor_task, delete_orphans_pre
):
"""Test whether an exception is raised when non-utf-8 is uploaded."""
temp_file = tmp_path / str(uuid.uuid4())
temp_file.write_bytes(http_get(RPM_WITH_NON_UTF_8_URL))
temp_file.write_bytes(requests.get(RPM_WITH_NON_UTF_8_URL).content)
artifact = artifacts_api_client.create(temp_file)
with pytest.raises(PulpTaskError) as ctx:
response = rpm_package_api.create(
Expand Down
33 changes: 13 additions & 20 deletions pulp_rpm/tests/functional/api/test_consume_content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Verify whether package manager, yum/dnf, can consume content from Pulp."""
import pytest
import subprocess
import itertools

import pytest
import requests

from pulp_rpm.tests.functional.constants import (
# REPO_WITH_XML_BASE_URL,
RPM_UNSIGNED_FIXTURE_URL,
)


dnf_installed = subprocess.run(("which", "dnf")).returncode == 0


Expand Down Expand Up @@ -189,7 +190,6 @@ def test_config_dot_repo(
generate_repo_config,
rpm_metadata_signing_service,
create_distribution,
http_get,
):
"""Test if the generated config.repo has the right content."""
if has_signing_service and rpm_metadata_signing_service is None:
Expand All @@ -202,7 +202,7 @@ def test_config_dot_repo(
has_signing_service=has_signing_service,
generate_repo_config=generate_repo_config,
)
content = http_get(f"{distribution.base_url}config.repo").decode("utf-8")
content = requests.get(f"{distribution.base_url}config.repo").text

assert f"[{distribution.name}]\n" in content
assert f"baseurl={distribution.base_url}\n" in content
Expand All @@ -218,23 +218,16 @@ def test_config_dot_repo(


@pytest.mark.parallel
def test_repomd_headers(
create_distribution,
http_get_headers,
):
def test_repomd_headers(create_distribution):
"""Test if repomd.xml is returned with Cache-control: no-cache header."""
distribution = create_distribution(
repo_config={}, has_signing_service=True, generate_repo_config=True
)
assert (
http_get_headers(f"{distribution.base_url}repodata/repomd.xml").get("Cache-control", "")
== "no-cache"
)
assert (
not http_get_headers(f"{distribution.base_url}config.repo").get("Cache-control", "")
== "no-cache"
)
assert (
http_get_headers(f"{distribution.base_url}repodata/repomd.xml.key").get("Cache-control", "")
== "no-cache"
)
resp = requests.get(f"{distribution.base_url}repodata/repomd.xml")
assert resp.headers.get("Cache-control", "") == "no-cache"

resp = requests.get(f"{distribution.base_url}config.repo")
assert not resp.headers.get("Cache-control", "") == "no-cache"

resp = requests.get(f"{distribution.base_url}repodata/repomd.xml.key")
assert resp.headers.get("Cache-control", "") == "no-cache"
25 changes: 8 additions & 17 deletions pulp_rpm/tests/functional/api/test_crud_content_unit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Tests that perform actions over content unit."""
import aiohttp
import asyncio
import json
import pytest

from urllib.parse import urljoin

import pytest
import requests

from pulp_rpm.tests.functional.utils import gen_rpm_content_attrs
from pulp_rpm.tests.functional.constants import (
RPM_KICKSTART_FIXTURE_URL,
Expand Down Expand Up @@ -101,9 +99,7 @@ def test_crud_content_unit(
[RPM_MODULAR_FIXTURE_URL, RPM_KICKSTART_FIXTURE_URL, RPM_REPO_METADATA_FIXTURE_URL],
ids=["MODULAR_FIXTURE_URL", "KICKSTART_FIXTURE_URL", "REPO_METADATA_FIXTURE_URL"],
)
def test_remove_content_unit(
url, init_and_sync, rpm_repository_version_api, bindings_cfg, http_get
):
def test_remove_content_unit(url, init_and_sync, rpm_repository_version_api, bindings_cfg):
"""
Sync a repository and test that content of any type cannot be removed directly.
Expand All @@ -123,21 +119,16 @@ def test_remove_content_unit(
# Test remove content by types contained in repository.
version = rpm_repository_version_api.read(repo.latest_version_href)

async def _delete_request(url, **kwargs):
async with aiohttp.ClientSession(raise_for_status=False) as session:
async with session.delete(url, **kwargs) as response:
return response.status

# iterate over content filtered by repository versions
for content_units in version.content_summary.added.values():
auth = aiohttp.BasicAuth(bindings_cfg.username, bindings_cfg.password)
auth = (bindings_cfg.username, bindings_cfg.password)
url = urljoin(bindings_cfg.host, content_units["href"])
response = json.loads(http_get(url, auth=auth).decode())
response = requests.get(url, auth=auth).json()

# iterate over particular content units and issue delete requests
for content_unit in response["results"]:
url = urljoin(bindings_cfg.host, content_unit["pulp_href"])
status = asyncio.run(_delete_request(url, auth=auth))
resp = requests.delete(url, auth=auth)

# check that '405' (method not allowed) is returned
assert status == 405
assert resp.status_code == 405
12 changes: 4 additions & 8 deletions pulp_rpm/tests/functional/api/test_download_content.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Tests that verify download of content served by Pulp."""
import pytest
import hashlib
from random import choice
from urllib.parse import urljoin

import pytest
import requests

from pulp_rpm.tests.functional.constants import RPM_UNSIGNED_FIXTURE_URL
from pulp_rpm.tests.functional.utils import (
get_package_repo_path,
Expand All @@ -18,7 +20,6 @@ def test_all(
rpm_publication_api,
rpm_distribution_factory,
download_content_unit,
http_get,
gen_object_with_cleanup,
):
"""Verify whether content served by pulp can be downloaded.
Expand All @@ -40,11 +41,6 @@ def test_all(
2. Select a random content unit in the distribution. Download that
content unit from Pulp, and verify that the content unit has the
same checksum when fetched directly from Pulp-Fixtures.
This test targets the following issues:
* `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
* `Pulp Smash #872 <https://github.com/pulp/pulp-smash/issues/872>`_
"""
# Sync a Repository
repo = rpm_unsigned_repo_immediate
Expand All @@ -61,7 +57,7 @@ def test_all(
package_paths = [p.location_href for p in packages.results]
unit_path = choice(package_paths)
fixture_hash = hashlib.sha256(
http_get(urljoin(RPM_UNSIGNED_FIXTURE_URL, unit_path))
requests.get(urljoin(RPM_UNSIGNED_FIXTURE_URL, unit_path)).content
).hexdigest()

# …and Pulp.
Expand Down
7 changes: 4 additions & 3 deletions pulp_rpm/tests/functional/api/test_fips_workflow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests that create/sync/distribute/publish MANY rpm plugin repositories."""
import pytest
import os
import re

import pytest
import requests


@pytest.fixture
def cdn_certs_and_keys():
Expand Down Expand Up @@ -178,7 +180,6 @@ def test_fips_workflow(
rpm_publication_factory,
rpm_distribution_factory,
cdn_certs_and_keys,
http_get,
):
# Convert a url into a name-string
name = _name_from_url(url)
Expand Down Expand Up @@ -208,5 +209,5 @@ def test_fips_workflow(
assert distribution is not None

# Test we can access the index of the distribution
response = http_get(distribution.base_url)
response = requests.get(distribution.base_url)
assert response is not None
Loading

0 comments on commit 392e74b

Please sign in to comment.