Files
my-rook-config/tests/integration/block_createBlock_api_test.go
T

160 lines
5.0 KiB
Go
Raw Normal View History

2017-06-26 21:52:06 -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-07-21 12:07:15 -07:00
package integration
2017-05-25 10:26:03 -07:00
import (
"strings"
"testing"
2017-06-26 21:52:06 -07:00
"github.com/rook/rook/pkg/model"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/contracts"
2017-07-20 23:30:32 -07:00
"github.com/rook/rook/tests/framework/utils"
2017-10-12 16:03:08 -07:00
"github.com/stretchr/testify/assert"
2017-06-26 21:52:06 -07:00
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
2017-05-25 10:26:03 -07:00
)
var (
2017-09-19 01:10:50 -07:00
pool1 = "rook_test_pool1"
pool2 = "rook_test_pool2"
2017-05-25 10:26:03 -07:00
blockImageName = "testImage"
)
func TestBlockImageCreateSuite(t *testing.T) {
2017-11-10 12:03:43 -08:00
s := new(BlockImageCreateSuite)
defer func(s *BlockImageCreateSuite) {
2017-11-21 00:37:46 -05:00
HandlePanics(recover(), s.op, s.T)
2017-11-10 12:03:43 -08:00
}(s)
suite.Run(t, s)
2017-05-25 10:26:03 -07:00
}
type BlockImageCreateSuite struct {
suite.Suite
testClient *clients.TestClient
2017-10-12 16:03:08 -07:00
kh *utils.K8sHelper
rc contracts.RestAPIOperator
2017-11-21 00:37:46 -05:00
op contracts.Setup
2017-07-05 12:26:18 -07:00
initBlockCount int
2017-10-12 16:03:08 -07:00
namespace string
2017-05-25 10:26:03 -07:00
}
func (s *BlockImageCreateSuite) SetupSuite() {
2017-10-12 16:03:08 -07:00
var err error
s.namespace = "block-api-ns"
2017-11-21 00:37:46 -05:00
s.op, s.kh = NewBaseTestOperations(s.T, s.namespace, "bluestore", "", false, false, 1)
s.testClient = GetTestClient(s.kh, s.namespace, s.op, s.T)
2017-05-25 10:26:03 -07:00
s.rc = s.testClient.GetRestAPIClient()
initialBlocks, err := s.rc.GetBlockImages()
2017-10-12 16:03:08 -07:00
assert.Nil(s.T(), err)
2017-07-05 12:26:18 -07:00
s.initBlockCount = len(initialBlocks)
2017-05-25 10:26:03 -07:00
}
//Test Creating Block image on custom pool
func (s *BlockImageCreateSuite) TestCreatingNewBlockImageOnCustomPool() {
s.T().Log("Test Creating new block image for custom pool")
newPool := model.Pool{Name: pool1}
_, err := s.rc.CreatePool(newPool)
require.Nil(s.T(), err)
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: newPool.Name}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
2017-07-05 12:26:18 -07:00
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
2017-05-25 10:26:03 -07:00
}
//Test Creating Block image twice on same pool
func (s *BlockImageCreateSuite) TestRecreatingBlockImageForSamePool() {
s.T().Log("Test Case when Block Image is created with Name that is already used by another block on same pool")
2017-09-19 01:10:50 -07:00
//create pool1
newPool1 := model.Pool{Name: pool1}
_, err := s.rc.CreatePool(newPool1)
require.Nil(s.T(), err)
2017-05-25 10:26:03 -07:00
// create new block image
2017-09-19 01:10:50 -07:00
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: pool1}
2017-05-25 10:26:03 -07:00
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
2017-07-05 12:26:18 -07:00
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
2017-05-25 10:26:03 -07:00
//create same block again on same pool
2017-09-19 01:10:50 -07:00
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: pool1}
2017-05-25 10:26:03 -07:00
cbi2, err := s.rc.CreateBlockImage(newImage2)
require.Error(s.T(), err, "Make sure dupe block is not created")
require.NotContains(s.T(), cbi2, "succeeded created image")
b2, _ := s.rc.GetBlockImages()
require.Equal(s.T(), len(b), len(b2), "Make sure new block image is not created")
}
//Test Creating Block image twice on different pool
func (s *BlockImageCreateSuite) TestRecreatingBlockImageForDifferentPool() {
s.T().Log("Test Case when Block Image is created with Name that is already used by another block on different pool")
2017-09-19 01:10:50 -07:00
//create pool1
newPool1 := model.Pool{Name: pool1}
_, err := s.rc.CreatePool(newPool1)
require.Nil(s.T(), err)
//create pool2
newPool2 := model.Pool{Name: pool2}
_, err = s.rc.CreatePool(newPool2)
require.Nil(s.T(), err)
2017-05-25 10:26:03 -07:00
// create new block image
2017-09-19 01:10:50 -07:00
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: pool1}
2017-05-25 10:26:03 -07:00
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
2017-07-05 12:26:18 -07:00
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
2017-05-25 10:26:03 -07:00
//create same block again on different pool
2017-09-19 01:10:50 -07:00
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: pool2}
2017-05-25 10:26:03 -07:00
cbi2, err := s.rc.CreateBlockImage(newImage2)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi2, "succeeded created image")
b2, _ := s.rc.GetBlockImages()
require.Equal(s.T(), len(b)+1, len(b2), "Make sure new block image is created")
}
// Delete all Block images that have the word Test in their name
func (s *BlockImageCreateSuite) TearDownTest() {
blocks, err := s.rc.GetBlockImages()
assert.NoError(s.T(), err)
2017-05-25 10:26:03 -07:00
for _, b := range blocks {
if strings.Contains(b.Name, "test") {
s.rc.DeleteBlockImage(b)
}
}
}
func (s *BlockImageCreateSuite) TearDownSuite() {
2017-11-21 00:37:46 -05:00
s.op.TearDown()
}