From 4a997f03b7696bce7b3022e319762137792147fe Mon Sep 17 00:00:00 2001 From: Xue Li Date: Sat, 3 Aug 2024 21:17:15 +0800 Subject: [PATCH] OCM-10085 | ci: fix external-auth profile failure and introduce more logs --- tests/utils/config/support.go | 28 +++++++----------- tests/utils/exec/occli/cmd_client.go | 44 +++++++++++++++------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/tests/utils/config/support.go b/tests/utils/config/support.go index 1b73365cd8..664060e47a 100644 --- a/tests/utils/config/support.go +++ b/tests/utils/config/support.go @@ -3,7 +3,6 @@ package config import ( "fmt" "path" - "strings" "time" "github.com/openshift/rosa/tests/ci/config" @@ -15,6 +14,8 @@ import ( // Only for HCP cluster now func DeployCilium(ocClient *occli.Client, podCIDR string, hostPrefix string, outputDir string, kubeconfigFile string) error { + var err error + ciliumVersion := "1.14.5" yamlFileNames := []string{ "cluster-network-03-cilium-ciliumconfigs-crd.yaml", @@ -33,20 +34,13 @@ func DeployCilium(ocClient *occli.Client, podCIDR string, hostPrefix string, out } url := "https://raw.githubusercontent.com/isovalent/olm-for-cilium/main/manifests" - for _, n := range yamlFileNames { - stdout, err := ocClient.Run( - fmt.Sprintf("oc apply -f %s/cilium.v%s/%s", url, ciliumVersion, n)) - time.Sleep(3 * time.Second) - + for _, yamlFile := range yamlFileNames { + _, err = ocClient.Run( + fmt.Sprintf("oc apply -f %s/cilium.v%s/%s", url, ciliumVersion, yamlFile), + 3, + ) if err != nil { - if strings.Contains(err.Error(), "Warning") { - stdout, err = ocClient.Run( - fmt.Sprintf("oc apply -f %s/cilium.v%s/%s", url, ciliumVersion, n)) - } - if err != nil { - log.Logger.Errorf("%s:%s", stdout, err.Error()) - return err - } + return err } } @@ -58,7 +52,7 @@ func DeployCilium(ocClient *occli.Client, podCIDR string, hostPrefix string, out resultFile := path.Join(outputDir, "cilium.yaml") - _, _, err := occli.RunCMD( + _, _, err = occli.RunCMD( fmt.Sprintf("cat %s | sed -e 's/HOSTPREFIX/%v/g' >> %s", fileName, hostPrefix, resultFile)) if err != nil { return err @@ -69,12 +63,12 @@ func DeployCilium(ocClient *occli.Client, podCIDR string, hostPrefix string, out return err } - stdout, err := ocClient.Run(fmt.Sprintf("oc apply -f %s --kubeconfig %s", resultFile, kubeconfigFile)) - time.Sleep(3 * time.Second) + stdout, err := ocClient.Run(fmt.Sprintf("oc apply -f %s --kubeconfig %s", resultFile, kubeconfigFile), 3) if err != nil { log.Logger.Errorf("%s", stdout) return err } + time.Sleep(3 * time.Second) return err } diff --git a/tests/utils/exec/occli/cmd_client.go b/tests/utils/exec/occli/cmd_client.go index d8a66275fa..5b3a965dce 100644 --- a/tests/utils/exec/occli/cmd_client.go +++ b/tests/utils/exec/occli/cmd_client.go @@ -5,6 +5,9 @@ import ( "fmt" "os/exec" "strings" + "time" + + "github.com/openshift/rosa/tests/utils/log" ) type Client struct { @@ -23,28 +26,26 @@ func NewOCClient(kubePath ...string) *Client { return ocClient } -type RunCMDError struct { - Stderr string - Err error - CMD string -} - -func (ocClient Client) Run(cmd string, pipeCommands ...string) (stdout string, err error) { - +func (ocClient Client) Run(cmd string, retryTimes int, pipeCommands ...string) (stdout string, err error) { var stderr string - fmt.Println(">> Running CMD: ", cmd) - var pipeCommand string - for _, command := range pipeCommands { - pipeCommand += fmt.Sprintf("|%s", command) - } - cmd = fmt.Sprintf("%s --kubeconfig %s %s", cmd, ocClient.KubePath, pipeCommand) - stdout, stderr, err = RunCMD(cmd) - if err != nil { - t := &RunCMDError{Stderr: stderr, Err: err, CMD: cmd} - err = t.Err + for retryTimes > 0 { + log.Logger.Info("Running CMD: ", cmd) + var pipeCommand string + for _, command := range pipeCommands { + pipeCommand += fmt.Sprintf("|%s", command) + } + cmd = fmt.Sprintf("%s --kubeconfig %s %s", cmd, ocClient.KubePath, pipeCommand) + stdout, stderr, err = RunCMD(cmd) + if err != nil { + log.Logger.Errorf("Got output: %s", stderr) + } else { + stdout = strings.TrimSuffix(stdout, "\n") + log.Logger.Infof("Got output: %s", stdout) + return + } + time.Sleep(3 * time.Second) + retryTimes-- } - stdout = strings.TrimSuffix(stdout, "\n") - fmt.Println(">> Got STDOUT: ", stdout) return } @@ -57,6 +58,9 @@ func RunCMD(cmd string) (stdout string, stderr string, err error) { err = CMD.Run() stdout = strings.TrimPrefix(stdoutput.String(), "\n") stderr = strings.TrimPrefix(stderroutput.String(), "\n") + if err != nil { + err = fmt.Errorf("%s:%s", err.Error(), stderr) + } return }