environment.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright 2016 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package installer
  14. import (
  15. "os"
  16. )
  17. // testHelmPath gets the helm path
  18. func testHelmPath() string {
  19. return getEnvVarWithDefault("TEST_HELM_PATH", "/tmp/rook-tests-scripts-helm/helm")
  20. }
  21. // TestLogCollectionLevel gets whether to collect all logs
  22. func TestLogCollectionLevel() string {
  23. return getEnvVarWithDefault("TEST_LOG_COLLECTION_LEVEL", "")
  24. }
  25. func StorageClassName() string {
  26. return getEnvVarWithDefault("TEST_STORAGE_CLASS", "")
  27. }
  28. func UsePVC() bool {
  29. return StorageClassName() != ""
  30. }
  31. // baseTestDir gets the base test directory
  32. func baseTestDir() (string, error) {
  33. // If the base test directory is actively set to WORKING_DIR (as in CI),
  34. // we use the current working directory.
  35. val := getEnvVarWithDefault("TEST_BASE_DIR", "/data")
  36. if val == "WORKING_DIR" {
  37. var err error
  38. val, err = os.Getwd()
  39. if err != nil {
  40. return "", err
  41. }
  42. }
  43. return val, nil
  44. }
  45. // TestScratchDevice get the scratch device to be used for OSD
  46. func TestScratchDevice() string {
  47. return getEnvVarWithDefault("TEST_SCRATCH_DEVICE", "/dev/nvme0n1")
  48. }
  49. // getDeviceFilter get the device name used for OSD
  50. func getDeviceFilter() string {
  51. return getEnvVarWithDefault("DEVICE_FILTER", `""`)
  52. }
  53. func getEnvVarWithDefault(env, defaultValue string) string {
  54. val := os.Getenv(env)
  55. if val == "" {
  56. logger.Infof("test environment variable (default) %q=%q", env, defaultValue)
  57. return defaultValue
  58. }
  59. logger.Infof("test environment variable %q=%q", env, val)
  60. return val
  61. }