Skip to content
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
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
name = "github.com/kubernetes-csi/csi-lib-utils"
source = "https://github.com/kubernetes-csi/csi-lib-utils"

[[constraint]]
name = "github.com/kubernetes-csi/csi-test"
version = "v2.2.0"

# Picked up from k/k Godeps/Godeps.json
[[override]]
name = "sigs.k8s.io/structured-merge-diff"
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ unit: depend
functional:
@echo "$@ not yet implemented"

test-csi-sanity: depend
test-cinder-csi-sanity: depend
go test $(GIT_HOST)/$(BASE_DIR)/pkg/csi/cinder/sanity/

test-manila-csi-sanity: depend
go test $(GIT_HOST)/$(BASE_DIR)/pkg/csi/manila/sanity/

fmt:
hack/verify-gofmt.sh

Expand Down
7 changes: 7 additions & 0 deletions docs/developers-csi-manila.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CSI Manila developer's guide

## Running CSI Sanity tests

Sanity tests create a real instance of driver with fake Manila client and CSI forwarding node plugin.
See [Sanity check](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) for more info.

Run the test suite with `make test-manila-csi-sanity`.

## Share adapters

A share adapter is an interface found here `pkg/csi/manila/shareadapters/shareadapter.go` that forms an adapter between a Manila share and a CSI plugin.
Expand Down
4 changes: 2 additions & 2 deletions docs/using-cinder-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ Filesystem Size Used Avail Use% Mounted on

## Running Sanity Tests

Sanity tests creates a real instance of driver and fake cloud provider.
Sanity tests create a real instance of driver and fake cloud provider.
see [Sanity check](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) for more info.
```
$ make test-csi-sanity
$ make test-cinder-csi-sanity
```

## Using CSC tool
Expand Down
29 changes: 12 additions & 17 deletions pkg/csi/cinder/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ package sanity
import (
"io/ioutil"
"os"
"path"
"testing"

"k8s.io/cloud-provider-openstack/pkg/csi/cinder"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
)

//start sanity test for driver
// start sanity test for driver
func TestDriver(t *testing.T) {
basePath, err := ioutil.TempDir("", "cinder.csi.openstack.org")
if err != nil {
t.Fatal(err)
}

socket := "/tmp/csi.sock"
defer os.RemoveAll(basePath)

socket := path.Join(basePath, "csi.sock")
endpoint := "unix://" + socket
cluster := "kubernetes"
nodeID := "45678"
Expand All @@ -25,25 +32,13 @@ func TestDriver(t *testing.T) {

d.SetupDriver(c, fakemnt, fakemet)

//TODO: Stop call
// TODO: Stop call

go d.Run()

mntDir, err := ioutil.TempDir("", "mnt")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(mntDir)

mntStageDir, err := ioutil.TempDir("", "mnt-stage")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(mntStageDir)

config := &sanity.Config{
TargetPath: mntDir,
StagingPath: mntStageDir,
TargetPath: path.Join(basePath, "mnt"),
StagingPath: path.Join(basePath, "mnt-stage"),
Address: endpoint,
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/csi/manila/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/cloud-provider-openstack/pkg/csi/manila/options"
"k8s.io/cloud-provider-openstack/pkg/csi/manila/responsebroker"
"k8s.io/cloud-provider-openstack/pkg/csi/manila/shareadapters"
clouderrors "k8s.io/cloud-provider-openstack/pkg/util/errors"
"k8s.io/klog"
)

Expand Down Expand Up @@ -229,7 +230,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
// Retrieve the source share

if sourceShare, res.err = manilaClient.GetShareByID(req.GetSourceVolumeId()); res.err != nil {
if isManilaErrNotFound(res.err) {
if clouderrors.IsNotFound(res.err) {
return nil, status.Errorf(codes.NotFound, "failed to create a snapshot (%s) for share %s because the share doesn't exist: %v", req.GetName(), req.GetSourceVolumeId(), err)
}

Expand All @@ -250,7 +251,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return nil, status.Errorf(codes.DeadlineExceeded, "deadline exceeded while waiting for snapshot %s of share %s to become available", snapshot.ID, req.GetSourceVolumeId())
}

if isManilaErrNotFound(res.err) {
if clouderrors.IsNotFound(res.err) {
return nil, status.Errorf(codes.NotFound, "failed to create a snapshot (%s) for share %s because the share doesn't exist: %v", req.GetName(), req.GetSourceVolumeId(), err)
}

Expand Down Expand Up @@ -370,7 +371,7 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req

share, err := manilaClient.GetShareByID(req.GetVolumeId())
if err != nil {
if isManilaErrNotFound(err) {
if clouderrors.IsNotFound(err) {
return nil, status.Errorf(codes.NotFound, "share %s not found: %v", req.GetVolumeId(), err)
}

Expand Down
13 changes: 11 additions & 2 deletions pkg/csi/manila/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"google.golang.org/grpc/status"
"k8s.io/cloud-provider-openstack/pkg/csi/manila/options"
"k8s.io/cloud-provider-openstack/pkg/csi/manila/shareadapters"
clouderrors "k8s.io/cloud-provider-openstack/pkg/util/errors"
"k8s.io/klog"
)

Expand Down Expand Up @@ -61,12 +62,20 @@ func (ns *nodeServer) buildVolumeContext(volID volumeID, shareOpts *options.Node
if shareOpts.ShareID != "" {
share, err = manilaClient.GetShareByID(shareOpts.ShareID)
if err != nil {
return nil, nil, status.Errorf(codes.InvalidArgument, "failed to retrieve share %s: %v", shareOpts.ShareID, err)
if clouderrors.IsNotFound(err) {
return nil, nil, status.Errorf(codes.NotFound, "share %s not found: %v", shareOpts.ShareID, err)
}

return nil, nil, status.Errorf(codes.Internal, "failed to retrieve share %s: %v", shareOpts.ShareID, err)
}
} else {
share, err = manilaClient.GetShareByName(shareOpts.ShareName)
if err != nil {
return nil, nil, status.Errorf(codes.InvalidArgument, "failed to retrieve share named %s: %v", shareOpts.ShareName, err)
if clouderrors.IsNotFound(err) {
return nil, nil, status.Errorf(codes.NotFound, "no share named %s found: %v", shareOpts.ShareName, err)
}

return nil, nil, status.Errorf(codes.Internal, "failed to retrieve share named %s: %v", shareOpts.ShareName, err)
}
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/csi/manila/sanity/fake-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CreateVolumeSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
DeleteVolumeSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
CreateSnapshotSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
DeleteSnapshotSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
ControllerValidateVolumeCapabilitiesSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
NodeStageVolumeSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
NodePublishVolumeSecret:
os-authURL: fake-url
os-region: fake-region
os-userID: fake-user-id
os-password: fake-password
os-domainID: fake-domain-id
os-projectID: fake-project-id
85 changes: 85 additions & 0 deletions pkg/csi/manila/sanity/fakecsiclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2019 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 sanity

import (
"context"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc"
"k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient"
)

type fakeIdentitySvcClient struct{}

func (c fakeIdentitySvcClient) GetPluginInfo(context.Context) (*csi.GetPluginInfoResponse, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious...why you need to fakeIdentitySvcClient, fakeNodeSvcClient?? sanity tests needs to fake cloud/mount functionality only, not nodeserver and identity server methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSI Manila takes on a bit different approach than Cinder. All node-related operations are delegated to, and performed by a dedicated Node Plugin (see the docs here).

return &csi.GetPluginInfoResponse{
Name: "fake-fwd-driver",
VendorVersion: "1.0.0",
}, nil
}

func (c fakeIdentitySvcClient) ProbeForever(*grpc.ClientConn, time.Duration) error { return nil }

type fakeNodeSvcClient struct{}

func (c fakeNodeSvcClient) GetCapabilities(context.Context) (*csi.NodeGetCapabilitiesResponse, error) {
return &csi.NodeGetCapabilitiesResponse{
Capabilities: []*csi.NodeServiceCapability{
{
Type: &csi.NodeServiceCapability_Rpc{
Rpc: &csi.NodeServiceCapability_RPC{
Type: csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
},
},
},
},
}, nil
}

func (c fakeNodeSvcClient) StageVolume(context.Context, *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
return &csi.NodeStageVolumeResponse{}, nil
}

func (c fakeNodeSvcClient) UnstageVolume(context.Context, *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
return &csi.NodeUnstageVolumeResponse{}, nil
}

func (c fakeNodeSvcClient) PublishVolume(context.Context, *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
return &csi.NodePublishVolumeResponse{}, nil
}

func (c fakeNodeSvcClient) UnpublishVolume(context.Context, *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
return &csi.NodeUnpublishVolumeResponse{}, nil
}

type fakeCSIClientBuilder struct{}

func (b fakeCSIClientBuilder) NewConnection(string) (*grpc.ClientConn, error) { return nil, nil }

func (b fakeCSIClientBuilder) NewConnectionWithContext(context.Context, string) (*grpc.ClientConn, error) {
return nil, nil
}

func (b fakeCSIClientBuilder) NewNodeServiceClient(conn *grpc.ClientConn) csiclient.Node {
return &fakeNodeSvcClient{}
}

func (b fakeCSIClientBuilder) NewIdentityServiceClient(conn *grpc.ClientConn) csiclient.Identity {
return &fakeIdentitySvcClient{}
}
Loading