Skip to content

Commit

Permalink
Merge pull request #1729 from StackStorm/travis-integration-tests
Browse files Browse the repository at this point in the history
Integration Tests via Travis
  • Loading branch information
lakshmi-kannan committed Jul 24, 2015
2 parents 528f44c + 1788262 commit 34216d3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 39 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; http://nedbatchelder.com/code/coverage/config.html

[run]
include = st2*
omit = *tests/*
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Used old infrastructure, needed for integration tests:
# http://docs.travis-ci.com/user/workers/standard-infrastructure/
sudo: true
language: python
sudo: false
python:
- 2.7

env:
- TASK=checks
- TASK=unit
- TASK=integration

services:
- mongodb
Expand All @@ -16,11 +18,12 @@ cache:
- $HOME/.cache/pip/

install:
- if [[ ${TASK} == 'unit' ]]; then pip install python-coveralls; fi
- make requirements
- pip install python-coveralls
- make requirements
- if [ ${TASK} = 'integration' ]; then sudo ./scripts/travis/prepare-integration.sh; fi

script:
- ./scripts/travis.sh
- ./scripts/travis/build.sh

after_success:
- if [[ ${TASK} == 'unit' ]]; then coveralls; fi
- coveralls
47 changes: 22 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ COMPONENT_SPECIFIC_TESTS := st2tests
# nasty hack to get a space into a variable
space_char :=
space_char +=
comma := ,
COMPONENT_PYTHONPATH = $(subst $(space_char),:,$(realpath $(COMPONENTS)))
COMPONENTS_TEST := $(foreach component,$(filter-out $(COMPONENT_SPECIFIC_TESTS),$(COMPONENTS)),$(component))
COMPONENTS_TEST_COMMA := $(subst $(space_char),$(comma),$(COMPONENTS_TEST))

PYTHON_TARGET := 2.7

Expand All @@ -40,6 +42,7 @@ all: requirements check tests docs
play:
@echo COMPONENTS=$(COMPONENTS)
@echo COMPONENTS_TEST=$(COMPONENTS_TEST)
@echo COMPONENTS_TEST_COMMA=$(COMPONENTS_TEST_COMMA)
@echo COMPONENT_PYTHONPATH=$(COMPONENT_PYTHONPATH)


Expand Down Expand Up @@ -218,19 +221,14 @@ $(VIRTUALENV_DIR)/bin/activate:
.PHONY: tests
tests: pytests

# Travis cannot run itests since those require users to be configured etc.
# Creating special travis target. (Yuck!)
.PHONY: tests-travis
tests-travis: requirements unit-tests-coverage-xml

.PHONY: pytests
pytests: compile requirements .flake8 .pylint .pytests-coverage

.PHONY: .pytests
.pytests: compile unit-tests itests clean

.PHONY: .pytests-coverage
.pytests-coverage: unit-tests-coverage-html itests clean
.pytests-coverage: .unit-tests-coverage-html .itests-coverage-html clean

.PHONY: unit-tests
unit-tests:
Expand All @@ -246,10 +244,10 @@ unit-tests:
. $(VIRTUALENV_DIR)/bin/activate; nosetests -s -v $$component/tests/unit || exit 1; \
done

.PHONY: unit-tests-coverage-xml
unit-tests-coverage-xml:
.PHONY: .unit-tests-coverage-html
.unit-tests-coverage-html:
@echo
@echo "==================== unit tests with coverage (XML reports) ===================="
@echo "==================== unit tests with coverage (HTML reports) ===================="
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
Expand All @@ -258,42 +256,41 @@ unit-tests-coverage-xml:
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv --with-coverage \
--cover-inclusive --cover-xml \
--cover-package=$$component $$component/tests/unit && \
mv coverage.xml coverage-$$component.xml || exit 1; \
--cover-inclusive --cover-html \
--cover-package=$(COMPONENTS_TEST_COMMA) $$component/tests/unit || exit 1; \
done

.PHONY: unit-tests-coverage-html
unit-tests-coverage-html:
.PHONY: itests
itests: requirements .itests

.PHONY: .itests
.itests:
@echo
@echo "==================== unit tests with coverage (HTML reports) ===================="
@echo "==================== integration tests ===================="
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv --with-coverage \
--cover-inclusive --cover-erase --cover-html \
--cover-package=$$component $$component/tests/unit || exit 1; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv $$component/tests/integration || exit 1; \
done

.PHONY: itests
itests: requirements .itests

.PHONY: .itests
.itests:
.PHONY: .itests-coverage-html
.itests-coverage-html:
@echo
@echo "==================== integration tests ===================="
@echo "================ integration tests with coverage (HTML reports) ================"
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv $$component/tests/integration || exit 1; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv --with-coverage \
--cover-inclusive --cover-html \
--cover-package=$(COMPONENTS_TEST_COMMA) $$component/tests/integration || exit 1; \
done

.PHONY: mistral-itests
Expand Down
10 changes: 4 additions & 6 deletions scripts/travis.sh → scripts/travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ if [ -z ${TASK} ]; then
exit 2
fi

if [ ${TASK} == 'checks' ]; then
make .flake8
make .pylint
make .docs
elif [ ${TASK} == 'unit' ]; then
if [ ${TASK} == 'unit' ]; then
# compile .py files, useful as compatibility syntax check
make compile
make unit-tests-coverage-xml
make .unit-tests-coverage-html
elif [ ${TASK} == 'integration' ]; then
make .itests-coverage-html
else
echo "Invalid task: ${TASK}"
exit 2
Expand Down
41 changes: 41 additions & 0 deletions scripts/travis/prepare-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -e

if [ "$(whoami)" != 'root' ]; then
echo 'Please run with sudo'
exit 2
fi

# create and configure user
# proudly stolen from `./tools/st2_deploy.sh`
TYPE='debs'
SYSTEMUSER='stanley'

echo "###########################################################################################"
echo "# Creating system user: ${SYSTEMUSER}"
useradd ${SYSTEMUSER}
mkdir -p /home/${SYSTEMUSER}/.ssh
chmod 0700 /home/${SYSTEMUSER}/.ssh
mkdir -p /home/${SYSTEMUSER}/${TYPE}
echo "###########################################################################################"
echo "# Generating system user ssh keys"
ssh-keygen -f /home/${SYSTEMUSER}/.ssh/stanley_rsa -P ""
cat /home/${SYSTEMUSER}/.ssh/stanley_rsa.pub >> /home/${SYSTEMUSER}/.ssh/authorized_keys
chmod 0600 /home/${SYSTEMUSER}/.ssh/authorized_keys
chown -R ${SYSTEMUSER}:${SYSTEMUSER} /home/${SYSTEMUSER}
if [ $(grep 'stanley' /etc/sudoers.d/* &> /dev/null; echo $?) != 0 ]; then
echo "${SYSTEMUSER} ALL=(ALL) NOPASSWD: SETENV: ALL" >> /etc/sudoers.d/st2
chmod 0440 /etc/sudoers.d/st2
fi
# make sure requiretty is disabled.
sed -i "s/^Defaults\s\+requiretty/# Defaults requiretty/g" /etc/sudoers

# install st2 client
python ./st2client/setup.py develop
st2 --version

# install screen
apt-get install -y screen

# start dev environment in screens
./tools/launchdev.sh start
2 changes: 1 addition & 1 deletion st2debug/st2debug/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
'''

# Fingerprint of the public key
GPG_KEY_FINGERPRINT = 'BDE9 89A1 F308 B18D 2978 9C71 7064 B11C 82F6 2D6F'
GPG_KEY_FINGERPRINT = 'BDE989A1F308B18D29789C717064B11C82F62D6F'

# Bucket where the encrypted tarballs are uploaded (bucket is writeable
# by everyone, but only reeadable by StackStorm)
Expand Down
2 changes: 1 addition & 1 deletion tools/launchdev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function st2start(){
--config-file $ST2_CONF --register-all

# List screen sessions
screen -ls
screen -ls || exit 0
}

function st2stop(){
Expand Down

0 comments on commit 34216d3

Please sign in to comment.