Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
16 changes: 14 additions & 2 deletions tests/e2e/vmservice_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down