Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path


import os
from github import Github


Expand All @@ -22,7 +23,7 @@

sha = sys.argv[1]
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
g = Github()
g = Github(os.environ.get("GITHUB_TOKEN"))
repo = g.get_repo("pulp/pulp_python")


Expand Down
2 changes: 1 addition & 1 deletion .github/template_gitref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.04.08-95-gbf7866c
2021.04.08-97-g74b81ba
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- name: Check commit message
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ github.event.pull_request.commits_url }}
run: sh .github/workflows/scripts/check_commit.sh

Expand Down Expand Up @@ -133,5 +134,79 @@ jobs:
docker exec pulp cat /etc/yum.repos.d/* || true
docker exec pulp pip3 list

upgrade:
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
include:
- FROM_PULPCORE_BRANCH: "3.11"
FROM_PULP_PYTHON_BRANCH: "3.2"

steps:
- uses: actions/checkout@v2
with:
# by default, it uses a depth of 1
# this fetches all history so that we can read each commit
fetch-depth: 0

- uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install httpie
run: |
echo ::group::HTTPIE
sudo apt-get update -yq
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install httpie
echo ::endgroup::
echo "TEST=upgrade" >> $GITHUB_ENV
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/.ci/assets/httpie/" >> $GITHUB_ENV
echo "FROM_PULP_PYTHON_BRANCH=${{ matrix.FROM_PULP_PYTHON_BRANCH }}" >> $GITHUB_ENV
echo "FROM_PULPCORE_BRANCH=${{ matrix.FROM_PULPCORE_BRANCH }}" >> $GITHUB_ENV

- name: Install python dependencies
run: |
echo ::group::PYDEPS
pip install wheel
echo ::endgroup::

- name: Before Install
run: .github/workflows/scripts/before_install.sh
shell: bash

- name: Install
run: .github/workflows/scripts/install.sh
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
shell: bash

- name: Install Python client
run: .github/workflows/scripts/install_python_client.sh

- name: Before Script
run: .github/workflows/scripts/before_script.sh

- name: Setting secrets
run: python3 .github/workflows/scripts/secrets.py "$SECRETS_CONTEXT"
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}

- name: Upgrade test
run: .github/workflows/scripts/script.sh

- name: After failure
if: failure()
run: |
http --timeout 30 --check-status --pretty format --print hb https://pulp/pulp/api/v3/status/ || true
docker images || true
docker ps -a || true
docker logs pulp || true
docker exec pulp ls -latr /etc/yum.repos.d/ || true
docker exec pulp cat /etc/yum.repos.d/* || true
docker exec pulp pip3 list



24 changes: 24 additions & 0 deletions .github/workflows/scripts/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COMMIT_MSG=$(git log --format=%B --no-merges -1)
export COMMIT_MSG

if [[ "$TEST" == "upgrade" ]]; then
pip install -r functest_requirements.txt
git checkout -b ci_upgrade_test
cp -R .github /tmp/.github
cp -R .ci /tmp/.ci
Expand Down Expand Up @@ -103,6 +104,21 @@ if [ -n "$PULP_OPENAPI_GENERATOR_PR_NUMBER" ]; then
fi


git clone --depth=1 https://github.com/pulp/pulp-cli.git
if [ -n "$PULP_CLI_PR_NUMBER" ]; then
cd pulp-cli
git fetch origin pull/$PULP_CLI_PR_NUMBER/head:$PULP_CLI_PR_NUMBER
git checkout $PULP_CLI_PR_NUMBER
cd ..
fi

cd pulp-cli
pip install -e .
pulp config create --base-url https://pulp --location tests/cli.toml
mkdir ~/.config/pulp
cp tests/cli.toml ~/.config/pulp/cli.toml
cd ..


git clone --depth=1 https://github.com/pulp/pulpcore.git --branch master

Expand All @@ -115,6 +131,14 @@ cd ..



if [[ "$TEST" == "upgrade" ]]; then
cd pulpcore
git checkout -b ci_upgrade_test
git fetch --depth=1 origin heads/$FROM_PULPCORE_BRANCH:$FROM_PULPCORE_BRANCH
git checkout $FROM_PULPCORE_BRANCH
cd ..
fi


# Intall requirements for ansible playbooks
pip install docker netaddr boto3 ansible
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/check_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip3 install pygithub

echo ::endgroup::

for sha in $(curl $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g')
for sha in $(curl -H "Authorization: token $GITHUB_TOKEN" $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g')
do
python3 .ci/scripts/validate_commit_message.py $sha
VALUE=$?
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,56 @@ cmd_prefix bash -c "PULP_DATABASES__default__USER=postgres django-admin test --n
export PYTHONPATH=$REPO_ROOT:$REPO_ROOT/../pulpcore${PYTHONPATH:+:${PYTHONPATH}}


if [[ "$TEST" == "upgrade" ]]; then
# Handle app label change:
sed -i "/require_pulp_plugins(/d" pulp_python/tests/functional/utils.py

# Running pre upgrade tests:
pytest -v -r sx --color=yes --pyargs -capture=no pulp_python.tests.upgrade.pre

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gerrod3 here is where the upgrade tests will start to run


# Checking out ci_upgrade_test branch and upgrading plugins
cmd_prefix bash -c "cd pulpcore; git checkout -f ci_upgrade_test; pip install --upgrade --force-reinstall ."
cmd_prefix bash -c "cd pulp_python; git checkout -f ci_upgrade_test; pip install ."

# Migrating
cmd_prefix bash -c "django-admin migrate --no-input"

# Restarting single container services
cmd_prefix bash -c "s6-svc -r /var/run/s6/services/pulpcore-api"
cmd_prefix bash -c "s6-svc -r /var/run/s6/services/pulpcore-content"
cmd_prefix bash -c "s6-svc -d /var/run/s6/services/pulpcore-resource-manager"
cmd_prefix bash -c "s6-svc -d /var/run/s6/services/pulpcore-worker@1"
cmd_prefix bash -c "s6-svc -d /var/run/s6/services/pulpcore-worker@2"
cmd_prefix bash -c "s6-svc -u /var/run/s6/services/new-pulpcore-resource-manager"
cmd_prefix bash -c "s6-svc -u /var/run/s6/services/new-pulpcore-worker@1"
cmd_prefix bash -c "s6-svc -u /var/run/s6/services/new-pulpcore-worker@2"

echo "Restarting in 60 seconds"
sleep 60

# CLI commands to display plugin versions and content data
pulp status
pulp content list
CONTENT_LENGTH=$(pulp content list | jq length)
if [[ "$CONTENT_LENGTH" == "0" ]]; then
echo "Empty content list"
exit 1
fi

# Rebuilding bindings
cd ../pulp-openapi-generator
./generate.sh pulpcore python
pip install ./pulpcore-client
./generate.sh pulp_python python
pip install ./pulp_python-client
cd $REPO_ROOT

# Running post upgrade tests
git checkout ci_upgrade_test -- pulp_python/tests/
pytest -v -r sx --color=yes --pyargs -capture=no pulp_python.tests.upgrade.post
exit
fi


if [[ "$TEST" == "performance" ]]; then
if [[ -z ${PERFORMANCE_TEST+x} ]]; then
Expand Down
1 change: 1 addition & 0 deletions CHANGES/408.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding upgrade tests
9 changes: 6 additions & 3 deletions docs/_scripts/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ if [ -z "$(pip freeze | grep pulp-cli)" ]; then
fi

# Set up CLI config file
mkdir ~/.config/pulp
cat > ~/.config/pulp/settings.toml << EOF
if [ ! -f ~/.config/pulp/settings.toml ]; then
echo "Configuring pulp-cli"
mkdir -p ~/.config/pulp
cat > ~/.config/pulp/cli.toml << EOF
[cli]
base_url = "$BASE_ADDR" # common to be localhost
base_url = "$BASE_ADDR"
verify_ssl = false
format = "json"
EOF
fi
23 changes: 20 additions & 3 deletions pulp_python/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ def latest_content_version(content_query, version):
return latest_content


def json_to_dict(data):
"""
Converts a JSON string into a Python dictionary.
Comment on lines +153 to +155

@gerrod3 gerrod3 Aug 24, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. Why is it needed? I see its use later on in another method, just safer this way?

@fao89 fao89 Aug 24, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the post-test was breaking because the data was already a dict:

127.0.0.1 [24/Aug/2021:02:26:55 +0000] "GET /pulp/content/pulp_pre_upgrade_test/pypi/shelf-reader/json HTTP/1.0" 500 231 "-" "bandersnatch/4.4.0 (cpython 3.8.6-final0, Linux x86_64) (aiohttp 3.7.4.post0)"
  File "/usr/local/lib/python3.8/site-packages/pulpcore/content/handler.py", line 212, in stream_content
    return await self._match_and_stream(path, request)
  File "/usr/local/lib/python3.8/site-packages/pulpcore/content/handler.py", line 454, in _match_and_stream
    content_handler_result = distro.content_handler(rel_path)
  File "/usr/local/lib/python3.8/site-packages/pulp_python/app/models.py", line 108, in content_handler
    json_body = python_content_to_json(self.base_path, package_content, version=version)
  File "/usr/local/lib/python3.8/site-packages/pulp_python/app/utils.py", line 127, in python_content_to_json
    full_metadata.update({"info": python_content_to_info(latest_content[0])})
  File "/usr/local/lib/python3.8/site-packages/pulp_python/app/utils.py", line 178, in python_content_to_info
    "project_urls": json.loads(content.project_urls) or None,
  File "/usr/lib64/python3.8/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict

https://github.com/pulp/pulp_python/runs/3406807006?check_suite_focus=true#step:12:645


Args:
data (string): JSON string

Returns:
dictionary: of JSON string

"""
if isinstance(data, dict):
return data

return json.loads(data)


def python_content_to_info(content):
"""
Takes in a PythonPackageContent instance and returns a dictionary of the Info fields
Expand All @@ -175,10 +192,10 @@ def python_content_to_info(content):
"package_url": content.project_url or "", # These two are usually identical
"project_url": content.project_url or "", # They also usually point to PyPI
"release_url": f"{content.project_url}{content.version}/" if content.project_url else "",
"project_urls": json.loads(content.project_urls) or None,
"project_urls": json_to_dict(content.project_urls) or None,
"platform": content.platform or "",
"requires_dist": json.loads(content.requires_dist) or None,
"classifiers": json.loads(content.classifiers) or None,
"requires_dist": json_to_dict(content.requires_dist) or None,
"classifiers": json_to_dict(content.classifiers) or None,
"yanked": False, # These are no longer used on PyPI, but are still present
"yanked_reason": None,
}
Expand Down
Empty file.
Empty file.
Loading