Skip to content

Commit ea8720b

Browse files
authored
Merge pull request #312 from davidz627/bump/sanity
Update CSI Sanity to v2.0.1 and fix compatibility errors
2 parents 16f5e99 + 7b74b9d commit ea8720b

File tree

14 files changed

+1397
-169
lines changed

14 files changed

+1397
-169
lines changed

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
[[constraint]]
4949
name = "github.com/kubernetes-csi/csi-test"
50-
version = "v1.0.0"
50+
version = "v2.0.1"
5151

5252
[[constraint]]
5353
branch = "master"

pkg/gce-pd-csi-driver/controller.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/golang/protobuf/ptypes"
2525

2626
"context"
27+
2728
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
2829
csi "github.com/container-storage-interface/spec/lib/go/csi"
2930
compute "google.golang.org/api/compute/v1"
@@ -163,6 +164,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
163164
if content.GetSnapshot() != nil {
164165
// TODO(#161): Add support for Volume Source (cloning) introduced in CSI v1.0.0
165166
snapshotId = content.GetSnapshot().GetSnapshotId()
167+
168+
// Verify that snapshot exists
169+
sl, err := gceCS.getSnapshotById(ctx, snapshotId)
170+
if err != nil {
171+
return nil, status.Errorf(codes.Internal, "CreateVolume failed to get snapshot %s: %v", snapshotId, err)
172+
} else if len(sl.Entries) == 0 {
173+
return nil, status.Errorf(codes.NotFound, "CreateVolume source snapshot %s does not exist", snapshotId)
174+
}
166175
}
167176
}
168177

@@ -171,7 +180,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
171180
switch replicationType {
172181
case replicationTypeNone:
173182
if len(zones) != 1 {
174-
return nil, status.Errorf(codes.Internal, fmt.Sprintf("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v", zones))
183+
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v", zones))
175184
}
176185
disk, err = createSingleZoneDisk(ctx, gceCS.CloudProvider, name, zones, diskType, capacityRange, capBytes, snapshotId, diskEncryptionKmsKey)
177186
if err != nil {

pkg/gce-pd-csi-driver/controller_test.go

+75-28
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import (
2222
"testing"
2323
"time"
2424

25+
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
2526
"github.com/golang/protobuf/ptypes"
2627

2728
"context"
29+
2830
compute "google.golang.org/api/compute/v1"
2931
"google.golang.org/grpc/codes"
3032
"google.golang.org/grpc/status"
@@ -588,34 +590,6 @@ func TestCreateVolumeArguments(t *testing.T) {
588590
},
589591
},
590592
},
591-
{
592-
name: "success with data source of snapshot type",
593-
req: &csi.CreateVolumeRequest{
594-
Name: "test-name",
595-
CapacityRange: stdCapRange,
596-
VolumeCapabilities: stdVolCaps,
597-
VolumeContentSource: &csi.VolumeContentSource{
598-
Type: &csi.VolumeContentSource_Snapshot{
599-
Snapshot: &csi.VolumeContentSource_SnapshotSource{
600-
SnapshotId: "snapshot-source",
601-
},
602-
},
603-
},
604-
},
605-
expVol: &csi.Volume{
606-
CapacityBytes: common.GbToBytes(20),
607-
VolumeId: testVolumeId,
608-
VolumeContext: nil,
609-
AccessibleTopology: stdTopology,
610-
ContentSource: &csi.VolumeContentSource{
611-
Type: &csi.VolumeContentSource_Snapshot{
612-
Snapshot: &csi.VolumeContentSource_SnapshotSource{
613-
SnapshotId: "snapshot-source",
614-
},
615-
},
616-
},
617-
},
618-
},
619593
{
620594
name: "success with block volume capability",
621595
req: &csi.CreateVolumeRequest{
@@ -690,6 +664,8 @@ func TestCreateVolumeArguments(t *testing.T) {
690664
// Setup new driver each time so no interference
691665
gceDriver := initGCEDriver(t, nil)
692666

667+
//gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )
668+
693669
// Start Test
694670
resp, err := gceDriver.cs.CreateVolume(context.Background(), tc.req)
695671
//check response
@@ -728,6 +704,77 @@ func TestCreateVolumeArguments(t *testing.T) {
728704
}
729705
}
730706

707+
func TestCreateVolumeWithVolumeSource(t *testing.T) {
708+
// Define test cases
709+
testCases := []struct {
710+
name string
711+
volKey *meta.Key
712+
snapshotOnCloud bool
713+
expErrCode codes.Code
714+
}{
715+
{
716+
name: "success with data source of snapshot type",
717+
volKey: meta.ZonalKey("my-disk", zone),
718+
snapshotOnCloud: true,
719+
},
720+
{
721+
name: "fail with data source of snapshot type that doesn't exist",
722+
volKey: meta.ZonalKey("my-disk", zone),
723+
snapshotOnCloud: false,
724+
expErrCode: codes.NotFound,
725+
},
726+
}
727+
728+
// Run test cases
729+
for _, tc := range testCases {
730+
t.Logf("test case: %s", tc.name)
731+
// Setup new driver each time so no interference
732+
gceDriver := initGCEDriver(t, nil)
733+
734+
//gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )
735+
736+
// Start Test
737+
req := &csi.CreateVolumeRequest{
738+
Name: "test-name",
739+
CapacityRange: stdCapRange,
740+
VolumeCapabilities: stdVolCaps,
741+
VolumeContentSource: &csi.VolumeContentSource{
742+
Type: &csi.VolumeContentSource_Snapshot{
743+
Snapshot: &csi.VolumeContentSource_SnapshotSource{
744+
SnapshotId: testSnapshotId,
745+
},
746+
},
747+
},
748+
}
749+
750+
if tc.snapshotOnCloud {
751+
gceDriver.cs.CloudProvider.CreateSnapshot(context.Background(), tc.volKey, name)
752+
}
753+
resp, err := gceDriver.cs.CreateVolume(context.Background(), req)
754+
//check response
755+
if err != nil {
756+
serverError, ok := status.FromError(err)
757+
if !ok {
758+
t.Fatalf("Could not get error status code from err: %v", serverError)
759+
}
760+
if serverError.Code() != tc.expErrCode {
761+
t.Fatalf("Expected error code: %v, got: %v. err : %v", tc.expErrCode, serverError.Code(), err)
762+
}
763+
continue
764+
}
765+
if tc.expErrCode != codes.OK {
766+
t.Fatalf("Expected error: %v, got no error", tc.expErrCode)
767+
}
768+
769+
// Make sure response has snapshot
770+
vol := resp.GetVolume()
771+
if vol.ContentSource == nil || vol.ContentSource.Type == nil || vol.ContentSource.GetSnapshot() == nil || vol.ContentSource.GetSnapshot().SnapshotId == "" {
772+
t.Fatalf("Expected volume content source to have snapshot ID, got none")
773+
}
774+
775+
}
776+
}
777+
731778
func TestCreateVolumeRandomRequisiteTopology(t *testing.T) {
732779
req := &csi.CreateVolumeRequest{
733780
Name: "test-name",

test/sanity/sanity_test.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ limitations under the License.
1515
package sanitytest
1616

1717
import (
18+
"fmt"
19+
"os"
20+
"path"
1821
"testing"
1922

2023
sanity "github.com/kubernetes-csi/csi-test/pkg/sanity"
@@ -31,9 +34,10 @@ func TestSanity(t *testing.T) {
3134
project := "test-project"
3235
zone := "test-zone"
3336
vendorVersion := "test-version"
34-
endpoint := "unix:/tmp/csi.sock"
35-
mountPath := "/tmp/csi/mount"
36-
stagePath := "/tmp/csi/stage"
37+
tmpDir := "/tmp/csi"
38+
endpoint := fmt.Sprintf("unix:%s/csi.sock", tmpDir)
39+
mountPath := path.Join(tmpDir, "mount")
40+
stagePath := path.Join(tmpDir, "stage")
3741
// Set up driver and env
3842
gceDriver := driver.GetGCEDriver()
3943

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

64+
err = os.MkdirAll(tmpDir, 0755)
65+
if err != nil {
66+
t.Fatalf("Failed to create sanity temp working dir %s: %v", tmpDir, err)
67+
}
68+
69+
defer func() {
70+
// Clean up tmp dir
71+
if err = os.RemoveAll(tmpDir); err != nil {
72+
t.Fatalf("Failed to clean up sanity temp working dir %s: %v", tmpDir, err)
73+
}
74+
}()
75+
6076
go func() {
6177
gceDriver.Run(endpoint)
6278
}()

vendor/github.com/kubernetes-csi/csi-test/.travis.yml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kubernetes-csi/csi-test/pkg/sanity/cleanup.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)