mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
6.0 KiB
YAML
208 lines
6.0 KiB
YAML
# 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
|
|
|
|
- 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
|
|
datastore: '{{ ds2 }}'
|
|
hardware:
|
|
version: latest
|
|
memory_mb: 1024
|
|
num_cpus: 1
|
|
scsi: paravirtual
|
|
cdrom:
|
|
type: iso
|
|
iso_path: "[{{ ds1 }}] fedora.iso"
|
|
networks:
|
|
- name: VM Network
|
|
|
|
- vmware_guest_tools_wait:
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
validate_certs: no
|
|
name: test_vm1
|
|
|
|
- name: gather network adapters' facts of the virtual machine
|
|
vmware_guest_network:
|
|
validate_certs: False
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
name: test_vm1
|
|
gather_network_info: true
|
|
register: netadapter_info
|
|
|
|
- debug: var=netadapter_info
|
|
|
|
- name: get number of existing netowrk adapters
|
|
set_fact:
|
|
netadapter_num: "{{ netadapter_info.network_data | length }}"
|
|
|
|
- name: add new network adapters to virtual machine
|
|
vmware_guest_network:
|
|
validate_certs: False
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
name: test_vm1
|
|
networks:
|
|
- name: "VM Network"
|
|
state: new
|
|
device_type: e1000e
|
|
manual_mac: "aa:50:56:58:59:60"
|
|
connected: True
|
|
- name: "VM Network"
|
|
state: new
|
|
connected: True
|
|
device_type: vmxnet3
|
|
manual_mac: "aa:50:56:58:59:61"
|
|
register: add_netadapter
|
|
|
|
- debug: var=add_netadapter
|
|
|
|
- name: assert the new netowrk adapters were added to VM
|
|
assert:
|
|
that:
|
|
- add_netadapter is changed
|
|
- "{{ 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 }}"
|
|
name: test_vm1
|
|
networks:
|
|
- state: absent
|
|
mac: "aa:50:56:58:59:60"
|
|
register: del_netadapter
|
|
|
|
- debug: var=del_netadapter
|
|
|
|
- name: assert the network adapter was removed
|
|
assert:
|
|
that:
|
|
- del_netadapter is changed
|
|
- "{{ del_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
|
|
|
|
- name: get instance uuid of virtual machines
|
|
vmware_guest_info:
|
|
validate_certs: False
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
name: test_vm1
|
|
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 }}"
|
|
uuid: '{{ vm1_instance_uuid }}'
|
|
use_instance_uuid: True
|
|
networks:
|
|
- name: "VM Network"
|
|
state: new
|
|
connected: True
|
|
device_type: e1000e
|
|
manual_mac: "bb:50:56:58:59:60"
|
|
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 }}"
|
|
name: test_vm1
|
|
networks:
|
|
- state: absent
|
|
mac: "bb:50:56:58:59:60"
|
|
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 }}"
|
|
|
|
- name: disconnect one specified network adapter
|
|
vmware_guest_network:
|
|
validate_certs: False
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
name: test_vm1
|
|
networks:
|
|
- state: present
|
|
mac: "aa:50:56:58:59:61"
|
|
connected: false
|
|
register: disc_netadapter
|
|
|
|
- debug: var=disc_netadapter
|
|
|
|
- name: assert the network adapter was disconnected
|
|
assert:
|
|
that:
|
|
- disc_netadapter is changed
|
|
- "{{ disc_netadapter.network_data[netadapter_num]['connected'] }} == false"
|
|
|
|
- name: Check if network does not exists
|
|
vmware_guest_network:
|
|
validate_certs: False
|
|
hostname: "{{ vcenter_hostname }}"
|
|
username: "{{ vcenter_username }}"
|
|
password: "{{ vcenter_password }}"
|
|
name: test_vm1
|
|
networks:
|
|
- name: non-existing-nw
|
|
manual_mac: "aa:50:56:11:22:33"
|
|
state: new
|
|
register: no_nw_details
|
|
ignore_errors: yes
|
|
|
|
- debug: var=no_nw_details
|
|
|
|
- name: Check if network does not exists
|
|
assert:
|
|
that:
|
|
- not (no_nw_details is changed)
|
|
- no_nw_details.failed
|