ceph_base_deploy_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. "fmt"
  16. "time"
  17. "testing"
  18. "github.com/coreos/pkg/capnslog"
  19. "github.com/rook/rook/tests/framework/clients"
  20. "github.com/rook/rook/tests/framework/installer"
  21. "github.com/rook/rook/tests/framework/utils"
  22. "github.com/stretchr/testify/assert"
  23. "github.com/stretchr/testify/require"
  24. "github.com/stretchr/testify/suite"
  25. )
  26. const (
  27. defaultNamespace = "default"
  28. )
  29. var (
  30. logger = capnslog.NewPackageLogger("github.com/rook/rook", "integrationTest")
  31. )
  32. // Test to make sure all rook components are installed and Running
  33. func checkIfRookClusterIsInstalled(s *suite.Suite, k8sh *utils.K8sHelper, opNamespace, clusterNamespace string, mons int) {
  34. logger.Infof("Make sure all Pods in Rook Cluster %s are running", clusterNamespace)
  35. assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-operator", opNamespace, 1, "Running"),
  36. "Make sure there is 1 rook-operator present in Running state")
  37. assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-mgr", clusterNamespace, 1, "Running"),
  38. "Make sure there is 1 rook-ceph-mgr present in Running state")
  39. assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-osd", clusterNamespace, 1, "Running"),
  40. "Make sure there is at lest 1 rook-ceph-osd present in Running state")
  41. assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-mon", clusterNamespace, mons, "Running"),
  42. fmt.Sprintf("Make sure there are %d rook-ceph-mon present in Running state", mons))
  43. assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-crashcollector", clusterNamespace, 1, "Running"),
  44. "Make sure there is at lest 1 rook-ceph-crash present in Running state")
  45. }
  46. func checkIfRookClusterIsHealthy(s *suite.Suite, testClient *clients.TestClient, clusterNamespace string) {
  47. logger.Infof("Testing cluster %s health", clusterNamespace)
  48. var (
  49. err error
  50. healthy bool
  51. )
  52. retryCount := 0
  53. for retryCount < utils.RetryLoop {
  54. healthy, err = clients.IsClusterHealthy(testClient, clusterNamespace)
  55. if healthy {
  56. logger.Infof("cluster %s is healthy", clusterNamespace)
  57. return
  58. }
  59. retryCount++
  60. logger.Infof("waiting for cluster %s to become healthy. err: %+v", clusterNamespace, err)
  61. <-time.After(time.Duration(utils.RetryInterval) * time.Second)
  62. }
  63. require.Nil(s.T(), err)
  64. }
  65. func checkIfRookClusterHasHealthyIngress(s *suite.Suite, k8sh *utils.K8sHelper, clusterNamespace string) {
  66. logger.Infof("Testing ingress %s health", clusterNamespace)
  67. _, err := k8sh.GetResourceStatus("Ingress", clusterNamespace+"-dashboard", clusterNamespace)
  68. assert.NoError(s.T(), err)
  69. }
  70. func HandlePanics(r interface{}, uninstaller func(), t func() *testing.T) {
  71. if r != nil {
  72. logger.Infof("unexpected panic occurred during test %s, --> %v", t().Name(), r)
  73. t().Fail()
  74. uninstaller()
  75. t().FailNow()
  76. }
  77. }
  78. // StartTestCluster creates new instance of TestCephSettings struct
  79. func StartTestCluster(t func() *testing.T, settings *installer.TestCephSettings) (*installer.CephInstaller, *utils.K8sHelper) {
  80. k8shelper, err := utils.CreateK8sHelper(t)
  81. require.NoError(t(), err)
  82. settings.KubernetesVersion = k8shelper.GetK8sServerVersion()
  83. // Turn on DEBUG logging
  84. capnslog.SetGlobalLogLevel(capnslog.DEBUG)
  85. installer := installer.NewCephInstaller(t, k8shelper.Clientset, settings)
  86. isRookInstalled, err := installer.InstallRook()
  87. if !isRookInstalled || err != nil {
  88. logger.Errorf("Rook was not installed successfully: %v", err)
  89. if !installer.T().Failed() {
  90. installer.GatherAllRookLogs(t().Name(), settings.Namespace, settings.OperatorNamespace)
  91. }
  92. t().Fail()
  93. installer.UninstallRook()
  94. t().FailNow()
  95. }
  96. return installer, k8shelper
  97. }