Skip to content

Commit

Permalink
Fix ntp_global servers config commands (#439)
Browse files Browse the repository at this point in the history
* Fix ntp_global servers config commands

Signed-off-by: rohitthakur2590 <[email protected]>

* Update integration tests

Signed-off-by: rohitthakur2590 <[email protected]>

* Update integration tests

Signed-off-by: rohitthakur2590 <[email protected]>

* fix command section

Signed-off-by: rohitthakur2590 <[email protected]>

* add unit tests

Signed-off-by: rohitthakur2590 <[email protected]>

* update integration test

Signed-off-by: rohitthakur2590 <[email protected]>

* fix tests

Signed-off-by: rohitthakur2590 <[email protected]>

* update tests

Signed-off-by: rohitthakur2590 <[email protected]>

---------

Signed-off-by: rohitthakur2590 <[email protected]>
  • Loading branch information
rohitthakur2590 authored Oct 26, 2023
1 parent 2b6a1b7 commit eb7f548
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/ntp_global_local_interface_fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fix command generated for local-interface with in ntp server attribute.
7 changes: 4 additions & 3 deletions plugins/module_utils/network/eos/rm_templates/ntp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def _tmplt_ntp_global_servers(config_data):
if el.get("key_id"):
command += " key {key_id}".format(**el)
if el.get("local_interface"):
command += " local_interface {local_interface}".format(**el)
linterface = el.get("local_interface").replace(" ", "")
command += " local-interface " + linterface
if el.get("maxpoll"):
command += " maxpoll {maxpoll}".format(**el)
if el.get("minpoll"):
Expand Down Expand Up @@ -227,12 +228,12 @@ def __init__(self, lines=None, module=None):
\s*(?P<prefer>prefer)*
\s*(?P<burst>burst)*
\s*(?P<iburst>iburst)*
\s*(?P<local_int>local-interface\s.+?)*
\s*(?P<maxpoll>maxpoll\s\d+)*
\s*(?P<minpoll>minpoll\s\d+)*
\s*(?P<source>source\s.+?)*
\s*(?P<version>version\s[1-4])*
\s*(?P<key>key\s.+)*
(\s*local-interface\s(?P<local_int>\S+))?
$""",
re.VERBOSE,
),
Expand All @@ -245,7 +246,7 @@ def __init__(self, lines=None, module=None):
"burst": "{{ True if burst is defined }}",
"iburst": "{{ True if iburst is defined }}",
"key_id": "{{ key.split(" ")[1] if key is defined }}",
"local_interface": "{{ local_int.split(" ")[1:] if local_int is defined }}",
"local_interface": "{{ local_int.replace(' ', '') if local_int is defined }}",
"maxpoll": "{{ maxpoll.split(" ")[1] if maxpoll is defined }}",
"minpoll": "{{ minpoll.split(" ")[1] if minpoll is defined }}",
"source": "{{ source.split(" ")[1] if source is defined }}",
Expand Down
72 changes: 72 additions & 0 deletions tests/integration/targets/eos_ntp_global/tests/common/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
- ansible.builtin.debug:
msg: Start eos_ntp_global update integration tests ansible_connection={{
ansible_connection }}

- block:
- name: merge given ntp_global configuration
become: true
register: result
arista.eos.eos_ntp_global: &update
config:
authenticate:
enable: true
authentication_keys:
- algorithm: "sha1"
encryption: 7
id: 2
key: "123456"
- algorithm: "md5"
encryption: 7
id: 23
key: "123456"
local_interface: "Ethernet1"
qos_dscp: 10
serve:
access_lists:
- acls:
- acl_name: "acl01"
direction: "in"
afi: "ip"
- acls:
- acl_name: "acl02"
direction: "in"
afi: "ipv6"
servers:
- burst: true
prefer: true
server: "10.1.1.1"
vrf: "vrf01"
- burst: true
minpoll: 13
prefer: true
server: "11.21.1.1"
vrf: "vrf01"
- key_id: 2
maxpoll: 15
server: "25.1.1.1"
vrf: "vrf01"
- server: "1.1.1.1"
vrf: "vrf01"
local_interface: "Management1"
trusted_key: "23"

- ansible.builtin.assert:
that:
- result.commands|length == 12
- result.changed == true
- result.commands|symmetric_difference(updated.commands) == []
- result.after == updated.after
- result.before == {}

- name: Idempotency check
become: true
register: result
arista.eos.eos_ntp_global: *update

- ansible.builtin.assert:
that:
- result.commands|length == 0
- result.changed == false
always:
- ansible.builtin.include_tasks: _remove_config.yaml
57 changes: 57 additions & 0 deletions tests/integration/targets/eos_ntp_global/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,63 @@ deleted:
- "no ntp qos dscp 10"
- "no ntp trusted-key 23"

updated:
commands:
- "ntp serve ip access-group acl01 in"
- "ntp serve ipv6 access-group acl02 in"
- "ntp authentication-key 2 sha1 7 ********"
- "ntp authentication-key 23 md5 7 ********"
- "ntp server vrf vrf01 10.1.1.1 burst prefer"
- "ntp server vrf vrf01 11.21.1.1 burst minpoll 13 prefer"
- "ntp server vrf vrf01 25.1.1.1 key 2 maxpoll 15"
- "ntp server vrf vrf01 1.1.1.1 local-interface Management1"
- "ntp authenticate"
- "ntp local-interface Ethernet1"
- "ntp qos dscp 10"
- "ntp trusted-key 23"
after:
authenticate:
enable: true
authentication_keys:
- algorithm: "sha1"
encryption: 7
id: 2
key: "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
- algorithm: "md5"
encryption: 7
id: 23
key: "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
local_interface: "Ethernet1"
qos_dscp: 10
serve:
access_lists:
- acls:
- acl_name: "acl01"
direction: "in"
afi: "ip"
- acls:
- acl_name: "acl02"
direction: "in"
afi: "ipv6"
servers:
- local_interface: "Management1"
server: "1.1.1.1"
vrf: "vrf01"
- burst: true
prefer: true
server: "10.1.1.1"
vrf: "vrf01"
- burst: true
minpoll: 13
prefer: true
server: "11.21.1.1"
vrf: "vrf01"
- key_id: 2
maxpoll: 15
server: "25.1.1.1"
vrf: "vrf01"
trusted_key: "23"

replaced:
before:
authenticate:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/modules/network/eos/test_eos_ntp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ def test_eos_ntp_global_merged(self):
iburst=True,
source="vlan500",
),
dict(
server="110.22.2.2",
local_interface="Management1",
),
],
serve=dict(
access_lists=[
Expand All @@ -246,6 +250,7 @@ def test_eos_ntp_global_merged(self):
"ntp serve ip access-group acl03 in",
"ntp authentication-key 4 sha1 0 123456",
"ntp server 110.21.1.1 iburst source Vlan500 version 3",
"ntp server 110.22.2.2 local-interface Management1",
"ntp qos dscp 15",
]
self.execute_module(changed=True, commands=sorted(commands))
Expand Down

0 comments on commit eb7f548

Please sign in to comment.