diff --git a/tests/e2e/util.go b/tests/e2e/util.go index f9aeb63c41..7b36f3a75a 100644 --- a/tests/e2e/util.go +++ b/tests/e2e/util.go @@ -1543,10 +1543,21 @@ func checkVcenterServicesRunning( // httpRequest takes client and http Request as input and performs GET operation // and returns bodybytes func httpRequest(client *http.Client, req *http.Request) ([]byte, int) { + var bodyBytes []byte resp, err := client.Do(req) gomega.Expect(err).NotTo(gomega.HaveOccurred()) defer resp.Body.Close() - bodyBytes, err := io.ReadAll(resp.Body) + + maxRetries := 3 + for attempt := 1; attempt <= maxRetries; attempt++ { + framework.Logf("Attempt %d of httpRequest ", attempt) + // Create the request + bodyBytes, err = io.ReadAll(resp.Body) + if err == nil { + break + } + time.Sleep(pollTimeoutShort) + } framework.Logf("API Response status %d", resp.StatusCode) gomega.Expect(err).NotTo(gomega.HaveOccurred()) diff --git a/tests/e2e/vmservice_utils.go b/tests/e2e/vmservice_utils.go index 7b76267d6c..22c1443bc9 100644 --- a/tests/e2e/vmservice_utils.go +++ b/tests/e2e/vmservice_utils.go @@ -331,12 +331,24 @@ func invokeVCRestAPIGetRequest(vcRestSessionId string, url string) ([]byte, int) // invokeVCRestAPIPostRequest invokes POST on given VC REST URL using the passed session token and request body func invokeVCRestAPIPostRequest(vcRestSessionId string, url string, reqBody string) ([]byte, int) { + var err error + var req *http.Request + transCfg := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } httpClient := &http.Client{Transport: transCfg} - framework.Logf("Invoking POST on url: %s", url) - req, err := http.NewRequest("POST", url, strings.NewReader(reqBody)) + + maxRetries := 3 + for attempt := 1; attempt <= maxRetries; attempt++ { + framework.Logf("Attempt %d: Invoking POST on URL: %s", attempt, url) + + req, err = http.NewRequest("POST", url, strings.NewReader(reqBody)) + if err == nil { + break + } + time.Sleep(pollTimeoutShort) + } gomega.Expect(err).NotTo(gomega.HaveOccurred()) req.Header.Add(vcRestSessionIdHeaderName, vcRestSessionId) req.Header.Add("Content-type", "application/json")