Skip to content
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

Add support to set static IPs, gateway, DNS to wired/wireless networks #5

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

nikeflight
Copy link

@nikeflight nikeflight commented Jan 16, 2025

  1. As per the team discussion.

Keep the wired-network logic simple.

If eth is plugged in, enable ethernet.
If not, disable ethernet.

  1. Create piaware-config.txt for debian-bookworm

a) Remove the wired-network option. No point in having it since it's based on whether an ethernet cable is physically plugged in.
b) Remove mention of dhc.

  1. Added support for setting static IPs, gateway, DNS to wired/wireless networks
  2. Unit Tests

Create piaware-config.txt for debian-bookworm
@nikeflight nikeflight requested a review from eric1tran January 16, 2025 15:26
setting static IP
setting gateway
setting netmask
setting nameservers
…, dns

Added unit test for generate-network-config-bookworm.service
@nikeflight nikeflight changed the title Removed logic to disable ethernet Add support to set static IPs, gateway, DNS to wired/wireless networks Jan 17, 2025
replace default values for wireless-type and wired-type to "network-manager"
Add start-network.service, start_network.py to up the connections aft…
@eric1tran eric1tran requested a review from mutability January 21, 2025 17:35
debian-bookworm/piaware-config.txt Outdated Show resolved Hide resolved
scripts/start_network.py Outdated Show resolved Hide resolved
… the connection profile before NM spins up

Change network-manager back to dhcp in piaware_config.py
…st will ignore any setting value for a particular key from that file.
Copy link
Collaborator

@mutability mutability left a comment

Choose a reason for hiding this comment

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

Some initial feedback. I need to do a wider review of the older changes at some point as I haven't looked at those in detail yet.

debian-bookworm/piaware-config.txt Outdated Show resolved Hide resolved
Wants=config-ready.target
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /usr/lib/piaware-support/generate-network-config-bookworm.py
ExecStart=/usr/bin/python3 /usr/lib/piaware-support/generate_network_config_bookworm.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we want a shebang interpreter here, not explicitly refer to python3 in the service file

Copy link
Author

Choose a reason for hiding this comment

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

As in:

Add #!/usr/bin/evn python3 to generate_network_config_bookworm.py.
Make it executable (chmod +x). I think we can do this in the rules folder.
Call it in this file like ExecStart=/usr/lib/piaware-support/generate_network_config_bookworm.py

Or is there a simpler way to do this.

Copy link
Contributor

@eric1tran eric1tran Jan 23, 2025

Choose a reason for hiding this comment

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

Yes I think the goal is to be able to call it in the .service file without python3 and the .py extension...i.e. ExecStart=/usr/lib/piaware-support/generate_network_config_bookworm

So you could just rename the file without the .py extension, add the shebang, and chmod +x it.

ipv4 += configure_static_network("wired", config)
ipv4 += "method=manual\n"
except ValueError:
ipv4 += "method=auto\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This hides a multitude of errors in a non-obvious way. Bad config should really result in user-visible errors.

scripts/generate_network_config_bookworm.py Outdated Show resolved Hide resolved
if not config.get("wireless-network"):
print("wireless-network set to no")
return

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you change from wireless-network yes to wireless-network no, then without a cleanup step, this will leave behind the old wireless.nmconnection with the old config.

I mentioned this in slack earlier and I thought you said the files were written unconditionally? If not then you need cleanup.

Copy link
Author

Choose a reason for hiding this comment

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

Yes I got my wires crossed.

We can write the files unconditionally. The autoconnect field will determine if the wireless/wired network will be enabled/disabled.

self.settings["wired-address"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wired-netmask"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
# Setting broadcast address directly through boot/firmare/piaware-config.txt has been deprecated.
self.settings["wired-broadcast"] = MetadataSettings(sdonly=True, network=True, setting_type="str", ignore_list=[BOOT_PIAWARE_CONF])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this setting ignored, but only from specific files?

Copy link
Author

Choose a reason for hiding this comment

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

I added this as a way to deprecate or ignore settings.

I guess it makes sense to just have the logic be ignore any settings for this value from all files.

self.settings["wireless-gateway"] = MetadataSettings(sdonly=True, network=True)
self.settings["wireless-nameservers"] = MetadataSettings(default = ["8.8.8.8", "8.8.4.4"], sdonly=True, network=True)
self.settings["wireless-address"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-broadcast"] = MetadataSettings(sdonly=True, network=True, setting_type="str", ignore_list=[BOOT_PIAWARE_CONF])
Copy link
Collaborator

Choose a reason for hiding this comment

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

as above

scripts/piaware_config.py Outdated Show resolved Hide resolved
@@ -210,6 +214,13 @@ def validate_uuid(self, val: str, version=4) -> bool:
def validate_gain(self, val: str) -> bool:
return self.validate_double(val) or (isinstance(val, str) and val == "max")

def check_if_file_in_ignore_list(self, key, file_name) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you defaulted ignore_list to [] then this function becomes just return (file_name in self.settings[key].ignore_list) which is brief enough you may not even need a function for it.

Moved MetadataSettings to be a dict literal
Change subprocess calls to use os module
We write unconditionally to connection files. We set autoconnect variable in order to enable/disable the network
Remove debian-bookworm/piaware-config.txt
Fix unit tests
Fix dict initialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants