mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
Add Test Suite for vmware_vswitch (#26076)
Fix adds test suite for vwmare_switch Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
69e55b2cfe
commit
5c374cd1ae
5 changed files with 68 additions and 12 deletions
|
@ -91,10 +91,12 @@ try:
|
|||
HAS_PYVMOMI = True
|
||||
except ImportError:
|
||||
HAS_PYVMOMI = False
|
||||
from ansible.module_utils.vmware import vmware_argument_spec, get_all_objs, connect_to_api
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def find_vswitch_by_name(host, vswitch_name):
|
||||
for vss in host.config.network.vswitch:
|
||||
for vss in host.configManager.networkSystem.networkInfo.vswitch:
|
||||
if vss.name == vswitch_name:
|
||||
return vss
|
||||
return None
|
||||
|
@ -137,7 +139,6 @@ class VMwareHostVirtualSwitch(object):
|
|||
except Exception as e:
|
||||
self.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
# Source from
|
||||
# https://github.com/rreubenur/pyvmomi-community-samples/blob/patch-1/samples/create_vswitch.py
|
||||
|
||||
|
@ -180,7 +181,7 @@ class VMwareHostVirtualSwitch(object):
|
|||
if not host:
|
||||
self.module.fail_json(msg="Unable to find host")
|
||||
|
||||
self.host_system = host.keys()[0]
|
||||
self.host_system = list(host.keys())[0]
|
||||
self.vss = find_vswitch_by_name(self.host_system, self.switch_name)
|
||||
|
||||
if self.vss is None:
|
||||
|
@ -192,10 +193,10 @@ class VMwareHostVirtualSwitch(object):
|
|||
def main():
|
||||
argument_spec = vmware_argument_spec()
|
||||
argument_spec.update(dict(switch_name=dict(required=True, type='str'),
|
||||
nic_name=dict(required=False, type='str'),
|
||||
number_of_ports=dict(required=False, type='int', default=128),
|
||||
mtu=dict(required=False, type='int', default=1500),
|
||||
state=dict(default='present', choices=['present', 'absent'], type='str')))
|
||||
nic_name=dict(required=False, type='str'),
|
||||
number_of_ports=dict(required=False, type='int', default=128),
|
||||
mtu=dict(required=False, type='int', default=1500),
|
||||
state=dict(default='present', choices=['present', 'absent'], type='str')))
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
|
||||
|
||||
|
@ -205,8 +206,5 @@ def main():
|
|||
host_virtual_switch = VMwareHostVirtualSwitch(module)
|
||||
host_virtual_switch.process_state()
|
||||
|
||||
from ansible.module_utils.vmware import *
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue