Skip to content

Commit

Permalink
Use environment variable to set db username when running unittest
Browse files Browse the repository at this point in the history
This updates the Travis config to the latest version of plugin_template.

re: #5425
https://pulp.plan.io/issues/5425
  • Loading branch information
dkliban committed Oct 8, 2019
1 parent 4b2cdd9 commit 662299f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 59 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ notifications:
- 'Change view : %{compare_url}'
- 'Build details : %{build_url}'
- '%{message}'

...
42 changes: 26 additions & 16 deletions .travis/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ -f $PRE_BEFORE_INSTALL ]; then
$PRE_BEFORE_INSTALL
fi

if [[ -n $(echo -e $COMMIT_MSG | grep -P "Required PR:.*" | grep -v "https") ]]; then
echo "Invalid Required PR link detected in commit message. Please use the full https url."
exit 1
fi

export PULP_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore\/pull\/(\d+)' | awk -F'/' '{print $7}')
export PULP_PLUGIN_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore-plugin\/pull\/(\d+)' | awk -F'/' '{print $7}')
export PULP_SMASH_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/PulpQE\/pulp-smash\/pull\/(\d+)' | awk -F'/' '{print $7}')
Expand Down Expand Up @@ -59,27 +64,32 @@ fi



git clone --depth=1 https://github.com/pulp/pulpcore-plugin.git
# When building a (release) tag, we don't need the development modules for the
# build (they will be installed as dependencies of the plugin).
if [ -z "$TRAVIS_TAG" ]; then

if [ -n "$PULP_PLUGIN_PR_NUMBER" ]; then
cd pulpcore-plugin
git fetch --depth=1 origin +refs/pull/$PULP_PLUGIN_PR_NUMBER/merge
git checkout FETCH_HEAD
cd ..
fi
git clone --depth=1 https://github.com/pulp/pulpcore-plugin.git

if [ -n "$PULP_PLUGIN_PR_NUMBER" ]; then
cd pulpcore-plugin
git fetch --depth=1 origin +refs/pull/$PULP_PLUGIN_PR_NUMBER/merge
git checkout FETCH_HEAD
cd ..
fi

git clone --depth=1 https://github.com/PulpQE/pulp-smash.git

if [ -n "$PULP_SMASH_PR_NUMBER" ]; then
cd pulp-smash
git fetch --depth=1 origin +refs/pull/$PULP_SMASH_PR_NUMBER/merge
git checkout FETCH_HEAD
cd ..
fi
git clone --depth=1 https://github.com/PulpQE/pulp-smash.git

# pulp-smash already got installed via test_requirements.txt
pip install --upgrade --force-reinstall ./pulp-smash
if [ -n "$PULP_SMASH_PR_NUMBER" ]; then
cd pulp-smash
git fetch --depth=1 origin +refs/pull/$PULP_SMASH_PR_NUMBER/merge
git checkout FETCH_HEAD
cd ..
fi

# pulp-smash already got installed via test_requirements.txt
pip install --upgrade --force-reinstall ./pulp-smash
fi

pip install ansible

Expand Down
24 changes: 19 additions & 5 deletions .travis/before_script.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

# WARNING: DO NOT EDIT!
#
Expand All @@ -12,20 +12,34 @@ set -euv
export PRE_BEFORE_SCRIPT=$TRAVIS_BUILD_DIR/.travis/pre_before_script.sh
export POST_BEFORE_SCRIPT=$TRAVIS_BUILD_DIR/.travis/post_before_script.sh

if [ -f $PRE_BEFORE_SCRIPT ]; then
# Aliases for running commands in the pulp-api container.
export PULP_API_POD=$(sudo kubectl get pods | grep -E -o "pulp-api-(\w+)-(\w+)")
# Run a command
export CMD_PREFIX="sudo kubectl exec $PULP_API_POD --"
# Run a command, and pass STDIN
export CMD_STDIN_PREFIX="sudo kubectl exec -i $PULP_API_POD --"

if [[ -f $PRE_BEFORE_SCRIPT ]]; then
$PRE_BEFORE_SCRIPT
fi


mkdir -p ~/.config/pulp_smash

if [ -f .travis/pulp-smash-config.json ]; then
if [[ -f .travis/pulp-smash-config.json ]]; then
sed "s/localhost/$(hostname)/g" .travis/pulp-smash-config.json > ~/.config/pulp_smash/settings.json
else
sed "s/localhost/$(hostname)/g" ../pulpcore/.travis/pulp-smash-config.json > ~/.config/pulp_smash/settings.json
fi

if [[ "$TEST" == 'pulp' || "$TEST" == 'performance' ]]; then
# Many tests require pytest/mock, but users do not need them at runtime
# (or to add plugins on top of pulpcore or pulp container images.)
# So install it here, rather than in the image Dockerfile.
$CMD_PREFIX pip3 install pytest mock
# Many functional tests require these
$CMD_PREFIX dnf install -yq lsof which dnf-plugins-core
fi

if [ -f $POST_BEFORE_SCRIPT ]; then
if [[ -f $POST_BEFORE_SCRIPT ]]; then
$POST_BEFORE_SCRIPT
fi
32 changes: 26 additions & 6 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ cd $TRAVIS_BUILD_DIR/../pulpcore/containers/
# starting point:
# https://stackoverflow.com/a/50687120
#
# If we are on a tag
if [ -n "$TRAVIS_TAG" ]; then
TAG=$(echo $TRAVIS_TAG | tr / _)
# If we are on a PR
if [ -n "$TRAVIS_PULL_REQUEST_BRANCH" ]; then
elif [ -n "$TRAVIS_PULL_REQUEST_BRANCH" ]; then
TAG=$(echo $TRAVIS_PULL_REQUEST_BRANCH | tr / _)
# For push builds, tag builds, and hopefully cron builds
# For push builds and hopefully cron builds
elif [ -n "$TRAVIS_BRANCH" ]; then
TAG=$(echo $TRAVIS_BRANCH | tr / _)
if [ "$TAG" = "master" ]; then
Expand All @@ -48,15 +51,30 @@ fi
PLUGIN=pulp_file


# For pulpcore, and any other repo that might check out a pulp-certguard PR
# For pulpcore, and any other repo that might check out some plugin PR

if [ -e $TRAVIS_BUILD_DIR/../pulp-certguard ]; then
PULP_CERTGUARD=./pulp-certguard
else
# Otherwise, master branch release
PULP_CERTGUARD=git+https://github.com/pulp/pulp-certguard.git
fi

cat > vars/vars.yaml << VARSYAML

if [ -n "$TRAVIS_TAG" ]; then
# Install the plugin only and use published PyPI packages for the rest
cat > vars/vars.yaml << VARSYAML
---
images:
- ${PLUGIN}-${TAG}:
image_name: $PLUGIN
tag: $TAG
plugins:
- ./$PLUGIN
- pulp-certguard
VARSYAML
else
cat > vars/vars.yaml << VARSYAML
---
images:
- ${PLUGIN}-${TAG}:
Expand All @@ -65,9 +83,11 @@ images:
pulpcore: ./pulpcore
pulpcore_plugin: ./pulpcore-plugin
plugins:
- $PULP_CERTGUARD
- ./$PLUGIN
- $PULP_CERTGUARD
VARSYAML
fi

ansible-playbook build.yaml

Expand Down
23 changes: 13 additions & 10 deletions .travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,17 @@ if [ "$TEST" = 'bindings' ]; then
exit
fi


PULP_API_POD=$(sudo kubectl get pods | grep -E -o "pulp-api-(\w+)-(\w+)")
# Aliases for running commands in the pulp-api container.
export PULP_API_POD=$(sudo kubectl get pods | grep -E -o "pulp-api-(\w+)-(\w+)")
# Run a command
export CMD_PREFIX="sudo kubectl exec $PULP_API_POD --"
# Many tests require pytest/mock, but users do not need them at runtime
# (or to add plugins on top of pulpcore or pulp container images.)
# So install it here, rather than in the image Dockerfile.
$CMD_PREFIX pip3 install pytest mock
# Many functional tests require these
$CMD_PREFIX dnf install -yq lsof which dnf-plugins-core
# Run a command, and pass STDIN
export CMD_STDIN_PREFIX="sudo kubectl exec -i $PULP_API_POD --"
# The alias does not seem to work in Travis / the scripting framework
#alias pytest="$CMD_PREFIX pytest"

# Run unit tests.
$CMD_PREFIX bash -c "sed \"s/'USER': 'pulp'/'USER': 'postgres'/g\" /etc/pulp/settings.py > unit-test.py"
$CMD_PREFIX bash -c "PULP_SETTINGS=/unit-test.py django-admin test --noinput /usr/local/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/pulpcore/tests/unit/"
$CMD_PREFIX bash -c "PULP_DATABASES__default__USER=postgres django-admin test --noinput /usr/local/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/pulpcore/tests/unit/"

# Note: This function is in the process of being merged into after_failure
show_logs_and_return_non_zero() {
Expand All @@ -103,6 +99,13 @@ set +u
export PYTHONPATH=$TRAVIS_BUILD_DIR:${PYTHONPATH}

set -u

if [[ "$TEST" == "performance" ]]; then
echo "--- Performance Tests ---"
pytest -vv -r sx --color=yes --pyargs --durations=0 pulpcore.tests.performance || show_logs_and_return_non_zero
exit
fi

if [ -f $FUNC_TEST_SCRIPT ]; then
$FUNC_TEST_SCRIPT
else
Expand Down
49 changes: 27 additions & 22 deletions template_config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
# This config represents the latest values used when running the plugin-template. Any settings that
# were not present before running plugin-template have been added with their default values.

plugin_name: pulpcore
additional_plugins: ['pulp-certguard']
black: false
check_commit_message: true
coverage: true
deploy_client_to_pypi: true
deploy_client_to_rubygems: true
deploy_daily_client_to_pypi: true
deploy_daily_client_to_rubygems: true
deploy_to_pypi: true
docs_test: true
plugin_app_label: pulpcore
plugin_snake: pulpcore
plugin_caps: PULPCORE
plugin_caps_short: PULPCORE
plugin_camel: Pulpcore
plugin_camel_short: Pulpcore
plugin_caps: PULPCORE
plugin_caps_short: PULPCORE
plugin_dash: pulpcore
plugin_dash_short: pulpcore
black: False
check_commit_message: True
coverage: True
deploy_client_to_pypi: True
deploy_client_to_rubygems: True
deploy_daily_client_to_pypi: True
deploy_daily_client_to_rubygems: True
deploy_to_pypi: True
docs_test: True
pydocstyle: True
test_bindings: True
plugin_name: pulpcore
plugin_snake: pulpcore
pulp_settings:
content_host: $(hostname):24816
pydocstyle: true
pypi_username: pulp
test_bindings: true
test_performance: false
travis_notifications:
irc:
channels:
- "chat.freenode.net#pulp-build"
template:
- "%{repository_slug}#%{build_number} (%{branch} - %{commit} : %{author} : %{commit_subject})"
- "Change view : %{compare_url}"
- "Build details : %{build_url}"
- "%{message}"
on_success: change
- chat.freenode.net#pulp-build
on_failure: always
on_success: change
template:
- '%{repository_slug}#%{build_number} (%{branch} - %{commit} : %{author} : %{commit_subject})'
- 'Change view : %{compare_url}'
- 'Build details : %{build_url}'
- '%{message}'

0 comments on commit 662299f

Please sign in to comment.