* 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
133 lines
4.3 KiB
Go
133 lines
4.3 KiB
Go
package operations
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/vmware/vic/lib/apiservers/portlayer/client"
|
|
)
|
|
|
|
func TestNewPodStopper(t *testing.T) {
|
|
_, ip, _, _ := createMocks(t)
|
|
client := client.Default
|
|
|
|
// Positive Cases
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
|
|
// Negative Cases
|
|
s, err = NewPodStopper(nil, ip)
|
|
assert.Nil(t, s, "Expected nil")
|
|
assert.Equal(t, err, PodStopperPortlayerClientError)
|
|
|
|
s, err = NewPodStopper(client, nil)
|
|
assert.Nil(t, s, "Expected nil")
|
|
assert.Equal(t, err, PodStopperIsolationProxyError)
|
|
}
|
|
|
|
func TestStopPod(t *testing.T) {
|
|
client := client.Default
|
|
_, ip, _, op := createMocks(t)
|
|
|
|
// Start with arguments
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
assert.Nil(t, err, "Expected nil")
|
|
|
|
// Set up the mocks for this test
|
|
ip.On("Handle", op, podID, podName).Return(podHandle, nil)
|
|
ip.On("UnbindScope", op, podHandle, podName).Return(podHandle, fakeEP, nil)
|
|
ip.On("SetState", op, podHandle, podName, "STOPPED").Return(podHandle, nil)
|
|
ip.On("CommitHandle", op, podHandle, podID, int32(-1)).Return(nil)
|
|
|
|
// Positive case
|
|
err = s.Stop(op, podID, podName)
|
|
assert.Nil(t, err, "Expected nil")
|
|
}
|
|
|
|
func TestStopPodErrorHandle(t *testing.T) {
|
|
client := client.Default
|
|
_, ip, _, op := createMocks(t)
|
|
|
|
// Start with arguments
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
assert.Nil(t, err, "Expected nil")
|
|
|
|
// Set up the mocks for this test
|
|
ip.On("UnbindScope", op, podHandle, podName).Return(podHandle, fakeEP, nil)
|
|
ip.On("SetState", op, podHandle, podName, "STOPPED").Return(podHandle, nil)
|
|
ip.On("CommitHandle", op, podHandle, podID, int32(-1)).Return(nil)
|
|
|
|
// Failed Handle
|
|
fakeErr := fakeError("invalid handle")
|
|
ip.On("Handle", op, podID, podName).Return("", fakeErr)
|
|
|
|
err = s.Stop(op, podID, podName)
|
|
assert.Equal(t, err, fakeErr, "Expected invalid handle error")
|
|
}
|
|
|
|
func TestStopPodErrorUnbindScope(t *testing.T) {
|
|
client := client.Default
|
|
_, ip, _, op := createMocks(t)
|
|
|
|
// Start with arguments
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
assert.Nil(t, err, "Expected nil")
|
|
|
|
// Set up the mocks for this test
|
|
ip.On("Handle", op, podID, podName).Return(podHandle, nil)
|
|
ip.On("SetState", op, podHandle, podName, "STOPPED").Return(podHandle, nil)
|
|
ip.On("CommitHandle", op, podHandle, podID, int32(-1)).Return(nil)
|
|
|
|
// Failed UnbindScope
|
|
fakeErr := fakeError("failed UnbindScope")
|
|
ip.On("UnbindScope", op, podHandle, podName).Return("", nil, fakeErr)
|
|
|
|
err = s.Stop(op, podID, podName)
|
|
assert.Equal(t, err, fakeErr, "Expected failed UnbindScope error")
|
|
}
|
|
|
|
func TestStopPodErrorSetState(t *testing.T) {
|
|
client := client.Default
|
|
_, ip, _, op := createMocks(t)
|
|
|
|
// Start with arguments
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
assert.Nil(t, err, "Expected nil")
|
|
|
|
// Set up the mocks for this test
|
|
ip.On("Handle", op, podID, podName).Return(podHandle, nil)
|
|
ip.On("UnbindScope", op, podHandle, podName).Return(podHandle, fakeEP, nil)
|
|
ip.On("CommitHandle", op, podHandle, podID, int32(-1)).Return(nil)
|
|
|
|
// Failed SetState
|
|
fakeErr := fakeError("failed SetState")
|
|
ip.On("SetState", op, podHandle, podName, "STOPPED").Return("", fakeErr)
|
|
err = s.Stop(op, podID, podName)
|
|
assert.Equal(t, err, fakeErr, "Expected failed SetState error")
|
|
}
|
|
|
|
func TestStopPodErrorCommit(t *testing.T) {
|
|
client := client.Default
|
|
_, ip, _, op := createMocks(t)
|
|
|
|
// Start with arguments
|
|
s, err := NewPodStopper(client, ip)
|
|
assert.NotNil(t, s, "Expected non-nil creating a pod Stopper but received nil")
|
|
assert.Nil(t, err, "Expected nil")
|
|
|
|
// Set up the mocks for this test
|
|
ip.On("Handle", op, podID, podName).Return(podHandle, nil)
|
|
ip.On("UnbindScope", op, podHandle, podName).Return(podHandle, fakeEP, nil)
|
|
ip.On("SetState", op, podHandle, podName, "STOPPED").Return(podHandle, nil)
|
|
|
|
// Failed Commit
|
|
fakeErr := fakeError("failed Commit")
|
|
ip.On("CommitHandle", op, podHandle, podID, int32(-1)).Return(fakeErr)
|
|
err = s.Stop(op, podID, podName)
|
|
assert.Equal(t, err, fakeErr ,"Expected failed Commit error")
|
|
} |