summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/docker_swarm/tasks/tests/basic.yml
blob: 7104b912a1f6a031c63d07fdae7640338211749c (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
---
####################################################################
## Errors ##########################################################
####################################################################

- name: Test parameters with state=join
  docker_swarm:
    state: join
  ignore_errors: yes
  register: output

- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
  assert:
    that:
       - 'output.failed'
       - 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'

- name: Test parameters with state=remove
  docker_swarm:
    state: remove
  ignore_errors: yes
  register: output

- name: assert failure when called with state=remove and no node_id
  assert:
    that:
       - 'output.failed'
       - 'output.msg == "state is remove but all of the following are missing: node_id"'

####################################################################
## Creation ########################################################
####################################################################

- name: Create a Swarm cluster (check mode)
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
  check_mode: yes
  diff: yes
  register: output_1

- name: Create a Swarm cluster
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
  diff: yes
  register: output_2

- name: Create a Swarm cluster (idempotent)
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
  diff: yes
  register: output_3

- name: Create a Swarm cluster (idempotent, check mode)
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
  check_mode: yes
  diff: yes
  register: output_4

- name: Create a Swarm cluster (force re-create)
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
    force: yes
  diff: yes
  register: output_5

- name: Create a Swarm cluster (force re-create, check mode)
  docker_swarm:
    state: present
    advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"
    force: yes
  check_mode: yes
  diff: yes
  register: output_6

- name: assert changed when create a new swarm cluster
  assert:
    that:
       - 'output_1 is changed'
       - 'output_1.diff.before is defined'
       - 'output_1.diff.after is defined'
       - 'output_2 is changed'
       - 'output_2.actions[0] | regex_search("New Swarm cluster created: ")'
       - 'output_2.swarm_facts.JoinTokens.Manager'
       - 'output_2.swarm_facts.JoinTokens.Worker'
       - 'output_2.diff.before is defined'
       - 'output_2.diff.after is defined'
       - 'output_3 is not changed'
       - 'output_3.diff.before is defined'
       - 'output_3.diff.after is defined'
       - 'output_4 is not changed'
       - 'output_4.diff.before is defined'
       - 'output_4.diff.after is defined'
       - 'output_5 is changed'
       - 'output_5.diff.before is defined'
       - 'output_5.diff.after is defined'
       - 'output_6 is changed'
       - 'output_6.diff.before is defined'
       - 'output_6.diff.after is defined'

####################################################################
## Removal #########################################################
####################################################################

- name: Remove a Swarm cluster (check mode)
  docker_swarm:
    state: absent
    force: true
  check_mode: yes
  diff: yes
  register: output_1

- name: Remove a Swarm cluster
  docker_swarm:
    state: absent
    force: true
  diff: yes
  register: output_2

- name: Remove a Swarm cluster (idempotent)
  docker_swarm:
    state: absent
    force: true
  diff: yes
  register: output_3

- name: Remove a Swarm cluster (idempotent, check mode)
  docker_swarm:
    state: absent
    force: true
  check_mode: yes
  diff: yes
  register: output_4

- name: assert changed when remove a swarm cluster
  assert:
    that:
       - 'output_1 is changed'
       - 'output_1.diff.before is defined'
       - 'output_1.diff.after is defined'
       - 'output_2 is changed'
       - 'output_2.actions[0] == "Node has left the swarm cluster"'
       - 'output_2.diff.before is defined'
       - 'output_2.diff.after is defined'
       - 'output_3 is not changed'
       - 'output_3.diff.before is defined'
       - 'output_3.diff.after is defined'
       - 'output_4 is not changed'
       - 'output_4.diff.before is defined'
       - 'output_4.diff.after is defined'