File tree Expand file tree Collapse file tree
netjsonconfig/backends/openwrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11Change log
22==========
33
4+ - Added dialup interface handling for openwrt backend.
5+ This change is backward incompatible for custom defined interfaces of the
6+ proto type ``other ``.
7+
48Version 0.8.1 [2020-05-28]
59--------------------------
610
Original file line number Diff line number Diff line change @@ -248,7 +248,8 @@ def __netjson_addresses(self, interface):
248248 return interface
249249 if proto not in ['static' , 'dhcp' , 'dhcpv6' , 'none' ]:
250250 interface ['proto' ] = proto
251- interface ['type' ] = 'other'
251+ interface ['type' ] = self .__get_special_interface_type (interface )
252+
252253 addresses = []
253254 ipv4 = interface .pop ('ipaddr' , [])
254255 ipv6 = interface .pop ('ip6addr' , [])
@@ -272,6 +273,15 @@ def __netjson_addresses(self, interface):
272273 interface ['addresses' ] = addresses
273274 return interface
274275
276+ def __get_special_interface_type (self , interface ):
277+ username = interface .get ('username' , False )
278+ password = interface .get ('password' , False )
279+
280+ if username and password :
281+ return 'dialup'
282+
283+ return 'other'
284+
275285 def __netjson_address (self , address , interface ):
276286 ip = ip_interface (address )
277287 family = 'ipv{0}' .format (ip .version )
Original file line number Diff line number Diff line change 114114 },
115115 "dialup_interface" : {
116116 "title" : "Dialup interface" ,
117- "required" : [
118- "proto" ,
119- "username" ,
120- "password"
121- ],
117+ "required" : ["proto" , "username" , "password" ],
122118 "allOf" : [
123119 {
124120 "properties" : {
121+ "type" : {
122+ "type" : "string" ,
123+ "enum" : ["dialup" ],
124+ "default" : "dialup" ,
125+ "propertyOrder" : 1 ,
126+ },
125127 "proto" : {
126128 "type" : "string" ,
127129 "enum" : [
135137 "pppoe" ,
136138 "pptp" ,
137139 "qmi" ,
138- "wwan"
140+ "wwan" ,
139141 ],
140142 "default" : "pppoe" ,
141143 "propertyOrder" : 8 ,
149151 "type" : "string" ,
150152 "description" : "password for authentication in protocols like PPPoE" ,
151153 "propertyOrder" : 10 ,
152- }
154+ },
153155 }
154156 },
155157 {"$ref" : "#/definitions/interface_settings" },
156- ]
158+ ],
157159 },
158160 "base_radio_settings" : {
159161 "properties" : {
209211 }
210212 },
211213 "interfaces" : {
212- "type" : "array" ,
213- "title" : "Interfaces" ,
214- "uniqueItems" : True ,
215- "additionalItems" : True ,
216- "propertyOrder" : 2 ,
217- "items" : {
218- "title" : "Interface" ,
219- "oneOf" : [
220- {"$ref" : "#/definitions/dialup_interface" }
221- ]
222- }
214+ "items" : {"oneOf" : [{"$ref" : "#/definitions/dialup_interface" }]}
223215 },
224216 "routes" : {
225217 "items" : {
Original file line number Diff line number Diff line change 1+ import unittest
2+
3+ from netjsonconfig import OpenWrt
4+ from netjsonconfig .utils import _TabsMixin
5+
6+
7+ class TestDialup (unittest .TestCase , _TabsMixin ):
8+ maxDiff = None
9+
10+ _dialup_interface_netjson = {
11+ "interfaces" : [
12+ {
13+ "mtu" : 1448 ,
14+ "network" : "xdsl" ,
15+ "type" : "dialup" ,
16+ "name" : "dsl0" ,
17+ "password" : "jf93nf82o023$" ,
18+ "username" : "dsluser" ,
19+ "proto" : "pppoe" ,
20+ },
21+ ]
22+ }
23+
24+ _dialup_interface_uci = """package network
25+
26+ config interface 'xdsl'
27+ option ifname 'dsl0'
28+ option mtu '1448'
29+ option password 'jf93nf82o023$'
30+ option proto 'pppoe'
31+ option username 'dsluser'
32+ """
33+
34+ def test_render_dialup_interface (self ):
35+ result = OpenWrt (self ._dialup_interface_netjson ).render ()
36+ expected = self ._tabs (self ._dialup_interface_uci )
37+ self .assertEqual (result , expected )
38+
39+ def test_parse_dialup_interface (self ):
40+ result = OpenWrt (native = self ._dialup_interface_uci ).config
41+ expected = self ._dialup_interface_netjson
42+ self .assertDictEqual (result , expected )
Original file line number Diff line number Diff line change @@ -601,25 +601,21 @@ def test_parse_custom_proto(self):
601601 native = self ._tabs (
602602 """package network
603603
604- config interface 'ppp0 '
604+ config interface 'custom_if0 '
605605 option device '/dev/usb/modem1'
606- option ifname 'ppp0 '
606+ option ifname 'custom_if0 '
607607 option ipv6 '1'
608608 option keepalive '3'
609- option password 'pwd0123'
610- option proto 'ppp'
611- option username 'user1'
609+ option proto 'custom'
612610"""
613611 )
614612 expected = {
615613 "interfaces" : [
616614 {
617- "name" : "ppp0 " ,
615+ "name" : "custom_if0 " ,
618616 "type" : "other" ,
619- "proto" : "ppp " ,
617+ "proto" : "custom " ,
620618 "device" : "/dev/usb/modem1" ,
621- "username" : "user1" ,
622- "password" : "pwd0123" ,
623619 "keepalive" : '3' ,
624620 "ipv6" : '1' ,
625621 }
You can’t perform that action at this time.
0 commit comments