Skip to content

Commit

Permalink
Require mask/cidr only on ipv4 (#880)
Browse files Browse the repository at this point in the history
fixes: #878
  • Loading branch information
mdellweg authored Jul 17, 2020
1 parent 30ada09 commit bc46d06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
7 changes: 4 additions & 3 deletions plugins/modules/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
required: true
type: str
cidr:
description: CIDR prefix length; Required if no mask provided
description: CIDR prefix length; Required if I(network_type=IPv4) and no I(mask) provided
type: int
mask:
description: Subnet netmask. Required if no cidr prefix length provided
description: Subnet netmask. Required if I(network_type=IPv4) and no I(cidr) prefix length provided
type: str
from_ip:
description: First IP address of the host IP allocation pool
Expand Down Expand Up @@ -226,7 +226,6 @@ def main():
vlanid=dict(type='int'),
mtu=dict(type='int'),
),
required_one_of=[['cidr', 'mask']],
required_plugins=[('discovery', ['discovery_proxy'])],
)

Expand All @@ -237,6 +236,8 @@ def main():

if not module.desired_absent:
if module_params['network_type'] == 'IPv4':
if 'mask' not in module_params and 'cidr' not in module_params:
module.fail_json(msg='When specifying IPv4 networks, either "mask" or "cidr" is required.')
IPNetwork = ipaddress.IPv4Network
else:
IPNetwork = ipaddress.IPv6Network
Expand Down
9 changes: 0 additions & 9 deletions tests/test_playbooks/subnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@
expected_change: true
- include: tasks/subnet.yml
vars:
subnet_mask: '255.255.255.224'
subnet_state: absent
expected_change: true
- include: tasks/subnet.yml
vars:
subnet_mask: '255.255.255.224'
subnet_state: absent
expected_change: false
- name: 'Test Subnet with minimal params (cidr)'
Expand All @@ -115,13 +113,11 @@
expected_change: false
- include: tasks/subnet.yml
vars:
subnet_cidr: 27
subnet_state: absent
expected_change: true
- include: tasks/subnet.yml
vars:
subnet_state: absent
subnet_cidr: 27
expected_change: false
- name: 'Test Subnet with proxies'
block:
Expand All @@ -145,13 +141,11 @@
expected_change: false
- include: tasks/subnet.yml
vars:
subnet_cidr: 27
subnet_state: absent
expected_change: true
- include: tasks/subnet.yml
vars:
subnet_state: absent
subnet_cidr: 27
expected_change: false
- name: 'Test Subnet name change'
block:
Expand All @@ -177,7 +171,6 @@
- include: tasks/subnet.yml
vars:
subnet_name: "My new test subnet"
subnet_mask: '255.255.255.224'
subnet_state: absent
expected_change: true
- name: 'Test Subnet with full params except smart proxies and cidr'
Expand Down Expand Up @@ -245,12 +238,10 @@
vars:
subnet_name: Test Subnet 2
subnet_state: absent
subnet_mask: '255.255.255.224'
expected_change: true
- include: tasks/subnet.yml
vars:
subnet_name: Test Subnet 2
subnet_mask: '255.255.255.224'
subnet_state: absent
expected_change: false

Expand Down

0 comments on commit bc46d06

Please sign in to comment.