Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require mask/cidr only on ipv4 #880

Merged
merged 4 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mdellweg marked this conversation as resolved.
Show resolved Hide resolved
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
mdellweg marked this conversation as resolved.
Show resolved Hide resolved
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('When specifying IPv4 networks, either "mask" or "cidr" is required.')
mdellweg marked this conversation as resolved.
Show resolved Hide resolved
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