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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
//go:build linux || freebsd
package integration
import (
"os"
"path/filepath"
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func createNetworkDevice(name string) {
session := SystemExec("ip", []string{"link", "add", name, "type", "bridge"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
}
func deleteNetworkDevice(name string) {
session := SystemExec("ip", []string{"link", "delete", name})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
}
func createContainersConfFileWithDeviceIfaceName(pTest *PodmanTestIntegration) {
configPath := filepath.Join(pTest.TempDir, "containers.conf")
containersConf := []byte("[containers]\ninterface_name = \"device\"\n")
err := os.WriteFile(configPath, containersConf, os.ModePerm)
Expect(err).ToNot(HaveOccurred())
// Set custom containers.conf file
os.Setenv("CONTAINERS_CONF_OVERRIDE", configPath)
if IsRemote() {
pTest.RestartRemoteService()
}
}
var _ = Describe("Podman container interface name", func() {
It("podman container interface name for bridge network", func() {
// Assert that the network interface name inside container for
// bridge network is ethX regardless of interface_name setting
// in the containers.conf file.
netName1 := createNetworkName("bridge")
netName2 := createNetworkName("bridge")
defer podmanTest.removeNetwork(netName1)
nc1 := podmanTest.Podman([]string{"network", "create", netName1})
nc1.WaitWithDefaultTimeout()
Expect(nc1).Should(ExitCleanly())
defer podmanTest.removeNetwork(netName2)
nc2 := podmanTest.Podman([]string{"network", "create", netName2})
nc2.WaitWithDefaultTimeout()
Expect(nc2).Should(ExitCleanly())
for _, override := range []bool{false, true} {
if override {
createContainersConfFileWithDeviceIfaceName(podmanTest)
}
ctr := podmanTest.Podman([]string{"run", "-d", "--network", netName1, "--name", "test", ALPINE, "top"})
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly())
exec1 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"})
exec1.WaitWithDefaultTimeout()
Expect(exec1).Should(ExitCleanly())
Expect(exec1.OutputToString()).Should(ContainSubstring("eth0"))
conn := podmanTest.Podman([]string{"network", "connect", netName2, "test"})
conn.WaitWithDefaultTimeout()
Expect(conn).Should(ExitCleanly())
exec2 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth1"})
exec2.WaitWithDefaultTimeout()
Expect(exec2).Should(ExitCleanly())
Expect(exec2.OutputToString()).Should(ContainSubstring("eth1"))
rm := podmanTest.Podman([]string{"rm", "--time=0", "-f", "test"})
rm.WaitWithDefaultTimeout()
Expect(rm).Should(ExitCleanly())
}
})
It("podman container interface name for macvlan/ipvlan network with no parent", func() {
// Assert that the network interface name inside container for
// macvlan/ipvlan network with no parent interface is ethX
// regardless of interface_name setting in the containers.conf
// file.
for _, override := range []bool{false, true} {
if override {
createContainersConfFileWithDeviceIfaceName(podmanTest)
}
for _, driverType := range []string{"macvlan", "ipvlan"} {
netName1 := createNetworkName(driverType)
netName2 := createNetworkName(driverType)
// There is no nic created by the macvlan/ipvlan driver.
defer podmanTest.removeNetwork(netName1)
nc1 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "--subnet", "10.10.0.0/24", netName1})
nc1.WaitWithDefaultTimeout()
Expect(nc1).Should(ExitCleanly())
ctr := podmanTest.Podman([]string{"run", "-d", "--network", netName1, "--name", "test", ALPINE, "top"})
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly())
exec1 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"})
exec1.WaitWithDefaultTimeout()
Expect(exec1).Should(ExitCleanly())
Expect(exec1.OutputToString()).Should(ContainSubstring("eth0"))
defer podmanTest.removeNetwork(netName2)
nc2 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "--subnet", "10.25.40.0/24", netName2})
nc2.WaitWithDefaultTimeout()
Expect(nc2).Should(ExitCleanly())
conn := podmanTest.Podman([]string{"network", "connect", netName2, "test"})
conn.WaitWithDefaultTimeout()
Expect(conn).Should(ExitCleanly())
exec2 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth1"})
exec2.WaitWithDefaultTimeout()
Expect(exec2).Should(ExitCleanly())
Expect(exec2.OutputToString()).Should(ContainSubstring("eth1"))
rm := podmanTest.Podman([]string{"rm", "--time=0", "-f", "test"})
rm.WaitWithDefaultTimeout()
Expect(rm).Should(ExitCleanly())
}
}
})
It("podman container interface name with default scheme for macvlan/ipvlan network with parent", func() {
// Assert that the network interface name inside container for
// macvlan/ipvlan network, created with a specific parent
// interface, continues to be ethX when interface_name in the
// containers.conf file is set to default value, i.e., "".
SkipIfRootless("cannot create network device in rootless mode.")
for _, driverType := range []string{"macvlan", "ipvlan"} {
// Create a nic to be used as a parent for macvlan/ipvlan network.
nicName1 := createNetworkName("nic")[:8]
nicName2 := createNetworkName("nic")[:8]
netName1 := createNetworkName(driverType)
netName2 := createNetworkName(driverType)
parent1 := "parent=" + nicName1
parent2 := "parent=" + nicName2
defer deleteNetworkDevice(nicName1)
createNetworkDevice(nicName1)
defer podmanTest.removeNetwork(netName1)
nc1 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "-o", parent1, "--subnet", "10.10.0.0/24", netName1})
nc1.WaitWithDefaultTimeout()
Expect(nc1).Should(ExitCleanly())
ctr := podmanTest.Podman([]string{"run", "-d", "--network", netName1, "--name", "test", ALPINE, "top"})
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly())
exec1 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"})
exec1.WaitWithDefaultTimeout()
Expect(exec1).Should(ExitCleanly())
Expect(exec1.OutputToString()).Should(ContainSubstring("eth0"))
defer deleteNetworkDevice(nicName2)
createNetworkDevice(nicName2)
defer podmanTest.removeNetwork(netName2)
nc2 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "-o", parent2, "--subnet", "10.25.40.0/24", netName2})
nc2.WaitWithDefaultTimeout()
Expect(nc2).Should(ExitCleanly())
conn := podmanTest.Podman([]string{"network", "connect", netName2, "test"})
conn.WaitWithDefaultTimeout()
Expect(conn).Should(ExitCleanly())
exec2 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth1"})
exec2.WaitWithDefaultTimeout()
Expect(exec2).Should(ExitCleanly())
Expect(exec2.OutputToString()).Should(ContainSubstring("eth1"))
rm := podmanTest.Podman([]string{"rm", "--time=0", "-f", "test"})
rm.WaitWithDefaultTimeout()
Expect(rm).Should(ExitCleanly())
}
})
It("podman container interface name with device scheme for macvlan/ipvlan network with parent", func() {
// Assert that the network interface name inside container for
// macvlan/ipvlan network, created with a specific parent
// interface, is the parent interface name ethX when
// interface_name in the containers.conf file is set to "device"
SkipIfRootless("cannot create network device in rootless mode.")
createContainersConfFileWithDeviceIfaceName(podmanTest)
for _, driverType := range []string{"macvlan", "ipvlan"} {
// Create a nic to be used as a parent for the network.
nicName1 := createNetworkName("nic")[:8]
nicName2 := createNetworkName("nic")[:8]
netName1 := createNetworkName(driverType)
netName2 := createNetworkName(driverType)
parent1 := "parent=" + nicName1
parent2 := "parent=" + nicName2
defer deleteNetworkDevice(nicName1)
createNetworkDevice(nicName1)
defer podmanTest.removeNetwork(netName1)
nc1 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "-o", parent1, "--subnet", "10.10.0.0/24", netName1})
nc1.WaitWithDefaultTimeout()
Expect(nc1).Should(ExitCleanly())
ctr := podmanTest.Podman([]string{"run", "-d", "--network", netName1, "--name", "test", ALPINE, "top"})
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly())
exec1 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", nicName1})
exec1.WaitWithDefaultTimeout()
Expect(exec1).Should(ExitCleanly())
Expect(exec1.OutputToString()).Should(ContainSubstring(nicName1))
defer deleteNetworkDevice(nicName2)
createNetworkDevice(nicName2)
defer podmanTest.removeNetwork(netName2)
nc2 := podmanTest.Podman([]string{"network", "create", "-d", driverType, "-o", parent2, "--subnet", "10.25.40.0/24", netName2})
nc2.WaitWithDefaultTimeout()
Expect(nc2).Should(ExitCleanly())
conn := podmanTest.Podman([]string{"network", "connect", netName2, "test"})
conn.WaitWithDefaultTimeout()
Expect(conn).Should(ExitCleanly())
exec2 := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", nicName2})
exec2.WaitWithDefaultTimeout()
Expect(exec2).Should(ExitCleanly())
Expect(exec2.OutputToString()).Should(ContainSubstring(nicName2))
rm := podmanTest.Podman([]string{"rm", "--time=0", "-f", "test"})
rm.WaitWithDefaultTimeout()
Expect(rm).Should(ExitCleanly())
}
})
})
|