csi-driver-nfs/test/e2e/dynamic_provisioning_test.go
Mayank Shah 5747698dff Add DynamicallyProvisionedCmdVolumeTest
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
2020-11-11 20:47:25 +05:30

99 lines
2.9 KiB
Go

/*
Copyright 2020 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/kubernetes-csi/csi-driver-nfs/test/e2e/driver"
"github.com/kubernetes-csi/csi-driver-nfs/test/e2e/testsuites"
"github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
clientset "k8s.io/client-go/kubernetes"
restclientset "k8s.io/client-go/rest"
"k8s.io/kubernetes/test/e2e/framework"
)
var _ = ginkgo.Describe("Dynamic Provisioning", func() {
f := framework.NewDefaultFramework("nfs")
var (
cs clientset.Interface
ns *v1.Namespace
testDriver driver.PVTestDriver
)
ginkgo.BeforeEach(func() {
checkPodsRestart := testCmd{
command: "sh",
args: []string{"test/utils/check_driver_pods_restart.sh"},
startLog: "Check driver pods for restarts",
endLog: "Check successful",
}
execTestCmd([]testCmd{checkPodsRestart})
cs = f.ClientSet
ns = f.Namespace
var err error
_, err = restClient(testsuites.SnapshotAPIGroup, testsuites.APIVersionv1beta1)
if err != nil {
ginkgo.Fail(fmt.Sprintf("could not get rest clientset: %v", err))
}
})
testDriver = driver.InitNFSDriver()
ginkgo.It("should create a volume on demand with mount options [nfs.csi.k8s.io]", func() {
pods := []testsuites.PodDetails{
{
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
Volumes: []testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: testDriver,
Pods: pods,
StorageClassParameters: defaultStorageClassParameters,
}
test.Run(cs, ns)
})
})
func restClient(group string, version string) (restclientset.Interface, error) {
config, err := framework.LoadConfig()
if err != nil {
ginkgo.Fail(fmt.Sprintf("could not load config: %v", err))
}
gv := schema.GroupVersion{Group: group, Version: version}
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = serializer.WithoutConversionCodecFactory{CodecFactory: serializer.NewCodecFactory(runtime.NewScheme())}
return restclientset.RESTClientFor(config)
}