1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#!/usr/bin/make -f
# Copyright 2015 Canonical Ltd.
#
# This file is part of the Cassandra Charm for Juju.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
JUJU = juju
default:
@echo Missing target
@echo 'Usage: make [ lint | unittest | test | clean | sync ]'
env
# Only trusty supported, but xenial expected soon.
SERIES := $(shell $(JUJU) get-environment default-series)
HOST_SERIES := $(shell lsb_release -sc)
ifeq ($(HOST_SERIES),trusty)
PYVER := 3.4
else
PYVER := 3.5
endif
# /!\ Ensure that errors early in pipes cause failures, rather than
# overridden by the last stage of the pipe. cf. 'test.py | ts'
SHELL := /bin/bash
export SHELLOPTS:=errexit:pipefail
# Calculate the CHARM_DIR (the directory this Makefile is in)
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
CHARM_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
VENV3:=$(CHARM_DIR)/.venv3
# Set the PATH so the correct tools are found.
export PATH:=$(VENV3)/bin:$(PATH)
SITE_PACKAGES=$(wildcard $(VENV3)/lib/python*/site-packages)
PIP=.venv3/bin/pip$(PYVER) -q
NOSETESTS=.venv3/bin/nosetests-3.4 -sv # Yes, even with 3.5
# Set pipefail so we can get sane error codes while tagging test output
# with ts(1)
SHELL=bash -o pipefail
deps: packages venv3
lint: deps
date
free --human
charm proof $(CHARM_DIR)
flake8 \
--ignore=E402,E265 \
--exclude=charmhelpers,.venv2,.venv3 hooks tests testing
@echo OK: Lint free `date`
unittest: lint
$(NOSETESTS) \
tests.test_actions --cover-package=actions \
tests.test_helpers --cover-package=helpers \
tests.test_definitions --cover-package=definitions \
--with-coverage --cover-branches
@echo OK: Unit tests pass `date`
test: unittest
AMULET_TIMEOUT=3600 \
$(NOSETESTS) tests.test_integration
ftest: unittest Test1UnitDeployment
Test1UnitDeployment: deps
date
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:Test1UnitDeployment 2>&1 | ts
20test: unittest Test20Deployment
Test20Deployment: deps
date
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:Test20Deployment 2>&1 | ts
21test: unittest Test21Deployment
Test21Deployment: deps
date
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:Test21Deployment 2>&1 | ts
30test: unittest Test30Deployment
Test30Deployment: deps
date
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:Test30Deployment 2>&1 | ts
3test: unittest Test3UnitDeployment
Test3UnitDeployment: deps
date
AMULET_TIMEOUT=7200 \
$(NOSETESTS) tests.test_integration:Test3UnitDeployment 2>&1 | ts
authtest: unittest TestAllowAllAuthenticatorDeployment
TestAllowAllAuthenticatorDeployment: deps
date
AMULET_TIMEOUT=7200 \
$(NOSETESTS) \
tests.test_integration:TestAllowAllAuthenticatorDeployment 2>&1 | ts
# Place a copy of the Oracle Java SE 7 Server Runtime tarball in ./lib
# to run these tests.
jretest: unittest
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:TestOracleJREDeployment 2>&1 | ts
# You need the Oracle JRE (per jretest) and set the DSE_SOURCE environment
# variable for this to work:
# DSE_SOURCE="deb http://un:pw@debian.datastax.com/enterprise stable main"
# You will also need a cache like squid-deb-proxy and have tweaked it to
# cache the authenticated files, or the tests will likely timeout waiting
# for huge downloads to complete. Alternatively, mirror the DataStax
# packages into your own private archive.
dsetest: unittest
AMULET_TIMEOUT=5400 \
$(NOSETESTS) tests.test_integration:TestDSEDeployment 2>&1 | ts
coverage: lint
$(NOSETESTS) \
tests.test_actions --cover-package=actions \
tests.test_helpers --cover-package=helpers \
tests.test_definitions --cover-package=definitions \
--with-coverage --cover-branches \
--cover-html --cover-html-dir=coverage \
--cover-min-percentage=100 || \
(gnome-open coverage/index.html; false)
clean:
rm -rf .venv? tests/.venv? .stamp-* coverage .coverage
find . -name __pycache__ -type d | xargs rm -rf
# Attempt to diagnose environment for test failures.
debug:
-which virtualenv
-which python
-which python2
-which python3
-which pip
-which pip3
-head -1 `which virtualenv || echo nothere`
-python -c 'import sys; print(sys.version); print(sys.path);'
-python2 -c 'import sys; print(sys.version); print(sys.path);'
-python3 -c 'import sys; print(sys.version); print(sys.path);'
-env
packages: .stamp-packages
.stamp-packages:
# Install bootstrap debs, and Python packages used by the charm
# to ensure versions match.
sudo add-apt-repository -y ppa:stub/juju
sudo add-apt-repository -y ppa:stub/cassandra
sudo apt-get update
sudo apt-get install -y \
python3 python3-pip python3-apt python3-dev python-virtualenv \
charm-tools build-essential libev4 libev-dev libffi-dev \
netcat python3-jinja2 juju-wait moreutils \
python3-cassandra python3-bcrypt
touch .stamp-packages
venv3: packages .stamp-venv3
.stamp-venv3:
# Build a Python virtualenv to run our tests.
virtualenv -p python3 --system-site-packages ${VENV3}
# Create a .pth so our tests can locate everything without
# sys.path hacks.
(echo ${CHARM_DIR}/hooks; echo ${CHARM_DIR}) \
> ${VENV3}/lib/python${PYVER}/site-packages/tests.pth
echo 'pip: ' `which pip`
# Pip install packages needed by the test suite but not used
# by the charm.
$(PIP) install bcrypt cassandra-driver blist
$(PIP) install --upgrade -I nose flake8
$(PIP) install --upgrade coverage amulet mock juju-deployer juju-wait
echo 'nosetests:' `which nosetests`
echo 'flake8:' `which flake8`
# Create a link for test shebang lines.
(cd tests && ln -s ${VENV3} .venv3)
touch .stamp-venv3
venv2: packages .stamp-venv2
.stamp-venv2:
virtualenv -p python2.7 --system-site-packages .venv2
.venv2/bin/pip install -q bundletester
touch .stamp-venv2
bundletest: venv2
.venv2/bin/bundletester
sync:
@bzr cat \
lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
> .charm_helpers_sync.py
@python .charm_helpers_sync.py -c charm-helpers.yaml
#@python .charm_helpers_sync.py \
# -c lib/testcharms/testclient/charm-helpers.yaml
@rm .charm_helpers_sync.py
|