* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
193 lines
3.9 KiB
Go
193 lines
3.9 KiB
Go
package netlink
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
type arpEntry struct {
|
|
ip net.IP
|
|
mac net.HardwareAddr
|
|
}
|
|
|
|
type proxyEntry struct {
|
|
ip net.IP
|
|
dev int
|
|
}
|
|
|
|
func parseMAC(s string) net.HardwareAddr {
|
|
m, err := net.ParseMAC(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
func dumpContains(dump []Neigh, e arpEntry) bool {
|
|
for _, n := range dump {
|
|
if n.IP.Equal(e.ip) && (n.State&NUD_INCOMPLETE) == 0 {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func dumpContainsProxy(dump []Neigh, p proxyEntry) bool {
|
|
for _, n := range dump {
|
|
if n.IP.Equal(p.ip) && (n.LinkIndex == p.dev) && (n.Flags&NTF_PROXY) == NTF_PROXY {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func TestNeighAddDel(t *testing.T) {
|
|
tearDown := setUpNetlinkTest(t)
|
|
defer tearDown()
|
|
|
|
dummy := Dummy{LinkAttrs{Name: "neigh0"}}
|
|
if err := LinkAdd(&dummy); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ensureIndex(dummy.Attrs())
|
|
|
|
arpTable := []arpEntry{
|
|
{net.ParseIP("10.99.0.1"), parseMAC("aa:bb:cc:dd:00:01")},
|
|
{net.ParseIP("10.99.0.2"), parseMAC("aa:bb:cc:dd:00:02")},
|
|
{net.ParseIP("10.99.0.3"), parseMAC("aa:bb:cc:dd:00:03")},
|
|
{net.ParseIP("10.99.0.4"), parseMAC("aa:bb:cc:dd:00:04")},
|
|
{net.ParseIP("10.99.0.5"), parseMAC("aa:bb:cc:dd:00:05")},
|
|
}
|
|
|
|
// Add the arpTable
|
|
for _, entry := range arpTable {
|
|
err := NeighAdd(&Neigh{
|
|
LinkIndex: dummy.Index,
|
|
State: NUD_REACHABLE,
|
|
IP: entry.ip,
|
|
HardwareAddr: entry.mac,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighAdd: %v", err)
|
|
}
|
|
}
|
|
|
|
// Dump and see that all added entries are there
|
|
dump, err := NeighList(dummy.Index, 0)
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighList: %v", err)
|
|
}
|
|
|
|
for _, entry := range arpTable {
|
|
if !dumpContains(dump, entry) {
|
|
t.Errorf("Dump does not contain: %v", entry)
|
|
}
|
|
}
|
|
|
|
// Delete the arpTable
|
|
for _, entry := range arpTable {
|
|
err := NeighDel(&Neigh{
|
|
LinkIndex: dummy.Index,
|
|
IP: entry.ip,
|
|
HardwareAddr: entry.mac,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighDel: %v", err)
|
|
}
|
|
}
|
|
|
|
// TODO: seems not working because of cache
|
|
//// Dump and see that none of deleted entries are there
|
|
//dump, err = NeighList(dummy.Index, 0)
|
|
//if err != nil {
|
|
//t.Errorf("Failed to NeighList: %v", err)
|
|
//}
|
|
|
|
//for _, entry := range arpTable {
|
|
//if dumpContains(dump, entry) {
|
|
//t.Errorf("Dump contains: %v", entry)
|
|
//}
|
|
//}
|
|
|
|
if err := LinkDel(&dummy); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestNeighAddDelProxy(t *testing.T) {
|
|
tearDown := setUpNetlinkTest(t)
|
|
defer tearDown()
|
|
|
|
dummy := Dummy{LinkAttrs{Name: "neigh0"}}
|
|
if err := LinkAdd(&dummy); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ensureIndex(dummy.Attrs())
|
|
|
|
proxyTable := []proxyEntry{
|
|
{net.ParseIP("10.99.0.1"), dummy.Index},
|
|
{net.ParseIP("10.99.0.2"), dummy.Index},
|
|
{net.ParseIP("10.99.0.3"), dummy.Index},
|
|
{net.ParseIP("10.99.0.4"), dummy.Index},
|
|
{net.ParseIP("10.99.0.5"), dummy.Index},
|
|
}
|
|
|
|
// Add the proxyTable
|
|
for _, entry := range proxyTable {
|
|
err := NeighAdd(&Neigh{
|
|
LinkIndex: dummy.Index,
|
|
Flags: NTF_PROXY,
|
|
IP: entry.ip,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighAdd: %v", err)
|
|
}
|
|
}
|
|
|
|
// Dump and see that all added entries are there
|
|
dump, err := NeighProxyList(dummy.Index, 0)
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighList: %v", err)
|
|
}
|
|
|
|
for _, entry := range proxyTable {
|
|
if !dumpContainsProxy(dump, entry) {
|
|
t.Errorf("Dump does not contain: %v", entry)
|
|
}
|
|
}
|
|
|
|
// Delete the proxyTable
|
|
for _, entry := range proxyTable {
|
|
err := NeighDel(&Neigh{
|
|
LinkIndex: dummy.Index,
|
|
Flags: NTF_PROXY,
|
|
IP: entry.ip,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighDel: %v", err)
|
|
}
|
|
}
|
|
|
|
// Dump and see that none of deleted entries are there
|
|
dump, err = NeighProxyList(dummy.Index, 0)
|
|
if err != nil {
|
|
t.Errorf("Failed to NeighList: %v", err)
|
|
}
|
|
|
|
for _, entry := range proxyTable {
|
|
if dumpContainsProxy(dump, entry) {
|
|
t.Errorf("Dump contains: %v", entry)
|
|
}
|
|
}
|
|
|
|
if err := LinkDel(&dummy); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|