From c2958df3a44669b9fd46ec85814c40e25a8ddc09 Mon Sep 17 00:00:00 2001 From: Anil Kumar Muraleedharan Date: Sat, 6 Apr 2019 07:20:29 +0530 Subject: [PATCH] Removing provider from facts, command and config (#54623) --- .../modules/network/cnos/cnos_command.py | 67 ++---------------- .../modules/network/cnos/cnos_config.py | 45 +----------- .../modules/network/cnos/cnos_facts.py | 70 +------------------ .../targets/cnos_command/README.md | 2 +- .../cnos_command/tests/cli/bad_operator.yaml | 1 - .../cnos_command/tests/cli/contains.yaml | 1 - .../cnos_command/tests/cli/invalid.yaml | 2 - .../cnos_command/tests/cli/output.yaml | 2 - .../cnos_command/tests/cli/timeout.yaml | 1 - .../targets/cnos_command/vars/main.yaml | 10 --- .../integration/targets/cnos_config/README.md | 13 ---- .../cnos_config/cnos_config_sample_hosts | 2 +- .../targets/cnos_config/tests/cli/backup.yaml | 5 +- .../targets/cnos_config/tests/cli/basic.yaml | 8 +-- .../cnos_config/tests/cli/defaults.yaml | 4 -- .../targets/cnos_config/vars/main.yml | 9 --- .../cnos_facts/tests/cli/default_facts.yaml | 5 -- .../targets/cnos_facts/vars/main.yml | 9 --- 18 files changed, 13 insertions(+), 243 deletions(-) delete mode 100644 test/integration/targets/cnos_command/vars/main.yaml delete mode 100644 test/integration/targets/cnos_config/vars/main.yml delete mode 100644 test/integration/targets/cnos_facts/vars/main.yml diff --git a/lib/ansible/modules/network/cnos/cnos_command.py b/lib/ansible/modules/network/cnos/cnos_command.py index 95a90ca2724..65b8c0d9585 100644 --- a/lib/ansible/modules/network/cnos/cnos_command.py +++ b/lib/ansible/modules/network/cnos/cnos_command.py @@ -37,54 +37,14 @@ description: argument that will cause the module to wait for a specific condition before returning or timing out if the condition is not met. options: - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote - device over the specified transport. The value of host is used as - the destination address for the transport. - required: true - port: - description: - - Specifies the port to use when building the connection to the remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. - timeout: - description: - - Specifies the timeout in seconds for communicating with the network device - for either connecting or sending commands. If the timeout is - exceeded before the operation is completed, the module will error. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not specified - in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. commands: version_added: "2.6" description: - - List of commands to send to the remote device over the - configured provider. The resulting output from the command - is returned. If the I(wait_for) argument is provided, the - module is not returned until the condition is satisfied or - the number of retires as expired. + - List of commands to send to the remote device. + The resulting output from the command is returned. + If the I(wait_for) argument is provided, the module is not + returned until the condition is satisfied or the number of + retires is expired. required: true wait_for: version_added: "2.6" @@ -124,17 +84,6 @@ options: """ EXAMPLES = """ -# Note: examples below use the following provider dict to handle -# transport and authentication to the node. ---- -vars: - cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 30 - --- - name: test contains operator cnos_command: @@ -144,7 +93,6 @@ vars: wait_for: - "result[0] contains 'Lenovo'" - "result[1] contains 'MemFree'" - provider: "{{ cli }}" register: result - assert: @@ -155,7 +103,6 @@ vars: - name: get output for single command cnos_command: commands: ['show version'] - provider: "{{ cli }}" register: result - assert: @@ -168,7 +115,6 @@ vars: commands: - show version - show interface information - provider: "{{ cli }}" register: result - assert: @@ -200,7 +146,6 @@ import time from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.cnos.cnos import run_commands, check_args -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.common.parsing import Conditional from ansible.module_utils.six import string_types @@ -224,8 +169,6 @@ def main(): interval=dict(default=1, type='int') ) - spec.update(cnos_argument_spec) - module = AnsibleModule(argument_spec=spec, supports_check_mode=True) result = {'changed': False} diff --git a/lib/ansible/modules/network/cnos/cnos_config.py b/lib/ansible/modules/network/cnos/cnos_config.py index e9db206bcda..5d52e8823b4 100644 --- a/lib/ansible/modules/network/cnos/cnos_config.py +++ b/lib/ansible/modules/network/cnos/cnos_config.py @@ -37,48 +37,8 @@ description: an implementation for working with CNOS configuration sections in a deterministic way. notes: - - Tested against CNOS 10.8.1 + - Tested against CNOS 10.9.1 options: - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote - device over the specified transport. The value of host is used as - the destination address for the transport. - required: true - port: - description: - - Specifies the port to use when building the connection to the remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. - timeout: - description: - - Specifies the timeout in seconds for communicating with the network device - for either connecting or sending commands. If the timeout is - exceeded before the operation is completed, the module will error. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not specified - in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. lines: description: - The ordered set of commands that should be configured in the @@ -231,7 +191,6 @@ backup_path: """ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.cnos.cnos import load_config, get_config -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.cnos.cnos import check_args from ansible.module_utils.network.common.config import NetworkConfig, dumps @@ -320,8 +279,6 @@ def main(): admin=dict(type='bool', default=False) ) - argument_spec.update(cnos_argument_spec) - mutually_exclusive = [('lines', 'src'), ('parents', 'src')] diff --git a/lib/ansible/modules/network/cnos/cnos_facts.py b/lib/ansible/modules/network/cnos/cnos_facts.py index aa2eba449c6..3f6f5e91882 100644 --- a/lib/ansible/modules/network/cnos/cnos_facts.py +++ b/lib/ansible/modules/network/cnos/cnos_facts.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# (C) 2017 Red Hat Inc. -# Copyright (C) 2017 Lenovo. +# (C) 2019 Red Hat Inc. +# Copyright (C) 2019 Lenovo. # # GNU General Public License v3.0+ # @@ -55,50 +55,6 @@ options: on the remote device. If I(authorize) is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable C(ANSIBLE_NET_AUTH_PASS) will be used instead. - provider: - version_added: "2.6" - description: - - A dict object containing connection details. - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote - device over the specified transport. The value of host is used as - the destination address for the transport. - required: true - port: - description: - - Specifies the port to use when building the connection to the - remote device. - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used - instead. - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used - instead. - timeout: - description: - - Specifies the timeout in seconds for communicating with the network - device for either connecting or sending commands. If the timeout - is exceeded before the operation is completed, the module will - error. - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not - specified in the task, the value of environment variable - C(ANSIBLE_NET_SSH_KEYFILE) will be used instead. gather_subset: version_added: "2.6" description: @@ -116,36 +72,21 @@ Tasks: The following are examples of using the module cnos_facts. --- - name: Test cnos Facts cnos_facts: - provider={{ cli }} - - vars: - cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - transport: cli - timeout: 30 - authorize: True - auth_pass: --- # Collect all facts from the device - cnos_facts: gather_subset: all - provider: "{{ cli }}" # Collect only the config and default facts - cnos_facts: gather_subset: - config - provider: "{{ cli }}" # Do not collect hardware facts - cnos_facts: gather_subset: - "!hardware" - provider: "{{ cli }}" ''' RETURN = ''' ansible_net_gather_subset: @@ -207,7 +148,6 @@ RETURN = ''' import re from ansible.module_utils.network.cnos.cnos import run_commands -from ansible.module_utils.network.cnos.cnos import cnos_argument_spec from ansible.module_utils.network.cnos.cnos import check_args from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule @@ -452,10 +392,6 @@ class Interfaces(FactsBase): if match: key = match.group(1) parsed.append(line) - # match = re.match(r'^(loopback+)', line) - # if match: - # key = match.group(1) - # parsed.append(line) return parsed def set_ip_interfaces(self, line4): @@ -545,8 +481,6 @@ def main(): gather_subset=dict(default=['!config'], type='list') ) - argument_spec.update(cnos_argument_spec) - module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) diff --git a/test/integration/targets/cnos_command/README.md b/test/integration/targets/cnos_command/README.md index 5195a59d130..19924738308 100644 --- a/test/integration/targets/cnos_command/README.md +++ b/test/integration/targets/cnos_command/README.md @@ -34,7 +34,7 @@ These are the various options the customer have in executing the cnos_command mo Variable | Description --- | --- -`commands` | List of commands to send to the remote device over the configured provider. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired. +`commands` | List of commands to send to the remote device. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired. `wait_for` | List of conditions to evaluate against the output of the command. The task will wait for each condition to be true before moving forward. If the conditional is not true within the configured number of retries, the task fails. See examples. `match` | The I(match) argument is used in conjunction with the I(wait_for) argument to specify the match policy. Valid values are C(all) or C(any). If the value is set to C(all) then all conditionals in the wait_for must be satisfied. If the value is set to C(any) then only one of the values must be satisfied. `retries` | Specifies the number of retries a command should by tried before it is considered failed. The command is run on the target device every retry and evaluated against the I(wait_for) conditions. diff --git a/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml b/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml index 79bba2b4f6f..0e885c4c21e 100644 --- a/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml +++ b/test/integration/targets/cnos_command/tests/cli/bad_operator.yaml @@ -8,7 +8,6 @@ - display interface brief wait_for: - result[0] contains 'Description: Foo' - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/tests/cli/contains.yaml b/test/integration/targets/cnos_command/tests/cli/contains.yaml index 78fbf0a9fb4..87a4035e721 100644 --- a/test/integration/targets/cnos_command/tests/cli/contains.yaml +++ b/test/integration/targets/cnos_command/tests/cli/contains.yaml @@ -9,7 +9,6 @@ wait_for: - "result[0] contains 'Lenovo'" - "result[1] contains 'Mem:'" - provider: "{{ cli }}" register: result - assert: diff --git a/test/integration/targets/cnos_command/tests/cli/invalid.yaml b/test/integration/targets/cnos_command/tests/cli/invalid.yaml index 017e6d6234d..f4df0c3f24d 100644 --- a/test/integration/targets/cnos_command/tests/cli/invalid.yaml +++ b/test/integration/targets/cnos_command/tests/cli/invalid.yaml @@ -4,7 +4,6 @@ - name: run invalid command cnos_command: commands: ['display foo'] - provider: "{{ cli }}" register: result ignore_errors: yes @@ -17,7 +16,6 @@ commands: - display version - display foo - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/tests/cli/output.yaml b/test/integration/targets/cnos_command/tests/cli/output.yaml index 4b262a98bc4..a9a328507ec 100644 --- a/test/integration/targets/cnos_command/tests/cli/output.yaml +++ b/test/integration/targets/cnos_command/tests/cli/output.yaml @@ -4,7 +4,6 @@ - name: get output for single command cnos_command: commands: ['display version'] - provider: "{{ cli }}" register: result - assert: @@ -17,7 +16,6 @@ commands: - display version - display interface brief - provider: "{{ cli }}" register: result - assert: diff --git a/test/integration/targets/cnos_command/tests/cli/timeout.yaml b/test/integration/targets/cnos_command/tests/cli/timeout.yaml index 5502ee8f1c4..54781db0ed3 100644 --- a/test/integration/targets/cnos_command/tests/cli/timeout.yaml +++ b/test/integration/targets/cnos_command/tests/cli/timeout.yaml @@ -7,7 +7,6 @@ - display version wait_for: - "result[0] contains bad_value_string" - provider: "{{ cli }}" register: result ignore_errors: yes diff --git a/test/integration/targets/cnos_command/vars/main.yaml b/test/integration/targets/cnos_command/vars/main.yaml deleted file mode 100644 index a5cf22b7986..00000000000 --- a/test/integration/targets/cnos_command/vars/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin -# transport: cli - timeout: 30 - authorize: True - auth_pass: diff --git a/test/integration/targets/cnos_config/README.md b/test/integration/targets/cnos_config/README.md index da5ab5d4b6b..e871c785e49 100644 --- a/test/integration/targets/cnos_config/README.md +++ b/test/integration/targets/cnos_config/README.md @@ -47,19 +47,6 @@ Variable | Description `admin` | Enters into administration configuration mode for making config changes to the device. -Need to specify these variables in vars/main.yml under variable `cli` - -Variable | Description ---- | --- -`host` | Has to be "{{ inventory_hostname }}" -`port` | Has to be`22` -`username` | User Name of switch -`password` | Password of switch -`timeout` | time out value for CLI -`authorixe` | Whether u have to enter enable mode for data collection. -`auth_pass`| Enable Password if required - - ## Dependencies --- diff --git a/test/integration/targets/cnos_config/cnos_config_sample_hosts b/test/integration/targets/cnos_config/cnos_config_sample_hosts index 4e61a815810..aa860b3cf65 100644 --- a/test/integration/targets/cnos_config/cnos_config_sample_hosts +++ b/test/integration/targets/cnos_config/cnos_config_sample_hosts @@ -6,7 +6,7 @@ # - You can enter hostnames or ip Addresses # - A hostname/ip can be a member of multiple groups # -# In the /etc/ansible/hosts file u have to enter [cnos_command_sample] tag +# In the /etc/ansible/hosts file u have to enter [cnos_config_sample] tag # Following you should specify IP Addresses details # Please change and with appropriate value for your switch. diff --git a/test/integration/targets/cnos_config/tests/cli/backup.yaml b/test/integration/targets/cnos_config/tests/cli/backup.yaml index 3f385311fd5..2f1673b699d 100644 --- a/test/integration/targets/cnos_config/tests/cli/backup.yaml +++ b/test/integration/targets/cnos_config/tests/cli/backup.yaml @@ -5,7 +5,6 @@ cnos_config: commands: - no vlan 13 - provider: "{{ cli }}" ignore_errors: yes - name: collect any backup files @@ -25,12 +24,11 @@ cnos_config: src: roles/cnos_config/templates/basic/config.j2 backup: yes - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - name: collect any backup files find: @@ -47,6 +45,5 @@ cnos_config: commands: - no vlan 13 - provider: "{{ cli }}" - debug: msg="END cli/backup.yaml" diff --git a/test/integration/targets/cnos_config/tests/cli/basic.yaml b/test/integration/targets/cnos_config/tests/cli/basic.yaml index 61773d2dcbd..21a4d2c35a2 100644 --- a/test/integration/targets/cnos_config/tests/cli/basic.yaml +++ b/test/integration/targets/cnos_config/tests/cli/basic.yaml @@ -5,35 +5,31 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" ignore_errors: yes - name: configure device with config cnos_config: src: roles/cnos_config/templates/basic/config.j2 - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - "result.updates is not defined" - name: check device with config cnos_config: src: roles/cnos_config/templates/basic/config.j2 - provider: "{{ cli }}" register: result - assert: that: - - "result.changed == false" + - "result.changed == true" - "result.updates is not defined" - name: teardown cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" - debug: msg="END cli/basic.yaml" diff --git a/test/integration/targets/cnos_config/tests/cli/defaults.yaml b/test/integration/targets/cnos_config/tests/cli/defaults.yaml index 3bea4e0c773..f557cd65e44 100644 --- a/test/integration/targets/cnos_config/tests/cli/defaults.yaml +++ b/test/integration/targets/cnos_config/tests/cli/defaults.yaml @@ -5,7 +5,6 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" ignore_errors: yes become: True become_method: enable @@ -13,7 +12,6 @@ - name: configure device with defaults included cnos_config: src: roles/cnos_config/templates/defaults/config.j2 - provider: "{{ cli }}" register: result become: True become_method: enable @@ -28,7 +26,6 @@ - name: check device with defaults included Hell cnos_config: src: roles/cnos_config/templates/defaults/config.j2 - provider: "{{ cli }}" register: result - debug: var=result @@ -42,7 +39,6 @@ cnos_config: commands: - no vlan 13\n - provider: "{{ cli }}" become: true become_method: enable ignore_errors: yes diff --git a/test/integration/targets/cnos_config/vars/main.yml b/test/integration/targets/cnos_config/vars/main.yml deleted file mode 100644 index d0fcdabf53b..00000000000 --- a/test/integration/targets/cnos_config/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 60 - context: ansible - auth_pass: diff --git a/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml b/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml index e0fd6e3d8f1..2b050f1b971 100644 --- a/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml +++ b/test/integration/targets/cnos_facts/tests/cli/default_facts.yaml @@ -15,16 +15,11 @@ - "'hardware' in result.ansible_facts.ansible_net_gather_subset" - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'interfaces' in result.ansible_facts.ansible_net_gather_subset" - #- "result.ansible_facts.ansible_net_filesystems is defined" - # ... and not present - "'config' not in result.ansible_facts.ansible_net_gather_subset" # Items from those subsets are present - #- "result.ansible_facts.ansible_net_filesystems is defined" #hw - "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw - "result.ansible_facts.ansible_net_interfaces | length > 1" # more than one interface returned - - # ... and not present - "result.ansible_facts.ansible_net_config is not defined" # config - debug: msg="END cli/default.yaml" diff --git a/test/integration/targets/cnos_facts/vars/main.yml b/test/integration/targets/cnos_facts/vars/main.yml deleted file mode 100644 index aa25153ec86..00000000000 --- a/test/integration/targets/cnos_facts/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -cli: - host: "{{ inventory_hostname }}" - port: 22 - username: admin - password: admin - timeout: 30 - authorize: True - auth_pass: