* 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
120 lines
2.9 KiB
Go
120 lines
2.9 KiB
Go
package driverapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net"
|
|
"testing"
|
|
|
|
_ "github.com/docker/libnetwork/testutils"
|
|
"github.com/docker/libnetwork/types"
|
|
)
|
|
|
|
func TestIPDataMarshalling(t *testing.T) {
|
|
i := &IPAMData{
|
|
AddressSpace: "giallo",
|
|
Pool: &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
Gateway: &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
AuxAddresses: map[string]*net.IPNet{
|
|
"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
},
|
|
}
|
|
|
|
b, err := json.Marshal(i)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ii := &IPAMData{}
|
|
err = json.Unmarshal(b, &ii)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if i.AddressSpace != ii.AddressSpace || !types.CompareIPNet(i.Pool, ii.Pool) ||
|
|
!types.CompareIPNet(i.Gateway, ii.Gateway) ||
|
|
!compareAddresses(i.AuxAddresses, ii.AuxAddresses) {
|
|
t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%s\nDecoded:\n%s", i, ii)
|
|
}
|
|
}
|
|
|
|
func compareAddresses(a, b map[string]*net.IPNet) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
if len(a) > 0 {
|
|
for k := range a {
|
|
if !types.CompareIPNet(a[k], b[k]) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func TestValidateAndIsV6(t *testing.T) {
|
|
var err error
|
|
|
|
i := &IPAMData{
|
|
Pool: &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
Gateway: &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
AuxAddresses: map[string]*net.IPNet{
|
|
"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
|
|
},
|
|
}
|
|
|
|
// Check ip version
|
|
if i.IsV6() {
|
|
t.Fatalf("incorrect ip version returned")
|
|
}
|
|
orig := i.Pool
|
|
if i.Pool, err = types.ParseCIDR("2003::33/64"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !i.IsV6() {
|
|
t.Fatalf("incorrect ip version returned")
|
|
}
|
|
i.Pool = orig
|
|
|
|
// valid ip data
|
|
if err = i.Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// incongruent gw ver
|
|
if i.Gateway, err = types.ParseCIDR("2001::45/65"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = i.Validate(); err == nil {
|
|
t.Fatalf("expected error but succeded")
|
|
}
|
|
i.Gateway = nil
|
|
|
|
// incongruent secondary ip ver
|
|
if i.AuxAddresses["ip2"], err = types.ParseCIDR("2002::44/80"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = i.Validate(); err == nil {
|
|
t.Fatalf("expected error but succeded")
|
|
}
|
|
delete(i.AuxAddresses, "ip2")
|
|
|
|
// gw outside pool
|
|
if i.Gateway, err = types.ParseCIDR("10.10.15.254/24"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = i.Validate(); err == nil {
|
|
t.Fatalf("expected error but succeded")
|
|
}
|
|
i.Gateway = nil
|
|
|
|
// sec ip outside of pool
|
|
if i.AuxAddresses["ip1"], err = types.ParseCIDR("10.10.2.1/24"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = i.Validate(); err == nil {
|
|
t.Fatalf("expected error but succeded")
|
|
}
|
|
}
|