Skip to content

Commit

Permalink
Merge pull request #47 from stoneshi-yunify/neonsan-e2e
Browse files Browse the repository at this point in the history
fix Neonsan e2e test code
  • Loading branch information
min-zh authored Oct 16, 2020
2 parents 5129dda + 4e41025 commit a326b83
Show file tree
Hide file tree
Showing 1,257 changed files with 314,748 additions and 17 deletions.
42 changes: 42 additions & 0 deletions cmd/tests/e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 2018 Yunify, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
You may obtain a copy of the License in the LICENSE file, or 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 (
"flag"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "github.com/yunify/qingstor-csi/pkg/test/e2e"
"k8s.io/kubernetes/test/e2e/framework"
"testing"
)

func init() {
framework.RegisterCommonFlags(flag.CommandLine)
framework.RegisterClusterFlags(flag.CommandLine)
flag.Parse()
framework.AfterReadingAllFlags(&framework.TestContext)
}

func Test(t *testing.T) {
flag.Parse()
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Suite")
}

func main() {
Test(&testing.T{})
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
golang.org/x/net v0.0.0-20191112182307-2180aed22343
google.golang.org/appengine v1.6.1 // indirect
google.golang.org/grpc v1.26.0
k8s.io/api v0.18.6
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.6
k8s.io/klog v1.0.0
Expand Down
34 changes: 34 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pkg/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ func (s *service) ControllerExpandVolume(ctx context.Context, req *csi.Controlle
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
// set NodeExpansionRequired flag
nodeExpansion := req.GetVolumeCapability() != nil && req.GetVolumeCapability().GetMount() != nil
return &csi.ControllerExpandVolumeResponse{
CapacityBytes: requiredSizeBytes,
NodeExpansionRequired: true,
NodeExpansionRequired: nodeExpansion,
}, nil
}

Expand Down
24 changes: 14 additions & 10 deletions pkg/service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func (s *service) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeR

// idempotent attach volume, qbd -m neonsan volume
devicePath, err := s.nodeAttachVolume(volumeID)
if err != nil{
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

// if block mode, skip mount
if req.GetVolumeCapability().GetBlock() != nil{
return &csi.NodeStageVolumeResponse{},nil
if req.GetVolumeCapability().GetBlock() != nil {
return &csi.NodeStageVolumeResponse{}, nil
}

// if volume already mounted
Expand Down Expand Up @@ -77,7 +77,7 @@ func (s *service) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVol
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if !notMnt{
if !notMnt {
// count mount point
_, cnt, err := mount.GetDeviceNameFromMount(s.mounter.Interface, targetPath)
if err != nil {
Expand Down Expand Up @@ -129,19 +129,19 @@ func (s *service) NodePublishVolume(ctx context.Context, req *csi.NodePublishVol
if req.GetReadonly() == true {
options = append(options, "ro")
}
if isBlock{
if isBlock {
devicePath, err := s.storageProvider.NodeGetDevice(volumeID)
if err != nil{
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if len(devicePath) == 0{
if len(devicePath) == 0 {
return nil, status.Error(codes.Internal, "device empty")
}
err = s.mounter.Interface.Mount(devicePath, targetPath, "", options)
} else {
err = s.mounter.Interface.Mount(stagePath, targetPath, fsType, options)
}
if err != nil{
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &csi.NodePublishVolumeResponse{}, nil
Expand Down Expand Up @@ -187,6 +187,10 @@ func (s *service) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolum
if err != nil {
return nil, status.Errorf(codes.Internal, "Cannot find device path of volume %s, error:%s", volumeID, err.Error())
}
isBlock := req.GetVolumeCapability() != nil && req.GetVolumeCapability().GetBlock() != nil
if isBlock {
return &csi.NodeExpandVolumeResponse{CapacityBytes: requestSizeBytes}, nil
}
resizeFs := resizefs.NewResizeFs(s.mounter)
ok, err := resizeFs.Resize(devicePath, volumePath)
if err != nil {
Expand Down Expand Up @@ -244,7 +248,7 @@ func (s *service) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolume

// nodeAttachVolume
// idempotent attach volume
func (s *service) nodeAttachVolume(volumeID string) (string, error) {
func (s *service) nodeAttachVolume(volumeID string) (string, error) {
// for idempotent, if device not empty, volume has already attached
devicePath, err := s.storageProvider.NodeGetDevice(volumeID)
if err != nil {
Expand Down Expand Up @@ -274,4 +278,4 @@ func (s *service) nodeDetachVolume(volumeID string) error {
}
// node detach volume
return s.storageProvider.NodeDetachVolume(volumeID)
}
}
15 changes: 9 additions & 6 deletions pkg/test/e2e/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/volume"
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
)
Expand All @@ -28,7 +29,7 @@ type driver struct {
driverInfo testsuites.DriverInfo
}

const driverName = "neonsan.csi.qingcloud.com"
const driverName = "neonsan.csi.qingstor.com"

// initDriver returns driver that implements TestDriver interface
func initDriver(name string) testsuites.TestDriver {
Expand All @@ -37,10 +38,10 @@ func initDriver(name string) testsuites.TestDriver {
)
return &driver{
driverInfo: testsuites.DriverInfo{
Name: name,
Name: driverName,
MaxFileSize: testpatterns.FileSizeLarge,
SupportedFsType: supportedTypes,
//SupportedSizeRange: volume.SizeRange{Min: "5Gi"},
SupportedSizeRange: volume.SizeRange{Min: "5Gi"},
SupportedMountOption: sets.NewString(),
Capabilities: map[testsuites.Capability]bool{
testsuites.CapPersistence: true,
Expand All @@ -54,7 +55,8 @@ func initDriver(name string) testsuites.TestDriver {
testsuites.CapNodeExpansion: true,
testsuites.CapVolumeLimits: true,
testsuites.CapSingleNodeVolume: true,
//testsuites.CapTopology: true,
testsuites.CapRWX: true,
testsuites.CapTopology: false,
},
},
}
Expand Down Expand Up @@ -82,7 +84,8 @@ func (n *driver) PrepareTest(f *framework.Framework) (*testsuites.PerTestConfig,

func (n *driver) GetDynamicProvisionStorageClass(config *testsuites.PerTestConfig, fsType string) *v12.StorageClass {
parameters := map[string]string{
"pool": "testPool",
"pool_name": "kube",
"rep_count": "1",
}
//if fsType != "" {
// parameters["fsType"] = fsType
Expand All @@ -102,6 +105,6 @@ func (n *driver) GetSnapshotClass(config *testsuites.PerTestConfig) *unstructure
return testsuites.GetSnapshotClass(driverName, parameters, ns, "neonsan")
}

func (n *driver) GetClaimSize() string{
func (n *driver) GetClaimSize() string {
return "5Gi"
}
1 change: 1 addition & 0 deletions pkg/test/e2e/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var CSITestSuites = []func() testsuites.TestSuite{
testsuites.InitVolumeIOTestSuite,
testsuites.InitVolumeLimitsTestSuite,
testsuites.InitVolumesTestSuite,
testsuites.InitVolumeModeTestSuite,
}

// This executes testSuites for csi volumes.
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/beorn7/perks/LICENSE

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

Loading

0 comments on commit a326b83

Please sign in to comment.