Skip to content

Commit

Permalink
Fix for pulp setup (#511)
Browse files Browse the repository at this point in the history
* Fix for pulp setup
* Bump pulp image to 3.23.3
  • Loading branch information
Shrews committed May 2, 2023
1 parent a6ceb61 commit b60f10c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
23 changes: 21 additions & 2 deletions .github/test-scripts/setup_pulp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,30 @@ docker:
EOF


##############################################################################
# Set up for an insecure registry. Back it up only once for local testing.
##############################################################################

REGISTRY_FILE="$HOME/.config/containers/registries.conf"
REGISTRY_FILE_BACKUP="${REGISTRY_FILE}.ORIG"
if [ -e "$REGISTRY_FILE" ] && [ ! -e "$REGISTRY_FILE_BACKUP" ]
then
echo "Backing up user's Podman registry to $REGISTRY_FILE_BACKUP"
mv $REGISTRY_FILE $REGISTRY_FILE_BACKUP
fi

cat <<EOF > "$REGISTRY_FILE"
[[registry]]
location="localhost:8080"
insecure=true
EOF

##############################################################################
# Pull and run the pulp container
##############################################################################

podman pull docker.io/pulp/pulp:3.19
PULP_IMAGE="pulp:3.23.3"
podman pull docker.io/pulp/$PULP_IMAGE

mkdir pulp
cd pulp
Expand All @@ -59,7 +78,7 @@ podman run --detach \
--volume "$(pwd)/pgsql":/var/lib/pgsql \
--volume "$(pwd)/containers":/var/lib/containers \
--device /dev/fuse \
pulp/pulp
$PULP_IMAGE

##############################################################################
# Iteratively query the REST API until we get a JSON response (http code will
Expand Down
32 changes: 1 addition & 31 deletions test/pulp_integration/test_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
RUN_UUID = str(uuid.uuid4())
USER_POLICY_PATH = '~/.config/containers/policy.json'
BACKUP_POLICY_PATH = f'~/.config/containers/policy.json.{RUN_UUID}'
USER_REGISTRIES_PATH = '~/.config/containers/registries.conf'
BACKUP_REGISTRIES_PATH = f'~/.config/containers/registries.conf.{RUN_UUID}'


@pytest.mark.serial
@pytest.mark.destructive
class TestPolicies:
"""
All tests within this class must run serially since they all make use of
the test user's policy.json file which is acting as our system-level
podman policy file. The user's registries.conf is also altered.
podman policy file.
"""

@classmethod
Expand All @@ -34,10 +31,6 @@ def setup_class(cls):
In order to assist developers with local testing, we'll move this file
out of the way (BACKUP_POLICY_PATH) and restore it during test teardown.
Our pulp-based test registry does not use secure connections, so we must
modify our registries.conf file so that podman commands will not fail.
The original registries.conf file should be restored during teardown.
After all tests are done, remove images downloaded from pulp repo and
dangling (<none>) images.
"""
Expand All @@ -46,24 +39,6 @@ def setup_class(cls):
target = Path(BACKUP_POLICY_PATH).expanduser()
user_policy.rename(target)

user_registries = Path(USER_REGISTRIES_PATH).expanduser()
if user_registries.exists():
target = Path(BACKUP_REGISTRIES_PATH).expanduser()
user_registries.rename(target)

data = '[[registry]]\nlocation="localhost:8080"\ninsecure=true\n'
conf = Path(USER_REGISTRIES_PATH).expanduser()
conf.parent.mkdir(parents=True, exist_ok=True)
conf.write_text(data)

try:
cmd = 'podman image prune --force'
subprocess.run(cmd.split())
cmd = 'podman rmi localhost:8080/testrepo/ansible-builder-rhel8:latest'
subprocess.run(cmd.split())
except Exception:
pass

@classmethod
def teardown_class(cls):
"""
Expand All @@ -74,11 +49,6 @@ def teardown_class(cls):
target = Path(USER_POLICY_PATH).expanduser()
renamed_policy.rename(target)

renamed_registries = Path(BACKUP_REGISTRIES_PATH).expanduser()
if renamed_registries.exists():
target = Path(USER_REGISTRIES_PATH).expanduser()
renamed_registries.rename(target)

def write_policy(self, data):
policy = Path(USER_POLICY_PATH).expanduser()
policy.parent.mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit b60f10c

Please sign in to comment.