summaryrefslogtreecommitdiff
path: root/test/integration/targets/aci_epg_to_domain/tasks/main.yml
blob: 5d95059a6eba25985bf90bf2ac7065ce001c3b81 (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
# Test code for the ACI modules
# Copyright: (c) 2017, Dag Wieers (@dagwieers) <dag@wieers.com>

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Test that we have an ACI APIC host, ACI username and ACI password
  fail:
    msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
  when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined

- name: ensure tenant exists for tests to kick off
  aci_tenant: &aci_tenant_present
    host: "{{ aci_hostname }}"
    username: "{{ aci_username }}"
    password: "{{ aci_password }}"
    validate_certs: '{{ aci_validate_certs | default(false) }}'
    use_ssl: '{{ aci_use_ssl | default(true) }}'
    use_proxy: '{{ aci_use_proxy | default(true) }}'
    output_level: debug
    tenant: anstest
    state: present
  register: tenant_present

- name: ensure ap exists for tests to kick off
  aci_ap: &aci_ap_present
    <<: *aci_tenant_present
    ap: anstest
  register: ap_present

- name: ensure epg exists for tests to kick off
  aci_epg: &aci_epg_present
    <<: *aci_ap_present
    epg: anstest
  register: epg_present

- name: ensure phys domain exists for tests to kick off
  aci_rest: &aci_rest_phys_domain
    host: "{{ aci_hostname }}"
    username: "{{ aci_username }}"
    password: "{{ aci_password }}"
    validate_certs: '{{ aci_validate_certs | default(false) }}'
    use_ssl: '{{ aci_use_ssl | default(true) }}'
    use_proxy: '{{ aci_use_proxy | default(true) }}'
    output_level: '{{ aci_output_level | default("info") }}'
    method: post
    path: api/mo/uni/phys-anstest.json
    content: {"physDomP": {"attributes": {}}}
  register: phys_domain_post

- name: ensure vmm domain exists for tests to kick off
  aci_rest: &aci_rest_vmm_domain
    <<: *aci_rest_phys_domain
    path: api/mo/uni/vmmp-VMware/dom-anstest.json
    content: {"vmmDomP": {"attributes": {}}}
  register: vmm_domain_post

- name: bind phys domain to epg - check mode works
  aci_epg_to_domain: &aci_epg_to_domain_present
    <<: *aci_epg_present
    domain: anstest
    domain_type: phys
  check_mode: yes
  register: phys_check_mode_present

- name: bind phys domain to epg - creation works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_present
  register: phys_present

- name: bind phys domain to epg - idempotency works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_present 
  register: phys_idempotent

- name: bind phys domain to epg - update works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_present
    deploy_immediacy: immediate
  register: phys_update

- name: bind vmm domain to epg - creation works
  aci_epg_to_domain: &aci_epg_to_domain_vmm_present
    <<: *aci_epg_to_domain_present
    domain_type: vmm
    vm_provider: vmware
    resolution_immediacy: pre-provision
  register: vmm_present

- name: bind vmm domain to epg - missing params
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_vmm_present
    vm_provider: "{{ fake_var | default(omit) }}"
  ignore_errors: yes
  register: present_missing_params

- name: bind vmm domain to epg - invalid vlan
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_present
    encap: 4097
  ignore_errors: yes
  register: invalid_vlan

- name: bind vmm domain to epg - incompatible params
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_present
    vm_provider: vmware
  ignore_errors: yes
  register: incompatible_params

- name: present assertions
  assert:
    that:
      - phys_check_mode_present is changed
      - phys_present is changed
      - phys_present.previous == []
      - 'phys_present.sent == {"fvRsDomAtt": {"attributes": {}}}'
      - '"[uni/phys-anstest].json" in phys_present.url'
      - phys_idempotent is not changed
      - phys_idempotent.sent == {}
      - phys_update is changed
      - 'phys_update.sent == {"fvRsDomAtt": {"attributes": {"instrImedcy": "immediate"}}}'
      - vmm_present is changed
      - 'vmm_present.sent == {"fvRsDomAtt": {"attributes": {"resImedcy": "pre-provision"}}}'
      - '"[uni/vmmp-VMware/dom-anstest].json" in vmm_present.url'
      - present_missing_params is failed
      - 'present_missing_params.msg == "domain_type is vmm but all of the following are missing: vm_provider"'
      - invalid_vlan is failed
      - invalid_vlan.msg == "Valid VLAN assigments are from 1 to 4096"
      - incompatible_params is failed
      - incompatible_params.msg == "Domain type 'phys' cannot have a 'vm_provider'"

- name: get domain epg binding
  aci_epg_to_domain: &aci_epg_domain_query
    <<: *aci_tenant_present
    state: query
    tenant: "{{ fake_var | default(omit) }}"
  register: binding_query

- name: query assertions
  assert:
    that:
      - binding_query is not changed
      - binding_query.current | length > 1
      - '"class/fvRsDomAtt.json" in binding_query.url'

- name: delete domain epg binding - check mode
  aci_epg_to_domain: &aci_epg_to_domain_absent
    <<: *aci_epg_to_domain_present
    state: absent
  check_mode: yes
  register: epg_domain_check_mode_absent

- name: delete phys domain epg binding - delete works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_absent
  register: epg_domain_absent

- name: delete vmm domain epg binding - delete works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_vmm_present
    state: absent
  register: epg_vmm_domain_absent

- name: delete domain epg binding - idempotency works
  aci_epg_to_domain:
    <<: *aci_epg_to_domain_absent
  register: idempotency_absent

- name: delete domain epg binding - missing param
  aci_epg_to_domain:
    <<: *aci_tenant_present
    state: absent
  ignore_errors: true
  register: absent_missing_param

- name: absent assertions
  assert:
    that:
      - epg_domain_check_mode_absent is changed
      - epg_domain_check_mode_absent.previous != []
      - epg_domain_absent is changed
      - epg_domain_absent.previous == epg_domain_check_mode_absent.previous
      - epg_vmm_domain_absent is changed
      - idempotency_absent is not changed
      - idempotency_absent.previous == []
      - absent_missing_param is failed
      - 'absent_missing_param.msg == "state is absent but all of the following are missing: ap, domain, domain_type, epg"'

- name: remove vmm domain - cleanup
  aci_rest:
    <<: *aci_rest_vmm_domain
    method: delete
  when: vmm_domain_post is changed

- name: remove phys domain - cleanup
  aci_rest:
    <<: *aci_rest_phys_domain
    method: delete
  when: phys_domain_post is changed

- name: remove epg - cleanup
  aci_epg:
    <<: *aci_epg_present
    state: absent
  when: epg_present is changed

- name: remove ap - cleanup
  aci_ap:
    <<: *aci_ap_present
    state: absent
  when: ap_present is changed

- name: remove tenant - cleanup
  aci_tenant:
    <<: *aci_tenant_present
    state: absent
  when: tenant_present is changed