Merge pull request #17730 from jhoblitt/maint-remove-dead-test-framework-files
tests: remove unused test framework helpers
This commit is contained in:
4 files changed
-304
No files matched your search
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package clients
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// ReadWriteOperation is a wrapper for k8s rook file operations
|
||||
type ReadWriteOperation struct {
|
||||
k8sh *utils.K8sHelper
|
||||
}
|
||||
|
||||
// CreateReadWriteOperation Constructor to create ReadWriteOperation - client to perform rook file system operations on k8s
|
||||
func CreateReadWriteOperation(k8sh *utils.K8sHelper) *ReadWriteOperation {
|
||||
return &ReadWriteOperation{k8sh: k8sh}
|
||||
}
|
||||
|
||||
// CreateWriteClient Function to create a nfs client in rook
|
||||
func (f *ReadWriteOperation) CreateWriteClient(volName string) ([]string, error) {
|
||||
logger.Infof("creating the filesystem via replication controller")
|
||||
writerSpec := getDeployment(volName)
|
||||
|
||||
if err := f.k8sh.ResourceOperation("apply", writerSpec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
assert.True(f.k8sh.T(), f.k8sh.CheckPodCountAndState("read-write-test", "default", 2, "Running"),
|
||||
"Make sure there are two read-write-test pods present in Running state")
|
||||
|
||||
podList, err := f.k8sh.GetPodNamesForApp("read-write-test", "default")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return podList, nil
|
||||
}
|
||||
|
||||
// Delete Function to delete a nfs consuming pod in rook
|
||||
func (f *ReadWriteOperation) Delete() error {
|
||||
return f.k8sh.DeleteResource("deployment", "read-write-test")
|
||||
}
|
||||
|
||||
// Read Function to read from nfs mount point created by rook ,i.e. Read data from a pod that has an nfs export mounted
|
||||
func (f *ReadWriteOperation) Read(name string) (string, error) {
|
||||
rd := "/mnt/data"
|
||||
|
||||
args := []string{"exec", name}
|
||||
|
||||
args = append(args, "--", "cat", rd)
|
||||
|
||||
result, err := f.k8sh.Kubectl(args...)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to write data to pod -- : %s", err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getDeployment(volName string) string {
|
||||
return `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: read-write-test
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: read-write-test
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: read-write-test
|
||||
spec:
|
||||
containers:
|
||||
- image: alpine
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- 'while true; do hostname > /mnt/data; sleep 3; done'
|
||||
name: alpine
|
||||
volumeMounts:
|
||||
- name: test-vol
|
||||
mountPath: "/mnt"
|
||||
volumes:
|
||||
- name: test-vol
|
||||
persistentVolumeClaim:
|
||||
claimName: ` + volName + `
|
||||
`
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
"github.com/rook/rook/pkg/util/sys"
|
||||
)
|
||||
|
||||
// IsAdditionalDeviceAvailableOnCluster checks whether a given device is available to become an OSD
|
||||
func IsAdditionalDeviceAvailableOnCluster() bool {
|
||||
executor := &exec.CommandExecutor{}
|
||||
devices, err := sys.ListDevices(executor)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
disks := 0
|
||||
logger.Infof("devices : %v", devices)
|
||||
for _, device := range devices {
|
||||
if strings.Contains(device, "loop") {
|
||||
continue
|
||||
}
|
||||
props, _ := sys.GetDeviceProperties(device, executor)
|
||||
if props["TYPE"] != "disk" {
|
||||
continue
|
||||
}
|
||||
devicePath, ok := props["NAME"]
|
||||
if !ok {
|
||||
logger.Warningf("failed to find device path for %q", device)
|
||||
continue
|
||||
}
|
||||
|
||||
pvcBackedOSD := false
|
||||
isAvailable, rejectedReason, err := sys.CheckIfDeviceAvailable(executor, devicePath, pvcBackedOSD)
|
||||
if err != nil {
|
||||
logger.Warningf("failed to detect device %q availability. %v", device, err)
|
||||
continue
|
||||
}
|
||||
if !isAvailable {
|
||||
logger.Infof("skipping device %q because %s", device, rejectedReason)
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(device, "rbd") {
|
||||
logger.Infof("skipping unexpected rbd device %q", device)
|
||||
continue
|
||||
}
|
||||
logger.Infof("available device %q", device)
|
||||
disks++
|
||||
}
|
||||
if disks > 0 {
|
||||
return true
|
||||
}
|
||||
logger.Info("No additional disks found on cluster")
|
||||
return false
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
hostPathStorageClassName = "hostpath"
|
||||
)
|
||||
|
||||
// ************************************************************************************************
|
||||
// HostPath provisioner functions
|
||||
// ************************************************************************************************
|
||||
func CreateHostPathPVs(k8shelper *utils.K8sHelper, count int, readOnly bool, pvcSize string) error {
|
||||
logger.Info("creating test PVs")
|
||||
|
||||
pv := `
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: test-hostpath-%d
|
||||
labels:
|
||||
hostpath: test
|
||||
spec:
|
||||
storageClassName: %s
|
||||
capacity:
|
||||
storage: %s
|
||||
accessModes:
|
||||
- %s
|
||||
persistentVolumeReclaimPolicy: Delete
|
||||
volumeMode: Filesystem
|
||||
local:
|
||||
path: "%s"
|
||||
nodeAffinity:
|
||||
required:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: kubernetes.io/hostname
|
||||
operator: Exists
|
||||
`
|
||||
storageClass := `
|
||||
---
|
||||
kind: StorageClass
|
||||
apiVersion: storage.k8s.io/v1
|
||||
metadata:
|
||||
name: %s
|
||||
annotations:
|
||||
storageclass.kubernetes.io/is-default-class: "true"
|
||||
provisioner: kubernetes.io/no-provisioner
|
||||
volumeBindingMode: WaitForFirstConsumer
|
||||
reclaimPolicy: Delete
|
||||
`
|
||||
accessMode := "ReadWriteMany"
|
||||
if readOnly {
|
||||
accessMode = "ReadWriteOnce"
|
||||
}
|
||||
yamlToCreate := fmt.Sprintf(storageClass, hostPathStorageClassName)
|
||||
for i := 0; i < count; i++ {
|
||||
tempDir, err := os.MkdirTemp("", "example")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create temp dir. %v", err)
|
||||
}
|
||||
logger.Infof("created temp dir: %s", tempDir)
|
||||
yamlToCreate += fmt.Sprintf(pv, i, hostPathStorageClassName, pvcSize, accessMode, tempDir)
|
||||
}
|
||||
out, err := k8shelper.KubectlWithStdin(yamlToCreate, createFromStdinArgs...)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create hostpath provisioner StorageClass: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
present, err := k8shelper.IsStorageClassPresent(hostPathStorageClassName)
|
||||
if !present {
|
||||
logger.Errorf("storageClass %s not found: %+v", hostPathStorageClassName, err)
|
||||
k8shelper.PrintStorageClasses(true /*detailed*/)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteHostPathPVs(k8shelper *utils.K8sHelper) error {
|
||||
logger.Info("deleting hostpath PVs")
|
||||
|
||||
args := []string{"delete", "pv", "-l", "hostpath=test"}
|
||||
_, err := k8shelper.Kubectl(args...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete test PVs. %v", err)
|
||||
}
|
||||
|
||||
args = []string{"delete", "sc", hostPathStorageClassName}
|
||||
out, err := k8shelper.Kubectl(args...)
|
||||
if err != nil && !utils.IsKubectlErrorNotFound(out, err) {
|
||||
return fmt.Errorf("failed to delete hostpath StorageClass: %v. %s", err, out)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -124,11 +124,6 @@ func (k8sh *K8sHelper) GetK8sServerVersion() string {
|
||||
return versionInfo.GitVersion
|
||||
}
|
||||
|
||||
func VersionAtLeast(actualVersion, minVersion string) bool {
|
||||
v := version.MustParseSemantic(actualVersion)
|
||||
return v.AtLeast(version.MustParseSemantic(minVersion))
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) VersionAtLeast(minVersion string) bool {
|
||||
v := version.MustParseSemantic(k8sh.GetK8sServerVersion())
|
||||
return v.AtLeast(version.MustParseSemantic(minVersion))
|
||||
@@ -1520,10 +1515,6 @@ func (k8sh *K8sHelper) CreateAnonSystemClusterBinding() {
|
||||
}
|
||||
}
|
||||
|
||||
func IsKubectlErrorNotFound(output string, err error) bool {
|
||||
return err != nil && strings.Contains(output, "Error from server (NotFound)")
|
||||
}
|
||||
|
||||
// WaitForDeploymentCount waits until the desired number of deployments with the label exist. The
|
||||
// deployments are not guaranteed to be running, only existing.
|
||||
func (k8sh *K8sHelper) WaitForDeploymentCount(label, namespace string, count int) error {
|
||||
|
||||
Reference in new issue
Block a user