summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Case <this.is@nathanielca.se>2018-05-21 23:51:21 +0200
committerGitHub <noreply@github.com>2018-05-21 23:51:21 +0200
commiteb818df1ecbc45458fa1aa446e2cc236e425056e (patch)
tree6d962fdfb3da677226eeca6a87beb998cecc8b7d
parentRemove tab check from validate-modules. (diff)
downloadansible-eb818df1ecbc45458fa1aa446e2cc236e425056e.tar.xz
ansible-eb818df1ecbc45458fa1aa446e2cc236e425056e.zip
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
-rw-r--r--lib/ansible/module_utils/network/ios/ios.py2
-rw-r--r--lib/ansible/modules/network/ios/ios_l3_interface.py9
-rw-r--r--lib/ansible/plugins/cliconf/__init__.py4
-rw-r--r--lib/ansible/plugins/cliconf/ios.py4
-rw-r--r--test/integration/targets/ios_l3_interface/tests/cli/basic.yaml8
5 files changed, 15 insertions, 12 deletions
diff --git a/lib/ansible/module_utils/network/ios/ios.py b/lib/ansible/module_utils/network/ios/ios.py
index fc690c98fd..1cbac6bcec 100644
--- a/lib/ansible/module_utils/network/ios/ios.py
+++ b/lib/ansible/module_utils/network/ios/ios.py
@@ -165,4 +165,4 @@ def run_commands(module, commands, check_rc=True):
def load_config(module, commands):
connection = get_connection(module)
- out = connection.edit_config(commands)
+ return connection.edit_config(commands)
diff --git a/lib/ansible/modules/network/ios/ios_l3_interface.py b/lib/ansible/modules/network/ios/ios_l3_interface.py
index 59c1e7eaa8..1547667b31 100644
--- a/lib/ansible/modules/network/ios/ios_l3_interface.py
+++ b/lib/ansible/modules/network/ios/ios_l3_interface.py
@@ -296,9 +296,6 @@ def main():
result = {'changed': False}
- if warnings:
- result['warnings'] = warnings
-
want = map_params_to_obj(module)
have = map_config_to_obj(module)
@@ -307,10 +304,14 @@ def main():
if commands:
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
+ if warnings:
+ result['warnings'] = warnings
+
module.exit_json(**result)
diff --git a/lib/ansible/plugins/cliconf/__init__.py b/lib/ansible/plugins/cliconf/__init__.py
index e613cf39eb..2ca50b60a0 100644
--- a/lib/ansible/plugins/cliconf/__init__.py
+++ b/lib/ansible/plugins/cliconf/__init__.py
@@ -183,7 +183,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
ssh = self._connection.paramiko_conn._connect_uncached()
if proto == '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:
out = scp.put(source, destination)
elif proto == 'sftp':
@@ -195,7 +195,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
ssh = self._connection.paramiko_conn._connect_uncached()
if proto == '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:
scp.get(source, destination)
elif proto == 'sftp':
diff --git a/lib/ansible/plugins/cliconf/ios.py b/lib/ansible/plugins/cliconf/ios.py
index ff2a6b048a..2883907247 100644
--- a/lib/ansible/plugins/cliconf/ios.py
+++ b/lib/ansible/plugins/cliconf/ios.py
@@ -72,6 +72,7 @@ class Cliconf(CliconfBase):
@enable_mode
def edit_config(self, command):
+ results = []
for cmd in chain(['configure terminal'], to_list(command), ['end']):
if isinstance(cmd, dict):
command = cmd['command']
@@ -84,7 +85,8 @@ class Cliconf(CliconfBase):
answer = None
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):
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
diff --git a/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml b/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml
index 58c0fd85de..c943b6f00c 100644
--- a/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml
+++ b/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml
@@ -22,7 +22,7 @@
- name: Configure interface ipv4 address
ios_l3_interface:
name: "{{ test_interface }}"
- ipv4: 192.168.0.1/24
+ ipv4: 192.168.20.1/24
state: present
provider: "{{ cli }}"
register: result
@@ -31,12 +31,12 @@
that:
- 'result.changed == true'
- '"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)
ios_l3_interface:
name: "{{ test_interface }}"
- ipv4: 192.168.0.1/24
+ ipv4: 192.168.20.1/24
state: present
provider: "{{ cli }}"
register: result
@@ -48,7 +48,7 @@
- name: Assign same ipv4 address to other interface (fail)
ios_l3_interface:
name: "{{ test_interface2 }}"
- ipv4: 192.168.0.1/24
+ ipv4: 192.168.20.1/24
state: present
provider: "{{ cli }}"
ignore_errors: yes