diff --git a/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup_facts.py b/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup_facts.py index 72620eebc3..b5c55974d6 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup_facts.py @@ -204,27 +204,32 @@ class DVSPortgroupFactsManager(PyVmomi): mac_changes=dvs_pg.config.defaultPortConfig.securityPolicy.macChanges.value ) if self.module.params['show_teaming_policy']: - teaming_policy = dict( - policy=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.policy.value, - inbound_policy=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.reversePolicy.value, - notify_switches=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.notifySwitches.value, - rolling_order=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.rollingOrder.value, - ) + # govcsim does not have uplinkTeamingPolicy, remove this check once + # PR https://github.com/vmware/govmomi/pull/1524 merged. + if dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy: + teaming_policy = dict( + policy=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.policy.value, + inbound_policy=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.reversePolicy.value, + notify_switches=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.notifySwitches.value, + rolling_order=dvs_pg.config.defaultPortConfig.uplinkTeamingPolicy.rollingOrder.value, + ) if self.params['show_port_policy']: - port_policy = dict( - block_override=dvs_pg.config.policy.blockOverrideAllowed, - ipfix_override=dvs_pg.config.policy.ipfixOverrideAllowed, - live_port_move=dvs_pg.config.policy.livePortMovingAllowed, - network_rp_override=dvs_pg.config.policy.networkResourcePoolOverrideAllowed, - port_config_reset_at_disconnect=dvs_pg.config.policy.portConfigResetAtDisconnect, - security_override=dvs_pg.config.policy.securityPolicyOverrideAllowed, - shaping_override=dvs_pg.config.policy.shapingOverrideAllowed, - traffic_filter_override=dvs_pg.config.policy.trafficFilterOverrideAllowed, - uplink_teaming_override=dvs_pg.config.policy.uplinkTeamingOverrideAllowed, - vendor_config_override=dvs_pg.config.policy.vendorConfigOverrideAllowed, - vlan_override=dvs_pg.config.policy.vlanOverrideAllowed - ) + # govcsim does not have port policy + if dvs_pg.config.policy: + port_policy = dict( + block_override=dvs_pg.config.policy.blockOverrideAllowed, + ipfix_override=dvs_pg.config.policy.ipfixOverrideAllowed, + live_port_move=dvs_pg.config.policy.livePortMovingAllowed, + network_rp_override=dvs_pg.config.policy.networkResourcePoolOverrideAllowed, + port_config_reset_at_disconnect=dvs_pg.config.policy.portConfigResetAtDisconnect, + security_override=dvs_pg.config.policy.securityPolicyOverrideAllowed, + shaping_override=dvs_pg.config.policy.shapingOverrideAllowed, + traffic_filter_override=dvs_pg.config.policy.trafficFilterOverrideAllowed, + uplink_teaming_override=dvs_pg.config.policy.uplinkTeamingOverrideAllowed, + vendor_config_override=dvs_pg.config.policy.vendorConfigOverrideAllowed, + vlan_override=dvs_pg.config.policy.vlanOverrideAllowed + ) if self.params['show_vlan_info']: vlan_info = self.get_vlan_info(dvs_pg.config.defaultPortConfig.vlan) diff --git a/test/integration/targets/vmware_dvs_portgroup_facts/tasks/main.yml b/test/integration/targets/vmware_dvs_portgroup_facts/tasks/main.yml index 4144bd7801..6ec52b31dd 100644 --- a/test/integration/targets/vmware_dvs_portgroup_facts/tasks/main.yml +++ b/test/integration/targets/vmware_dvs_portgroup_facts/tasks/main.yml @@ -34,3 +34,21 @@ - assert: that: - dvs_results.dvs_portgroup_facts is defined + +# Testcase 0002: Get portgroup facts for a given dvswitch +- name: get facts for a given dvswitch + vmware_dvs_portgroup_facts: + validate_certs: False + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + datacenter: "{{ dc1 }}" + dvswitch: "{{ dvswitch1 }}" + register: dvs_results_0002 + +- debug: + msg: "{{ dvs_results_0002 }}" + +- assert: + that: + - "dvs_results_0002['dvs_portgroup_facts']['DVS0'] is defined"