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

net: Passthough v2 netconfigs in netplan systems #1650

Merged
merged 5 commits into from Aug 24, 2022

Conversation

aciba90
Copy link
Contributor

@aciba90 aciba90 commented Aug 12, 2022

Proposed Commit Message

net: Passthough v2 raw net_conf in netplan systems

Adhere to Netplan Passthrough documented behavior,
not limiting v2 netplan configs to the subset of
props that cloud-init supports.

LP: #1978543

Additional Context

SC-1120
https://bugs.launchpad.net/cloud-init/+bug/1978543
Netplan Passthrough

Test Steps

cat > /tmp/lp1978543.yaml <<EOF
network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: false
      addresses: [10.0.4.10/24]
      nameservers:
        addresses: [10.0.4.1]
      routes:
      - to: default
        via: 10.0.4.1
        metric: 100
EOF

lxc init ubuntu-daily:jammy lp1978543
lxc file push /tmp/lp1978543.yaml lp1978543/etc/cloud/cloud.cfg.d/custom-networking.cfg
lxc file push /tmp/lp1978543.yaml lp1978543/root/
lxc start lp1978543
lxc exec lp1978543 -- cloud-init status --wait

lxc exec lp1978543 -- grep -in valueerror /var/log/cloud-init.log
# No errors found
$ lxc exec lp1978543 -- cat /etc/netplan/50-cloud-init.yaml
...
network:
    ethernets:
        enp0s3:
            addresses:
            - 10.0.4.10/24
            dhcp4: false
            nameservers:
                addresses:
                - 10.0.4.1
            routes:
            -   metric: 100
                to: default
                via: 10.0.4.1
    version: 2

lxc exec lp1978543 -- python3 -m cloudinit.cmd.main devel net-convert -m enp0s3,AA -O netplan --k yaml -p lp1978543.yaml -D ubuntu -d out
# No errors found

$ lxc exec lp1978543 -- cat out/etc/netplan/50-cloud-init.yaml
...
network:
    ethernets:
        enp0s3:
            addresses:
            - 10.0.4.10/24
            dhcp4: false
            nameservers:
                addresses:
                - 10.0.4.1
            routes:
            -   metric: 100
                to: default
                via: 10.0.4.1
    version: 2

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

I left two comments inline. Neither are strongly held though. Otherwise, looks good.

@@ -230,6 +236,16 @@ def _apply_network_from_network_config(self, netconfig, bring_up=True):
def generate_fallback_config(self):
return net.generate_fallback_config()

def _is_netplan(self) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Since most of this method is doing the same thing as the beginnning of _write_network_state, I think it might make more sense to fetch the renderer one time at the beginning of apply_network_config and pass it where it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -241,7 +257,11 @@ def apply_network_config(self, netconfig, bring_up=False) -> bool:
"""
# This method is preferred to apply_network which only takes
# a much less complete network config format (interfaces(5)).
network_state = parse_net_config_data(netconfig)
if self._is_netplan() and netconfig.get("version") == 2:
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how the network rendering abstraction is leaking into the distro code here. Do you think it's possible to push this section of code down into either parse_net_config_data or even into NetworkStateInterpreter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logic moved to NetworkStateInterpreter. The downside is that we have to pass the renderer around, but it looks more cohesive in this way. Thanks for the comment.

@TheRealFalcon TheRealFalcon self-assigned this Aug 23, 2022
@aciba90
Copy link
Contributor Author

aciba90 commented Aug 24, 2022

Thanks, @TheRealFalcon, for the review. I have addressed the comments and this PR is ready to be reviewed.

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Thanks @aciba90 , nice work here.

The isinstance checks feel a little awkward. Long term, it might make sense for us to add a name property to the renderers and check that instead, but not required for this PR.

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.

None yet

2 participants