roll up of fixes for nxos_facts (#21954)

* fixes commands to work with nxapi
* updates test case timeouts
This commit is contained in:
Peter Sprygada 2017-02-25 17:48:09 -05:00 committed by GitHub
commit a284c3f7ea
4 changed files with 22 additions and 19 deletions

View file

@ -208,7 +208,7 @@ class Nxapi:
return dict(ins_api=msg) return dict(ins_api=msg)
def send_request(self, commands, output='text'): def send_request(self, commands, output='text', check_status=True):
# only 10 show commands can be encoded in each request # only 10 show commands can be encoded in each request
# messages sent to the remote device # messages sent to the remote device
if output != 'config': if output != 'config':
@ -255,12 +255,13 @@ class Nxapi:
except ValueError: except ValueError:
self._module.fail_json(msg='unable to parse response') self._module.fail_json(msg='unable to parse response')
output = response['ins_api']['outputs']['output'] if check_status:
for item in to_list(output): output = response['ins_api']['outputs']['output']
if item['code'] != '200': for item in to_list(output):
self._error(output=output, **item) if item['code'] != '200':
else: self._error(output=output, **item)
result.append(item['body']) else:
result.append(item['body'])
return result return result
@ -288,7 +289,7 @@ class Nxapi:
queue = list() queue = list()
responses = list() responses = list()
_send = lambda commands, output: self.send_request(commands, output) _send = lambda commands, output: self.send_request(commands, output, check_status=check_rc)
for item in to_list(commands): for item in to_list(commands):
if is_json(item['command']): if is_json(item['command']):

View file

@ -16,9 +16,11 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# #
ANSIBLE_METADATA = {'status': ['preview'], ANSIBLE_METADATA = {
'supported_by': 'community', 'status': ['preview'],
'version': '1.0'} 'supported_by': 'community',
'version': '1.0'
}
DOCUMENTATION = """ DOCUMENTATION = """
--- ---
@ -181,7 +183,6 @@ import re
from ansible.module_utils.nxos import run_commands from ansible.module_utils.nxos import run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import exec_command
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
@ -239,7 +240,7 @@ class Config(FactsBase):
class Hardware(FactsBase): class Hardware(FactsBase):
COMMANDS = [ COMMANDS = [
'dir', {'command': 'dir', 'output': 'text'},
'show system resources | json' 'show system resources | json'
] ]
@ -287,13 +288,12 @@ class Interfaces(FactsBase):
data = run_commands(self.module, ['show interface | json'])[0] data = run_commands(self.module, ['show interface | json'])[0]
self.facts['interfaces'] = self.populate_interfaces(data) self.facts['interfaces'] = self.populate_interfaces(data)
rc, out, err = exec_command(self.module, 'show ipv6 interface | json') out = run_commands(self.module, ['show ipv6 interface | json'])
if rc == 0: if out[0]:
if out: self.parse_ipv6_interfaces(out)
self.parse_ipv6_interfaces(out)
rc, out, err = exec_command(self.module, 'show lldp neighbors') out = run_commands(self.module, ['show lldp neighbors'], check_rc=False)
if rc == 0: if out and out[0]:
self.facts['neighbors'] = self.populate_neighbors(out) self.facts['neighbors'] = self.populate_neighbors(out)
def populate_interfaces(self, data): def populate_interfaces(self, data):

View file

@ -7,6 +7,7 @@
provider: "{{ nxapi }}" provider: "{{ nxapi }}"
gather_subset: gather_subset:
- all - all
timeout: 60
register: result register: result

View file

@ -7,6 +7,7 @@
provider: "{{ nxapi }}" provider: "{{ nxapi }}"
gather_subset: gather_subset:
- "!hardware" - "!hardware"
timeout: 30
register: result register: result
- assert: - assert: