Ios test fixes (#40503)

* Return messages generated from edit_config to module

* This does not seem to work that way

* Change test IP addresses to not conflict with device config
This commit is contained in:
Nathaniel Case 2018-05-21 17:51:21 -04:00 committed by GitHub
parent 8d39515914
commit eb818df1ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 12 deletions

View file

@ -165,4 +165,4 @@ def run_commands(module, commands, check_rc=True):
def load_config(module, commands): def load_config(module, commands):
connection = get_connection(module) connection = get_connection(module)
out = connection.edit_config(commands) return connection.edit_config(commands)

View file

@ -296,9 +296,6 @@ def main():
result = {'changed': False} result = {'changed': False}
if warnings:
result['warnings'] = warnings
want = map_params_to_obj(module) want = map_params_to_obj(module)
have = map_config_to_obj(module) have = map_config_to_obj(module)
@ -307,10 +304,14 @@ def main():
if commands: if commands:
if not module.check_mode: if not module.check_mode:
load_config(module, commands) resp = load_config(module, commands)
warnings.extend((out for out in resp if out))
result['changed'] = True result['changed'] = True
if warnings:
result['warnings'] = warnings
module.exit_json(**result) module.exit_json(**result)

View file

@ -183,7 +183,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
ssh = self._connection.paramiko_conn._connect_uncached() ssh = self._connection.paramiko_conn._connect_uncached()
if proto == 'scp': if proto == 'scp':
if not HAS_SCP: if not HAS_SCP:
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`") raise AnsibleError("Required library scp is not installed. Please install it using `pip install scp`")
with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp: with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp:
out = scp.put(source, destination) out = scp.put(source, destination)
elif proto == 'sftp': elif proto == 'sftp':
@ -195,7 +195,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
ssh = self._connection.paramiko_conn._connect_uncached() ssh = self._connection.paramiko_conn._connect_uncached()
if proto == 'scp': if proto == 'scp':
if not HAS_SCP: if not HAS_SCP:
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`") raise AnsibleError("Required library scp is not installed. Please install it using `pip install scp`")
with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp: with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp:
scp.get(source, destination) scp.get(source, destination)
elif proto == 'sftp': elif proto == 'sftp':

View file

@ -72,6 +72,7 @@ class Cliconf(CliconfBase):
@enable_mode @enable_mode
def edit_config(self, command): def edit_config(self, command):
results = []
for cmd in chain(['configure terminal'], to_list(command), ['end']): for cmd in chain(['configure terminal'], to_list(command), ['end']):
if isinstance(cmd, dict): if isinstance(cmd, dict):
command = cmd['command'] command = cmd['command']
@ -84,7 +85,8 @@ class Cliconf(CliconfBase):
answer = None answer = None
newline = True newline = True
self.send_command(command, prompt, answer, False, newline) results.append(self.send_command(command, prompt, answer, False, newline))
return results[1:-1]
def get(self, command, prompt=None, answer=None, sendonly=False): def get(self, command, prompt=None, answer=None, sendonly=False):
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly) return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)

View file

@ -22,7 +22,7 @@
- name: Configure interface ipv4 address - name: Configure interface ipv4 address
ios_l3_interface: ios_l3_interface:
name: "{{ test_interface }}" name: "{{ test_interface }}"
ipv4: 192.168.0.1/24 ipv4: 192.168.20.1/24
state: present state: present
provider: "{{ cli }}" provider: "{{ cli }}"
register: result register: result
@ -31,12 +31,12 @@
that: that:
- 'result.changed == true' - 'result.changed == true'
- '"interface {{ test_interface }}" in result.commands' - '"interface {{ test_interface }}" in result.commands'
- '"ip address 192.168.0.1 255.255.255.0" in result.commands' - '"ip address 192.168.20.1 255.255.255.0" in result.commands'
- name: Configure interface ipv4 address (idempotent) - name: Configure interface ipv4 address (idempotent)
ios_l3_interface: ios_l3_interface:
name: "{{ test_interface }}" name: "{{ test_interface }}"
ipv4: 192.168.0.1/24 ipv4: 192.168.20.1/24
state: present state: present
provider: "{{ cli }}" provider: "{{ cli }}"
register: result register: result
@ -48,7 +48,7 @@
- name: Assign same ipv4 address to other interface (fail) - name: Assign same ipv4 address to other interface (fail)
ios_l3_interface: ios_l3_interface:
name: "{{ test_interface2 }}" name: "{{ test_interface2 }}"
ipv4: 192.168.0.1/24 ipv4: 192.168.20.1/24
state: present state: present
provider: "{{ cli }}" provider: "{{ cli }}"
ignore_errors: yes ignore_errors: yes