Scripting
Each workflow renders bash scripts that allow the developers to ensure the continued correctness of the instructions. These scripts may also be helpful to users as a basis for their own scripts. All of the scripts can be found at https://github.com/pulp/pulp_rpm/tree/main/docs/_scripts/
Some scripts have conditional statements for setting REPO_NAME, REMOTE_NAME, and DIST_NAME. These are used by Pulp team for validity testing.
The scripts come in pairs, with one (scriptname_cli.sh) using pulp-cli commands where available, and the other (scriptname.sh) using httpie REST calls.
The following scripts are used in conjunction with all the workflow scripts:
Base
Setting up to use pulp-cli:
#!/usr/bin/env bash
set -e
echo "Setting environment variables for default hostname/port for the API and the Content app"
BASE_ADDR=${BASE_ADDR:-http://localhost:24817}
export BASE_ADDR
CONTENT_ADDR=${CONTENT_ADDR:-http://localhost:24816}
export CONTENT_ADDR
# Necessary for `django-admin`
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings
# Set up a config for pulp-cli
if [ ! -f ${HOME}/.config/pulp/cli.toml ]
then
pulp config create --username admin --password password --base-url "${BASE_ADDR}" --no-verify-ssl
fi
# Poll a Pulp task until it is finished (needed when using httpie to make requests)
wait_until_task_finished() {
echo "Polling the task until it has reached a final state."
local task_url=$1
while true
do
response=$(http "$task_url")
local response
state=$(jq -r .state <<< "${response}")
local state
jq . <<< "${response}"
case ${state} in
failed|canceled)
echo "Task in final state: ${state}"
exit 1
;;
completed)
echo "$task_url complete."
break
;;
*)
echo "Still waiting..."
sleep 1
;;
esac
done
}
Setting up to use httpie:
#!/usr/bin/env bash
set -e
echo "Setting environment variables for default hostname/port for the API and the Content app"
BASE_ADDR=${BASE_ADDR:-http://localhost:24817}
export BASE_ADDR
CONTENT_ADDR=${CONTENT_ADDR:-http://localhost:24816}
export CONTENT_ADDR
# Necessary for `django-admin`
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings
# Poll a Pulp task until it is finished.
wait_until_task_finished() {
echo "Polling the task until it has reached a final state."
local task_url=$1
while true
do
response=$(http "$task_url")
local response
state=$(jq -r .state <<< "${response}")
local state
jq . <<< "${response}"
case ${state} in
failed|canceled)
echo "Task in final state: ${state}"
exit 1
;;
completed)
echo "$task_url complete."
break
;;
*)
echo "Still waiting..."
sleep 1
;;
esac
done
}
Correctness Checks
Warning
These scripts can harm your data.
To check the correctness of the sync with publish and download workflow scripts, they can all be run together using:
Using pulp-cli commands :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie (requires a .netrc for authentication), jq, curl and pulp-cli
# From the _scripts directory, run with `source docs_check_sync_publish.sh` (source to preserve the
# environment variables)
export REPO_NAME="sync-repo"
export REMOTE_NAME="sync-remote"
export DIST_NAME="sync-dist"
source base_cli.sh
source repo_cli.sh "${REPO_NAME}"
source remote_cli.sh "${REMOTE_NAME}"
source sync_cli.sh
source publication_cli.sh
source distribution_cli.sh "${DIST_NAME}"
source download_cli.sh
Using httpie to talk directly to the REST API :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie, jq and requires a .netrc for authentication with Pulp
# From the _scripts directory, run with `source docs_check_sync_publish.sh` (source to preserve the
# environment variables)
export REPO_NAME="sync-repo"
export DIST_NAME="sync-dist"
source base.sh
source repo.sh "$REPO_NAME"
source remote.sh
source sync.sh
source publication.sh
source distribution.sh "$DIST_NAME"
source download.sh
To check the correctness of the upload with publish and download workflow scripts, they can all be run together using:
Using pulp-cli commands :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie (requires a .netrc for authentication), jq, curl and pulp-cli
# From the _scripts directory, run with `source docs_check_upload.sh` (source to preserve
# the environment variables)
export REPO_NAME="upload-repo"
export DIST_NAME="upload-dist"
source base_cli.sh
source repo_cli.sh "${REPO_NAME}"
source artifact_cli.sh
source package_cli.sh
source add_remove_cli.sh
source advisory_cli.sh
source publication_cli.sh
source distribution_cli.sh "${DIST_NAME}"
source download_cli.sh
Using httpie to talk directly to the REST API :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie, jq, curl and requires a .netrc for authentication with Pulp
# From the _scripts directory, run with `source docs_check_upload.sh` (source to preserve
# the environment variables)
export REPO_NAME="upload-repo"
export DIST_NAME="upload-dist"
source base.sh
source repo.sh "$REPO_NAME"
source artifact.sh
source package.sh
source add_remove.sh
source advisory.sh
source publication.sh
source distribution.sh "$DIST_NAME"
source download.sh
To check the correctness of the basic copy with publish and download workflow scripts, they can all be run together using:
Using pulp-cli commands :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie (requires a .netrc for authentication), jq, curl and pulp-cli
# From the _scripts directory, run with `source docs_check_copy.sh` (source to preserve
# the environment variables)
export REPO_NAME="copy-repo"
export DIST_NAME="copy-dist"
export REMOTE_ARTIFACT="https://fixtures.pulpproject.org/rpm-signed/shark-0.1-1.noarch.rpm"
source base_cli.sh
source repo_cli.sh "${REPO_NAME}"
source artifact_cli.sh ${REMOTE_ARTIFACT}
source package_cli.sh
source copy_basic_cli.sh
source publication_cli.sh
source distribution_cli.sh "${DIST_NAME}"
source download_cli.sh
Using httpie to talk directly to the REST API :
#!/usr/bin/env bash
# This script will execute the component scripts and ensure that the documented examples
# work as expected.
# NOTE: These scripts use httpie, jq, curl and requires a .netrc for authentication with Pulp
# From the _scripts directory, run with `source docs_check_copy.sh` (source to preserve
# the environment variables)
export REPO_NAME="copy-repo"
export DIST_NAME="copy-dist"
export REMOTE_ARTIFACT="https://fixtures.pulpproject.org/rpm-signed/shark-0.1-1.noarch.rpm"
source base.sh
source repo.sh "$REPO_NAME"
source artifact.sh $REMOTE_ARTIFACT
source package.sh
source copy_basic.sh
source publication.sh
source distribution.sh "$DIST_NAME"
source download.sh