Skip to content

Commit

Permalink
Alters cloud-init network rendering so that we use ValueWithMask from
Browse files Browse the repository at this point in the history
InterfaceInfos address members instead of the now-removed CIDRAddress.
  • Loading branch information
manadart committed Mar 30, 2021
1 parent 95492c2 commit 7c8f331
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cloudconfig/cloudinit/network_ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func GenerateNetplan(interfaces corenetwork.InterfaceInfos) (string, error) {
netPlan.Network.Version = 2
for _, info := range interfaces {
var iface netplan.Ethernet
cidr, err := info.CIDRAddress()
cidr, err := info.PrimaryAddress().ValueWithMask()
if err != nil && !errors.IsNotFound(err) {
return "", errors.Trace(err)
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func PrepareNetworkConfigFromInterfaces(interfaces corenetwork.InterfaceInfos) (
autoStarted.Add(ifaceName)
}

cidr, err := info.CIDRAddress()
cidr, err := info.PrimaryAddress().ValueWithMask()
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
Expand Down
34 changes: 17 additions & 17 deletions cloudconfig/cloudinit/network_ubuntu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ func (s *NetworkUbuntuSuite) SetUpTest(c *gc.C) {
s.jujuNetplanFile = filepath.Join(netplanFolder, "79-juju.yaml")

s.fakeInterfaces = corenetwork.InterfaceInfos{{
InterfaceName: "any0",
CIDR: "0.1.2.0/24",
ConfigType: corenetwork.ConfigStatic,
NoAutoStart: false,
Addresses: corenetwork.ProviderAddresses{corenetwork.NewProviderAddress("0.1.2.3")},
InterfaceName: "any0",
ConfigType: corenetwork.ConfigStatic,
NoAutoStart: false,
Addresses: corenetwork.ProviderAddresses{
corenetwork.NewProviderAddress("0.1.2.3", corenetwork.WithCIDR("0.1.2.0/24"))},
DNSServers: corenetwork.NewProviderAddresses("ns1.invalid", "ns2.invalid"),
DNSSearchDomains: []string{"foo", "bar"},
GatewayAddress: corenetwork.NewProviderAddress("0.1.2.1"),
MACAddress: "aa:bb:cc:dd:ee:f0",
MTU: 8317,
}, {
InterfaceName: "any1",
CIDR: "0.2.2.0/24",
ConfigType: corenetwork.ConfigStatic,
NoAutoStart: false,
Addresses: corenetwork.ProviderAddresses{corenetwork.NewProviderAddress("0.2.2.4")},
InterfaceName: "any1",
ConfigType: corenetwork.ConfigStatic,
NoAutoStart: false,
Addresses: corenetwork.ProviderAddresses{
corenetwork.NewProviderAddress("0.2.2.4", corenetwork.WithCIDR("0.2.2.0/24"))},
DNSServers: corenetwork.NewProviderAddresses("ns1.invalid", "ns2.invalid"),
DNSSearchDomains: []string{"foo", "bar"},
GatewayAddress: corenetwork.NewProviderAddress("0.2.2.1"),
Expand All @@ -108,12 +108,12 @@ func (s *NetworkUbuntuSuite) SetUpTest(c *gc.C) {
MACAddress: "aa:bb:cc:dd:ee:f4",
NoAutoStart: true,
}, {
InterfaceName: "any5",
ConfigType: corenetwork.ConfigStatic,
MACAddress: "aa:bb:cc:dd:ee:f5",
NoAutoStart: false,
CIDR: "2001:db8::/64",
Addresses: corenetwork.ProviderAddresses{corenetwork.NewProviderAddress("2001:db8::dead:beef")},
InterfaceName: "any5",
ConfigType: corenetwork.ConfigStatic,
MACAddress: "aa:bb:cc:dd:ee:f5",
NoAutoStart: false,
Addresses: corenetwork.ProviderAddresses{
corenetwork.NewProviderAddress("2001:db8::dead:beef", corenetwork.WithCIDR("2001:db8::/64"))},
GatewayAddress: corenetwork.NewProviderAddress("2001:db8::dead:f00"),
}}

Expand Down Expand Up @@ -555,7 +555,7 @@ func (s *NetworkUbuntuSuite) TestENIScriptHotplug(c *gc.C) {
}

func (s *NetworkUbuntuSuite) TestPrepareNetworkConfigFromInterfacesBadCIDRError(c *gc.C) {
s.fakeInterfaces[0].CIDR = "invalid"
s.fakeInterfaces[0].Addresses[0].CIDR = "invalid"
_, err := cloudinit.PrepareNetworkConfigFromInterfaces(s.fakeInterfaces)
c.Assert(err, gc.ErrorMatches, `invalid CIDR address: invalid`)
}
Expand Down

0 comments on commit 7c8f331

Please sign in to comment.