Skip to content

Commit

Permalink
BDD for CSP deletion if pool is not created
Browse files Browse the repository at this point in the history
Signed-off-by: mayank <mayank.patel@mayadata.io>
  • Loading branch information
mayank committed Jan 23, 2020
1 parent 284e3ba commit 5517104
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
109 changes: 109 additions & 0 deletions tests/cstor/pool/negative/provision_without_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2019 The OpenEBS 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 negative

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/openebs/maya/cmd/cstor-pool-mgmt/pool"
apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
"github.com/openebs/maya/tests"
"github.com/openebs/maya/tests/cstor"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
)

var _ = Describe("[cstor] [-ve] TEST PROVISION WITHOUT POOL", func() {
var (
err error
)

BeforeEach(func() {
By("creating storagepoolclaim")
spcConfig := &tests.SPCConfig{
Name: spcName,
DiskType: "sparse",
PoolCount: cstor.PoolCount,
IsOverProvisioning: false,
PoolType: "striped",
}
ops.Config = spcConfig
spcObj = ops.BuildAndCreateSPC()
By("Creating SPC, Desired Number of CSP Should Be Created", func() {
ops.VerifyDesiredCSPCount(spcObj, cstor.PoolCount)
})
})

AfterEach(func() {
By("deleting storagepoolclaim")

err = ops.SPCClient.Delete(spcObj.Name, &metav1.DeleteOptions{})
Expect(err).To(BeNil(), "while deleting the storagepoolclaim {%s}", spcObj.Name)

cspCount := ops.GetCSPCount(getLabelSelector(spcObj))
Expect(cspCount).To(Equal(0), "stale CSP")
})

When("creating storagepoolclaim without", func() {
It("Testing SPC deletion if pool does not exist", func() {
spcLabel := getLabelSelector(spcObj)
poolPodList, err := ops.PodClient.
WithNamespace(openebsNamespace).
List(metav1.ListOptions{LabelSelector: spcLabel})
Expect(err).To(BeNil())
Expect(len(poolPodList.Items)).Should(BeNumerically(">=", 1))

tPod := poolPodList.Items[0]
var puid string
for _, e := range tPod.Spec.Containers[0].Env {
if e.Name == "OPENEBS_IO_CSTOR_ID" {
puid = e.Value
}
}
Expect(len(puid)).Should(BeNumerically(">=", 1))

cspList, err := ops.CSPClient.List(metav1.ListOptions{LabelSelector: string(apis.StoragePoolClaimCPK) + "=" + spcObj.Name})
Expect(len(cspList.Items)).Should(BeNumerically(">=", 1))
var cspObj apis.CStorPool
for _, l := range cspList.Items {
if l.GetUID() == types.UID(puid) {
cspObj = l
break
}
}

poolName := string(pool.PoolPrefix) + string(cspObj.ObjectMeta.UID)
zfsCmd := "zpool destroy -f " + poolName
cmd := []string{"/bin/bash", "-c", zfsCmd}

opts := tests.NewOptions().
WithPodName(tPod.Name).
WithNamespace(openebsNamespace).
WithContainer("cstor-pool").
WithCommand(cmd...)

out, err := ops.ExecPod(opts)
Expect(err).To(BeNil())
Expect(execOut.Len()).Should(BeNumerically("=", 0))
})
})
})

func getLabelSelector(spc *apis.StoragePoolClaim) string {
return string(apis.StoragePoolClaimCPK) + "=" + spc.Name
}
2 changes: 1 addition & 1 deletion tests/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ func (ops *Operations) ExecPod(opts *Options) ([]byte, error) {
Tty: false,
})
Expect(err).To(BeNil(), "while streaming the command in pod ", opts.podName, execOut.String(), execErr.String())
Expect(execOut.Len()).Should(BeNumerically(">", 0), "while streaming the command in pod ", opts.podName, execErr.String(), execOut.String())
Expect(execOut.Len()).Should(BeNumerically(">=", 0), "while streaming the command in pod ", opts.podName, execErr.String(), execOut.String())
return execOut.Bytes(), nil
}

Expand Down

0 comments on commit 5517104

Please sign in to comment.