From 28afede3090aa89b7315a5e581c34f5136fd47ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Miguel=20Olmo=20Mart=C3=ADnez?= Date: Thu, 16 Apr 2020 11:54:05 +0200 Subject: [PATCH] ceph: refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/integration/ceph_base_deploy_test.go | 48 ++++++++++++---------- tests/integration/ceph_flex_test.go | 20 +++++++-- tests/integration/ceph_helm_test.go | 19 +++++++-- tests/integration/ceph_smoke_test.go | 18 ++++++-- tests/integration/ceph_upgrade_test.go | 30 +++++++------- 5 files changed, 87 insertions(+), 48 deletions(-) diff --git a/tests/integration/ceph_base_deploy_test.go b/tests/integration/ceph_base_deploy_test.go index 32a50fe93..04ad2df70 100644 --- a/tests/integration/ceph_base_deploy_test.go +++ b/tests/integration/ceph_base_deploy_test.go @@ -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 diff --git a/tests/integration/ceph_flex_test.go b/tests/integration/ceph_flex_test.go index 89af28c31..41d602ed6 100644 --- a/tests/integration/ceph_flex_test.go +++ b/tests/integration/ceph_flex_test.go @@ -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 } diff --git a/tests/integration/ceph_helm_test.go b/tests/integration/ceph_helm_test.go index 9891a7a6c..ed61cc9ea 100644 --- a/tests/integration/ceph_helm_test.go +++ b/tests/integration/ceph_helm_test.go @@ -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) } diff --git a/tests/integration/ceph_smoke_test.go b/tests/integration/ceph_smoke_test.go index 1ba9a039f..3cfafd28a 100644 --- a/tests/integration/ceph_smoke_test.go +++ b/tests/integration/ceph_smoke_test.go @@ -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) } diff --git a/tests/integration/ceph_upgrade_test.go b/tests/integration/ceph_upgrade_test.go index ae7da3d3b..1a10863f7 100644 --- a/tests/integration/ceph_upgrade_test.go +++ b/tests/integration/ceph_upgrade_test.go @@ -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) }