2020-10-29 02:44:35 +00:00
|
|
|
package fio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-01 20:45:57 +00:00
|
|
|
"encoding/json"
|
2020-10-29 02:44:35 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-29 19:46:29 +00:00
|
|
|
"github.com/kastenhq/kubestr/pkg/common"
|
2020-10-29 02:44:35 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
. "gopkg.in/check.v1"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
scv1 "k8s.io/api/storage/v1"
|
2020-12-01 01:37:56 +00:00
|
|
|
sv1 "k8s.io/api/storage/v1"
|
2020-10-29 02:44:35 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
|
|
k8stesting "k8s.io/client-go/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
|
|
|
type FIOTestSuite struct{}
|
|
|
|
|
|
|
|
var _ = Suite(&FIOTestSuite{})
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestRunner(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
runner := &FIOrunner{
|
|
|
|
Cli: nil,
|
|
|
|
}
|
|
|
|
_, err := runner.RunFio(ctx, nil)
|
|
|
|
c.Check(err, NotNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestRunFioHelper(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
for i, tc := range []struct {
|
|
|
|
cli kubernetes.Interface
|
|
|
|
stepper *fakeFioStepper
|
|
|
|
args *RunFIOArgs
|
|
|
|
expectedSteps []string
|
|
|
|
checker Checker
|
|
|
|
expectedCM string
|
|
|
|
expectedSC string
|
|
|
|
expectedSize string
|
|
|
|
expectedTFN string
|
|
|
|
expectedPVC string
|
|
|
|
}{
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // invalid args (storageclass)
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{},
|
|
|
|
args: &RunFIOArgs{},
|
|
|
|
checker: NotNil,
|
|
|
|
},
|
|
|
|
{ // invalid args (size)
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{},
|
|
|
|
args: &RunFIOArgs{
|
|
|
|
StorageClass: "sc",
|
|
|
|
},
|
|
|
|
checker: NotNil,
|
|
|
|
},
|
|
|
|
{ // invalid args (namespace)
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{},
|
|
|
|
args: &RunFIOArgs{
|
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
},
|
|
|
|
checker: NotNil,
|
|
|
|
},
|
|
|
|
{ // namespace doesn't exist
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
2020-12-01 01:37:56 +00:00
|
|
|
vnErr: fmt.Errorf("namespace Err"),
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: NotNil,
|
2020-12-01 01:37:56 +00:00
|
|
|
expectedSteps: []string{"VN"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
2022-08-16 19:51:19 +00:00
|
|
|
{ // no node satisfies selector
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
vnsErr: fmt.Errorf("node selector Err"),
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
|
|
|
checker: NotNil,
|
|
|
|
expectedSteps: []string{"VN", "VNS"},
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // storageclass not found
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
2020-12-01 01:37:56 +00:00
|
|
|
sceErr: fmt.Errorf("storageclass Err"),
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // success
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmConfigMap: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "CM1",
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "testfiledata",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
cPVC: &v1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "PVC",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cPod: &v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "Pod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: IsNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM", "CPVC", "CPOD", "RFIOC", "DPOD", "DPVC", "DCM"},
|
2020-12-01 01:37:56 +00:00
|
|
|
expectedSC: "sc",
|
|
|
|
expectedSize: DefaultPVCSize,
|
2020-10-29 02:44:35 +00:00
|
|
|
expectedTFN: "testfile.fio",
|
|
|
|
expectedCM: "CM1",
|
|
|
|
expectedPVC: "PVC",
|
|
|
|
},
|
|
|
|
{ // fio test error
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmConfigMap: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "CM1",
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "testfiledata",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
cPVC: &v1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "PVC",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cPod: &v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "Pod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rFIOErr: fmt.Errorf("run fio error"),
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM", "CPVC", "CPOD", "RFIOC", "DPOD", "DPVC", "DCM"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{ // create pod error
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmConfigMap: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "CM1",
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "testfiledata",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
cPVC: &v1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "PVC",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cPod: &v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "Pod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cPodErr: fmt.Errorf("pod create error"),
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM", "CPVC", "CPOD", "DPVC", "DCM"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{ // create PVC error
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmConfigMap: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "CM1",
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "testfiledata",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
cPVCErr: fmt.Errorf("pvc create error"),
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM", "CPVC", "DCM"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{ // testfilename retrieval error, more than one provided
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmConfigMap: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "CM1",
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "testfiledata",
|
|
|
|
"testfile.fio2": "testfiledata",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM", "DCM"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{ // load configmap error
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
stepper: &fakeFioStepper{
|
|
|
|
lcmErr: fmt.Errorf("failed to load configmap"),
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
args: &RunFIOArgs{
|
|
|
|
StorageClass: "sc",
|
|
|
|
Size: "100Gi",
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
2020-10-29 02:44:35 +00:00
|
|
|
checker: NotNil,
|
2022-08-16 19:51:19 +00:00
|
|
|
expectedSteps: []string{"VN", "VNS", "SCE", "LCM"},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
c.Log(i)
|
|
|
|
fio := &FIOrunner{
|
|
|
|
Cli: tc.cli,
|
|
|
|
fioSteps: tc.stepper,
|
|
|
|
}
|
|
|
|
_, err := fio.RunFioHelper(ctx, tc.args)
|
|
|
|
c.Check(err, tc.checker)
|
|
|
|
c.Assert(tc.stepper.steps, DeepEquals, tc.expectedSteps)
|
|
|
|
if err == nil {
|
|
|
|
c.Assert(tc.expectedSC, Equals, tc.stepper.cPVCExpSC)
|
|
|
|
c.Assert(tc.expectedSize, Equals, tc.stepper.cPVCExpSize)
|
|
|
|
c.Assert(tc.expectedTFN, Equals, tc.stepper.cPodExpFN)
|
|
|
|
c.Assert(tc.expectedCM, Equals, tc.stepper.cPodExpCM)
|
|
|
|
c.Assert(tc.expectedPVC, Equals, tc.stepper.cPodExpPVC)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeFioStepper struct {
|
|
|
|
steps []string
|
|
|
|
|
2020-12-01 01:37:56 +00:00
|
|
|
vnErr error
|
|
|
|
|
2022-08-16 19:51:19 +00:00
|
|
|
vnsErr error
|
|
|
|
|
2020-12-01 01:37:56 +00:00
|
|
|
sceSC *sv1.StorageClass
|
|
|
|
sceErr error
|
2020-10-29 02:44:35 +00:00
|
|
|
|
|
|
|
lcmConfigMap *v1.ConfigMap
|
|
|
|
lcmErr error
|
|
|
|
|
|
|
|
cPVCExpSC string
|
|
|
|
cPVCExpSize string
|
|
|
|
cPVC *v1.PersistentVolumeClaim
|
|
|
|
cPVCErr error
|
|
|
|
|
|
|
|
dPVCErr error
|
|
|
|
|
|
|
|
cPodExpFN string
|
|
|
|
cPodExpCM string
|
|
|
|
cPodExpPVC string
|
|
|
|
cPod *v1.Pod
|
|
|
|
cPodErr error
|
|
|
|
|
|
|
|
dPodErr error
|
|
|
|
|
2021-02-01 20:45:57 +00:00
|
|
|
rFIOout FioResult
|
2020-10-29 02:44:35 +00:00
|
|
|
rFIOErr error
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) validateNamespace(ctx context.Context, namespace string) error {
|
|
|
|
f.steps = append(f.steps, "VN")
|
|
|
|
return f.vnErr
|
|
|
|
}
|
2022-08-16 19:51:19 +00:00
|
|
|
func (f *fakeFioStepper) validateNodeSelector(ctx context.Context, selector map[string]string) error {
|
|
|
|
f.steps = append(f.steps, "VNS")
|
|
|
|
return f.vnsErr
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) storageClassExists(ctx context.Context, storageClass string) (*sv1.StorageClass, error) {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "SCE")
|
2020-12-01 01:37:56 +00:00
|
|
|
return f.sceSC, f.sceErr
|
2020-10-29 02:44:35 +00:00
|
|
|
}
|
|
|
|
func (f *fakeFioStepper) loadConfigMap(ctx context.Context, args *RunFIOArgs) (*v1.ConfigMap, error) {
|
|
|
|
f.steps = append(f.steps, "LCM")
|
|
|
|
return f.lcmConfigMap, f.lcmErr
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) createPVC(ctx context.Context, storageclass, size, namespace string) (*v1.PersistentVolumeClaim, error) {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "CPVC")
|
|
|
|
f.cPVCExpSC = storageclass
|
|
|
|
f.cPVCExpSize = size
|
|
|
|
return f.cPVC, f.cPVCErr
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) deletePVC(ctx context.Context, pvcName, namespace string) error {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "DPVC")
|
|
|
|
return f.dPVCErr
|
|
|
|
}
|
2022-08-16 19:51:19 +00:00
|
|
|
func (f *fakeFioStepper) createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string, nodeSelector map[string]string, image string) (*v1.Pod, error) {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "CPOD")
|
|
|
|
f.cPodExpCM = configMapName
|
|
|
|
f.cPodExpFN = testFileName
|
|
|
|
f.cPodExpPVC = pvcName
|
|
|
|
return f.cPod, f.cPodErr
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) deletePod(ctx context.Context, podName, namespace string) error {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "DPOD")
|
|
|
|
return f.dPodErr
|
|
|
|
}
|
2021-02-01 20:45:57 +00:00
|
|
|
func (f *fakeFioStepper) runFIOCommand(ctx context.Context, podName, containerName, testFileName, namespace string) (FioResult, error) {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "RFIOC")
|
|
|
|
return f.rFIOout, f.rFIOErr
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
func (f *fakeFioStepper) deleteConfigMap(ctx context.Context, configMap *v1.ConfigMap, namespace string) error {
|
2020-10-29 02:44:35 +00:00
|
|
|
f.steps = append(f.steps, "DCM")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestStorageClassExists(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
for _, tc := range []struct {
|
|
|
|
cli kubernetes.Interface
|
|
|
|
storageClass string
|
|
|
|
checker Checker
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
storageClass: "sc",
|
|
|
|
checker: NotNil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cli: fake.NewSimpleClientset(&scv1.StorageClass{ObjectMeta: metav1.ObjectMeta{Name: "sc"}}),
|
|
|
|
storageClass: "sc",
|
|
|
|
checker: IsNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
stepper := &fioStepper{cli: tc.cli}
|
2020-12-01 01:37:56 +00:00
|
|
|
_, err := stepper.storageClassExists(ctx, tc.storageClass)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Check(err, tc.checker)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:37:56 +00:00
|
|
|
func (s *FIOTestSuite) TestValidateNamespace(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
stepper := &fioStepper{cli: fake.NewSimpleClientset()}
|
|
|
|
err := stepper.validateNamespace(ctx, "ns")
|
|
|
|
c.Assert(err, NotNil)
|
|
|
|
stepper = &fioStepper{cli: fake.NewSimpleClientset(&v1.Namespace{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "ns",
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
err = stepper.validateNamespace(ctx, "ns")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
}
|
|
|
|
|
2022-08-16 19:51:19 +00:00
|
|
|
func (s *FIOTestSuite) TestValidateNodeSelector(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
stepper := &fioStepper{cli: fake.NewSimpleClientset(
|
|
|
|
&v1.Node{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "a",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"key": "value",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&v1.Node{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "b",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"key": "value",
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)}
|
|
|
|
for _, tc := range []struct {
|
|
|
|
nodeSelector map[string]string
|
|
|
|
checker Checker
|
|
|
|
}{
|
|
|
|
{ // 0 nodes satisfy
|
|
|
|
nodeSelector: map[string]string{
|
|
|
|
"not": "present",
|
|
|
|
},
|
|
|
|
checker: NotNil,
|
|
|
|
},
|
|
|
|
{ // 1 node satisfies
|
|
|
|
nodeSelector: map[string]string{
|
|
|
|
"key": "value",
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
checker: IsNil,
|
|
|
|
},
|
|
|
|
{ // 2 nodes satisfy
|
|
|
|
nodeSelector: map[string]string{
|
|
|
|
"key": "value",
|
|
|
|
},
|
|
|
|
checker: IsNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
err := stepper.validateNodeSelector(ctx, tc.nodeSelector)
|
|
|
|
c.Check(err, tc.checker)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 02:44:35 +00:00
|
|
|
func (s *FIOTestSuite) TestLoadConfigMap(c *C) {
|
|
|
|
ctx := context.Background()
|
2022-08-10 18:46:52 +00:00
|
|
|
file, err := os.CreateTemp("", "tempTLCfile")
|
2020-12-01 01:37:56 +00:00
|
|
|
c.Check(err, IsNil)
|
|
|
|
defer os.Remove(file.Name())
|
2020-10-29 02:44:35 +00:00
|
|
|
for i, tc := range []struct {
|
|
|
|
cli kubernetes.Interface
|
|
|
|
configMapName string
|
|
|
|
jobName string
|
|
|
|
args *RunFIOArgs
|
|
|
|
cmChecker Checker
|
|
|
|
errChecker Checker
|
|
|
|
failCreates bool
|
|
|
|
hasLabel bool
|
|
|
|
}{
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // provided file name not found
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
FIOJobFilepath: "nonexistantfile",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
cmChecker: IsNil,
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
{ // specified config map found
|
2020-12-01 01:37:56 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
2020-11-25 20:03:17 +00:00
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
FIOJobFilepath: file.Name(),
|
|
|
|
FIOJobName: "random", // won't use this case
|
2020-11-25 20:03:17 +00:00
|
|
|
},
|
|
|
|
cmChecker: NotNil,
|
|
|
|
errChecker: IsNil,
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // specified job name, not found
|
|
|
|
cli: fake.NewSimpleClientset(),
|
2020-11-25 20:03:17 +00:00
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
FIOJobName: "random",
|
2020-11-25 20:03:17 +00:00
|
|
|
},
|
|
|
|
cmChecker: IsNil,
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // specified job name, found
|
|
|
|
cli: fake.NewSimpleClientset(),
|
2020-11-25 20:03:17 +00:00
|
|
|
args: &RunFIOArgs{
|
2020-12-01 01:37:56 +00:00
|
|
|
FIOJobName: DefaultFIOJob,
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
cmChecker: NotNil,
|
|
|
|
errChecker: IsNil,
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // use default job
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
2020-12-01 01:37:56 +00:00
|
|
|
args: &RunFIOArgs{},
|
2020-10-29 02:44:35 +00:00
|
|
|
cmChecker: NotNil,
|
|
|
|
errChecker: IsNil,
|
|
|
|
},
|
2020-12-01 01:37:56 +00:00
|
|
|
{ // Fails to create configMap
|
2020-10-29 02:44:35 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
cmChecker: IsNil,
|
|
|
|
errChecker: NotNil,
|
|
|
|
args: &RunFIOArgs{},
|
|
|
|
failCreates: true,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
c.Log(i)
|
|
|
|
stepper := &fioStepper{cli: tc.cli}
|
|
|
|
if tc.failCreates {
|
|
|
|
stepper.cli.(*fake.Clientset).Fake.PrependReactor("create", "configmaps", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, nil, errors.New("Error creating object")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
cm, err := stepper.loadConfigMap(ctx, tc.args)
|
|
|
|
c.Check(err, tc.errChecker)
|
|
|
|
c.Check(cm, tc.cmChecker)
|
|
|
|
if cm != nil {
|
|
|
|
_, ok := cm.Labels[CreatedByFIOLabel]
|
2020-11-25 20:03:17 +00:00
|
|
|
c.Assert(ok, Equals, true)
|
2020-10-29 02:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestCreatePVC(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
for _, tc := range []struct {
|
|
|
|
cli kubernetes.Interface
|
|
|
|
storageclass string
|
|
|
|
size string
|
|
|
|
errChecker Checker
|
|
|
|
pvcChecker Checker
|
|
|
|
failCreates bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
storageclass: "fakesc",
|
|
|
|
size: "20Gi",
|
|
|
|
errChecker: IsNil,
|
|
|
|
pvcChecker: NotNil,
|
|
|
|
},
|
|
|
|
{ // Fails to create pvc
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
storageclass: "fakesc",
|
|
|
|
size: "10Gi",
|
|
|
|
pvcChecker: IsNil,
|
|
|
|
errChecker: NotNil,
|
|
|
|
failCreates: true,
|
|
|
|
},
|
|
|
|
{ // parse error
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
storageclass: "fakesc",
|
|
|
|
size: "Not a quantity",
|
|
|
|
pvcChecker: IsNil,
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
stepper := &fioStepper{cli: tc.cli}
|
|
|
|
if tc.failCreates {
|
|
|
|
stepper.cli.(*fake.Clientset).Fake.PrependReactor("create", "*", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, nil, errors.New("Error creating object")
|
|
|
|
})
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
pvc, err := stepper.createPVC(ctx, tc.storageclass, tc.size, DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Check(err, tc.errChecker)
|
|
|
|
c.Check(pvc, tc.pvcChecker)
|
|
|
|
if pvc != nil {
|
|
|
|
c.Assert(pvc.GenerateName, Equals, PVCGenerateName)
|
|
|
|
c.Assert(*pvc.Spec.StorageClassName, Equals, tc.storageclass)
|
|
|
|
value, ok := pvc.Spec.Resources.Requests.Storage().AsInt64()
|
|
|
|
c.Assert(ok, Equals, true)
|
|
|
|
c.Assert(value, Equals, int64(21474836480))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestDeletePVC(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
stepper := &fioStepper{cli: fake.NewSimpleClientset(&v1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "pvc",
|
2020-12-01 01:37:56 +00:00
|
|
|
Namespace: DefaultNS,
|
2020-10-29 02:44:35 +00:00
|
|
|
}})}
|
2020-12-01 01:37:56 +00:00
|
|
|
err := stepper.deletePVC(ctx, "pvc", DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(err, IsNil)
|
2020-12-01 01:37:56 +00:00
|
|
|
err = stepper.deletePVC(ctx, "pvc", DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(err, NotNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestCreatPod(c *C) {
|
|
|
|
ctx := context.Background()
|
2020-12-07 21:16:53 +00:00
|
|
|
for _, tc := range []struct {
|
2020-12-01 01:37:56 +00:00
|
|
|
pvcName string
|
|
|
|
configMapName string
|
|
|
|
testFileName string
|
2022-08-16 19:51:19 +00:00
|
|
|
nodeSelector map[string]string
|
2020-12-15 00:14:53 +00:00
|
|
|
image string
|
2020-12-01 01:37:56 +00:00
|
|
|
reactor []k8stesting.Reactor
|
|
|
|
podReadyErr error
|
|
|
|
errChecker Checker
|
2020-10-29 02:44:35 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "testfile",
|
2022-08-16 19:51:19 +00:00
|
|
|
nodeSelector: map[string]string{
|
|
|
|
"key": "",
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
errChecker: IsNil,
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "testfile",
|
|
|
|
errChecker: NotNil,
|
|
|
|
reactor: []k8stesting.Reactor{
|
|
|
|
&k8stesting.SimpleReactor{
|
|
|
|
Verb: "create",
|
|
|
|
Resource: "*",
|
|
|
|
Reaction: func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod"}}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&k8stesting.SimpleReactor{
|
|
|
|
Verb: "get",
|
|
|
|
Resource: "*",
|
|
|
|
Reaction: func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, nil, errors.New("Error getting object")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "testfile",
|
|
|
|
errChecker: NotNil,
|
|
|
|
reactor: []k8stesting.Reactor{
|
|
|
|
&k8stesting.SimpleReactor{
|
|
|
|
Verb: "create",
|
|
|
|
Resource: "*",
|
|
|
|
Reaction: func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod"}}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
podReadyErr: fmt.Errorf("pod ready error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "testfile",
|
|
|
|
errChecker: NotNil,
|
|
|
|
reactor: []k8stesting.Reactor{
|
|
|
|
&k8stesting.SimpleReactor{
|
|
|
|
Verb: "create",
|
|
|
|
Resource: "*",
|
|
|
|
Reaction: func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
return true, nil, fmt.Errorf("pod create error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "",
|
2020-12-15 00:14:53 +00:00
|
|
|
image: "someotherimage",
|
2020-10-29 02:44:35 +00:00
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "",
|
|
|
|
configMapName: "cm",
|
|
|
|
testFileName: "asdf",
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pvcName: "pvc",
|
|
|
|
configMapName: "",
|
|
|
|
testFileName: "asd",
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
stepper := &fioStepper{
|
2020-12-01 01:37:56 +00:00
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
podReady: &fakePodReadyChecker{prcErr: tc.podReadyErr},
|
2020-10-29 02:44:35 +00:00
|
|
|
}
|
|
|
|
if tc.reactor != nil {
|
|
|
|
stepper.cli.(*fake.Clientset).Fake.ReactionChain = tc.reactor
|
|
|
|
}
|
2022-08-16 19:51:19 +00:00
|
|
|
pod, err := stepper.createPod(ctx, tc.pvcName, tc.configMapName, tc.testFileName, DefaultNS, tc.nodeSelector, tc.image)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Check(err, tc.errChecker)
|
|
|
|
if err == nil {
|
|
|
|
c.Assert(pod.GenerateName, Equals, PodGenerateName)
|
|
|
|
c.Assert(len(pod.Spec.Volumes), Equals, 2)
|
|
|
|
for _, vol := range pod.Spec.Volumes {
|
|
|
|
switch vol.Name {
|
|
|
|
case "persistent-storage":
|
|
|
|
c.Assert(vol.VolumeSource.PersistentVolumeClaim.ClaimName, Equals, tc.pvcName)
|
|
|
|
case "config-map":
|
|
|
|
c.Assert(vol.VolumeSource.ConfigMap.Name, Equals, tc.configMapName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Assert(len(pod.Spec.Containers), Equals, 1)
|
|
|
|
c.Assert(pod.Spec.Containers[0].Name, Equals, ContainerName)
|
|
|
|
c.Assert(pod.Spec.Containers[0].Command, DeepEquals, []string{"/bin/sh"})
|
|
|
|
c.Assert(pod.Spec.Containers[0].Args, DeepEquals, []string{"-c", "tail -f /dev/null"})
|
|
|
|
c.Assert(pod.Spec.Containers[0].VolumeMounts, DeepEquals, []v1.VolumeMount{
|
|
|
|
{Name: "persistent-storage", MountPath: VolumeMountPath},
|
|
|
|
{Name: "config-map", MountPath: ConfigMapMountPath},
|
|
|
|
})
|
2020-12-15 00:14:53 +00:00
|
|
|
if tc.image == "" {
|
2020-12-29 19:46:29 +00:00
|
|
|
c.Assert(pod.Spec.Containers[0].Image, Equals, common.DefaultPodImage)
|
2020-12-15 00:14:53 +00:00
|
|
|
} else {
|
|
|
|
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.image)
|
|
|
|
}
|
2022-08-16 19:51:19 +00:00
|
|
|
c.Assert(pod.Spec.NodeSelector, DeepEquals, tc.nodeSelector)
|
2020-10-29 02:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestDeletePod(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
stepper := &fioStepper{cli: fake.NewSimpleClientset(&v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "pod",
|
2020-12-01 01:37:56 +00:00
|
|
|
Namespace: DefaultNS,
|
2020-10-29 02:44:35 +00:00
|
|
|
}})}
|
2020-12-01 01:37:56 +00:00
|
|
|
err := stepper.deletePod(ctx, "pod", DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(err, IsNil)
|
2020-12-01 01:37:56 +00:00
|
|
|
err = stepper.deletePod(ctx, "pod", DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(err, NotNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestFioTestFileName(c *C) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
configMap map[string]string
|
|
|
|
retVal string
|
|
|
|
errChecker Checker
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
configMap: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"testfile.fio": "some test data",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
retVal: "testfile.fio",
|
|
|
|
errChecker: IsNil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
configMap: map[string]string{
|
2020-12-01 01:37:56 +00:00
|
|
|
"ConfigMapSCKey": "storageclass",
|
|
|
|
"ConfigMapSizeKey": "10Gi",
|
|
|
|
"testfile.fio": "some test data",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
retVal: "",
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
ret, err := fioTestFilename(tc.configMap)
|
|
|
|
c.Check(err, tc.errChecker)
|
|
|
|
c.Assert(ret, Equals, tc.retVal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestRunFioCommand(c *C) {
|
2021-02-01 20:45:57 +00:00
|
|
|
var parsedout FioResult
|
|
|
|
err := json.Unmarshal([]byte(parsableFioOutput), &parsedout)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2020-10-29 02:44:35 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
for _, tc := range []struct {
|
|
|
|
executor *fakeKubeExecutor
|
|
|
|
errChecker Checker
|
|
|
|
podName string
|
|
|
|
containerName string
|
|
|
|
testFileName string
|
2021-02-01 20:45:57 +00:00
|
|
|
out FioResult
|
2020-10-29 02:44:35 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
executor: &fakeKubeExecutor{
|
|
|
|
keErr: nil,
|
|
|
|
keStrErr: "",
|
2021-02-01 20:45:57 +00:00
|
|
|
keStdOut: parsableFioOutput,
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
errChecker: IsNil,
|
|
|
|
podName: "pod",
|
|
|
|
containerName: "container",
|
|
|
|
testFileName: "tfName",
|
2021-02-01 20:45:57 +00:00
|
|
|
out: parsedout,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executor: &fakeKubeExecutor{
|
|
|
|
keErr: nil,
|
|
|
|
keStrErr: "",
|
|
|
|
keStdOut: "unparsable string",
|
|
|
|
},
|
|
|
|
errChecker: NotNil,
|
|
|
|
podName: "pod",
|
|
|
|
containerName: "container",
|
|
|
|
testFileName: "tfName",
|
|
|
|
out: FioResult{},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
executor: &fakeKubeExecutor{
|
|
|
|
keErr: fmt.Errorf("kubeexec err"),
|
|
|
|
keStrErr: "",
|
2021-02-01 20:45:57 +00:00
|
|
|
keStdOut: "unparsable string",
|
|
|
|
},
|
|
|
|
errChecker: NotNil,
|
|
|
|
podName: "pod",
|
|
|
|
containerName: "container",
|
|
|
|
testFileName: "tfName",
|
|
|
|
out: FioResult{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executor: &fakeKubeExecutor{
|
|
|
|
keErr: nil,
|
|
|
|
keStrErr: "execution error",
|
|
|
|
keStdOut: "unparsable string",
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
errChecker: NotNil,
|
|
|
|
podName: "pod",
|
|
|
|
containerName: "container",
|
|
|
|
testFileName: "tfName",
|
2021-02-01 20:45:57 +00:00
|
|
|
out: FioResult{},
|
2020-10-29 02:44:35 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
stepper := &fioStepper{
|
|
|
|
kubeExecutor: tc.executor,
|
|
|
|
}
|
2020-12-01 01:37:56 +00:00
|
|
|
out, err := stepper.runFIOCommand(ctx, tc.podName, tc.containerName, tc.testFileName, DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Check(err, tc.errChecker)
|
2021-02-01 20:45:57 +00:00
|
|
|
c.Assert(out, DeepEquals, tc.out)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(tc.executor.keInPodName, Equals, tc.podName)
|
|
|
|
c.Assert(tc.executor.keInContainerName, Equals, tc.containerName)
|
2021-02-01 20:45:57 +00:00
|
|
|
c.Assert(len(tc.executor.keInCommand), Equals, 5)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Assert(tc.executor.keInCommand[0], Equals, "fio")
|
|
|
|
c.Assert(tc.executor.keInCommand[1], Equals, "--directory")
|
|
|
|
c.Assert(tc.executor.keInCommand[2], Equals, VolumeMountPath)
|
|
|
|
jobFilePath := fmt.Sprintf("%s/%s", ConfigMapMountPath, tc.testFileName)
|
|
|
|
c.Assert(tc.executor.keInCommand[3], Equals, jobFilePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestDeleteConfigMap(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
defaultNS := "default"
|
|
|
|
os.Setenv(PodNamespaceEnvKey, defaultNS)
|
|
|
|
for _, tc := range []struct {
|
|
|
|
cli kubernetes.Interface
|
|
|
|
cm *v1.ConfigMap
|
|
|
|
errChecker Checker
|
|
|
|
lenCMList int
|
|
|
|
}{
|
|
|
|
{ // Don't delete it unless it has the label
|
|
|
|
cli: fake.NewSimpleClientset(&v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "cm",
|
|
|
|
Namespace: defaultNS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cm: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "cm",
|
|
|
|
Namespace: defaultNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errChecker: IsNil,
|
|
|
|
lenCMList: 1,
|
|
|
|
},
|
|
|
|
{ // Has label delete
|
|
|
|
cli: fake.NewSimpleClientset(&v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "cm",
|
|
|
|
Namespace: defaultNS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cm: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "cm",
|
|
|
|
Namespace: defaultNS,
|
|
|
|
Labels: map[string]string{
|
|
|
|
CreatedByFIOLabel: "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errChecker: IsNil,
|
|
|
|
lenCMList: 0,
|
|
|
|
},
|
|
|
|
{ // No cm exists
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
cm: &v1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "cm",
|
|
|
|
Namespace: defaultNS,
|
|
|
|
Labels: map[string]string{
|
|
|
|
CreatedByFIOLabel: "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errChecker: NotNil,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
stepper := &fioStepper{cli: tc.cli}
|
2020-12-01 01:37:56 +00:00
|
|
|
err := stepper.deleteConfigMap(ctx, tc.cm, DefaultNS)
|
2020-10-29 02:44:35 +00:00
|
|
|
c.Check(err, tc.errChecker)
|
|
|
|
if err == nil {
|
|
|
|
list, err := stepper.cli.CoreV1().ConfigMaps(defaultNS).List(ctx, metav1.ListOptions{})
|
|
|
|
c.Check(err, IsNil)
|
|
|
|
c.Assert(len(list.Items), Equals, tc.lenCMList)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os.Unsetenv(PodNamespaceEnvKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FIOTestSuite) TestWaitForPodReady(c *C) {
|
|
|
|
ctx := context.Background()
|
|
|
|
prChecker := &podReadyChecker{
|
|
|
|
cli: fake.NewSimpleClientset(),
|
|
|
|
}
|
|
|
|
err := prChecker.waitForPodReady(ctx, "somens", "somePod")
|
|
|
|
c.Check(err, NotNil)
|
|
|
|
prChecker.cli = fake.NewSimpleClientset(&v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "somePod",
|
|
|
|
Namespace: "somens",
|
|
|
|
},
|
|
|
|
Status: v1.PodStatus{
|
|
|
|
Phase: v1.PodRunning,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakePodReadyChecker struct {
|
|
|
|
prcErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakePodReadyChecker) waitForPodReady(ctx context.Context, namespace, name string) error {
|
|
|
|
return f.prcErr
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeKubeExecutor struct {
|
|
|
|
keErr error
|
|
|
|
keStdOut string
|
|
|
|
keStrErr string
|
|
|
|
keInNS string
|
|
|
|
keInPodName string
|
|
|
|
keInContainerName string
|
|
|
|
keInCommand []string
|
|
|
|
}
|
|
|
|
|
2024-06-04 21:44:33 +00:00
|
|
|
func (fk *fakeKubeExecutor) exec(_ context.Context, namespace, podName, containerName string, command []string) (string, string, error) {
|
2020-10-29 02:44:35 +00:00
|
|
|
fk.keInNS = namespace
|
|
|
|
fk.keInPodName = podName
|
|
|
|
fk.keInContainerName = containerName
|
|
|
|
fk.keInCommand = command
|
|
|
|
return fk.keStdOut, fk.keStrErr, fk.keErr
|
|
|
|
}
|