From d51a5e303d6eb208656077fcda7e6451eae5defa Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 19 Mar 2018 19:20:50 +0000 Subject: [PATCH] lint: Fix virtcontainers unused errors Remove unused variables and functions identified by the `varcheck` and `unused` linters. Signed-off-by: James O. D. Hunt --- virtcontainers/cc_shim_test.go | 1 - virtcontainers/cnm_test.go | 30 ---------------------- virtcontainers/container.go | 4 --- virtcontainers/device.go | 7 ----- virtcontainers/hack/virtc/main.go | 23 ----------------- virtcontainers/hyperstart_agent.go | 4 --- virtcontainers/kata_agent.go | 15 ----------- virtcontainers/kata_shim_test.go | 3 --- virtcontainers/mount.go | 9 ------- virtcontainers/network.go | 10 -------- virtcontainers/no_proxy_test.go | 2 -- virtcontainers/pkg/mock/cc_proxy_mock.go | 12 --------- virtcontainers/pkg/nsenter/nsenter_test.go | 5 +--- virtcontainers/pod_test.go | 5 ---- virtcontainers/proxy.go | 5 ---- virtcontainers/qemu.go | 13 ---------- 16 files changed, 1 insertion(+), 147 deletions(-) delete mode 100644 virtcontainers/cnm_test.go diff --git a/virtcontainers/cc_shim_test.go b/virtcontainers/cc_shim_test.go index ddea0f8d0b..9811b31631 100644 --- a/virtcontainers/cc_shim_test.go +++ b/virtcontainers/cc_shim_test.go @@ -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 == "" { diff --git a/virtcontainers/cnm_test.go b/virtcontainers/cnm_test.go deleted file mode 100644 index 419b36c7a9..0000000000 --- a/virtcontainers/cnm_test.go +++ /dev/null @@ -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 -} diff --git a/virtcontainers/container.go b/virtcontainers/container.go index c91fbba0dc..87ea329dfa 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -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) } diff --git a/virtcontainers/device.go b/virtcontainers/device.go index 7010f59be6..ffe0be486e 100644 --- a/virtcontainers/device.go +++ b/virtcontainers/device.go @@ -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/" ) diff --git a/virtcontainers/hack/virtc/main.go b/virtcontainers/hack/virtc/main.go index f45cf1844f..d0e86a1ff4 100644 --- a/virtcontainers/hack/virtc/main.go +++ b/virtcontainers/hack/virtc/main.go @@ -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", diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index 4b29ef5d11..4f0e487ffc 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -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 { diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index e80411240b..329e576cfa 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -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 diff --git a/virtcontainers/kata_shim_test.go b/virtcontainers/kata_shim_test.go index 8d5ac7dc93..777c2b72ab 100644 --- a/virtcontainers/kata_shim_test.go +++ b/virtcontainers/kata_shim_test.go @@ -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" diff --git a/virtcontainers/mount.go b/virtcontainers/mount.go index 7bd5ab0487..adffa21aab 100644 --- a/virtcontainers/mount.go +++ b/virtcontainers/mount.go @@ -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 { diff --git a/virtcontainers/network.go b/virtcontainers/network.go index 491dea60bd..45d687bb57 100644 --- a/virtcontainers/network.go +++ b/virtcontainers/network.go @@ -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. diff --git a/virtcontainers/no_proxy_test.go b/virtcontainers/no_proxy_test.go index 5fb8d2bf6b..d0df409a01 100644 --- a/virtcontainers/no_proxy_test.go +++ b/virtcontainers/no_proxy_test.go @@ -20,8 +20,6 @@ import ( "testing" ) -var testNoProxyVMURL = "vmURL" - func TestNoProxyStart(t *testing.T) { pod := Pod{ agent: newAgent(NoopAgentType), diff --git a/virtcontainers/pkg/mock/cc_proxy_mock.go b/virtcontainers/pkg/mock/cc_proxy_mock.go index 1cc4bc2e42..3acee1a67e 100644 --- a/virtcontainers/pkg/mock/cc_proxy_mock.go +++ b/virtcontainers/pkg/mock/cc_proxy_mock.go @@ -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 } diff --git a/virtcontainers/pkg/nsenter/nsenter_test.go b/virtcontainers/pkg/nsenter/nsenter_test.go index a0ad8f3827..220d9c63d6 100644 --- a/virtcontainers/pkg/nsenter/nsenter_test.go +++ b/virtcontainers/pkg/nsenter/nsenter_test.go @@ -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 { diff --git a/virtcontainers/pod_test.go b/virtcontainers/pod_test.go index ef75997925..ff4e370d21 100644 --- a/virtcontainers/pod_test.go +++ b/virtcontainers/pod_test.go @@ -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) } diff --git a/virtcontainers/proxy.go b/virtcontainers/proxy.go index 8e941333a8..e3ff0d426b 100644 --- a/virtcontainers/proxy.go +++ b/virtcontainers/proxy.go @@ -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 { diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 3d093ae8c0..90004c0938 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -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 {