Skip to content

Commit 699e36f

Browse files
author
Ritwick DSouza
committed
[raspbian] Added converter/template/tests for general settings
1 parent 74abbbe commit 699e36f

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

netjsonconfig/backends/raspbian/converters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
from ipaddress import IPv4Interface
44

55

6+
class General(BaseConverter):
7+
netjson_key = 'general'
8+
9+
def to_intermediate(self):
10+
result = []
11+
general = get_copy(self.netjson, self.netjson_key)
12+
result.append(general)
13+
return (('general', result),)
614
class Interfaces(BaseConverter):
715
netjson_key = 'interfaces'
816

netjsonconfig/backends/raspbian/raspbian.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .converters import Interfaces, Wireless, DnsServers, DnsSearch, Ntp
1+
from .converters import General, Interfaces, Wireless, DnsServers, DnsSearch, Ntp
22
from .renderers import Raspbian
33
from ..base.backend import BaseBackend
44
from .schema import schema
@@ -11,6 +11,7 @@ class Raspbian(BaseBackend):
1111
schema = schema
1212
env_path = 'netjsonconfig.backends.raspbian'
1313
converters = [
14+
General,
1415
Interfaces,
1516
Wireless,
1617
DnsServers,

netjsonconfig/backends/raspbian/templates/raspbian.jinja2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
{% for i, j in data.items() %}
2+
{% if i|string() == 'general' %}
3+
{% for general in j %}
4+
{% if general.get('hostname') %}
5+
config: /etc/hostname
6+
{{ general.get('hostname') }}
7+
8+
{% endif %}
9+
{% endfor %}
10+
{% endif %}
11+
{% endfor %}
12+
{% for i, j in data.items() %}
13+
{% if i|string() == 'general' %}
14+
{% for general in j %}
15+
{% if general.get('timezone') %}
16+
run commands:
17+
$ timedatectl set-timezone {{ general.get('timezone') }}
18+
19+
{% endif %}
20+
{% endfor %}
21+
{% endif %}
22+
{% endfor%}
23+
{% for i, j in data.items() %}
224
{% if i|string() == 'interfaces' %}
325
{% for interface in j %}
426
{% if interface.get('iftype') == 'wireless' %}

tests/raspbian/test_system.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66

77
class TestSystemRender(unittest.TestCase, _TabsMixin):
88

9+
def test_general(self):
10+
o = Raspbian({
11+
"general": {
12+
"hostname": "test-system",
13+
"timezone": "Europe/Rome",
14+
"custom_setting": True,
15+
"empty_setting1": None,
16+
"empty_setting2": ""
17+
}
18+
})
19+
20+
expected = '''config: /etc/hostname
21+
test-system
22+
23+
run commands:
24+
$ timedatectl set-timezone Europe/Rome
25+
26+
'''
27+
self.assertEqual(o.render(), expected)
28+
929
def test_ntp(self):
1030
o = Raspbian({
1131
"ntp": {

0 commit comments

Comments
 (0)