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

nxos_lacp: updated tests to handle platforms not supporting lacp system mac command #64074

Merged
merged 3 commits into from Nov 10, 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
5 changes: 4 additions & 1 deletion lib/ansible/module_utils/network/common/utils.py
Expand Up @@ -260,7 +260,10 @@ def dict_diff(base, comparable):
if not isinstance(base, dict):
raise AssertionError("`base` must be of type <dict>")
if not isinstance(comparable, dict):
raise AssertionError("`comparable` must be of type <dict>")
if comparable is None:
comparable = dict()
else:
raise AssertionError("`comparable` must be of type <dict>")

updates = dict()

Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/module_utils/network/nxos/config/lacp/lacp.py
Expand Up @@ -130,9 +130,11 @@ def _state_replaced(self, want, have):
del diff[k]
deleted_commands = self.del_all(diff)
merged_commands = self._state_merged(want, have)

commands.extend(deleted_commands)
if merged_commands:
commands.extend(deleted_commands)
commands.extend(merged_commands)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

        commands.extend(deleted_commands)
        if merged_commands:
            commands.extend(merged_commands)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you caught my laziness. will change

return commands

def _state_merged(self, want, have):
Expand Down
18 changes: 18 additions & 0 deletions test/integration/targets/nxos_lacp/tests/cli/deleted.yaml
Expand Up @@ -6,11 +6,19 @@
nxos_feature:
feature: lacp

- set_fact:
mac: "lacp system-mac 00c1.4c00.bd15 role primary"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- block:
- name: Setup
cli_config:
config: lacp system-priority 11

- name: Setup
cli_config:
config: "{{ mac|default(omit) }}"

- name: Gather lacp facts
nxos_facts: &facts
gather_subset:
Expand All @@ -29,6 +37,16 @@
- "'no lacp system-priority' in result.commands"
- "result.changed == true"
- "result.commands|length == 1"
when: platform is not search('N9K')

- assert:
that:
- "ansible_facts.network_resources.lacp == result.before"
- "'no lacp system-priority' in result.commands"
- "'no lacp system-mac' in result.commands"
- "result.changed == true"
- "result.commands|length == 2"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- name: Gather lacp post facts
nxos_facts: *facts
Expand Down
17 changes: 17 additions & 0 deletions test/integration/targets/nxos_lacp/tests/cli/merged.yaml
Expand Up @@ -6,21 +6,38 @@
nxos_feature:
feature: lacp

- set_fact:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the following failure running the merged test from your nxos_lacp PR on the following release images (camden, dplus, evergreen and freeport)

These older release images likey do not have support for this command.

Fails in:

camden (I2)
dplus (I4)
evergreen (I5)
freeport (I6)

I suggest you do the following:

  1. Check to see if priority works on these older releases and still test that but omit mac.
  2. If neither property is supported, you can skip the tests for tag (I2 – I6)
TASK [nxos_lacp : Merged] ************************************************************************************************************************************************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_lacp/tests/cli/merged.yaml:16
<camden-n9k.example.com.cisco.com> attempting to start connection
<camden-n9k.example.com.cisco.com> using connection plugin network_cli
Found ansible-connection at path /root/agents-ci/ansible/bin/ansible-connection
<camden-n9k.example.com.cisco.com> found existing local domain socket, using it!
<camden-n9k.example.com.cisco.com> updating play_context for connection
<camden-n9k.example.com.cisco.com> 
<camden-n9k.example.com.cisco.com> local domain socket path is /root/.ansible/pc/0355643899
<camden-n9k.example.com.cisco.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<camden-n9k.example.com.cisco.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944 `" && echo ansible-tmp-1572449641.13-1032907249944="` echo /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944 `" ) && sleep 0'
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_lacp.py
<camden-n9k.example.com.cisco.com> PUT /root/.ansible/tmp/ansible-local-10715130OGa/tmpRge0Xc TO /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py
<camden-n9k.example.com.cisco.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/ /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py && sleep 0'
<camden-n9k.example.com.cisco.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py && sleep 0'
<camden-n9k.example.com.cisco.com> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py", line 102, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.network.nxos.nxos_lacp', init_globals=None, run_name='__main__', alter_sys=False)
  File "/usr/lib/python2.7/runpy.py", line 192, in run_module
    fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/modules/network/nxos/nxos_lacp.py", line 188, in <module>
  File "/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/modules/network/nxos/nxos_lacp.py", line 183, in main
  File "/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/module_utils/network/nxos/config/lacp/lacp.py", line 69, in execute_module
  File "/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/module_utils/connection.py", line 187, in __rpc__
ansible.module_utils.connection.ConnectionError: lacp system-mac 00c1.4c00.bd15 role primary
                                 ^
% Invalid command at '^' marker.
camden-n9k.example.com(config)# 

fatal: [camden-n9k.example.com.cisco.com]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-local-10715130OGa/ansible-tmp-1572449641.13-1032907249944/AnsiballZ_nxos_lacp.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.network.nxos.nxos_lacp', init_globals=None, run_name='__main__', alter_sys=False)\n  File \"/usr/lib/python2.7/runpy.py\", line 192, in run_module\n    fname, loader, pkg_name)\n  File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/modules/network/nxos/nxos_lacp.py\", line 188, in <module>\n  File \"/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/modules/network/nxos/nxos_lacp.py\", line 183, in main\n  File \"/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/module_utils/network/nxos/config/lacp/lacp.py\", line 69, in execute_module\n  File \"/tmp/ansible_nxos_lacp_payload_xO14YU/ansible_nxos_lacp_payload.zip/ansible/module_utils/connection.py\", line 187, in __rpc__\nansible.module_utils.connection.ConnectionError: lacp system-mac 00c1.4c00.bd15 role primary\r\r\n                                 ^\r\n% Invalid command at '^' marker.\r\n\rcamden-n9k.example.com(config)# \n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

mac:
address: 00c1.4c00.bd15
role: primary
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- block:
- name: Merged
nxos_lacp: &merged
config:
system:
priority: 11
mac: "{{ mac|default(omit) }}"
state: merged
register: result

- assert:
that:
- "result.before|length == 0"
- "result.changed == true"
- "'lacp system-priority 11' in result.commands"
- "'lacp system-mac 00c1.4c00.bd15 role primary' in result.commands"
- "result.commands|length == 2"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- assert:
that:
- "result.before|length == 0"
- "result.changed == true"
- "'lacp system-priority 11' in result.commands"
- "result.commands|length == 1"
when: platform is not search('N9K')

- name: Gather lacp facts
nxos_facts:
Expand Down
57 changes: 51 additions & 6 deletions test/integration/targets/nxos_lacp/tests/cli/replaced.yaml
@@ -1,16 +1,31 @@
---

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add a few more tests on platforms that support both properties to be complete.

  1. Configure both properties (replace them both with new values)
  2. Configure mac only (playbook specifies no values so mac gets removed)

- debug:
msg: "Start nxos_lacp replaced integration tests connection={{ ansible_connection }}"

- name: Enable lacp feature
nxos_feature:
feature: lacp

- set_fact:
mac1: "lacp system-mac 00c1.4c00.bd20 role primary"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- set_fact:
mac2:
address: 00c1.4c00.bd15
role: secondary
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- block:
- name: Setup
- name: Setup1
cli_config:
config: lacp system-priority 11

- name: Setup2
cli_config:
config: "{{ mac1|default(omit) }}"

- name: Gather lacp facts
nxos_facts: &facts
gather_subset:
Expand All @@ -22,26 +37,38 @@
nxos_lacp: &replaced
config:
system:
mac:
address: 00c1.4c00.bd15
role: primary
priority: 12
mac: "{{ mac2|default(omit) }}"
state: replaced
register: result

- assert:
that:
- "ansible_facts.network_resources.lacp == result.before"
- "result.changed == true"
- "'no lacp system-priority' in result.commands"
- "'lacp system-mac 00c1.4c00.bd15 role primary' in result.commands"
- "result.commands|length == 2"
- "'no lacp system-priority' in result.commands"
- "'lacp system-priority 12' in result.commands"
when: platform is not search('N9K')

- assert:
that:
- "ansible_facts.network_resources.lacp == result.before"
- "result.changed == true"
- "'no lacp system-priority' in result.commands"
- "'no lacp system-mac' in result.commands"
- "'lacp system-priority 12' in result.commands"
- "'lacp system-mac 00c1.4c00.bd15 role secondary' in result.commands"
- "result.commands|length == 4"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- name: Gather lacp interfaces post facts
nxos_facts: *facts

- assert:
that:
- "ansible_facts.network_resources.lacp == result.after"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- name: Idempotence - Replaced
nxos_lacp: *replaced
Expand All @@ -52,6 +79,24 @@
- "result.changed == false"
- "result.commands|length == 0"

- name: Setup3
cli_config:
config: "{{ mac1|default(omit) }}"

- name: Replaced
nxos_lacp:
state: replaced
register: result
when: platform is search('N9K') and imagetag is not search('I[2-6]')

- assert:
that:
- "result.changed == true"
- "result.commands|length == 2"
- "'no lacp system-mac' in result.commands"
- "'no lacp system-priority' in result.commands"
when: platform is search('N9K') and imagetag is not search('I[2-6]')

always:
- name: teardown
nxos_feature:
Expand Down
1 change: 0 additions & 1 deletion test/integration/targets/prepare_nxos_tests/tasks/main.yml
Expand Up @@ -31,7 +31,6 @@
- name: "Collect interface list"
nxos_command:
commands: ['show interface brief | json']
timeout: 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already addressed by: #63963

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, thx

connection: network_cli
register: intout

Expand Down