removing test init - singleton installation of rook
This commit is contained in:
1 parent
3d8ff7200f
commit
c464f6fa1e
8 files changed
+107
-164
No files matched your search
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
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 tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
)
|
||||
|
||||
var (
|
||||
// Env var containing environment manifest
|
||||
Env objects.EnvironmentManifest
|
||||
rook *installer.InstallHelper
|
||||
//Platform where rook needs to installed eg:k8s or standalone
|
||||
Platform enums.RookPlatformType
|
||||
)
|
||||
|
||||
//One init function per package - initializes Rook infra and installs rook(if needed based on flags)
|
||||
func init() {
|
||||
Env = objects.NewManifest()
|
||||
fmt.Println(Env)
|
||||
var err error
|
||||
platform, err := enums.GetRookPlatFormTypeFromString(Env.Platform)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Cannot get platform %v", err))
|
||||
}
|
||||
Platform = platform
|
||||
rook, err := installer.NewK8sRookhelper()
|
||||
|
||||
skipRookInstall := strings.EqualFold(Env.SkipInstallRook, "true")
|
||||
if skipRookInstall {
|
||||
return
|
||||
}
|
||||
err = rook.InstallRookOnK8s(Env.K8sVersion)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to install rook: %v", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// CleanUp function to install Rook
|
||||
func CleanUp() {
|
||||
skipRookInstall := strings.EqualFold(Env.SkipInstallRook, "true")
|
||||
if skipRookInstall {
|
||||
return
|
||||
}
|
||||
rook.UninstallRookFromK8s(Env.K8sVersion)
|
||||
|
||||
}
|
||||
@@ -21,17 +21,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/rook/rook/pkg/model"
|
||||
"github.com/rook/rook/tests"
|
||||
"github.com/rook/rook/tests/framework/clients"
|
||||
"github.com/rook/rook/tests/framework/contracts"
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultPool = "rbd"
|
||||
defaultPool = "rbd"
|
||||
pool1 = "rook_test_pool"
|
||||
blockImageName = "testImage"
|
||||
kubeContext *installer.InstallHelper
|
||||
)
|
||||
|
||||
func TestBlockCreate(t *testing.T) {
|
||||
@@ -40,8 +42,8 @@ func TestBlockCreate(t *testing.T) {
|
||||
|
||||
type BlockImageCreateSuite struct {
|
||||
suite.Suite
|
||||
testClient *clients.TestClient
|
||||
rc contracts.RestAPIOperator
|
||||
testClient *clients.TestClient
|
||||
rc contracts.RestAPIOperator
|
||||
initBlockCount int
|
||||
}
|
||||
|
||||
@@ -49,7 +51,13 @@ func (s *BlockImageCreateSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(tests.Platform)
|
||||
kubeContext, err = installer.NewK8sRookhelper()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
err = kubeContext.InstallRookOnK8s()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(enums.Kubernetes)
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
s.rc = s.testClient.GetRestAPIClient()
|
||||
@@ -149,6 +157,6 @@ func (s *BlockImageCreateSuite) TearDownTest() {
|
||||
}
|
||||
func (s *BlockImageCreateSuite) TearDownSuite() {
|
||||
|
||||
tests.CleanUp()
|
||||
kubeContext.UninstallRookFromK8s()
|
||||
|
||||
}
|
||||
@@ -25,9 +25,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rook/rook/tests"
|
||||
"github.com/rook/rook/tests/framework/clients"
|
||||
"github.com/rook/rook/tests/framework/contracts"
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -36,7 +37,8 @@ import (
|
||||
|
||||
// Test K8s Block Image Creation Scenarios. These tests work when platform is set to Kubernetes
|
||||
var (
|
||||
claimName = "test-claim1"
|
||||
claimName = "test-claim1"
|
||||
kubeContext *installer.InstallHelper
|
||||
)
|
||||
|
||||
func TestK8sBlockCreate(t *testing.T) {
|
||||
@@ -57,7 +59,13 @@ func (s *K8sBlockImageCreateSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(tests.Platform)
|
||||
kubeContext, err = installer.NewK8sRookhelper()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
err = kubeContext.InstallRookOnK8s()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(enums.Kubernetes)
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
s.bc = s.testClient.GetBlockClient()
|
||||
@@ -224,6 +232,6 @@ func (s *K8sBlockImageCreateSuite) isPVCBound(name string) bool {
|
||||
}
|
||||
func (s *K8sBlockImageCreateSuite) TearDownSuite() {
|
||||
|
||||
tests.CleanUp()
|
||||
kubeContext.UninstallRookFromK8s()
|
||||
|
||||
}
|
||||
@@ -23,9 +23,10 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rook/rook/tests"
|
||||
"github.com/rook/rook/tests/framework/clients"
|
||||
"github.com/rook/rook/tests/framework/contracts"
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -35,6 +36,9 @@ import (
|
||||
// Rook Block Storage integration test
|
||||
// Start MySql database that is using rook provisoned block storage.
|
||||
// Make sure database is functional
|
||||
var (
|
||||
kubeContext *installer.InstallHelper
|
||||
)
|
||||
|
||||
func TestK8sBlockIntegration(t *testing.T) {
|
||||
suite.Run(t, new(K8sBlockEnd2EndIntegrationSuite))
|
||||
@@ -57,7 +61,13 @@ func (s *K8sBlockEnd2EndIntegrationSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(tests.Platform)
|
||||
kubeContext, err = installer.NewK8sRookhelper()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
err = kubeContext.InstallRookOnK8s()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(enums.Kubernetes)
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
s.bc = s.testClient.GetBlockClient()
|
||||
@@ -136,12 +146,11 @@ func (s *K8sBlockEnd2EndIntegrationSuite) TearDownTest() {
|
||||
|
||||
s.kh.ResourceOperation("delete", s.mysqlappPath)
|
||||
s.storageClassOperation("mysql-pool", "delete")
|
||||
tests.CleanUp()
|
||||
|
||||
}
|
||||
|
||||
func (s *K8sBlockEnd2EndIntegrationSuite) TearDownSuite() {
|
||||
|
||||
tests.CleanUp()
|
||||
kubeContext.UninstallRookFromK8s()
|
||||
|
||||
}
|
||||
@@ -2,22 +2,28 @@ package longhaul
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/rook/rook/tests"
|
||||
"html/template"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/rook/rook/tests/framework/clients"
|
||||
"github.com/rook/rook/tests/framework/contracts"
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"html/template"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Rook Block Storage integration test
|
||||
// Start MySql database that is using rook provisoned block storage.
|
||||
// Make sure database is functional
|
||||
|
||||
var (
|
||||
kubeContext *installer.InstallHelper
|
||||
)
|
||||
|
||||
func TestK8sBlockLongHaul(t *testing.T) {
|
||||
suite.Run(t, new(K8sBlockLongHaulSuite))
|
||||
}
|
||||
@@ -39,7 +45,13 @@ type K8sBlockLongHaulSuite struct {
|
||||
func (s *K8sBlockLongHaulSuite) SetupSuite() {
|
||||
var err error
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(tests.Platform)
|
||||
kubeContext, err = installer.NewK8sRookhelper()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
err = kubeContext.InstallRookOnK8s()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
s.testClient, err = clients.CreateTestClient(enums.Kubernetes)
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
s.bc = s.testClient.GetBlockClient()
|
||||
@@ -86,8 +98,8 @@ func (s *K8sBlockLongHaulSuite) SetupSuite() {
|
||||
|
||||
func (s *K8sBlockLongHaulSuite) TestBlockLonghaulRun() {
|
||||
|
||||
s.wg.Add(tests.Env.LoadConcurrentRuns)
|
||||
for i := 1; i <= tests.Env.LoadConcurrentRuns; i++ {
|
||||
s.wg.Add(kubeContext.Env.LoadConcurrentRuns)
|
||||
for i := 1; i <= kubeContext.Env.LoadConcurrentRuns; i++ {
|
||||
go s.dbOperation(i)
|
||||
}
|
||||
s.wg.Wait()
|
||||
@@ -114,6 +126,9 @@ func (s *K8sBlockLongHaulSuite) TearDownSuite() {
|
||||
s.kh = nil
|
||||
s.db = nil
|
||||
s = nil
|
||||
|
||||
kubeContext.UninstallRookFromK8s()
|
||||
|
||||
}
|
||||
func (s *K8sBlockLongHaulSuite) storageClassOperation(poolName string, action string) (string, string, int) {
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
"github.com/rook/rook/tests/framework/contracts"
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
"github.com/rook/rook/tests/framework/transport"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"strings"
|
||||
@@ -42,14 +43,13 @@ const (
|
||||
|
||||
var (
|
||||
r *InstallHelper
|
||||
once Once
|
||||
logger = capnslog.NewPackageLogger("github.com/rook/rook", "installer")
|
||||
)
|
||||
|
||||
//InstallHelper wraps installation and uninstallaion of rook on a platfom
|
||||
type InstallHelper struct {
|
||||
transportClient contracts.ITransportClient
|
||||
isRookInstalled bool
|
||||
Env objects.EnvironmentManifest
|
||||
}
|
||||
|
||||
func getPodSpecPath(k8sverion string) string {
|
||||
@@ -138,15 +138,19 @@ func (h *InstallHelper) createk8sRookCluster(k8sHelper *utils.K8sHelper, k8svers
|
||||
}
|
||||
|
||||
//InstallRookOnK8s installs rook on k8s
|
||||
func (h *InstallHelper) InstallRookOnK8s(k8sversion string) (err error) {
|
||||
if h.isRookInstalled {
|
||||
func (h *InstallHelper) InstallRookOnK8s() (err error) {
|
||||
|
||||
//flag used for local debuggin purpose, when rook is pre-installed
|
||||
skipRookInstall := strings.EqualFold(h.Env.SkipInstallRook, "true")
|
||||
if skipRookInstall {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof("Installing rook on k8s %s", h.Env.K8sVersion)
|
||||
//Create rook operator
|
||||
k8sHelp := utils.CreatK8sHelper()
|
||||
|
||||
err = h.createK8sRookOperator(k8sHelp, k8sversion)
|
||||
err = h.createK8sRookOperator(k8sHelp, h.Env.K8sVersion)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -154,7 +158,7 @@ func (h *InstallHelper) InstallRookOnK8s(k8sversion string) (err error) {
|
||||
time.Sleep(10 * time.Second) ///TODO: add real check here
|
||||
|
||||
//Create rook cluster
|
||||
err = h.createk8sRookCluster(k8sHelp, k8sversion)
|
||||
err = h.createk8sRookCluster(k8sHelp, h.Env.K8sVersion)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -162,22 +166,26 @@ func (h *InstallHelper) InstallRookOnK8s(k8sversion string) (err error) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
//Create rook client
|
||||
err = h.createK8sRookToolbox(k8sHelp, k8sversion)
|
||||
err = h.createK8sRookToolbox(k8sHelp, h.Env.K8sVersion)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
h.isRookInstalled = true
|
||||
|
||||
logger.Infof("installed rook on k8s %s", h.Env.K8sVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
//UninstallRookFromK8s uninstalls rook from k8s
|
||||
func (h *InstallHelper) UninstallRookFromK8s(k8sversion string) {
|
||||
func (h *InstallHelper) UninstallRookFromK8s() {
|
||||
//flag used for local debugging purpose, when rook is pre-installed
|
||||
skipRookInstall := strings.EqualFold(h.Env.SkipInstallRook, "true")
|
||||
if skipRookInstall {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof("Uninstalling Rook")
|
||||
k8sHelp := utils.CreatK8sHelper()
|
||||
var err error
|
||||
_, err = k8sHelp.ResourceOperation("delete", path.Join(getPodSpecPath(k8sversion), rookOperatorFileName))
|
||||
_, err = k8sHelp.ResourceOperation("delete", path.Join(getPodSpecPath(h.Env.K8sVersion), rookOperatorFileName))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -189,7 +197,7 @@ func (h *InstallHelper) UninstallRookFromK8s(k8sversion string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !strings.EqualFold(k8sversion, "v1.5") {
|
||||
if !strings.EqualFold(h.Env.K8sVersion, "v1.5") {
|
||||
_, err = k8sHelp.DeleteResource([]string{"clusterrole", "rook-api"})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -216,7 +224,6 @@ func (h *InstallHelper) UninstallRookFromK8s(k8sversion string) {
|
||||
|
||||
if isRookUninstalled {
|
||||
logger.Infof("Rook uninstalled successfully")
|
||||
once.Reset()
|
||||
return
|
||||
}
|
||||
panic(fmt.Errorf("Rook not uninstalled"))
|
||||
@@ -224,13 +231,16 @@ func (h *InstallHelper) UninstallRookFromK8s(k8sversion string) {
|
||||
|
||||
//NewK8sRookhelper creates new instance of InstallHelper
|
||||
func NewK8sRookhelper() (*InstallHelper, error) {
|
||||
env := objects.NewManifest()
|
||||
if kv := os.Getenv("KUBE_VERSION"); kv != "" {
|
||||
env.K8sVersion = kv
|
||||
}
|
||||
|
||||
transportClient := transport.CreateNewk8sTransportClient()
|
||||
once.Do(func() {
|
||||
r = &InstallHelper{
|
||||
transportClient: transportClient,
|
||||
isRookInstalled: false,
|
||||
}
|
||||
})
|
||||
r = &InstallHelper{
|
||||
transportClient: transportClient,
|
||||
Env: env,
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
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 installer
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// Once is an object that will perform exactly one action.
|
||||
type Once struct {
|
||||
m sync.Mutex
|
||||
done uint32
|
||||
}
|
||||
|
||||
//Do simulate sync.Once.Do by executing function only once
|
||||
//until rest is called.
|
||||
//See http://golang.org/pkg/sync/#Once
|
||||
func (o *Once) Do(f func()) {
|
||||
if atomic.LoadUint32(&o.done) == 1 {
|
||||
return
|
||||
}
|
||||
// Slow-path.
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
if o.done == 0 {
|
||||
defer atomic.StoreUint32(&o.done, 1)
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
// Reset indicates that the next call to Do should actually be called
|
||||
// once again.
|
||||
//See http://golang.org/pkg/sync/#Once
|
||||
func (o *Once) Reset() {
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
atomic.StoreUint32(&o.done, 0)
|
||||
}
|
||||
@@ -21,12 +21,16 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
"github.com/rook/rook/tests"
|
||||
"github.com/rook/rook/tests/framework/enums"
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
var (
|
||||
kubeContext *installer.InstallHelper
|
||||
)
|
||||
|
||||
func TestRookSmokeSuiteK8s(t *testing.T) {
|
||||
suite.Run(t, new(SmokeSuite))
|
||||
}
|
||||
@@ -38,7 +42,14 @@ type SmokeSuite struct {
|
||||
|
||||
func (suite *SmokeSuite) SetupSuite() {
|
||||
var err error
|
||||
suite.helper, err = CreateSmokeTestClient(enums.Kubernetes, tests.Env.K8sVersion)
|
||||
|
||||
kubeContext, err = installer.NewK8sRookhelper()
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
err = kubeContext.InstallRookOnK8s()
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
suite.helper, err = CreateSmokeTestClient(enums.Kubernetes, kubeContext.Env.K8sVersion)
|
||||
require.Nil(suite.T(), err)
|
||||
}
|
||||
|
||||
@@ -97,7 +108,9 @@ func (suite *SmokeSuite) blockTestDataCleanUp() {
|
||||
}
|
||||
|
||||
func (suite *SmokeSuite) TearDownSuite() {
|
||||
tests.CleanUp()
|
||||
|
||||
kubeContext.UninstallRookFromK8s()
|
||||
|
||||
}
|
||||
|
||||
// periodically checking if block image count has changed to expected value
|
||||
|
||||
Reference in new issue
Block a user