aboutsummaryrefslogtreecommitdiff
path: root/libpod/network/cni/cni_suite_test.go
blob: f98869c960f6b8abc19a4b7169adce9fdb75fe44 (plain)
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
// +build linux

package cni_test

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/containers/podman/v3/libpod/network/cni"
	"github.com/containers/podman/v3/libpod/network/types"
	"github.com/containers/podman/v3/test/utils"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var cniPluginDirs = []string{
	"/usr/libexec/cni",
	"/usr/lib/cni",
	"/usr/local/lib/cni",
	"/opt/cni/bin",
}

func TestCni(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "CNI Suite")
}

func getNetworkInterface(cniConfDir string, machine bool) (types.ContainerNetwork, error) {
	return cni.NewCNINetworkInterface(cni.InitConfig{
		CNIConfigDir:  cniConfDir,
		CNIPluginDirs: cniPluginDirs,
		IsMachine:     machine,
		LockFile:      filepath.Join(cniConfDir, "cni.lock"),
	})
}

func SkipIfNoDnsname() {
	for _, path := range cniPluginDirs {
		f, err := os.Stat(filepath.Join(path, "dnsname"))
		if err == nil && f.Mode().IsRegular() {
			return
		}
	}
	Skip("dnsname cni plugin needs to be installed for this test")
}

func SkipIfNotFedora(msg string) {
	info := utils.GetHostDistributionInfo()
	if info.Distribution != "fedora" {
		Skip("Test can only run on Fedora: " + msg)
	}
}