bandwidth: increase test coverage to 1.0.0 and older spec versions

Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
Dan Williams 2021-02-11 20:15:56 -06:00
parent 02cdaafe93
commit da52be35bc
2 changed files with 904 additions and 1054 deletions

File diff suppressed because it is too large Load Diff

View File

@ -106,7 +106,7 @@ func makeTcpClientInNS(netns string, address string, port int, numBytes int) {
Expect(string(out)).To(Equal(message)) Expect(string(out)).To(Equal(message))
} }
func createVeth(hostNamespace string, hostVethIfName string, containerNamespace string, containerVethIfName string, hostIP []byte, containerIP []byte, hostIfaceMTU int) { func createVeth(hostNs ns.NetNS, hostVethIfName string, containerNs ns.NetNS, containerVethIfName string, hostIP []byte, containerIP []byte, hostIfaceMTU int) {
vethDeviceRequest := &netlink.Veth{ vethDeviceRequest := &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
Name: hostVethIfName, Name: hostVethIfName,
@ -116,10 +116,7 @@ func createVeth(hostNamespace string, hostVethIfName string, containerNamespace
PeerName: containerVethIfName, PeerName: containerVethIfName,
} }
hostNs, err := ns.GetNS(hostNamespace) err := hostNs.Do(func(_ ns.NetNS) error {
Expect(err).NotTo(HaveOccurred())
err = hostNs.Do(func(_ ns.NetNS) error {
if err := netlink.LinkAdd(vethDeviceRequest); err != nil { if err := netlink.LinkAdd(vethDeviceRequest); err != nil {
return fmt.Errorf("creating veth pair: %s", err) return fmt.Errorf("creating veth pair: %s", err)
} }
@ -129,11 +126,6 @@ func createVeth(hostNamespace string, hostVethIfName string, containerNamespace
return fmt.Errorf("failed to find newly-created veth device %q: %v", containerVethIfName, err) return fmt.Errorf("failed to find newly-created veth device %q: %v", containerVethIfName, err)
} }
containerNs, err := ns.GetNS(containerNamespace)
if err != nil {
return err
}
err = netlink.LinkSetNsFd(containerVeth, int(containerNs.Fd())) err = netlink.LinkSetNsFd(containerVeth, int(containerNs.Fd()))
if err != nil { if err != nil {
return fmt.Errorf("failed to move veth to container namespace: %s", err) return fmt.Errorf("failed to move veth to container namespace: %s", err)
@ -169,8 +161,6 @@ func createVeth(hostNamespace string, hostVethIfName string, containerNamespace
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
containerNs, err := ns.GetNS(containerNamespace)
Expect(err).NotTo(HaveOccurred())
err = containerNs.Do(func(_ ns.NetNS) error { err = containerNs.Do(func(_ ns.NetNS) error {
peerAddr := &net.IPNet{ peerAddr := &net.IPNet{
IP: hostIP, IP: hostIP,
@ -203,7 +193,7 @@ func createVeth(hostNamespace string, hostVethIfName string, containerNamespace
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
func createVethInOneNs(namespace, vethName, peerName string) { func createVethInOneNs(netNS ns.NetNS, vethName, peerName string) {
vethDeviceRequest := &netlink.Veth{ vethDeviceRequest := &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
Name: vethName, Name: vethName,
@ -212,10 +202,7 @@ func createVethInOneNs(namespace, vethName, peerName string) {
PeerName: peerName, PeerName: peerName,
} }
netNS, err := ns.GetNS(namespace) err := netNS.Do(func(_ ns.NetNS) error {
Expect(err).NotTo(HaveOccurred())
err = netNS.Do(func(_ ns.NetNS) error {
if err := netlink.LinkAdd(vethDeviceRequest); err != nil { if err := netlink.LinkAdd(vethDeviceRequest); err != nil {
return fmt.Errorf("failed to create veth pair: %v", err) return fmt.Errorf("failed to create veth pair: %v", err)
} }
@ -229,11 +216,8 @@ func createVethInOneNs(namespace, vethName, peerName string) {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
func createMacvlan(namespace, master, macvlanName string) { func createMacvlan(netNS ns.NetNS, master, macvlanName string) {
netNS, err := ns.GetNS(namespace) err := netNS.Do(func(_ ns.NetNS) error {
Expect(err).NotTo(HaveOccurred())
err = netNS.Do(func(_ ns.NetNS) error {
m, err := netlink.LinkByName(master) m, err := netlink.LinkByName(master)
if err != nil { if err != nil {
return fmt.Errorf("failed to lookup master %q: %v", master, err) return fmt.Errorf("failed to lookup master %q: %v", master, err)