ceph: refactor <StartTestCluster>

Refactor the StartTestCluster method to make it more readable.

I have put most of the parameters used in this function in the struct.
In this way the call to this function is more easy to understand and to use.
The addition of new parameters to this method started to be annoying.

[test ceph]

Signed-off-by: Juan Miguel Olmo Martínez <jolmomar@redhat.com>
This commit is contained in:
Juan Miguel Olmo Martínez committed 2020-04-16 12:03:45 +02:00
1 parent a62c67a00c
commit 28afede309
5 files changed
+87 -48

No files matched your search

+26 -22
View File
@@ -97,16 +97,21 @@ func HandlePanics(r interface{}, op installer.TestSuite, t func() *testing.T) {
// TestCluster struct for handling panic and test suite tear down
type TestCluster struct {
installer *installer.CephInstaller
kh *utils.K8sHelper
helper *clients.TestClient
T func() *testing.T
namespace string
storeType string
storageClassName string
usePVC bool
mons int
rbdMirrorWorkers int
installer *installer.CephInstaller
kh *utils.K8sHelper
helper *clients.TestClient
T func() *testing.T
namespace string
storeType string
storageClassName string
useHelm bool
usePVC bool
mons int
rbdMirrorWorkers int
rookCephCleanup bool
minimalMatrixK8sVersion string
rookVersion string
cephVersion cephv1.CephVersionSpec
}
func checkIfShouldRunForMinimalTestMatrix(t func() *testing.T, k8sh *utils.K8sHelper, version string) {
@@ -133,26 +138,25 @@ func checkIfShouldRunForMinimalTestMatrix(t func() *testing.T, k8sh *utils.K8sHe
}
// StartTestCluster creates new instance of TestCluster struct
func StartTestCluster(t func() *testing.T, minimalMatrixK8sVersion, namespace, storeType string, useHelm bool, usePVC bool, storageClassName string, mons,
rbdMirrorWorkers int, rookVersion string, cephVersion cephv1.CephVersionSpec, cleanupHost bool) (*TestCluster, *utils.K8sHelper) {
func StartTestCluster(t func() *testing.T, cluster *TestCluster) (*TestCluster, *utils.K8sHelper) {
kh, err := utils.CreateK8sHelper(t)
require.NoError(t(), err)
checkIfShouldRunForMinimalTestMatrix(t, kh, minimalMatrixK8sVersion)
checkIfShouldRunForMinimalTestMatrix(t, kh, cluster.minimalMatrixK8sVersion)
i := installer.NewCephInstaller(t, kh.Clientset, useHelm, rookVersion, cephVersion, cleanupHost)
cluster.installer = installer.NewCephInstaller(t, kh.Clientset, cluster.useHelm, cluster.rookVersion, cluster.cephVersion, cluster.rookCephCleanup)
cluster.kh = kh
cluster.helper = nil
cluster.T = t
op := &TestCluster{i, kh, nil, t, namespace, storeType, storageClassName, usePVC, mons, rbdMirrorWorkers}
if rookVersion != installer.VersionMaster {
if cluster.rookVersion != installer.VersionMaster {
// make sure we have the images from a previous release locally so the test doesn't hit a timeout
assert.NoError(t(), kh.GetDockerImage("rook/ceph:"+rookVersion))
assert.NoError(t(), kh.GetDockerImage("rook/ceph:"+cluster.rookVersion))
}
assert.NoError(t(), kh.GetDockerImage(cephVersion.Image))
assert.NoError(t(), kh.GetDockerImage(cluster.cephVersion.Image))
op.Setup()
return op, kh
cluster.Setup()
return cluster, kh
}
// SetUpRook is a wrapper for setting up rook
+16 -4
View File
@@ -81,10 +81,22 @@ func (s *CephFlexDriverSuite) SetupSuite() {
s.namespace = "flex-ns"
s.pvcNameRWO = "block-persistent-rwo"
s.pvcNameRWX = "block-persistent-rwx"
useHelm := false
mons := 1
rbdMirrorWorkers := 1
s.op, s.kh = StartTestCluster(s.T, flexDriverMinimalTestVersion, s.namespace, "bluestore", useHelm, false, "", mons, rbdMirrorWorkers, installer.VersionMaster, installer.OctopusVersion, false)
flexTestCluster := TestCluster{
namespace: s.namespace,
storeType: "bluestore",
storageClassName: "",
useHelm: false,
usePVC: false,
mons: 1,
rbdMirrorWorkers: 1,
rookCephCleanup: false,
minimalMatrixK8sVersion: flexDriverMinimalTestVersion,
rookVersion: installer.VersionMaster,
cephVersion: installer.OctopusVersion,
}
s.op, s.kh = StartTestCluster(s.T, &flexTestCluster)
s.testClient = clients.CreateTestClient(s.kh, s.op.installer.Manifests)
s.bc = s.testClient.BlockClient
}
+15 -4
View File
@@ -68,10 +68,21 @@ type HelmSuite struct {
func (hs *HelmSuite) SetupSuite() {
hs.namespace = "helm-ns"
mons := 1
rbdMirrorWorkers := 1
rookCephCleanup := true
hs.op, hs.kh = StartTestCluster(hs.T, helmMinimalTestVersion, hs.namespace, "bluestore", true, false, "", mons, rbdMirrorWorkers, installer.VersionMaster, installer.NautilusVersion, rookCephCleanup)
helmTestCluster := TestCluster{
namespace: hs.namespace,
storeType: "bluestore",
storageClassName: "",
useHelm: true,
usePVC: false,
mons: 1,
rbdMirrorWorkers: 1,
rookCephCleanup: true,
minimalMatrixK8sVersion: helmMinimalTestVersion,
rookVersion: installer.VersionMaster,
cephVersion: installer.NautilusVersion,
}
hs.op, hs.kh = StartTestCluster(hs.T, &helmTestCluster)
hs.helper = clients.CreateTestClient(hs.kh, hs.op.installer.Manifests)
}
+15 -3
View File
@@ -78,9 +78,21 @@ type SmokeSuite struct {
func (suite *SmokeSuite) SetupSuite() {
suite.namespace = "smoke-ns"
mons := 3
rbdMirrorWorkers := 1
suite.op, suite.k8sh = StartTestCluster(suite.T, smokeSuiteMinimalTestVersion, suite.namespace, "bluestore", false, false, "", mons, rbdMirrorWorkers, installer.VersionMaster, installer.OctopusVersion, false)
smokeTestCluster := TestCluster{
namespace: suite.namespace,
storeType: "bluestore",
storageClassName: "",
useHelm: false,
usePVC: false,
mons: 3,
rbdMirrorWorkers: 1,
rookCephCleanup: false,
minimalMatrixK8sVersion: smokeSuiteMinimalTestVersion,
rookVersion: installer.VersionMaster,
cephVersion: installer.OctopusVersion,
}
suite.op, suite.k8sh = StartTestCluster(suite.T, &smokeTestCluster)
suite.helper = clients.CreateTestClient(suite.k8sh, suite.op.installer.Manifests)
}
+15 -15
View File
@@ -72,21 +72,21 @@ type UpgradeSuite struct {
func (s *UpgradeSuite) SetupSuite() {
s.namespace = "upgrade-ns"
mons := 1
rbdMirrorWorkers := 0
s.op, s.k8sh = StartTestCluster(s.T,
upgradeMinimalTestVersion,
s.namespace,
"",
false,
false,
"",
mons,
rbdMirrorWorkers,
installer.Version1_2,
installer.NautilusVersion,
false,
)
upgradeTestCluster := TestCluster{
namespace: s.namespace,
storeType: "",
storageClassName: "",
useHelm: false,
usePVC: false,
mons: 1,
rbdMirrorWorkers: 0,
rookCephCleanup: false,
minimalMatrixK8sVersion: upgradeMinimalTestVersion,
rookVersion: installer.Version1_2,
cephVersion: installer.NautilusVersion,
}
s.op, s.k8sh = StartTestCluster(s.T, &upgradeTestCluster)
s.helper = clients.CreateTestClient(s.k8sh, s.op.installer.Manifests)
}