2017-09-06 23:36:13 -07:00
|
|
|
/*
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-19 01:10:50 -07:00
|
|
|
package integration
|
2017-09-06 23:36:13 -07:00
|
|
|
|
|
|
|
|
import (
|
2017-10-26 17:49:18 -07:00
|
|
|
"fmt"
|
2018-01-09 18:18:20 -08:00
|
|
|
"testing"
|
2025-03-13 15:24:58 -07:00
|
|
|
"time"
|
2018-01-09 18:18:20 -08:00
|
|
|
|
2017-09-06 23:36:13 -07:00
|
|
|
"github.com/coreos/pkg/capnslog"
|
2017-10-06 17:26:39 -07:00
|
|
|
"github.com/rook/rook/tests/framework/clients"
|
2017-11-10 12:03:43 -08:00
|
|
|
"github.com/rook/rook/tests/framework/installer"
|
2017-09-06 23:36:13 -07:00
|
|
|
"github.com/rook/rook/tests/framework/utils"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-10-06 17:26:39 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-09-06 23:36:13 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
)
|
|
|
|
|
|
2018-08-21 15:24:52 -06:00
|
|
|
const (
|
|
|
|
|
defaultNamespace = "default"
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-13 15:24:58 -07:00
|
|
|
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "integrationTest")
|
2017-09-06 23:36:13 -07:00
|
|
|
|
2018-10-14 12:10:08 +02:00
|
|
|
// Test to make sure all rook components are installed and Running
|
2022-07-26 15:05:39 -06:00
|
|
|
func checkIfRookClusterIsInstalled(s *suite.Suite, k8sh *utils.K8sHelper, opNamespace, clusterNamespace string, mons int) {
|
2017-10-06 17:26:39 -07:00
|
|
|
logger.Infof("Make sure all Pods in Rook Cluster %s are running", clusterNamespace)
|
2018-05-18 14:32:43 -07:00
|
|
|
assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-operator", opNamespace, 1, "Running"),
|
2017-09-06 23:36:13 -07:00
|
|
|
"Make sure there is 1 rook-operator present in Running state")
|
2017-10-06 17:26:39 -07:00
|
|
|
assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-mgr", clusterNamespace, 1, "Running"),
|
2017-09-06 23:36:13 -07:00
|
|
|
"Make sure there is 1 rook-ceph-mgr present in Running state")
|
2017-10-06 17:26:39 -07:00
|
|
|
assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-osd", clusterNamespace, 1, "Running"),
|
2017-09-06 23:36:13 -07:00
|
|
|
"Make sure there is at lest 1 rook-ceph-osd present in Running state")
|
2017-10-26 17:49:18 -07:00
|
|
|
assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-mon", clusterNamespace, mons, "Running"),
|
|
|
|
|
fmt.Sprintf("Make sure there are %d rook-ceph-mon present in Running state", mons))
|
2019-06-14 15:07:06 +02:00
|
|
|
assert.True(s.T(), k8sh.CheckPodCountAndState("rook-ceph-crashcollector", clusterNamespace, 1, "Running"),
|
|
|
|
|
"Make sure there is at lest 1 rook-ceph-crash present in Running state")
|
2017-09-06 23:36:13 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-26 15:05:39 -06:00
|
|
|
func checkIfRookClusterIsHealthy(s *suite.Suite, testClient *clients.TestClient, clusterNamespace string) {
|
2017-10-06 17:26:39 -07:00
|
|
|
logger.Infof("Testing cluster %s health", clusterNamespace)
|
2022-07-12 11:50:42 +08:00
|
|
|
var (
|
|
|
|
|
err error
|
|
|
|
|
healthy bool
|
|
|
|
|
)
|
2017-10-06 17:26:39 -07:00
|
|
|
|
|
|
|
|
retryCount := 0
|
2017-10-17 10:14:00 -07:00
|
|
|
for retryCount < utils.RetryLoop {
|
2022-07-12 11:50:42 +08:00
|
|
|
healthy, err = clients.IsClusterHealthy(testClient, clusterNamespace)
|
2020-05-27 05:20:24 +09:00
|
|
|
if healthy {
|
2018-03-16 08:31:34 -07:00
|
|
|
logger.Infof("cluster %s is healthy", clusterNamespace)
|
2017-10-06 17:26:39 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retryCount++
|
|
|
|
|
logger.Infof("waiting for cluster %s to become healthy. err: %+v", clusterNamespace, err)
|
2017-10-17 10:14:00 -07:00
|
|
|
<-time.After(time.Duration(utils.RetryInterval) * time.Second)
|
2017-10-06 17:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require.Nil(s.T(), err)
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-26 15:05:39 -06:00
|
|
|
func checkIfRookClusterHasHealthyIngress(s *suite.Suite, k8sh *utils.K8sHelper, clusterNamespace string) {
|
2021-11-19 14:54:57 +00:00
|
|
|
logger.Infof("Testing ingress %s health", clusterNamespace)
|
2022-04-18 10:13:08 -06:00
|
|
|
_, err := k8sh.GetResourceStatus("Ingress", clusterNamespace+"-dashboard", clusterNamespace)
|
2021-11-19 14:54:57 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 22:52:21 -07:00
|
|
|
func HandlePanics(r interface{}, uninstaller func(), t func() *testing.T) {
|
2017-11-10 12:03:43 -08:00
|
|
|
if r != nil {
|
|
|
|
|
logger.Infof("unexpected panic occurred during test %s, --> %v", t().Name(), r)
|
|
|
|
|
t().Fail()
|
2021-03-09 22:52:21 -07:00
|
|
|
uninstaller()
|
2017-11-10 12:03:43 -08:00
|
|
|
t().FailNow()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 22:52:21 -07:00
|
|
|
// StartTestCluster creates new instance of TestCephSettings struct
|
2021-09-16 17:48:29 -06:00
|
|
|
func StartTestCluster(t func() *testing.T, settings *installer.TestCephSettings) (*installer.CephInstaller, *utils.K8sHelper) {
|
2021-03-09 22:52:21 -07:00
|
|
|
k8shelper, err := utils.CreateK8sHelper(t)
|
2017-11-21 00:37:46 -05:00
|
|
|
require.NoError(t(), err)
|
2022-04-18 10:13:08 -06:00
|
|
|
settings.KubernetesVersion = k8shelper.GetK8sServerVersion()
|
2017-11-21 00:37:46 -05:00
|
|
|
|
2020-03-17 17:34:59 +01:00
|
|
|
// Turn on DEBUG logging
|
|
|
|
|
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
|
2021-03-09 22:52:21 -07:00
|
|
|
|
|
|
|
|
installer := installer.NewCephInstaller(t, k8shelper.Clientset, settings)
|
|
|
|
|
isRookInstalled, err := installer.InstallRook()
|
2018-06-27 12:21:20 -06:00
|
|
|
|
|
|
|
|
if !isRookInstalled || err != nil {
|
|
|
|
|
logger.Errorf("Rook was not installed successfully: %v", err)
|
2021-03-09 22:52:21 -07:00
|
|
|
if !installer.T().Failed() {
|
|
|
|
|
installer.GatherAllRookLogs(t().Name(), settings.Namespace, settings.OperatorNamespace)
|
2018-06-19 13:08:33 -07:00
|
|
|
}
|
2021-03-09 22:52:21 -07:00
|
|
|
t().Fail()
|
|
|
|
|
installer.UninstallRook()
|
|
|
|
|
t().FailNow()
|
2017-11-10 12:03:43 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-09 22:52:21 -07:00
|
|
|
return installer, k8shelper
|
2017-09-06 23:36:13 -07:00
|
|
|
}
|