From e4e373cd476a687c70e43dab8e1e40867211a17d Mon Sep 17 00:00:00 2001 From: karthik-us Date: Tue, 6 Jun 2023 18:46:27 +0530 Subject: [PATCH] e2e: Make getConfigFile() generic Update the getConfigFile() function to allow any file to be looked at on the preferred location first and fall back to the alternate location if it does not exist there. Signed-off-by: karthik-us --- e2e/cephfs.go | 2 +- e2e/nfs.go | 2 +- e2e/rbd.go | 2 +- e2e/utils.go | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index b10498e14..1a2388301 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -67,7 +67,7 @@ func deleteCephfsPlugin() { } func createORDeleteCephfsResources(action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/nfs.go b/e2e/nfs.go index 06d2f80b5..d06e06e4e 100644 --- a/e2e/nfs.go +++ b/e2e/nfs.go @@ -79,7 +79,7 @@ func deleteNFSPlugin() { } func createORDeleteNFSResources(f *framework.Framework, action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/rbd.go b/e2e/rbd.go index c820dee32..6bac023da 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -130,7 +130,7 @@ func deleteRBDPlugin() { } func createORDeleteRbdResources(action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/utils.go b/e2e/utils.go index 9150a791f..4a748f15d 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -1733,11 +1733,12 @@ func rwopMayFail(err error) bool { return !rwopSupported } -// getConfigFile returns the passed config file location if it exists, else -// returns the old location of the config file under 'examples/' directory. -func getConfigFile(configFile string) string { +// getConfigFile returns the config file path at the preferred location if it +// exists there. Returns the fallback location otherwise. +func getConfigFile(filename, preferred, fallback string) string { + configFile := preferred + filename if _, err := os.Stat(configFile); os.IsNotExist(err) { - configFile = examplePath + cephConfconfigMap + configFile = fallback + filename } return configFile