network Renderer for rhel is unavailable when render bond/vlan interface.

Bug #1682014 reported by lewis Liu
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
cloud-init
Confirmed
Medium
Unassigned

Bug Description

In rhel, when use clodinit to config network from network_data.json, network renderer cann't work well when render bond or vlan.
In sysconfig renderer, '_render_bond_interfaces' method has a wrong logic when type is bond,there is no 'bond-master' in iface object.
apart from this, '_render_bond_interfaces' and '_render_vlan_interfaces' should also process _render_subnet too. IMO, this two method should like this:

    @classmethod
    def _render_bond_interfaces(cls, network_state, iface_contents):
        bond_filter = renderer.filter_by_type('bond')
        for iface in network_state.iter_interfaces(bond_filter):
            iface_name = iface['name']
            iface_cfg = iface_contents[iface_name]
            cls._render_bonding_opts(iface_cfg, iface)
            iface_subnets = iface.get("subnets", [])
            route_cfg = iface_cfg.routes
            if len(iface_subnets) == 1:
                cls._render_subnet(iface_cfg, route_cfg, iface_subnets[0])
            elif len(iface_subnets) > 1:
                for i, iface_subnet in enumerate(iface_subnets,
                                                 start=len(iface.children)):
                    iface_sub_cfg = iface_cfg.copy()
                    iface_sub_cfg.name = "%s:%s" % (iface_name, i)
                    iface.children.append(iface_sub_cfg)
                    cls._render_subnet(iface_sub_cfg, route_cfg, iface_subnet)
            master_cfgs = [iface_cfg]
            master_cfgs.extend(iface_cfg.children)
            for master_cfg in master_cfgs:
                master_cfg['BONDING_MASTER'] = True
                master_cfg.kind = 'bond'

    @classmethod
    def _render_vlan_interfaces(cls, network_state, iface_contents):
        vlan_filter = renderer.filter_by_type('vlan')
        for iface in network_state.iter_interfaces(vlan_filter):
            iface_name = iface['name']
            iface_cfg = iface_contents[iface_name]
            iface_cfg['VLAN'] = True
            iface_cfg['PHYSDEV'] = iface_name[:iface_name.rfind('.')]
            iface_subnets = iface.get("subnets", [])
            route_cfg = iface_cfg.routes
            if len(iface_subnets) == 1:
                cls._render_subnet(iface_cfg, route_cfg, iface_subnets[0])
            elif len(iface_subnets) > 1:
                for i, iface_subnet in enumerate(iface_subnets,
                                                 start=len(iface.children)):
                    iface_sub_cfg = iface_cfg.copy()
                    iface_sub_cfg.name = "%s:%s" % (iface_name, i)
                    iface.children.append(iface_sub_cfg)
                    cls._render_subnet(iface_sub_cfg, route_cfg, iface_subnet)

Ryan Harper (raharper)
Changed in cloud-init:
status: New → Confirmed
tags: added: centos7
Revision history for this message
Scott Moser (smoser) wrote :

Heres a recreate:

$ cat bond.yaml
## Notes:
## * I had to add 'subnets' to the physical entries. that is a bug too.
## * if 'mac_address' is omitted from bond0, bond should use first slave addr
##
version: 1
config:
  - type: physical
    name: eth0
    subnets: []
  - type: physical
    name: eth1
    subnets: []
  - type: bond
    name: bond0
    mac_address: "aa:bb:cc:dd:ee:ff"
    bond_interfaces: [eth0, eth1]
    params:
      bond-mode: active-backup
    subnets:
      - type: dhcp4

$ PYTHONPATH=$PWD ./tools/net-convert.py --network-data=bond.yaml --kind=yaml \
    --output-kind=sysconfig --directory=out.d
...
Traceback (most recent call last):
  File "./tools/net-convert.py", line 82, in <module>
    main()
  File "./tools/net-convert.py", line 78, in main
    r.render_network_state(ns, target=args.directory)
  File "/home/smoser-public/src/cloud-init/cloud-init/cloudinit/net/sysconfig.py", line 397, in render_network_state
    network_state).items():
  File "/home/smoser-public/src/cloud-init/cloud-init/cloudinit/net/sysconfig.py", line 379, in _render_sysconfig
    cls._render_bond_interfaces(network_state, iface_contents)
  File "/home/smoser-public/src/cloud-init/cloud-init/cloudinit/net/sysconfig.py", line 315, in _render_bond_interfaces
    iface_master_name = iface['bond-master']
KeyError: 'bond-master'

Changed in cloud-init:
importance: Undecided → Medium
Revision history for this message
Ryan Harper (raharper) wrote :

This is a more complete fix for bonds

GUO Larry (larrygu)
tags: added: redhat7
Revision history for this message
Ryan Harper (raharper) wrote :

This appears to have been fixed in master already at commit:

hash: 51febf7363692d7947fe17a4fbfcb85058168ccb
subject: sysconfig: fix rendering of bond, bridge and vlan types.

Likely a duplicate of https://bugs.launchpad.net/cloud-init/+bug/1695092 which is fixed in 17.1

Revision history for this message
Scott Moser (smoser) wrote :

I'm marking this as a dupe of bug 1695092 if this is not the case and this is still an issue, please feel free to give information and un-dupe.

Thanks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.