-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
ceph_multi_cluster_test.go
185 lines (160 loc) · 6.3 KB
/
ceph_multi_cluster_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 integration
import (
"path/filepath"
"testing"
"github.com/rook/rook/pkg/daemon/ceph/client"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/installer"
"github.com/rook/rook/tests/framework/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
const (
localPathPVCmd = "tests/scripts/localPathPV.sh"
)
// *************************************************************
// *** Major scenarios tested by the MultiClusterDeploySuite ***
// Setup
// - Two clusters started in different namespaces via the CRD
// Monitors
// - One mon in each cluster
// OSDs
// - Bluestore running on a raw block device
// Block
// - Create a pool in each cluster
// - Mount/unmount a block device through the dynamic provisioner
// File system
// - Create a file system via the CRD
// Object
// - Create the object store via the CRD
// *************************************************************
func TestCephMultiClusterDeploySuite(t *testing.T) {
if installer.SkipTestSuite(installer.CephTestSuite) {
t.Skip()
}
s := new(MultiClusterDeploySuite)
defer func(s *MultiClusterDeploySuite) {
HandlePanics(recover(), s.TearDownSuite, s.T)
}(s)
suite.Run(t, s)
}
type MultiClusterDeploySuite struct {
suite.Suite
testClient *clients.TestClient
k8sh *utils.K8sHelper
settings *installer.TestCephSettings
externalManifests installer.CephManifests
installer *installer.CephInstaller
coreToolbox string
externalToolbox string
poolName string
}
// Deploy Multiple Rook clusters
func (s *MultiClusterDeploySuite) SetupSuite() {
s.poolName = "multi-cluster-pool1"
coreNamespace := "multi-core"
s.settings = &installer.TestCephSettings{
ClusterName: "multi-cluster",
Namespace: coreNamespace,
OperatorNamespace: installer.SystemNamespace(coreNamespace),
StorageClassName: "manual",
UsePVC: installer.UsePVC(),
Mons: 1,
UseCSI: true,
MultipleMgrs: true,
EnableAdmissionController: true,
RookVersion: installer.LocalBuildTag,
CephVersion: installer.NautilusVersion,
}
s.settings.ApplyEnvVars()
externalSettings := &installer.TestCephSettings{
IsExternal: true,
ClusterName: "test-external",
Namespace: "multi-external",
OperatorNamespace: s.settings.OperatorNamespace,
RookVersion: s.settings.RookVersion,
UseCSI: true,
}
externalSettings.ApplyEnvVars()
s.externalManifests = installer.NewCephManifests(externalSettings)
k8sh, err := utils.CreateK8sHelper(s.T)
assert.NoError(s.T(), err)
if !k8sh.VersionAtLeast("v1.16.0") {
s.T().Skip("requires at least k8s 1.16, no need to run on older versions")
}
// Start the core storage cluster
s.setupMultiClusterCore()
s.createPools()
// Start the external cluster that will connect to the core cluster
// create an external cluster
s.startExternalCluster()
logger.Infof("finished starting clusters")
}
func (s *MultiClusterDeploySuite) AfterTest(suiteName, testName string) {
s.installer.CollectOperatorLog(suiteName, testName)
}
func (s *MultiClusterDeploySuite) createPools() {
// create a test pool in each cluster so that we get some PGs
logger.Infof("Creating pool %s", s.poolName)
err := s.testClient.PoolClient.Create(s.poolName, s.settings.Namespace, 1)
require.Nil(s.T(), err)
}
func (s *MultiClusterDeploySuite) deletePools() {
// create a test pool in each cluster so that we get some PGs
clusterInfo := client.AdminClusterInfo(s.settings.Namespace)
if err := s.testClient.PoolClient.DeletePool(s.testClient.BlockClient, clusterInfo, s.poolName); err != nil {
logger.Errorf("failed to delete pool %q. %v", s.poolName, err)
} else {
logger.Infof("deleted pool %q", s.poolName)
}
}
func (s *MultiClusterDeploySuite) TearDownSuite() {
s.deletePools()
s.installer.UninstallRookFromMultipleNS(s.externalManifests, s.installer.Manifests)
}
// Test to make sure all rook components are installed and Running
func (s *MultiClusterDeploySuite) TestInstallingMultipleRookClusters() {
// Check if Rook cluster 1 is deployed successfully
client.RunAllCephCommandsInToolboxPod = s.coreToolbox
checkIfRookClusterIsInstalled(s.Suite, s.k8sh, s.settings.OperatorNamespace, s.settings.Namespace, 1)
checkIfRookClusterIsHealthy(s.Suite, s.testClient, s.settings.Namespace)
// Check if Rook external cluster is deployed successfully
// Checking health status is enough to validate the connection
client.RunAllCephCommandsInToolboxPod = s.externalToolbox
checkIfRookClusterIsHealthy(s.Suite, s.testClient, s.externalManifests.Settings().Namespace)
}
// Setup is wrapper for setting up multiple rook clusters.
func (s *MultiClusterDeploySuite) setupMultiClusterCore() {
root, err := utils.FindRookRoot()
require.NoError(s.T(), err, "failed to get rook root")
cmdArgs := utils.CommandArgs{Command: filepath.Join(root, localPathPVCmd),
CmdArgs: []string{installer.TestScratchDevice()}}
cmdOut := utils.ExecuteCommand(cmdArgs)
require.NoError(s.T(), cmdOut.Err)
s.installer, s.k8sh = StartTestCluster(s.T, s.settings)
s.testClient = clients.CreateTestClient(s.k8sh, s.installer.Manifests)
s.coreToolbox = client.RunAllCephCommandsInToolboxPod
}
func (s *MultiClusterDeploySuite) startExternalCluster() {
err := s.installer.CreateRookExternalCluster(s.externalManifests)
if err != nil {
s.T().Fail()
s.installer.GatherAllRookLogs(s.T().Name(), s.externalManifests.Settings().Namespace)
require.NoError(s.T(), err)
}
s.externalToolbox = client.RunAllCephCommandsInToolboxPod
logger.Infof("succeeded starting external cluster %s", s.externalManifests.Settings().Namespace)
}