From 56a0b988a963bd28a67d38ca5de5c2eccfd822b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Wed, 19 Jul 2017 14:00:05 -0400 Subject: [PATCH] nxos integration fix part 1 (#27069) * Assorted Python 3 fixes * Fix `testcase` definition in integration tests * Fix nxos_acl_interface * clean up nxapi after nxos_nxapi --- lib/ansible/module_utils/nxos.py | 2 +- lib/ansible/modules/network/nxos/nxos_acl_interface.py | 5 ++++- lib/ansible/plugins/action/nxos_config.py | 4 ++-- lib/ansible/plugins/action/nxos_template.py | 6 +++--- .../targets/nxos_command/tests/cli/lessthanorequal.yaml | 4 ++-- .../integration/targets/nxos_evpn_global/defaults/main.yaml | 2 ++ test/integration/targets/nxos_feature/defaults/main.yaml | 2 ++ test/integration/targets/nxos_interface/defaults/main.yaml | 2 ++ test/integration/targets/nxos_mtu/defaults/main.yaml | 2 ++ test/integration/targets/nxos_nxapi/tasks/cli.yaml | 6 ++++++ test/integration/targets/nxos_system/defaults/main.yaml | 2 ++ test/units/modules/network/nxos/test_nxos_acl_interface.py | 3 +-- 12 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 test/integration/targets/nxos_evpn_global/defaults/main.yaml create mode 100644 test/integration/targets/nxos_feature/defaults/main.yaml create mode 100644 test/integration/targets/nxos_interface/defaults/main.yaml create mode 100644 test/integration/targets/nxos_mtu/defaults/main.yaml create mode 100644 test/integration/targets/nxos_system/defaults/main.yaml diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 52974d03b4d..285f326f64e 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -27,7 +27,7 @@ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -import re + import collections from ansible.module_utils._text import to_text diff --git a/lib/ansible/modules/network/nxos/nxos_acl_interface.py b/lib/ansible/modules/network/nxos/nxos_acl_interface.py index df597c897bd..e50e64ee141 100644 --- a/lib/ansible/modules/network/nxos/nxos_acl_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_acl_interface.py @@ -88,7 +88,10 @@ from ansible.module_utils.basic import AnsibleModule def check_for_acl_int_present(module, name, intf, direction): # Need to Captitalize the interface name as the nxos # output has capitalization - command = ['show running-config aclmgr | section {0}'.format(intf.title())] + command = [{ + 'command': 'show running-config aclmgr | section {0}'.format(intf.title()), + 'output': 'text', + }] body = run_commands(module, command) if direction == 'ingress': diff --git a/lib/ansible/plugins/action/nxos_config.py b/lib/ansible/plugins/action/nxos_config.py index f3b0e995c4e..125c7779842 100644 --- a/lib/ansible/plugins/action/nxos_config.py +++ b/lib/ansible/plugins/action/nxos_config.py @@ -41,7 +41,7 @@ class ActionModule(_ActionModule): try: self._handle_template() except ValueError as exc: - return dict(failed=True, msg=exc.message) + return dict(failed=True, msg=str(exc)) result = super(ActionModule, self).run(tmp, task_vars) @@ -55,7 +55,7 @@ class ActionModule(_ActionModule): # strip out any keys that have two leading and two trailing # underscore characters - for key in result.keys(): + for key in list(result.keys()): if PRIVATE_KEYS_RE.match(key): del result[key] diff --git a/lib/ansible/plugins/action/nxos_template.py b/lib/ansible/plugins/action/nxos_template.py index cc24b0c21af..da0da20b2e8 100644 --- a/lib/ansible/plugins/action/nxos_template.py +++ b/lib/ansible/plugins/action/nxos_template.py @@ -22,9 +22,9 @@ __metaclass__ = type import os import time import glob -import urlparse from ansible.module_utils._text import to_text +from ansible.module_utils.six.moves.urllib.parse import urlsplit from ansible.plugins.action.nxos import ActionModule as _ActionModule @@ -35,7 +35,7 @@ class ActionModule(_ActionModule): try: self._handle_template() except (ValueError, AttributeError) as exc: - return dict(failed=True, msg=exc.message) + return dict(failed=True, msg=str(exc)) result = super(ActionModule, self).run(tmp, task_vars) @@ -72,7 +72,7 @@ class ActionModule(_ActionModule): working_path = self._get_working_path() - if os.path.isabs(src) or urlparse.urlsplit(src).scheme: + if os.path.isabs(src) or urlsplit(src).scheme: source = src else: source = self._loader.path_dwim_relative(working_path, 'templates', src) diff --git a/test/integration/targets/nxos_command/tests/cli/lessthanorequal.yaml b/test/integration/targets/nxos_command/tests/cli/lessthanorequal.yaml index 2576fc11bd5..b0b5f3faeb5 100644 --- a/test/integration/targets/nxos_command/tests/cli/lessthanorequal.yaml +++ b/test/integration/targets/nxos_command/tests/cli/lessthanorequal.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/lesstahnorequal.yaml" +- debug: msg="START cli/lessthanorequal.yaml" - name: test le operator nxos_command: @@ -29,4 +29,4 @@ that: - "result.changed == false" -- debug: msg="END cli/lesstahnorequal.yaml" +- debug: msg="END cli/lessthanorequal.yaml" diff --git a/test/integration/targets/nxos_evpn_global/defaults/main.yaml b/test/integration/targets/nxos_evpn_global/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_evpn_global/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_feature/defaults/main.yaml b/test/integration/targets/nxos_feature/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_feature/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_interface/defaults/main.yaml b/test/integration/targets/nxos_interface/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_interface/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_mtu/defaults/main.yaml b/test/integration/targets/nxos_mtu/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_mtu/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_nxapi/tasks/cli.yaml b/test/integration/targets/nxos_nxapi/tasks/cli.yaml index d675462dd02..0aaecf32868 100644 --- a/test/integration/targets/nxos_nxapi/tasks/cli.yaml +++ b/test/integration/targets/nxos_nxapi/tasks/cli.yaml @@ -13,3 +13,9 @@ with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: disable nxapi + nxos_config: + lines: + - no feature nxapi + provider: "{{ cli }}" diff --git a/test/integration/targets/nxos_system/defaults/main.yaml b/test/integration/targets/nxos_system/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_system/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/units/modules/network/nxos/test_nxos_acl_interface.py b/test/units/modules/network/nxos/test_nxos_acl_interface.py index f3db93f107c..c4dc3591d68 100644 --- a/test/units/modules/network/nxos/test_nxos_acl_interface.py +++ b/test/units/modules/network/nxos/test_nxos_acl_interface.py @@ -48,8 +48,7 @@ class TestNxosAclInterfaceModule(TestNxosModule): for item in commands: try: - obj = json.loads(item) - command = obj['command'] + command = item['command'] except ValueError: command = item filename = '%s.txt' % str(command).split(' | ')[0].replace(' ', '_')