Fix the dependency issue (#231)
This commit is contained in:
137
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/container_proxy.go
generated
vendored
137
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/container_proxy.go
generated
vendored
@@ -88,10 +88,16 @@ type VicContainerProxy interface {
|
||||
UnbindContainerFromNetwork(ctx context.Context, vc *viccontainer.VicContainer, handle string) (string, error)
|
||||
CommitContainerHandle(ctx context.Context, handle, containerID string, waitTime int32) error
|
||||
|
||||
// TODO: we should not be returning a swagger model here, however we do not have a solid architected return for this yet.
|
||||
InspectTask(op trace.Operation, handle string, eid string, cid string) (*models.TaskInspectResponse, error)
|
||||
BindTask(op trace.Operation, handle string, eid string) (string, error)
|
||||
WaitTask(op trace.Operation, cid string, cname string, eid string) error
|
||||
|
||||
Handle(ctx context.Context, id, name string) (string, error)
|
||||
|
||||
Stop(ctx context.Context, vc *viccontainer.VicContainer, name string, seconds *int, unbound bool) error
|
||||
State(ctx context.Context, vc *viccontainer.VicContainer) (*types.ContainerState, error)
|
||||
GetStateFromHandle(op trace.Operation, handle string) (string, string, error)
|
||||
Wait(ctx context.Context, vc *viccontainer.VicContainer, timeout time.Duration) (*types.ContainerState, error)
|
||||
Signal(ctx context.Context, vc *viccontainer.VicContainer, sig uint64) error
|
||||
Resize(ctx context.Context, id string, height, width int32) error
|
||||
@@ -489,6 +495,115 @@ func (c *ContainerProxy) CommitContainerHandle(ctx context.Context, handle, cont
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ContainerProxy) InspectTask(op trace.Operation, handle string, eid string, cid string) (*models.TaskInspectResponse, error) {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("handle(%s), eid(%s), cid(%s)", handle, eid, cid)))
|
||||
|
||||
if c.client == nil {
|
||||
return nil, errors.NillPortlayerClientError("ContainerProxy")
|
||||
}
|
||||
|
||||
// inspect the Task to obtain ProcessConfig
|
||||
config := &models.TaskInspectConfig{
|
||||
Handle: handle,
|
||||
ID: eid,
|
||||
}
|
||||
|
||||
// FIXME: right now we are only using this path for exec targets. But later the error messages may need to be changed
|
||||
// to be more accurate.
|
||||
params := tasks.NewInspectParamsWithContext(op).WithConfig(config)
|
||||
resp, err := c.client.Tasks.Inspect(params)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case *tasks.InspectNotFound:
|
||||
// These error types may need to be expanded. NotFoundError does not fit here.
|
||||
op.Errorf("received a TaskNotFound error during task inspect: %s", err.Payload.Message)
|
||||
return nil, errors.TaskPoweredOffError(cid)
|
||||
case *tasks.InspectInternalServerError:
|
||||
op.Errorf("received an internal server error during task inspect: %s", err.Payload.Message)
|
||||
return nil, errors.InternalServerError(err.Payload.Message)
|
||||
default:
|
||||
// right now Task inspection in the portlayer does not return a conflict error
|
||||
return nil, errors.InternalServerError(err.Error())
|
||||
}
|
||||
}
|
||||
return resp.Payload, nil
|
||||
}
|
||||
|
||||
func (c *ContainerProxy) BindTask(op trace.Operation, handle string, eid string) (string, error) {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("handle(%s), eid(%s)", handle, eid)))
|
||||
|
||||
if c.client == nil {
|
||||
return "", errors.NillPortlayerClientError("ContainerProxy")
|
||||
}
|
||||
|
||||
bindconfig := &models.TaskBindConfig{
|
||||
Handle: handle,
|
||||
ID: eid,
|
||||
}
|
||||
bindparams := tasks.NewBindParamsWithContext(op).WithConfig(bindconfig)
|
||||
|
||||
// call Bind with bindparams
|
||||
resp, err := c.client.Tasks.Bind(bindparams)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case *tasks.BindNotFound:
|
||||
op.Errorf("received TaskNotFound error during task bind: %s", err.Payload.Message)
|
||||
return "", errors.TaskBindPowerError()
|
||||
case *tasks.BindInternalServerError:
|
||||
op.Errorf("received unexpected error attempting to bind task(%s) for handle(%s): %s", eid, handle, err.Payload.Message)
|
||||
return "", errors.InternalServerError(err.Payload.Message)
|
||||
default:
|
||||
op.Errorf("received unexpected error attempting to bind task(%s) for handle(%s): %s", eid, handle, err.Error())
|
||||
return "", errors.InternalServerError(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
respHandle, ok := resp.Payload.Handle.(string)
|
||||
if !ok {
|
||||
op.Errorf("Unable to marshal string object from BindTask response for handle(%s) on eid(%s)", handle, eid)
|
||||
// TODO: perhaps a better error message here?
|
||||
return "", errors.InternalServerError("An unknown error occurred during the handling of this request")
|
||||
}
|
||||
|
||||
return respHandle, nil
|
||||
}
|
||||
|
||||
func (c *ContainerProxy) WaitTask(op trace.Operation, cid string, cname string, eid string) error {
|
||||
if c.client == nil {
|
||||
return errors.NillPortlayerClientError("ContainerProxy")
|
||||
}
|
||||
|
||||
handle, err := c.Handle(op, cid, cname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// wait the Task to start
|
||||
config := &models.TaskWaitConfig{
|
||||
Handle: handle,
|
||||
ID: eid,
|
||||
}
|
||||
|
||||
params := tasks.NewWaitParamsWithContext(op).WithConfig(config)
|
||||
_, err = c.client.Tasks.Wait(params)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case *tasks.WaitNotFound:
|
||||
return errors.InternalServerError(fmt.Sprintf("the Container(%s) has been shutdown during execution of the exec operation", cid))
|
||||
case *tasks.WaitPreconditionRequired:
|
||||
return errors.InternalServerError(fmt.Sprintf("container(%s) must be powered on in order to perform the desired exec operation", cid))
|
||||
case *tasks.WaitInternalServerError:
|
||||
return errors.InternalServerError(err.Payload.Message)
|
||||
default:
|
||||
return errors.InternalServerError(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// Stop will stop (shutdown) a VIC container.
|
||||
//
|
||||
// returns
|
||||
@@ -618,6 +733,28 @@ func (c *ContainerProxy) State(ctx context.Context, vc *viccontainer.VicContaine
|
||||
return inspectJSON.State, nil
|
||||
}
|
||||
|
||||
// GetStateFromHandle takes a handle and returns the state of the container based on that handle. Also returns handle that comes back with the response.
|
||||
func (c *ContainerProxy) GetStateFromHandle(op trace.Operation, handle string) (string, string, error) {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("handle(%s)", handle), op))
|
||||
|
||||
if c.client == nil {
|
||||
return "", "", errors.NillPortlayerClientError("ContainerProxy")
|
||||
}
|
||||
|
||||
params := containers.NewGetStateParams().WithHandle(handle)
|
||||
resp, err := c.client.Containers.GetState(params)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case *containers.GetStateNotFound:
|
||||
return handle, "", errors.NotFoundError(err.Payload.Message)
|
||||
default:
|
||||
return handle, "", errors.InternalServerError(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Payload.Handle, resp.Payload.State, nil
|
||||
}
|
||||
|
||||
// ExitCode returns container exitCode
|
||||
func (c *ContainerProxy) ExitCode(ctx context.Context, vc *viccontainer.VicContainer) (string, error) {
|
||||
defer trace.End(trace.Begin(""))
|
||||
|
||||
83
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/container_proxy_test.go
generated
vendored
83
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/container_proxy_test.go
generated
vendored
@@ -1,83 +0,0 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestProcessVolumeParams(t *testing.T) {
|
||||
rawTestVolumes := []string{"/blah", "testVolume:/mount", "testVolume:/mount/path:r"}
|
||||
invalidVolume := "/dir:/dir"
|
||||
var processedTestVolumes []volumeFields
|
||||
|
||||
for _, testString := range rawTestVolumes {
|
||||
processedFields, err := processVolumeParam(testString)
|
||||
assert.Nil(t, err)
|
||||
processedTestVolumes = append(processedTestVolumes, processedFields)
|
||||
}
|
||||
assert.Equal(t, 3, len(processedTestVolumes))
|
||||
|
||||
assert.NotEmpty(t, processedTestVolumes[0].ID)
|
||||
assert.Equal(t, "/blah", processedTestVolumes[0].Dest)
|
||||
assert.Equal(t, "rw", processedTestVolumes[0].Flags)
|
||||
|
||||
assert.Equal(t, "testVolume", processedTestVolumes[1].ID)
|
||||
assert.Equal(t, "/mount", processedTestVolumes[1].Dest)
|
||||
assert.Equal(t, "rw", processedTestVolumes[1].Flags)
|
||||
|
||||
assert.Equal(t, "testVolume", processedTestVolumes[2].ID)
|
||||
assert.Equal(t, "/mount/path", processedTestVolumes[2].Dest)
|
||||
assert.Equal(t, "r", processedTestVolumes[2].Flags)
|
||||
|
||||
invalidFields, _ := processVolumeParam(invalidVolume)
|
||||
assert.Equal(t, volumeFields{}, invalidFields)
|
||||
}
|
||||
|
||||
func TestPort(t *testing.T) {
|
||||
portMap, bindingMap, err := nat.ParsePortSpecs([]string{
|
||||
"1236:1235/tcp",
|
||||
"1237:1235/tcp",
|
||||
"2345/udp", "80",
|
||||
"127.0.0.1::8080",
|
||||
"127.0.0.1:5279:8080",
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("Failed to parse ports: %s", err.Error())
|
||||
}
|
||||
t.Logf("portMap: %s", portMap)
|
||||
t.Logf("bindingMap: %s", bindingMap)
|
||||
|
||||
for p := range bindingMap {
|
||||
expected := bindingMap[p]
|
||||
for i := range expected {
|
||||
expected[i].HostIP = ""
|
||||
}
|
||||
|
||||
bindings := fromPortbinding(p, bindingMap[p])
|
||||
t.Logf("binding: %s", bindings)
|
||||
_, outMap, err := nat.ParsePortSpecs(bindings)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to parse back string bindings: %s", err)
|
||||
}
|
||||
for op := range outMap {
|
||||
assert.Equal(t, outMap[op], bindingMap[op])
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
129
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/storage_proxy_test.go
generated
vendored
129
vendor/github.com/vmware/vic/lib/apiservers/engine/proxy/storage_proxy_test.go
generated
vendored
@@ -1,129 +0,0 @@
|
||||
// Copyright 2016-2018 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/vmware/vic/lib/apiservers/portlayer/models"
|
||||
)
|
||||
|
||||
func TestFillDockerVolume(t *testing.T) {
|
||||
testResponse := &models.VolumeResponse{
|
||||
Driver: "vsphere",
|
||||
Name: "Test Volume",
|
||||
Label: "Test Label",
|
||||
}
|
||||
testLabels := make(map[string]string)
|
||||
testLabels["TestMeta"] = "custom info about my volume"
|
||||
|
||||
dockerVolume := NewVolumeModel(testResponse, testLabels)
|
||||
|
||||
assert.Equal(t, "vsphere", dockerVolume.Driver)
|
||||
assert.Equal(t, "Test Volume", dockerVolume.Name)
|
||||
assert.Equal(t, "Test Label", dockerVolume.Mountpoint)
|
||||
assert.Equal(t, "custom info about my volume", dockerVolume.Labels["TestMeta"])
|
||||
}
|
||||
|
||||
func TestTranslatVolumeRequestModel(t *testing.T) {
|
||||
testLabels := make(map[string]string)
|
||||
testLabels["TestMeta"] = "custom info about my volume"
|
||||
|
||||
testDriverArgs := make(map[string]string)
|
||||
testDriverArgs["testarg"] = "important driver stuff"
|
||||
testDriverArgs[OptsVolumeStoreKey] = "testStore"
|
||||
testDriverArgs[OptsCapacityKey] = "12MB"
|
||||
|
||||
testRequest, err := newVolumeCreateReq("testName", "vsphere", testDriverArgs, testLabels)
|
||||
if !assert.Error(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
delete(testDriverArgs, "testarg")
|
||||
testRequest, err = newVolumeCreateReq("testName", "vsphere", testDriverArgs, testLabels)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, "testName", testRequest.Name)
|
||||
assert.Equal(t, "", testRequest.DriverArgs["testarg"]) // unsupported keys should just be empty
|
||||
assert.Equal(t, "testStore", testRequest.Store)
|
||||
assert.Equal(t, "vsphere", testRequest.Driver)
|
||||
assert.Equal(t, int64(12), testRequest.Capacity)
|
||||
|
||||
testMetaDatabuf, err := createVolumeMetadata(testRequest, testDriverArgs, testLabels)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, testMetaDatabuf, testRequest.Metadata[DockerMetadataModelKey])
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestValidateDriverArgs(t *testing.T) {
|
||||
testMap := make(map[string]string)
|
||||
testStore := "Mystore"
|
||||
testCap := "12MB"
|
||||
testBadCap := "This is not valid!"
|
||||
testModel := models.VolumeRequest{
|
||||
Driver: "vsphere",
|
||||
DriverArgs: testMap,
|
||||
Name: "testModel",
|
||||
}
|
||||
|
||||
err := validateDriverArgs(testMap, &testModel)
|
||||
if !assert.Equal(t, "default", testModel.Store) || !assert.Equal(t, int64(-1), testModel.Capacity) || !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
testMap[OptsVolumeStoreKey] = testStore
|
||||
testMap[OptsCapacityKey] = testCap
|
||||
err = validateDriverArgs(testMap, &testModel)
|
||||
if !assert.Equal(t, testStore, testModel.Store) || !assert.Equal(t, int64(12), testModel.Capacity) || !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
//This is a negative test case. We want an error
|
||||
testMap[OptsCapacityKey] = testBadCap
|
||||
err = validateDriverArgs(testMap, &testModel)
|
||||
if !assert.Equal(t, testStore, testModel.Store) || !assert.Equal(t, int64(12), testModel.Capacity) || !assert.Error(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
testMap[OptsCapacityKey] = testCap
|
||||
delete(testMap, OptsVolumeStoreKey)
|
||||
err = validateDriverArgs(testMap, &testModel)
|
||||
if !assert.Equal(t, "default", testModel.Store) || !assert.Equal(t, int64(12), testModel.Capacity) || !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeDriverArgs(t *testing.T) {
|
||||
testOptMap := make(map[string]string)
|
||||
testOptMap["VOLUMESTORE"] = "foo"
|
||||
testOptMap["CAPACITY"] = "bar"
|
||||
|
||||
normalizeDriverArgs(testOptMap)
|
||||
|
||||
assert.Equal(t, testOptMap["volumestore"], "foo")
|
||||
assert.Equal(t, testOptMap["capacity"], "bar")
|
||||
|
||||
testOptMap["bogus"] = "bogus"
|
||||
|
||||
err := normalizeDriverArgs(testOptMap)
|
||||
assert.Error(t, err, "expected: bogus is not a supported option")
|
||||
}
|
||||
Reference in New Issue
Block a user