Skip to content

Commit

Permalink
e2e tests: add test hotplugging an iface for an IPAM network
Browse files Browse the repository at this point in the history
This test explicitly requests both the IP address (which requires IPAM)
and the MAC address (which requires the `tuning` plugin) for the pod.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Oct 17, 2022
1 parent 271c070 commit 769e549
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ var _ = Describe("Multus dynamic networks controller", func() {
Expect(clients.RemoveNetworkFromPod(pod, networkName, namespace, ifaceToRemove)).To(Succeed())
Eventually(filterPodNonDefaultNetworks).Should(BeEmpty())
})

Context("a network with IPAM", func() {
const ipamNetworkToAdd = "tenant-network-ipam"

BeforeEach(func() {
_, err := clients.AddNetAttachDef(macvlanNetworkWitStaticIPAM(ipamNetworkToAdd, namespace))
Expect(err).NotTo(HaveOccurred())
})

It("can be hotplugged into a running pod", func() {
const (
ifaceToAddWithIPAM = "ens202"
ipAddressToAdd = "10.10.10.111"
netmaskLen = 24
)

macAddress := "02:03:04:05:06:07"
Expect(clients.AddNetworkToPod(pod, &nettypes.NetworkSelectionElement{
Name: ipamNetworkToAdd,
Namespace: namespace,
IPRequest: []string{ipWithMask(ipAddressToAdd, netmaskLen)},
InterfaceRequest: ifaceToAddWithIPAM,
MacRequest: macAddress,
})).To(Succeed())
Eventually(filterPodNonDefaultNetworks).Should(
ContainElements(
nettypes.NetworkStatus{
Name: namespacedName(namespace, ipamNetworkToAdd),
Interface: ifaceToAddWithIPAM,
IPs: []string{ipAddressToAdd},
Mac: macAddress,
},
))
})
})
})
})
})
Expand Down Expand Up @@ -153,6 +188,28 @@ func macvlanNetworkWithoutIPAM(networkName string, namespaceName string) *nettyp
return generateNetAttachDefSpec(networkName, namespaceName, macvlanConfig)
}

func macvlanNetworkWitStaticIPAM(networkName string, namespaceName string) *nettypes.NetworkAttachmentDefinition {
macvlanConfig := fmt.Sprintf(`{
"cniVersion": "1.0.0",
"disableCheck": true,
"name": "%s",
"plugins": [
{
"type": "macvlan",
"capabilities": { "ips": true },
"master": "eth1",
"mode": "bridge",
"ipam": {
"type": "static"
}
}, {
"type": "tuning"
}
]
}`, networkName)
return generateNetAttachDefSpec(networkName, namespaceName, macvlanConfig)
}

func generateNetAttachDefSpec(name, namespace, config string) *nettypes.NetworkAttachmentDefinition {
return &nettypes.NetworkAttachmentDefinition{
TypeMeta: metav1.TypeMeta{
Expand Down

0 comments on commit 769e549

Please sign in to comment.