Skip to content

Commit

Permalink
Backport PR ansible-collections#1337 to stable-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolenz committed Jun 6, 2022
1 parent 58c8e4b commit cccd235
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- vmware_host_vmnic_info - Fix a bug that crashes the module when a host is disconnected (https://github.com/ansible-collections/community.vmware/pull/1337).
17 changes: 10 additions & 7 deletions plugins/modules/vmware_host_vmnic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
'''

try:
from pyVmomi import vim
from pyVmomi import vim, vmodl
except ImportError:
pass

Expand Down Expand Up @@ -231,12 +231,15 @@ def gather_host_vmnic_info(self):
pnic_info['status'] = 'Connected'
pnic_info['actual_speed'] = pnic.linkSpeed.speedMb
pnic_info['actual_duplex'] = 'Full Duplex' if pnic.linkSpeed.duplex else 'Half Duplex'
network_hint = host_nw_system.QueryNetworkHint(pnic.device)
for hint in self.to_json(network_hint):
if hint.get('lldpInfo'):
pnic_info['lldp_info'] = {x['key']: x['value'] for x in hint['lldpInfo'].get('parameter')}
else:
pnic_info['lldp_info'] = 'N/A'
try:
network_hint = host_nw_system.QueryNetworkHint(pnic.device)
for hint in self.to_json(network_hint):
if hint.get('lldpInfo'):
pnic_info['lldp_info'] = {x['key']: x['value'] for x in hint['lldpInfo'].get('parameter')}
else:
pnic_info['lldp_info'] = 'N/A'
except (vmodl.fault.HostNotConnected, vmodl.fault.HostNotReachable):
pnic_info['lldp_info'] = 'N/A'
else:
pnic_info['status'] = 'Disconnected'
pnic_info['actual_speed'] = 'N/A'
Expand Down
120 changes: 87 additions & 33 deletions tests/integration/targets/vmware_host_vmnic_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,93 @@
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# TODO: vcsim does not support networkConfig related to operations
- when: vcsim is not defined
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true

- name: Gather vmnic info about a host
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
register: host_vmnics
- debug: var=host_vmnics
- assert:
that:
- host_vmnics.hosts_vmnics_info is defined

- name: Gather extended vmnic info about a host
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
capabilities: true
directpath_io: true
sriov: true
register: host_vmnics_extended
- debug: var=host_vmnics_extended
- assert:
that:
- host_vmnics_extended.hosts_vmnics_info is defined

- name: Get info from an ESXi host that is offline / disconnected / shut down
block:
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
- name: Disconnect ESXi host
community.vmware.vmware_host:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: '{{ dc1 }}'
cluster_name: '{{ ccr1 }}'
esxi_hostname: "{{ esxi1 }}"
state: disconnected

- name: Give the ESXi host time to disconnect
ansible.builtin.pause:
minutes: 1

- name: Gather vmnic info about a host
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
register: host_vmnics
- debug: var=host_vmnics
- assert:
that:
- host_vmnics.hosts_vmnics_info is defined
- name: Gather vmnic info about a host that is offline / disconnected / shut down
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
register: host_vmnics_disconnected
- debug: var=host_vmnics_disconnected
- assert:
that:
- host_vmnics_disconnected.hosts_vmnics_info is defined

- name: Gather extended vmnic info about a host
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
capabilities: true
directpath_io: true
sriov: true
register: host_vmnics_extended
- debug: var=host_vmnics_extended
- assert:
that:
- host_vmnics_extended.hosts_vmnics_info is defined
- name: Gather extended vmnic info about a host that is offline / disconnected / shut down
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
capabilities: true
directpath_io: true
sriov: true
register: host_vmnics_extended_disconnected
- debug: var=host_vmnics_extended_disconnected
- assert:
that:
- host_vmnics_extended_disconnected.hosts_vmnics_info is defined
always:
- name: Reconnect ESXi host
community.vmware.vmware_host:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: '{{ dc1 }}'
cluster_name: '{{ ccr1 }}'
esxi_hostname: "{{ esxi1 }}"
state: reconnect

0 comments on commit cccd235

Please sign in to comment.