Skip to content

Commit

Permalink
🐞 NTP: Fix config template to init default parameters (sonic-net#18736)
Browse files Browse the repository at this point in the history
fixes sonic-net#17906

#### Why I did it
To fix NTP config generation from the minigraph and save backward compatability

#### How I did it
Align `ntp.conf.j2` template to generate config out of empty `NTP_SERVER` DB configuration

#### How to verify it
Out of that NTP_SERVER configuration:
```json
{
  "10.210.25.32": {},
  "10.75.202.2": {}
}
```

The next config in `ntp.conf` file should be produced:
```
server 10.210.25.32
restrict 10.210.25.32 kod limited nomodify notrap noquery nopeer

server 10.75.202.2
restrict 10.75.202.2 kod limited nomodify notrap noquery nopeer
```
  • Loading branch information
fastiuk committed May 16, 2024
1 parent e7c7c15 commit a8ee291
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions files/image_config/ntp/ntp.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ filegen clockstats file clockstats type day enable
{# Adding NTP servers. We need to know if we have some pools, to set proper
config -#}
{% set ns = namespace(is_pools=false) %}
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' and
NTP_SERVER[server].resolve_as and
NTP_SERVER[server].association_type -%}
{% for server in NTP_SERVER if NTP_SERVER[server].admin_state != 'disabled' -%}
{% set config = NTP_SERVER[server] -%}
{# Server options -#}
{% set soptions = '' -%}
{# Server access control options -#}
{% set aoptions = '' -%}

{# Define defaults if not defined -#}
{% set association_type = config.association_type | d('server') -%}
{% set resolve_as = config.resolve_as | d(server) -%}

{# Authentication key -#}
{% if global.authentication == 'enabled' -%}
Expand All @@ -49,17 +49,13 @@ config -#}
{# Check if there are any pool configured. BTW it doesn't matter what was
configured as "resolve_as" for pools. If they were configured with FQDN they
must remain like that -#}
{% set config_as = config.resolve_as -%}
{% if config.association_type == 'pool' -%}
{% set ns.is_pools = true -%}
{% set config_as = server -%}
{% else -%}
{% set aoptions = aoptions ~ ' nopeer' -%}
{% if association_type == 'pool' -%}
{% set resolve_as = server -%}
{% endif -%}

{{ config.association_type }} {{ config_as }}{{ soptions }}
{{ association_type }} {{ resolve_as }}{{ soptions }}
{% if global.server_role == 'disabled' %}
restrict {{ config_as }} kod limited nomodify notrap noquery{{ aoptions }}
restrict {{ resolve_as }} kod limited nomodify noquery
{% endif %}

{% endfor -%}
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-config-engine/tests/sample_output/py3/ntp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server 10.20.30.50 key 42 iburst version 3
restrict 10.20.30.50 kod limited nomodify notrap noquery nopeer
restrict 10.20.30.50 kod limited nomodify noquery

pool pool.ntp.org iburst version 3
restrict pool.ntp.org kod limited nomodify notrap noquery
restrict pool.ntp.org kod limited nomodify noquery


keys /etc/ntp.keys
Expand Down

0 comments on commit a8ee291

Please sign in to comment.