Skip to content

Commit

Permalink
Docs script fix
Browse files Browse the repository at this point in the history
Fix copy script - moved as single script used in correctness check script.
Add this copy script to travis docs check.

Adjust scripts to pass shellcheck.

closes: #7176
https://pulp.plan.io/issues/7176
  • Loading branch information
pavelpicka committed Aug 18, 2020
1 parent 6244263 commit 64c60dd
Show file tree
Hide file tree
Showing 21 changed files with 2,081 additions and 16,401 deletions.
1 change: 1 addition & 0 deletions .travis/post_docs_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export CONTENT_ADDR=http://pulp:80
cd docs/_scripts/
bash docs_check_upload.sh
bash docs_check_sync.sh
bash docs_check_copy.sh
1 change: 1 addition & 0 deletions CHANGES/7176.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix copy script example typos.
10 changes: 6 additions & 4 deletions docs/_scripts/add_remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

# Add created RPM content to repository
echo "Add created RPM Package to repository."
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'modify/' \
TASK_URL=$(http POST "$BASE_ADDR""$REPO_HREF"'modify/' \
add_content_units:="[\"$PACKAGE_HREF\"]" | jq -r '.task')
export TASK_URL

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
export REPOVERSION_HREF_WITH_PKG=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')
REPOVERSION_HREF_WITH_PKG=$(http "$BASE_ADDR""$TASK_URL" | jq -r '.created_resources | first')
export REPOVERSION_HREF_WITH_PKG

echo "Inspecting RepositoryVersion."
http $BASE_ADDR$REPOVERSION_HREF_WITH_PKG
http "$BASE_ADDR""$REPOVERSION_HREF_WITH_PKG"
12 changes: 7 additions & 5 deletions docs/_scripts/advisory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ export ADVISORY="advisory.json"

# Upload advisory
echo "Upload advisory in JSON format."
export TASK_URL=$(http --form POST $BASE_ADDR/pulp/api/v3/content/rpm/advisories/ \
file@./$ADVISORY repository=$REPO_HREF | jq -r '.task')
TASK_URL=$(http --form POST "$BASE_ADDR"/pulp/api/v3/content/rpm/advisories/ \
file@./"$ADVISORY" repository="$REPO_HREF" | jq -r '.task')
export TASK_URL

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set ADVISORY_HREF from finished task."
export ADVISORY_HREF=$(http $BASE_ADDR$TASK_URL \
ADVISORY_HREF=$(http "$BASE_ADDR""$TASK_URL" \
| jq -r '.created_resources | .[] | match(".*advisories.*") | .string')
export ADVISORY_HREF

echo "Inspecting advisory."
http $BASE_ADDR$ADVISORY_HREF
http "$BASE_ADDR""$ADVISORY_HREF"
17 changes: 12 additions & 5 deletions docs/_scripts/artifact.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env bash

# Get an RPM package
curl -O https://fixtures.pulpproject.org/rpm-unsigned/squirrel-0.1-1.noarch.rpm
export PKG="squirrel-0.1-1.noarch.rpm"
if [[ -n "$1" ]]; then
export REMOTE_FILE="$1"
else
export REMOTE_FILE="https://fixtures.pulpproject.org/rpm-signed/squirrel-0.1-1.noarch.rpm"
fi
curl -O "$REMOTE_FILE"
PKG="$(basename $REMOTE_FILE)"
export PKG

# Upload it as an Artifact
echo "Upload an RPM package."
export ARTIFACT_HREF=$(http --form POST $BASE_ADDR/pulp/api/v3/artifacts/ \
file@./$PKG | jq -r '.pulp_href')
ARTIFACT_HREF=$(http --form POST "$BASE_ADDR"/pulp/api/v3/artifacts/ \
file@./"$PKG" | jq -r '.pulp_href')
export ARTIFACT_HREF

echo "Inspecting artifact."
http $BASE_ADDR$ARTIFACT_HREF
http "$BASE_ADDR""$ARTIFACT_HREF"
12 changes: 8 additions & 4 deletions docs/_scripts/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
set -e

echo "Setting environment variables for default hostname/port for the API and the Content app"
export BASE_ADDR=${BASE_ADDR:-http://localhost:24817}
export CONTENT_ADDR=${CONTENT_ADDR:-http://localhost:24816}
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
Expand All @@ -14,8 +16,10 @@ wait_until_task_finished() {
local task_url=$1
while true
do
local response=$(http $task_url)
local state=$(jq -r .state <<< ${response})
response=$(http "$task_url")
local response
state=$(jq -r .state <<< "${response}")
local state
jq . <<< "${response}"
case ${state} in
failed|canceled)
Expand Down
27 changes: 27 additions & 0 deletions docs/_scripts/copy_basic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Add content unit to the repository
echo "Add and then remove content from repository."
TASK_URL=$(http POST "$BASE_ADDR""$REPO_HREF"'modify'/ add_content_units:="[\"$PACKAGE_HREF\"]" | jq -r '.task')
wait_until_task_finished "$BASE_ADDR""$TASK_URL"
REPOVERSION_HREF_WITH_PKG=$(http "$BASE_ADDR""$TASK_URL" | jq -r '.created_resources | first')
export REPOVERSION_HREF_WITH_PKG

# Remove content units from the repository
http POST "$BASE_ADDR""$REPO_HREF"'modify'/ remove_content_units:="[\"$PACKAGE_HREF\"]"

# Clone a repository (can be composed with addition or removal of units)
echo "Clone a repository with a content."
TASK_URL=$(http POST "$BASE_ADDR""$REPO_HREF"'modify'/ \
base_version="$REPOVERSION_HREF_WITH_PKG" | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
REPOVERSION_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export REPOVERSION_HREF

echo "Inspecting RepositoryVersion."
http "$BASE_ADDR""$REPOVERSION_HREF"
16 changes: 9 additions & 7 deletions docs/_scripts/distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

# Variables
if [ $# -eq 0 ]; then
export BASE_PATH="foo"
BASE_PATH="foo"
else
export BASE_PATH="$1"
BASE_PATH="$1"
fi
export BASE_PATH

# Create RPM distribution for publication
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/distributions/rpm/rpm/ \
publication=$PUBLICATION_HREF name="$BASE_PATH" base_path="$REPO_NAME" | jq -r '.task')
TASK_URL=$(http POST "$BASE_ADDR"/pulp/api/v3/distributions/rpm/rpm/ \
publication="$PUBLICATION_HREF" name="$BASE_PATH" base_path="$REPO_NAME" | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new distribution
echo "Set DISTRIBUTION_HREF from finished task."
export DISTRIBUTION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')
DISTRIBUTION_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export DISTRIBUTION_HREF

echo "Inspecting Distribution."
http $BASE_ADDR$DISTRIBUTION_HREF
http "$BASE_ADDR""$DISTRIBUTION_HREF"
24 changes: 24 additions & 0 deletions docs/_scripts/docs_check_copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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
2 changes: 1 addition & 1 deletion docs/_scripts/docs_check_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# 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_publish.sh` (source to preserve
# From the _scripts directory, run with `source docs_check_upload.sh` (source to preserve
# the environment variables)

export REPO_NAME="upload-repo"
Expand Down
7 changes: 4 additions & 3 deletions docs/_scripts/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ SHORT="${PKG:0:1}"

# The distribution will return a url that can be used by http clients
echo "Setting DISTRIBUTION_BASE_URL, which is used to retrieve content from the content app."
export DISTRIBUTION_BASE_URL=$(http $BASE_ADDR$DISTRIBUTION_HREF | jq -r '.base_url')
DISTRIBUTION_BASE_URL=$(http "$BASE_ADDR""$DISTRIBUTION_HREF" | jq -r '.base_url')
export DISTRIBUTION_BASE_URL

# If Pulp was installed without CONTENT_HOST set, it's just the path.
# And httpie will default to localhost:80
if [[ "${DISTRIBUTION_BASE_URL:0:1}" = "/" ]]; then
DISTRIBUTION_BASE_URL=$CONTENT_ADDR$DISTRIBUTION_BASE_URL
DISTRIBUTION_BASE_URL="$CONTENT_ADDR""$DISTRIBUTION_BASE_URL"
fi

# Download a package from the distribution
echo "Download a package from the distribution."
http -d ${DISTRIBUTION_BASE_URL}Packages/${SHORT}/${PKG}
http -d "$DISTRIBUTION_BASE_URL"Packages/"$SHORT"/"$PKG"
14 changes: 7 additions & 7 deletions docs/_scripts/install_from_signed_repository.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env bash

BASE_URL=$(http ${BASE_ADDR}${DISTRIBUTION_HREF} | jq -r '.base_url')
BASE_PATH=$(http ${BASE_ADDR}${DISTRIBUTION_HREF} | jq -r '.base_path')
PUBLIC_KEY_URL=${BASE_URL}/repodata/public.key
BASE_URL=$(http "$BASE_ADDR""$DISTRIBUTION_HREF" | jq -r '.base_url')
BASE_PATH=$(http "$BASE_ADDR""$DISTRIBUTION_HREF" | jq -r '.base_path')
PUBLIC_KEY_URL="$BASE_URL"/repodata/public.key

echo "Setting up a YUM repository."
sudo dnf config-manager --add-repo ${BASE_URL}
sudo dnf config-manager --add-repo "$BASE_URL"
sudo dnf config-manager --save \
--setopt=*${BASE_PATH}.gpgcheck=0 \
--setopt=*${BASE_PATH}.repo_gpgcheck=1 \
--setopt=*${BASE_PATH}.gpgkey=${PUBLIC_KEY_URL}
--setopt=*"$BASE_PATH".gpgcheck=0 \
--setopt=*"$BASE_PATH".repo_gpgcheck=1 \
--setopt=*"$BASE_PATH".gpgkey="$PUBLIC_KEY_URL"

sudo dnf install -y walrus
11 changes: 6 additions & 5 deletions docs/_scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

# Create RPM package from an artifact
echo "Create RPM content from artifact."
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/content/rpm/packages/ \
artifact=$ARTIFACT_HREF relative_path=$PKG | jq -r '.task')
TASK_URL=$(http POST "$BASE_ADDR"/pulp/api/v3/content/rpm/packages/ \
artifact="$ARTIFACT_HREF" relative_path="$PKG" | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new package (RPM content)
echo "Set PACKAGE_HREF from finished task."
export PACKAGE_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')
PACKAGE_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export PACKAGE_HREF

echo "Inspecting Package."
http $BASE_ADDR$PACKAGE_HREF
http "$BASE_ADDR""$PACKAGE_HREF"
11 changes: 6 additions & 5 deletions docs/_scripts/publication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

# Create RPM publication
echo "Create a task to create a publication."
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/publications/rpm/rpm/ \
repository=$REPO_HREF metadata_checksum_type=sha256 | jq -r '.task')
TASK_URL=$(http POST "$BASE_ADDR"/pulp/api/v3/publications/rpm/rpm/ \
repository="$REPO_HREF" metadata_checksum_type=sha256 | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new publication
echo "Set PUBLICATION_HREF from finished task."
export PUBLICATION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')
PUBLICATION_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export PUBLICATION_HREF

echo "Inspecting Publication."
http $BASE_ADDR$PUBLICATION_HREF
http "$BASE_ADDR""$PUBLICATION_HREF"
7 changes: 4 additions & 3 deletions docs/_scripts/remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

# Create new RPM remote
echo "Creating a remote that points to an external source of files."
http POST $BASE_ADDR/pulp/api/v3/remotes/rpm/rpm/ \
http POST "$BASE_ADDR"/pulp/api/v3/remotes/rpm/rpm/ \
name='bar' \
url='https://fixtures.pulpproject.org/rpm-unsigned/' \
policy='on_demand'

echo "Export an environment variable for the new remote URI."
export REMOTE_HREF=$(http $BASE_ADDR/pulp/api/v3/remotes/rpm/rpm/ \
REMOTE_HREF=$(http "$BASE_ADDR"/pulp/api/v3/remotes/rpm/rpm/ \
| jq -r '.results[] | select(.name == "bar") | .pulp_href')
export REMOTE_HREF

echo "Inspecting new Remote."
http $BASE_ADDR$REMOTE_HREF
http "$BASE_ADDR""$REMOTE_HREF"
10 changes: 6 additions & 4 deletions docs/_scripts/repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

# Create RPM repository
if [ $# -eq 0 ]; then
export REPO_NAME="foo"
REPO_NAME="foo"
else
export REPO_NAME="$1"
REPO_NAME="$1"
fi
export REPO_NAME

echo "Creating a new repository named $REPO_NAME."
export REPO_HREF=$(http POST $BASE_ADDR/pulp/api/v3/repositories/rpm/rpm/ name=$REPO_NAME \
REPO_HREF=$(http POST "$BASE_ADDR"/pulp/api/v3/repositories/rpm/rpm/ name="$REPO_NAME" \
| jq -r '.pulp_href')
export REPO_HREF

echo "Inspecting Repository."
http $BASE_ADDR$REPO_HREF
http "$BASE_ADDR""$REPO_HREF"
15 changes: 9 additions & 6 deletions docs/_scripts/repo_with_signing_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

# Create RPM repository
if [ $# -eq 0 ]; then
export REPO_NAME="foo"
REPO_NAME="foo"
else
export REPO_NAME="$1"
REPO_NAME="$1"
fi
export REPO_NAME

echo "Fetching the signing service."
export SIGNING_SERVICE_HREF=$(http ${BASE_ADDR}/pulp/api/v3/signing-services/?name="sign-metadata" \
SIGNING_SERVICE_HREF=$(http "$BASE_ADDR"/pulp/api/v3/signing-services/?name="sign-metadata" \
| jq -r '.results[0].pulp_href')
export SIGNING_SERVICE_HREF

echo "Creating a new repository named $REPO_NAME."
export REPO_HREF=$(http POST ${BASE_ADDR}/pulp/api/v3/repositories/rpm/rpm/ name=$REPO_NAME \
metadata_signing_service=${SIGNING_SERVICE_HREF} \
REPO_HREF=$(http POST "$BASE_ADDR"/pulp/api/v3/repositories/rpm/rpm/ name="$REPO_NAME" \
metadata_signing_service="$SIGNING_SERVICE_HREF" \
| jq -r '.pulp_href')
export REPO_HREF

echo "Inspecting Repository."
http ${BASE_ADDR}${REPO_HREF}
http "$BASE_ADDR""$REPO_HREF"
11 changes: 6 additions & 5 deletions docs/_scripts/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

# Sync repository foo using remote bar
echo "Create a task to sync the repository using the remote."
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'sync/' \
remote=$REMOTE_HREF \
TASK_URL=$(http POST "$BASE_ADDR""$REPO_HREF"'sync/' \
remote="$REMOTE_HREF" \
| jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
export REPOVERSION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')
REPOVERSION_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export REPOVERSION_HREF

echo "Inspecting RepositoryVersion."
http $BASE_ADDR$REPOVERSION_HREF
http "$BASE_ADDR""$REPOVERSION_HREF"
Loading

0 comments on commit 64c60dd

Please sign in to comment.