Skip to content

Commit

Permalink
[change] Render and parse custom proto
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp committed Mar 30, 2022
1 parent 361bb93 commit c94c130
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 3 additions & 2 deletions netjsonconfig/backends/openwrt/converters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class Interfaces(OpenWrtConverter):
'all': ['vlan_filtering', 'macaddr'],
}
_device_config = {}
_custom_protocols = ['ppp']

def to_intermediate_loop(self, block, result, index=None):
result.setdefault('network', [])
uci_name = self._get_uci_name(block.get('network') or block['name'])
address_list = self.__intermediate_addresses(block)
interface = self.__intermediate_interface(block, uci_name)
if self.dsa:
if self.dsa and interface.get('proto', None) not in self._custom_protocols:
uci_device = self.__intermediate_device(interface)
if uci_device:
result['network'].append(self.sorted_dict(uci_device))
Expand Down Expand Up @@ -266,7 +267,7 @@ def __clean_intermediate_bridge(self, interface):
"""
Removes options that are not required in the configuration.
"""
if self.dsa:
if self.dsa and interface.get('proto', None) not in self._custom_protocols:
repeated_options = (
['ifname', 'type', 'bridge_members']
+ self._bridge_interface_options['stp']
Expand Down
13 changes: 5 additions & 8 deletions tests/openwrt/test_interfaces_dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,9 @@ def test_render_custom_proto(self):
expected = self._tabs(
"""package network
config device 'device_ppp0'
option name 'ppp0'
config interface 'ppp0'
option device 'ppp0'
option device '/dev/usb/modem1'
option ifname 'ppp0'
option ipv6 '1'
option keepalive '3'
option password 'pwd0123'
Expand All @@ -663,11 +661,9 @@ def test_parse_custom_proto(self):
native = self._tabs(
"""package network
config device 'device_custom_if0'
option name 'custom_if0'
config interface 'custom_if0'
option device 'custom_if0'
option device '/dev/usb/modem1'
option ifname 'custom_if0'
option ipv6 '1'
option keepalive '3'
option proto 'custom'
Expand All @@ -679,6 +675,7 @@ def test_parse_custom_proto(self):
"name": "custom_if0",
"type": "other",
"proto": "custom",
"device": "/dev/usb/modem1",
"keepalive": '3',
"ipv6": '1',
}
Expand Down

0 comments on commit c94c130

Please sign in to comment.