-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
- Loading branch information
Showing
6 changed files
with
270 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
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 main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
csi "github.com/container-storage-interface/spec/lib/go/csi/v0" | ||
"github.com/golang/mock/gomock" | ||
"github.com/kubernetes-csi/csi-test/driver" | ||
"github.com/kubernetes-csi/livenessprobe/pkg/connection" | ||
) | ||
|
||
const ( | ||
driverName = "foo/bar" | ||
) | ||
|
||
func createMockServer(t *testing.T) ( | ||
*gomock.Controller, | ||
*driver.MockCSIDriver, | ||
*driver.MockIdentityServer, | ||
*driver.MockControllerServer, | ||
*driver.MockNodeServer, | ||
connection.CSIConnection, | ||
error) { | ||
// Start the mock server | ||
mockController := gomock.NewController(t) | ||
identityServer := driver.NewMockIdentityServer(mockController) | ||
controllerServer := driver.NewMockControllerServer(mockController) | ||
nodeServer := driver.NewMockNodeServer(mockController) | ||
drv := driver.NewMockCSIDriver(&driver.MockCSIDriverServers{ | ||
Identity: identityServer, | ||
Controller: controllerServer, | ||
Node: nodeServer, | ||
}) | ||
drv.Start() | ||
|
||
// Create a client connection to it | ||
addr := drv.Address() | ||
csiConn, err := connection.NewConnection(addr, 10) | ||
if err != nil { | ||
return nil, nil, nil, nil, nil, nil, err | ||
} | ||
|
||
return mockController, drv, identityServer, controllerServer, nodeServer, csiConn, nil | ||
} | ||
|
||
func TestProbe(t *testing.T) { | ||
mockController, driver, idServer, _, nodeServer, csiConn, err := createMockServer(t) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer mockController.Finish() | ||
defer driver.Stop() | ||
defer csiConn.Close() | ||
|
||
// Setting up expected calls' responses | ||
inPlugin := &csi.GetPluginInfoRequest{} | ||
outPlugin := &csi.GetPluginInfoResponse{ | ||
Name: "foo/bar", | ||
} | ||
var injectedErr error | ||
idServer.EXPECT().GetPluginInfo(gomock.Any(), inPlugin).Return(outPlugin, injectedErr).Times(1) | ||
|
||
inNode := &csi.NodeGetIdRequest{} | ||
outNode := &csi.NodeGetIdResponse{ | ||
NodeId: "test_node_id", | ||
} | ||
nodeServer.EXPECT().NodeGetId(gomock.Any(), inNode).Return(outNode, injectedErr).Times(1) | ||
inProbe := &csi.ProbeRequest{} | ||
outProbe := &csi.ProbeResponse{} | ||
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1) | ||
// Calling Probing function | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
if err := runProbe(ctx, csiConn); err != nil { | ||
t.Fatalf("failed to run probe with error: %+v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
## This file is for livenessprove which runs in a pair with csi | ||
## hostpath | ||
|
||
## Must be run from the root of the repo | ||
UDS="/tmp/e2e-csi-sanity.sock" | ||
CSI_ENDPOINT="unix://${UDS}" | ||
CSI_MOUNTPOINT="/mnt" | ||
APP=hostpathplugin | ||
|
||
SKIP="WithCapacity" | ||
if [ x${TRAVIS} = x"true" ] ; then | ||
SKIP="WithCapacity|NodeUnpublishVolume|NodePublishVolume" | ||
fi | ||
|
||
git clone https://github.com/kubernetes-csi/drivers $GOPATH/src/github.com/kubernetes-csi/drivers | ||
pushd $GOPATH/src/github.com/kubernetes-csi/drivers | ||
# Build | ||
make hostpath; ret=$? | ||
if [ $ret -ne 0 ]; then | ||
echo "Failed to build hostpath plugin, file a bug against drivers repo" | ||
exit 1 | ||
fi | ||
popd | ||
|
||
sudo rm -rf "$UDS" || true | ||
|
||
# Start hostpathplugin in the background | ||
sudo $GOPATH/src/github.com/kubernetes-csi/drivers/_output/$APP --endpoint=$CSI_ENDPOINT --nodeid=1 --v=5 & | ||
|
||
# Start liveness probe in the background | ||
sudo ./bin/livenessprobe --csi-address=$CSI_ENDPOINT & | ||
|
||
# Give time to CSI hostpathplugin and livenessprobe to initialize | ||
sleep 3 | ||
|
||
# Requesting health | ||
health=$(curl -I http://localhost:9808/healthz | grep HTTP | awk '{print $2}') | ||
if [[ "x$health" != "x200" ]]; then | ||
echo "Health check failed, but it was not supposed to, exiting..." | ||
exit 1 | ||
fi | ||
|
||
# Killing hostpathplugin | ||
sudo kill -9 $(pidof hostpathplugin) | ||
sleep 3 | ||
|
||
# Requesting health, should fail since hostpathplugin is gone | ||
health=$(curl -I http://localhost:9808/healthz| grep HTTP | awk '{print $2}') | ||
if [[ "x$health" != "x500" ]]; then | ||
echo "Health check did not detect driver failure, returned code: $health, exiting..." | ||
exit 1 | ||
fi | ||
|
||
sudo rm -f $UDS | ||
exit 0 |