summaryrefslogtreecommitdiff
path: root/test/integration/Makefile
blob: ac75f2f6d1cd8c93770521cf1ce7490c347765b9 (plain)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
TEST_DIR ?= ~/ansible_testing
INVENTORY ?= inventory
VARS_FILE ?= integration_config.yml

# Create a semi-random string for use when testing cloud-based resources
ifndef CLOUD_RESOURCE_PREFIX
CLOUD_RESOURCE_PREFIX := $(shell python -c "import string,random; print('ansible-testing-' + ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)));")
endif

CREDENTIALS_FILE ?= credentials.yml
# If credentials.yml exists, use it
ifneq ("$(wildcard $(CREDENTIALS_FILE))","")
CREDENTIALS_ARG = -e @$(CREDENTIALS_FILE)
else
CREDENTIALS_ARG =
endif

# http://unix.stackexchange.com/questions/30091/fix-or-alternative-for-mktemp-in-os-x
MYTMPDIR = $(shell mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')

VAULT_PASSWORD_FILE = vault-password

CONSUL_RUNNING := $(shell python consul_running.py)
EUID := $(shell id -u -r)

UNAME := $(shell uname | tr '[:upper:]' '[:lower:]')

all: other non_destructive destructive

other: test_test_infra parsing test_var_precedence unicode test_templating_settings environment test_as includes blocks pull_run pull_no_127 pull_limit_inventory check_mode test_hash test_handlers test_group_by test_vault test_tags test_lookup_paths no_log test_gathering_facts test_binary_modules_posix test_hosts_field test_lookup_properties args

test_test_infra:
	(cd targets/test_infra && ./runme.sh $(TEST_FLAGS))

setup:
	rm -rf $(TEST_DIR)
	mkdir -p $(TEST_DIR)

parsing:
	(cd targets/parsing && ./runme.sh $(TEST_FLAGS))

includes:
	(cd targets/includes && ./runme.sh $(TEST_FLAGS))

pull_run:
	(cd targets/pull_run && ./runme.sh $(TEST_FLAGS))

pull_no_127:
	(cd targets/pull_no_127 && ./runme.sh $(TEST_FLAGS))

pull_limit_inventory:
	(cd targets/pull_limit_inventory && ./runme.sh $(TEST_FLAGS))

unicode:
	(cd targets/unicode && ./runme.sh $(TEST_FLAGS))

test_templating_settings:
	(cd targets/templating_settings && ./runme.sh $(TEST_FLAGS))

test_gathering_facts:
	(cd targets/gathering_facts && ./runme.sh $(TEST_FLAGS))

environment:
	(cd targets/environment && ./runme.sh $(TEST_FLAGS))

non_destructive: setup
	ansible-playbook non_destructive.yml -i $(INVENTORY) -e outputdir=$(TEST_DIR) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)

# Tests which can be run when running as root and a local SSH daemon is available.
test_root_ssh: test_connection_local test_connection_chroot test_connection_ssh test_connection_paramiko_ssh test_delegate_to

# For tests running in our Docker containers (identified with "ENV container=docker").
# These tests are run as root and have access to a local SSH daemon.
test_as_docker: test_root_ssh test_async_extra_data

# For tests running in our FreeBSD instances on EC2 (identified with "ENV container=freebsd").
# These tests are run as root and have access to a local SSH daemon.
test_as_freebsd: test_root_ssh

# For tests running in our OS X instances at MacStadium (identified with "ENV container=osx").
# These tests are run as root and have access to a local SSH daemon.
test_as_osx: test_root_ssh

# For tests running as root.
# Login to a local SSH daemon assumed to be unavailable.
test_as_root: test_connection_local test_connection_chroot

# For tests not running as root.
# Login to a local SSH daemon assumed to be unavailable.
test_as_non_root: test_connection_local

# Determine which of the above environments we're running in.
ifeq ($(container),docker)
TEST_AS_TARGET := test_as_docker
else ifeq ($(container),freebsd)
TEST_AS_TARGET := test_as_freebsd
else ifeq ($(container),osx)
TEST_AS_TARGET := test_as_osx
else ifeq ($(EUID),0)
TEST_AS_TARGET := test_as_root
else
TEST_AS_TARGET := test_as_non_root
endif

test_as: $(TEST_AS_TARGET)

test_connection_local:
	(cd targets/connection_local && ./runme.sh $(TEST_FLAGS))

test_connection_chroot:
	(cd targets/connection_chroot && ./runme.sh $(TEST_FLAGS))

test_connection_docker:
	(cd targets/connection_docker && ./runme.sh $(TEST_FLAGS))

test_connection_libvirt_lxc:
	(cd targets/connection_libvirt_lxc && ./runme.sh $(TEST_FLAGS))

test_connection_jail:
	(cd targets/connection_jail && ./runme.sh $(TEST_FLAGS))

test_connection_ssh:
	(cd targets/connection_ssh && ./runme.sh $(TEST_FLAGS))

test_connection_paramiko_ssh:
	(cd targets/connection_paramiko_ssh && ./runme.sh $(TEST_FLAGS))

test_connection_lxd:
	(cd targets/connection_lxd && ./runme.sh $(TEST_FLAGS))

test_connection_lxc:
	(cd targets/connection_lxc && ./runme.sh $(TEST_FLAGS))

test_connection_winrm:
	(cd targets/connection_winrm && ./runme.sh $(TEST_FLAGS))

destructive: setup
	ansible-playbook destructive.yml -i $(INVENTORY) -e outputdir=$(TEST_DIR) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)

check_mode:
	(cd targets/check_mode && ./runme.sh $(TEST_FLAGS))

test_group_by:
	(cd targets/group_by && ./runme.sh $(TEST_FLAGS))

test_handlers:
	(cd targets/handlers && ./runme.sh $(TEST_FLAGS))

test_hash:
	(cd targets/hash && ./runme.sh $(TEST_FLAGS))

test_var_precedence:
	(cd targets/var_precedence && ./runme.sh $(TEST_FLAGS))

test_vault:
	(cd targets/vault && ./runme.sh $(TEST_FLAGS))

test_delegate_to:
	(cd targets/delegate_to && ./runme.sh $(TEST_FLAGS))

# Split Windows CI targets to support parallel execution.
# Targets should be balanced to have similar run times.
ci_win: ci_win1 ci_win2 ci_win3
ci_win1: test_win_group1
ci_win2: test_win_group2 test_binary_modules_winrm
ci_win3: test_win_group3 test_connection_winrm

test_winrm: test_win_group1 test_win_group2 test_win_group3

test_win_group1:
	ansible-playbook test_win_group1.yml -i inventory.winrm -e outputdir=$(TEST_DIR) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)

test_win_group2:
	ansible-playbook test_win_group2.yml -i inventory.winrm -e outputdir=$(TEST_DIR) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)

test_win_group3:
	ansible-playbook test_win_group3.yml -i inventory.winrm -e outputdir=$(TEST_DIR) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)

test_tags:
	(cd targets/tags && ./runme.sh $(TEST_FLAGS))

blocks:
	(cd targets/blocks && ./runme.sh $(TEST_FLAGS))

cloud: amazon rackspace azure

cloud_cleanup: amazon_cleanup rackspace_cleanup

amazon_cleanup:
	python cleanup_ec2.py -y --match="^$(CLOUD_RESOURCE_PREFIX)"

azure_cleanup:
	python cleanup_azure.py -y --match="^$(CLOUD_RESOURCE_PREFIX)"

gce_setup:
	python setup_gce.py "$(CLOUD_RESOURCE_PREFIX)"

gce_cleanup:
	python cleanup_gce.py -y --match="^$(CLOUD_RESOURCE_PREFIX)"

rackspace_cleanup:
	python cleanup_rax.py -y --match="^$(CLOUD_RESOURCE_PREFIX)"

$(CREDENTIALS_FILE):
	@echo "No credentials file found.  A file named '$(CREDENTIALS_FILE)' is needed to provide credentials needed to run cloud tests.  See sample 'credentials.template' file."
	@exit 1

amazon: $(CREDENTIALS_FILE)
	ANSIBLE_HOST_KEY_CHECKING=False ANSIBLE_SSH_PIPELINING=no BOTO_CONFIG=/dev/null ansible-playbook amazon.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make amazon_cleanup ; \
    exit $$RC;

azure: $(CREDENTIALS_FILE)
	ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook azure.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make azure_cleanup ; \
    exit $$RC;

gce: $(CREDENTIALS_FILE)
	CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make gce_setup ; \
    ansible-playbook gce.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make gce_cleanup ; \
    exit $$RC;

rackspace: $(CREDENTIALS_FILE)
	ansible-playbook rackspace.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make rackspace_cleanup ; \
    exit $$RC;

cloudstack:
	ansible-playbook cloudstack.yml -i $(INVENTORY) -e @$(VARS_FILE) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
	RC=$$? ; \
	exit $$RC;

exoscale:
	ansible-playbook exoscale.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS) ; \
	RC=$$? ; \
	exit $$RC;

jenkins:
	ansible-playbook jenkins.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS) ; \
	RC=$$? ; \
	exit $$RC;

cloudflare: $(CREDENTIALS_FILE)
	ansible-playbook cloudflare.yml -i $(INVENTORY) -e @$(VARS_FILE) -e @$(CREDENTIALS_FILE) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
	RC=$$? ; \
	exit $$RC;

$(CONSUL_RUNNING):

consul:
ifeq ($(CONSUL_RUNNING), True)
	ansible-playbook -i $(INVENTORY) consul.yml ; \
	ansible-playbook -i ../../contrib/inventory/consul_io.py consul_inventory.yml
else
	@echo "Consul agent is not running locally. To run a cluster locally see http://github.com/sgargan/consul-vagrant"
endif

test_galaxy: test_galaxy_spec test_galaxy_yaml test_galaxy_git

test_galaxy_spec: setup
	mytmpdir=$(MYTMPDIR) ; \
	ansible-galaxy install -r galaxy_rolesfile -p $$mytmpdir/roles -vvvv ; \
    cp galaxy_playbook.yml $$mytmpdir ; \
    ansible-playbook -i $(INVENTORY) $$mytmpdir/galaxy_playbook.yml -e outputdir=$(TEST_DIR) -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    rm -rf $$mytmpdir ; \
    exit $$RC

test_galaxy_yaml: setup
	mytmpdir=$(MYTMPDIR) ; \
	ansible-galaxy install -r galaxy_roles.yml -p $$mytmpdir/roles -vvvv; \
    cp galaxy_playbook.yml $$mytmpdir ; \
    ansible-playbook -i $(INVENTORY) $$mytmpdir/galaxy_playbook.yml -e outputdir=$(TEST_DIR) -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    rm -rf $$mytmpdir ; \
    exit $$RC

test_galaxy_git: setup
	mytmpdir=$(MYTMPDIR) ; \
	ansible-galaxy install git+https://bitbucket.org/willthames/git-ansible-galaxy,v1.6 -p $$mytmpdir/roles -vvvv; \
    cp galaxy_playbook_git.yml $$mytmpdir ; \
    ansible-playbook -i $(INVENTORY) $$mytmpdir/galaxy_playbook_git.yml -v $(TEST_FLAGS) ; \
    RC=$$? ; \
    rm -rf $$mytmpdir ; \
    exit $$RC

test_lookup_paths:
	(cd targets/lookup_paths && ./runme.sh $(TEST_FLAGS))

no_log:
	(cd targets/no_log && ./runme.sh $(TEST_FLAGS))

test_binary_modules_winrm:
	(cd targets/binary_modules_winrm && ./runme.sh $(TEST_FLAGS))

test_binary_modules_posix:
	(cd targets/binary_modules_posix && ./runme.sh $(TEST_FLAGS))

test_async_extra_data:
	(cd targets/async_extra_data && ./runme.sh $(TEST_FLAGS))

test_hosts_field:
	(cd targets/hosts_field && ./runme.sh $(TEST_FLAGS))

test_lookup_properties:
	(cd targets/lookup_properties && ./runme.sh $(TEST_FLAGS))

args:
	(cd targets/args && ./runme.sh $(TEST_FLAGS))