Skip to content

Commit

Permalink
Test framework initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Pan committed Oct 11, 2019
1 parent 2071560 commit 8649833
Show file tree
Hide file tree
Showing 13 changed files with 755 additions and 519 deletions.
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -9,7 +9,9 @@ require (
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
google.golang.org/grpc v1.23.0
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/client-go v0.0.0
k8s.io/klog v0.4.0
k8s.io/kubernetes v1.16.1
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/driver.go
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
driverName = "fsx.csi.aws.com"
DriverName = "fsx.csi.aws.com"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/identity.go
Expand Up @@ -24,7 +24,7 @@ import (

func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
resp := &csi.GetPluginInfoResponse{
Name: driverName,
Name: DriverName,
VendorVersion: driverVersion,
}

Expand Down
58 changes: 58 additions & 0 deletions tests/e2e/cloud.go
@@ -0,0 +1,58 @@
/*
Copyright 2018 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 e2e

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)

func getNodeInstance(clusterName string) (*ec2.Instance, error) {
config := &aws.Config{
Region: region,
}
nodeName := fmt.Sprintf("nodes.%s", clusterName)
svc := ec2.New(session.Must(session.NewSession(config)))
request := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:Name"),
Values: []*string{aws.String(nodeName)},
},
},
}

instances := []*ec2.Instance{}
response, err := svc.DescribeInstances(request)
if err != nil {
return nil, err
}
for _, reservation := range response.Reservations {
instances = append(instances, reservation.Instances...)
}

return instances[0], nil
}

func getSecurityGroupIds(node *ec2.Instance) []string {
groups := []string{}
for _, sg := range node.SecurityGroups {
groups = append(groups, *sg.GroupId)
}
return groups
}
61 changes: 61 additions & 0 deletions tests/e2e/driver/driver.go
@@ -0,0 +1,61 @@
/*
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 driver

import (
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type PVTestDriver interface {
DynamicPVTestDriver
}

// DynamicPVTestDriver represents an interface for a CSI driver that supports DynamicPV
type DynamicPVTestDriver interface {
// GetDynamicProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume
GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
}

func getStorageClass(
generateName string,
provisioner string,
parameters map[string]string,
mountOptions []string,
reclaimPolicy *v1.PersistentVolumeReclaimPolicy,
bindingMode *storagev1.VolumeBindingMode,
allowedTopologies []v1.TopologySelectorTerm,
) *storagev1.StorageClass {
if reclaimPolicy == nil {
defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete
reclaimPolicy = &defaultReclaimPolicy
}
if bindingMode == nil {
defaultBindingMode := storagev1.VolumeBindingImmediate
bindingMode = &defaultBindingMode
}
return &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
GenerateName: generateName,
},
Provisioner: provisioner,
Parameters: parameters,
MountOptions: mountOptions,
ReclaimPolicy: reclaimPolicy,
VolumeBindingMode: bindingMode,
AllowedTopologies: allowedTopologies,
}
}
42 changes: 42 additions & 0 deletions tests/e2e/driver/fsx_csi_driver.go
@@ -0,0 +1,42 @@
/*
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 driver

import (
"fmt"

fsxcsidriver "github.com/kubernetes-sigs/aws-fsx-csi-driver/pkg/driver"
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
)

// Implement PVTestDriver interface
type fsxCSIDriver struct {
driverName string
}

// InitFSxCSIDriver returns fsxCSIDriver that implements DynamicPVTestDriver interface
func InitFSxCSIDriver() PVTestDriver {
return &fsxCSIDriver{
driverName: fsxcsidriver.DriverName,
}
}

func (d *fsxCSIDriver) GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass {
provisioner := d.driverName
generateName := fmt.Sprintf("%s-%s-dynamic-sc-", namespace, provisioner)
allowedTopologies := []v1.TopologySelectorTerm{}
return getStorageClass(generateName, provisioner, parameters, mountOptions, reclaimPolicy, bindingMode, allowedTopologies)
}
134 changes: 89 additions & 45 deletions tests/e2e/dynamic_provisioning_test.go
@@ -1,63 +1,107 @@
/*
Copyright 2018 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 e2e

import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/kubernetes-sigs/aws-fsx-csi-driver/tests/e2e/driver"
"github.com/kubernetes-sigs/aws-fsx-csi-driver/tests/e2e/testsuites"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
)

var _ = Describe("[ebs-csi-e2e] [single-az] Dynamic Provisioning", func() {
var _ = Describe("[fsx-csi-e2e] Dynamic Provisioning", func() {
f := framework.NewDefaultFramework("fsx")

It("should succeed", func() {
fmt.Println("Cluster name " + *clusterName)
fmt.Println(framework.TestContext.ReportDir)
var (
cs clientset.Interface
ns *v1.Namespace
dvr driver.PVTestDriver
subnetId string
securityGroupIds []string
)

BeforeEach(func() {
cs = f.ClientSet
ns = f.Namespace
dvr = driver.InitFSxCSIDriver()
instance, err := getNodeInstance(*clusterName)
if err != nil {
fmt.Println(err)
Fail(fmt.Sprintf("could ge node instance %v", err))
}
fmt.Println(getSecurityGroup(instance))
fmt.Println(*instance.SubnetId)
Expect(true).To(Equal(true))
securityGroupIds = getSecurityGroupIds(instance)
subnetId = *instance.SubnetId
})
})

func getNodeInstance(clusterName string) (*ec2.Instance, error) {
config := &aws.Config{
Region: region,
}
nodeName := fmt.Sprintf("nodes.%s", clusterName)
svc := ec2.New(session.Must(session.NewSession(config)))
request := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
It("should create a volume on demand with subnetId and security groups", func() {
log.Printf("Using subnet ID %s security group ID %s", subnetId, securityGroupIds)
pods := []testsuites.PodDetails{
{
Name: aws.String("tag:Name"),
Values: []*string{aws.String(nodeName)},
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
Volumes: []testsuites.VolumeDetails{
{
Parameters: map[string]string{
"subnetId": subnetId,
"securityGroupIds": strings.Join(securityGroupIds, ","),
},
ClaimSize: "3600Gi",
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
},
},
}

instances := []*ec2.Instance{}
response, err := svc.DescribeInstances(request)
if err != nil {
return nil, err
}
for _, reservation := range response.Reservations {
instances = append(instances, reservation.Instances...)
}

return instances[0], nil
}

func getSecurityGroup(node *ec2.Instance) []string {
groups := []string{}
for _, sg := range node.SecurityGroups {
groups = append(groups, *sg.GroupId)
}
return groups
}
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: dvr,
Pods: pods,
}
test.Run(cs, ns)
})

It("should create a volume on demand with flock mount option", func() {
log.Printf("Using subnet ID %s security group ID %s", subnetId, securityGroupIds)
pods := []testsuites.PodDetails{
{
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
Volumes: []testsuites.VolumeDetails{
{
Parameters: map[string]string{
"subnetId": subnetId,
"securityGroupIds": strings.Join(securityGroupIds, ","),
},
MountOptions: []string{"flock"},
ClaimSize: "1200Gi",
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: dvr,
Pods: pods,
}
test.Run(cs, ns)
})
})

0 comments on commit 8649833

Please sign in to comment.