Skip to content

T7492: Fix modem connection code #4527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: current
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/conf_mode/interfaces_wwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from vyos.configverify import verify_mtu_ipv6
from vyos.ifconfig import WWANIf
from vyos.utils.dict import dict_search
from vyos.utils.network import is_wwan_connected
from vyos.utils.process import cmd
from vyos.utils.process import call
from vyos.utils.process import DEVNULL
Expand Down Expand Up @@ -137,7 +138,7 @@ def apply(wwan):
break
sleep(0.250)

if 'shutdown_required' in wwan:
if 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname'])):
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The same compound condition is repeated later in the file (line 163). Consider extracting shutdown_required or disconnected logic into a descriptive boolean variable (e.g. reconnect_required) to reduce duplication and improve readability.

Suggested change
if 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname'])):
reconnect_required = 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname']))
if reconnect_required:

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound condition ('shutdown_required' in wwan or not is_wwan_connected(...)) is duplicated. Consider extracting it into a descriptive variable (e.g., needs_modem_connect) to DRY up the code and improve readability.

Suggested change
if 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname'])):
needs_modem_connect = 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname']))
if needs_modem_connect:

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The call to is_wwan_connected is made twice in this function. Consider calling it once, storing the result in a variable, and reusing it to avoid potential overhead or redundant checks.

Suggested change
if 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname'])):
is_connected = is_wwan_connected(wwan['ifname'])
if 'shutdown_required' in wwan or (not is_connected):

Copilot uses AI. Check for mistakes.

# we only need the modem number. wwan0 -> 0, wwan1 -> 1
modem = wwan['ifname'].lstrip('wwan')
base_cmd = f'mmcli --modem {modem}'
Expand All @@ -159,7 +160,7 @@ def apply(wwan):

return None

if 'shutdown_required' in wwan:
if 'shutdown_required' in wwan or (not is_wwan_connected(wwan['ifname'])):
ip_type = 'ipv4'
slaac = dict_search('ipv6.address.autoconf', wwan) != None
if 'address' in wwan:
Expand Down
Loading