summaryrefslogtreecommitdiffstats
path: root/test/integration/roles/test_consul_service/tasks/main.yml
blob: 1b6643f59cb63d06366589fdf1e899c3c65a63b9 (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
- name: cleanup any previous failed runs
  consul:
    service_id: '{{item}}'
    state: absent
  with_items:
      - service1
      - service2
      - http_check
      - with_check
      - with_tags

- name: cleanup previous checks
  consul:
    check_id: '{{item}}'
    state: absent
  with_items:
    - node_level
    - node_level_http

- name: register very basic service with consul gets default id
  consul:
    service_name: service1
    service_port: 80
  register: basic_result

- name: verify basic service registration
  assert:
    that:
        - basic_result.changed
        - basic_result.service_port == 80
        - basic_result.service_id == 'service1'
        - basic_result.service_name == 'service1'

- name: register very basic service with explicit id
  consul:
    service_name: Basic Service
    service_id: service2
    service_port: 80
  register: basic2_result

- name: verify service2 registration
  assert:
    that:
        - basic2_result.changed
        - basic2_result.service_port == 80
        - basic2_result.service_id == 'service2'
        - basic2_result.service_name == 'Basic Service'

- name: register a service with an http check
  consul:
    service_name: http_check
    service_id: http_check
    service_port: 80
    http: "http://localhost/status"
    interval: 60s
  register: http_result

- name: verify service with an http check
  assert:
    that:
      - http_result.changed
      - http_result.service_port == 80
      - http_result.checks | length == 1

- name: register very basic service with check script
  consul:
    service_name: with_check
    service_port: 80
    script: "sh -c true"
    interval: 60s
  register: script_result

- name: verify service with check registration
  assert:
    that:
        - script_result.changed
        - script_result.service_port == 80
        - script_result.service_id == 'with_check'
        - script_result.checks | length == 1

- name: register service with some service tags
  consul:
    service_name: with_tags
    service_port: 80
    tags:
      - prod
      - webservers
  register: tags_result


- name: verify tags registration
  assert:
    that:
        - tags_result.changed
        - "tags_result.tags == ['prod', 'webservers']"

- name: create a node level check
  consul:
    check_name: Node Level Check
    check_id: node_level
    script: "sh -c true"
    interval: 50m
  register: nodelevel_result

- name: verify service with check registration
  assert:
    that:
        - nodelevel_result.changed
        - nodelevel_result.check_name == 'Node Level Check'
        - nodelevel_result.check_id == 'node_level'
        - nodelevel_result.script == 'sh -c true'
        - nodelevel_result.interval == '50m'

- name: create a node level http check
  consul:
    check_name: Node Level HTTP Check
    check_id: node_level_http
    http: 'http://localhost/status'
    interval: 1m
    timeout: 30s
  register: nodelevel_http_result

- name: verify node level http check
  assert:
    that:
      - nodelevel_http_result.changed
      - nodelevel_http_result.check_name == 'Node Level HTTP Check'
      - nodelevel_http_result.check_id == 'node_level_http'
      - nodelevel_http_result.http == 'http://localhost/status'
      - nodelevel_http_result.interval == '1m'
      - nodelevel_http_result.timeout == '30s'

- name: remove a service
  consul:
    service_id: 'service1'
    state: absent
  register: delete_service_result

- name: verify service removal
  assert:
    that:
      - delete_service_result.changed

- name: removal of an non-existant service causes no change
  consul:
    service_id: 'service1'
    state: absent
  register: delete_service_result

- name: verify service removal caused no change
  assert:
    that:
      - not delete_service_result.changed

- name: remove a check
  consul:
    check_id: 'node_level'
    state: absent
  register: delete_check_result

- name: verify check removal
  assert:
    that:
      - delete_check_result.changed

- name: removal of an non-existant check causes no change
  consul:
    check_id: 'node_level'
    state: absent
  register: delete_check_result

- name: verify check removal cause no change
  assert:
    that:
      - not delete_service_result.changed

- name: add service to test removal by name
  consul:
    service_name: by_name
    service_port: 12345

- name: remove service by name
  consul:
    service_name: by_name
    state: absent
  register: delete_service_by_name_result

- name: verify service removal
  assert:
    that:
      - delete_service_by_name_result.changed

- name: cleanup
  consul:
    service_id: '{{item}}'
    state: absent
  with_items:
    - service2
    - with_check
    - with_tags