Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion platform/net/ubuntu_net_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ func (net UbuntuNetManager) writeDHCPConfiguration(dnsServers []string, opts bos
return changed, nil
}

// The bosh-agent expects this file to be used for the network configuration
// Using 09- to make sure it takes priority over any other files
func interfaceConfigurationFile(name string) string {
interfaceBasename := fmt.Sprintf("10_%s.network", name)
interfaceBasename := fmt.Sprintf("09-%s.network", name)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return filepath.Join(systemdNetworkFolder, interfaceBasename)
}

Expand Down
9 changes: 9 additions & 0 deletions platform/net/ubuntu_net_manager_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !windows

package net_test

import "fmt"

func netFile(iface string) string {
return fmt.Sprintf("/etc/systemd/network/09-%s.network", iface)
}
24 changes: 12 additions & 12 deletions platform/net/ubuntu_net_manager_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ var _ = Describe("UbuntuNetManager (IPv6)", func() {
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_ethstatic1.network",
netFile("ethstatic1"),
))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethstatic1.network")
networkConfig := fs.GetFileTestStat(netFile("ethstatic1"))
Expect(networkConfig).ToNot(BeNil())

Expect(strings.Contains(networkConfig.StringContents(), `
Expand Down Expand Up @@ -239,10 +239,10 @@ Gateway=2001:db8::1
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
netFile("eth0"),
))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(ContainSubstring(`
[Match]
Expand Down Expand Up @@ -366,11 +366,11 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_ethstatic1.network",
"/etc/systemd/network/10_ethstatic2.network",
"/etc/systemd/network/10_ethstatic3.network",
netFile("ethstatic1"),
netFile("ethstatic2"),
netFile("ethstatic3"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethstatic1.network")
networkConfig := fs.GetFileTestStat(netFile("ethstatic1"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -387,7 +387,7 @@ DNS=9.9.9.9
DNSDefaultRoute=no

`))
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_ethstatic2.network")
networkConfig = fs.GetFileTestStat(netFile("ethstatic2"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -402,7 +402,7 @@ DNS=9.9.9.9
DNSDefaultRoute=no

`))
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_ethstatic3.network")
networkConfig = fs.GetFileTestStat(netFile("ethstatic3"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -450,9 +450,9 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_ethstatic1.network",
netFile("ethstatic1"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethstatic1.network")
networkConfig := fs.GetFileTestStat(netFile("ethstatic1"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down
99 changes: 58 additions & 41 deletions platform/net/ubuntu_net_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ dns-nameservers 8.8.8.8 9.9.9.9`
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
"/etc/systemd/network/10_eth1.network",
netFile("eth0"),
netFile("eth1"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -368,7 +368,7 @@ DNS=8.8.8.8
DNSDefaultRoute=no

`))
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_eth1.network")
networkConfig = fs.GetFileTestStat(netFile("eth1"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -424,12 +424,12 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
"/etc/systemd/network/10_eth1.network",
netFile("eth0"),
netFile("eth1"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_eth1.network")
networkConfig = fs.GetFileTestStat(netFile("eth1"))
Expect(networkConfig).ToNot(BeNil())
})

Expand Down Expand Up @@ -461,9 +461,9 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
netFile("eth0"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -531,10 +531,10 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
"/etc/systemd/network/10_eth1.network",
netFile("eth0"),
netFile("eth1"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -556,7 +556,7 @@ Destination=10.0.1.0/8
Gateway=3.4.5.6

`))
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_eth1.network")
networkConfig = fs.GetFileTestStat(netFile("eth1"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -613,9 +613,9 @@ DNSDefaultRoute=no
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
netFile("eth0"),
))
networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -651,11 +651,28 @@ Gateway=3.4.5.6
}, nil, nil)
Expect(err).ToNot(HaveOccurred())

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).ToNot(ContainSubstring("UseRoutes=no"))
})

It("generates a .network filename that sorts before the netplan file", func() {
stubInterfaces(map[string]boshsettings.Network{
"eth0": dhcpNetwork,
})
Expect(fs.WriteFileString("/run/systemd/network/10-netplan-eth0.network", "")).To(Succeed())

err := netManager.SetupNetworking(boshsettings.Networks{
"dhcp-1": dhcpNetwork,
}, nil, nil)
Expect(err).ToNot(HaveOccurred())

boshBase := strings.TrimPrefix(netFile("eth0"), "/etc/systemd/network/")
netplanBase := "10-netplan-eth0.network"
Expect(boshBase < netplanBase).To(BeTrue(),
"BOSH file %q must sort before netplan file %q", boshBase, netplanBase)
})

It("writes /etc/network/interfaces without dns-namservers if there are no dns servers", func() {
staticNetworkWithoutDNS := boshsettings.Network{
Type: "manual",
Expand All @@ -675,9 +692,9 @@ Gateway=3.4.5.6

matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf("/etc/systemd/network/10_ethstatic.network"))
Expect(matches).To(ConsistOf(netFile("ethstatic")))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethstatic.network")
networkConfig := fs.GetFileTestStat(netFile("ethstatic"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -709,9 +726,9 @@ Gateway=3.4.5.6

matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf("/etc/systemd/network/10_ethdhcp.network"))
Expect(matches).To(ConsistOf(netFile("ethdhcp")))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethdhcp.network")
networkConfig := fs.GetFileTestStat(netFile("ethdhcp"))
Expect(networkConfig).ToNot(BeNil())
// With no cloud-config dns the global scope is empty, so the DHCP-provided
// DNS on this link is the only external path and must stay the DNS default
Expand Down Expand Up @@ -1024,11 +1041,11 @@ prepend domain-name-servers 8.8.8.8, 9.9.9.9;
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_ethdhcp.network",
"/etc/systemd/network/10_ethstatic.network",
netFile("ethdhcp"),
netFile("ethstatic"),
))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethdhcp.network")
networkConfig := fs.GetFileTestStat(netFile("ethdhcp"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -1047,7 +1064,7 @@ UseRoutes=no

`))

networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_ethstatic.network")
networkConfig = fs.GetFileTestStat(netFile("ethstatic"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1089,7 +1106,7 @@ DNSDefaultRoute=no
}, nil, nil)
Expect(err).ToNot(HaveOccurred())

primaryConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethprimary.network")
primaryConfig := fs.GetFileTestStat(netFile("ethprimary"))
Expect(primaryConfig).ToNot(BeNil())
Expect(primaryConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -1106,7 +1123,7 @@ UseMTU=yes

`))

secondaryConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethsecondary.network")
secondaryConfig := fs.GetFileTestStat(netFile("ethsecondary"))
Expect(secondaryConfig).ToNot(BeNil())
Expect(secondaryConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1148,7 +1165,7 @@ UseRoutes=no
}, nil, nil)
Expect(err).ToNot(HaveOccurred())

sharedConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethshared.network")
sharedConfig := fs.GetFileTestStat(netFile("ethshared"))
Expect(sharedConfig).ToNot(BeNil())
Expect(sharedConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1202,9 +1219,9 @@ UseMTU=yes

matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf("/etc/systemd/network/10_ethshared.network"))
Expect(matches).To(ConsistOf(netFile("ethshared")))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethshared.network")
networkConfig := fs.GetFileTestStat(netFile("ethshared"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1267,9 +1284,9 @@ DNSDefaultRoute=no

matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).ToNot(HaveOccurred())
Expect(matches).To(ConsistOf("/etc/systemd/network/10_ethshared.network"))
Expect(matches).To(ConsistOf(netFile("ethshared")))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethshared.network")
networkConfig := fs.GetFileTestStat(netFile("ethshared"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1340,10 +1357,10 @@ Gateway=10.20.0.1
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_ethstatic.network",
netFile("ethstatic"),
))

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_ethstatic.network")
networkConfig := fs.GetFileTestStat(netFile("ethstatic"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1433,13 +1450,13 @@ nameserver 10.0.80.12
matches, err := fs.Ls("/etc/systemd/network/")
Expect(err).NotTo(HaveOccurred())
Expect(matches).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
"/etc/systemd/network/10_eth1.network",
netFile("eth0"),
netFile("eth1"),
))

format.TruncatedDiff = false

networkConfig := fs.GetFileTestStat("/etc/systemd/network/10_eth0.network")
networkConfig := fs.GetFileTestStat(netFile("eth0"))
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
[Match]
Expand All @@ -1459,7 +1476,7 @@ DNS=10.0.80.12
DNSDefaultRoute=no

`))
networkConfig = fs.GetFileTestStat("/etc/systemd/network/10_eth1.network")
networkConfig = fs.GetFileTestStat(netFile("eth1"))
Expect(networkConfig).ToNot(BeNil())
Expect(scrubMultipleLines(networkConfig.StringContents())).To(Equal(`# Generated by bosh-agent
[Match]
Expand Down Expand Up @@ -1526,7 +1543,7 @@ DNSDefaultRoute=no
}

Expect(files).To(ConsistOf(
"/etc/systemd/network/10_eth0.network",
netFile("eth0"),
"/etc/systemd/network/02_custom_unmanaged.network",
"/etc/systemd/network/04_special_unmanaged.network",
))
Expand All @@ -1545,9 +1562,9 @@ DNSDefaultRoute=no
})

It("returns networks that are defined in /etc/network/interfaces", func() {
err := fs.WriteFileString("/etc/systemd/network/10_fake-eth0.network", ``)
err := fs.WriteFileString(netFile("fake-eth0"), ``)
Expect(err).NotTo(HaveOccurred())
err = fs.WriteFileString("/etc/systemd/network/10_fake-eth2.network", ``)
err = fs.WriteFileString(netFile("fake-eth2"), ``)
Expect(err).NotTo(HaveOccurred())

interfaces, err := netManager.GetConfiguredNetworkInterfaces()
Expand Down
Loading