Merge pull request #72 from jodh-intel/fix-lint-errors

Fix lint errors & get virtcontainers tests running
This commit is contained in:
Sebastien Boeuf 2018-03-20 10:38:04 -07:00 committed by GitHub
commit c8e0c2cc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 245 additions and 449 deletions

View File

@ -1,99 +0,0 @@
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -e
# Perform static go tests.
function usage {
echo "Usage $0 [OPTIONS] [PACKAGES]"
echo "Perform static go checks on PACKAGES (./... by default)."
echo
echo "List of options:"
echo " -h, --help print this help"
echo " -n, --no-network do not access the network"
}
for i in "$@"; do
case $i in
-h|--help)
usage
exit 0
;;
-n|--no-network)
NONETWORK=1
shift
;;
*)
args="$args $i"
;;
esac
done
go_packages=$args
[ -z "$go_packages" ] && {
go_packages=$(go list ./... | grep -v vendor)
}
function install_package {
url="$1"
name=${url##*/}
if [ -n "$NONETWORK" ]; then
echo "Skipping updating package $name, no network access allowed"
return
fi
echo Updating $name...
go get -u $url
}
install_package github.com/fzipp/gocyclo
install_package github.com/client9/misspell/cmd/misspell
install_package github.com/golang/lint/golint
install_package github.com/gordonklaus/ineffassign
install_package github.com/opennota/check/cmd/structcheck
install_package honnef.co/go/tools/cmd/unused
install_package honnef.co/go/tools/cmd/staticcheck
echo Doing go static checks on packages: $go_packages
echo "Running misspell..."
go list -f '{{.Dir}}/*.go' $go_packages |\
xargs -I % bash -c "misspell -error %"
echo "Running go vet..."
go vet $go_packages
cmd="gofmt -s -d -l"
echo "Running gofmt..."
# Note: ignore git directory in case any refs end in ".go" too.
diff=$(find . -not -wholename '*/vendor/*' -not -wholename '*/.git/*' -name '*.go' | \
xargs $cmd)
if [ -n "$diff" -a $(echo "$diff" | wc -l) -ne 0 ]
then
echo 2>&1 "ERROR: '$cmd' found problems:"
echo 2>&1 "$diff"
exit 1
fi
echo "Running cyclo..."
gocyclo -over 15 `go list -f '{{.Dir}}/*.go' $go_packages`
echo "Running golint..."
for p in $go_packages; do golint -set_exit_status $p; done
echo "Running ineffassign..."
go list -f '{{.Dir}}' $go_packages | xargs -L 1 ineffassign
for tool in structcheck unused staticcheck
do
echo "Running ${tool}..."
eval "$tool" "$go_packages"
done
echo "All Good!"

View File

@ -14,3 +14,9 @@ clone_tests_repo
pushd "${tests_repo_dir}"
.ci/setup.sh
popd
echo "Setup virtcontainers environment"
chronic sudo -E PATH=$PATH bash -c "${cidir}/../virtcontainers/utils/virtcontainers-setup.sh"
echo "Install virtcontainers"
make -C "${cidir}/../virtcontainers" && chronic sudo make -C "${cidir}/../virtcontainers" install

View File

@ -374,7 +374,7 @@ check-go-test: $(GENERATED_FILES)
$(QUIET_TEST)$(MAKEFILE_DIR)/../.ci/go-test.sh
check-go-static:
$(QUIET_CHECK)$(MAKEFILE_DIR)/../.ci/go-static-checks.sh $(GO_STATIC_CHECKS_ARGS)
$(QUIET_CHECK)$(MAKEFILE_DIR)/../.ci/static-checks.sh
$(QUIET_CHECK)$(MAKEFILE_DIR)/../.ci/go-no-os-exit.sh
coverage:

View File

@ -26,7 +26,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
@ -301,9 +301,9 @@ func TestCreateCLIFunctionCreateFail(t *testing.T) {
func TestCreateInvalidArgs(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
{MockID: testContainerID},
{MockID: testContainerID},
@ -401,7 +401,7 @@ func TestCreateInvalidConfigJSON(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
@ -448,7 +448,7 @@ func TestCreateInvalidContainerType(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
@ -496,16 +496,16 @@ func TestCreateContainerInvalid(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
},
}
@ -598,9 +598,9 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
},
}
@ -671,7 +671,7 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
@ -683,9 +683,9 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
},
}
@ -747,16 +747,16 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
func TestCreate(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
},
}
@ -873,7 +873,7 @@ func TestCreateInvalidKernelParams(t *testing.T) {
for detach := range []bool{true, false} {
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
assert.Errorf(err, "%+v", detach)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}
@ -921,7 +921,7 @@ func TestCreateCreatePodPodConfigFail(t *testing.T) {
_, err = createPod(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestCreateCreatePodFail(t *testing.T) {
@ -956,7 +956,7 @@ func TestCreateCreatePodFail(t *testing.T) {
_, err = createPod(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
func TestCreateCreateContainerContainerConfigFail(t *testing.T) {
@ -998,7 +998,7 @@ func TestCreateCreateContainerContainerConfigFail(t *testing.T) {
for _, disableOutput := range []bool{true, false} {
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
assert.True(strings.Contains(err.Error(), containerType))
}
}
@ -1042,7 +1042,7 @@ func TestCreateCreateContainerFail(t *testing.T) {
for _, disableOutput := range []bool{true, false} {
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
}
@ -1055,7 +1055,7 @@ func TestCreateCreateContainer(t *testing.T) {
}
testingImpl.CreateContainerFunc = func(podID string, containerConfig vc.ContainerConfig) (vc.VCPod, vc.VCContainer, error) {
return &vcMock.Pod{}, &vcMock.Container{}, nil
return &vcmock.Pod{}, &vcmock.Container{}, nil
}
defer func() {

View File

@ -23,7 +23,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -61,12 +61,12 @@ func TestDeleteInvalidContainer(t *testing.T) {
// Missing container id
err := delete("", false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// Mock Listpod error
err = delete(testContainerID, false)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) {
return []vc.PodStatus{}, nil
@ -79,13 +79,13 @@ func TestDeleteInvalidContainer(t *testing.T) {
// Container missing in ListPod
err = delete(testContainerID, false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestDeleteMissingContainerTypeAnnotation(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -109,13 +109,13 @@ func TestDeleteMissingContainerTypeAnnotation(t *testing.T) {
err := delete(pod.ID(), false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestDeleteInvalidConfig(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -141,7 +141,7 @@ func TestDeleteInvalidConfig(t *testing.T) {
err := delete(pod.ID(), false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func testConfigSetup(t *testing.T) string {
@ -165,7 +165,7 @@ func testConfigSetup(t *testing.T) string {
func TestDeletePod(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -199,7 +199,7 @@ func TestDeletePod(t *testing.T) {
err = delete(pod.ID(), false)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.StopPodFunc = func(podID string) (vc.VCPod, error) {
return pod, nil
@ -211,7 +211,7 @@ func TestDeletePod(t *testing.T) {
err = delete(pod.ID(), false)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) {
return pod, nil
@ -228,7 +228,7 @@ func TestDeletePod(t *testing.T) {
func TestDeleteInvalidContainerType(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -263,13 +263,13 @@ func TestDeleteInvalidContainerType(t *testing.T) {
// Delete an invalid container type
err = delete(pod.ID(), false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestDeletePodRunning(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -304,7 +304,7 @@ func TestDeletePodRunning(t *testing.T) {
// Delete on a running pod should fail
err = delete(pod.ID(), false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
testingImpl.StopPodFunc = func(podID string) (vc.VCPod, error) {
return pod, nil
@ -317,7 +317,7 @@ func TestDeletePodRunning(t *testing.T) {
// Force delete a running pod
err = delete(pod.ID(), true)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) {
return pod, nil
@ -334,11 +334,11 @@ func TestDeletePodRunning(t *testing.T) {
func TestDeleteRunningContainer(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,
@ -376,12 +376,12 @@ func TestDeleteRunningContainer(t *testing.T) {
// Delete on a running container should fail.
err = delete(pod.MockContainers[0].ID(), false)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// force delete
err = delete(pod.MockContainers[0].ID(), true)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
defer func() {
@ -390,10 +390,10 @@ func TestDeleteRunningContainer(t *testing.T) {
err = delete(pod.MockContainers[0].ID(), true)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) {
return &vcMock.Container{}, nil
return &vcmock.Container{}, nil
}
defer func() {
@ -407,11 +407,11 @@ func TestDeleteRunningContainer(t *testing.T) {
func TestDeleteContainer(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,
@ -448,7 +448,7 @@ func TestDeleteContainer(t *testing.T) {
err = delete(pod.MockContainers[0].ID(), false)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
defer func() {
@ -457,10 +457,10 @@ func TestDeleteContainer(t *testing.T) {
err = delete(pod.MockContainers[0].ID(), false)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) {
return &vcMock.Container{}, nil
return &vcmock.Container{}, nil
}
defer func() {
@ -485,7 +485,7 @@ func TestDeleteCLIFunction(t *testing.T) {
// no container id in the Metadata
err := fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
flagSet.Parse([]string{"xyz"})
@ -493,17 +493,17 @@ func TestDeleteCLIFunction(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
func TestDeleteCLIFunctionSuccess(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,
@ -558,7 +558,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
flagSet.Parse([]string{pod.ID()})

View File

@ -25,7 +25,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -43,7 +43,7 @@ func TestExecCLIFunction(t *testing.T) {
// no container-id in the Metadata
err := fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// pass container-id
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
@ -52,7 +52,7 @@ func TestExecCLIFunction(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
func TestExecuteErrors(t *testing.T) {
@ -64,13 +64,13 @@ func TestExecuteErrors(t *testing.T) {
// missing container id
err := execute(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// ListPod error
flagSet.Parse([]string{testContainerID})
err = execute(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
// Config path missing in annotations
annotations := map[string]string{
@ -87,7 +87,7 @@ func TestExecuteErrors(t *testing.T) {
err = execute(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// Container not running
configPath := testConfigSetup(t)
@ -109,7 +109,7 @@ func TestExecuteErrors(t *testing.T) {
err = execute(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestExecuteErrorReadingProcessJson(t *testing.T) {
@ -154,7 +154,7 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestExecuteErrorOpeningConsole(t *testing.T) {
@ -198,7 +198,7 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func testExecParamsSetup(t *testing.T, pidFilePath, consolePath string, detach bool) *flag.FlagSet {
@ -260,10 +260,10 @@ func TestExecuteWithFlags(t *testing.T) {
// EnterContainer error
err = fn(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) {
return &vcMock.Pod{}, &vcMock.Container{}, &vc.Process{}, nil
return &vcmock.Pod{}, &vcmock.Container{}, &vc.Process{}, nil
}
defer func() {
@ -274,7 +274,7 @@ func TestExecuteWithFlags(t *testing.T) {
// Process not running error
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
os.Remove(pidFilePath)
@ -288,7 +288,7 @@ func TestExecuteWithFlags(t *testing.T) {
vcProcess := vc.Process{}
vcProcess.Pid = command.Process.Pid
return &vcMock.Pod{}, &vcMock.Container{}, &vcProcess, nil
return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil
}
defer func() {
@ -347,7 +347,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
vcProcess := vc.Process{}
vcProcess.Pid = command.Process.Pid
return &vcMock.Pod{}, &vcMock.Container{}, &vcProcess, nil
return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil
}
defer func() {
@ -417,7 +417,7 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestExecuteWithValidProcessJson(t *testing.T) {
@ -499,7 +499,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
vcProcess := vc.Process{}
vcProcess.Pid = command.Process.Pid
return &vcMock.Pod{}, &vcMock.Container{}, &vcProcess, nil
return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil
}
defer func() {
@ -572,7 +572,7 @@ func TestExecuteWithInvalidEnvironment(t *testing.T) {
// vcAnnotations.EnvVars error due to incorrect environment
err = fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestGenerateExecParams(t *testing.T) {

View File

@ -21,7 +21,7 @@ import (
"testing"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
)
@ -31,7 +31,7 @@ var (
}
testStopContainerFuncReturnNil = func(podID, containerID string) (vc.VCContainer, error) {
return &vcMock.Container{}, nil
return &vcmock.Container{}, nil
}
)

View File

@ -28,7 +28,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -395,7 +395,7 @@ func TestListGetContainersListPodFail(t *testing.T) {
_, err = getContainers(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
func TestListGetContainers(t *testing.T) {
@ -433,7 +433,7 @@ func TestListGetContainers(t *testing.T) {
func TestListGetContainersPodWithoutContainers(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -477,7 +477,7 @@ func TestListGetContainersPodWithContainer(t *testing.T) {
assert.NoError(err)
defer os.RemoveAll(tmpdir)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -550,7 +550,7 @@ func TestListCLIFunctionFormatFail(t *testing.T) {
{"invalid", invalidFlags},
}
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -621,7 +621,7 @@ func TestListCLIFunctionFormatFail(t *testing.T) {
// invalid output file
assert.Error(err, d)
assert.False(vcMock.IsMockError(err), d)
assert.False(vcmock.IsMockError(err), d)
output := filepath.Join(tmpdir, "output")
f, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE, testFileMode)
@ -634,7 +634,7 @@ func TestListCLIFunctionFormatFail(t *testing.T) {
err = fn(ctx)
if d.format == "invalid" {
assert.Error(err)
assert.False(vcMock.IsMockError(err), d)
assert.False(vcmock.IsMockError(err), d)
} else {
assert.NoError(err)
}
@ -651,7 +651,7 @@ func TestListCLIFunctionQuiet(t *testing.T) {
runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true)
assert.NoError(err)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}

View File

@ -34,7 +34,7 @@ import (
"github.com/dlespiau/covertool/pkg/cover"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
@ -62,7 +62,7 @@ var (
)
// testingImpl is a concrete mock RVC implementation used for testing
var testingImpl = &vcMock.VCMock{}
var testingImpl = &vcmock.VCMock{}
func init() {
if version == "" {

View File

@ -29,7 +29,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/opencontainers/runc/libcontainer/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
@ -83,7 +83,7 @@ func TestGetContainerInfoContainerIDEmptyFailure(t *testing.T) {
func TestGetContainerInfo(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -118,7 +118,7 @@ func TestGetContainerInfo(t *testing.T) {
func TestGetContainerInfoMismatch(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -154,7 +154,7 @@ func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) {
_, err := validCreateParams("", "")
assert.Error(err, "This test should fail because containerID is empty")
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestGetExistingContainerInfoContainerIDEmptyFailure(t *testing.T) {
@ -170,7 +170,7 @@ func TestValidCreateParamsContainerIDNotUnique(t *testing.T) {
containerID := testContainerID + testContainerID
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -204,7 +204,7 @@ func TestValidCreateParamsContainerIDNotUnique(t *testing.T) {
_, err := validCreateParams(testContainerID, "")
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) {
@ -212,7 +212,7 @@ func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) {
containerID := testContainerID + testContainerID
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -238,7 +238,7 @@ func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) {
_, err := validCreateParams(testContainerID, "")
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestValidCreateParamsInvalidBundle(t *testing.T) {
@ -261,7 +261,7 @@ func TestValidCreateParamsInvalidBundle(t *testing.T) {
_, err = validCreateParams(testContainerID, bundlePath)
// bundle is ENOENT
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestValidCreateParamsBundleIsAFile(t *testing.T) {
@ -286,7 +286,7 @@ func TestValidCreateParamsBundleIsAFile(t *testing.T) {
_, err = validCreateParams(testContainerID, bundlePath)
// bundle exists as a file, not a directory
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func testProcessCgroupsPath(t *testing.T, ociSpec oci.CompatOCISpec, expected []string) {
@ -565,7 +565,7 @@ func TestProcessCgroupsPathForResource(t *testing.T) {
for _, isPod := range []bool{true, false} {
_, err := processCgroupsPathForResource(spec, "", isPod)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
}

View File

@ -19,17 +19,17 @@ import (
"testing"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
)
var (
testPausePodFuncReturnNil = func(podID string) (vc.VCPod, error) {
return &vcMock.Pod{}, nil
return &vcmock.Pod{}, nil
}
testResumePodFuncReturnNil = func(podID string) (vc.VCPod, error) {
return &vcMock.Pod{}, nil
return &vcmock.Pod{}, nil
}
)

View File

@ -20,7 +20,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -45,11 +45,11 @@ func TestPSCLIAction(t *testing.T) {
func TestPSFailure(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testContainerID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: pod.ID(),
MockPod: pod,
@ -89,11 +89,11 @@ func TestPSFailure(t *testing.T) {
func TestPSSuccessful(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testContainerID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: pod.ID(),
MockPod: pod,

View File

@ -26,7 +26,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -67,9 +67,9 @@ func TestRunCliAction(t *testing.T) {
func TestRunInvalidArgs(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
MockContainers: []*vcMock.Container{
MockContainers: []*vcmock.Container{
{MockID: testContainerID},
},
}
@ -161,7 +161,7 @@ type runContainerData struct {
consolePath string
bundlePath string
configJSON string
pod *vcMock.Pod
pod *vcmock.Pod
runtimeConfig oci.RuntimeConfig
process *os.Process
tmpDir string
@ -196,11 +196,11 @@ func testRunContainerSetup(t *testing.T) runContainerData {
configPath := filepath.Join(bundlePath, specConfig)
// pod id and container id must be the same otherwise delete will not works
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testContainerID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPid: cmd.Process.Pid,
@ -599,11 +599,11 @@ func TestRunContainerStartFailNoContainers(t *testing.T) {
d := testRunContainerSetup(t)
defer os.RemoveAll(d.tmpDir)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,
@ -651,5 +651,5 @@ func TestRunContainerStartFailNoContainers(t *testing.T) {
err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}

View File

@ -20,7 +20,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -31,12 +31,12 @@ func TestStartInvalidArgs(t *testing.T) {
// Missing container id
_, err := start("")
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
// Mock Listpod error
_, err = start(testContainerID)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) {
return []vc.PodStatus{}, nil
@ -49,13 +49,13 @@ func TestStartInvalidArgs(t *testing.T) {
// Container missing in ListPod
_, err = start(testContainerID)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestStartPod(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -81,7 +81,7 @@ func TestStartPod(t *testing.T) {
_, err := start(pod.ID())
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) {
return pod, nil
@ -98,7 +98,7 @@ func TestStartPod(t *testing.T) {
func TestStartMissingAnnotation(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
@ -122,17 +122,17 @@ func TestStartMissingAnnotation(t *testing.T) {
_, err := start(pod.ID())
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
}
func TestStartContainerSucessFailure(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,
@ -161,7 +161,7 @@ func TestStartContainerSucessFailure(t *testing.T) {
_, err := start(testContainerID)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) {
return pod.MockContainers[0], nil
@ -189,7 +189,7 @@ func TestStartCLIFunction(t *testing.T) {
// no container id in the Metadata
err := fn(ctx)
assert.Error(err)
assert.False(vcMock.IsMockError(err))
assert.False(vcmock.IsMockError(err))
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
flagSet.Parse([]string{"xyz"})
@ -197,17 +197,17 @@ func TestStartCLIFunction(t *testing.T) {
err = fn(ctx)
assert.Error(err)
assert.True(vcMock.IsMockError(err))
assert.True(vcmock.IsMockError(err))
}
func TestStartCLIFunctionSuccess(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testPodID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: testContainerID,
MockPod: pod,

View File

@ -20,7 +20,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcMock"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -49,11 +49,11 @@ func TestStateCliAction(t *testing.T) {
func TestStateSuccessful(t *testing.T) {
assert := assert.New(t)
pod := &vcMock.Pod{
pod := &vcmock.Pod{
MockID: testContainerID,
}
pod.MockContainers = []*vcMock.Container{
pod.MockContainers = []*vcmock.Container{
{
MockID: pod.ID(),
MockPod: pod,

View File

@ -279,6 +279,10 @@ func testGenerateCCProxySockDir() (string, error) {
}
func TestCreatePodHyperstartAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigHyperstartAgent()
@ -308,6 +312,10 @@ func TestCreatePodHyperstartAgentSuccessful(t *testing.T) {
}
func TestCreatePodKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigKataAgent()
@ -383,6 +391,10 @@ func TestDeletePodNoopAgentSuccessful(t *testing.T) {
}
func TestDeletePodHyperstartAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigHyperstartAgent()
@ -422,6 +434,10 @@ func TestDeletePodHyperstartAgentSuccessful(t *testing.T) {
}
func TestDeletePodKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigKataAgent()
@ -527,6 +543,10 @@ func TestStartPodHyperstartAgentSuccessful(t *testing.T) {
}
func TestStartPodKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigKataAgent()
@ -685,6 +705,10 @@ func TestStopPodHyperstartAgentSuccessful(t *testing.T) {
}
func TestStopPodKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigKataAgent()
@ -791,6 +815,10 @@ func TestRunPodHyperstartAgentSuccessful(t *testing.T) {
}
func TestRunPodKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
cleanUp()
config := newTestPodConfigKataAgent()

View File

@ -112,6 +112,6 @@ func TestAssetNew(t *testing.T) {
},
}
a, err = newAsset(p, kernelAsset)
_, err = newAsset(p, kernelAsset)
assert.NotNil(err)
}

View File

@ -22,7 +22,7 @@ type bridgeType string
const (
pciBridge bridgeType = "pci"
pcieBridge = "pcie"
pcieBridge bridgeType = "pcie"
)
const pciBridgeMaxCapacity = 30

View File

@ -37,7 +37,6 @@ const testContainer = "testContainer"
var testCCShimPath = "/usr/bin/virtcontainers/bin/test/cc-shim"
var testProxyURL = "foo:///foo/clear-containers/proxy.sock"
var testWrongConsolePath = "/foo/wrong-console"
var testConsolePath = "tty-console"
func getMockCCShimBinPath() string {
if DefaultMockCCShimBinPath == "" {

View File

@ -22,7 +22,6 @@ import (
// cnm is a network implementation for the CNM plugin.
type cnm struct {
config NetworkConfig
}
func cnmLogger() *logrus.Entry {

View File

@ -1,30 +0,0 @@
//
// Copyright (c) 2017 Intel Corporation
//
// 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 virtcontainers
type mockAddr struct {
network string
ipAddr string
}
func (m mockAddr) Network() string {
return m.network
}
func (m mockAddr) String() string {
return m.ipAddr
}

View File

@ -231,10 +231,6 @@ func (c *Container) storeProcess() error {
return c.pod.storage.storeContainerProcess(c.podID, c.id, c.process)
}
func (c *Container) fetchProcess() (Process, error) {
return c.pod.storage.fetchContainerProcess(c.podID, c.id)
}
func (c *Container) storeMounts() error {
return c.pod.storage.storeContainerMounts(c.podID, c.id, c.mounts)
}

View File

@ -193,6 +193,10 @@ func cleanupFakeRootfsSetup(testRawFile, loopDev, mntDir string) {
}
func TestContainerAddDriveDir(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
testRawFile, loopDev, fakeRootfs, err := testSetupFakeRootfs(t)
defer cleanupFakeRootfsSetup(testRawFile, loopDev, fakeRootfs)

View File

@ -46,13 +46,6 @@ var sysIOMMUPath = "/sys/kernel/iommu_groups"
var sysDevPrefix = "/sys/dev"
var blockPaths = []string{
"/dev/sd", //SCSI block device
"/dev/hd", //IDE block device
"/dev/vd", //Virtual Block device
"/dev/ida/", //Compaq Intelligent Drive Array devices
}
const (
vfioPath = "/dev/vfio/"
)

View File

@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"text/tabwriter"
@ -860,28 +859,6 @@ var statusContainerCommand = cli.Command{
},
}
func startCCShim(process *vc.Process, shimPath, url string) error {
if process.Token == "" {
return fmt.Errorf("Token cannot be empty")
}
if url == "" {
return fmt.Errorf("URL cannot be empty")
}
if shimPath == "" {
return fmt.Errorf("Shim path cannot be empty")
}
cmd := exec.Command(shimPath, "-t", process.Token, "-u", url)
cmd.Env = os.Environ()
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func main() {
cli.VersionFlag = cli.BoolFlag{
Name: "version",

View File

@ -40,10 +40,6 @@ var defaultSharedDir = "/run/hyper/shared/pods/"
var mountTag = "hyperShared"
var maxHostnameLen = 64
const (
unixSocket = "unix"
)
// HyperConfig is a structure storing information needed for
// hyperstart agent initialization.
type HyperConfig struct {
@ -637,7 +633,7 @@ func (h *hyper) processListOneContainer(podID, cID string, options ProcessListOp
func (h *hyper) connectProxyRetry(scheme, address string) (conn net.Conn, err error) {
attempt := 1
timeoutSecs := time.Duration(waitForProxyTimeoutSecs * time.Second)
timeoutSecs := waitForProxyTimeoutSecs * time.Second
startTime := time.Now()
lastLogTime := startTime

View File

@ -68,13 +68,13 @@ const (
netDev
// SerialDev is the serial device type.
serialDev
serialDev // nolint: varcheck,unused
// BlockDev is the block device type.
blockDev
// ConsoleDev is the console device type.
consoleDev
consoleDev // nolint: varcheck,unused
// SerialPortDev is the serial port device type.
serialPortDev
@ -131,7 +131,7 @@ func newHypervisor(hType HypervisorType) (hypervisor, error) {
func makeNameID(namedType string, id string) string {
nameID := fmt.Sprintf("%s-%s", namedType, id)
if len(nameID) > maxDevIDSize {
nameID = string(nameID[:maxDevIDSize])
nameID = nameID[:maxDevIDSize]
}
return nameID
@ -145,6 +145,12 @@ type Param struct {
// HypervisorConfig is the hypervisor configuration.
type HypervisorConfig struct {
// KernelParams are additional guest kernel parameters.
KernelParams []Param
// HypervisorParams are additional hypervisor parameters.
HypervisorParams []Param
// KernelPath is the guest kernel host path.
KernelPath string
@ -160,26 +166,19 @@ type HypervisorConfig struct {
// HypervisorPath is the hypervisor executable host path.
HypervisorPath string
// DisableBlockDeviceUse disallows a block device from being used.
DisableBlockDeviceUse bool
// BlockDeviceDriver specifies the driver to be used for block device
// either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver
BlockDeviceDriver string
// KernelParams are additional guest kernel parameters.
KernelParams []Param
// HypervisorParams are additional hypervisor parameters.
HypervisorParams []Param
// HypervisorMachineType specifies the type of machine being
// emulated.
HypervisorMachineType string
// Debug changes the default hypervisor and kernel parameters to
// enable debug output where available.
Debug bool
// customAssets is a map of assets.
// Each value in that map takes precedence over the configured assets.
// For example, if there is a value for the "kernel" key in this map,
// it will be used for the pod's kernel path instead of KernelPath.
customAssets map[assetType]*asset
// DefaultVCPUs specifies default number of vCPUs for the VM.
DefaultVCPUs uint32
@ -195,6 +194,13 @@ type HypervisorConfig struct {
// Bridges can be used to hot plug devices
DefaultBridges uint32
// DisableBlockDeviceUse disallows a block device from being used.
DisableBlockDeviceUse bool
// Debug changes the default hypervisor and kernel parameters to
// enable debug output where available.
Debug bool
// MemPrealloc specifies if the memory should be pre-allocated
MemPrealloc bool
@ -212,12 +218,6 @@ type HypervisorConfig struct {
// DisableNestingChecks is used to override customizations performed
// when running on top of another VMM.
DisableNestingChecks bool
// customAssets is a map of assets.
// Each value in that map takes precedence over the configured assets.
// For example, if there is a value for the "kernel" key in this map,
// it will be used for the pod's kernel path instead of KernelPath.
customAssets map[assetType]*asset
}
func (conf *HypervisorConfig) valid() (bool, error) {

View File

@ -515,21 +515,6 @@ func (k *kataAgent) stopPod(pod Pod) error {
return k.proxy.stop(pod, k.state.ProxyPid)
}
func appendStorageFromMounts(storage []*grpc.Storage, mounts []*Mount) []*grpc.Storage {
for _, m := range mounts {
s := &grpc.Storage{
Source: m.Source,
MountPoint: m.Destination,
Fstype: m.Type,
Options: m.Options,
}
storage = append(storage, s)
}
return storage
}
func (k *kataAgent) replaceOCIMountSource(spec *specs.Spec, guestMounts []Mount) error {
ociMounts := spec.Mounts
@ -770,11 +755,7 @@ func (k *kataAgent) stopContainer(pod Pod, c Container) error {
return err
}
if err := bindUnmountContainerRootfs(kataHostSharedDir, pod.id, c.id); err != nil {
return err
}
return nil
return bindUnmountContainerRootfs(kataHostSharedDir, pod.id, c.id)
}
func (k *kataAgent) killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error {

View File

@ -24,9 +24,9 @@ import (
"reflect"
"testing"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
gpb "github.com/gogo/protobuf/types"
pb "github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"

View File

@ -29,9 +29,6 @@ import (
. "github.com/kata-containers/runtime/virtcontainers/pkg/mock"
)
// These tests don't care about the format of the container ID
const testKataContainer = "testContainer"
var testKataShimPath = "/usr/bin/virtcontainers/bin/test/kata-shim"
var testKataShimProxyURL = "foo:///foo/kata-containers/proxy.sock"

View File

@ -25,19 +25,10 @@ import (
"path/filepath"
"strings"
"syscall"
"github.com/sirupsen/logrus"
)
var rootfsDir = "rootfs"
func mountLogger() *logrus.Entry {
return virtLog.WithField("subsystem", "mount")
}
// These mounts need to be created by the agent within the VM
var systemMounts = []string{"/proc", "/dev", "/dev/pts", "/dev/shm", "/dev/mqueue", "/sys", "/sys/fs/cgroup"}
var systemMountPrefixes = []string{"/proc", "/dev", "/sys"}
func isSystemMount(m string) bool {

View File

@ -453,7 +453,6 @@ func (n NetworkNamespace) MarshalJSON() ([]byte, error) {
// UnmarshalJSON is the custom NetworkNamespace unmarshalling routine.
// This is needed for unmarshalling the Endpoints interfaces array.
func (n *NetworkNamespace) UnmarshalJSON(b []byte) error {
type tmp NetworkNamespace
var s struct {
NetNsPath string
NetNsCreated bool
@ -1081,15 +1080,6 @@ func createNetNS() (string, error) {
return n.Path(), nil
}
func setNetNS(netNSPath string) error {
n, err := ns.GetNS(netNSPath)
if err != nil {
return err
}
return n.Set()
}
// doNetNS is free from any call to a go routine, and it calls
// into runtime.LockOSThread(), meaning it won't be executed in a
// different thread than the one expected by the caller.

View File

@ -309,6 +309,10 @@ func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) {
}
func TestIsPhysicalIface(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
testNetIface := "testIface0"
testMTU := 1500
testMACAddr := "00:00:00:00:00:01"

View File

@ -20,8 +20,6 @@ import (
"testing"
)
var testNoProxyVMURL = "vmURL"
func TestNoProxyStart(t *testing.T) {
pod := Pod{
agent: newAgent(NoopAgentType),

View File

@ -345,7 +345,7 @@ func (h *Hyperstart) WriteCtlMessage(conn net.Conn, m *DecodedMessage) error {
return fmt.Errorf("message too long %d", length)
}
msg := make([]byte, length)
binary.BigEndian.PutUint32(msg[:], uint32(m.Code))
binary.BigEndian.PutUint32(msg[:], m.Code)
binary.BigEndian.PutUint32(msg[CtlHdrLenOffset:], uint32(length))
copy(msg[CtlHdrSize:], m.Message)
@ -485,7 +485,7 @@ func (h *Hyperstart) WaitForPAE(containerID, processID string) (*PAECommand, err
msg := <-channel
var paeData PAECommand
err = json.Unmarshal(msg.Message, paeData)
err = json.Unmarshal(msg.Message, &paeData)
if err != nil {
return nil, err
}

View File

@ -285,7 +285,7 @@ func (h *Hyperstart) SendIo(seq uint64, data []byte) {
h.logf("io: <-- writing %d bytes for seq %d\n", len(data), seq)
binary.BigEndian.PutUint64(header[:], uint64(seq))
binary.BigEndian.PutUint64(header[:], seq)
binary.BigEndian.PutUint32(header[8:], uint32(length))
h.writeIo(header)

View File

@ -78,7 +78,7 @@ func (m *multicast) buildEventID(containerID, processID string) string {
func (m *multicast) sendEvent(msg *DecodedMessage) error {
var paeData PAECommand
err := json.Unmarshal(msg.Message, paeData)
err := json.Unmarshal(msg.Message, &paeData)
if err != nil {
return err
}

View File

@ -168,28 +168,34 @@ type Capabilities struct {
// Process describes a process running on a container inside a pod.
type Process struct {
// Args specifies the binary and arguments for the application to execute.
Args []string `json:"args"`
// Rlimits specifies rlimit options to apply to the process.
Rlimits []Rlimit `json:"rlimits,omitempty"`
// Envs populates the process environment for the process.
Envs []EnvironmentVar `json:"envs,omitempty"`
AdditionalGroups []string `json:"additionalGroups,omitempty"`
// Workdir is the current working directory for the process and must be
// relative to the container's root.
Workdir string `json:"workdir"`
User string `json:"user,omitempty"`
Group string `json:"group,omitempty"`
AdditionalGroups []string `json:"additionalGroups,omitempty"`
// Terminal creates an interactive terminal for the process.
Terminal bool `json:"terminal"`
// Sequeue number for stdin and stdout
Stdio uint64 `json:"stdio,omitempty"`
// Sequeue number for stderr if it is not shared with stdout
Stderr uint64 `json:"stderr,omitempty"`
// Args specifies the binary and arguments for the application to execute.
Args []string `json:"args"`
// Envs populates the process environment for the process.
Envs []EnvironmentVar `json:"envs,omitempty"`
// Workdir is the current working directory for the process and must be
// relative to the container's root.
Workdir string `json:"workdir"`
// Rlimits specifies rlimit options to apply to the process.
Rlimits []Rlimit `json:"rlimits,omitempty"`
// NoNewPrivileges indicates that the process should not gain any additional privileges
Capabilities Capabilities `json:"capabilities"`
NoNewPrivileges bool `json:"noNewPrivileges"`
// Capabilities specifies the sets of capabilities for the process(es) inside the container.
Capabilities Capabilities `json:"capabilities"`
// Terminal creates an interactive terminal for the process.
Terminal bool `json:"terminal"`
}
// SystemMountsInfo describes additional information for system mounts that the agent

View File

@ -27,7 +27,6 @@ import (
"github.com/stretchr/testify/assert"
)
const testContainerid = "123456789"
const testToken = "pF56IaDpuax6hihJ5PneB8JypqmOvjkqY-wKGVYqgIM="
// CCProxyMock is an object mocking clearcontainers Proxy
@ -73,10 +72,6 @@ func (proxy *CCProxyMock) GetProxyToken() string {
return proxy.token
}
func newSignalList() []ShimSignal {
return make([]ShimSignal, 0, 5)
}
// GetLastStdinStream returns the last received stdin stream
func (proxy *CCProxyMock) GetLastStdinStream() []byte {
return proxy.lastStdinStream
@ -375,13 +370,6 @@ type FrameKey struct {
opcode int
}
func newFrameKey(frameType api.FrameType, opcode int) FrameKey {
return FrameKey{
ftype: frameType,
opcode: opcode,
}
}
type ccProxyProtocol struct {
cmdHandlers map[FrameKey]ccProxyProtocolHandler
}
@ -429,7 +417,7 @@ func (proto *ccProxyProtocol) handleCommand(ctx *clientCtx, cmd *api.Frame) *api
// cmd.Header.Opcode is guaranteed to be within the right bounds by
// ReadFrame().
handler := proto.cmdHandlers[FrameKey{cmd.Header.Type, int(cmd.Header.Opcode)}]
handler := proto.cmdHandlers[FrameKey{cmd.Header.Type, cmd.Header.Opcode}]
handler(cmd.Payload, ctx.userData, &hr)
if hr.err != nil {

View File

@ -52,10 +52,10 @@ type NSType string
// without multithreading issues.
const (
NSTypeCGroup NSType = "cgroup"
NSTypeIPC = "ipc"
NSTypeNet = "net"
NSTypePID = "pid"
NSTypeUTS = "uts"
NSTypeIPC NSType = "ipc"
NSTypeNet NSType = "net"
NSTypePID NSType = "pid"
NSTypeUTS NSType = "uts"
)
// CloneFlagsTable is exported so that consumers of this package don't need

View File

@ -31,10 +31,7 @@ import (
"golang.org/x/sys/unix"
)
const (
testPID = 12345
testNSPath = "/foo/bar/ns"
)
const testPID = 12345
func TestGetNSPathFromPID(t *testing.T) {
for nsType := range CloneFlagsTable {

View File

@ -133,7 +133,7 @@ func (u UUID) String() string {
clkSeqLow := u[9]
buf := make([]byte, 8)
copy(buf[2:], u[10:])
node := uint64(binary.BigEndian.Uint64(buf))
node := binary.BigEndian.Uint64(buf)
return fmt.Sprintf("%08x-%04x-%04x-%02x%02x-%012x",
timeLow, timeMid, timeHi, clkSeqHi, clkSeqLow, node)

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package vcMock
package vcmock
import (
vc "github.com/kata-containers/runtime/virtcontainers"

View File

@ -22,7 +22,7 @@
// well-known format. Callers can detect this scenario by calling
// IsMockError().
package vcMock
package vcmock
import (
"fmt"
@ -34,7 +34,7 @@ import (
// mockErrorPrefix is a string that all errors returned by the mock
// implementation itself will contain as a prefix.
const mockErrorPrefix = "vcMock forced failure"
const mockErrorPrefix = "vcmock forced failure"
// SetLogger implements the VC function of the same name.
func (m *VCMock) SetLogger(logger logrus.FieldLogger) {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package vcMock
package vcmock
import (
"reflect"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package vcMock
package vcmock
import (
vc "github.com/kata-containers/runtime/virtcontainers"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package vcMock
package vcmock
import (
"syscall"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package vcMock
package vcmock
import (
"runtime"

View File

@ -276,7 +276,7 @@ type LinuxCapabilities struct {
type Cmd struct {
Args []string
Envs []EnvVar
WorkDir string
SupplementaryGroups []string
// Note that these fields *MUST* remain as strings.
//
@ -302,13 +302,13 @@ type Cmd struct {
// configuration file generated by the container manager.
User string
PrimaryGroup string
SupplementaryGroups []string
WorkDir string
Console string
Capabilities LinuxCapabilities
Interactive bool
Console string
Detach bool
NoNewPrivileges bool
Capabilities LinuxCapabilities
}
// Resources describes VM resources configuration.
@ -466,8 +466,6 @@ type Pod struct {
networkNS NetworkNamespace
lockFile *os.File
annotationsLock *sync.RWMutex
wg *sync.WaitGroup

View File

@ -1263,11 +1263,6 @@ func TestFindContainerSuccess(t *testing.T) {
assert.True(t, c == pod.containers[0], "Container pointers should point to the same address")
}
func testRemoveContainerFailure(t *testing.T, pod *Pod, cid string) {
err := pod.removeContainer(cid)
assert.NotNil(t, err, "Should have returned an error")
}
func TestRemoveContainerPodNilFailure(t *testing.T) {
testFindContainerFailure(t, nil, testContainerID)
}

View File

@ -21,7 +21,6 @@ import (
"path/filepath"
"github.com/mitchellh/mapstructure"
"github.com/sirupsen/logrus"
)
// ProxyConfig is a structure storing information needed from any
@ -60,10 +59,6 @@ const (
waitForProxyTimeoutSecs = 5.0
)
func proxyLogger() *logrus.Entry {
return virtLog.WithField("subsystem", "proxy")
}
// Set sets a proxy type based on the input string.
func (pType *ProxyType) Set(value string) error {
switch value {

View File

@ -24,8 +24,8 @@ import (
"strings"
"time"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/sirupsen/logrus"
)
@ -559,19 +559,6 @@ func (q *qemu) addDeviceToBridge(ID string) (string, string, error) {
return "", "", err
}
func (q *qemu) removeDeviceFromBridge(ID string) error {
var err error
for _, b := range q.state.Bridges {
err = b.removeDevice(ID)
if err == nil {
// device was removed correctly
return nil
}
}
return err
}
func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error {
defer func(qemu *qemu) {
if q.qmpMonitorCh.qmp != nil {