e2e: Add a new function to run commands in toolboxpod

Updated code to use new function execCommandInToolBoxPod
to run commands in toolboxpod.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-05-15 14:19:38 +05:30 committed by mergify[bot]
parent 0f6c6c15a8
commit 7a5e064f50
3 changed files with 36 additions and 71 deletions

View File

@ -122,11 +122,8 @@ func deleteSnapshot(snap *snapapi.VolumeSnapshot, t int) error {
} }
func listSnapshots(f *framework.Framework, pool, imageName string) ([]snapInfo, error) { func listSnapshots(f *framework.Framework, pool, imageName string) ([]snapInfo, error) {
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
command := fmt.Sprintf("rbd snap ls %s/%s --format=json", pool, imageName) command := fmt.Sprintf("rbd snap ls %s/%s --format=json", pool, imageName)
stdout, stdErr := execCommandInPod(f, command, rookNamespace, &opt) stdout, stdErr := execCommandInToolBoxPod(f, command, rookNamespace)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
var snapInfos []snapInfo var snapInfos []snapInfo
@ -141,10 +138,7 @@ func createRBDSnapshotClass(f *framework.Framework) {
sc.Parameters["csi.storage.k8s.io/snapshotter-secret-namespace"] = cephCSINamespace sc.Parameters["csi.storage.k8s.io/snapshotter-secret-namespace"] = cephCSINamespace
opt := metav1.ListOptions{ fsID, stdErr := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
fsID, stdErr := execCommandInPod(f, "ceph fsid", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
fsID = strings.Trim(fsID, "\n") fsID = strings.Trim(fsID, "\n")
sc.Parameters["clusterID"] = fsID sc.Parameters["clusterID"] = fsID

View File

@ -91,11 +91,7 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
c := f.ClientSet c := f.ClientSet
listOpt := metav1.ListOptions{ fsID, e := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
fsID, e := execCommandInPod(f, "ceph fsid", rookNamespace, &listOpt)
if e != "" { if e != "" {
return fmt.Errorf("failed to get fsid from ceph cluster %s", e) return fmt.Errorf("failed to get fsid from ceph cluster %s", e)
} }
@ -105,7 +101,7 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
// create rbd image // create rbd image
cmd := fmt.Sprintf("rbd create %s --size=%d --pool=%s --image-feature=layering", rbdImageName, 4096, defaultRBDPool) cmd := fmt.Sprintf("rbd create %s --size=%d --pool=%s --image-feature=layering", rbdImageName, 4096, defaultRBDPool)
_, e = execCommandInPod(f, cmd, rookNamespace, &listOpt) _, e = execCommandInToolBoxPod(f, cmd, rookNamespace)
if e != "" { if e != "" {
return fmt.Errorf("failed to create rbd image %s", e) return fmt.Errorf("failed to create rbd image %s", e)
} }
@ -156,7 +152,7 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
} }
cmd = fmt.Sprintf("rbd rm %s --pool=%s", rbdImageName, defaultRBDPool) cmd = fmt.Sprintf("rbd rm %s --pool=%s", rbdImageName, defaultRBDPool)
execCommandInPod(f, cmd, rookNamespace, &listOpt) execCommandInToolBoxPod(f, cmd, rookNamespace)
return nil return nil
} }

View File

@ -42,6 +42,8 @@ const (
// rook created rbd user // rook created rbd user
rbdNodePluginSecretName = "rook-csi-rbd-node" // nolint: gosec rbdNodePluginSecretName = "rook-csi-rbd-node" // nolint: gosec
rbdProvisionerSecretName = "rook-csi-rbd-provisioner" // nolint: gosec rbdProvisionerSecretName = "rook-csi-rbd-provisioner" // nolint: gosec
rookTolBoxPodLabel = "app=rook-ceph-tools"
) )
var ( var (
@ -212,6 +214,19 @@ func execCommandInPod(f *framework.Framework, c, ns string, opt *metav1.ListOpti
return stdOut, stdErr return stdOut, stdErr
} }
func execCommandInToolBoxPod(f *framework.Framework, c, ns string) (string, string) {
opt := &metav1.ListOptions{
LabelSelector: rookTolBoxPodLabel,
}
podPot := getCommandInPodOpts(f, c, ns, opt)
stdOut, stdErr, err := f.ExecWithOptions(podPot)
if stdErr != "" {
e2elog.Logf("stdErr occurred: %v", stdErr)
}
Expect(err).Should(BeNil())
return stdOut, stdErr
}
func execCommandInPodAndAllowFail(f *framework.Framework, c, ns string, opt *metav1.ListOptions) (string, string) { func execCommandInPodAndAllowFail(f *framework.Framework, c, ns string, opt *metav1.ListOptions) (string, string) {
podPot := getCommandInPodOpts(f, c, ns, opt) podPot := getCommandInPodOpts(f, c, ns, opt)
stdOut, stdErr, err := f.ExecWithOptions(podPot) stdOut, stdErr, err := f.ExecWithOptions(podPot)
@ -258,10 +273,7 @@ func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, en
if enablePool { if enablePool {
sc.Parameters["pool"] = "myfs-data0" sc.Parameters["pool"] = "myfs-data0"
} }
opt := metav1.ListOptions{ fsID, stdErr := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
fsID, stdErr := execCommandInPod(f, "ceph fsid", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
// remove new line present in fsID // remove new line present in fsID
fsID = strings.Trim(fsID, "\n") fsID = strings.Trim(fsID, "\n")
@ -284,10 +296,7 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, scOpt
sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = rookNamespace sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = rookNamespace
sc.Parameters["csi.storage.k8s.io/node-stage-secret-name"] = rbdNodePluginSecretName sc.Parameters["csi.storage.k8s.io/node-stage-secret-name"] = rbdNodePluginSecretName
opt := metav1.ListOptions{ fsID, stdErr := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
fsID, stdErr := execCommandInPod(f, "ceph fsid", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
// remove new line present in fsID // remove new line present in fsID
fsID = strings.Trim(fsID, "\n") fsID = strings.Trim(fsID, "\n")
@ -319,10 +328,8 @@ func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Fra
cm := v1.ConfigMap{} cm := v1.ConfigMap{}
err := unmarshal(path, &cm) err := unmarshal(path, &cm)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools", fsID, stdErr := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
}
fsID, stdErr := execCommandInPod(f, "ceph fsid", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
// remove new line present in fsID // remove new line present in fsID
fsID = strings.Trim(fsID, "\n") fsID = strings.Trim(fsID, "\n")
@ -367,10 +374,8 @@ func getSecret(path string) v1.Secret {
func createCephfsSecret(c kubernetes.Interface, f *framework.Framework) { func createCephfsSecret(c kubernetes.Interface, f *framework.Framework) {
scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "secret.yaml") scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "secret.yaml")
sc := getSecret(scPath) sc := getSecret(scPath)
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools", adminKey, stdErr := execCommandInToolBoxPod(f, "ceph auth get-key client.admin", rookNamespace)
}
adminKey, stdErr := execCommandInPod(f, "ceph auth get-key client.admin", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
sc.StringData["adminID"] = "admin" sc.StringData["adminID"] = "admin"
sc.StringData["adminKey"] = adminKey sc.StringData["adminKey"] = adminKey
@ -384,10 +389,8 @@ func createCephfsSecret(c kubernetes.Interface, f *framework.Framework) {
func createRBDSecret(c kubernetes.Interface, f *framework.Framework) { func createRBDSecret(c kubernetes.Interface, f *framework.Framework) {
scPath := fmt.Sprintf("%s/%s", rbdExamplePath, "secret.yaml") scPath := fmt.Sprintf("%s/%s", rbdExamplePath, "secret.yaml")
sc := getSecret(scPath) sc := getSecret(scPath)
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools", adminKey, stdErr := execCommandInToolBoxPod(f, "ceph auth get-key client.admin", rookNamespace)
}
adminKey, stdErr := execCommandInPod(f, "ceph auth get-key client.admin", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
sc.StringData["userID"] = "admin" sc.StringData["userID"] = "admin"
sc.StringData["userKey"] = adminKey sc.StringData["userKey"] = adminKey
@ -715,10 +718,7 @@ func getImageInfoFromPVC(pvcNamespace, pvcName string, f *framework.Framework) (
func getImageMeta(rbdImageSpec, metaKey string, f *framework.Framework) (string, error) { func getImageMeta(rbdImageSpec, metaKey string, f *framework.Framework) (string, error) {
cmd := fmt.Sprintf("rbd image-meta get %s %s", rbdImageSpec, metaKey) cmd := fmt.Sprintf("rbd image-meta get %s %s", rbdImageSpec, metaKey)
opt := metav1.ListOptions{ stdOut, stdErr := execCommandInToolBoxPod(f, cmd, rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
stdOut, stdErr := execCommandInPod(f, cmd, rookNamespace, &opt)
if stdErr != "" { if stdErr != "" {
return strings.TrimSpace(stdOut), fmt.Errorf(stdErr) return strings.TrimSpace(stdOut), fmt.Errorf(stdErr)
} }
@ -887,10 +887,7 @@ func deleteBackingCephFSVolume(f *framework.Framework, pvc *v1.PersistentVolumeC
return err return err
} }
opt := metav1.ListOptions{ _, stdErr := execCommandInToolBoxPod(f, "ceph fs subvolume rm myfs "+imageData.imageName+" e2e", rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
_, stdErr := execCommandInPod(f, "ceph fs subvolume rm myfs "+imageData.imageName+" e2e", rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
if stdErr != "" { if stdErr != "" {
@ -900,10 +897,7 @@ func deleteBackingCephFSVolume(f *framework.Framework, pvc *v1.PersistentVolumeC
} }
func listRBDImages(f *framework.Framework) []string { func listRBDImages(f *framework.Framework) []string {
opt := metav1.ListOptions{ stdout, stdErr := execCommandInToolBoxPod(f, fmt.Sprintf("rbd ls --pool=%s --format=json", defaultRBDPool), rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
stdout, stdErr := execCommandInPod(f, fmt.Sprintf("rbd ls --pool=%s --format=json", defaultRBDPool), rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
var imgInfos []string var imgInfos []string
@ -969,19 +963,12 @@ func deleteBackingRBDImage(f *framework.Framework, pvc *v1.PersistentVolumeClaim
return err return err
} }
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
cmd := fmt.Sprintf("rbd rm %s --pool=%s", imageData.imageName, defaultRBDPool) cmd := fmt.Sprintf("rbd rm %s --pool=%s", imageData.imageName, defaultRBDPool)
execCommandInPod(f, cmd, rookNamespace, &opt) execCommandInToolBoxPod(f, cmd, rookNamespace)
return nil return nil
} }
func deletePool(name string, cephfs bool, f *framework.Framework) { func deletePool(name string, cephfs bool, f *framework.Framework) {
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
var cmds = []string{} var cmds = []string{}
if cephfs { if cephfs {
// ceph fs fail // ceph fs fail
@ -1002,7 +989,7 @@ func deletePool(name string, cephfs bool, f *framework.Framework) {
for _, cmd := range cmds { for _, cmd := range cmds {
// discard stdErr as some commands prints warning in strErr // discard stdErr as some commands prints warning in strErr
execCommandInPod(f, cmd, rookNamespace, &opt) execCommandInToolBoxPod(f, cmd, rookNamespace)
} }
} }
@ -1105,11 +1092,7 @@ func getPVCImageInfoInPool(f *framework.Framework, pvc *v1.PersistentVolumeClaim
return "", err return "", err
} }
opt := metav1.ListOptions{ stdOut, stdErr := execCommandInToolBoxPod(f, "rbd info "+pool+"/"+imageData.imageName, rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
stdOut, stdErr := execCommandInPod(f, "rbd info "+pool+"/"+imageData.imageName, rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
e2elog.Logf("found image %s in pool %s", imageData.imageName, pool) e2elog.Logf("found image %s in pool %s", imageData.imageName, pool)
@ -1142,11 +1125,7 @@ func checkPVCImageJournalInPool(f *framework.Framework, pvc *v1.PersistentVolume
return err return err
} }
opt := metav1.ListOptions{ _, stdErr := execCommandInToolBoxPod(f, "rados listomapkeys -p "+pool+" csi.volume."+imageData.imageID, rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
_, stdErr := execCommandInPod(f, "rados listomapkeys -p "+pool+" csi.volume."+imageData.imageID, rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
e2elog.Logf("found image journal %s in pool %s", "csi.volume."+imageData.imageID, pool) e2elog.Logf("found image journal %s in pool %s", "csi.volume."+imageData.imageID, pool)
@ -1160,11 +1139,7 @@ func checkPVCCSIJournalInPool(f *framework.Framework, pvc *v1.PersistentVolumeCl
return err return err
} }
opt := metav1.ListOptions{ _, stdErr := execCommandInToolBoxPod(f, "rados getomapval -p "+pool+" csi.volumes.default csi.volume."+imageData.pvName, rookNamespace)
LabelSelector: "app=rook-ceph-tools",
}
_, stdErr := execCommandInPod(f, "rados getomapval -p "+pool+" csi.volumes.default csi.volume."+imageData.pvName, rookNamespace, &opt)
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
e2elog.Logf("found CSI journal entry %s in pool %s", "csi.volume."+imageData.pvName, pool) e2elog.Logf("found CSI journal entry %s in pool %s", "csi.volume."+imageData.pvName, pool)