cloudbase / cloudbase-init

Cross-platform instance initialization
http://openstack.org
Apache License 2.0
421 stars 149 forks source link

Using network-config v1, can't have a MAC address with all numbers #152

Open neilgierman opened 1 month ago

neilgierman commented 1 month ago

We are still on CloudBase-Init 1.1.4 due to https://github.com/cloudbase/cloudbase-init/issues/147. In testing using kvm, I found that if my VM and network-config has a MAC address with only numbers, CloudBase-Init fails to parse it because "int type doesn't have lower function".

Seems there needs to be some protection that if a MAC is of int type, don't try toLower (or always force the incoming MAC to be string).

My network-config:

version: 1
config:
  # multiple interfaces or networks so we need a bond/team NIC
  - type: physical
    name: eth0
    mac_address: 52:54:00:00:00:01
    mtu: 1450
  - type: physical
    name: eth1
    mac_address: 52:54:00:00:00:02
    mtu: 1450
  - type: bond
    name: Default
    mac_address: 52:54:00:00:00:01
    bond_interfaces:
    -  eth0
    -  eth1
    params:
      bond-mode: active-backup
      xmit_hash_policy: layer2
      bond-lacp-rate: false

  # multiple networks with vlans
  - type: vlan
    name: "Default.0"
    vlan_link:  Default
    vlan_id: 0
    subnets:
    - type: static
      address: 192.168.122.200/24
      gateway: 192.168.122.1
      dns_nameservers:
        - 192.168.1.254

My virt-install command to bring up the VM:

virt-install \
  --name win2022 \
  --memory 2048 \
  --vcpus 2 \
  --disk size=50 \
  --cdrom ./Win2022.iso \
  --os-variant win2k22 \
  --network network=default,mac=52:54:00:00:00:01 \
  --network network=default,mac=52:54:00:00:00:02 \
  --graphics spice,listen=0.0.0.0 \
  --boot uefi \
  --disk path=./win2022.img,format=raw,cache=none,device=floppy

From error log: image

neilgierman commented 1 month ago

Linux cloud-init might have a similar issue however have not tried it: https://github.com/canonical/cloud-init/blob/main/cloudinit/net/network_state.py#L738

ader1990 commented 1 month ago

Hello,

I could reproduce the issue and it looks like a yaml quirk, as the yaml implementation sees the unquoted MAC addresses as integers.

Cloud-init has the same implementation and from a similar bug report, see https://github.com/canonical/cloud-init/issues/3703:

cloud-init suggests in network config docs above that mac_address values should be colon-delimited values such as 04:11:20:54:23:11.
 Also, the network-config file is read as yaml, any integer-only values present in yaml will be interpreted as an int instead of strings. 
To ensure yaml sees an integer value as a string you would need either single quotes or double quotes around a value.

Is it possible to use single quotes or double quotes around the MAC address?

Thank you, Adrian