summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Case <ncase@redhat.com>2019-10-18 10:36:30 -0400
committerGitHub <noreply@github.com>2019-10-18 10:36:30 -0400
commit741d529409a03c361efc78a418bc56c4dc5a52eb (patch)
tree524dc6a2eb033e2ec18856af847abda37c2fb8ff
parent4326165be56c1bc990d0e9eaef951227b0e94687 (diff)
downloadansible-741d529409a03c361efc78a418bc56c4dc5a52eb.tar.gz
Eos vlan override (#63639)
* Fix overridden & deleted in eos_vlans * Fix vlan creation in overridden * Right, Python 2.6
-rw-r--r--lib/ansible/module_utils/network/eos/config/vlans/vlans.py60
-rw-r--r--test/integration/targets/eos_vlans/tests/cli/deleted.yaml1
-rw-r--r--test/integration/targets/eos_vlans/tests/cli/overridden.yaml6
3 files changed, 39 insertions, 28 deletions
diff --git a/lib/ansible/module_utils/network/eos/config/vlans/vlans.py b/lib/ansible/module_utils/network/eos/config/vlans/vlans.py
index b62c85d315..f1402d2245 100644
--- a/lib/ansible/module_utils/network/eos/config/vlans/vlans.py
+++ b/lib/ansible/module_utils/network/eos/config/vlans/vlans.py
@@ -94,8 +94,8 @@ class Vlans(ConfigBase):
to the desired configuration
"""
state = self._module.params['state']
- want = param_list_to_dict(want, "vlan_id", False)
- have = param_list_to_dict(have, "vlan_id", False)
+ want = param_list_to_dict(want, "vlan_id", remove_key=False)
+ have = param_list_to_dict(have, "vlan_id", remove_key=False)
if state == 'overridden':
commands = self._state_overridden(want, have)
elif state == 'deleted':
@@ -115,16 +115,16 @@ class Vlans(ConfigBase):
to the desired configuration
"""
commands = []
- for key, desired in want.items():
- if key in have:
- extant = have[key]
+ for vlan_id, desired in want.items():
+ if vlan_id in have:
+ extant = have[vlan_id]
else:
- extant = dict(vlan_id=key)
+ extant = dict()
add_config = dict_diff(extant, desired)
del_config = dict_diff(desired, extant)
- commands.extend(generate_commands(key, add_config, del_config))
+ commands.extend(generate_commands(vlan_id, add_config, del_config))
return commands
@@ -137,16 +137,25 @@ class Vlans(ConfigBase):
to the desired configuration
"""
commands = []
- for key, extant in have.items():
- if key in want:
- desired = want[key]
+ for vlan_id, extant in have.items():
+ if vlan_id in want:
+ desired = want[vlan_id]
else:
- desired = dict(vlan_id=key)
+ desired = dict()
add_config = dict_diff(extant, desired)
del_config = dict_diff(desired, extant)
- commands.extend(generate_commands(key, add_config, del_config))
+ commands.extend(generate_commands(vlan_id, add_config, del_config))
+
+ # Handle vlans not already in config
+ new_vlans = [vlan_id for vlan_id in want if vlan_id not in have]
+ for vlan_id in new_vlans:
+ desired = want[vlan_id]
+ extant = dict(vlan_id=vlan_id)
+ add_config = dict_diff(extant, desired)
+
+ commands.extend(generate_commands(vlan_id, add_config, {}))
return commands
@@ -159,15 +168,15 @@ class Vlans(ConfigBase):
the current configuration
"""
commands = []
- for key, desired in want.items():
- if key in have:
- extant = have[key]
+ for vlan_id, desired in want.items():
+ if vlan_id in have:
+ extant = have[vlan_id]
else:
- extant = dict(vlan_id=key)
+ extant = dict()
add_config = dict_diff(extant, desired)
- commands.extend(generate_commands(key, add_config, {}))
+ commands.extend(generate_commands(vlan_id, add_config, {}))
return commands
@@ -180,29 +189,32 @@ class Vlans(ConfigBase):
of the provided objects
"""
commands = []
- for key in want.keys():
- desired = dict(vlan_id=key)
- if key in have:
- extant = have[key]
+ for vlan_id in want:
+ desired = dict()
+ if vlan_id in have:
+ extant = have[vlan_id]
else:
- extant = dict(vlan_id=key)
+ continue
del_config = dict_diff(desired, extant)
- commands.extend(generate_commands(key, {}, del_config))
+ commands.extend(generate_commands(vlan_id, {}, del_config))
return commands
def generate_commands(vlan_id, to_set, to_remove):
commands = []
+ if "vlan_id" in to_remove:
+ return ["no vlan {0}".format(vlan_id)]
+
for key, value in to_set.items():
if value is None:
continue
commands.append("{0} {1}".format(key, value))
- for key in to_remove.keys():
+ for key in to_remove:
commands.append("no {0}".format(key))
if commands:
diff --git a/test/integration/targets/eos_vlans/tests/cli/deleted.yaml b/test/integration/targets/eos_vlans/tests/cli/deleted.yaml
index 7abeda68be..6cd5130428 100644
--- a/test/integration/targets/eos_vlans/tests/cli/deleted.yaml
+++ b/test/integration/targets/eos_vlans/tests/cli/deleted.yaml
@@ -32,7 +32,6 @@
expected_config:
- vlan_id: 10
name: ten
- - vlan_id: 20
- assert:
that:
diff --git a/test/integration/targets/eos_vlans/tests/cli/overridden.yaml b/test/integration/targets/eos_vlans/tests/cli/overridden.yaml
index edd3511ae0..ea406b6b47 100644
--- a/test/integration/targets/eos_vlans/tests/cli/overridden.yaml
+++ b/test/integration/targets/eos_vlans/tests/cli/overridden.yaml
@@ -5,8 +5,8 @@
config:
- vlan_id: 20
state: suspend
- other_config:
- - vlan_id: 10
+ - vlan_id: 50
+ name: fifty
- eos_facts:
gather_network_resources: vlans
@@ -32,7 +32,7 @@
- "ansible_facts.network_resources.vlans|symmetric_difference(result.after) == []"
- set_fact:
- expected_config: "{{ config }} + {{ other_config }}"
+ expected_config: "{{ config }}"
- assert:
that: