Skip to content

Commit

Permalink
[fix] Removed device configuration block for modemmanager interface #316
Browse files Browse the repository at this point in the history


Fixes #316
  • Loading branch information
pandafy authored and nemesifier committed Oct 16, 2024
1 parent 5d41601 commit 1ddddcf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
4 changes: 4 additions & 0 deletions docs/source/backends/openwrt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,8 @@ The following *configuration dictionary*:
"name": "modem0",
"mtu": 1500,
"signalrate": 5,
"loglevel": "ERR",
"force_link": True,
}
]
}
Expand All @@ -1700,6 +1702,8 @@ Will be rendered as follows:
config interface 'modem0'
option apn 'apn.operator.com'
option device '/sys/devices/platform/ahb/1b000000.usb/usb1/1-1'
option force_link '1'
option loglevel 'ERR'
option lowpower '0'
option metric '50'
option password 'pwd123456'
Expand Down
17 changes: 3 additions & 14 deletions netjsonconfig/backends/openwrt/converters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ class Interfaces(OpenWrtConverter):
}
_device_config = {}
_custom_protocols = ['ppp']
_proto_dsa_conflict = ['modemmanager', 'modem-manager']
_interface_dsa_types = [
'loopback',
'ethernet',
'bridge',
'wireless',
] + _proto_dsa_conflict
]

def __set_dsa_interface(self, interface):
"""
Expand Down Expand Up @@ -452,18 +451,11 @@ def __netjson_interface(self, interface):
def __get_device_config_for_interface(self, interface):
device = interface.get('device')
name = interface.get('name')
if not name and interface.get('proto') in self._proto_dsa_conflict:
name = interface.get('.name')
device_config = self._device_config.get(device, self._device_config.get(name))
if not device_config:
return device_config
if interface.get('proto') in self._proto_dsa_conflict:
del device_config['type']
# ifname has been renamed to device in OpenWrt 21.02
if device_config.get('type') == 'bridge':
interface['ifname'] = interface.pop('device')
elif interface.get('proto') not in self._proto_dsa_conflict:
interface['ifname'] = interface.pop('device')
interface['ifname'] = interface.pop('device')
return device_config

def __netjson_dsa_interface(self, interface):
Expand All @@ -472,10 +464,7 @@ def __netjson_dsa_interface(self, interface):
else:
device_config = self.__get_device_config_for_interface(interface)
if device_config:
if (
device_config.pop('bridge_21', None)
or interface.get('proto') in self._proto_dsa_conflict
):
if device_config.pop('bridge_21', None):
for option in device_config:
if 'name' in option:
continue
Expand Down
28 changes: 27 additions & 1 deletion netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,33 @@
"propertyOrder": 1.9,
"description": "singal refresh rate in seconds",
},
}
"force_link": {
"type": "boolean",
"title": "Force link",
"format": "checkbox",
"default": True,
"description": (
"Set interface properties regardless of the link carrier"
" (If set, carrier sense events do not invoke hotplug handlers)."
),
"propertyOrder": 1.11,
},
"loglevel": {
"type": "string",
"title": "Log output level",
"default": "ERR",
"enum": ["ERR", "WARN", "INFO", "DEBUG"],
"options": {
"enum_titles": [
"Error",
"Warning",
"Info",
"Debug",
]
},
"propertyOrder": 1.12,
},
},
},
{"$ref": "#/definitions/base_interface_settings"},
],
Expand Down
10 changes: 6 additions & 4 deletions tests/openwrt/test_modemmanager_dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ class TestModemManager(unittest.TestCase, _TabsMixin):
"lowpower": False,
"mtu": 1500,
"signalrate": 5,
"loglevel": "ERR",
"force_link": True,
}
]
}

_modemmanager_interface_uci = """package network
config device 'device_wwan0'
option mtu '1500'
option name 'wwan0'
config interface 'wwan0'
option apn 'apn.vodafone.com'
option device '/sys/devices/platform/ahb/1b000000.usb/usb1/1-1'
option force_link '1'
option ifname 'wwan0'
option iptype 'ipv4v6'
option loglevel 'ERR'
option lowpower '0'
option metric '50'
option mtu '1500'
option password 'pwd123456'
option pincode '1234'
option proto 'modemmanager'
Expand Down

0 comments on commit 1ddddcf

Please sign in to comment.