Ubuntu Pastebin

Paste from smoser at Tue, 18 Jul 2017 21:22:07 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
commit dc930aac7f4ae05136b042fdcdd097a3149aeb00 (HEAD)
Author: Ryan Harper <ryan.harper@canonical.com>
Date:   Fri Jun 9 15:33:37 2017 -0500

    Use prefix for ipv6 and set v4 and v6 gateway keys, use DEFROUTE
    
    LP: #1704872

diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index ad8c268e..e4ffa7f5 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -311,7 +311,7 @@ class Renderer(renderer.Renderer):
                     if 'netmask' in subnet and str(subnet['netmask']) != "":
                         ipv6_cidr = (subnet['address'] +
                                      '/' +
-                                     str(subnet['netmask']))
+                                     str(subnet['prefix']))


## smoser
I think this is shorter written as:
+                    if subnet['prefix']:
+                        ipv6_cidr = (
+                            "%s/%s" % (subnet['address'], subnet['prefix']))

The 'subnet' here is the normalized subnet, right?
i thought the generic path was guaranteeing that we have a
prefix for all cases now.

Then, you dont have a unit test changes to accomodate this change.

## end smoser

                     else:
                         ipv6_cidr = subnet['address']
                     if ipv6_index == 0:
@@ -330,7 +330,11 @@ class Renderer(renderer.Renderer):
                         net_prefix_to_ipv4_mask(subnet['prefix'])
 
                 if 'gateway' in subnet:
-                    iface_cfg['GATEWAY'] = subnet['gateway']
+                    iface_cfg['DEFROUTE'] = True
+                    if ':' in subnet['gateway']:
+                        iface_cfg['IPV6_DEFAULTGW'] = subnet['gateway']
+                    else:
+                        iface_cfg['GATEWAY'] = subnet['gateway']

## smoser
## this hunk looked fine.
 
     @classmethod
     def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index dffe1781..af8c9983 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -476,7 +476,9 @@ NETWORKING=yes
 # Created by cloud-init on instance boot automatically, do not edit.
 #
 BOOTPROTO=none
+DEFROUTE=yes
 DEVICE=eth0
+GATEWAY=192.168.1.254
 IPADDR=192.168.1.5
 NETMASK=255.255.255.0
 GATEWAY=192.168.1.254
@@ -626,10 +628,12 @@ IPV6_AUTOCONF=no
 # Created by cloud-init on instance boot automatically, do not edit.
 #
 BOOTPROTO=none
+DEFROUTE=yes
 DEVICE=eth0
 IPV6ADDR=2607:f0d0:1002:0011::2/64
 GATEWAY=2607:f0d0:1002:0011::1
 IPV6INIT=yes
+IPV6_DEFAULTGW=2607:f0d0:1002:0011::1
 NM_CONTROLLED=no
 ONBOOT=yes
 TYPE=Ethernet
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 71c9c457..bcf72aeb 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -1161,6 +1161,7 @@ USERCTL=no
 # Created by cloud-init on instance boot automatically, do not edit.
 #
 BOOTPROTO=none
+DEFROUTE=yes
 DEVICE=interface0
 GATEWAY=10.0.2.2
 HWADDR=52:54:00:12:34:00
Download as text