flannel: increase test coverage to 1.0.0 and older spec versions
Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
parent
f33eedb6eb
commit
8f7fe6d8e8
@ -31,6 +31,7 @@ import (
|
|||||||
var _ = Describe("Flannel", func() {
|
var _ = Describe("Flannel", func() {
|
||||||
var (
|
var (
|
||||||
originalNS ns.NetNS
|
originalNS ns.NetNS
|
||||||
|
targetNS ns.NetNS
|
||||||
onlyIpv4Input string
|
onlyIpv4Input string
|
||||||
onlyIpv6Input string
|
onlyIpv6Input string
|
||||||
dualStackInput string
|
dualStackInput string
|
||||||
@ -40,16 +41,6 @@ var _ = Describe("Flannel", func() {
|
|||||||
dataDir string
|
dataDir string
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
|
||||||
var err error
|
|
||||||
originalNS, err = testutils.NewNS()
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
|
||||||
|
|
||||||
AfterEach(func() {
|
|
||||||
Expect(originalNS.Close()).To(Succeed())
|
|
||||||
})
|
|
||||||
|
|
||||||
const inputTemplate = `{
|
const inputTemplate = `{
|
||||||
"name": "cni-flannel",
|
"name": "cni-flannel",
|
||||||
"type": "flannel",
|
"type": "flannel",
|
||||||
@ -95,6 +86,8 @@ FLANNEL_MTU=1472
|
|||||||
FLANNEL_IPMASQ=true
|
FLANNEL_IPMASQ=true
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const IFNAME = "eth0"
|
||||||
|
|
||||||
var writeSubnetEnv = func(contents string) string {
|
var writeSubnetEnv = func(contents string) string {
|
||||||
file, err := ioutil.TempFile("", "subnet.env")
|
file, err := ioutil.TempFile("", "subnet.env")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -114,17 +107,29 @@ FLANNEL_IPMASQ=true
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
var makeInput = func(inputIPAM string, subnetFile string) string {
|
var makeInput = func(cniVersion, inputIPAM string, subnetFile string) string {
|
||||||
ipamPart := ""
|
ipamPart := ""
|
||||||
if len(inputIPAM) > 0 {
|
if len(inputIPAM) > 0 {
|
||||||
ipamPart = ",\n \"ipam\":\n" + inputIPAM
|
ipamPart = ",\n \"ipam\":\n" + inputIPAM
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(inputTemplate, current.ImplementedSpecVersion, subnetFile, dataDir, ipamPart)
|
return fmt.Sprintf(inputTemplate, cniVersion, subnetFile, dataDir, ipamPart)
|
||||||
|
}
|
||||||
|
|
||||||
|
var makeHostLocalIPAM = func(dataDir string) string {
|
||||||
|
return fmt.Sprintf(`{
|
||||||
|
"type": "host-local",
|
||||||
|
"dataDir": "%s"
|
||||||
|
}`, dataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
var err error
|
var err error
|
||||||
|
originalNS, err = testutils.NewNS()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
targetNS, err = testutils.NewNS()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
// flannel subnet.env
|
// flannel subnet.env
|
||||||
onlyIpv4SubnetFile = writeSubnetEnv(onlyIpv4FlannelSubnetEnv)
|
onlyIpv4SubnetFile = writeSubnetEnv(onlyIpv4FlannelSubnetEnv)
|
||||||
onlyIpv6SubnetFile = writeSubnetEnv(onlyIpv6FlannelSubnetEnv)
|
onlyIpv6SubnetFile = writeSubnetEnv(onlyIpv6FlannelSubnetEnv)
|
||||||
@ -133,38 +138,42 @@ FLANNEL_IPMASQ=true
|
|||||||
// flannel state dir
|
// flannel state dir
|
||||||
dataDir, err = ioutil.TempDir("", "dataDir")
|
dataDir, err = ioutil.TempDir("", "dataDir")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
onlyIpv4Input = makeInput("", onlyIpv4SubnetFile)
|
|
||||||
onlyIpv6Input = makeInput("", onlyIpv6SubnetFile)
|
|
||||||
dualStackInput = makeInput("", dualStackSubnetFile)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
|
Expect(targetNS.Close()).To(Succeed())
|
||||||
|
Expect(testutils.UnmountNS(targetNS)).To(Succeed())
|
||||||
|
Expect(originalNS.Close()).To(Succeed())
|
||||||
|
Expect(testutils.UnmountNS(originalNS)).To(Succeed())
|
||||||
|
|
||||||
os.Remove(onlyIpv4SubnetFile)
|
os.Remove(onlyIpv4SubnetFile)
|
||||||
os.Remove(onlyIpv6SubnetFile)
|
os.Remove(onlyIpv6SubnetFile)
|
||||||
os.Remove(dualStackSubnetFile)
|
os.Remove(dualStackSubnetFile)
|
||||||
os.Remove(dataDir)
|
Expect(os.RemoveAll(dataDir)).To(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("CNI lifecycle", func() {
|
Describe("CNI lifecycle", func() {
|
||||||
|
for _, ver := range testutils.AllSpecVersions {
|
||||||
|
// Redefine ver inside for scope so real value is picked up by each dynamically defined It()
|
||||||
|
// See Gingkgo's "Patterns for dynamically generating tests" documentation.
|
||||||
|
ver := ver
|
||||||
|
|
||||||
Context("when using only ipv4 stack", func() {
|
Context("when using only ipv4 stack", func() {
|
||||||
It("uses dataDir for storing network configuration with ipv4 stack", func() {
|
It(fmt.Sprintf("[%s] uses dataDir for storing network configuration with ipv4 stack", ver), func() {
|
||||||
const IFNAME = "eth0"
|
inputIPAM := makeHostLocalIPAM(dataDir)
|
||||||
|
|
||||||
targetNs, err := testutils.NewNS()
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
defer targetNs.Close()
|
|
||||||
|
|
||||||
args := &skel.CmdArgs{
|
args := &skel.CmdArgs{
|
||||||
ContainerID: "some-container-id-ipv4",
|
ContainerID: "some-container-id-ipv4",
|
||||||
Netns: targetNs.Path(),
|
Netns: targetNS.Path(),
|
||||||
IfName: IFNAME,
|
IfName: IFNAME,
|
||||||
StdinData: []byte(onlyIpv4Input),
|
StdinData: []byte(makeInput(ver, inputIPAM, onlyIpv4SubnetFile)),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = originalNS.Do(func(ns.NetNS) error {
|
err := originalNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
By("calling ADD with ipv4 stack")
|
By("calling ADD with ipv4 stack")
|
||||||
|
GinkgoT().Logf("dataDir is %s", dataDir)
|
||||||
|
GinkgoT().Logf("conf is %s", args.StdinData)
|
||||||
resI, _, err := testutils.CmdAddWithArgs(args, func() error {
|
resI, _, err := testutils.CmdAddWithArgs(args, func() error {
|
||||||
return cmdAdd(args)
|
return cmdAdd(args)
|
||||||
})
|
})
|
||||||
@ -190,13 +199,14 @@ FLANNEL_IPMASQ=true
|
|||||||
"subnet": "10.1.17.0/24"
|
"subnet": "10.1.17.0/24"
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
"type": "host-local"
|
"type": "host-local",
|
||||||
|
"dataDir": "%s"
|
||||||
},
|
},
|
||||||
"isGateway": true,
|
"isGateway": true,
|
||||||
"mtu": 1472,
|
"mtu": 1472,
|
||||||
"name": "cni-flannel",
|
"name": "cni-flannel",
|
||||||
"type": "bridge"
|
"type": "bridge"
|
||||||
}`, current.ImplementedSpecVersion)
|
}`, ver, dataDir)
|
||||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||||
|
|
||||||
result, err := current.NewResultFromResult(resI)
|
result, err := current.NewResultFromResult(resI)
|
||||||
@ -226,21 +236,16 @@ FLANNEL_IPMASQ=true
|
|||||||
})
|
})
|
||||||
|
|
||||||
Context("when using only ipv6 stack", func() {
|
Context("when using only ipv6 stack", func() {
|
||||||
It("uses dataDir for storing network configuration with ipv6 stack", func() {
|
It(fmt.Sprintf("[%s] uses dataDir for storing network configuration with ipv6 stack", ver), func() {
|
||||||
const IFNAME = "eth0"
|
inputIPAM := makeHostLocalIPAM(dataDir)
|
||||||
|
|
||||||
targetNs, err := testutils.NewNS()
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
defer targetNs.Close()
|
|
||||||
|
|
||||||
args := &skel.CmdArgs{
|
args := &skel.CmdArgs{
|
||||||
ContainerID: "some-container-id-ipv6",
|
ContainerID: "some-container-id-ipv6",
|
||||||
Netns: targetNs.Path(),
|
Netns: targetNS.Path(),
|
||||||
IfName: IFNAME,
|
IfName: IFNAME,
|
||||||
StdinData: []byte(onlyIpv6Input),
|
StdinData: []byte(makeInput(ver, inputIPAM, onlyIpv6SubnetFile)),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = originalNS.Do(func(ns.NetNS) error {
|
err := originalNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
By("calling ADD with ipv6 stack")
|
By("calling ADD with ipv6 stack")
|
||||||
@ -269,13 +274,14 @@ FLANNEL_IPMASQ=true
|
|||||||
"subnet": "fc00::/64"
|
"subnet": "fc00::/64"
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
"type": "host-local"
|
"type": "host-local",
|
||||||
|
"dataDir": "%s"
|
||||||
},
|
},
|
||||||
"isGateway": true,
|
"isGateway": true,
|
||||||
"mtu": 1472,
|
"mtu": 1472,
|
||||||
"name": "cni-flannel",
|
"name": "cni-flannel",
|
||||||
"type": "bridge"
|
"type": "bridge"
|
||||||
}`, current.ImplementedSpecVersion)
|
}`, ver, dataDir)
|
||||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||||
|
|
||||||
result, err := current.NewResultFromResult(resI)
|
result, err := current.NewResultFromResult(resI)
|
||||||
@ -305,21 +311,16 @@ FLANNEL_IPMASQ=true
|
|||||||
})
|
})
|
||||||
|
|
||||||
Context("when using dual stack", func() {
|
Context("when using dual stack", func() {
|
||||||
It("uses dataDir for storing network configuration with dual stack", func() {
|
It(fmt.Sprintf("[%s] uses dataDir for storing network configuration with dual stack", ver), func() {
|
||||||
const IFNAME = "eth0"
|
inputIPAM := makeHostLocalIPAM(dataDir)
|
||||||
|
|
||||||
targetNs, err := testutils.NewNS()
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
defer targetNs.Close()
|
|
||||||
|
|
||||||
args := &skel.CmdArgs{
|
args := &skel.CmdArgs{
|
||||||
ContainerID: "some-container-id-dual-stack",
|
ContainerID: "some-container-id-dual-stack",
|
||||||
Netns: targetNs.Path(),
|
Netns: targetNS.Path(),
|
||||||
IfName: IFNAME,
|
IfName: IFNAME,
|
||||||
StdinData: []byte(dualStackInput),
|
StdinData: []byte(makeInput(ver, inputIPAM, dualStackSubnetFile)),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = originalNS.Do(func(ns.NetNS) error {
|
err := originalNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
By("calling ADD with dual stack")
|
By("calling ADD with dual stack")
|
||||||
@ -354,13 +355,14 @@ FLANNEL_IPMASQ=true
|
|||||||
"subnet": "fc00::/64"
|
"subnet": "fc00::/64"
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
"type": "host-local"
|
"type": "host-local",
|
||||||
|
"dataDir": "%s"
|
||||||
},
|
},
|
||||||
"isGateway": true,
|
"isGateway": true,
|
||||||
"mtu": 1472,
|
"mtu": 1472,
|
||||||
"name": "cni-flannel",
|
"name": "cni-flannel",
|
||||||
"type": "bridge"
|
"type": "bridge"
|
||||||
}`, current.ImplementedSpecVersion)
|
}`, ver, dataDir)
|
||||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||||
|
|
||||||
result, err := current.NewResultFromResult(resI)
|
result, err := current.NewResultFromResult(resI)
|
||||||
@ -388,9 +390,22 @@ FLANNEL_IPMASQ=true
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("loadFlannelNetConf", func() {
|
Describe("loadFlannelNetConf", func() {
|
||||||
|
var (
|
||||||
|
onlyIpv4Input string
|
||||||
|
onlyIpv6Input string
|
||||||
|
dualStackInput string
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
onlyIpv4Input = makeInput(current.ImplementedSpecVersion, "", onlyIpv4SubnetFile)
|
||||||
|
onlyIpv6Input = makeInput(current.ImplementedSpecVersion, "", onlyIpv6SubnetFile)
|
||||||
|
dualStackInput = makeInput(current.ImplementedSpecVersion, "", dualStackSubnetFile)
|
||||||
|
})
|
||||||
|
|
||||||
Context("when subnetFile and dataDir are specified with ipv4 stack", func() {
|
Context("when subnetFile and dataDir are specified with ipv4 stack", func() {
|
||||||
It("loads flannel network config with ipv4 stack", func() {
|
It("loads flannel network config with ipv4 stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
||||||
@ -553,7 +568,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided with ipv4 stack", func() {
|
Context("when input IPAM is provided with ipv4 stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
||||||
onlyIpv4Input = makeInput(inputIPAM, onlyIpv4SubnetFile)
|
onlyIpv4Input = makeInput(current.ImplementedSpecVersion, inputIPAM, onlyIpv4SubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM accordingly with ipv4 stack", func() {
|
It("configures Delegate IPAM accordingly with ipv4 stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
||||||
@ -575,7 +590,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided with ipv6 stack", func() {
|
Context("when input IPAM is provided with ipv6 stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
||||||
onlyIpv6Input = makeInput(inputIPAM, onlyIpv6SubnetFile)
|
onlyIpv6Input = makeInput(current.ImplementedSpecVersion, inputIPAM, onlyIpv6SubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM accordingly with ipv6 stack", func() {
|
It("configures Delegate IPAM accordingly with ipv6 stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(onlyIpv6Input))
|
conf, err := loadFlannelNetConf([]byte(onlyIpv6Input))
|
||||||
@ -597,7 +612,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided with dual stack", func() {
|
Context("when input IPAM is provided with dual stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM(inputIPAMType, inputIPAMRoutes, "")
|
||||||
dualStackInput = makeInput(inputIPAM, dualStackSubnetFile)
|
dualStackInput = makeInput(current.ImplementedSpecVersion, inputIPAM, dualStackSubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM accordingly with dual stack", func() {
|
It("configures Delegate IPAM accordingly with dual stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(dualStackInput))
|
conf, err := loadFlannelNetConf([]byte(dualStackInput))
|
||||||
@ -619,7 +634,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided without 'type' with ipv4 stack", func() {
|
Context("when input IPAM is provided without 'type' with ipv4 stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
||||||
onlyIpv4Input = makeInput(inputIPAM, onlyIpv4SubnetFile)
|
onlyIpv4Input = makeInput(current.ImplementedSpecVersion, inputIPAM, onlyIpv4SubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM with 'host-local' ipam with ipv4 stack", func() {
|
It("configures Delegate IPAM with 'host-local' ipam with ipv4 stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
conf, err := loadFlannelNetConf([]byte(onlyIpv4Input))
|
||||||
@ -640,7 +655,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided without 'type' with ipv6 stack", func() {
|
Context("when input IPAM is provided without 'type' with ipv6 stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
||||||
onlyIpv6Input = makeInput(inputIPAM, onlyIpv6SubnetFile)
|
onlyIpv6Input = makeInput(current.ImplementedSpecVersion, inputIPAM, onlyIpv6SubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM with 'host-local' ipam with ipv6 stack", func() {
|
It("configures Delegate IPAM with 'host-local' ipam with ipv6 stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(onlyIpv6Input))
|
conf, err := loadFlannelNetConf([]byte(onlyIpv6Input))
|
||||||
@ -661,7 +676,7 @@ FLANNEL_IPMASQ=true
|
|||||||
Context("when input IPAM is provided without 'type' with dual stack", func() {
|
Context("when input IPAM is provided without 'type' with dual stack", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
inputIPAM := makeInputIPAM("", inputIPAMRoutes, "")
|
||||||
dualStackInput = makeInput(inputIPAM, dualStackSubnetFile)
|
dualStackInput = makeInput(current.ImplementedSpecVersion, inputIPAM, dualStackSubnetFile)
|
||||||
})
|
})
|
||||||
It("configures Delegate IPAM with 'host-local' ipam with dual stack", func() {
|
It("configures Delegate IPAM with 'host-local' ipam with dual stack", func() {
|
||||||
conf, err := loadFlannelNetConf([]byte(dualStackInput))
|
conf, err := loadFlannelNetConf([]byte(dualStackInput))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user