blob: 1718dc7e467ff3a5c12263ed0e77680f0d41da93 (
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
|
# Test code for the vmware_dvswitch module.
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- 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
- name: get a list of Datacenter from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: datacenters
- debug: var=vcsim_instance
- debug: var=datacenters
# Testcase 0001: Add Distributed vSwitch
- name: add distributed vSwitch
vmware_dvswitch:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
datacenter_name: "{{ item | basename }}"
state: present
switch_name: dvswitch_0001
mtu: 9000
uplink_quantity: 2
discovery_proto: lldp
discovery_operation: both
register: dvs_result_0001
with_items:
- "{{ datacenters['json'] }}"
- name: ensure distributed vswitch is present
assert:
that:
- "{{ dvs_result_0001.changed == true }}"
- 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'] }}"
- set_fact: new_dvs_name="{% for dvs in new_dvs_0001['json'] %} {{ True if (dvs | basename) == 'dvswitch_0001' else False }}{% endfor %}"
- debug: var=new_dvs_name
- assert:
that:
- "{{ 'True' in new_dvs_name }}"
# Testcase 0002: Add Distributed vSwitch again
- name: add distributed vSwitch again
vmware_dvswitch:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
datacenter_name: "{{ item | basename }}"
state: present
switch_name: dvswitch_0001
mtu: 9000
uplink_quantity: 2
discovery_proto: lldp
discovery_operation: both
register: dvs_result_0002
with_items:
- "{{ datacenters['json'] }}"
- name: ensure distributed vswitch is present
assert:
that:
- "{{ dvs_result_0002.changed == false }}"
# FIXME: Uncomment this testcase once vcsim supports distributed vswitch delete method
# Currently, vcsim does not support distributed vswitch delete option,
# Once this feature is available we can uncomment following testcase
# Testcase 0003: Add Distributed vSwitch
#- name: add distributed vSwitch
# vmware_dvswitch:
# validate_certs: False
# hostname: "{{ vcsim }}"
# username: root
# password: esxi@123
# datacenter_name: "{{ item | basename }}"
# state: absent
# switch_name: dvswitch_0001
# mtu: 9000
# uplink_quantity: 2
# discovery_proto: lldp
# discovery_operation: both
# with_items:
# - "{{ datacenters['json'] }}"
# register: dvs_result_0003
#- name: ensure distributed vswitch is present
# assert:
# that:
# - "{{ dvs_result_0003.changed == true }}"
#- name: get a list of Datacenter from vcsim after adding datacenter
# uri:
# url: http://{{ vcsim }}:5000/govc_find?filter=DVS
# register: del_dvs
#- debug:
# msg: "{{ item | basename }}"
# with_items: "{{ del_dvs['json'] }}"
#- set_fact: del_dvs_name="{% for i in del_dvs['json'] %} {{ True if (i | basename) == 'dvswitch_0001' else False }}{% endfor %}"
#- debug: var=del_dvs_name
#- assert:
# that:
# - "{{ 'True' not in del_dvs_name }}"
|