mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
8d39515914
commit
eb818df1ec
5 changed files with 15 additions and 12 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue