forked from pulp/pulp_file
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pulp#225 from asmacdo/script-docs
Replace commands with scripts
- Loading branch information
Showing
20 changed files
with
331 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Manually add content to a repository by creating a new version, creating a task | ||
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'versions/' \ | ||
add_content_units:="[\"$CONTENT_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 | ||
|
||
# After the task is complete, it gives us a new repository version | ||
export REPOVERSION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first') | ||
|
||
# Lets inspect our newly created RepositoryVersion | ||
http $BASE_ADDR$REPOVERSION_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Create a dummy file to upload | ||
echo "Very important content." > test_upload.txt | ||
|
||
# Upload the file to Pulp, creating an artifact | ||
export ARTIFACT_HREF=$(http --form POST $BASE_ADDR/pulp/api/v3/artifacts/ file@./test_upload.txt \ | ||
| jq -r '._href') | ||
|
||
# Lets inspect our newly created artifact | ||
http $BASE_ADDR$ARTIFACT_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Set environment variables for default hostname and ports for the API and the Content app | ||
export BASE_ADDR=http://localhost:24817 | ||
export CONTENT_ADDR=http://localhost:24816 | ||
|
||
# Necessary for `django-admin` | ||
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings | ||
|
||
# Poll a Pulp task until it is finished. | ||
wait_until_task_finished() { | ||
local task_url=$1 | ||
while true | ||
do | ||
local response=$(http $task_url) | ||
local state=$(jq -r .state <<< ${response}) | ||
jq . <<< "${response}" | ||
case ${state} in | ||
failed|completed|canceled) | ||
break | ||
;; | ||
*) | ||
sleep 1 | ||
;; | ||
esac | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Stop all pulp services | ||
sudo systemctl stop pulp-content-app pulp-worker@1 pulp-worker@2 pulp-resource-manager pulp-api | ||
|
||
# Reset the database (destructive!) | ||
django-admin reset_db --noinput | ||
django-admin migrate | ||
django-admin reset-admin-password --password password | ||
|
||
# Restart all pulp services | ||
sudo systemctl restart pulp-content-app pulp-worker@1 pulp-worker@2 pulp-resource-manager pulp-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Create File Content from the artifact | ||
http POST $BASE_ADDR/pulp/api/v3/content/file/files/ \ | ||
relative_path=test_upload.txt \ | ||
_artifact=$ARTIFACT_HREF | ||
|
||
export CONTENT_HREF=$(http :24817/pulp/api/v3/content/file/files/ | \ | ||
jq -r '.results[] | select(.relative_path == "test_upload.txt") | ._href') | ||
|
||
# Lets inspect our newly created file content | ||
http $BASE_ADDR$CONTENT_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This script will execute the component scripts and ensure that the documented examples | ||
# work as expected. | ||
|
||
# From the _scripts directory, run with `source destructive_scripts_check.sh` (source to preserve | ||
# the environment variables) | ||
source clean.sh | ||
source base.sh | ||
|
||
source repo.sh | ||
source remote.sh | ||
source sync.sh | ||
|
||
source publication.sh | ||
source distribution.sh | ||
source download_after_sync.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This script will execute the component scripts and ensure that the documented examples | ||
# work as expected. | ||
|
||
# From the _scripts directory, run with `source destructive_scripts_check.sh` (source to preserve | ||
# the environment variables) | ||
source clean.sh | ||
source base.sh | ||
|
||
source repo.sh | ||
source artifact.sh | ||
source content.sh | ||
source add_remove.sh | ||
|
||
source publication.sh | ||
source distribution.sh | ||
source download_after_upload.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Distributions are created asynchronously. Create one, and specify the publication that will | ||
# be served at the base path specified. | ||
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/distributions/file/file/ \ | ||
name='baz' \ | ||
base_path='foo' \ | ||
publication=$PUBLICATION_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 | ||
|
||
# After the task is complete, it gives us a new file distribution | ||
export DISTRIBUTION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first') | ||
|
||
# Lets inspect the Distribution | ||
http $BASE_ADDR$DISTRIBUTION_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The distribution will return a url that can be used by http clients | ||
export DISTRIBUTION_BASE_URL=$(http $BASE_ADDR$DISTRIBUTION_HREF | jq -r '.base_url') | ||
|
||
# Next we download a file from the distribution | ||
http -d http://$DISTRIBUTION_BASE_URL/test.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The distribution will return a url that can be used by http clients | ||
export DISTRIBUTION_BASE_URL=$(http $BASE_ADDR$DISTRIBUTION_HREF | jq -r '.base_url') | ||
|
||
# Next we download a file from the distribution | ||
http -d http://$DISTRIBUTION_BASE_URL/test_upload.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Create a new publication specifying the repository_version. | ||
# Alternatively, you can specify the repository, and Pulp will assume the latest version. | ||
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/publications/file/file/ \ | ||
repository_version=$REPOVERSION_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 | ||
|
||
# After the task is complete, it gives us a new file publication | ||
export PUBLICATION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first') | ||
|
||
# Lets inspect our newly created Publication. | ||
http $BASE_ADDR$PUBLICATION_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Create a remote that points to an external source of files | ||
http POST http://localhost:24817/pulp/api/v3/remotes/file/file/ \ | ||
name='bar' \ | ||
url='https://repos.fedorapeople.org/pulp/pulp/demo_repos/test_file_repo/PULP_MANIFEST' | ||
|
||
# Export an environment variable for the new remote URI. | ||
export REMOTE_HREF=$(http $BASE_ADDR/pulp/api/v3/remotes/file/file/ | jq -r '.results[] | select(.name == "bar") | ._href') | ||
|
||
# Lets inspect our newly created RepositoryVersion. | ||
http $BASE_ADDR$REMOTE_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Start by creating a new repository named "foo": | ||
http POST $BASE_ADDR/pulp/api/v3/repositories/ name=foo | ||
|
||
# If you want to copy/paste your way through the guide, | ||
# create an environment variable for the repository URI. | ||
export REPO_HREF=$(http $BASE_ADDR/pulp/api/v3/repositories/ | \ | ||
jq -r '.results[] | select(.name == "foo") | ._href') | ||
|
||
# Lets inspect our newly created repository. | ||
http $BASE_ADDR$REPO_HREF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Using the Remote we just created, we kick off a sync task | ||
export TASK_URL=$(http POST $BASE_ADDR$REMOTE_HREF'sync/' repository=$REPO_HREF mirror=False \ | ||
| 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 | ||
export REPOVERSION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first') | ||
|
||
# Lets inspect our newly created RepositoryVersion | ||
http $BASE_ADDR$REPOVERSION_HREF |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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_file/tree/master/docs/_scripts/ | ||
|
||
The following scripts are used in conjunction with all the workflow scripts: | ||
|
||
**Base** | ||
|
||
.. literalinclude:: ../_scripts/base.sh | ||
:language: bash | ||
|
||
**Cleanup (Destructive)** | ||
|
||
.. literalinclude:: ../_scripts/clean.sh | ||
:language: bash | ||
|
||
Correctness Check (Destructive) | ||
------------------------------- | ||
|
||
To check the correctness of the sync and publish workflow scripts, they can all be run together using: | ||
|
||
.. literalinclude:: ../_scripts/destructive_check_sync_publish.sh | ||
:language: bash | ||
|
||
To check the correctness of the upload and publish workflow scripts, they can all be run together using: | ||
script. | ||
|
||
.. literalinclude:: ../_scripts/destructive_check_upload_publish.sh | ||
:language: bash |
Oops, something went wrong.