Skip to content

Commit 225fc7e

Browse files
committed
initial commit
0 parents  commit 225fc7e

11 files changed

+361
-0
lines changed

.gitignore

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
venv/
48+
.python-version
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
57+
# Sphinx documentation
58+
docs/_build/
59+
60+
# PyBuilder
61+
target/
62+
63+
#Ipython Notebook
64+
.ipynb_checkpoints

.swagger-codegen-ignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# Swagger Codegen Ignore
3+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
4+
5+
# Use this file to prevent files from being overwritten by the generator.
6+
# The patterns follow closely to .gitignore or .dockerignore.
7+
8+
# As an example, the C# client generator defines ApiClient.cs.
9+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
10+
#ApiClient.cs
11+
12+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
13+
#foo/*/qux
14+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
15+
16+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
17+
#foo/**/qux
18+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
19+
20+
# You can also negate patterns with an exclamation (!).
21+
# For example, you can ignore all files in a docs folder with the file extension .md:
22+
#docs/*.md
23+
# Then explicitly reverse the ignore rule for a single file:
24+
#!docs/README.md

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
sudo: required
3+
# https://docs.travis-ci.com/user/trusty-ci-environment/
4+
dist: xenial
5+
language: python
6+
python:
7+
- "3.6"
8+
env:
9+
- DB=postgres
10+
addons:
11+
# postgres versions provided by el7 RHSCL (lowest supportable version)
12+
postgresql: "9.6"
13+
services:
14+
- postgresql
15+
- redis-server
16+
install: source .travis/install.sh
17+
before_script: source .travis/before_script.sh
18+
script: source .travis/script.sh
19+
after_failure:
20+
- sh -c "cat ~/django_runserver.log"
21+
- sh -c "cat ~/resource_manager.log"
22+
- sh -c "cat ~/reserved_workers-1.log"

.travis/before_script.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env sh
2+
set -v
3+
4+
psql -U postgres -c 'CREATE USER pulp WITH SUPERUSER LOGIN;'
5+
psql -U postgres -c 'CREATE DATABASE pulp OWNER pulp;'
6+
7+
mkdir -p ~/.config/pulp_smash
8+
cp ../pulpcore/.travis/pulp-smash-config.json ~/.config/pulp_smash/settings.json
9+
10+
sudo mkdir -p /var/lib/pulp/tmp
11+
sudo mkdir /etc/pulp/
12+
sudo chown -R travis:travis /var/lib/pulp
13+
14+
echo "SECRET_KEY: \"$(cat /dev/urandom | tr -dc 'a-z0-9!@#$%^&*(\-_=+)' | head -c 50)\"" | sudo tee -a /etc/pulp/settings.py

.travis/check_commit.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# skip this check for everything but PRs
4+
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
5+
exit 0
6+
fi
7+
8+
if [ "$TRAVIS_COMMIT_RANGE" != "" ]; then
9+
RANGE=$TRAVIS_COMMIT_RANGE
10+
elif [ "$TRAVIS_COMMIT" != "" ]; then
11+
RANGE=$TRAVIS_COMMIT
12+
fi
13+
14+
# Travis sends the ranges with 3 dots. Git only wants one.
15+
if [[ "$RANGE" == *...* ]]; then
16+
RANGE=`echo $TRAVIS_COMMIT_RANGE | sed 's/\.\.\./../'`
17+
else
18+
RANGE="$RANGE~..$RANGE"
19+
fi
20+
21+
for sha in `git log --format=oneline --no-merges "$RANGE" | cut '-d ' -f1`
22+
do
23+
python .travis/validate_commit_message.py $sha
24+
VALUE=$?
25+
26+
if [ "$VALUE" -gt 0 ]; then
27+
exit $VALUE
28+
fi
29+
done

.travis/install.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env sh
2+
set -v
3+
4+
export COMMIT_MSG=$(git show HEAD^2 -s)
5+
export PULP_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore\/pull\/(\d+)' | awk -F'/' '{print $7}')
6+
export PULP_PLUGIN_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore-plugin\/pull\/(\d+)' | awk -F'/' '{print $7}')
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}')
8+
export PULP_FILE_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp_file\/pull\/(\d+)' | awk -F'/' '{print $7}')
9+
10+
pip install -r test-requirements.txt
11+
12+
cd .. && git clone https://github.com/pulp/pulpcore.git
13+
14+
if [ -n "$PULP_PR_NUMBER" ]; then
15+
pushd pulpcore
16+
git fetch origin +refs/pull/$PULP_PR_NUMBER/merge
17+
git checkout FETCH_HEAD
18+
popd
19+
fi
20+
21+
pip install -e ./pulpcore[postgres]
22+
23+
git clone https://github.com/pulp/pulpcore-plugin.git
24+
25+
if [ -n "$PULP_PLUGIN_PR_NUMBER" ]; then
26+
pushd pulpcore-plugin
27+
git fetch origin +refs/pull/$PULP_PLUGIN_PR_NUMBER/merge
28+
git checkout FETCH_HEAD
29+
popd
30+
fi
31+
32+
pip install -e ./pulpcore-plugin
33+
34+
35+
if [ -z "$PULP_FILE_PR_NUMBER" ]; then
36+
pip install git+https://github.com/pulp/pulp_file.git#egg=pulp_file
37+
else
38+
cd ../
39+
git clone https://github.com/pulp/pulp_file.git
40+
cd pulp_file
41+
git fetch origin +refs/pull/$PULP_FILE_PR_NUMBER/merge
42+
git checkout FETCH_HEAD
43+
pip install -e .
44+
cd ../pulpcore
45+
fi
46+
47+
if [ -n "$PULP_SMASH_PR_NUMBER" ]; then
48+
pip uninstall -y pulp-smash
49+
git clone https://github.com/PulpQE/pulp-smash.git
50+
pushd pulp-smash
51+
git fetch origin +refs/pull/$PULP_SMASH_PR_NUMBER/merge
52+
git checkout FETCH_HEAD
53+
popd
54+
pip install -e ./pulp-smash
55+
fi
56+
57+
cd pulp-swagger-codegen

.travis/script.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# coding=utf-8
3+
set -veuo pipefail
4+
5+
# check the commit message
6+
# ./.travis/check_commit.sh
7+
8+
# Lint code.
9+
# flake8 --config flake8.cfg || exit 1
10+
11+
# Run migrations.
12+
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings
13+
export PULP_CONTENT_HOST=localhost:24816
14+
export PULP3_HOST=localhost:24817
15+
pulp-manager makemigrations file --noinput
16+
pulp-manager migrate --noinput
17+
18+
# Run unit tests.
19+
# (cd ../pulpcore && coverage run manage.py test pulp_certguard.tests.unit)
20+
21+
# Run functional tests.
22+
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings
23+
pulp-manager reset-admin-password --password admin
24+
pulp-manager runserver 24817 >> ~/django_runserver.log 2>&1 &
25+
gunicorn pulpcore.content:server --bind 'localhost:24816' --worker-class 'aiohttp.GunicornWebWorker' -w 2 >> ~/content_app.log 2>&1 &
26+
rq worker -n 'resource-manager@%h' -w 'pulpcore.tasking.worker.PulpWorker' >> ~/resource_manager.log 2>&1 &
27+
rq worker -n 'reserved-resource-worker_1@%h' -w 'pulpcore.tasking.worker.PulpWorker' >> ~/reserved_worker-1.log 2>&1 &
28+
sleep 8
29+
30+
show_logs_and_return_non_zero() {
31+
readonly local rc="$?"
32+
cat ~/django_runserver.log
33+
cat ~/content_app.log
34+
cat ~/resource_manager.log
35+
cat ~/reserved_worker-1.log
36+
return "${rc}"
37+
}
38+
39+
sudo ./generate.sh python 3.0.0rc1
40+
41+
# Travis' scripts use unbound variables. This is problematic, because the
42+
# changes made to this script's environment appear to persist when Travis'
43+
# scripts execute. Perhaps this script is sourced by Travis? Regardless of why,
44+
# we need to reset the environment when this script finishes.
45+
#
46+
# We can't use `trap cleanup_function EXIT` or similar, because this script is
47+
# apparently sourced, and such a trap won't execute until the (buggy!) calling
48+
# script finishes.
49+
set +euo pipefail

.travis/validate_commit_message.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import re
2+
import requests
3+
import subprocess
4+
import sys
5+
6+
KEYWORDS = ['fixes', 'closes', 're', 'ref']
7+
NO_ISSUE = '[noissue]'
8+
STATUSES = ['NEW', 'ASSIGNED', 'POST']
9+
10+
sha = sys.argv[1]
11+
message = subprocess.check_output(['git', 'log', '--format=%B', '-n 1', sha]).decode('utf-8')
12+
13+
14+
def __check_status(issue):
15+
response = requests.get('https://pulp.plan.io/issues/{}.json'.format(issue))
16+
response.raise_for_status()
17+
bug_json = response.json()
18+
status = bug_json['issue']['status']['name']
19+
if status not in STATUSES:
20+
sys.exit("Error: issue #{issue} has invalid status of {status}. Status must be one of "
21+
"{statuses}.".format(issue=issue, status=status, statuses=", ".join(STATUSES)))
22+
23+
24+
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
25+
26+
# validate the issue attached to the commit
27+
if NO_ISSUE in message:
28+
print("Commit {sha} has no issue attached. Skipping issue check".format(sha=sha[0:7]))
29+
else:
30+
regex = r'(?:{keywords})[\s:]+#(\d+)'.format(keywords=('|').join(KEYWORDS))
31+
pattern = re.compile(regex)
32+
33+
issues = pattern.findall(message)
34+
35+
if issues:
36+
for issue in pattern.findall(message):
37+
__check_status(issue)
38+
else:
39+
sys.exit("Error: no attached issues found for {sha}. If this was intentional, add "
40+
" '{tag}' to the commit message.".format(sha=sha[0:7], tag=NO_ISSUE))
41+
42+
print("Commit message for {sha} passed.".format(sha=sha[0:7]))

README.rst

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pulp-swagger-codegen
2+
====================
3+
4+
This repository provides a script that helps generate Python bindings for pulpcore or any of it's
5+
plugins. This script can only generate Python bindings at this time.
6+
7+
The first time the script is run, a docker container with swagger-codegen-cli is downloaded. All
8+
subsequent runs will re-use the container that was downloaded on the initial run.
9+
10+
Requirements
11+
------------
12+
Pulp 3 running on localhost:24817
13+
Docker
14+
15+
Generating bindings
16+
-------------------
17+
18+
The ``generate.sh`` script takes two positional arguments: module name, version. The following
19+
commands should be used to generate bindings for ``pulpcore``:
20+
21+
.. code-block:: bash
22+
23+
sudo ./generate.sh pulpcore
24+
25+
Bindings for the Python plugin can be generated with the following command:
26+
27+
.. code-block:: bash
28+
29+
sudo ./generate.sh pulp_python
30+

generate.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/bash
2+
# Before executing do `export PULP3_HOST=host`
3+
4+
if [ $# -eq 0 ]; then
5+
echo "No arguments provided"
6+
exit 1
7+
fi
8+
9+
curl -o api.json http://localhost:24817/pulp/api/v3/docs/api.json?plugin=$1
10+
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
11+
-i /local/api.json \
12+
-l python \
13+
-o /local/$1-client \
14+
-DpackageName=pulpcore.client.$1 \
15+
-DprojectName=$1-client \
16+
-DpackageVersion=$2
17+
cp python/__init__.py $1-client/pulpcore/
18+
cp python/__init__.py $1-client/pulpcore/client
19+
20+
# There is a bug in swagger-codegen. When using package names within a namespace it creates the package
21+
# accross 2 different directories. We move everything back into place here.
22+
cp $1-client/pulpcore.client.$1/* $1-client/pulpcore/client/$1/
23+
cp $1-client/pulpcore.client.$1/api/* $1-client/pulpcore/client/$1/api/
24+
cp $1-client/pulpcore.client.$1/models/* $1-client/pulpcore/client/$1/models/
25+
# Then remove the wrong directory
26+
rm -rf $1-client/pulpcore.client.$1
27+
28+
rm api.json

python/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from pkgutil import extend_path
2+
__path__ = extend_path(__path__, __name__)

0 commit comments

Comments
 (0)