ceph_multi_cluster_test.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. Copyright 2016 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package integration
  14. import (
  15. "path/filepath"
  16. "testing"
  17. "github.com/rook/rook/pkg/daemon/ceph/client"
  18. "github.com/rook/rook/tests/framework/clients"
  19. "github.com/rook/rook/tests/framework/installer"
  20. "github.com/rook/rook/tests/framework/utils"
  21. "github.com/stretchr/testify/require"
  22. "github.com/stretchr/testify/suite"
  23. )
  24. const (
  25. localPathPVCmd = "tests/scripts/localPathPV.sh"
  26. )
  27. // *************************************************************
  28. // *** Major scenarios tested by the MultiClusterDeploySuite ***
  29. // Setup
  30. // - Two clusters started in different namespaces via the CRD
  31. // Monitors
  32. // - One mon in each cluster
  33. // OSDs
  34. // - Bluestore running on a raw block device
  35. // Block
  36. // - Create a pool in each cluster
  37. // - Mount/unmount a block device through the dynamic provisioner
  38. // File system
  39. // - Create a file system via the CRD
  40. // Object
  41. // - Create the object store via the CRD
  42. // *************************************************************
  43. func TestCephMultiClusterDeploySuite(t *testing.T) {
  44. s := new(MultiClusterDeploySuite)
  45. defer func(s *MultiClusterDeploySuite) {
  46. HandlePanics(recover(), s.TearDownSuite, s.T)
  47. }(s)
  48. suite.Run(t, s)
  49. }
  50. type MultiClusterDeploySuite struct {
  51. suite.Suite
  52. testClient *clients.TestClient
  53. k8sh *utils.K8sHelper
  54. settings *installer.TestCephSettings
  55. externalManifests installer.CephManifests
  56. installer *installer.CephInstaller
  57. coreToolbox string
  58. externalToolbox string
  59. poolName string
  60. }
  61. // Deploy Multiple Rook clusters
  62. func (s *MultiClusterDeploySuite) SetupSuite() {
  63. s.poolName = "multi-cluster-pool1"
  64. coreNamespace := "multi-core"
  65. s.settings = &installer.TestCephSettings{
  66. ClusterName: "multi-cluster",
  67. Namespace: coreNamespace,
  68. OperatorNamespace: installer.SystemNamespace(coreNamespace),
  69. StorageClassName: "manual",
  70. UsePVC: installer.UsePVC(),
  71. Mons: 1,
  72. MultipleMgrs: true,
  73. RookVersion: installer.LocalBuildTag,
  74. CephVersion: installer.QuincyVersion,
  75. RequireMsgr2: true,
  76. }
  77. s.settings.ApplyEnvVars()
  78. externalSettings := &installer.TestCephSettings{
  79. IsExternal: true,
  80. ClusterName: "test-external",
  81. Namespace: "multi-external",
  82. OperatorNamespace: s.settings.OperatorNamespace,
  83. RookVersion: s.settings.RookVersion,
  84. CephVersion: installer.QuincyVersion,
  85. }
  86. externalSettings.ApplyEnvVars()
  87. s.externalManifests = installer.NewCephManifests(externalSettings)
  88. // Start the core storage cluster
  89. s.setupMultiClusterCore()
  90. s.createPools()
  91. // Start the external cluster that will connect to the core cluster
  92. // create an external cluster
  93. s.startExternalCluster()
  94. logger.Infof("finished starting clusters")
  95. }
  96. func (s *MultiClusterDeploySuite) AfterTest(suiteName, testName string) {
  97. s.installer.CollectOperatorLog(suiteName, testName)
  98. }
  99. func (s *MultiClusterDeploySuite) createPools() {
  100. // create a test pool in each cluster so that we get some PGs
  101. logger.Infof("Creating pool %s", s.poolName)
  102. err := s.testClient.PoolClient.Create(s.poolName, s.settings.Namespace, 1)
  103. require.Nil(s.T(), err)
  104. }
  105. func (s *MultiClusterDeploySuite) deletePools() {
  106. // create a test pool in each cluster so that we get some PGs
  107. clusterInfo := client.AdminTestClusterInfo(s.settings.Namespace)
  108. if err := s.testClient.PoolClient.DeletePool(s.testClient.BlockClient, clusterInfo, s.poolName); err != nil {
  109. logger.Errorf("failed to delete pool %q. %v", s.poolName, err)
  110. } else {
  111. logger.Infof("deleted pool %q", s.poolName)
  112. }
  113. }
  114. func (s *MultiClusterDeploySuite) TearDownSuite() {
  115. s.deletePools()
  116. s.installer.UninstallRookFromMultipleNS(s.externalManifests, s.installer.Manifests)
  117. }
  118. // Test to make sure all rook components are installed and Running
  119. func (s *MultiClusterDeploySuite) TestInstallingMultipleRookClusters() {
  120. // Check if Rook cluster 1 is deployed successfully
  121. client.RunAllCephCommandsInToolboxPod = s.coreToolbox
  122. checkIfRookClusterIsInstalled(&s.Suite, s.k8sh, s.settings.OperatorNamespace, s.settings.Namespace, 1)
  123. checkIfRookClusterIsHealthy(&s.Suite, s.testClient, s.settings.Namespace)
  124. // Check if Rook external cluster is deployed successfully
  125. // Checking health status is enough to validate the connection
  126. client.RunAllCephCommandsInToolboxPod = s.externalToolbox
  127. checkIfRookClusterIsHealthy(&s.Suite, s.testClient, s.externalManifests.Settings().Namespace)
  128. }
  129. // Setup is wrapper for setting up multiple rook clusters.
  130. func (s *MultiClusterDeploySuite) setupMultiClusterCore() {
  131. root, err := utils.FindRookRoot()
  132. require.NoError(s.T(), err, "failed to get rook root")
  133. cmdArgs := utils.CommandArgs{Command: filepath.Join(root, localPathPVCmd),
  134. CmdArgs: []string{installer.TestScratchDevice()}}
  135. cmdOut := utils.ExecuteCommand(cmdArgs)
  136. require.NoError(s.T(), cmdOut.Err)
  137. s.installer, s.k8sh = StartTestCluster(s.T, s.settings)
  138. s.testClient = clients.CreateTestClient(s.k8sh, s.installer.Manifests)
  139. s.coreToolbox = client.RunAllCephCommandsInToolboxPod
  140. }
  141. func (s *MultiClusterDeploySuite) startExternalCluster() {
  142. err := s.installer.CreateRookExternalCluster(s.externalManifests)
  143. if err != nil {
  144. s.T().Fail()
  145. s.installer.GatherAllRookLogs(s.T().Name(), s.externalManifests.Settings().Namespace)
  146. require.NoError(s.T(), err)
  147. }
  148. s.externalToolbox = client.RunAllCephCommandsInToolboxPod
  149. logger.Infof("succeeded starting external cluster %s", s.externalManifests.Settings().Namespace)
  150. }