Files
my-rook-config/tests/framework/clients/filesystem.go
T

92 lines
3.2 KiB
Go
Raw Normal View History

2017-06-26 21:52:06 -07:00
/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2017-04-28 08:02:37 -07:00
package clients
import (
"fmt"
2017-06-26 21:52:06 -07:00
2018-03-16 08:31:34 -07:00
"github.com/rook/rook/pkg/daemon/ceph/client"
2018-08-21 15:24:52 -06:00
"github.com/rook/rook/tests/framework/installer"
2017-07-21 12:07:15 -07:00
"github.com/rook/rook/tests/framework/utils"
2017-10-05 10:00:19 -07:00
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
2018-03-16 08:31:34 -07:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2017-04-28 08:02:37 -07:00
)
// FilesystemOperation is a wrapper for k8s rook file operations
2017-10-05 10:00:19 -07:00
type FilesystemOperation struct {
2018-08-21 15:24:52 -06:00
k8sh *utils.K8sHelper
manifests installer.CephManifests
2017-04-28 08:02:37 -07:00
}
2018-08-21 15:24:52 -06:00
// CreateFilesystemOperation Constructor to create FilesystemOperation - client to perform rook file system operations on k8s
func CreateFilesystemOperation(k8sh *utils.K8sHelper, manifests installer.CephManifests) *FilesystemOperation {
return &FilesystemOperation{k8sh, manifests}
2017-04-28 08:02:37 -07:00
}
2018-10-10 16:41:06 -06:00
// Create creates a filesystem in Rook
2018-03-16 08:31:34 -07:00
func (f *FilesystemOperation) Create(name, namespace string) error {
logger.Infof("creating the filesystem via CRD")
if err := f.k8sh.ResourceOperation("apply", f.manifests.GetFilesystem(namespace, name, 2)); err != nil {
2018-03-16 08:31:34 -07:00
return err
2017-10-05 10:00:19 -07:00
}
logger.Infof("Make sure rook-ceph-mds pod is running")
err := f.k8sh.WaitForLabeledPodsToRun(fmt.Sprintf("rook_file_system=%s", name), namespace)
assert.Nil(f.k8sh.T(), err)
2017-10-05 10:00:19 -07:00
assert.True(f.k8sh.T(), f.k8sh.CheckPodCountAndState("rook-ceph-mds", namespace, 4, "Running"),
2018-10-10 16:41:06 -06:00
"Make sure there are four rook-ceph-mds pods present in Running state")
return nil
}
// ScaleDown scales down the number of active metadata servers of a filesystem in Rook
func (f *FilesystemOperation) ScaleDown(name, namespace string) error {
logger.Infof("scaling down the number of filesystem active metadata servers via CRD")
if err := f.k8sh.ResourceOperation("apply", f.manifests.GetFilesystem(namespace, name, 1)); err != nil {
2018-10-10 16:41:06 -06:00
return err
}
assert.True(f.k8sh.T(), f.k8sh.CheckPodCountAndState("rook-ceph-mds", namespace, 2, "Running"),
2017-10-05 10:00:19 -07:00
"Make sure there are two rook-ceph-mds pods present in Running state")
return nil
2017-04-28 08:02:37 -07:00
}
2018-10-10 16:41:06 -06:00
// Delete deletes a filesystem in Rook
2018-03-16 08:31:34 -07:00
func (f *FilesystemOperation) Delete(name, namespace string) error {
options := &metav1.DeleteOptions{}
logger.Infof("Deleting filesystem %s in namespace %s", name, namespace)
2018-12-03 23:48:40 -07:00
err := f.k8sh.RookClientset.CephV1().CephFilesystems(namespace).Delete(name, options)
if err != nil && !errors.IsNotFound(err) {
return err
}
2018-12-03 23:48:40 -07:00
logger.Infof("Deleted filesystem %s in namespace %s", name, namespace)
return nil
2017-04-28 08:02:37 -07:00
}
2018-10-10 16:41:06 -06:00
// List lists filesystems in Rook
2018-03-16 08:31:34 -07:00
func (f *FilesystemOperation) List(namespace string) ([]client.CephFilesystem, error) {
context := f.k8sh.MakeContext()
filesystems, err := client.ListFilesystems(context, namespace)
if err != nil {
return nil, fmt.Errorf("failed to list pools: %+v", err)
}
return filesystems, nil
2017-04-28 08:02:37 -07:00
}