Skip to content

Update CSI Sanity to v2.0.1 and fix compatibility errors #312

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 3 commits into from
Jun 24, 2019
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.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

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

[[constraint]]
branch = "master"
Expand Down
11 changes: 10 additions & 1 deletion pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/golang/protobuf/ptypes"

"context"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
csi "github.com/container-storage-interface/spec/lib/go/csi"
compute "google.golang.org/api/compute/v1"
Expand Down Expand Up @@ -163,6 +164,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
if content.GetSnapshot() != nil {
// TODO(#161): Add support for Volume Source (cloning) introduced in CSI v1.0.0
snapshotId = content.GetSnapshot().GetSnapshotId()

// Verify that snapshot exists
sl, err := gceCS.getSnapshotById(ctx, snapshotId)
if err != nil {
return nil, status.Errorf(codes.Internal, "CreateVolume failed to get snapshot %s: %v", snapshotId, err)
} else if len(sl.Entries) == 0 {
return nil, status.Errorf(codes.NotFound, "CreateVolume source snapshot %s does not exist", snapshotId)
}
}
}

Expand All @@ -171,7 +180,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
switch replicationType {
case replicationTypeNone:
if len(zones) != 1 {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v", zones))
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v", zones))
}
disk, err = createSingleZoneDisk(ctx, gceCS.CloudProvider, name, zones, diskType, capacityRange, capBytes, snapshotId, diskEncryptionKmsKey)
if err != nil {
Expand Down
103 changes: 75 additions & 28 deletions pkg/gce-pd-csi-driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (
"testing"
"time"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"github.com/golang/protobuf/ptypes"

"context"

compute "google.golang.org/api/compute/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -588,34 +590,6 @@ func TestCreateVolumeArguments(t *testing.T) {
},
},
},
{
name: "success with data source of snapshot type",
req: &csi.CreateVolumeRequest{
Name: "test-name",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCaps,
VolumeContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: "snapshot-source",
},
},
},
},
expVol: &csi.Volume{
CapacityBytes: common.GbToBytes(20),
VolumeId: testVolumeId,
VolumeContext: nil,
AccessibleTopology: stdTopology,
ContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: "snapshot-source",
},
},
},
},
},
{
name: "success with block volume capability",
req: &csi.CreateVolumeRequest{
Expand Down Expand Up @@ -690,6 +664,8 @@ func TestCreateVolumeArguments(t *testing.T) {
// Setup new driver each time so no interference
gceDriver := initGCEDriver(t, nil)

//gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )

// Start Test
resp, err := gceDriver.cs.CreateVolume(context.Background(), tc.req)
//check response
Expand Down Expand Up @@ -728,6 +704,77 @@ func TestCreateVolumeArguments(t *testing.T) {
}
}

func TestCreateVolumeWithVolumeSource(t *testing.T) {
// Define test cases
testCases := []struct {
name string
volKey *meta.Key
snapshotOnCloud bool
expErrCode codes.Code
}{
{
name: "success with data source of snapshot type",
volKey: meta.ZonalKey("my-disk", zone),
snapshotOnCloud: true,
},
{
name: "fail with data source of snapshot type that doesn't exist",
volKey: meta.ZonalKey("my-disk", zone),
snapshotOnCloud: false,
expErrCode: codes.NotFound,
},
}

// Run test cases
for _, tc := range testCases {
t.Logf("test case: %s", tc.name)
// Setup new driver each time so no interference
gceDriver := initGCEDriver(t, nil)

//gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )

// Start Test
req := &csi.CreateVolumeRequest{
Name: "test-name",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCaps,
VolumeContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: testSnapshotId,
},
},
},
}

if tc.snapshotOnCloud {
gceDriver.cs.CloudProvider.CreateSnapshot(context.Background(), tc.volKey, name)
}
resp, err := gceDriver.cs.CreateVolume(context.Background(), req)
//check response
if err != nil {
serverError, ok := status.FromError(err)
if !ok {
t.Fatalf("Could not get error status code from err: %v", serverError)
}
if serverError.Code() != tc.expErrCode {
t.Fatalf("Expected error code: %v, got: %v. err : %v", tc.expErrCode, serverError.Code(), err)
}
continue
}
if tc.expErrCode != codes.OK {
t.Fatalf("Expected error: %v, got no error", tc.expErrCode)
}

// Make sure response has snapshot
vol := resp.GetVolume()
if vol.ContentSource == nil || vol.ContentSource.Type == nil || vol.ContentSource.GetSnapshot() == nil || vol.ContentSource.GetSnapshot().SnapshotId == "" {
t.Fatalf("Expected volume content source to have snapshot ID, got none")
}

}
}

func TestCreateVolumeRandomRequisiteTopology(t *testing.T) {
req := &csi.CreateVolumeRequest{
Name: "test-name",
Expand Down
22 changes: 19 additions & 3 deletions test/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ limitations under the License.
package sanitytest

import (
"fmt"
"os"
"path"
"testing"

sanity "github.com/kubernetes-csi/csi-test/pkg/sanity"
Expand All @@ -31,9 +34,10 @@ func TestSanity(t *testing.T) {
project := "test-project"
zone := "test-zone"
vendorVersion := "test-version"
endpoint := "unix:/tmp/csi.sock"
mountPath := "/tmp/csi/mount"
stagePath := "/tmp/csi/stage"
tmpDir := "/tmp/csi"
endpoint := fmt.Sprintf("unix:%s/csi.sock", tmpDir)
mountPath := path.Join(tmpDir, "mount")
stagePath := path.Join(tmpDir, "stage")
// Set up driver and env
gceDriver := driver.GetGCEDriver()

Expand All @@ -57,6 +61,18 @@ func TestSanity(t *testing.T) {
}
cloudProvider.InsertInstance(instance, "test-location", "test-name")

err = os.MkdirAll(tmpDir, 0755)
if err != nil {
t.Fatalf("Failed to create sanity temp working dir %s: %v", tmpDir, err)
}

defer func() {
// Clean up tmp dir
if err = os.RemoveAll(tmpDir); err != nil {
t.Fatalf("Failed to clean up sanity temp working dir %s: %v", tmpDir, err)
}
}()

go func() {
gceDriver.Run(endpoint)
}()
Expand Down

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

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

Loading