Skip to content

Commit

Permalink
Merge pull request #97 from svanoort/jenkins-installtest
Browse files Browse the repository at this point in the history
Docker enhancements and initial CI testing of installation
  • Loading branch information
svanoort committed Oct 11, 2015
2 parents e42f5de + caed9ee commit e20af67
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -111,7 +111,7 @@ Now, let's get started!
**This is what testing is for.**

## System Requirements:
- Linux or Mac OS X with python 2.6+ installed and pycurl
- Linux or Mac OS X with python 2.6+ or 2.7 installed and pycurl
- Do not use a virtualenv (or have it custom configured to find libcurl)

# Quickstart Part 0: Setting Up a Sample REST Service
Expand Down
12 changes: 9 additions & 3 deletions building.md
Expand Up @@ -6,10 +6,10 @@ There are two options for how to work with code
- Unit + functional tests: run_tests.sh
- Coverage Test: coverage.sh (result in htmlconv/index.html)

# Conventions
## Conventions
- All non-functional unit tests (runnable without a server) start with 'test_'

# Environments
## Environments
1. Local (native) python (Linux or Mac)
- You'll need to pip install the following packages:
+ pycurl
Expand All @@ -31,4 +31,10 @@ There are two options for how to work with code
3. OR just run the images and clone the repo from within them:
1. (sudo) docker run -it --rm pyresttest-build-ubuntu-14 /bin/bash
2. Inside container: cd /tmp && git clone https://github.com/svanoort/pyresttest.git
3. Do your coding and commit/push, etc
3. Do your coding and commit/push, etc

## Releasing
Release tooling requires its own special goodies. The docker images have it all baked in, for convenience's sake.

1. Tar (for packaging distributions)
2. For CentOS 6, rpm-build
6 changes: 3 additions & 3 deletions docker/build.sh
Expand Up @@ -2,9 +2,9 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

UBUNTU_14_VERSION=0.1
CENTOS6_VERSION=0.1
PYTHON3_VERSION=0.2
UBUNTU_14_VERSION=0.2
CENTOS6_VERSION=0.2
PYTHON3_VERSION=0.3

docker build -t pyresttest-build-ubuntu-14:$UBUNTU_14_VERSION-SNAPSHOT ./ubuntu14-py27
docker build -t pyresttest-build-centos6:$CENTOS6_VERSION-SNAPSHOT ./centos6-py26
Expand Down
2 changes: 1 addition & 1 deletion docker/centos6-py26/Dockerfile
Expand Up @@ -5,7 +5,7 @@ MAINTAINER svanoort <samvanoort@gmail.com>
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# pycurl is part of yum, and so is python, so we don't install
RUN yum install -y python-pip git-core python-mock && yum clean all \
RUN yum install -y python-pip git-core python-mock rpm-build tar && yum clean all \
&& pip install discover pyyaml django==1.6.5 django-tastypie

COPY verify_image.py /tmp/verify_image.py
2 changes: 1 addition & 1 deletion docker/python3/Dockerfile
@@ -1,7 +1,7 @@
FROM python:3.4.3-wheezy
MAINTAINER svanoort <samvanoort@gmail.com>

RUN apt-get update && apt-get install --no-install-recommends -y git-core \
RUN apt-get update && apt-get install --no-install-recommends -y git-core tar \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Python 2 and 3 dependencies, future is just for python 3 compat, sigh
Expand Down
2 changes: 1 addition & 1 deletion docker/ubuntu14-py27/Dockerfile
@@ -1,7 +1,7 @@
FROM ubuntu:14.04
MAINTAINER svanoort <samvanoort@gmail.com>

RUN apt-get update && apt-get install --no-install-recommends -y python python-pip python-pycurl git-core \
RUN apt-get update && apt-get install --no-install-recommends -y python python-pip python-pycurl tar git-core \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Python 2 and 3 dependencies
Expand Down
13 changes: 13 additions & 0 deletions github_api_smoketest.yaml
@@ -0,0 +1,13 @@
# Simple tests to verify things work against a live REST service that returns JSON.. Github is a natural one
---
- config:
- testset: "Simple github.com API Test"
- test:
- name: "Basic smoketest of github API"
- headers: {accept: 'application/json'}
- url: "/users/svanoort"
- validators: # operator is applied as: <actual> <operator> <expected>
- compare: {header: "content-type", comparator: contains, expected: 'application/json'}
- compare: {jsonpath_mini: "login", comparator: "eq", expected: "svanoort"}
- compare: {raw_body: "", comparator: "regex", expected: '.*'}
- extract_test: {jsonpath_mini: "does_not_exist", test: "not_exists"}
10 changes: 6 additions & 4 deletions jenkins/jenkins-build-images.groovy
@@ -1,3 +1,5 @@
//Supply parameter "branch" to build

def run_test(dockerImg, python_name, version) {
def id = dockerImg.id
echo "My id is $id"
Expand All @@ -15,19 +17,19 @@ def run_test(dockerImg, python_name, version) {
}

node {
git url:'https://github.com/svanoort/pyresttest.git', branch:'master'
git url:'https://github.com/svanoort/pyresttest.git', branch:"$branch"

stage name:'build', concurrency: 1
def ubuntu14_py27 = docker.build("pyresttest-build-ubuntu-14:test", 'docker/ubuntu14-py27')
def centos6_py26 = docker.build("pyresttest-build-centos6:test", 'docker/centos6-py26')
def python3 = docker.build("pyresttest-build-python3:test", 'docker/python3')

stage name:'test/tag', concurrency: 1
run_test(ubuntu14_py27, 'python', '0.1')
run_test(centos6_py26, 'python', '0.1')
run_test(ubuntu14_py27, 'python', '0.2')
run_test(centos6_py26, 'python', '0.2')

// For some inexplicable reasons, the test script here is more brittle than the others
// Direct docker run works, it hit issues with docker.build, so... okay?
run_test(python3, 'python3', '0.2')
run_test(python3, 'python3', '0.3')
}

128 changes: 128 additions & 0 deletions jenkins/jenkins-installtest.groovy
@@ -0,0 +1,128 @@
def testEnv = docker.image('pyresttest-build-ubuntu-14:latest')
def testEnv26 = docker.image('pyresttest-build-centos6:latest')
def centos = docker.image('centos:centos6')
def ubuntu = docker.image('ubuntu:14.04')
def args = '-u root' //We need this to allow installs inside container

def headlesstests() {
// Tests that only require python/pip and a pyresttest installation, no django server
echo 'Running headless test'

// The dir command causes a hangup *sigh*
//dir('/tmp') {
// sh 'python -c "import pyresttest"'
// Check command will run, but capture error code since help will also return error code
sh "resttest.py 2>/dev/null | grep 'Usage' "
sh "pyresttest 2>/dev/null | grep 'Usage' "
// }
sh "resttest.py https://api.github.com github_api_smoketest.yaml" // Real test
}


// Really finnicky, gets connection refused for reasons I cannot discern sometimes (docker issues?)
def servertests() {
// Tests that require a full test server running to execute
//dir ('/tmp') {
echo 'Skipping server test'
// sh "python pyresttest/testapp/manage.py testserver pyresttest/testapp/test_data.json &"
// sh "pyresttest http://localhost:8000 pyresttest/content-test.yaml"
//}
}

def clean_workspace() {
sh 'rm -rf /tmp/work'
def cur = pwd()
sh "cp -rf $cur /tmp/work"
sh 'cd /tmp/work'
}

node {
git url:'https://github.com/svanoort/pyresttest.git', branch:'jenkins-installtest'

//sh 'git clean -fdx' //Hangs it!

// Test easyinstall, etc installation of scripts
testEnv.inside(args) {
clean_workspace()
sh 'python setup.py install'
headlesstests()
servertests()
}

// Test standard local build/install with CentOS 6 / python 2.6
testEnv26.inside(args) {
clean_workspace()
sh 'python setup.py install'
headlesstests()
servertests()
}

// Test RPM build/install
testEnv26.inside(args) {
clean_workspace()
sh 'python setup.py bdist_rpm'
stash includes: 'dist/*.noarch.rpm', name: 'rpm-py26'
sh 'rpm -if dist/*.noarch.rpm'
headlesstests()
servertests()
}

// THIS DOESN'T WORK YET, SIGH
/*stage name:'Publish to test PyPi', concurrency:1
withCredentials([[$class: 'FileBinding', variable: 'SECRET', credentialsId: '014760b9-3146-49e6-8198-849094a28246']]) {
sh 'cp $SECRET .pypirc'
}
testEnv.inside(args) {
'cp .pypirc ~/.pypirc'
clean_workspace()
// Requires credentials and credentials binding plugin
// Uses a secret stored pypirc file with pypitest enabled
sh 'python setup.py sdist bdist upload -r pypitest'
//TODO Needs some setup to enable wheel packaging
}
*/

stage name:'Test PyPy installation'

// Smoketest pip installation in a naked CentOS image
centos.inside(args) {
clean_workspace()
sh 'rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
sh 'yum install -y python-pip'
sh 'pip install -i https://testpypi.python.org/pypi pyresttest'
headlesstests()
}

// Smoketest RPM installation in a naked CentOS image
centos.inside(args) {
clean_workspace()
dir ("/tmp") {
unstash name: 'rpm-py26'
sh 'rpm -if dist/*.noarch.rpm'
sh 'yum install -y PyYAML'
}
headlesstests()
}

// Smoketest pip installation inside a naked ubuntu 14 image
ubuntu.inside(args) {
clean_workspace()
sh 'apt-get update && apt-get install -y python-pip'
sh 'pip install -i https://testpypi.python.org/pypi pyresttest'
headlesstests()
}

// Functional test using integrated server
testEnv.inside(args) {
clean_workspace()
sh 'pip install -i https://testpypi.python.org/pypi pyresttest'
servertests()
}

// Functional test using integrated server
testEnv26.inside(args) {
clean_workspace()
sh 'pip install -i https://testpypi.python.org/pypi pyresttest'
servertests()
}
}
7 changes: 3 additions & 4 deletions setup.py
@@ -1,15 +1,14 @@
from distutils.core import setup

setup(name='pyresttest',
version='1.6.0-SNAPSHOT',
version='1.6.0.dev',
description='Python RESTful API Testing & Microbenchmarking Tool',
long_description='Python RESTful API Testing & Microbenchmarking Tool',
long_description='Python RESTful API Testing & Microbenchmarking Tool \n Documentation at https://github.com/svanoort/pyresttest',
maintainer='Sam Van Oort',
maintainer_email='samvanoort@gmail.com',
url='https://github.com/svanoort/pyresttest',
keywords=['rest', 'web', 'http', 'testing'],
classifiers = [
'Development Status :: 3 - Alpha',
'Environment :: Console',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
Expand All @@ -23,7 +22,7 @@
'pyresttest.parsing', 'pyresttest.validators', 'pyresttest.contenthandling',
'pyresttest.benchmarks','pyresttest.tests', 'pyresttest.ext.validator_jsonschema'],
license='Apache License, Version 2.0',
requires=['yaml','pycurl'],
requires=['pyyaml','pycurl'],
scripts=['util/pyresttest','util/resttest.py'], #Make this executable from command line when installed
provides=['pyresttest']
)

0 comments on commit e20af67

Please sign in to comment.