Skip to content

Commit

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

To fix NTP config generation from the minigraph and save backward compatability

Align `ntp.conf.j2` template to generate config out of empty `NTP_SERVER` DB configuration

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
```

Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk authored May 28, 2024
1 parent 10831ac commit 2e1892b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions files/image_config/ntp/ntp.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ 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' -%}
{% if config.key -%}
Expand All @@ -49,17 +51,16 @@ 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' -%}
{% if association_type == 'pool' -%}
{% set ns.is_pools = true -%}
{% set config_as = server -%}
{% set resolve_as = server -%}
{% else -%}
{% set aoptions = aoptions ~ ' nopeer' -%}
{% 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 notrap noquery{{ aoptions }}
{% endif %}

{% endfor -%}
Expand Down

0 comments on commit 2e1892b

Please sign in to comment.