Skip to content

Redid test framework to bring up driver on instance and expose TCP socket with SSH Tunneling #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ all: gce-pd-driver
gce-pd-driver:
mkdir -p bin
go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/gce-pd-csi-driver ./cmd/
go test -c sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e -o bin/e2e.test

build-container:
docker build --build-arg TAG=$(STAGINGVERSION) -t $(STAGINGIMAGE):$(STAGINGVERSION) .
Expand Down
12 changes: 8 additions & 4 deletions pkg/gce-pd-csi-driver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func (s *nonBlockingGRPCServer) ForceStop() {
}

func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
opts := []grpc.ServerOption{
grpc.UnaryInterceptor(logGRPC),
}

u, err := url.Parse(endpoint)

Expand All @@ -83,6 +86,8 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
glog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
}
} else if u.Scheme == "tcp" {
addr = u.Host
} else {
glog.Fatalf("%v endpoint scheme not supported", u.Scheme)
}
Expand All @@ -93,9 +98,6 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
glog.Fatalf("Failed to listen: %v", err)
}

opts := []grpc.ServerOption{
grpc.UnaryInterceptor(logGRPC),
}
server := grpc.NewServer(opts...)
s.server = server

Expand All @@ -111,6 +113,8 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c

glog.Infof("Listening for connections on address: %#v", listener.Addr())

server.Serve(listener)
if err := server.Serve(listener); err != nil {
glog.Fatalf("Failed to serve: %v", err)
}

}
73 changes: 73 additions & 0 deletions test/binremote/archiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2018 The Kubernetes Authors.

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 binremote

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"

"github.com/golang/glog"
)

func CreateDriverArchive(archiveName, pkgPath, binPath string) (string, error) {
glog.V(2).Infof("Building archive...")
tarDir, err := ioutil.TempDir("", "driver-temp-archive")
if err != nil {
return "", fmt.Errorf("failed to create temporary directory %v", err)
}
defer os.RemoveAll(tarDir)

// Call the suite function to setup the test package.
err = setupBinaries(tarDir, pkgPath, binPath)
if err != nil {
return "", fmt.Errorf("failed to setup test package %q: %v", tarDir, err)
}

// Build the tar
out, err := exec.Command("tar", "-zcvf", archiveName, "-C", tarDir, ".").CombinedOutput()
if err != nil {
return "", fmt.Errorf("failed to build tar %v. Output:\n%s", err, out)
}

dir, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get working directory %v", err)
}
return filepath.Join(dir, archiveName), nil
}

func setupBinaries(tarDir, pkgPath, binPath string) error {
glog.V(4).Infof("Making binaries and copying to temp dir...")
out, err := exec.Command("make", "-C", pkgPath).CombinedOutput()
if err != nil {
return fmt.Errorf("Failed to make at %s: %v: %v", pkgPath, string(out), err)
}

// Copy binaries
if _, err := os.Stat(binPath); err != nil {
return fmt.Errorf("failed to locate test binary %s: %v", binPath, err)
}
out, err = exec.Command("cp", binPath, tarDir).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to copy %q: %v Output: %q", binPath, err, out)
}

return nil
}
Loading