Bug 1760072

Summary: cloudinit/net/sysconfig.py write incorrect config for dhcp-stateless openstack subnets
Product: Red Hat Enterprise Linux 7 Reporter: Harald Jensås <hjensas>
Component: cloud-initAssignee: Eduardo Otubo <eterrell>
Status: CLOSED CURRENTRELEASE QA Contact: xiachen
Severity: high Docs Contact:
Priority: high    
Version: 7.9CC: bfournie, eterrell, huzhao, jgreguske, linl, mtessun, ribarry, xiachen, yacao
Target Milestone: rcKeywords: DevelBlocker, OtherQA
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1760394 (view as bug list) Environment:
Last Closed: 2020-05-13 11:43:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1459187, 1760394    

Description Harald Jensås 2019-10-09 18:49:24 UTC
Description of problem:


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Install openstack
2. Create a subnet with:
ipv6_address_mode -c ipv6_ra_mode
+-------------------+------------------+
| Field | Value |
+-------------------+------------------+
| ipv6_address_mode | dhcpv6-stateless |
| ipv6_ra_mode | dhcpv6-stateless |
+-------------------+------------------+
3. Deploy an instance

Actual results:
File: openstack/latest/network_data.json
----------------------------------------
{
    "services": [
        {
            "type": "dns",
            "address": "fd12:3456:789a:1::1"
        }
    ],
    "networks": [
        {
            "network_id": "cf79eea0-6196-45a0-b9f8-ff9dd95eaab3",
            "type": "ipv6_dhcpv6-stateless",
            "services": [
                {
                    "type": "dns",
                    "address": "fd12:3456:789a:1::1"
                }
            ],
            "netmask": "ffff:ffff:ffff:ffff::",
            "link": "tap5910c6cc-2d",
            "routes": [
                {
                    "netmask": "::",
                    "network": "::",
                    "gateway": "fd12:3456:789a:1::fffe"
                }
            ],
            "ip_address": "fd12:3456:789a:1:f816:3eff:fee2:3aa3",
            "id": "network0"
        }
    ],
    "links": [
        {
            "vif_id": "5910c6cc-2d6e-4a44-bf05-2accdefd0316",
            "type": "phy",
            "ethernet_mac_address": "fa:16:3e:73:0d:96",
            "id": "tap5910c6cc-2d",
            "mtu": 1450
        }
    ]
}

The network config forces the client to try dhcpv6, not stateless e.g slaac. This fails when there is no DHCPv6 configured, or DHCPv6 is only configured to provide advanced options such a bootfile-url etc.

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
DHCPV6C=yes
HWADDR=fa:16:3e:73:0d:96
IPV6INIT=yes
IPV6_DEFAULTGW=fd12:3456:789a:1::fffe
MTU=1450
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

Expected results:
The configuration written should differentiate between dhcp6-stateful and dhcp6-stateless.
For dhcp6-stateless "DHCPV6C=yes" should be replaced by IPV6_AUTOCONF=yes as shown in the example below.

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
IPV6_AUTOCONF=yes
HWADDR=fa:16:3e:73:0d:96
IPV6INIT=yes
IPV6_DEFAULTGW=fd12:3456:789a:1::fffe
MTU=1450
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

Additional info:

The issue starts is in the following code[1]:
    if 'dhcp' in network['type']:
        t = 'dhcp6' if network['type'].startswith('ipv6') else 'dhcp4'
        subnet.update({
            'type': t,
        })

This makes the assumption that 'ipv6_dhcpv6-stateless' and 'ipv6_dhcpv6-stateful' can be treated the same.

Then in the code[2] the subnet type is checked and DHCPV6C is always used.
    if subnet_type == 'dhcp6':
        # TODO need to set BOOTPROTO to dhcp6 on SUSE
        iface_cfg['IPV6INIT'] = True
        iface_cfg['DHCPV6C'] = True

Grepping the source code it looks like this is only affecting cloudinit/net/sysconfig.py.

[1] https://git.launchpad.net/cloud-init/tree/cloudinit/sources/helpers/openstack.py#n587
[2] https://git.launchpad.net/cloud-init/tree/cloudinit/net/sysconfig.py#n346

Comment 2 Harald Jensås 2019-10-09 18:52:23 UTC
Description of problem:
cloud-init writed incorrect configuration for dhcp6-stateless subnets.

Version-Release number of selected component (if applicable):
cloud-init-18.5-3.el7.centos.x86_64

How reproducible:
100%

Comment 3 Harald Jensås 2019-10-09 21:54:08 UTC
Proposed fix: https://git.launchpad.net/~harald-jensas/cloud-init/commit/?id=d707d885ac5a2b5dccf491693de718613cbd2240

I will test this change, if it works I will propose it for merge upstream.

Comment 4 Harald Jensås 2019-10-10 03:08:34 UTC
The fix tested and works.

Upstream merge request: https://code.launchpad.net/~harald-jensas/cloud-init/+git/cloud-init/+merge/373932


(undercloud) [centos@undercloud ~]$ openstack subnet show ctlplane-subnet
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                                                                   |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| allocation_pools  | fd12:3456:789a:1::4-fd12:3456:789a:1::aaa9,fd12:3456:789a:1::b000-fd12:3456:789a:1::fffd,fd12:3456:789a:1::ffff-fd12:3456:789a:1:ffff:ffff:ffff:fffe    |
| cidr              | fd12:3456:789a:1::/64                                                                                                                                   |
| created_at        | 2019-10-09T23:57:12Z                                                                                                                                    |
| description       |                                                                                                                                                         |
| dns_nameservers   | fd12:3456:789a:1::1                                                                                                                                     |
| enable_dhcp       | True                                                                                                                                                    |
| gateway_ip        | fd12:3456:789a:1::fffe                                                                                                                                  |
| host_routes       |                                                                                                                                                         |
| id                | 968c4fd0-6cec-48f8-9e7f-d1d0c479fcd2                                                                                                                    |
| ip_version        | 6                                                                                                                                                       |
| ipv6_address_mode | dhcpv6-stateless                                                                                                                                        |
| ipv6_ra_mode      | dhcpv6-stateless                                                                                                                                        |
| location          | cloud='', project.domain_id=, project.domain_name='Default', project.id='9c8878b90225463e980c7d3425527e78', project.name='admin', region_name='', zone= |
| name              | ctlplane-subnet                                                                                                                                         |
| network_id        | c73d4b39-1e4f-4a48-a1d7-4d91da3f5cd9                                                                                                                    |
| prefix_length     | None                                                                                                                                                    |
| project_id        | 9c8878b90225463e980c7d3425527e78                                                                                                                        |
| revision_number   | 0                                                                                                                                                       |
| segment_id        | c37882bc-2169-411d-9825-86e673c677a2                                                                                                                    |
| service_types     |                                                                                                                                                         |
| subnetpool_id     | None                                                                                                                                                    |
| tags              |                                                                                                                                                         |
| updated_at        | 2019-10-09T23:57:12Z                                                                                                                                    |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
(undercloud) [centos@undercloud ~]$ openstack server list
+--------------------------------------+------------------------+--------+-----------------------------------------------+----------------+---------+
| ID                                   | Name                   | Status | Networks                                      | Image          | Flavor  |
+--------------------------------------+------------------------+--------+-----------------------------------------------+----------------+---------+
| 5cc2be01-8da5-47f8-8322-ed043fb13640 | overcloud-controller-0 | ACTIVE | ctlplane=fd12:3456:789a:1:f816:3eff:fe7d:50f0 | overcloud-full | control |
+--------------------------------------+------------------------+--------+-----------------------------------------------+----------------+---------+
(undercloud) [centos@undercloud ~]$ ping6 fd12:3456:789a:1:f816:3eff:fe7d:50f0
PING fd12:3456:789a:1:f816:3eff:fe7d:50f0(fd12:3456:789a:1:f816:3eff:fe7d:50f0) 56 data bytes
64 bytes from fd12:3456:789a:1:f816:3eff:fe7d:50f0: icmp_seq=1 ttl=64 time=0.974 ms

Comment 7 Harald Jensås 2019-11-20 18:03:17 UTC
Upstream commit to fix this merged: https://github.com/canonical/cloud-init/commit/62bbc262c3c7f633eac1d09ec78c055eef05166a