blob: fc0875e9df2b221b77c691b2cc4808742a15d2b8 (
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
|
# Test code for the vmware_dvs_portgroup module.
# (c) 2017, Philippe Dellaert <philippe@dellaert.org>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY 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 Ansible. If not, see <http://www.gnu.org/licenses/>.
#
- name: make sure pyvmomi is installed
pip:
name: pyvmomi
state: latest
when: "{{ ansible_user_id == 'root' }}"
- name: store the vcenter container ip
set_fact:
vcsim: "{{ lookup('env', 'vcenter_host') }}"
- debug: var=vcsim
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: "{{ 'http://' + vcsim + ':5000/killall' }}"
- name: start vcsim
uri:
url: "{{ 'http://' + vcsim + ':5000/spawn?cluster=2' }}"
register: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- debug: var=vcsim_instance
- name: get a list of distributed vswitch from vcsim after adding
uri:
url: "{{ 'http://' + vcsim + ':5000/govc_find?filter=DVS' }}"
register: new_dvs_0001
- debug:
msg: "{{ item | basename }}"
with_items: "{{ new_dvs_0001['json'] }}"
# Testcase 0001: Add basic portgroup
- name: create basic portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: present
register: dvs_pg_result_0001
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0001.changed == true }}"
# Testcase 0002: Add basic VLAN portgroup
- name: create basic VLAN portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic-vlan10"
vlan_id: 10
num_ports: 32
portgroup_type: earlyBinding
state: present
register: dvs_pg_result_0002
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0002.changed == true }}"
# Testcase 0003: Add basic trunk portgroup
- name: create basic trunk portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic-trunk"
vlan_id: 1-4096
vlan_trunk: True
num_ports: 32
portgroup_type: earlyBinding
state: present
register: dvs_pg_result_0003
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0003.changed == true }}"
# Testcase 0004: Add basic portgroup again
- name: create basic portgroup again
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: present
register: dvs_pg_result_0004
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0004.changed == false }}"
# Testcase 0005: Add basic portgroup with all security and policy settings enabled
- name: create basic portgroup with all security and policy settings enabled
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic-all-enabled"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: present
security:
promiscuous: yes
forged_transmits: yes
mac_changes: yes
port_policy:
block_override: yes
ipfix_override: yes
live_port_move: yes
network_rp_override: yes
port_config_reset_at_disconnect: yes
security_override: yes
shaping_override: yes
traffic_filter_override: yes
uplink_teaming_override: yes
vendor_config_override: yes
vlan_override: yes
register: dvs_pg_result_0005
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0005.changed == true }}"
# Testcase 0006: Add basic portgroup with some settings enabled
- name: create basic portgroup with all security and policy settings enabled
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic-some-enabled"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: present
security:
promiscuous: yes
forged_transmits: yes
mac_changes: no
port_policy:
vlan_override: yes
register: dvs_pg_result_0006
- name: ensure dvs portgroup is present
assert:
that:
- "{{ dvs_pg_result_0006.changed == true }}"
# Testcase 0007: Delete basic portgroup
- name: delete basic portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: absent
register: dvs_pg_result_0007
- name: ensure dvs portgroup is removed
assert:
that:
- "{{ dvs_pg_result_0007.changed == true }}"
# Testcase 0008: Delete basic portgroup again
- name: delete basic portgroup again
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
switch_name: "{{ new_dvs_0001['json'][0] | basename }}"
portgroup_name: "basic"
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: absent
register: dvs_pg_result_0008
- name: ensure dvs portgroup is removed
assert:
that:
- "{{ dvs_pg_result_0008.changed == false }}"
|