summaryrefslogtreecommitdiff
path: root/test/e2e/common_test.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-01-05 13:10:56 -0600
committerBrent Baude <bbaude@redhat.com>2022-02-02 13:03:45 -0600
commit7d3ad6081f6598b8fa6385409e5109f11f29254f (patch)
treee68f74bfc0393443ee322380fee4940ca043aba3 /test/e2e/common_test.go
parentc2d0011b723428c622b99cf633439f84c4bf901a (diff)
downloadpodman-7d3ad6081f6598b8fa6385409e5109f11f29254f.tar.gz
podman-7d3ad6081f6598b8fa6385409e5109f11f29254f.tar.bz2
podman-7d3ad6081f6598b8fa6385409e5109f11f29254f.zip
netavark e2e tests
enabled e2e tests for netavark Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r--test/e2e/common_test.go127
1 files changed, 114 insertions, 13 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 796ae8141..f843a8984 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"math/rand"
+ "net"
"os"
"os/exec"
"path/filepath"
@@ -46,7 +47,7 @@ type PodmanTestIntegration struct {
PodmanTest
ConmonBinary string
Root string
- CNIConfigDir string
+ NetworkConfigDir string
OCIRuntime string
RunRoot string
StorageOptions string
@@ -199,6 +200,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
host := GetHostDistributionInfo()
cwd, _ := os.Getwd()
+ root := filepath.Join(tempDir, "root")
podmanBinary := filepath.Join(cwd, "../../bin/podman")
if os.Getenv("PODMAN_BINARY") != "" {
podmanBinary = os.Getenv("PODMAN_BINARY")
@@ -235,11 +237,26 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
ociRuntime = "crun"
}
os.Setenv("DISABLE_HC_SYSTEMD", "true")
- CNIConfigDir := "/etc/cni/net.d"
+
+ networkBackend := CNI
+ networkConfigDir := "/etc/cni/net.d"
if rootless.IsRootless() {
- CNIConfigDir = filepath.Join(os.Getenv("HOME"), ".config/cni/net.d")
+ networkConfigDir = filepath.Join(os.Getenv("HOME"), ".config/cni/net.d")
}
- if err := os.MkdirAll(CNIConfigDir, 0755); err != nil {
+
+ if strings.ToLower(os.Getenv("NETWORK_BACKEND")) == "netavark" {
+ networkBackend = Netavark
+ networkConfigDir = "/etc/containers/networks"
+ if rootless.IsRootless() {
+ networkConfigDir = filepath.Join(root, "etc", "networks")
+ }
+ }
+
+ if err := os.MkdirAll(root, 0755); err != nil {
+ panic(err)
+ }
+
+ if err := os.MkdirAll(networkConfigDir, 0755); err != nil {
panic(err)
}
@@ -251,7 +268,6 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
storageFs = os.Getenv("STORAGE_FS")
storageOptions = "--storage-driver " + storageFs
}
-
p := &PodmanTestIntegration{
PodmanTest: PodmanTest{
PodmanBinary: podmanBinary,
@@ -260,11 +276,12 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
RemoteTest: remote,
ImageCacheFS: storageFs,
ImageCacheDir: ImageCacheDir,
+ NetworkBackend: networkBackend,
},
ConmonBinary: conmonBinary,
- Root: filepath.Join(tempDir, "root"),
+ Root: root,
TmpDir: tempDir,
- CNIConfigDir: CNIConfigDir,
+ NetworkConfigDir: networkConfigDir,
OCIRuntime: ociRuntime,
RunRoot: filepath.Join(tempDir, "runroot"),
StorageOptions: storageOptions,
@@ -754,6 +771,18 @@ func SkipIfNotActive(unit string, reason string) {
}
}
+func SkipIfNetavark(p *PodmanTestIntegration) {
+ if p.NetworkBackend == Netavark {
+ Skip("This test is not compatible with the netavark network backend")
+ }
+}
+
+func SkipUntilAardvark(p *PodmanTestIntegration) {
+ if p.NetworkBackend == Netavark {
+ Skip("Re-enable when aardvark is functional")
+ }
+}
+
// PodmanAsUser is the exec call to podman on the filesystem with the specified uid/gid and environment
func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd string, env []string) *PodmanSessionIntegration {
podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false, false, nil, nil)
@@ -815,7 +844,9 @@ func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache boo
if p.RemoteTest {
return args
}
- var debug string
+ var (
+ debug string
+ )
if _, ok := os.LookupEnv("DEBUG"); ok {
debug = "--log-level=debug --syslog=true "
}
@@ -825,12 +856,19 @@ func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache boo
eventsType = "none"
}
+ networkBackend := p.NetworkBackend.ToString()
+ networkDir := p.NetworkConfigDir
+ if p.NetworkBackend == Netavark {
+ networkDir = p.NetworkConfigDir
+ }
podmanOptions := strings.Split(fmt.Sprintf("%s--root %s --runroot %s --runtime %s --conmon %s --network-config-dir %s --cgroup-manager %s --tmpdir %s --events-backend %s",
- debug, p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager, p.TmpDir, eventsType), " ")
+ debug, p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, networkDir, p.CgroupManager, p.TmpDir, eventsType), " ")
if os.Getenv("HOOK_OPTION") != "" {
podmanOptions = append(podmanOptions, os.Getenv("HOOK_OPTION"))
}
+ podmanOptions = append(podmanOptions, "--network-backend", networkBackend)
+
podmanOptions = append(podmanOptions, strings.Split(p.StorageOptions, " ")...)
if !noCache {
cacheOptions := []string{"--storage-opt",
@@ -842,6 +880,11 @@ func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache boo
}
func writeConf(conf []byte, confPath string) {
+ if _, err := os.Stat(filepath.Dir(confPath)); os.IsNotExist(err) {
+ if err := os.MkdirAll(filepath.Dir(confPath), 777); err != nil {
+ fmt.Println(err)
+ }
+ }
if err := ioutil.WriteFile(confPath, conf, 777); err != nil {
fmt.Println(err)
}
@@ -856,10 +899,15 @@ func removeConf(confPath string) {
// generateNetworkConfig generates a cni config with a random name
// it returns the network name and the filepath
func generateNetworkConfig(p *PodmanTestIntegration) (string, string) {
+ var (
+ path string
+ conf string
+ )
// generate a random name to prevent conflicts with other tests
name := "net" + stringid.GenerateNonCryptoID()
- path := filepath.Join(p.CNIConfigDir, fmt.Sprintf("%s.conflist", name))
- conf := fmt.Sprintf(`{
+ if p.NetworkBackend != Netavark {
+ path = filepath.Join(p.NetworkConfigDir, fmt.Sprintf("%s.conflist", name))
+ conf = fmt.Sprintf(`{
"cniVersion": "0.3.0",
"name": "%s",
"plugins": [
@@ -884,12 +932,35 @@ func generateNetworkConfig(p *PodmanTestIntegration) (string, string) {
}
]
}`, name)
+ } else {
+ path = filepath.Join(p.NetworkConfigDir, fmt.Sprintf("%s.json", name))
+ conf = fmt.Sprintf(`
+{
+ "name": "%s",
+ "id": "e1ef2749024b88f5663ca693a9118e036d6bfc48bcfe460faf45e9614a513e5c",
+ "driver": "bridge",
+ "network_interface": "netavark1",
+ "created": "2022-01-05T14:15:10.975493521-06:00",
+ "subnets": [
+ {
+ "subnet": "10.100.0.0/16",
+ "gateway": "10.100.0.1"
+ }
+ ],
+ "ipv6_enabled": false,
+ "internal": false,
+ "dns_enabled": true,
+ "ipam_options": {
+ "driver": "host-local"
+ }
+}
+`, name)
+ }
writeConf([]byte(conf), path)
-
return name, path
}
-func (p *PodmanTestIntegration) removeCNINetwork(name string) {
+func (p *PodmanTestIntegration) removeNetwork(name string) {
session := p.Podman([]string{"network", "rm", "-f", name})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeNumerically("<=", 1), "Exit code must be 0 or 1")
@@ -937,3 +1008,33 @@ func writeYaml(content string, fileName string) error {
return nil
}
+
+// GetPort finds an unused port on the system
+func GetPort() int {
+ a, err := net.ResolveTCPAddr("tcp", "localhost:0")
+ if err != nil {
+ Fail(fmt.Sprintf("unable to get free port: %v", err))
+ }
+
+ l, err := net.ListenTCP("tcp", a)
+ if err != nil {
+ Fail(fmt.Sprintf("unable to get free port: %v", err))
+ }
+ defer l.Close()
+ return l.Addr().(*net.TCPAddr).Port
+}
+
+func ncz(port int) bool {
+ timeout := 500 * time.Millisecond
+ for i := 0; i < 5; i++ {
+ ncCmd := []string{"-z", "localhost", fmt.Sprintf("%d", port)}
+ fmt.Printf("Running: nc %s\n", strings.Join(ncCmd, " "))
+ check := SystemExec("nc", ncCmd)
+ if check.ExitCode() == 0 {
+ return true
+ }
+ time.Sleep(timeout)
+ timeout++
+ }
+ return false
+}