Skip to content

Commit

Permalink
[airos] added schema for ntp servers with defaults, use them in
Browse files Browse the repository at this point in the history
converter
  • Loading branch information
edoput committed Aug 22, 2017
1 parent ed32157 commit 26c7382
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
9 changes: 2 additions & 7 deletions netjsonconfig/backends/airos/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ...utils import get_copy
from ..base.converter import BaseConverter
from .schema import default_ntp_servers
from .wpasupplicant import available_mode_authentication


Expand Down Expand Up @@ -351,12 +352,6 @@ def to_intermediate(self):
class Ntpclient(AirOsConverter):
netjson_key = 'ntp'

default_servers = [
"0.openwrt.pool.ntp.org",
"1.openwrt.pool.ntp.org",
"2.openwrt.pool.ntp.org",
"3.openwrt.pool.ntp.org",
]

def ntp_status(self, ntp):
if ntp.get('enabled', True):
Expand All @@ -370,7 +365,7 @@ def to_intermediate(self):
original = get_copy(self.netjson, self.netjson_key, {})
result.append({'status': self.ntp_status(original)})

for ntp in original.get('servers', self.default_servers):
for ntp in original.get('server', default_ntp_servers):
servers.append({
'server': ntp,
'status': 'enabled',
Expand Down
43 changes: 43 additions & 0 deletions netjsonconfig/backends/airos/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
on a bridge
"""

default_ntp_servers = [
"0.pool.ntp.org",
"1.pool.ntp.org",
"2.pool.ntp.org",
"3.pool.ntp.org",
]

override_schema = {
"type": "object",
"addtionalProperties": True,
Expand Down Expand Up @@ -96,6 +103,42 @@
"salt",
],
},
"ntp": {
"type": "object",
"title": "NTP Settings",
"additionalProperties": True,
"propertyOrder": 8,
"properties": {
"enabled": {
"type": "boolean",
"title": "enable NTP client",
"default": True,
"format": "checkbox",
"propertyOrder": 1,
},
"enable_server": {
"type": "boolean",
"title": "enable NTP server",
"default": False,
"format": "checkbox",
"propertyOrder": 2,
},
"server": {
"title": "NTP Servers",
"description": "NTP server candidates",
"type": "array",
"uniqueItems": True,
"additionalItems": True,
"propertyOrder": 3,
"items": {
"title": "NTP server",
"type": "string",
"format": "hostname"
},
"default": default_ntp_servers,
}
}
},
},
}

Expand Down
18 changes: 9 additions & 9 deletions tests/airos/test_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class TestResolvConverter(ConverterTest):

def test_ntp_key(self):
o = self.backend({
'ntp_server': [],
'ntp': {}
})
o.to_intermediate()
expected = [
{
'status': 'enabled',
},
{
'1.server': '0.openwrt.pool.ntp.org',
'1.server': '0.pool.ntp.org',
'1.status': 'enabled',
},
{
'2.server': '1.openwrt.pool.ntp.org',
'2.server': '1.pool.ntp.org',
'2.status': 'enabled',
},
{
'3.server': '2.openwrt.pool.ntp.org',
'3.server': '2.pool.ntp.org',
'3.status': 'enabled',
},
{
'4.server': '3.openwrt.pool.ntp.org',
'4.server': '3.pool.ntp.org',
'4.status': 'enabled',
},
]
Expand All @@ -46,19 +46,19 @@ def test_no_ntp_server(self):
'status': 'disabled',
},
{
'1.server': '0.openwrt.pool.ntp.org',
'1.server': '0.pool.ntp.org',
'1.status': 'enabled',
},
{
'2.server': '1.openwrt.pool.ntp.org',
'2.server': '1.pool.ntp.org',
'2.status': 'enabled',
},
{
'3.server': '2.openwrt.pool.ntp.org',
'3.server': '2.pool.ntp.org',
'3.status': 'enabled',
},
{
'4.server': '3.openwrt.pool.ntp.org',
'4.server': '3.pool.ntp.org',
'4.status': 'enabled',
},
]
Expand Down

0 comments on commit 26c7382

Please sign in to comment.