improve logging and fix lint issues

This commit is contained in:
Divesh Angula committed 2017-07-14 14:10:31 -07:00
1 parent 8c3df0003f
commit 394df46889
35 files changed
+667 -423

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ The following parameters are available while running tests
Parameter | Description | Possible values | Default
--- |--- | --- | ---
rook_platform| platform rook needs to be installed on | kubernetes | kubernetes
k8s_version | version of Kubernetes to be installed | v1.6 | v1.6
k8s_version | version of Kubernetes to be installed | v1.5,v1.6 and v1.7 | v1.6
rook_image | rook image name to be installed | valid image name | rook/rook
toolbox_image | toolbox image name to be installed | valid image name | rook/toolbox
skip_install_rook | skips installing rook (if already installed) | true or false | false
+8 -4
View File
@@ -26,14 +26,17 @@ import (
)
var (
Env objects.EnvironmentManifest
rook *installer.InstallHelper
// 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 {
@@ -46,18 +49,19 @@ func init() {
if skipRookInstall {
return
}
err = rook.InstallRookOnK8s()
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()
rook.UninstallRookFromK8s(Env.K8sVersion)
}
+11 -11
View File
@@ -29,7 +29,7 @@ import (
)
var (
default_pool = "rbd"
defaultPool = "rbd"
pool1 = "rook_test_pool"
blockImageName = "testImage"
)
@@ -42,7 +42,7 @@ type BlockImageCreateSuite struct {
suite.Suite
testClient *clients.TestClient
rc contracts.RestAPIOperator
init_blockCount int
initBlockCount int
}
func (s *BlockImageCreateSuite) SetupSuite() {
@@ -55,19 +55,19 @@ func (s *BlockImageCreateSuite) SetupSuite() {
s.rc = s.testClient.GetRestAPIClient()
initialBlocks, err := s.rc.GetBlockImages()
require.Nil(s.T(), err)
s.init_blockCount = len(initialBlocks)
s.initBlockCount = len(initialBlocks)
}
//Test Creating Block image on default pool(rbd)
func (s *BlockImageCreateSuite) TestCreatingNewBlockImageOnDefaultPool() {
s.T().Log("Test Creating new block image for default pool")
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: default_pool}
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: defaultPool}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.init_blockCount+1, len(b), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
@@ -84,7 +84,7 @@ func (s *BlockImageCreateSuite) TestCreatingNewBlockImageOnCustomPool() {
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.init_blockCount+1, len(b), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
@@ -93,15 +93,15 @@ 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")
// create new block image
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: default_pool}
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: defaultPool}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.init_blockCount+1, len(b), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
//create same block again on same pool
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: default_pool}
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: defaultPool}
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")
@@ -115,12 +115,12 @@ 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")
// create new block image
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: default_pool}
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: defaultPool}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.init_blockCount+1, len(b), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
newPool := model.Pool{Name: pool1}
_, err = s.rc.CreatePool(newPool)
+5 -5
View File
@@ -48,7 +48,7 @@ type K8sBlockImageCreateSuite struct {
testClient *clients.TestClient
bc contracts.BlockOperator
kh *utils.K8sHelper
init_blockCount int
initBlockCount int
pvPath string
storageclassPath string
}
@@ -64,7 +64,7 @@ func (s *K8sBlockImageCreateSuite) SetupSuite() {
s.kh = utils.CreatK8sHelper()
initialBlocks, err := s.bc.BlockList()
require.Nil(s.T(), err)
s.init_blockCount = len(initialBlocks)
s.initBlockCount = len(initialBlocks)
s.pvPath = filepath.Join(os.Getenv("GOPATH"), "src/github.com/rook/rook/tests/data/block/pvc.tmpl")
s.storageclassPath = filepath.Join(os.Getenv("GOPATH"), "src/github.com/rook/rook/tests/data/block/storageclass_pool.tmpl")
}
@@ -86,7 +86,7 @@ func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenNoStorageClassExists() {
//check block image count
b, _ := s.bc.BlockList()
require.Equal(s.T(), s.init_blockCount, len(b), "Make sure new block image is not created")
require.Equal(s.T(), s.initBlockCount, len(b), "Make sure new block image is not created")
}
@@ -117,7 +117,7 @@ func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenStorageClassExists() {
//check block image count
b, _ := s.bc.BlockList()
require.Equal(s.T(), s.init_blockCount+1, len(b), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
@@ -148,7 +148,7 @@ func (s *K8sBlockImageCreateSuite) TestCreateSamePVCTwice() {
require.True(s.T(), s.isPVCBound(claimName))
b1, _ := s.bc.BlockList()
require.Equal(s.T(), s.init_blockCount+1, len(b1), "Make sure new block image is created")
require.Equal(s.T(), s.initBlockCount+1, len(b1), "Make sure new block image is created")
//Create same pvc again
sout2, serr2, status2 := s.pvcOperation(claimName, "create")
@@ -45,10 +45,10 @@ type K8sBlockEnd2EndIntegrationSuite struct {
testClient *clients.TestClient
bc contracts.BlockOperator
kh *utils.K8sHelper
init_blockCount int
initBlockCount int
storageclassPath string
mysqlappPath string
db *utils.MySqlHelper
db *utils.MySQLHelper
}
//Test set up - does the following in order
@@ -64,7 +64,7 @@ func (s *K8sBlockEnd2EndIntegrationSuite) SetupSuite() {
s.kh = utils.CreatK8sHelper()
initialBlocks, err := s.bc.BlockList()
require.Nil(s.T(), err)
s.init_blockCount = len(initialBlocks)
s.initBlockCount = len(initialBlocks)
s.storageclassPath = filepath.Join(os.Getenv("GOPATH"), "src/github.com/rook/rook/tests/data/block/storageclass_pool.tmpl")
s.mysqlappPath = filepath.Join(os.Getenv("GOPATH"), "src/github.com/rook/rook/tests/data/integration/mysqlapp.yaml")
@@ -87,10 +87,10 @@ func (s *K8sBlockEnd2EndIntegrationSuite) SetupSuite() {
require.Nil(s.T(), err)
require.Contains(s.T(), pvcStatus, "Bound")
dbIp, err := s.kh.GetPodHostId("mysqldb", "")
dbIP, err := s.kh.GetPodHostID("mysqldb", "")
require.Nil(s.T(), err)
//create database connection
s.db = utils.CreateNewMySqlHelper("mysql", "mysql", dbIp+":30003", "sample")
s.db = utils.CreateNewMySQLHelper("mysql", "mysql", dbIP+":30003", "sample")
}
@@ -24,14 +24,14 @@ func TestK8sBlockLongHaul(t *testing.T) {
type K8sBlockLongHaulSuite struct {
suite.Suite
testClient *clients.TestClient
bc contracts.BlockOperator
kh *utils.K8sHelper
init_blockCount int
storageClass_Path string
mysqlApp_Path string
db *utils.MySqlHelper
wg sync.WaitGroup
testClient *clients.TestClient
bc contracts.BlockOperator
kh *utils.K8sHelper
initBlockCount int
storageClassPath string
mysqlAppPath string
db *utils.MySQLHelper
wg sync.WaitGroup
}
//Test set up - does the following in order
@@ -46,9 +46,9 @@ func (s *K8sBlockLongHaulSuite) SetupSuite() {
s.kh = utils.CreatK8sHelper()
initialBlocks, err := s.bc.BlockList()
require.Nil(s.T(), err)
s.init_blockCount = len(initialBlocks)
s.storageClass_Path = "../../../../data/block/storageclass_pool.tmpl"
s.mysqlApp_Path = "../../../../data/integration/mysqlapp.yaml"
s.initBlockCount = len(initialBlocks)
s.storageClassPath = "../../../../data/block/storageclass_pool.tmpl"
s.mysqlAppPath = "../../../../data/integration/mysqlapp.yaml"
//create storage class
if scp, _ := s.kh.IsStorageClassPresent("rook-block"); !scp {
@@ -63,7 +63,7 @@ func (s *K8sBlockLongHaulSuite) SetupSuite() {
//create mysql pod
if _, err := s.kh.GetPVCStatus("mysql-pv-claim"); err != nil {
s.kh.ResourceOperation("create", s.mysqlApp_Path)
s.kh.ResourceOperation("create", s.mysqlAppPath)
//wait till mysql pod is up
require.True(s.T(), s.kh.IsPodInExpectedState("mysqldb", "", "Running"))
@@ -71,10 +71,10 @@ func (s *K8sBlockLongHaulSuite) SetupSuite() {
require.Nil(s.T(), err)
require.Contains(s.T(), pvcStatus, "Bound")
}
dbIp, err := s.kh.GetPodHostId("mysqldb", "")
dbIP, err := s.kh.GetPodHostID("mysqldb", "")
require.Nil(s.T(), err)
//create database connection
s.db = utils.CreateNewMySqlHelper("mysql", "mysql", dbIp+":30003", "sample")
s.db = utils.CreateNewMySQLHelper("mysql", "mysql", dbIP+":30003", "sample")
require.True(s.T(), s.db.PingSuccess())
@@ -117,7 +117,7 @@ func (s *K8sBlockLongHaulSuite) TearDownSuite() {
}
func (s *K8sBlockLongHaulSuite) storageClassOperation(poolName string, action string) (string, string, int) {
t, _ := template.ParseFiles(s.storageClass_Path)
t, _ := template.ParseFiles(s.storageClassPath)
var tpl bytes.Buffer
config := map[string]string{
+24
View File
@@ -0,0 +1,24 @@
apiVersion: rook.io/v1alpha1
kind: Pool
metadata:
name: replicapool
namespace: rook
spec:
replication:
size: 1
# For an erasure-coded pool, comment out the replication size above and uncomment the following settings.
# Make sure you have enough OSDs to support the replica size or erasure code chunks.
#erasureCode:
# codingChunks: 2
# dataChunks: 2
---
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: rook-block
provisioner: rook.io/block
parameters:
pool: replicapool
# Specify the Rook cluster from which to create volumes. If not specified, it will use `rook` as the namespace and name of the cluster.
# clusterName: rook
# clusterNamespace: rook
+29 -30
View File
@@ -23,7 +23,8 @@ import (
"github.com/rook/rook/tests/framework/contracts"
)
type blockOperation struct {
//BlockOperation is wrapper for k8s rook block operations
type BlockOperation struct {
transportClient contracts.ITransportClient
restClient contracts.RestAPIOperator
}
@@ -33,63 +34,62 @@ var (
readDataFromBlockPod = []string{"cat", "READ_DATA_CMD"}
)
// Constructor to create blockOperation - client to perform rook Block operations on k8s
func CreateK8BlockOperation(client contracts.ITransportClient, rookRestClient contracts.RestAPIOperator) *blockOperation {
return &blockOperation{transportClient: client, restClient: rookRestClient}
// CreateK8BlockOperation - Constructor to create BlockOperation - client to perform rook Block operations on k8s
func CreateK8BlockOperation(client contracts.ITransportClient, rookRestClient contracts.RestAPIOperator) *BlockOperation {
return &BlockOperation{transportClient: client, restClient: rookRestClient}
}
// Function to create a Block using Rook
// BlockCreate Function to create a Block using Rook
// Input paramaters -
//name - path to a yaml file that creates a pvc in k8s - yaml should describe name and size of pvc being created
//size - not user for k8s implementation since its descried on the pvc yaml definition
//Output - k8s create pvc operation output and/or error
func (rb *blockOperation) BlockCreate(name string, size int) (string, error) {
func (rb *BlockOperation) BlockCreate(name string, size int) (string, error) {
cmdArgs := []string{name}
out, err, status := rb.transportClient.Create(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to create block -- : %s", err)
}
return err, fmt.Errorf("Unable to create block -- : %s", err)
}
// Function to delete a Block using Rook
// BlockDelete Function to delete a Block using Rook
// Input paramaters -
//name - path to a yaml file that where pvc is described - delete is run on the the yaml definition
//Output - k8s delete pvc operation output and/or error
func (rb *blockOperation) BlockDelete(name string) (string, error) {
func (rb *BlockOperation) BlockDelete(name string) (string, error) {
cmdArgs := []string{name}
out, err, status := rb.transportClient.Delete(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to delete block -- : %s", err)
}
return err, fmt.Errorf("Unable to delete block -- : %s", err)
}
// Function to list all the blocks created/being managed by rook
func (rb *blockOperation) BlockList() ([]model.BlockImage, error) {
// BlockList Function to list all the blocks created/being managed by rook
func (rb *BlockOperation) BlockList() ([]model.BlockImage, error) {
return rb.restClient.GetBlockImages()
}
// Function to map a Block using Rook
// BlockMap Function to map a Block using Rook
// Input paramaters -
//name - path to a yaml file that creates a pod - pod should be defined to use a pvc that was created earlier
//mountpath - not used in this impl since mountpath is defined in the pod definition
//Output - k8s create pod operation output and/or error
func (rb *blockOperation) BlockMap(name string, mountpath string) (string, error) {
func (rb *BlockOperation) BlockMap(name string, mountpath string) (string, error) {
cmdArgs := []string{name}
out, err, status := rb.transportClient.Create(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to Map block -- : %s", err)
}
return err, fmt.Errorf("Unable to Map block -- : %s", err)
}
// Function to write data to block created by rook ,i.e. write data to a pod that is using a pvc
//BlockWrite Function to write data to block created by rook ,i.e. write data to a pod that is using a pvc
// Input paramaters -
//name - path to a yaml file that creates a pod - pod should be defined to use a pvc that was created earlier
//mountpath - folder on the pod were data is supposed to be written(should match the mountpath described in the pod definition)
@@ -97,7 +97,7 @@ func (rb *blockOperation) BlockMap(name string, mountpath string) (string, error
//filename - file where data is written to
//namespace - optional param - namespace of the pod
//Output - k8s exec pod operation output and/or error
func (rb *blockOperation) BlockWrite(name string, mountpath string, data string, filename string, namespace string) (string, error) {
func (rb *BlockOperation) BlockWrite(name string, mountpath string, data string, filename string, namespace string) (string, error) {
wt := "echo \"" + data + "\">" + mountpath + "/" + filename
writeDataToBlockPod[2] = wt
option := []string{name}
@@ -107,19 +107,19 @@ func (rb *blockOperation) BlockWrite(name string, mountpath string, data string,
out, err, status := rb.transportClient.Execute(writeDataToBlockPod, option)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to write data to pod: %s --> %s", err, out)
}
return err, fmt.Errorf("Unable to write data to pod: %s --> %s", err, out)
}
// Function to read from block created by rook ,i.e. Read data from a pod that is using a pvc
// BlockRead Function to read from block created by rook ,i.e. Read data from a pod that is using a pvc
// Input paramaters -
//name - path to a yaml file that creates a pod - pod should be defined to use a pvc that was created earlier
//mountpath - folder on the pod were data is supposed to be written(should match the mountpath described in the pod definition)
//filename - file to be read
//namespace - optional param - namespace of the pod
//Output - k8s exec pod operation output and/or error
func (rb *blockOperation) BlockRead(name string, mountpath string, filename string, namespace string) (string, error) {
func (rb *BlockOperation) BlockRead(name string, mountpath string, filename string, namespace string) (string, error) {
rd := mountpath + "/" + filename
readDataFromBlockPod[1] = rd
option := []string{name}
@@ -129,23 +129,22 @@ func (rb *blockOperation) BlockRead(name string, mountpath string, filename stri
out, err, status := rb.transportClient.Execute(readDataFromBlockPod, option)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to read data to pod -- : %s", err)
}
return err, fmt.Errorf("Unable to read data to pod -- : %s", err)
}
// Function to map a Block using Rook
// BlockUnmap Function to map a Block using Rook
// Input paramaters -
//name - path to a yaml file - the pod described in yam file is deleted
//mountpath - not used in this impl since mountpath is defined in the pod definition
//Output - k8s delete pod operation output and/or error
func (rb *blockOperation) BlockUnmap(name string, mountpath string) (string, error) {
func (rb *BlockOperation) BlockUnmap(name string, mountpath string) (string, error) {
cmdArgs := []string{name}
out, err, status := rb.transportClient.Delete(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to unmap block -- : %s", err)
}
return err, fmt.Errorf("Unable to unmap block -- : %s", err)
}
+25 -26
View File
@@ -23,7 +23,8 @@ import (
"github.com/rook/rook/tests/framework/contracts"
)
type fileSystemOperation struct {
//FileSystemOperation is a wrapper for k8s rook file operations
type FileSystemOperation struct {
transportClient contracts.ITransportClient
restClient contracts.RestAPIOperator
}
@@ -33,53 +34,52 @@ var (
readDataFromFilePod = []string{"cat", "READ_DATA_CMD"}
)
// Constructor to create fileSystemOperation - client to perform rook file system operations on k8s
func CreateK8sFileSystemOperation(client contracts.ITransportClient, rookRestClient contracts.RestAPIOperator) *fileSystemOperation {
return &fileSystemOperation{transportClient: client, restClient: rookRestClient}
// CreateK8sFileSystemOperation Constructor to create FileSystemOperation - client to perform rook file system operations on k8s
func CreateK8sFileSystemOperation(client contracts.ITransportClient, rookRestClient contracts.RestAPIOperator) *FileSystemOperation {
return &FileSystemOperation{transportClient: client, restClient: rookRestClient}
}
//Function to create a fileSystem in rook
//FSCreate Function to create a fileSystem in rook
//Input paramatres -
// name - name of the shared file system to be created
//Output - output returned by rook rest API client
func (rfs *fileSystemOperation) FSCreate(name string) (string, error) {
func (rfs *FileSystemOperation) FSCreate(name string) (string, error) {
createFilesystem := model.FilesystemRequest{Name: name}
return rfs.restClient.CreateFilesystem(createFilesystem)
}
//Function to delete a fileSystem in rook
//FSDelete Function to delete a fileSystem in rook
//Input paramatres -
// name - name of the shared file system to be deleted
//Output - output returned by rook rest API client
func (rfs *fileSystemOperation) FSDelete(name string) (string, error) {
func (rfs *FileSystemOperation) FSDelete(name string) (string, error) {
deleteFilesystem := model.FilesystemRequest{Name: name}
return rfs.restClient.DeleteFilesystem(deleteFilesystem)
}
//Function to list a fileSystem in rook
//FSList Function to list a fileSystem in rook
//Output - output returned by rook rest API client
func (rfs *fileSystemOperation) FSList() ([]model.Filesystem, error) {
func (rfs *FileSystemOperation) FSList() ([]model.Filesystem, error) {
return rfs.restClient.GetFilesystems()
}
//Function to Mount a file system created by rook(on a pod)
//FSMount Function to Mount a file system created by rook(on a pod)
//Input paramaters -
//name - path to the yaml defintion file - definition of pod to be created that mounts existing file system
//path - ignored in this case - moount path is defined in the path definition
//output - output returned by k8s create pod operaton and/or error
func (rfs *fileSystemOperation) FSMount(name string, path string) (string, error) {
func (rfs *FileSystemOperation) FSMount(name string, path string) (string, error) {
cmdArgs := []string{name}
out, err, status := rfs.transportClient.Create(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to mount FileSystem -- : %s", err)
}
return err, fmt.Errorf("Unable to mount FileSystem -- : %s", err)
}
// Function to write data to file system created by rook ,i.e. write data to a pod that has filesystem mounted
//FSWrite Function to write data to file system created by rook ,i.e. write data to a pod that has filesystem mounted
// Input paramaters -
//name - path to a yaml file that creates a pod - pod should be defined to use a pvc that was created earlier
//mountpath - folder on the pod were data is supposed to be written(should match the mountpath described in the pod definition)
@@ -87,7 +87,7 @@ func (rfs *fileSystemOperation) FSMount(name string, path string) (string, error
//filename - file where data is written to
//namespace - optional param - namespace of the pod
//Output - k8s exec pod operation output and/or error
func (rfs *fileSystemOperation) FSWrite(name string, mountpath string, data string, filename string, namespace string) (string, error) {
func (rfs *FileSystemOperation) FSWrite(name string, mountpath string, data string, filename string, namespace string) (string, error) {
wt := "echo \"" + data + "\">" + mountpath + "/" + filename
writeDataToFilePod[2] = wt
option := []string{name}
@@ -97,19 +97,19 @@ func (rfs *fileSystemOperation) FSWrite(name string, mountpath string, data stri
out, err, status := rfs.transportClient.Execute(writeDataToFilePod, option)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to write data to pod -- : %s", err)
}
return err, fmt.Errorf("Unable to write data to pod -- : %s", err)
}
// Function to write read from file system created by rook ,i.e. Read data from a pod that filesystem mounted
//FSRead Function to write read from file system created by rook ,i.e. Read data from a pod that filesystem mounted
// Input paramaters -
//name - path to a yaml file that creates a pod - pod should be defined to use a pvc that was created earlier
//mountpath - folder on the pod were data is supposed to be written(should match the mountpath described in the pod definition)
//filename - file to be read
//namespace - optional param - namespace of the pod
//Output - k8s exec pod operation output and/or error
func (rfs *fileSystemOperation) FSRead(name string, mountpath string, filename string, namespace string) (string, error) {
func (rfs *FileSystemOperation) FSRead(name string, mountpath string, filename string, namespace string) (string, error) {
rd := mountpath + "/" + filename
readDataFromFilePod[1] = rd
option := []string{name}
@@ -119,23 +119,22 @@ func (rfs *fileSystemOperation) FSRead(name string, mountpath string, filename s
out, err, status := rfs.transportClient.Execute(readDataFromFilePod, option)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to write data to pod -- : %s", err)
}
return err, fmt.Errorf("Unable to write data to pod -- : %s", err)
}
//Function to UnMount a file system created by rook(delete pod)
//FSUnmount Function to UnMount a file system created by rook(delete pod)
//Input paramaters -
//name - path to the yaml defintion file - definition of pod to be deleted that has a file system mounted
//path - ignored in this case - moount path is defined in the path definition
//output - output returned by k8s delete pod operaton and/or error
func (rfs *fileSystemOperation) FSUnmount(name string) (string, error) {
func (rfs *FileSystemOperation) FSUnmount(name string) (string, error) {
cmdArgs := []string{name}
out, err, status := rfs.transportClient.Delete(cmdArgs, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf("Unable to unmount FileSystem -- : %s", err)
}
return err, fmt.Errorf("Unable to unmount FileSystem -- : %s", err)
}
+10 -8
View File
@@ -21,15 +21,17 @@ import (
"github.com/rook/rook/tests/framework/contracts"
)
//ObjectOperation is wrapper for k8s rook object operations
type ObjectOperation struct {
restClient contracts.RestAPIOperator
}
//CreateObjectOperation creates new rook object client
func CreateObjectOperation(rookRestClient contracts.RestAPIOperator) *ObjectOperation {
return &ObjectOperation{restClient: rookRestClient}
}
//Function to create a object store in rook
//ObjectCreate Function to create a object store in rook
//Input paramatres -None
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectCreate() (string, error) {
@@ -37,7 +39,7 @@ func (ro *ObjectOperation) ObjectCreate() (string, error) {
}
//Function to get Buckets present in rook object store
//ObjectBucketList Function to get Buckets present in rook object store
//Input paramatres - None
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectBucketList() ([]model.ObjectBucket, error) {
@@ -45,7 +47,7 @@ func (ro *ObjectOperation) ObjectBucketList() ([]model.ObjectBucket, error) {
}
//Function to get connection information for a user
//ObjectConnection Function to get connection information for a user
//Input paramatres - None
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectConnection() (*model.ObjectStoreConnectInfo, error) {
@@ -53,7 +55,7 @@ func (ro *ObjectOperation) ObjectConnection() (*model.ObjectStoreConnectInfo, er
}
//Function to create user on rook object store
//ObjectCreateUser Function to create user on rook object store
//Input paramatres - userId and display Name
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectCreateUser(userid string, displayname string) (*model.ObjectUser, error) {
@@ -62,7 +64,7 @@ func (ro *ObjectOperation) ObjectCreateUser(userid string, displayname string) (
}
//Function to update a user on rook object store
//ObjectUpdateUser Function to update a user on rook object store
//Input paramatres - userId,display Name and email address
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectUpdateUser(userid string, displayname string, emailid string) (*model.ObjectUser, error) {
@@ -70,21 +72,21 @@ func (ro *ObjectOperation) ObjectUpdateUser(userid string, displayname string, e
return ro.restClient.UpdateObjectUser(objectUser)
}
//Function to delete user on rook object store
//ObjectDeleteUser Function to delete user on rook object store
//Input paramatres - userId
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectDeleteUser(userid string) error {
return ro.restClient.DeleteObjectUser(userid)
}
//Function to get a user on rook object store
//ObjectGetUser Function to get a user on rook object store
//Input paramatres - userId
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectGetUser(userid string) (*model.ObjectUser, error) {
return ro.restClient.GetObjectUser(userid)
}
//Function to get all users on rook object store
//ObjectListUser Function to get all users on rook object store
//Input paramatres - none
//Output - output returned by rook Rest API client
func (ro *ObjectOperation) ObjectListUser() ([]model.ObjectUser, error) {
+4
View File
@@ -21,19 +21,23 @@ import (
"github.com/rook/rook/tests/framework/contracts"
)
//PoolClient is a wrapper for rook pool operations
type PoolClient struct {
transportClient contracts.ITransportClient
restClient contracts.RestAPIOperator
}
//CreatePoolClient creates a new pool client
func CreatePoolClient(rookRestClient contracts.RestAPIOperator) *PoolClient {
return &PoolClient{restClient: rookRestClient}
}
//PoolList returns all pools in rook
func (rp *PoolClient) PoolList() ([]model.Pool, error) {
return rp.restClient.GetPools()
}
//PoolCreate creates new pool
func (rp *PoolClient) PoolCreate(pool model.Pool) (string, error) {
return rp.restClient.CreatePool(pool)
}
+39 -4
View File
@@ -31,11 +31,12 @@ import (
"github.com/rook/rook/tests/framework/utils"
)
//RestAPIClient is wrapper for rook rest api client
type RestAPIClient struct {
rrc *rclient.RookNetworkRestClient
}
//Create Rook REST API client
//CreateRestAPIClient Create Rook REST API client
func CreateRestAPIClient(platform enums.RookPlatformType) *RestAPIClient {
var endpoint string
switch {
@@ -50,11 +51,11 @@ func CreateRestAPIClient(platform enums.RookPlatformType) *RestAPIClient {
panic(fmt.Errorf("failed to kubectl create %v: %+v", path, err))
}
}
apiIp, err := rkh.GetPodHostId("rook-api", "rook")
apiIP, err := rkh.GetPodHostID("rook-api", "rook")
if err != nil {
panic(fmt.Errorf("Host Ip for Rook-api service not found. %+v", err))
}
endpoint = "http://" + apiIp + ":30002"
endpoint = "http://" + apiIP + ":30002"
case platform == enums.StandAlone:
endpoint = "http://localhost:8124"
default:
@@ -78,69 +79,103 @@ func CreateRestAPIClient(platform enums.RookPlatformType) *RestAPIClient {
return &RestAPIClient{client}
}
//URL returns URL for rookAPI
func (a *RestAPIClient) URL() string {
return a.rrc.RestURL
}
//GetNodes returns all rook nodes
func (a *RestAPIClient) GetNodes() ([]model.Node, error) {
return a.rrc.GetNodes()
}
//GetPools returns all pools in rook
func (a *RestAPIClient) GetPools() ([]model.Pool, error) {
return a.rrc.GetPools()
}
//CreatePool creates a new pool
func (a *RestAPIClient) CreatePool(pool model.Pool) (string, error) {
return a.rrc.CreatePool(pool)
}
//GetBlockImages returns list of a block images
func (a *RestAPIClient) GetBlockImages() ([]model.BlockImage, error) {
return a.rrc.GetBlockImages()
}
//CreateBlockImage creates a new block image in rook
func (a *RestAPIClient) CreateBlockImage(image model.BlockImage) (string, error) {
return a.rrc.CreateBlockImage(image)
}
//DeleteBlockImage deletes a block image from rook
func (a *RestAPIClient) DeleteBlockImage(image model.BlockImage) (string, error) {
return a.rrc.DeleteBlockImage(image)
}
//GetClientAccessInfo returns rook REST API client info
func (a *RestAPIClient) GetClientAccessInfo() (model.ClientAccessInfo, error) {
return a.rrc.GetClientAccessInfo()
}
//GetFilesystems returns rook filesystem
func (a *RestAPIClient) GetFilesystems() ([]model.Filesystem, error) {
return a.rrc.GetFilesystems()
}
//CreateFilesystem creates file system on rook
func (a *RestAPIClient) CreateFilesystem(fsmodel model.FilesystemRequest) (string, error) {
return a.rrc.CreateFilesystem(fsmodel)
}
//DeleteFilesystem deletes file system from rook
func (a *RestAPIClient) DeleteFilesystem(fsmodel model.FilesystemRequest) (string, error) {
return a.rrc.DeleteFilesystem(fsmodel)
}
//GetStatusDetails retuns rook status details
func (a *RestAPIClient) GetStatusDetails() (model.StatusDetails, error) {
return a.rrc.GetStatusDetails()
}
//CreateObjectStore creates object store
func (a *RestAPIClient) CreateObjectStore() (string, error) {
return a.rrc.CreateObjectStore()
}
//GetObjectStoreConnectionInfo returns object store connection info
func (a *RestAPIClient) GetObjectStoreConnectionInfo() (*model.ObjectStoreConnectInfo, error) {
return a.rrc.GetObjectStoreConnectionInfo()
}
//ListBuckets lists all buckets in object store
func (a *RestAPIClient) ListBuckets() ([]model.ObjectBucket, error) {
return a.rrc.ListBuckets()
}
//ListObjectUsers returns all object store users
func (a *RestAPIClient) ListObjectUsers() ([]model.ObjectUser, error) {
return a.rrc.ListObjectUsers()
}
//GetObjectUser returns a object user from object store
func (a *RestAPIClient) GetObjectUser(id string) (*model.ObjectUser, error) {
return a.rrc.GetObjectUser(id)
}
//CreateObjectUser creates new user in object store
func (a *RestAPIClient) CreateObjectUser(user model.ObjectUser) (*model.ObjectUser, error) {
return a.rrc.CreateObjectUser(user)
}
//UpdateObjectUser updates user in object store
func (a *RestAPIClient) UpdateObjectUser(user model.ObjectUser) (*model.ObjectUser, error) {
return a.rrc.UpdateObjectUser(user)
}
//DeleteObjectUser deletes user from object store
func (a *RestAPIClient) DeleteObjectUser(id string) error {
return a.rrc.DeleteObjectUser(id)
+32 -21
View File
@@ -26,9 +26,10 @@ import (
)
var (
VERSION_CMD = []string{"rook", "version"}
versionCmd = []string{"rook", "version"}
)
//TestClient is a wrapper for test client, containing interfaces for all rook operations
type TestClient struct {
platform enums.RookPlatformType
transportClient contracts.ITransportClient
@@ -40,30 +41,31 @@ type TestClient struct {
}
const (
unable_to_check_rook_status_msg = "Unable to check rook status - please check of rook is up and running"
unableToCheckRookStatusMsg = "Unable to check rook status - please check of rook is up and running"
)
//CreateTestClient creates new instance of test client for a platform
func CreateTestClient(platform enums.RookPlatformType) (*TestClient, error) {
var transportClient contracts.ITransportClient
var block_client contracts.BlockOperator
var fs_client contracts.FileSystemOperator
var object_client contracts.ObjectOperator
var pool_client contracts.PoolOperator
var blockClient contracts.BlockOperator
var fsClient contracts.FileSystemOperator
var objectClient contracts.ObjectOperator
var poolClient contracts.PoolOperator
rookRestClient := CreateRestAPIClient(platform)
switch {
case platform == enums.Kubernetes:
transportClient = transport.CreateNewk8sTransportClient()
block_client = CreateK8BlockOperation(transportClient, rookRestClient)
fs_client = CreateK8sFileSystemOperation(transportClient, rookRestClient)
object_client = CreateObjectOperation(rookRestClient)
pool_client = CreatePoolClient(rookRestClient)
blockClient = CreateK8BlockOperation(transportClient, rookRestClient)
fsClient = CreateK8sFileSystemOperation(transportClient, rookRestClient)
objectClient = CreateObjectOperation(rookRestClient)
poolClient = CreatePoolClient(rookRestClient)
case platform == enums.StandAlone:
transportClient = nil //TODO- Not yet implemented
block_client = nil //TODO- Not yet implemented
fs_client = nil //TODO- Not yet implemented
object_client = nil //TODO- Not yet implemented
pool_client = nil //TODO- Not yet implemented
blockClient = nil //TODO- Not yet implemented
fsClient = nil //TODO- Not yet implemented
objectClient = nil //TODO- Not yet implemented
poolClient = nil //TODO- Not yet implemented
default:
return &TestClient{}, fmt.Errorf("Unsupported Rook Platform Type")
}
@@ -71,52 +73,61 @@ func CreateTestClient(platform enums.RookPlatformType) (*TestClient, error) {
return &TestClient{
platform,
transportClient,
block_client,
fs_client,
object_client,
pool_client,
blockClient,
fsClient,
objectClient,
poolClient,
rookRestClient,
}, nil
}
//Status returns rook status details
func (c TestClient) Status() (model.StatusDetails, error) {
return c.restClient.GetStatusDetails()
}
//Version returns rook version installed
func (c TestClient) Version() (string, error) {
out, err, status := c.transportClient.Execute(VERSION_CMD, nil)
out, err, status := c.transportClient.Execute(versionCmd, nil)
if status == 0 {
return out, nil
} else {
return err, fmt.Errorf(unable_to_check_rook_status_msg)
}
return err, fmt.Errorf(unableToCheckRookStatusMsg)
}
//Node returns list of rook nodes
func (c TestClient) Node() ([]model.Node, error) {
return c.restClient.GetNodes()
}
//GetTransportClient returns transport client for platform in context
func (c TestClient) GetTransportClient() contracts.ITransportClient {
return c.transportClient
}
//GetBlockClient returns Block client for platform in context
func (c TestClient) GetBlockClient() contracts.BlockOperator {
return c.blockClient
}
//GetFileSystemClient returns fileSystem client for platform in context
func (c TestClient) GetFileSystemClient() contracts.FileSystemOperator {
return c.fsClient
}
//GetObjectClient returns Object client for platform in context
func (c TestClient) GetObjectClient() contracts.ObjectOperator {
return c.objectClient
}
//GetPoolClient returns pool client for platform in context
func (c TestClient) GetPoolClient() contracts.PoolOperator {
return c.poolClient
}
//GetRestAPIClient returns RestAPI client for platform in context
func (c TestClient) GetRestAPIClient() contracts.RestAPIOperator {
return c.restClient
}
@@ -16,6 +16,7 @@ limitations under the License.
package contracts
//IDockerClient is a interface for docker commands
type IDockerClient interface {
Execute(cmd []string) (stdout string, stderr string, err error)
Stop(cmd []string) (stdout string, stderr string, err error)
@@ -16,6 +16,7 @@ limitations under the License.
package contracts
//ITransportClient is interface for rook commands on different platforms
type ITransportClient interface {
Execute(cmd []string, optional []string) (stdout string, stderr string, exitCode int)
Create(cmd []string, optional []string) (stdout string, stderr string, exitCode int)
+5
View File
@@ -18,6 +18,7 @@ package contracts
import "github.com/rook/rook/pkg/model"
//BlockOperator - interface for rook block operations
type BlockOperator interface {
BlockCreate(name string, size int) (string, error)
BlockDelete(name string) (string, error)
@@ -28,6 +29,7 @@ type BlockOperator interface {
BlockUnmap(name string, mountpath string) (string, error)
}
//FileSystemOperator - interface for rook fileSystem operations
type FileSystemOperator interface {
FSCreate(name string) (string, error)
FSDelete(name string) (string, error)
@@ -38,6 +40,7 @@ type FileSystemOperator interface {
FSUnmount(mountpath string) (string, error)
}
//ObjectOperator - interface for rook object operations
type ObjectOperator interface {
ObjectCreate() (string, error)
ObjectBucketList() ([]model.ObjectBucket, error)
@@ -49,11 +52,13 @@ type ObjectOperator interface {
ObjectListUser() ([]model.ObjectUser, error)
}
//PoolOperator - interface for rook pool operations
type PoolOperator interface {
PoolList() ([]model.Pool, error)
PoolCreate(pool model.Pool) (string, error)
}
//RestAPIOperator - interface for rook rest API operations
type RestAPIOperator interface {
URL() string
GetNodes() ([]model.Node, error)
@@ -21,17 +21,27 @@ import (
"strings"
)
//DockerSubCommand is enum of docker commands
type DockerSubCommand int
const (
//Exec docker command
Exec DockerSubCommand = iota + 1
//Run docker command
Run
//Copy docker command
Copy
//Ps docker command
Ps
//Pull docker command
Pull
//Save docker command
Save
//Kill docker command
Kill
//Rm docker command
Rm
//Empty docker command
Empty
)
@@ -51,6 +61,7 @@ func (subCommand DockerSubCommand) String() string {
return dockerSubCommands[subCommand-1]
}
//GetDockerSubCommandFromString returns docker sub command
func GetDockerSubCommandFromString(name string) (DockerSubCommand, error) {
switch {
case strings.EqualFold(name, Exec.String()):
+4
View File
@@ -21,10 +21,13 @@ import (
"strings"
)
//K8sVersion is a enum of k8s versions
type K8sVersion int
const (
//V1dot5 k8s version 1.5
V1dot5 K8sVersion = iota + 1
// V1dot6 k8s version 1.6
V1dot6
)
@@ -38,6 +41,7 @@ func (version K8sVersion) String() string {
return versions[version-1]
}
//GetK8sVersionFromString returns k8s version
func GetK8sVersionFromString(name string) (K8sVersion, error) {
switch {
case strings.EqualFold(name, V1dot6.String()):
@@ -21,12 +21,17 @@ import (
"strings"
)
//RookPlatformType is enum if rook platforms
type RookPlatformType int
const (
//Kubernetes plafrom is default
Kubernetes RookPlatformType = iota + 1
//BareMetal plafrom
BareMetal
//StandAlone plafrom is default
StandAlone
//None platform
None
)
@@ -41,6 +46,7 @@ func (platform RookPlatformType) String() string {
return platforms[platform-1]
}
//GetRookPlatFormTypeFromString returns rook platform type
func GetRookPlatFormTypeFromString(name string) (RookPlatformType, error) {
switch {
case strings.EqualFold(name, Kubernetes.String()):
+47 -32
View File
@@ -24,9 +24,11 @@ import (
"path/filepath"
"time"
"github.com/coreos/pkg/capnslog"
"github.com/rook/rook/tests/framework/contracts"
"github.com/rook/rook/tests/framework/transport"
"github.com/rook/rook/tests/framework/utils"
"strings"
)
const (
@@ -34,27 +36,36 @@ const (
rookClusterFileName = "rook-cluster.yaml"
rookToolsFileName = "rook-tools.yaml"
podSpecPath = "src/github.com/rook/rook/demo/kubernetes"
podSpecPath1_5 = "src/github.com/rook/rook/demo/kubernetes/1.5"
rookOperatorCreatedTpr = "cluster.rook.io"
)
var (
r *InstallHelper
once Once
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
}
func getPodSpecPath() string {
return filepath.Join(os.Getenv("GOPATH"), podSpecPath)
func getPodSpecPath(k8sverion string) string {
switch k8sverion {
case "v1.5":
return filepath.Join(os.Getenv("GOPATH"), podSpecPath1_5)
default:
return filepath.Join(os.Getenv("GOPATH"), podSpecPath)
}
}
//method for create rook-operator via kubectl
func (h *InstallHelper) createK8sRookOperator(k8sHelper *utils.K8sHelper) error {
func (h *InstallHelper) createK8sRookOperator(k8sHelper *utils.K8sHelper, k8sversion string) error {
logger.Infof("Starting Rook Operator")
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(), rookOperatorFileName))
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(k8sversion), rookOperatorFileName))
if err != nil {
return err
@@ -67,20 +78,19 @@ func (h *InstallHelper) createK8sRookOperator(k8sHelper *utils.K8sHelper) error
return fmt.Errorf(string("Failed to create rook-operator pod; kubectl exit code = " + string(exitCode)))
}
fmt.Println()
if !k8sHelper.IsThirdPartyResourcePresent(rookOperatorCreatedTpr) {
return fmt.Errorf("Failed to start Rook Operator; k8s thirdpartyresource did not appear")
} else {
fmt.Println("Rook Operator started")
}
logger.Infof("Rook Operator started")
return nil
}
func (h *InstallHelper) createK8sRookToolbox(k8sHelper *utils.K8sHelper) (err error) {
func (h *InstallHelper) createK8sRookToolbox(k8sHelper *utils.K8sHelper, k8sversion string) (err error) {
logger.Infof("Starting Rook toolbox")
//Create rook toolbox
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(), rookToolsFileName))
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(k8sversion), rookToolsFileName))
if err != nil {
panic(err)
@@ -96,16 +106,16 @@ func (h *InstallHelper) createK8sRookToolbox(k8sHelper *utils.K8sHelper) (err er
if !k8sHelper.IsPodRunningInNamespace("rook-tools") {
return fmt.Errorf("Rook Toolbox couldn't start")
} else {
fmt.Println("Rook Toolbox started")
}
logger.Infof("Rook Toolbox started")
return nil
}
func (h *InstallHelper) createk8sRookCluster(k8sHelper *utils.K8sHelper) error {
func (h *InstallHelper) createk8sRookCluster(k8sHelper *utils.K8sHelper, k8sversion string) error {
logger.Infof("Starting Rook Cluster")
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(), rookClusterFileName))
raw, err := ioutil.ReadFile(path.Join(getPodSpecPath(k8sversion), rookClusterFileName))
if err != nil {
return err
@@ -119,15 +129,16 @@ func (h *InstallHelper) createk8sRookCluster(k8sHelper *utils.K8sHelper) error {
}
if !k8sHelper.IsServiceUpInNameSpace("rook-api") {
fmt.Println("Rook Cluster couldn't start")
logger.Infof("Rook Cluster couldn't start")
} else {
fmt.Println("Rook Cluster started")
logger.Infof("Rook Cluster started")
}
return nil
}
func (h *InstallHelper) InstallRookOnK8s() (err error) {
//InstallRookOnK8s installs rook on k8s
func (h *InstallHelper) InstallRookOnK8s(k8sversion string) (err error) {
if h.isRookInstalled {
return
}
@@ -135,7 +146,7 @@ func (h *InstallHelper) InstallRookOnK8s() (err error) {
//Create rook operator
k8sHelp := utils.CreatK8sHelper()
err = h.createK8sRookOperator(k8sHelp)
err = h.createK8sRookOperator(k8sHelp, k8sversion)
if err != nil {
panic(err)
}
@@ -143,7 +154,7 @@ func (h *InstallHelper) InstallRookOnK8s() (err error) {
time.Sleep(10 * time.Second) ///TODO: add real check here
//Create rook cluster
err = h.createk8sRookCluster(k8sHelp)
err = h.createk8sRookCluster(k8sHelp, k8sversion)
if err != nil {
panic(err)
}
@@ -151,7 +162,7 @@ func (h *InstallHelper) InstallRookOnK8s() (err error) {
time.Sleep(5 * time.Second)
//Create rook client
err = h.createK8sRookToolbox(k8sHelp)
err = h.createK8sRookToolbox(k8sHelp, k8sversion)
if err != nil {
panic(err)
}
@@ -161,11 +172,12 @@ func (h *InstallHelper) InstallRookOnK8s() (err error) {
return nil
}
func (h *InstallHelper) UninstallRookFromK8s() {
//UninstallRookFromK8s uninstalls rook from k8s
func (h *InstallHelper) UninstallRookFromK8s(k8sversion string) {
logger.Infof("Uninstalling Rook")
k8sHelp := utils.CreatK8sHelper()
var err error
_, err = k8sHelp.ResourceOperation("delete", path.Join(getPodSpecPath(), rookOperatorFileName))
_, err = k8sHelp.ResourceOperation("delete", path.Join(getPodSpecPath(k8sversion), rookOperatorFileName))
if err != nil {
panic(err)
}
@@ -177,13 +189,15 @@ func (h *InstallHelper) UninstallRookFromK8s() {
if err != nil {
panic(err)
}
_, err = k8sHelp.DeleteResource([]string{"clusterrole", "rook-api"})
if err != nil {
panic(err)
}
_, err = k8sHelp.DeleteResource([]string{"clusterrolebinding", "rook-api"})
if err != nil {
panic(err)
if !strings.EqualFold(k8sversion, "v1.5") {
_, err = k8sHelp.DeleteResource([]string{"clusterrole", "rook-api"})
if err != nil {
panic(err)
}
_, err = k8sHelp.DeleteResource([]string{"clusterrolebinding", "rook-api"})
if err != nil {
panic(err)
}
}
_, err = k8sHelp.DeleteResource([]string{"thirdpartyresources", "cluster.rook.io", "pool.rook.io"})
if err != nil {
@@ -201,13 +215,14 @@ func (h *InstallHelper) UninstallRookFromK8s() {
isRookUninstalled := k8sHelp.WaitUntilPodInNamespaceIsDeleted("rook-ceph-mon", "rook")
if isRookUninstalled {
fmt.Println("Rook uninstalled successfully")
logger.Infof("Rook uninstalled successfully")
once.Reset()
return
}
panic(fmt.Errorf("Rook not uninstalled"))
}
//NewK8sRookhelper creates new instance of InstallHelper
func NewK8sRookhelper() (*InstallHelper, error) {
transportClient := transport.CreateNewk8sTransportClient()
+1 -1
View File
@@ -27,7 +27,7 @@ type Once struct {
done uint32
}
//simulate sync.Once.Do by executing function only once
//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()) {
+2
View File
@@ -16,6 +16,7 @@ limitations under the License.
package objects
// CommandArgs is a warpper for cmd args
type CommandArgs struct {
Command string
SubCommand string
@@ -25,6 +26,7 @@ type CommandArgs struct {
EnvironmentVariable []string
}
//CommandOut is a wrapper for cmd out returned after executing command args
type CommandOut struct {
StdOut string
StdErr string
+12 -7
View File
@@ -18,25 +18,30 @@ package objects
import "github.com/rook/rook/tests/framework/contracts"
//DockerContext is wrapperr for docker client
type DockerContext struct {
containerId string
containerID string
dockerClient contracts.IDockerClient
}
//SetDockerContext function sets docker context instance
func SetDockerContext(dockerClient contracts.IDockerClient) DockerContext {
return DockerContext{dockerClient: dockerClient}
}
func (d *DockerContext) Get_ContainerId() string {
return d.containerId
//GetContainerID gets container Id from dockerContext instance
func (d *DockerContext) GetContainerID() string {
return d.containerID
}
func (d *DockerContext) Set_ContainerId(containerId string) string {
d.containerId = containerId
//SetContainerID sets container Id on dockerContext instance
func (d *DockerContext) SetContainerID(containerID string) string {
d.containerID = containerID
return containerId
return containerID
}
func (d *DockerContext) Get_DockerClient() contracts.IDockerClient {
//GetDockerClient returns docker client instance
func (d *DockerContext) GetDockerClient() contracts.IDockerClient {
return d.dockerClient
}
@@ -20,6 +20,7 @@ import (
"flag"
)
//EnvironmentManifest contains informaton about system under test
type EnvironmentManifest struct {
K8sVersion string
Platform string
@@ -29,6 +30,7 @@ type EnvironmentManifest struct {
LoadConcurrentRuns int
}
//NewManifest creates a new instance of EnvironmentManifest
func NewManifest() EnvironmentManifest {
e := EnvironmentManifest{}
@@ -24,33 +24,30 @@ type dockerClient struct {
env []string
}
const docker_executable = "docker"
func CreateDockerClient(dockerEnv []string) *dockerClient {
return &dockerClient{env: dockerEnv}
}
const dockerExecutable = "docker"
// TODO remove this file : unused.
func (k *dockerClient) Execute(cmdArgs []string) (stdout string, stderr string, err error) {
initialArgs := []string{"exec"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmdAndLogToConsole(docker_executable, cmdArgs, k.env)
return utils.ExecuteCmdAndLogToConsole(dockerExecutable, cmdArgs, k.env)
}
func (k *dockerClient) Run(cmdArgs []string) (stdout string, stderr string, err error) {
initialArgs := []string{"run"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmdAndLogToConsole(docker_executable, cmdArgs, k.env)
return utils.ExecuteCmdAndLogToConsole(dockerExecutable, cmdArgs, k.env)
}
func (k *dockerClient) Stop(cmdArgs []string) (stdout string, stderr string, err error) {
initialArgs := []string{"stop"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmdAndLogToConsole(docker_executable, cmdArgs, k.env)
return utils.ExecuteCmdAndLogToConsole(dockerExecutable, cmdArgs, k.env)
}
func (k *dockerClient) ExecuteCmd(cmdArgs []string) (stdout string, stderr string, err error) {
return utils.ExecuteCmdAndLogToConsole(docker_executable, cmdArgs, k.env)
return utils.ExecuteCmdAndLogToConsole(dockerExecutable, cmdArgs, k.env)
}
@@ -21,29 +21,34 @@ import (
"github.com/rook/rook/tests/framework/utils"
)
type k8sTransportClient struct {
//K8sTransportClient is struct for perform kubectl operations on args
type K8sTransportClient struct {
}
func CreateNewk8sTransportClient() *k8sTransportClient {
return &k8sTransportClient{}
//CreateNewk8sTransportClient creates new instance of transport interface for k8s
func CreateNewk8sTransportClient() *K8sTransportClient {
return &K8sTransportClient{}
}
const (
kubectl_executable = "kubectl"
kubectlExecutable = "kubectl"
)
func (k *k8sTransportClient) ExecuteCmd(cmd []string) (stdout string, stderr string, err error) {
return utils.ExecuteCmdAndLogToConsole(kubectl_executable, cmd, []string{})
//ExecuteCmd executes kubectl commands
func (k *K8sTransportClient) ExecuteCmd(cmd []string) (stdout string, stderr string, err error) {
return utils.ExecuteCmdAndLogToConsole(kubectlExecutable, cmd, []string{})
}
func (k *k8sTransportClient) Apply(cmdArgs []string) (stdout string, stderr string, err error) {
//Apply executes kubectl apply commands
func (k *K8sTransportClient) Apply(cmdArgs []string) (stdout string, stderr string, err error) {
initialArgs := []string{"replace", "--force", "-f"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmdAndLogToConsole("kubectl", cmdArgs, []string{})
}
func (k *k8sTransportClient) Execute(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
//Execute executes kubectl commands
func (k *K8sTransportClient) Execute(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
if optional != nil {
if len(optional) == 1 {
@@ -60,26 +65,29 @@ func (k *k8sTransportClient) Execute(cmdArgs []string, optional []string) (stdou
cmdArgs = append(initialArgs, cmdArgs...)
}
return utils.ExecuteCmd(kubectl_executable, cmdArgs)
return utils.ExecuteCmd(kubectlExecutable, cmdArgs)
}
func (k *k8sTransportClient) CreateWithStdin(stdinText string) (stdout string, stderr string, exitCode int) {
cmdStruct := objects.CommandArgs{Command: kubectl_executable, PipeToStdIn: stdinText, CmdArgs: []string{"create", "-f", "-"}}
//CreateWithStdin executes kubectl create commands and logs output
func (k *K8sTransportClient) CreateWithStdin(stdinText string) (stdout string, stderr string, exitCode int) {
cmdStruct := objects.CommandArgs{Command: kubectlExecutable, PipeToStdIn: stdinText, CmdArgs: []string{"create", "-f", "-"}}
cmdOut := utils.ExecuteCommand(cmdStruct)
return cmdOut.StdOut, cmdOut.StdErr, cmdOut.ExitCode
}
func (k *k8sTransportClient) Create(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
//Create executes kubectl create commands
func (k *K8sTransportClient) Create(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
initialArgs := []string{"create", "-f"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmd(kubectl_executable, cmdArgs)
return utils.ExecuteCmd(kubectlExecutable, cmdArgs)
}
func (k *k8sTransportClient) Delete(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
//Delete executes kubectl delete commands
func (k *K8sTransportClient) Delete(cmdArgs []string, optional []string) (stdout string, stderr string, exitCode int) {
initialArgs := []string{"delete", "-f"}
cmdArgs = append(initialArgs, cmdArgs...)
return utils.ExecuteCmd(kubectl_executable, cmdArgs)
return utils.ExecuteCmd(kubectlExecutable, cmdArgs)
}
+3 -32
View File
@@ -28,6 +28,7 @@ import (
"github.com/rook/rook/tests/framework/objects"
)
//ExecuteCommand executes a os command and returs output
func ExecuteCommand(cmdStruct objects.CommandArgs) objects.CommandOut {
var outBuffer, errBuffer bytes.Buffer
@@ -103,37 +104,7 @@ func ExecuteCommand(cmdStruct objects.CommandArgs) objects.CommandOut {
return objects.CommandOut{StdErr: errBuffer.String(), StdOut: outBuffer.String(), Err: err}
}
func ExecuteCmdWithEnv(Cmd string, cmdArgs []string, env []string) (stdout string, stderr string, exitCode int) {
var outbuf, errbuf bytes.Buffer
cmd := exec.Command(Cmd, strings.Join(cmdArgs, " "))
cmd.Env = append(cmd.Env, env...)
cmd.Stdout = &outbuf
cmd.Stderr = &errbuf
err := cmd.Run()
stdout = outbuf.String()
stderr = errbuf.String()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
exitCode = ws.ExitStatus()
} else {
exitCode = 1
if stderr == "" {
stderr = err.Error() + stdout
}
}
} else {
ws := cmd.ProcessState.Sys().(syscall.WaitStatus)
exitCode = ws.ExitStatus()
}
return
}
//ExecuteCmd functions executes a command returs status,stdout and stderror
func ExecuteCmd(Cmd string, cmdArgs []string) (stdout string, stderr string, exitCode int) {
var outbuf, errbuf bytes.Buffer
@@ -162,7 +133,7 @@ func ExecuteCmd(Cmd string, cmdArgs []string) (stdout string, stderr string, exi
return
}
//TODO add timeout parameter
//ExecuteCmdAndLogToConsole functions executes a command returs status,stdout and stderror and logs output to console
func ExecuteCmdAndLogToConsole(command string, cmdArgs []string, cmdEnv []string) (stdout string, stderr string, err error) {
var outbuf, errbuf bytes.Buffer
+93 -33
View File
@@ -26,16 +26,35 @@ import (
"strings"
"time"
"github.com/coreos/pkg/capnslog"
"github.com/jmoiron/jsonq"
"github.com/rook/rook/pkg/util/exec"
)
//K8sHelper is a helper for common kubectl commads
type K8sHelper struct {
executor *exec.CommandExecutor
}
//CreatK8sHelper creates a instance of k8sHelper
func CreatK8sHelper() *K8sHelper {
return &K8sHelper{}
return &K8sHelper{&exec.CommandExecutor{}}
}
var k8slogger = capnslog.NewPackageLogger("github.com/rook/rook", "k8sutil")
//Kubectl is wrapper for executing kubectl commands
func (k8sh *K8sHelper) Kubectl(args ...string) string {
result, error := k8sh.executor.ExecuteCommandWithOutput("", "kubectl", args...)
if error != nil {
k8slogger.Errorf("Errors Encounterd while executing kubectl command : %v", error)
panic(error)
}
return result
}
//GetMonIP returns IP address for a ceph mon pod
func (k8sh *K8sHelper) GetMonIP(mon string) (string, error) {
//kubectl -n rook get pod mon0 -o json|jq ".status.podIP"|
cmdArgs := []string{"-n", "rook", "get", "pod", mon, "-o", "json"}
@@ -47,11 +66,11 @@ func (k8sh *K8sHelper) GetMonIP(mon string) (string, error) {
jq := jsonq.NewQuery(data)
ip, _ := jq.String("status", "podIP")
return ip + ":6790", nil
} else {
return err, fmt.Errorf("Error Getting Monitor IP")
}
return err, fmt.Errorf("Error Getting Monitor IP")
}
//ResourceOperationFromTemplate performs a kubectl action from a template file after replacing its context
func (k8sh *K8sHelper) ResourceOperationFromTemplate(action string, poddefPath string, config map[string]string) (string, error) {
t, _ := template.ParseFiles(poddefPath)
@@ -63,43 +82,46 @@ func (k8sh *K8sHelper) ResourceOperationFromTemplate(action string, poddefPath s
stdout, stderr, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
return stdout, nil
} else {
return stdout + " : " + stderr, fmt.Errorf("Could Not create resource in k8s. status=%d, stdout=%s, stderr=%s", status, stdout, stderr)
}
return stdout + " : " + stderr, fmt.Errorf("Could Not create resource in k8s. status=%d, stdout=%s, stderr=%s", status, stdout, stderr)
}
//ResourceOperation performs a kubectl action on a yaml file
func (k8sh *K8sHelper) ResourceOperation(action string, poddefPath string) (string, error) {
cmdArgs := []string{action, "-f", poddefPath}
out, err, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
return out, nil
} else {
return out + " : " + err, fmt.Errorf("Could Not create resource in k8s")
}
return out + " : " + err, fmt.Errorf("Could Not create resource in k8s")
}
func (K8sh *K8sHelper) DeleteResource(args []string) (string, error) {
//DeleteResource performs a kubectl delete on give args
func (k8sh *K8sHelper) DeleteResource(args []string) (string, error) {
cmdArgs := append([]string{"delete"}, args...)
out, err, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
return out, nil
} else {
return out + " : " + err, fmt.Errorf("Could Not delete resource in k8s")
}
return out + " : " + err, fmt.Errorf("Could Not delete resource in k8s")
}
func (K8sh *K8sHelper) GetResource(args []string) (string, error) {
//GetResource performs a kubectl get on give args
func (k8sh *K8sHelper) GetResource(args []string) (string, error) {
cmdArgs := append([]string{"get"}, args...)
out, err, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
return out, nil
} else {
return out + " : " + err, fmt.Errorf("Could Not Get resource in k8s")
}
return out + " : " + err, fmt.Errorf("Could Not Get resource in k8s")
}
//GetMonitorPods returns all ceph mon pod names
func (k8sh *K8sHelper) GetMonitorPods() ([]string, error) {
mons := []string{}
monIdx := 0
@@ -130,6 +152,7 @@ func (k8sh *K8sHelper) GetMonitorPods() ([]string, error) {
return mons, nil
}
//IsPodRunning retuns true if a Pod is running status or goes to Running status within 90s else returns false
func (k8sh *K8sHelper) IsPodRunning(name string) bool {
cmdArgs := []string{"get", "pod", name}
inc := 0
@@ -157,6 +180,9 @@ func (k8sh *K8sHelper) IsPodRunning(name string) bool {
}
return false
}
//IsPodRunningInNamespace retuns true if a Pod in a namespace is running status or goes to Running
// status within 90s else returns false
func (k8sh *K8sHelper) IsPodRunningInNamespace(name string) bool {
cmdArgs := []string{"get", "pods", "-n", "rook", name}
inc := 0
@@ -185,59 +211,63 @@ func (k8sh *K8sHelper) IsPodRunningInNamespace(name string) bool {
return false
}
//TODO: Combine these like functions
//IsPodTerminated retuns true if a Pod is terminated status or goes to Terminated status
// within 90s else returns false\
func (k8sh *K8sHelper) IsPodTerminated(name string) bool {
cmdArgs := []string{"get", "pods", name}
inc := 0
for inc < 20 {
_, _, status := ExecuteCmd("kubectl", cmdArgs)
if status != 0 {
fmt.Println("Pod in default namespace terminated: " + name)
k8slogger.Infof("Pod in default namespace terminated: " + name)
return true
}
time.Sleep(5 * time.Second)
inc++
}
fmt.Println("Pod in default namespace did not terminated: " + name)
k8slogger.Infof("Pod in default namespace did not terminated: " + name)
return false
}
//TODO: Combine these like functions
//IsPodTerminatedInNamespace retuns true if a Pod in a namespace is terminated status
// or goes to Terminated status within 90s else returns false\
func (k8sh *K8sHelper) IsPodTerminatedInNamespace(name string) bool {
cmdArgs := []string{"get", "-n", "rook", "pods", name}
inc := 0
for inc < 20 {
_, _, status := ExecuteCmd("kubectl", cmdArgs)
if status != 0 {
fmt.Println("Pod in rook namespace terminated: " + name)
k8slogger.Infof("Pod in rook namespace terminated: " + name)
return true
}
time.Sleep(5 * time.Second)
inc++
}
fmt.Println("Pod in rook namespace did not terminated: " + name)
k8slogger.Infof("Pod in rook namespace did not terminated: " + name)
return false
}
//IsServiceUp returns true if a service is up or comes up within 40s, else returns false
func (k8sh *K8sHelper) IsServiceUp(name string) bool {
cmdArgs := []string{"get", "svc", name}
inc := 0
for inc < 20 {
_, _, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
fmt.Println("Service in default namespace is up: " + name)
k8slogger.Infof("Service in default namespace is up: " + name)
return true
}
time.Sleep(2 * time.Second)
inc++
}
fmt.Println("Service in default namespace is not up: " + name)
k8slogger.Infof("Service in default namespace is not up: " + name)
return false
}
//IsServiceUpInNameSpace returns true if a service in a namespace is up or comes up within 40s, else returns false
func (k8sh *K8sHelper) IsServiceUpInNameSpace(name string) bool {
cmdArgs := []string{"get", "svc", "-n", "rook", name}
@@ -251,10 +281,11 @@ func (k8sh *K8sHelper) IsServiceUpInNameSpace(name string) bool {
inc++
}
fmt.Println("Service in rook namespace is not up: " + name)
k8slogger.Infof("Service in rook namespace is not up: " + name)
return false
}
//GetService returns output from "kubectl get svc $NAME" command
func (k8sh *K8sHelper) GetService(servicename string) (string, error) {
cmdArgs := []string{"get", "svc", "-n", "rook", servicename}
sout, serr, status := ExecuteCmd("kubectl", cmdArgs)
@@ -264,6 +295,7 @@ func (k8sh *K8sHelper) GetService(servicename string) (string, error) {
return sout, nil
}
//IsThirdPartyResourcePresent returns true if Third party resource is present
func (k8sh *K8sHelper) IsThirdPartyResourcePresent(tprname string) bool {
cmdArgs := []string{"get", "thirdpartyresources", tprname}
@@ -271,7 +303,7 @@ func (k8sh *K8sHelper) IsThirdPartyResourcePresent(tprname string) bool {
for inc < 20 {
_, _, exitCode := ExecuteCmd("kubectl", cmdArgs)
if exitCode == 0 {
fmt.Println("Found the thirdparty resource: " + tprname)
k8slogger.Infof("Found the thirdparty resource: " + tprname)
return true
}
time.Sleep(5 * time.Second)
@@ -281,6 +313,7 @@ func (k8sh *K8sHelper) IsThirdPartyResourcePresent(tprname string) bool {
return false
}
//GetPodDetails returns details about a pod
func (k8sh *K8sHelper) GetPodDetails(podNamePattern string, namespace string) (string, error) {
cmdArgs := []string{"get", "pods", "-l", "app=" + podNamePattern, "-o", "wide", "--no-headers=true"}
if namespace != "" {
@@ -293,7 +326,8 @@ func (k8sh *K8sHelper) GetPodDetails(podNamePattern string, namespace string) (s
return sout, nil
}
func (k8sh *K8sHelper) GetPodHostId(podNamePattern string, namespace string) (string, error) {
//GetPodHostID returns HostIP address of a pod
func (k8sh *K8sHelper) GetPodHostID(podNamePattern string, namespace string) (string, error) {
data, err := k8sh.GetPodDetails(podNamePattern, namespace)
if err != nil {
return data, err
@@ -318,13 +352,14 @@ func (k8sh *K8sHelper) GetPodHostId(podNamePattern string, namespace string) (st
}
sout, serr, status := ExecuteCmd("kubectl", cmdArgs)
if status == 0 {
hostIp := strings.Replace(sout, "'", "", -1)
return strings.TrimSpace(hostIp), nil
} else {
return serr, fmt.Errorf("Error Getting Monitor IP")
hostIP := strings.Replace(sout, "'", "", -1)
return strings.TrimSpace(hostIP), nil
}
return serr, fmt.Errorf("Error Getting Monitor IP")
}
//IsStorageClassPresent returns true if storageClass is present, if not false
func (k8sh *K8sHelper) IsStorageClassPresent(name string) (bool, error) {
cmdArgs := []string{"get", "storageclass", "-o", "jsonpath='{.items[*].metadata.name}'"}
sout, serr, _ := ExecuteCmd("kubectl", cmdArgs)
@@ -335,6 +370,7 @@ func (k8sh *K8sHelper) IsStorageClassPresent(name string) (bool, error) {
}
//GetPVCStatus returns status of PVC
func (k8sh *K8sHelper) GetPVCStatus(name string) (string, error) {
cmdArgs := []string{"get", "pvc", "-o", "jsonpath='{.items[*].metadata.name}'"}
sout, serr, _ := ExecuteCmd("kubectl", cmdArgs)
@@ -346,6 +382,8 @@ func (k8sh *K8sHelper) GetPVCStatus(name string) (string, error) {
return "PVC NOT FOUND", fmt.Errorf("PVC %s not found,err->%s", name, serr)
}
//IsPodInExpectedState waits for 90s for a pod to be an expected state
//If the pod is in expected state within 90s true is returned, if not false
func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace string, state string) bool {
cmdArgs := []string{"get", "pods", "-l", "app=" + podNamePattern, "-o", "jsonpath={.items[0].status.phase}", "--no-headers=true"}
if namespace != "" {
@@ -366,8 +404,10 @@ func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace str
return false
}
func (k8sh *K8sHelper) WaitUntilPodInNamespaceIsDeleted(podNamePattern string, namespace string) bool{
args := []string{"-n", namespace, "pods", "-l", "app="+podNamePattern}
//WaitUntilPodInNamespaceIsDeleted waits for 90s for a pod in a namespace to be terminated
//If the pod disappears within 90s true is returned, if not false
func (k8sh *K8sHelper) WaitUntilPodInNamespaceIsDeleted(podNamePattern string, namespace string) bool {
args := []string{"-n", namespace, "pods", "-l", "app=" + podNamePattern}
inc := 0
for inc < 30 {
out, _ := k8sh.GetResource(args)
@@ -382,8 +422,11 @@ func (k8sh *K8sHelper) WaitUntilPodInNamespaceIsDeleted(podNamePattern string, n
return false
}
func (k8sh *K8sHelper) WaitUntilPodIsDeleted(podNamePattern string) bool{
args := []string{ "pods", "-l", "app="+podNamePattern}
//WaitUntilPodIsDeleted waits for 90s for a pod to be terminated
//If the pod disappears within 90s true is returned, if not false
func (k8sh *K8sHelper) WaitUntilPodIsDeleted(podNamePattern string) bool {
args := []string{"pods", "-l", "app=" + podNamePattern}
inc := 0
for inc < 30 {
out, _ := k8sh.GetResource(args)
@@ -395,4 +438,21 @@ func (k8sh *K8sHelper) WaitUntilPodIsDeleted(podNamePattern string) bool{
time.Sleep(3 * time.Second)
}
return false
}
}
//WaitUntilPVCIsBound waits for a PVC to be in bound state for 90 seconds
//if PVC goes to Bound state within 90s True is returned, if not false
func (k8sh *K8sHelper) WaitUntilPVCIsBound(pvcname string) bool {
inc := 0
for inc < 30 {
out, _ := k8sh.GetPVCStatus(pvcname)
if strings.Contains(out, "Bound") {
return true
}
inc++
time.Sleep(3 * time.Second)
}
return false
}
+22 -18
View File
@@ -21,29 +21,34 @@ import (
"math/rand"
"strconv"
"time"
// import mysql driver
_ "github.com/go-sql-driver/mysql"
"github.com/icrowley/fake"
)
type MySqlHelper struct {
//MySQLHelper contains pointer to MySqlDB and wrappers for basic object on mySql database
type MySQLHelper struct {
DB *sql.DB
}
// create a s3 client for specfied endpoint and creds
func CreateNewMySqlHelper(username string, password string, url string, dbname string) *MySqlHelper {
// CreateNewMySQLHelper creates a s3 client for specfied endpoint and creds
func CreateNewMySQLHelper(username string, password string, url string, dbname string) *MySQLHelper {
dataSourceName := username + ":" + password + "@tcp(" + url + ")/" + dbname
db, err := sql.Open("mysql", dataSourceName)
if err != nil {
panic(err)
}
return &MySqlHelper{DB: db}
return &MySQLHelper{DB: db}
}
func (h *MySqlHelper) CloseConnection() {
//CloseConnection function closes mysql connection
func (h *MySQLHelper) CloseConnection() {
h.DB.Close()
}
func (h *MySqlHelper) PingSuccess() bool {
//PingSuccess function is used check connection to a database
func (h *MySQLHelper) PingSuccess() bool {
inc := 0
for inc < 30 {
@@ -59,8 +64,8 @@ func (h *MySqlHelper) PingSuccess() bool {
return false
}
//func create sample Table
func (h *MySqlHelper) CreateTable() sql.Result {
//CreateTable func create sample Table
func (h *MySQLHelper) CreateTable() sql.Result {
result, err := h.DB.Exec("CREATE TABLE LONGHAUL (id int NOT NULL AUTO_INCREMENT,number int,data varchar(32)" +
", PRIMARY KEY (id) )")
if err != nil {
@@ -69,8 +74,8 @@ func (h *MySqlHelper) CreateTable() sql.Result {
return result
}
//Insert Data
func (h *MySqlHelper) InsertRandomData() sql.Result {
//InsertRandomData Inserts random Data into the table
func (h *MySQLHelper) InsertRandomData() sql.Result {
stmtIns, err := h.DB.Prepare("INSERT INTO LONGHAUL (number, data) VALUES ( ?, ? )") // ? = placeholder
if err != nil {
panic(err)
@@ -85,8 +90,8 @@ func (h *MySqlHelper) InsertRandomData() sql.Result {
return result
}
//Get row count
func (h *MySqlHelper) TableRowCount() (count int) {
//TableRowCount gets row count of table
func (h *MySQLHelper) TableRowCount() (count int) {
rows, err := h.DB.Query("SELECT COUNT(*) as count FROM LONGHAUL")
if err != nil {
panic(err)
@@ -101,9 +106,8 @@ func (h *MySqlHelper) TableRowCount() (count int) {
}
//check if table exists
func (h *MySqlHelper) TableExists() bool {
//TableExists checks if a table exists
func (h *MySQLHelper) TableExists() bool {
_, err := h.DB.Query("SELECT 1 FROM LONGHAUL LIMIT 1 ")
if err != nil {
return false
@@ -111,8 +115,8 @@ func (h *MySqlHelper) TableExists() bool {
return true
}
//Delete row
func (h *MySqlHelper) DeleteRandomRow() sql.Result {
//DeleteRandomRow deletes a random row
func (h *MySQLHelper) DeleteRandomRow() sql.Result {
var id int
rows, err := h.DB.Query("SELECT id FROM LONGHAUL ORDER BY RAND() LIMIT 1")
if err != nil {
+20 -4
View File
@@ -24,16 +24,20 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/coreos/pkg/capnslog"
)
//S3Helper contains pointer to s3 client and wrappers for basic object store operations
type S3Helper struct {
s3client *s3.S3
}
// create a s3 client for specfied endpoint and creds
func CreateNewS3Helper(endpoint string, keyId string, keySecret string) *S3Helper {
var s3logger = capnslog.NewPackageLogger("github.com/rook/rook", "s3utils")
creds := credentials.NewStaticCredentials(keyId, keySecret, "")
// CreateNewS3Helper creates a s3 client for specfied endpoint and creds
func CreateNewS3Helper(endpoint string, keyID string, keySecret string) *S3Helper {
creds := credentials.NewStaticCredentials(keyID, keySecret, "")
// create aws s3 config, must use 'us-east-1' default aws region for ceph object store
awsConfig := aws.NewConfig().
@@ -41,7 +45,8 @@ func CreateNewS3Helper(endpoint string, keyId string, keySecret string) *S3Helpe
WithCredentials(creds).
WithEndpoint(endpoint).
WithS3ForcePathStyle(true).
WithDisableSSL(true)
WithDisableSSL(true).
WithMaxRetries(20)
//create new session
ses := session.New()
@@ -52,28 +57,33 @@ func CreateNewS3Helper(endpoint string, keyId string, keySecret string) *S3Helpe
return &S3Helper{c}
}
//CreateBucket function creates bucket using s3 client
func (h *S3Helper) CreateBucket(name string) (bool, error) {
_, err := h.s3client.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(name),
})
if err != nil {
s3logger.Errorf("error encountered while creating bucket : %v", err)
return false, err
}
return true, nil
}
//DeleteBucket function deletes given bucket using s3 client
func (h *S3Helper) DeleteBucket(name string) (bool, error) {
_, err := h.s3client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: aws.String(name),
})
if err != nil {
s3logger.Errorf("error encountered while deleting bucket : %v", err)
return false, err
}
return true, nil
}
//PutObjectInBucket function puts an object in a bucket using s3 client
func (h *S3Helper) PutObjectInBucket(bucketname string, body string, key string,
contentType string) (bool, error) {
_, err := h.s3client.PutObject(&s3.PutObjectInput{
@@ -83,12 +93,14 @@ func (h *S3Helper) PutObjectInBucket(bucketname string, body string, key string,
ContentType: &contentType,
})
if err != nil {
s3logger.Errorf("error encountered while putting object in bucket : %v", err)
return false, err
}
return true, nil
}
//GetObjectInBucket function retrieves an object from a bucket using s3 client
func (h *S3Helper) GetObjectInBucket(bucketname string, key string) (string, error) {
result, err := h.s3client.GetObject(&s3.GetObjectInput{
Bucket: aws.String(bucketname),
@@ -96,6 +108,7 @@ func (h *S3Helper) GetObjectInBucket(bucketname string, key string) (string, err
})
if err != nil {
s3logger.Errorf("error encountered while retrieving object from bucket : %v", err)
return "ERROR_ OBJCET NOT FOUND", err
}
@@ -104,12 +117,15 @@ func (h *S3Helper) GetObjectInBucket(bucketname string, key string) (string, err
return buf.String(), nil
}
//DeleteObjectInBucket function deletes given bucket using s3 client
func (h *S3Helper) DeleteObjectInBucket(bucketname string, key string) (bool, error) {
_, err := h.s3client.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(bucketname),
Key: aws.String(key),
})
if err != nil {
s3logger.Errorf("error encountered while deleting object from bucket : %v", err)
return false, err
}
+1
View File
@@ -23,6 +23,7 @@ copy_rbd() {
for c in kube-master kube-node-1 kube-node-2; do
docker cp ${scriptdir}/dind-cluster-rbd ${c}:/bin/rbd
docker exec ${c} /bin/bash -c "chmod +x /bin/rbd"
docker exec ${c} /bin/bash -c "docker pull ceph/base"
done
}
+40 -37
View File
@@ -20,6 +20,7 @@ import (
"testing"
"time"
"github.com/coreos/pkg/capnslog"
"github.com/rook/rook/tests"
"github.com/rook/rook/tests/framework/enums"
"github.com/stretchr/testify/require"
@@ -32,64 +33,67 @@ func TestRookSmokeSuiteK8s(t *testing.T) {
type SmokeSuite struct {
suite.Suite
helper *SmokeTestHelper
helper *TestHelper
}
func (suite *SmokeSuite) SetupSuite() {
var err error
suite.helper, err = CreateSmokeTestClient(enums.Kubernetes)
suite.helper, err = CreateSmokeTestClient(enums.Kubernetes, tests.Env.K8sVersion)
require.Nil(suite.T(), err)
}
// Smoke Test for Block Storage - Test check the following operations on Block Storage in order
//Create,Mount,Write,Read,Unmount and Delete.
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "smoketest")
func (suite *SmokeSuite) TestBlockStorage_SmokeTest() {
defer suite.blockTestDataCleanUp()
suite.T().Log("Block Storage Smoke Test - Create,Mount,write to, read from and Unmount Block")
logger.Infof("Block Storage Smoke Test - Create,Mount,write to, read from and Unmount Block")
rbc := suite.helper.GetBlockClient()
suite.T().Log("Step 0 : Get Initial List Block")
logger.Infof("Step 0 : Get Initial List Block")
initBlockImages, _ := rbc.BlockList()
suite.T().Log("step 1: Create block storage")
_, cb_err := suite.helper.CreateBlockStorage()
require.Nil(suite.T(), cb_err)
logger.Infof("step 1: Create block storage")
_, cbErr := suite.helper.CreateBlockStorage()
require.Nil(suite.T(), cbErr)
require.True(suite.T(), retryBlockImageCountCheck(suite.helper, len(initBlockImages), 1), "Make sure a new block is created")
suite.T().Log("Block Storage created successfully")
logger.Infof("Block Storage created successfully")
require.True(suite.T(), suite.helper.WaitUntilPVCIsBound(), "Make sure PVC is Bound")
suite.T().Log("step 2: Mount block storage")
_, mt_err := suite.helper.MountBlockStorage()
require.Nil(suite.T(), mt_err)
suite.T().Log("Block Storage Mounted successfully")
logger.Infof("step 2: Mount block storage")
_, mtErr := suite.helper.MountBlockStorage()
require.Nil(suite.T(), mtErr)
logger.Infof("Block Storage Mounted successfully")
suite.T().Log("step 3: Write to block storage")
_, wt_err := suite.helper.WriteToBlockStorage("Test Data", "testFile1")
require.Nil(suite.T(), wt_err)
suite.T().Log("Write to Block storage successfully")
logger.Infof("step 3: Write to block storage")
_, wtErr := suite.helper.WriteToBlockStorage("Test Data", "testFile1")
require.Nil(suite.T(), wtErr)
logger.Infof("Write to Block storage successfully")
suite.T().Log("step 4: Read from block storage")
read, r_err := suite.helper.ReadFromBlockStorage("testFile1")
require.Nil(suite.T(), r_err)
logger.Infof("step 4: Read from block storage")
read, rErr := suite.helper.ReadFromBlockStorage("testFile1")
require.Nil(suite.T(), rErr)
require.Contains(suite.T(), read, "Test Data", "make sure content of the files is unchanged")
suite.T().Log("Read from Block storage successfully")
logger.Infof("Read from Block storage successfully")
suite.T().Log("step 5: Unmount block storage")
_, unmt_err := suite.helper.UnMountBlockStorage()
require.Nil(suite.T(), unmt_err)
suite.T().Log("Block Storage unmounted successfully")
logger.Infof("step 5: Unmount block storage")
_, unmtErr := suite.helper.UnMountBlockStorage()
require.Nil(suite.T(), unmtErr)
logger.Infof("Block Storage unmounted successfully")
suite.T().Log("step 6: Deleting block storage")
_, db_err := suite.helper.DeleteBlockStorage()
require.Nil(suite.T(), db_err)
logger.Infof("step 6: Deleting block storage")
_, dbErr := suite.helper.DeleteBlockStorage()
require.Nil(suite.T(), dbErr)
require.True(suite.T(), retryBlockImageCountCheck(suite.helper, len(initBlockImages), 0), "Make sure a new block is created")
suite.T().Log("Block Storage deleted successfully")
logger.Infof("Block Storage deleted successfully")
}
func (s *SmokeSuite) blockTestDataCleanUp() {
s.helper.UnMountBlockStorage()
s.helper.DeleteBlockStorage()
s.helper.CleanUpDymanicBlockStorage()
func (suite *SmokeSuite) blockTestDataCleanUp() {
suite.helper.UnMountBlockStorage()
suite.helper.DeleteBlockStorage()
suite.helper.CleanUpDymanicBlockStorage()
}
func (suite *SmokeSuite) TearDownSuite() {
@@ -98,16 +102,15 @@ func (suite *SmokeSuite) TearDownSuite() {
// periodically checking if block image count has changed to expected value
// When creating pvc in k8s platform, it may take some time for the block Image to be bounded
func retryBlockImageCountCheck(h *SmokeTestHelper, imageCount int, expectedChange int) bool {
func retryBlockImageCountCheck(h *TestHelper, imageCount int, expectedChange int) bool {
inc := 0
for inc < 30 {
for inc < 60 {
blockImages, _ := h.GetBlockClient().BlockList()
if imageCount+expectedChange == len(blockImages) {
return true
} else {
time.Sleep(time.Second * 2)
inc++
}
time.Sleep(time.Second * 3)
inc++
}
return false
}
+26 -26
View File
@@ -24,48 +24,48 @@ import (
//Create,Mount,Write,Read,Unmount and Delete.
func (suite *SmokeSuite) TestFileStorage_SmokeTest() {
defer suite.fileTestDataCleanUp()
suite.T().Log("File Storage Smoke Test - Create,Mount,write to, read from and Unmount Filesystem")
logger.Infof("File Storage Smoke Test - Create,Mount,write to, read from and Unmount Filesystem")
rfc := suite.helper.GetFileSystemClient()
suite.T().Log("Step 1: Create file System")
_, fsc_err := suite.helper.CreateFileStorage()
require.Nil(suite.T(), fsc_err)
logger.Infof("Step 1: Create file System")
_, fscErr := suite.helper.CreateFileStorage()
require.Nil(suite.T(), fscErr)
fileSystemList, _ := rfc.FSList()
require.Equal(suite.T(), 1, len(fileSystemList), "There should one shared file system present")
filesystemData := fileSystemList[0]
require.Equal(suite.T(), "testfs", filesystemData.Name, "make sure filesystem name matches")
suite.T().Log("File system created")
logger.Infof("File system created")
suite.T().Log("Step 2: Mount file System")
_, mtfs_err := suite.helper.MountFileStorage()
require.Nil(suite.T(), mtfs_err)
suite.T().Log("File system mounted successfully")
logger.Infof("Step 2: Mount file System")
_, mtfsErr := suite.helper.MountFileStorage()
require.Nil(suite.T(), mtfsErr)
logger.Infof("File system mounted successfully")
suite.T().Log("Step 3: Write to file system")
_, wfs_err := suite.helper.WriteToFileStorage("Test data for file", "fsFile1")
require.Nil(suite.T(), wfs_err)
suite.T().Log("Write to file system successful")
logger.Infof("Step 3: Write to file system")
_, wfsErr := suite.helper.WriteToFileStorage("Test data for file", "fsFile1")
require.Nil(suite.T(), wfsErr)
logger.Infof("Write to file system successful")
suite.T().Log("Step 4: Read from file system")
read, rd_err := suite.helper.ReadFromFileStorage("fsFile1")
require.Nil(suite.T(), rd_err)
logger.Infof("Step 4: Read from file system")
read, rdErr := suite.helper.ReadFromFileStorage("fsFile1")
require.Nil(suite.T(), rdErr)
require.Contains(suite.T(), read, "Test data for file", "make sure content of the files is unchanged")
suite.T().Log("Read from file system successful")
logger.Infof("Read from file system successful")
suite.T().Log("Step 5: Mount file System")
_, umtfs_err := suite.helper.UnmountFileStorage()
require.Nil(suite.T(), umtfs_err)
suite.T().Log("File system mounted successfully")
logger.Infof("Step 5: UnMount file System")
_, umtfsErr := suite.helper.UnmountFileStorage()
require.Nil(suite.T(), umtfsErr)
logger.Infof("File system mounted successfully")
suite.T().Log("Step 6: Deleting file storage")
logger.Infof("Step 6: Deleting file storage")
suite.helper.DeleteFileStorage()
//Delete is not deleting filesystem - known issue
//require.Nil(suite.T(), fsd_err)
suite.T().Log("File system deleted")
logger.Infof("File system deleted")
}
func (s *SmokeSuite) fileTestDataCleanUp() {
s.helper.UnmountFileStorage()
s.helper.DeleteFileStorage()
func (suite *SmokeSuite) fileTestDataCleanUp() {
suite.helper.UnmountFileStorage()
suite.helper.DeleteFileStorage()
}
+37 -37
View File
@@ -38,33 +38,33 @@ var (
//Delete user
func (suite *SmokeSuite) TestObjectStorage_SmokeTest() {
defer suite.blockTestDataCleanUp()
suite.T().Log("Object Storage Smoke Test - Create Object Store, User,Bucket and read/write to bucket")
logger.Infof("Object Storage Smoke Test - Create Object Store, User,Bucket and read/write to bucket")
suite.T().Log("Step 0 : Create Object Store")
_, cobs_err := suite.helper.CreateObjectStore()
require.Nil(suite.T(), cobs_err)
suite.T().Log("Object store created successfully")
logger.Infof("Step 0 : Create Object Store")
_, cobsErr := suite.helper.CreateObjectStore()
require.Nil(suite.T(), cobsErr)
logger.Infof("Object store created successfully")
suite.T().Log("Step 1 : Create Object Store User")
logger.Infof("Step 1 : Create Object Store User")
initialUsers, _ := suite.helper.GetObjectStoreUsers()
_, cosu_err := suite.helper.CreateObjectStoreUser()
require.Nil(suite.T(), cosu_err)
_, cosuErr := suite.helper.CreateObjectStoreUser()
require.Nil(suite.T(), cosuErr)
usersAfterCrate, _ := suite.helper.GetObjectStoreUsers()
require.Equal(suite.T(), len(initialUsers)+1, len(usersAfterCrate), "Make sure user list count is increaded by 1")
getuserData, gu_err := suite.helper.GetObjectStoreUser(userid)
require.Nil(suite.T(), gu_err)
getuserData, guErr := suite.helper.GetObjectStoreUser(userid)
require.Nil(suite.T(), guErr)
require.Equal(suite.T(), userid, getuserData.UserID, "Check user id returned")
require.Equal(suite.T(), userdisplayname, *getuserData.DisplayName, "Check user name returned")
suite.T().Log("Object store user created successfully")
logger.Infof("Object store user created successfully")
suite.T().Log("Step 2 : Get connection information")
conninfo, conninfo_error := suite.helper.GetObjectStoreUser(userid)
require.Nil(suite.T(), conninfo_error)
logger.Infof("Step 2 : Get connection information")
conninfo, conninfoError := suite.helper.GetObjectStoreUser(userid)
require.Nil(suite.T(), conninfoError)
s3endpoint, _ := suite.helper.GetRGWServiceUrl()
s3endpoint, _ := suite.helper.GetRGWServiceURL()
s3client := utils.CreateNewS3Helper(s3endpoint, *conninfo.AccessKey, *conninfo.SecretKey)
suite.T().Log("Step 3 : Create bucket")
logger.Infof("Step 3 : Create bucket")
initialBuckets, _ := suite.helper.GetObjectStoreBucketList()
s3client.CreateBucket(bucketname)
BucketsAfterCreate, _ := suite.helper.GetObjectStoreBucketList()
@@ -72,61 +72,61 @@ func (suite *SmokeSuite) TestObjectStorage_SmokeTest() {
bkt, _ := getBucket(bucketname, BucketsAfterCreate)
require.Equal(suite.T(), bucketname, bkt.Name)
require.Equal(suite.T(), userid, bkt.Owner)
suite.T().Log("Bucket created in Object store successfully")
logger.Infof("Bucket created in Object store successfully")
suite.T().Log("Step 4 : Put Object on bucket")
logger.Infof("Step 4 : Put Object on bucket")
initObjSize, initObjNum, _ := getBucketSizeAndObjectes(bucketname, BucketsAfterCreate)
require.Equal(suite.T(), uint64(0), initObjSize)
require.Equal(suite.T(), uint64(0), initObjNum)
_, po_err := s3client.PutObjectInBucket(bucketname, objBody, objectKey, contentType)
require.Nil(suite.T(), po_err)
_, poErr := s3client.PutObjectInBucket(bucketname, objBody, objectKey, contentType)
require.Nil(suite.T(), poErr)
BucketsAfterPut, _ := suite.helper.GetObjectStoreBucketList()
ObjSize, ObjNum, _ := getBucketSizeAndObjectes(bucketname, BucketsAfterPut)
require.NotEmpty(suite.T(), ObjSize)
require.Equal(suite.T(), uint64(1), ObjNum)
suite.T().Log("Object Created on bucket successfully")
logger.Infof("Object Created on bucket successfully")
suite.T().Log("Step 5 : Put Object from bucket")
logger.Infof("Step 5 : Put Object from bucket")
read, err := s3client.GetObjectInBucket(bucketname, objectKey)
require.Nil(suite.T(), err)
require.Equal(suite.T(), objBody, read)
suite.T().Log("Object retrived from bucket successfully")
logger.Infof("Object retrived from bucket successfully")
suite.T().Log("Step 6 : Delete Object on bucket")
_, delobj_err := s3client.DeleteObjectInBucket(bucketname, objectKey)
require.Nil(suite.T(), delobj_err)
logger.Infof("Step 6 : Delete Object on bucket")
_, delobjErr := s3client.DeleteObjectInBucket(bucketname, objectKey)
require.Nil(suite.T(), delobjErr)
BucketsAfterOjbDelete, _ := suite.helper.GetObjectStoreBucketList()
ObjSize1, ObjNum1, _ := getBucketSizeAndObjectes(bucketname, BucketsAfterOjbDelete)
require.Equal(suite.T(), uint64(0), ObjSize1)
require.Equal(suite.T(), uint64(0), ObjNum1)
suite.T().Log("Object deleted on bucket successfully")
logger.Infof("Object deleted on bucket successfully")
suite.T().Log("Step 6 : Delete bucket")
_, bkdel_err := s3client.DeleteBucket(bucketname)
require.Nil(suite.T(), bkdel_err)
logger.Infof("Step 6 : Delete bucket")
_, bkdelErr := s3client.DeleteBucket(bucketname)
require.Nil(suite.T(), bkdelErr)
BucketsAfterDelete, _ := suite.helper.GetObjectStoreBucketList()
require.Equal(suite.T(), len(initialBuckets), len(BucketsAfterDelete), "Make sure new bucket is deleted")
suite.T().Log("Bucket deleted successfully")
logger.Infof("Bucket deleted successfully")
suite.T().Log("Step 7 : Delete User")
logger.Infof("Step 7 : Delete User")
usersBeforeDelete, _ := suite.helper.GetObjectStoreUsers()
suite.helper.DeleteObjectStoreUser()
usersAfterDelete, _ := suite.helper.GetObjectStoreUsers()
require.Equal(suite.T(), len(usersBeforeDelete)-1, len(usersAfterDelete), "Make sure user list count is reducd by 1")
suite.T().Log("Object store user deleted successfully")
logger.Infof("Object store user deleted successfully")
}
func (s *SmokeSuite) objectTestDataCleanUp() {
userinfo, err := s.helper.GetObjectStoreUser(userid)
func (suite *SmokeSuite) objectTestDataCleanUp() {
userinfo, err := suite.helper.GetObjectStoreUser(userid)
if err != nil {
return //when user is not found
}
s3endpoint, _ := s.helper.GetRGWServiceUrl()
s3endpoint, _ := suite.helper.GetRGWServiceURL()
s3client := utils.CreateNewS3Helper(s3endpoint, *userinfo.AccessKey, *userinfo.SecretKey)
s3client.DeleteObjectInBucket(bucketname, objectKey)
s3client.DeleteBucket(bucketname)
s.helper.DeleteObjectStoreUser()
suite.helper.DeleteObjectStoreUser()
}
+96 -42
View File
@@ -27,16 +27,19 @@ import (
"github.com/rook/rook/tests/framework/contracts"
"github.com/rook/rook/tests/framework/enums"
"github.com/rook/rook/tests/framework/utils"
"strings"
)
const (
dataPath = "src/github.com/rook/rook/tests/data"
)
type SmokeTestHelper struct {
//TestHelper struct for smoke test
type TestHelper struct {
platform enums.RookPlatformType
rookclient *clients.TestClient
k8sHelp *utils.K8sHelper
k8sVersion string
}
type blockTestData struct {
@@ -55,15 +58,15 @@ type fileTestData struct {
}
type objectUserData struct {
userId string
userID string
displayname string
emailId string
emailID string
}
type objectConnectionData struct {
awsEndpoint string
awsHost string
awsSecretKeyId string
awsSecretKeyID string
awsSecretAccessKey string
}
@@ -75,13 +78,15 @@ func createObjectConnectionData(endpoint string, host string, secretid string, s
return objectConnectionData{endpoint, host, secretid, secretkey}
}
func CreateSmokeTestClient(platform enums.RookPlatformType) (*SmokeTestHelper, error) {
//CreateSmokeTestClient constructor for creating instance of smoke test client
func CreateSmokeTestClient(platform enums.RookPlatformType, k8sversion string) (*TestHelper, error) {
rc, err := getRookClient(platform)
return &SmokeTestHelper{platform: platform,
return &TestHelper{platform: platform,
rookclient: rc,
k8sHelp: utils.CreatK8sHelper()}, err
k8sHelp: utils.CreatK8sHelper(),
k8sVersion: k8sversion}, err
}
@@ -89,15 +94,19 @@ func getRookClient(platform enums.RookPlatformType) (*clients.TestClient, error)
return clients.CreateTestClient(platform)
}
func (h *SmokeTestHelper) GetBlockClient() contracts.BlockOperator {
//GetBlockClient returns a pointer to block client to perform block operations
func (h *TestHelper) GetBlockClient() contracts.BlockOperator {
return h.rookclient.GetBlockClient()
}
func (h *SmokeTestHelper) GetFileSystemClient() contracts.FileSystemOperator {
//GetFileSystemClient returns a pointer to fileSystem client to perform filesSystem operations
func (h *TestHelper) GetFileSystemClient() contracts.FileSystemOperator {
return h.rookclient.GetFileSystemClient()
}
func (h *SmokeTestHelper) GetObjectClient() contracts.ObjectOperator {
//GetObjectClient returns a pointer to object store client to perform object store operations
func (h *TestHelper) GetObjectClient() contracts.ObjectOperator {
return h.rookclient.GetObjectClient()
}
@@ -105,7 +114,7 @@ func getDataPath(file string) string {
return filepath.Join(os.Getenv("GOPATH"), dataPath, file)
}
func (h *SmokeTestHelper) getBlockTestData() (blockTestData, error) {
func (h *TestHelper) getBlockTestData() (blockTestData, error) {
switch h.platform {
case enums.Kubernetes:
return blockTestData{"block-test",
@@ -125,7 +134,7 @@ func (h *SmokeTestHelper) getBlockTestData() (blockTestData, error) {
}
}
func (h *SmokeTestHelper) getFileTestData() (fileTestData, error) {
func (h *TestHelper) getFileTestData() (fileTestData, error) {
switch h.platform {
case enums.Kubernetes:
return fileTestData{"testfs",
@@ -141,21 +150,28 @@ func (h *SmokeTestHelper) getFileTestData() (fileTestData, error) {
}
}
func (h *SmokeTestHelper) getObjectStoreUserData() objectUserData {
func (h *TestHelper) getObjectStoreUserData() objectUserData {
return objectUserData{"rook-user", "A rook RGW user", ""}
}
func (h *SmokeTestHelper) getRGWExtenalSevDef() string {
func (h *TestHelper) getRGWExtenalSevDef() string {
return getDataPath("smoke/rgw_external.yaml")
}
func (h *SmokeTestHelper) CreateBlockStorage() (string, error) {
//CreateBlockStorage function creates a block store
func (h *TestHelper) CreateBlockStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
h.k8sHelp.ResourceOperation("create", getDataPath("smoke/pool_sc.yaml"))
if strings.EqualFold(h.k8sVersion, "v1.5") {
h.k8sHelp.ResourceOperation("create", getDataPath("smoke/pool_sc_1_5.yaml"))
} else {
h.k8sHelp.ResourceOperation("create", getDataPath("smoke/pool_sc.yaml"))
}
// see https://github.com/rook/rook/issues/767
time.Sleep(5 * time.Second)
time.Sleep(10 * time.Second)
return h.k8sHelp.ResourceOperation("create", blockData.pvcDefPath)
case enums.StandAlone:
return "NEED TO IMPLEMENT", fmt.Errorf("NOT YET IMPLEMENTED")
default:
@@ -164,7 +180,15 @@ func (h *SmokeTestHelper) CreateBlockStorage() (string, error) {
}
}
func (h *SmokeTestHelper) MountBlockStorage() (string, error) {
//WaitUntilPVCIsBound waits untill PVC is in bound state and returs true if the state is transitisioned to
//Bound state, or returns false
func (h *TestHelper) WaitUntilPVCIsBound() bool {
return h.k8sHelp.WaitUntilPVCIsBound("block-pv-claim")
}
//MountBlockStorage function mounts a rook created block storage
func (h *TestHelper) MountBlockStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
@@ -186,7 +210,8 @@ func (h *SmokeTestHelper) MountBlockStorage() (string, error) {
}
}
func (h *SmokeTestHelper) WriteToBlockStorage(data string, filename string) (string, error) {
//WriteToBlockStorage function writes a block to rook provisioned block store
func (h *TestHelper) WriteToBlockStorage(data string, filename string) (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
@@ -200,7 +225,8 @@ func (h *SmokeTestHelper) WriteToBlockStorage(data string, filename string) (str
}
}
func (h *SmokeTestHelper) ReadFromBlockStorage(filename string) (string, error) {
//ReadFromBlockStorage function Reads a block from rook provisioned block store
func (h *TestHelper) ReadFromBlockStorage(filename string) (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
@@ -214,7 +240,8 @@ func (h *SmokeTestHelper) ReadFromBlockStorage(filename string) (string, error)
}
}
func (h *SmokeTestHelper) UnMountBlockStorage() (string, error) {
//UnMountBlockStorage function unmounts Block storage
func (h *TestHelper) UnMountBlockStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
@@ -235,11 +262,18 @@ func (h *SmokeTestHelper) UnMountBlockStorage() (string, error) {
}
}
func (h *SmokeTestHelper) DeleteBlockStorage() (string, error) {
//DeleteBlockStorage function deletes block storage
func (h *TestHelper) DeleteBlockStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
blockData, _ := h.getBlockTestData()
// Delete storage pool, storage class and pvc
if strings.EqualFold(h.k8sVersion, "v1.5") {
h.k8sHelp.ResourceOperation("delete", getDataPath("smoke/pool_sc_1_5.yaml"))
} else {
h.k8sHelp.ResourceOperation("delete", getDataPath("smoke/pool_sc.yaml"))
}
return h.k8sHelp.ResourceOperation("delete", blockData.pvcDefPath)
case enums.StandAlone:
return "NEED TO IMPLEMENT", fmt.Errorf("NOT YET IMPLEMENTED")
@@ -249,7 +283,8 @@ func (h *SmokeTestHelper) DeleteBlockStorage() (string, error) {
}
}
func (h *SmokeTestHelper) CleanUpDymanicBlockStorage() {
//CleanUpDymanicBlockStorage is helper method to clean up bock storage created by tests
func (h *TestHelper) CleanUpDymanicBlockStorage() {
switch h.platform {
case enums.Kubernetes:
// Delete storage pool, storage class and pvc
@@ -262,7 +297,8 @@ func (h *SmokeTestHelper) CleanUpDymanicBlockStorage() {
}
}
func (h *SmokeTestHelper) CreateFileStorage() (string, error) {
//CreateFileStorage function creates a file system
func (h *TestHelper) CreateFileStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -276,7 +312,8 @@ func (h *SmokeTestHelper) CreateFileStorage() (string, error) {
}
}
func (h *SmokeTestHelper) MountFileStorage() (string, error) {
//MountFileStorage function mounts a file system
func (h *TestHelper) MountFileStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -311,7 +348,8 @@ func (h *SmokeTestHelper) MountFileStorage() (string, error) {
}
}
func (h *SmokeTestHelper) WriteToFileStorage(data string, filename string) (string, error) {
//WriteToFileStorage functions creates a new file on rook file system
func (h *TestHelper) WriteToFileStorage(data string, filename string) (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -325,7 +363,8 @@ func (h *SmokeTestHelper) WriteToFileStorage(data string, filename string) (stri
}
}
func (h *SmokeTestHelper) ReadFromFileStorage(filename string) (string, error) {
//ReadFromFileStorage function get file content from a rook file storage
func (h *TestHelper) ReadFromFileStorage(filename string) (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -339,7 +378,8 @@ func (h *SmokeTestHelper) ReadFromFileStorage(filename string) (string, error) {
}
}
func (h *SmokeTestHelper) UnmountFileStorage() (string, error) {
//UnmountFileStorage funxtion unmounts a file system
func (h *TestHelper) UnmountFileStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -373,7 +413,8 @@ func (h *SmokeTestHelper) UnmountFileStorage() (string, error) {
}
}
func (h *SmokeTestHelper) DeleteFileStorage() (string, error) {
//DeleteFileStorage deletes File system
func (h *TestHelper) DeleteFileStorage() (string, error) {
switch h.platform {
case enums.Kubernetes:
fileTestData, _ := h.getFileTestData()
@@ -387,7 +428,8 @@ func (h *SmokeTestHelper) DeleteFileStorage() (string, error) {
}
}
func (h *SmokeTestHelper) CreateObjectStore() (string, error) {
//CreateObjectStore function creates a object store
func (h *TestHelper) CreateObjectStore() (string, error) {
switch h.platform {
case enums.Kubernetes:
h.GetObjectClient().ObjectCreate()
@@ -396,6 +438,10 @@ func (h *SmokeTestHelper) CreateObjectStore() (string, error) {
_, err := h.k8sHelp.GetService("rgw-external")
if err != nil {
h.k8sHelp.ResourceOperation("create", h.getRGWExtenalSevDef())
if !h.k8sHelp.IsServiceUpInNameSpace("rgw-external") {
return "Couldn't create object store ", fmt.Errorf("Cannot expose rgw servie for external user")
}
}
return "OJECT STORE CREATED", nil
@@ -408,49 +454,57 @@ func (h *SmokeTestHelper) CreateObjectStore() (string, error) {
}
}
func (h *SmokeTestHelper) CreateObjectStoreUser() (string, error) {
//CreateObjectStoreUser function creates a new object store user
func (h *TestHelper) CreateObjectStoreUser() (string, error) {
objectUserdata := h.getObjectStoreUserData()
_, err := h.GetObjectClient().ObjectCreateUser(objectUserdata.userId, objectUserdata.displayname)
_, err := h.GetObjectClient().ObjectCreateUser(objectUserdata.userID, objectUserdata.displayname)
if err != nil {
return "USER NOT CREATED", fmt.Errorf("User not created for object store")
return "USER NOT CREATED", fmt.Errorf("User not created for object store %+v", err)
}
return "USER CREATED ", nil
}
func (h *SmokeTestHelper) GetObjectStoreUsers() ([]model.ObjectUser, error) {
//GetObjectStoreUsers returns all useres
func (h *TestHelper) GetObjectStoreUsers() ([]model.ObjectUser, error) {
return h.GetObjectClient().ObjectListUser()
}
func (h *SmokeTestHelper) GetObjectStoreUser(userid string) (*model.ObjectUser, error) {
//GetObjectStoreUser function returns a user object with matching userId
func (h *TestHelper) GetObjectStoreUser(userid string) (*model.ObjectUser, error) {
return h.GetObjectClient().ObjectGetUser(userid)
}
func (h *SmokeTestHelper) GetObjectStoreConnection() (*model.ObjectStoreConnectInfo, error) {
//GetObjectStoreConnection function returns connection information about object store
func (h *TestHelper) GetObjectStoreConnection() (*model.ObjectStoreConnectInfo, error) {
return h.GetObjectClient().ObjectConnection()
}
func (h *SmokeTestHelper) GetObjectStoreBucketList() ([]model.ObjectBucket, error) {
//GetObjectStoreBucketList function returns list of buckets for a user
func (h *TestHelper) GetObjectStoreBucketList() ([]model.ObjectBucket, error) {
return h.GetObjectClient().ObjectBucketList()
}
func (h *SmokeTestHelper) DeleteObjectStoreUser() error {
//DeleteObjectStoreUser function deletes rgw object store user
func (h *TestHelper) DeleteObjectStoreUser() error {
objectUserdata := h.getObjectStoreUserData()
return h.GetObjectClient().ObjectDeleteUser(objectUserdata.userId)
return h.GetObjectClient().ObjectDeleteUser(objectUserdata.userID)
}
func (h *SmokeTestHelper) GetRGWServiceUrl() (string, error) {
//GetRGWServiceURL returns URL of ceph RGW service in the cluster
func (h *TestHelper) GetRGWServiceURL() (string, error) {
switch h.platform {
case enums.Kubernetes:
hostip, err := h.k8sHelp.GetPodHostId("rook-ceph-rgw", "rook")
hostip, err := h.k8sHelp.GetPodHostID("rook-ceph-rgw", "rook")
if err != nil {
panic(fmt.Errorf("RGW pods not found/object store possibly not started"))
}
return hostip + ":30001", err
endpoint := hostip + ":30001"
return endpoint, err
case enums.StandAlone:
return "NEED TO IMPLEMENT", fmt.Errorf("NOT YET IMPLEMENTED")
default: