2019-07-08 04:24:54 +02:00
|
|
|
# Test code for the vmware_guest_network module
|
|
|
|
# Copyright: (c) 2019, Diane Wang (Tomorrow9) <dianew@vmware.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
- when: vcsim is not defined
|
|
|
|
block:
|
|
|
|
- import_role:
|
|
|
|
name: prepare_vmware_tests
|
|
|
|
vars:
|
|
|
|
setup_attach_host: true
|
|
|
|
setup_datastore: true
|
2020-01-17 00:07:15 +01:00
|
|
|
setup_dvs_portgroup: true
|
|
|
|
setup_dvswitch: true
|
2019-10-10 15:31:23 +02:00
|
|
|
|
|
|
|
- name: Create VMs
|
|
|
|
vmware_guest:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
validate_certs: no
|
|
|
|
folder: '/DC0/vm/F0'
|
|
|
|
name: test_vm1
|
|
|
|
state: poweredon
|
|
|
|
guest_id: centos7_64Guest
|
|
|
|
disk:
|
|
|
|
- size_gb: 1
|
|
|
|
type: thin
|
2019-11-13 16:37:31 +01:00
|
|
|
datastore: '{{ rw_datastore }}'
|
2019-10-10 15:31:23 +02:00
|
|
|
hardware:
|
|
|
|
version: latest
|
|
|
|
memory_mb: 1024
|
|
|
|
num_cpus: 1
|
|
|
|
scsi: paravirtual
|
|
|
|
cdrom:
|
|
|
|
type: iso
|
2019-11-13 16:37:31 +01:00
|
|
|
iso_path: "[{{ ro_datastore }}] fedora.iso"
|
2019-10-10 15:31:23 +02:00
|
|
|
networks:
|
|
|
|
- name: VM Network
|
|
|
|
|
|
|
|
- vmware_guest_tools_wait:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2020-01-31 18:18:18 +01:00
|
|
|
timeout: 600
|
2019-10-10 15:31:23 +02:00
|
|
|
validate_certs: no
|
|
|
|
name: test_vm1
|
2019-07-08 04:24:54 +02:00
|
|
|
|
|
|
|
- name: gather network adapters' facts of the virtual machine
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-10 15:31:23 +02:00
|
|
|
name: test_vm1
|
2019-08-26 20:45:34 +02:00
|
|
|
gather_network_info: true
|
|
|
|
register: netadapter_info
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-08-26 20:45:34 +02:00
|
|
|
- debug: var=netadapter_info
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: get number of existing netowrk adapters
|
|
|
|
set_fact:
|
2019-08-26 20:45:34 +02:00
|
|
|
netadapter_num: "{{ netadapter_info.network_data | length }}"
|
2019-07-08 04:24:54 +02:00
|
|
|
|
|
|
|
- name: add new network adapters to virtual machine
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-10 15:31:23 +02:00
|
|
|
name: test_vm1
|
2019-07-08 04:24:54 +02:00
|
|
|
networks:
|
|
|
|
- name: "VM Network"
|
|
|
|
state: new
|
|
|
|
device_type: e1000e
|
2019-10-10 15:31:23 +02:00
|
|
|
manual_mac: "aa:50:56:58:59:60"
|
2019-10-17 08:53:13 +02:00
|
|
|
connected: True
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: "VM Network"
|
|
|
|
state: new
|
2019-10-17 08:53:13 +02:00
|
|
|
connected: True
|
2019-07-08 04:24:54 +02:00
|
|
|
device_type: vmxnet3
|
2019-10-10 15:31:23 +02:00
|
|
|
manual_mac: "aa:50:56:58:59:61"
|
2019-07-08 04:24:54 +02:00
|
|
|
register: add_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- debug: var=add_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: assert the new netowrk adapters were added to VM
|
|
|
|
assert:
|
|
|
|
that:
|
2019-10-17 08:53:13 +02:00
|
|
|
- add_netadapter is changed
|
2019-07-08 04:24:54 +02:00
|
|
|
- "{{ add_netadapter.network_data | length | int }} == {{ netadapter_num | int + 2 }}"
|
|
|
|
|
|
|
|
- name: delete one specified network adapter
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-10 15:31:23 +02:00
|
|
|
name: test_vm1
|
2019-07-08 04:24:54 +02:00
|
|
|
networks:
|
|
|
|
- state: absent
|
2019-10-10 15:31:23 +02:00
|
|
|
mac: "aa:50:56:58:59:60"
|
2019-07-08 04:24:54 +02:00
|
|
|
register: del_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- debug: var=del_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: assert the network adapter was removed
|
|
|
|
assert:
|
|
|
|
that:
|
2019-10-17 08:53:13 +02:00
|
|
|
- del_netadapter is changed
|
2019-07-08 04:24:54 +02:00
|
|
|
- "{{ del_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
|
|
|
|
|
2019-10-17 08:53:13 +02:00
|
|
|
- name: get instance uuid of virtual machines
|
|
|
|
vmware_guest_info:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-17 22:47:03 +02:00
|
|
|
name: test_vm1
|
2019-10-17 08:53:13 +02:00
|
|
|
datacenter: '{{ dc1 }}'
|
|
|
|
register: guest_info
|
|
|
|
|
|
|
|
- set_fact: vm1_instance_uuid="{{ guest_info['instance']['instance_uuid'] }}"
|
|
|
|
|
|
|
|
- name: add new network adapters to virtual machine with instance uuid
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-17 22:47:03 +02:00
|
|
|
uuid: '{{ vm1_instance_uuid }}'
|
2019-10-17 08:53:13 +02:00
|
|
|
use_instance_uuid: True
|
|
|
|
networks:
|
|
|
|
- name: "VM Network"
|
|
|
|
state: new
|
|
|
|
connected: True
|
|
|
|
device_type: e1000e
|
2019-10-17 22:47:03 +02:00
|
|
|
manual_mac: "bb:50:56:58:59:60"
|
2019-10-17 08:53:13 +02:00
|
|
|
register: add_netadapter_instanceuuid
|
|
|
|
|
|
|
|
- debug: var=add_netadapter_instanceuuid
|
|
|
|
|
|
|
|
- name: assert the new netowrk adapters were added to VM
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_netadapter_instanceuuid is changed
|
|
|
|
- "{{ add_netadapter_instanceuuid.network_data | length | int }} == {{ netadapter_num | int + 2 }}"
|
|
|
|
|
|
|
|
- name: delete again one specified network adapter
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-17 22:47:03 +02:00
|
|
|
name: test_vm1
|
2019-10-17 08:53:13 +02:00
|
|
|
networks:
|
|
|
|
- state: absent
|
2019-10-17 22:47:03 +02:00
|
|
|
mac: "bb:50:56:58:59:60"
|
2019-10-17 08:53:13 +02:00
|
|
|
register: del_again_netadapter
|
|
|
|
|
|
|
|
- debug: var=del_again_netadapter
|
|
|
|
|
|
|
|
- name: assert the network adapter was removed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- del_again_netadapter is changed
|
|
|
|
- "{{ del_again_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
|
|
|
|
|
2019-10-17 09:40:10 +02:00
|
|
|
- name: disable DirectPath I/O on a Vmxnet3 adapter
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-29 07:43:10 +01:00
|
|
|
name: "test_vm1"
|
2019-10-17 09:40:10 +02:00
|
|
|
networks:
|
|
|
|
- state: present
|
2019-10-29 07:43:10 +01:00
|
|
|
mac: "aa:50:56:58:59:61"
|
2019-10-17 10:50:38 +02:00
|
|
|
directpath_io: False
|
2019-10-17 09:40:10 +02:00
|
|
|
register: disable_directpath_io
|
|
|
|
|
|
|
|
- debug: var=disable_directpath_io
|
|
|
|
|
2019-10-17 10:50:38 +02:00
|
|
|
- name: enable DirectPath I/O on a Vmxnet3 adapter
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-29 07:43:10 +01:00
|
|
|
name: "test_vm1"
|
2019-10-17 10:50:38 +02:00
|
|
|
networks:
|
|
|
|
- state: present
|
2019-10-29 07:43:10 +01:00
|
|
|
mac: "aa:50:56:58:59:61"
|
2019-10-17 10:50:38 +02:00
|
|
|
directpath_io: True
|
|
|
|
register: enable_directpath_io
|
|
|
|
|
|
|
|
- debug: var=enable_directpath_io
|
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: disconnect one specified network adapter
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-10 15:31:23 +02:00
|
|
|
name: test_vm1
|
2019-07-08 04:24:54 +02:00
|
|
|
networks:
|
|
|
|
- state: present
|
2019-10-10 15:31:23 +02:00
|
|
|
mac: "aa:50:56:58:59:61"
|
2019-07-08 04:24:54 +02:00
|
|
|
connected: false
|
|
|
|
register: disc_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- debug: var=disc_netadapter
|
2019-07-12 07:52:06 +02:00
|
|
|
|
2019-07-08 04:24:54 +02:00
|
|
|
- name: assert the network adapter was disconnected
|
|
|
|
assert:
|
|
|
|
that:
|
2019-10-17 08:53:13 +02:00
|
|
|
- disc_netadapter is changed
|
2019-07-08 04:24:54 +02:00
|
|
|
- "{{ disc_netadapter.network_data[netadapter_num]['connected'] }} == false"
|
2019-07-12 07:52:06 +02:00
|
|
|
|
|
|
|
- name: Check if network does not exists
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-10-10 15:31:23 +02:00
|
|
|
name: test_vm1
|
2019-07-12 07:52:06 +02:00
|
|
|
networks:
|
|
|
|
- name: non-existing-nw
|
2019-10-10 15:31:23 +02:00
|
|
|
manual_mac: "aa:50:56:11:22:33"
|
2019-07-12 07:52:06 +02:00
|
|
|
state: new
|
|
|
|
register: no_nw_details
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- debug: var=no_nw_details
|
|
|
|
|
|
|
|
- name: Check if network does not exists
|
|
|
|
assert:
|
|
|
|
that:
|
2019-10-17 08:53:13 +02:00
|
|
|
- not (no_nw_details is changed)
|
2019-07-12 07:52:06 +02:00
|
|
|
- no_nw_details.failed
|
2020-01-15 17:26:19 +01:00
|
|
|
|
|
|
|
- name: Change portgroup to dvPortgroup
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
name: test_vm1
|
|
|
|
networks:
|
|
|
|
- name: "{{ dvpg1 }}"
|
|
|
|
label: "Network adapter 1"
|
|
|
|
connected: false
|
|
|
|
start_connected: true
|
|
|
|
state: present
|
|
|
|
register: change_netaddr_dvp
|
|
|
|
|
|
|
|
- debug: var=change_netaddr_dvp
|
|
|
|
|
|
|
|
- name: Check changed to dvPortgroup from PortGroup
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- change_netaddr_dvp.changed is sameas true
|
|
|
|
|
|
|
|
- name: Change portgroup to dvPortgroup
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
name: test_vm1
|
|
|
|
networks:
|
|
|
|
- name: "{{ dvpg1 }}"
|
|
|
|
label: "Network adapter 1"
|
|
|
|
connected: false
|
|
|
|
start_connected: true
|
|
|
|
state: present
|
|
|
|
register: change_netaddr_dvp
|
|
|
|
|
|
|
|
- debug: var=change_netaddr_dvp
|
|
|
|
|
|
|
|
- name: Check not changed of dvPortgroup
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- change_netaddr_dvp.changed is sameas false
|
|
|
|
|
|
|
|
- name: Change dvPortgroup to PortGroup
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
name: test_vm1
|
|
|
|
networks:
|
|
|
|
- name: "VM Network"
|
|
|
|
label: "Network adapter 1"
|
|
|
|
connected: false
|
|
|
|
start_connected: true
|
|
|
|
state: present
|
|
|
|
register: change_netaddr_pg
|
|
|
|
|
|
|
|
- debug: var=change_netaddr_pg
|
|
|
|
|
|
|
|
- name: Check changed to dvPortgroup from PortGroup
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- change_netaddr_pg.changed is sameas true
|
|
|
|
- change_netaddr_pg.network_data['0'].name == "VM Network"
|
|
|
|
|
|
|
|
- name: Change dvPortgroup to PortGroup
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
name: test_vm1
|
|
|
|
networks:
|
|
|
|
- name: "VM Network"
|
|
|
|
label: "Network adapter 1"
|
|
|
|
connected: false
|
|
|
|
start_connected: true
|
|
|
|
state: present
|
|
|
|
register: change_netaddr_pg
|
|
|
|
|
|
|
|
- debug: var=change_netaddr_pg
|
|
|
|
|
|
|
|
- name: Check not changed of PortGroup
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- change_netaddr_pg.changed is sameas false
|
|
|
|
- change_netaddr_pg.network_data['0'].name == "VM Network"
|
|
|
|
|
|
|
|
# https://github.com/ansible/ansible/issues/65968
|
|
|
|
- name: Create a network with dvPortgroup
|
|
|
|
vmware_guest_network:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
name: test_vm1
|
|
|
|
networks:
|
|
|
|
- name: "{{ dvpg1 }}"
|
|
|
|
label: "Network adapter 2"
|
|
|
|
connected: true
|
|
|
|
start_connected: true
|
|
|
|
state: new
|
|
|
|
register: create_netaddr_pg
|
|
|
|
|
|
|
|
- debug: var=create_netaddr_pg
|
|
|
|
|
|
|
|
- name: Check if network is created with dvpg
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- create_netaddr_pg.changed is sameas true
|