Skip to content

Commit d92821d

Browse files
committed
csi test
1 parent 1b1960b commit d92821d

File tree

15 files changed

+1370
-69
lines changed

15 files changed

+1370
-69
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ script:
2424
- go test -v github.com/opensds/nbp/csi/... -cover
2525
- go test -v github.com/opensds/nbp/flexvolume/... -cover
2626
- go test -v github.com/opensds/nbp/cindercompatibleapi/... -cover
27+
- go test -v github.com/opensds/nbp/csi/server/sanity/... -cover
2728

2829
after_success:
2930
# Clean OpenSDS northbound plugin built data

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
name = "k8s.io/client-go"
7878
version = "kubernetes-1.13.0-beta.1"
7979

80+
[[constraint]]
81+
name = "github.com/kubernetes-csi/csi-test"
82+
version = "v1.1.0"
83+
8084
[prune]
8185
non-go = true
8286
go-tests = true

csi/server/plugin/opensds/controller.go

Lines changed: 97 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ func (p *Plugin) CreateVolume(
7676

7777
func checkInputParameters(params map[string]string) error {
7878
if params == nil {
79-
return errors.New("input parameters cannot be nil")
79+
return errors.New("volume creation parameters cannot be nil")
8080
}
8181

8282
keyList := []string{ParamProfile, ParamEnableReplication, ParamSecondaryAZ, PublishAttachMode, StorageType}
8383

8484
for k, _ := range params {
8585
if !util.Contained(k, keyList) {
86-
return fmt.Errorf("invalid input paramter key: %s. It should be one of %s,%s,%s,%s,%s",
86+
return fmt.Errorf("invalid volume creation paramter key: %s. It should be one of %s,%s,%s,%s,%s",
8787
k, ParamProfile, ParamEnableReplication, ParamSecondaryAZ, PublishAttachMode, StorageType)
8888
}
8989
}
@@ -148,12 +148,22 @@ func (p *Plugin) ControllerPublishVolume(ctx context.Context,
148148
return nil, status.Error(codes.InvalidArgument, msg)
149149
}
150150

151-
if req.NodeId == "" {
151+
if req.GetNodeId() == "" {
152152
msg := "node ID must be provided"
153153
glog.Error(msg)
154154
return nil, status.Error(codes.InvalidArgument, msg)
155155
}
156156

157+
if req.GetVolumeCapability() == nil {
158+
msg := "volume capability must be provided"
159+
glog.Error(msg)
160+
return nil, status.Error(codes.InvalidArgument, msg)
161+
}
162+
163+
if req.GetReadonly() {
164+
return nil, status.Error(codes.AlreadyExists, "read only volumes are not supported")
165+
}
166+
157167
glog.V(5).Infof("plugin information %#v", p)
158168
glog.V(5).Infof("current storage type: %s", p.PluginStorageType)
159169

@@ -193,11 +203,29 @@ func (p *Plugin) ControllerUnpublishVolume(
193203
}
194204

195205
// ValidateVolumeCapabilities implementation
196-
func (p *Plugin) ValidateVolumeCapabilities(
197-
ctx context.Context,
206+
func (p *Plugin) ValidateVolumeCapabilities(ctx context.Context,
198207
req *csi.ValidateVolumeCapabilitiesRequest) (
199208
*csi.ValidateVolumeCapabilitiesResponse, error) {
200-
return nil, status.Error(codes.Unimplemented, "")
209+
210+
volId := req.GetVolumeId()
211+
if volId == "" {
212+
return nil, status.Error(codes.InvalidArgument, "")
213+
}
214+
215+
if req.GetVolumeCapabilities() == nil {
216+
return nil, status.Error(codes.InvalidArgument, "")
217+
}
218+
219+
vol, err := p.Client.GetVolume(volId)
220+
if vol == nil || err != nil {
221+
return nil, status.Error(codes.NotFound, err.Error())
222+
}
223+
224+
return &csi.ValidateVolumeCapabilitiesResponse{
225+
Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{
226+
VolumeCapabilities: req.VolumeCapabilities,
227+
},
228+
}, nil
201229
}
202230

203231
// ListVolumes implementation
@@ -296,6 +324,13 @@ func (p *Plugin) ControllerGetCapabilities(
296324
},
297325
},
298326
},
327+
&csi.ControllerServiceCapability{
328+
Type: &csi.ControllerServiceCapability_Rpc{
329+
Rpc: &csi.ControllerServiceCapability_RPC{
330+
Type: csi.ControllerServiceCapability_RPC_PUBLISH_READONLY,
331+
},
332+
},
333+
},
299334
},
300335
}, nil
301336
}
@@ -426,12 +461,17 @@ func (p *Plugin) DeleteSnapshot(
426461
glog.V(5).Infof("start to delete snapshot, snapshot id: %v, delete snapshot secrets: %v!",
427462
req.SnapshotId, req.Secrets)
428463

429-
if 0 == len(req.SnapshotId) {
464+
snpId := req.GetSnapshotId()
465+
if snpId == "" {
430466
return nil, status.Error(codes.InvalidArgument, "snapshot id cannot be empty")
431467
}
432468

433-
err := p.Client.DeleteVolumeSnapshot(req.SnapshotId, nil)
469+
snp, _ := p.Client.GetVolumeSnapshot(snpId)
470+
if snp == nil {
471+
return &csi.DeleteSnapshotResponse{}, nil
472+
}
434473

474+
err := p.Client.DeleteVolumeSnapshot(req.SnapshotId, nil)
435475
if nil != err {
436476
msg := fmt.Sprintf("delete snapshot failed: %v", err)
437477
glog.Error(msg)
@@ -488,18 +528,19 @@ func (p *Plugin) ListSnapshots(
488528
break
489529
case (0 == snapshotIDLen) && (0 != sourceVolumeIdLen):
490530
if len(snapshotsFilterByVolumeId) <= 0 {
491-
return nil, status.Error(codes.NotFound, fmt.Sprintf("no snapshot with source volume id %s", sourceVolumeId))
531+
return &csi.ListSnapshotsResponse{Entries: []*csi.ListSnapshotsResponse_Entry{}}, nil
492532
}
493533

494534
filterResult = snapshotsFilterByVolumeId
495535
break
496536
case (0 != snapshotIDLen) && (0 == sourceVolumeIdLen):
497537
if len(snapshotsFilterById) <= 0 {
498-
return nil, status.Error(codes.NotFound, fmt.Sprintf("no snapshot with id %s", snapshotId))
538+
return &csi.ListSnapshotsResponse{Entries: []*csi.ListSnapshotsResponse_Entry{}}, nil
499539
}
500540

501541
filterResult = snapshotsFilterById
502542
break
543+
case (0 != snapshotIDLen) && (0 != sourceVolumeIdLen):
503544
case (0 != snapshotIDLen) && (0 != sourceVolumeIdLen):
504545
for _, snapshot := range snapshotsFilterById {
505546
if snapshot.VolumeId == sourceVolumeId {
@@ -687,28 +728,24 @@ func (p *Plugin) UnpublishRoutine() {
687728

688729
if err := p.Client.DeleteVolumeAttachment(act.Id, act); err != nil {
689730
glog.Errorf("%s failed to unpublish: %v", act.Id, err)
690-
} else {
691-
waitAttachmentDeleted(act.Id, func(id string) (interface{}, error) {
692-
return p.Client.GetVolumeAttachment(id)
693-
}, e)
694731
}
695732

733+
waitAttachmentDeleted(act.Id, func(id string) (interface{}, error) {
734+
return p.Client.GetVolumeAttachment(id)
735+
}, e)
736+
696737
// delete fileshare access control list if storage type is file
697738
case *model.FileShareAclSpec:
698739
act := e.Value.(*model.FileShareAclSpec)
699740

700741
if err := p.Client.DeleteFileShareAcl(act.Id); err != nil {
701-
if strings.Contains(err.Error(), "Not Found") {
702-
glog.Infof("delete attachment %s successfully", act.Id)
703-
UnpublishAttachmentList.Delete(e)
704-
} else {
705-
glog.Errorf("%s failed to unpublish: %v", act.Id, err)
706-
}
707-
} else {
708-
waitAttachmentDeleted(act.Id, func(id string) (interface{}, error) {
709-
return p.Client.GetFileShareAcl(id)
710-
}, e)
742+
glog.Errorf("%s failed to unpublish: %v", act.Id, err)
711743
}
744+
745+
waitAttachmentDeleted(act.Id, func(id string) (interface{}, error) {
746+
return p.Client.GetFileShareAcl(id)
747+
}, e)
748+
712749
}
713750

714751
time.Sleep(10 * time.Second)
@@ -726,16 +763,25 @@ func waitAttachmentDeleted(id string, f func(string) (interface{}, error), e *li
726763
for {
727764
select {
728765
case <-ticker.C:
729-
_, err := f(id)
730-
731-
if err != nil && strings.Contains(err.Error(), "Not Found") {
732-
glog.Infof("delete attachment %s successfully", id)
733-
UnpublishAttachmentList.Delete(e)
734-
return
735-
} else {
736-
glog.Errorf("delete attachment failed: %v", err)
766+
v, _ := f(id)
767+
768+
switch v.(type) {
769+
case *model.VolumeAttachmentSpec:
770+
if v.(*model.VolumeAttachmentSpec) == nil {
771+
glog.Infof("delete attachment %s successfully", id)
772+
UnpublishAttachmentList.Delete(e)
773+
return
774+
}
775+
case *model.FileShareAclSpec:
776+
if v.(*model.FileShareAclSpec) == nil {
777+
glog.Infof("delete attachment %s successfully", id)
778+
UnpublishAttachmentList.Delete(e)
779+
return
780+
}
737781
}
738782

783+
glog.Errorf("delete attachment %#v failed", v)
784+
739785
case <-timeout:
740786
glog.Errorf("waiting to delete %s timeout", id)
741787
return
@@ -755,14 +801,14 @@ func extractISCSIInitiatorFromNodeInfo(nodeInfo string) (string, error) {
755801
}
756802

757803
func extractNvmeofInitiatorFromNodeInfo(nodeInfo string) (string, error) {
758-
for _, v := range strings.Split(nodeInfo, ",") {
759-
if strings.Contains(v, "nqn") {
760-
glog.V(5).Info("Nvmeof initiator is ", v)
761-
return v, nil
762-
}
763-
}
764-
765-
return "", errors.New("no Nvmeof initiators found")
804+
for _, v := range strings.Split(nodeInfo, ",") {
805+
if strings.Contains(v, "nqn") {
806+
glog.V(5).Info("Nvmeof initiator is ", v)
807+
return v, nil
808+
}
809+
}
810+
811+
return "", errors.New("no Nvmeof initiators found")
766812
}
767813

768814
func extractFCInitiatorFromNodeInfo(nodeInfo string) ([]string, error) {
@@ -782,6 +828,17 @@ func extractFCInitiatorFromNodeInfo(nodeInfo string) ([]string, error) {
782828
return wwpns, nil
783829
}
784830

831+
func extractIpFromNodeInfo(nodeInfo string) (string, error) {
832+
for _, v := range strings.Split(nodeInfo, ",") {
833+
ip := net.ParseIP(v)
834+
if ip != nil {
835+
return v, nil
836+
}
837+
}
838+
839+
return "", errors.New("cannot find valid ip address")
840+
}
841+
785842
func getZone(requirement *csi.TopologyRequirement) string {
786843
if requirement == nil {
787844
return ""

csi/server/plugin/opensds/fileshare.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ const (
3434
)
3535

3636
type FileShare struct {
37-
Client *client.Client
37+
Client *client.Client
38+
Mounter connector.Mounter
3839
}
3940

40-
func NewFileshare(c *client.Client) *FileShare {
41-
return &FileShare{Client: c}
41+
func NewFileshare(c *client.Client, Mounter connector.Mounter) *FileShare {
42+
return &FileShare{
43+
Client: c,
44+
Mounter: Mounter,
45+
}
4246
}
4347

4448
func (f *FileShare) CreateFileShare(req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {

csi/server/plugin/opensds/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (p *Plugin) NodeGetInfo(
162162
glog.Info("start to get node info")
163163
defer glog.Info("end to get node info")
164164

165-
hostName, err := connector.GetHostName()
165+
hostName, err := p.Mounter.GetHostName()
166166
if err != nil {
167167
msg := fmt.Sprintf("failed to get node name: %v", err)
168168
glog.Error(msg)
@@ -171,7 +171,7 @@ func (p *Plugin) NodeGetInfo(
171171

172172
var initiators []string
173173

174-
volDriverTypes := []string{connector.FcDriver, connector.IscsiDriver, connector.NvmeofDriver}
174+
volDriverTypes := []string{connector.FcDriver, connector.IscsiDriver, connector.NvmeofDriver, connector.SampleDriver}
175175

176176
for _, volDriverType := range volDriverTypes {
177177
volDriver := connector.NewConnector(volDriverType)
@@ -195,7 +195,7 @@ func (p *Plugin) NodeGetInfo(
195195
return nil, status.Error(codes.FailedPrecondition, msg)
196196
}
197197

198-
nodeId := hostName + "," + strings.Join(initiators, ",") + "," + connector.GetHostIP()
198+
nodeId := hostName + "," + strings.Join(initiators, ",") + "," + p.Mounter.GetHostIP()
199199

200200
glog.Infof("node info is %s", nodeId)
201201

csi/server/plugin/opensds/plugin.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/opensds/nbp/client/opensds"
2020
"github.com/opensds/nbp/csi/server/plugin"
2121
"github.com/opensds/opensds/client"
22+
"github.com/opensds/opensds/contrib/connector"
2223
)
2324

2425
// Plugin define
@@ -27,6 +28,7 @@ type Plugin struct {
2728
Client *client.Client
2829
VolumeClient *Volume
2930
FileShareClient *FileShare
31+
Mounter connector.Mounter
3032
}
3133

3234
func NewServer(endpoint, authStrategy, storageType string) (plugin.Service, error) {
@@ -40,8 +42,9 @@ func NewServer(endpoint, authStrategy, storageType string) (plugin.Service, erro
4042
p := &Plugin{
4143
PluginStorageType: storageType,
4244
Client: client,
43-
VolumeClient: NewVolume(client),
44-
FileShareClient: NewFileshare(client),
45+
VolumeClient: NewVolume(client, connector.GetCommonMounter()),
46+
FileShareClient: NewFileshare(client, connector.GetCommonMounter()),
47+
Mounter: connector.GetCommonMounter(),
4548
}
4649

4750
// When there are multiple volumes unmount at the same time,

0 commit comments

Comments
 (0)