Skip to content

Commit

Permalink
Fix some errors in tests/integration + remove initial space at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
earendilfr committed Dec 5, 2023
1 parent a5b909b commit f8e64f4
Show file tree
Hide file tree
Showing 6 changed files with 570 additions and 165 deletions.
11 changes: 0 additions & 11 deletions plugins/module_utils/network/ios/config/line/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_merge,
to_list,
)

from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.facts import Facts
Expand Down Expand Up @@ -276,15 +275,5 @@ def _compare_lists(self, want, have):
else:
self.compare(parsers=self.parsers[key], want={}, have={key: h_entry})

def addcmd(self, data, tmplt, negate=False):
command = self._tmplt.render(data, tmplt, False)
if negate:
if isinstance(command, list):
command = [(" no" + each) for each in command]
else:
command = " no" + command
if command:
self.commands.extend(to_list(command))

def _convert_list_to_dict(self, data, key="name"):
return {_k.get(key, ""): _k for _k in data} if data else {}
65 changes: 33 additions & 32 deletions plugins/module_utils/network/ios/rm_templates/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, lines=None, module=None):
^\s+access-class\s+(?P<access_classes_in>\S+)\s+in
""", re.VERBOSE,
),
"setval": " access-class {{ access_classes_in }} in",
"setval": "access-class {{ access_classes_in }} in",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -68,7 +68,7 @@ def __init__(self, lines=None, module=None):
^\s+access-class\s+(?P<access_classes_in>\S+)\s+out
""", re.VERBOSE,
),
"setval": " access-class {{ access_classes_out }} out",
"setval": "access-class {{ access_classes_out }} out",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -84,7 +84,7 @@ def __init__(self, lines=None, module=None):
^\s+accounting\s+arap\s+(?P<arap>\S+)
""", re.VERBOSE,
),
"setval": " accounting arap {{ accounting.arap }}",
"setval": "accounting arap {{ accounting.arap }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -103,7 +103,7 @@ def __init__(self, lines=None, module=None):
^\s+accounting\s+commands\s+(?P<level>\d+)\s+(?P<command>\S+)
""", re.VERBOSE,
),
"setval": " accounting commands {{ commands.level }} {{ commands.command }}",
"setval": "accounting commands {{ commands.level }} {{ commands.command }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -126,7 +126,7 @@ def __init__(self, lines=None, module=None):
^\s+accounting\s+connection\s+(?P<connection>\S+)
""", re.VERBOSE,
),
"setval": " accounting connection {{ accounting.connection }}",
"setval": "accounting connection {{ accounting.connection }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -144,7 +144,7 @@ def __init__(self, lines=None, module=None):
^\s+accounting\s+exec\s+(?P<exec>\S+)
""", re.VERBOSE,
),
"setval": " accounting exec {{ accounting.exec }}",
"setval": "accounting exec {{ accounting.exec }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -162,7 +162,7 @@ def __init__(self, lines=None, module=None):
^\s+accounting\s+resource\s+(?P<resource>\S+)
""", re.VERBOSE,
),
"setval": " accounting resource {{ accounting.resource }}",
"setval": "accounting resource {{ accounting.resource }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -180,7 +180,7 @@ def __init__(self, lines=None, module=None):
^\s+authorization\s+arap\s+(?P<arap>\S+)
""", re.VERBOSE,
),
"setval": " authorization arap {{ authorization.arap }}",
"setval": "authorization arap {{ authorization.arap }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -199,7 +199,7 @@ def __init__(self, lines=None, module=None):
^\s+authorization\s+commands\s+(?P<level>\d+)\s+(?P<command>\S+)
""", re.VERBOSE,
),
"setval": " authorization commands {{ commands.level }} {{ commands.command }}",
"setval": "authorization commands {{ commands.level }} {{ commands.command }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -222,7 +222,7 @@ def __init__(self, lines=None, module=None):
^\s+authorization\s+exec\s+(?P<exec>\S+)
""", re.VERBOSE,
),
"setval": " authorization exec {{ authorization.exec }}",
"setval": "authorization exec {{ authorization.exec }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -240,7 +240,7 @@ def __init__(self, lines=None, module=None):
^\s+authorization\s+reverse-access\s+(?P<reverse_access>\S+)
""", re.VERBOSE,
),
"setval": " authorization reverse-access {{ authorization.reverse_access }}",
"setval": "authorization reverse-access {{ authorization.reverse_access }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -260,7 +260,7 @@ def __init__(self, lines=None, module=None):
\s+(?P<value>\S+)
""", re.VERBOSE,
),
"setval": " escape-character"
"setval": "escape-character"
"{{ ' soft' if escape_character.soft|d(False) else '' }}"
"{{ ' ' + escape_character.value }}",
"result": {
Expand All @@ -281,7 +281,7 @@ def __init__(self, lines=None, module=None):
^\s+exec-banner
""", re.VERBOSE,
),
"setval": " exec-banner",
"setval": "exec-banner",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -299,7 +299,7 @@ def __init__(self, lines=None, module=None):
^\s+exec-character-bits\s+(?P<character_bits>7|8)
""", re.VERBOSE,
),
"setval": " exec-character-bits {{ exec.character_bits }}",
"setval": "exec-character-bits {{ exec.character_bits }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand Down Expand Up @@ -357,7 +357,7 @@ def __init__(self, lines=None, module=None):
^\s+exec-timeout\s+(?P<timeout>\d+)
""", re.VERBOSE,
),
"setval": " exec-timeout {{ exec.timeout }} 0",
"setval": "exec-timeout {{ exec.timeout }} 0",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -375,7 +375,7 @@ def __init__(self, lines=None, module=None):
^\s+length\s(?P<length>\d+)
""", re.VERBOSE,
),
"setval": " length {{ length|string }}",
"setval": "length {{ length|string }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -391,7 +391,7 @@ def __init__(self, lines=None, module=None):
^\s+location\s+(?P<location>.+)$
""", re.VERBOSE,
),
"setval": " location {{ location }}",
"setval": "location {{ location }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -409,7 +409,7 @@ def __init__(self, lines=None, module=None):
(\s+(?P<limit>\d+))?
""", re.VERBOSE,
),
"setval": " logging synchronous"
"setval": "logging synchronous"
"{{ ' level ' + logging.level if logging.level is defined else '' }}"
"{{ ' limit ' + logging.limit if logging.limit is defined else '' }}",
"result": {
Expand All @@ -431,7 +431,7 @@ def __init__(self, lines=None, module=None):
^\s+login\s+authentication\s+(?P<login>\S+)
""", re.VERBOSE,
),
"setval": " login authentication {{ login }}",
"setval": "login authentication {{ login }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -447,7 +447,7 @@ def __init__(self, lines=None, module=None):
^\s+logout-warning\s+(?P<logout_warning>\d+)
""", re.VERBOSE,
),
"setval": " logout-warning {{ logout_warning }}",
"setval": "logout-warning {{ logout_warning }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -463,7 +463,7 @@ def __init__(self, lines=None, module=None):
^\s+motd-banner
""", re.VERBOSE,
),
"setval": " motd-banner",
"setval": "motd-banner",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -479,7 +479,7 @@ def __init__(self, lines=None, module=None):
^\s+notify
""", re.VERBOSE,
),
"setval": " notify",
"setval": "notify",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -495,7 +495,7 @@ def __init__(self, lines=None, module=None):
^\s+padding\s+(?P<padding>\S+)
""", re.VERBOSE,
),
"setval": " padding {{ padding }}",
"setval": "padding {{ padding }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -511,7 +511,7 @@ def __init__(self, lines=None, module=None):
^\s+parity\s+(?P<parity>even|mark|none|odd|space)
""", re.VERBOSE,
),
"setval": " parity {{ parity }}",
"setval": "parity {{ parity }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -530,7 +530,7 @@ def __init__(self, lines=None, module=None):
""", re.VERBOSE,
),
"setval": "{% if 'value' in password and password.value is defined %}"
" password"
"password"
"{{ ' ' + password.hash|string if password.hash is defined else '' }}"
"{{ ' ' + password.value }}"
"{% endif %}",
Expand All @@ -552,7 +552,7 @@ def __init__(self, lines=None, module=None):
^\s+privilege\s+level\s+(?P<privilege>\d+)
""", re.VERBOSE,
),
"setval": " privilege level {{ privilege }}",
"setval": "privilege level {{ privilege }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -568,7 +568,7 @@ def __init__(self, lines=None, module=None):
^\s+session-disconnect-warning\s+(?P<disconnect_warning>\d+)
""", re.VERBOSE,
),
"setval": " session-disconnect-warning {{ session.disconnect_warning }}",
"setval": "session-disconnect-warning {{ session.disconnect_warning }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -586,7 +586,7 @@ def __init__(self, lines=None, module=None):
^\s+session-limit\s+(?P<limit>\d+)
""", re.VERBOSE,
),
"setval": " session-limit {{ session.limit }}",
"setval": "session-limit {{ session.limit }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -604,7 +604,7 @@ def __init__(self, lines=None, module=None):
^\s+session-timeout\s+(?P<timeout>\d+)
""", re.VERBOSE,
),
"setval": " session-timeout {{ session.timeout }}",
"setval": "session-timeout {{ session.timeout }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -622,7 +622,7 @@ def __init__(self, lines=None, module=None):
^\s+speed\s+(?P<speed>\d+)
""", re.VERBOSE,
),
"setval": " speed {{ speed }}",
"setval": "speed {{ speed }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -638,7 +638,7 @@ def __init__(self, lines=None, module=None):
^\s+stopbits\s+(?P<stopbits>1|1.5|2)
""", re.VERBOSE,
),
"setval": " stopbits {{ stopbits }}",
"setval": "stopbits {{ stopbits }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand All @@ -660,7 +660,7 @@ def __init__(self, lines=None, module=None):
(\s+(?P<t_ssh>ssh))?
""", re.VERBOSE,
),
"setval": " transport {{ transport.name }}"
"setval": "transport {{ transport.name }}"
"{% if transport.all|d(False) %}"
" all"
"{% elif transport.none|d(False) %}"
Expand All @@ -671,6 +671,7 @@ def __init__(self, lines=None, module=None):
"{{ ' rlogin' if transport.rlogin|d(False) }}"
"{{ ' ssh' if transport.ssh|d(False) }}"
"{% endif %}",
"remval": "transport {{ transport.name }}",
"result": {
"lines": {
"{{ name|d() }}": {
Expand Down
Loading

0 comments on commit f8e64f4

Please sign in to comment.