From 8c3934fd0dc507fcb5e02cb58fc5dcd219dc6f5b Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 19 Apr 2017 08:40:39 -0700 Subject: [PATCH] shim: Remove all files related to shim Shim is now handled by virtcontainers, no need to keep those unused files related to shim. Signed-off-by: Sebastien Boeuf --- .travis.yml | 5 --- shim.go | 70 ------------------------------------ shim/mock/shim.go | 84 ------------------------------------------- shim_test.go | 92 ----------------------------------------------- 4 files changed, 251 deletions(-) delete mode 100644 shim.go delete mode 100644 shim/mock/shim.go delete mode 100644 shim_test.go diff --git a/.travis.yml b/.travis.yml index a92bb322..9db4aecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,6 @@ after_success: - go get github.com/mattn/goveralls - "$GOPATH/bin/goveralls -service=travis-ci -coverprofile=profile.cov" -install: -- sudo mkdir -p /tmp/cc-runtime/bin -- go build -o cc-shim $GOPATH/src/github.com/clearcontainers/runtime/shim/mock/shim.go -- sudo cp cc-shim /tmp/cc-runtime/bin/ - notifications: slack: secure: nJc3XJ9vx9pI/7MRyt6/lg0CW3xdCaOKerTqcJbRUyDchrp6SuKYv47fPY6pBK+S5x2hQuwV25mT5J6QLXL8rIKA/1ThRqbnvaGkfYm2714O5F+QcdXf6APaB9GHXpJOdSYjfdT1bvwCANjSvKpj3Xfe6+V6jyiOmnjiAJkk1n+qtt/LNEk8CwFTMx2nz+KKQuBY3PTbtFvsOV6p+njO3vPYA+QGbxftsweMUx4IrtGzc8j7/aPXrI8oGhFYuM0cQF1WJheHR8qPqHPtoTsXLhCPfdzTZfUW42EnraUziq5bCgKVqH8kMJAUZl7p3XdYwOyJXs0G8B7JBDzmPozrJFyw7su85zda88Upt48VxbacyBygFdRL/Ue6uRHAR6vz0nRmGwqVd7pDhbIAEX3U8ulCG78qa5oQPmAlKtcp+QSotCBGEJI4nmuAsLxvb4y8eohIQ6uR+o2KFDPoG0JSNF9OlKVRDDFSHocoXc1aDpFN+GF7dXxRjkcZZH1JmhiQCnSJjosQ7srGigVsNXq5COl2JKuO1bZKXnR8vUPO3Mt9S28Yafms0mldxvquOJCxMD8fmhPVSVhqgcLzaT/6zUb2+TIq9Y8V7WMk1cptCdUdhuC71wnYdNPae8WPvFtF8ElQUn21iiWhkJX0Wg3G07FMh4S1jnJ/UuKn9LH2vc8= diff --git a/shim.go b/shim.go deleted file mode 100644 index 96904faf..00000000 --- a/shim.go +++ /dev/null @@ -1,70 +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 main - -import ( - "fmt" - "os" - "os/exec" - - vc "github.com/containers/virtcontainers" -) - -// ShimConfig holds configuration data related to a shim. -type ShimConfig struct { - Path string -} - -func startShim(process *vc.Process, config ShimConfig, url string) (int, error) { - if process.Token == "" { - return -1, fmt.Errorf("Token cannot be empty") - } - - if url == "" { - return -1, fmt.Errorf("URL cannot be empty") - } - - if config.Path == "" { - config.Path = defaultShimPath - } - ccLog.Infof("Shim binary path: %s", config.Path) - - cmd := exec.Command(config.Path, "-t", process.Token, "-u", url) - cmd.Env = os.Environ() - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - if err := cmd.Start(); err != nil { - return -1, err - } - - return cmd.Process.Pid, nil -} - -func startContainerShim(container *vc.Container, config ShimConfig, url string) (int, error) { - process := container.Process() - - pid, err := startShim(&process, config, url) - if err != nil { - return -1, err - } - - if err := container.SetPid(pid); err != nil { - return -1, err - } - - return pid, nil -} diff --git a/shim/mock/shim.go b/shim/mock/shim.go deleted file mode 100644 index ba8348c1..00000000 --- a/shim/mock/shim.go +++ /dev/null @@ -1,84 +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 main - -import ( - "flag" - "fmt" - "io/ioutil" - "net/url" - "os" - "os/signal" - "path/filepath" - "syscall" -) - -const logFileName = "mock_shim.log" -const dirMode = os.FileMode(0750) -const numArgsExpected = 2 - -func main() { - logDirPath, err := ioutil.TempDir("", "cc-shim-") - if err != nil { - fmt.Printf("ERROR: Could not generate temporary log directory path: %s\n", err) - os.Exit(1) - } - - if err := os.MkdirAll(logDirPath, dirMode); err != nil { - fmt.Printf("ERROR: Could not create temporary log directory %q: %s\n", logDirPath, err) - os.Exit(1) - } - - logFilePath := filepath.Join(logDirPath, logFileName) - - f, err := os.Create(logFilePath) - if err != nil { - fmt.Printf("ERROR: Could not create temporary log file %q: %s\n", logFilePath, err) - os.Exit(1) - } - defer f.Close() - - tokenFlag := flag.String("t", "", "Proxy token") - urlFlag := flag.String("u", "", "Proxy URL") - - flag.Parse() - - fmt.Fprintf(f, "INFO: Token = %s\n", *tokenFlag) - fmt.Fprintf(f, "INFO: URL = %s\n", *urlFlag) - - if *tokenFlag == "" { - fmt.Fprintf(f, "ERROR: Token should not be empty\n") - os.Exit(1) - } - - if *urlFlag == "" { - fmt.Fprintf(f, "ERROR: URL should not be empty\n") - os.Exit(1) - } - - if _, err := url.Parse(*urlFlag); err != nil { - fmt.Fprintf(f, "ERROR: Could not parse the URL %q: %s\n", *urlFlag, err) - os.Exit(1) - } - - exitShim := make(chan os.Signal) - signal.Notify(exitShim, syscall.SIGUSR1) - - <-exitShim - - fmt.Fprintf(f, "INFO: Shim exited properly\n") -} diff --git a/shim_test.go b/shim_test.go deleted file mode 100644 index 24de5694..00000000 --- a/shim_test.go +++ /dev/null @@ -1,92 +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 main - -import ( - "os" - "syscall" - "testing" - - vc "github.com/containers/virtcontainers" -) - -const mockShimPath = "/tmp/cc-runtime/bin/cc-shim" - -var testToken = "test-token" -var testURL = "sheme://ipAddress:8080/path" - -func TestStartShimTokenEmptyFailure(t *testing.T) { - if _, err := startShim(&vc.Process{}, ShimConfig{}, testURL); err == nil { - t.Fatalf("This test should fail because process.Token is empty") - } -} - -func TestStartShimURLEmptyFailure(t *testing.T) { - process := &vc.Process{ - Token: testToken, - } - - if _, err := startShim(process, ShimConfig{}, ""); err == nil { - t.Fatalf("This test should fail because process.Token is empty") - } -} - -func testStartShimSuccessful(t *testing.T, process *vc.Process, shimConfig ShimConfig, url string) { - pid, err := startShim(process, shimConfig, url) - if err != nil { - t.Fatal(err) - } - - if pid < 0 { - t.Fatalf("Invalid PID %d", pid) - } - - p, err := os.FindProcess(pid) - if err != nil { - t.Fatalf("Could not find shim PID %d: %s", pid, err) - } - - if err := p.Signal(syscall.SIGUSR1); err != nil { - t.Fatalf("Could not stop shim PID %d: %s", pid, err) - } -} - -func TestStartShimDefaultShimPathSuccessful(t *testing.T) { - defaultShimPath = mockShimPath - - process := &vc.Process{ - Token: testToken, - } - - testStartShimSuccessful(t, process, ShimConfig{}, testURL) -} - -func TestStartShimSuccessful(t *testing.T) { - process := &vc.Process{ - Token: testToken, - } - - shimConfig := ShimConfig{ - Path: mockShimPath, - } - - testStartShimSuccessful(t, process, shimConfig, testURL) -} - -func TestStartContainerShimContainerEmptyFailure(t *testing.T) { - if _, err := startContainerShim(&vc.Container{}, ShimConfig{}, testURL); err == nil { - t.Fatal("This test should fail because container is empty") - } -}