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

iosxr_lacp: Update argspec to normalize across platforms #59596

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ansible/module_utils/network/iosxr/argspec/lacp/lacp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def __init__(self, **kwargs):
'system': {
'options': {
'mac': {
'type': 'str'
'type': 'dict',
'options': {
'address': {
'type': 'str'
}
}
},
'priority': {
'type': 'int'
Expand Down
11 changes: 6 additions & 5 deletions lib/ansible/module_utils/network/iosxr/config/lacp/lacp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from ansible.module_utils.network.iosxr.facts.facts import Facts
from ansible.module_utils.network.common.utils import dict_diff
from ansible.module_utils.six import iteritems
from ansible.module_utils.network.common import utils
from ansible.module_utils.network.common.utils import remove_empties
from ansible.module_utils.network.iosxr. \
utils.utils import flatten_dict


class Lacp(ConfigBase):
Expand Down Expand Up @@ -147,9 +149,8 @@ def _state_merged(want, have):

updates = dict_diff(have, want)
if updates:
for key, value in iteritems(updates['system']):
if value:
commands.append('lacp system {0} {1}'.format(key, value))
for key, value in iteritems(flatten_dict(remove_empties(updates['system']))):
commands.append('lacp system {0} {1}'.format(key.replace('address', 'mac'), value))

return commands

Expand All @@ -163,7 +164,7 @@ def _state_deleted(want, have):
"""
commands = []

for x in [k for k in have.get('system', {}) if k not in utils.remove_empties(want.get('system', {}))]:
for x in [k for k in have.get('system', {}) if k not in remove_empties(want.get('system', {}))]:
commands.append('no lacp system {0}'.format(x))

return commands
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/network/iosxr/facts/lacp/lacp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ def render_config(self, spec, conf):

system_priority = utils.parse_conf_arg(conf, 'priority')
config['system']['priority'] = int(system_priority) if system_priority else system_priority
config['system']['mac'] = utils.parse_conf_arg(conf, 'mac')
config['system']['mac']['address'] = utils.parse_conf_arg(conf, 'mac')

return config
Empty file.
32 changes: 32 additions & 0 deletions lib/ansible/module_utils/network/iosxr/utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# utils

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.six import iteritems


def search_obj_in_list(name, lst, key='name'):
for item in lst:
if item[key] == name:
return item
return None


def flatten_dict(x):
result = {}
if not isinstance(x, dict):
return result

for key, value in iteritems(x):
if isinstance(value, dict):
result.update(flatten_dict(value))
else:
result[key] = value

return result
24 changes: 18 additions & 6 deletions lib/ansible/modules/network/iosxr/iosxr_lacp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@
- Refer to vendor documentation for valid values.
type: int
mac:
type: dict
description:
- The system ID to use in LACP negotiations.
type: str
- The system MAC related configuration for LACP.
suboptions:
address:
description:
- The system ID to use in LACP negotiations.
type: str
state:
description:
- The state the configuration should be left in.
Expand Down Expand Up @@ -92,7 +97,8 @@
config:
system:
priority: 10
mac: 00c1.4c00.bd15
mac:
address: 00c1.4c00.bd15
state: merged

#
Expand All @@ -112,7 +118,9 @@
#
# "after": {
# "system": {
# "mac": "00c1.4c00.bd15",
# "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 10
# }
# }
Expand Down Expand Up @@ -156,7 +164,9 @@
# -----------------------
# "before": {
# "system": {
# "mac": "00c1.4c00.bd15",
# "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 10
# }
# }
Expand Down Expand Up @@ -211,7 +221,9 @@
# -----------------------
# "before": {
# "system": {
# "mac": "00c1.4c00.bd15",
# "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 11
# }
# }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/iosxr_lacp/tests/cli/deleted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- include_tasks: _populate.yaml

- block:
- name: Delete attributes of given interfaces
- name: Delete LACP attributes
iosxr_lacp: &deleted
state: deleted
register: result
Expand Down
3 changes: 2 additions & 1 deletion test/integration/targets/iosxr_lacp/tests/cli/merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
config:
system:
priority: 11
mac: 00c1.4c00.bd15
mac:
address: 00c1.4c00.bd15
state: merged
register: result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- include_tasks: _populate.yaml

- block:
- name: Replace device configurations of listed interfaces with provided configurations
- name: Replace LACP configuration with provided configurations
iosxr_lacp: &replaced
config:
system:
Expand Down
6 changes: 4 additions & 2 deletions test/integration/targets/iosxr_lacp/tests/cli/rtt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
config:
system:
priority: 15
mac: 00c1.4c00.bd16
mac:
address: 00c1.4c00.bd16
state: merged
register: base_config

Expand All @@ -27,7 +28,8 @@
config:
system:
priority: 10
mac: 00c1.4c00.bd10
mac:
address: 00c1.4c00.bd10
state: merged
register: result

Expand Down
9 changes: 6 additions & 3 deletions test/integration/targets/iosxr_lacp/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ merged:
after:
system:
priority: 11
mac: "00c1.4c00.bd15"
mac:
address: "00c1.4c00.bd15"

populate:
system:
priority: 12
mac: "00c1.4c00.bd16"
mac:
address: "00c1.4c00.bd16"

replaced:
commands:
Expand All @@ -36,5 +38,6 @@ round_trip:
after:
system:
priority: 10
mac: "00c1.4c00.bd10"
mac:
address: "00c1.4c00.bd10"