Files
my-rook-config/tests/framework/installer/environment.go
T

82 lines
2.1 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.
*/
2018-08-21 15:24:52 -06:00
package installer
2017-06-26 21:52:06 -07:00
import (
2020-04-13 16:10:39 -06:00
"os"
2025-06-11 18:48:43 +02:00
"os/exec"
2017-06-26 21:52:06 -07:00
)
2025-06-11 18:48:43 +02:00
// TestHelmPath gets the path of the helm binary
func TestHelmPath() string {
helmPath := os.Getenv("TEST_HELM_PATH")
if helmPath == "" {
if path, err := exec.LookPath("helm"); err == nil {
helmPath = path
}
}
return helmPath
2020-04-13 16:10:39 -06:00
}
// TestLogCollectionLevel gets whether to collect all logs
func TestLogCollectionLevel() string {
return getEnvVarWithDefault("TEST_LOG_COLLECTION_LEVEL", "")
}
2020-08-31 12:33:57 +05:30
func StorageClassName() string {
return getEnvVarWithDefault("TEST_STORAGE_CLASS", "")
}
func UsePVC() bool {
return StorageClassName() != ""
}
2020-04-13 16:10:39 -06:00
// baseTestDir gets the base test directory
2020-08-06 06:51:17 +00:00
func baseTestDir() (string, error) {
// If the base test directory is actively set to WORKING_DIR (as in CI),
// we use the current working directory.
2020-04-13 16:10:39 -06:00
val := getEnvVarWithDefault("TEST_BASE_DIR", "/data")
if val == "WORKING_DIR" {
2020-08-06 06:51:17 +00:00
var err error
val, err = os.Getwd()
if err != nil {
return "", err
}
2020-04-13 16:10:39 -06:00
}
2020-08-06 06:51:17 +00:00
return val, nil
2020-04-13 16:10:39 -06:00
}
// TestScratchDevice get the scratch device to be used for OSD
func TestScratchDevice() string {
2020-08-31 20:50:47 +02:00
return getEnvVarWithDefault("TEST_SCRATCH_DEVICE", "/dev/nvme0n1")
}
2020-11-17 18:46:00 +05:30
// getDeviceFilter get the device name used for OSD
func getDeviceFilter() string {
return getEnvVarWithDefault("DEVICE_FILTER", `""`)
2020-11-17 18:46:00 +05:30
}
2020-04-13 16:10:39 -06:00
func getEnvVarWithDefault(env, defaultValue string) string {
val := os.Getenv(env)
if val == "" {
logger.Infof("test environment variable (default) %q=%q", env, defaultValue)
2020-04-13 16:10:39 -06:00
return defaultValue
}
logger.Infof("test environment variable %q=%q", env, val)
2020-04-13 16:10:39 -06:00
return val
2017-06-26 21:52:06 -07:00
}