Skip to content

Commit

Permalink
Merge pull request #2110 from Nordix/kashif/fix-downloadImage-withExp…
Browse files Browse the repository at this point in the history
…onentialBackoff

 🌱 Use wget while downloading image
  • Loading branch information
metal3-io-bot authored Nov 26, 2024
2 parents 476b7e1 + f4dbb7e commit 18c723a
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,14 @@ func EnsureImage(k8sVersion string) (imageURL string, imageChecksum string) {

// DownloadFile will download a url and store it in local filepath.
func DownloadFile(filePath string, url string) error {
// Get the data
/* #nosec G107 */
resp, err := http.Get(url) //nolint:noctx
// TODO: Lets change the wget to use go's native http client when network
// more resilient
cmd := exec.Command("wget", "-O", filePath, url)
output, err := cmd.CombinedOutput()
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return errors.Errorf("failed to download image from %q got %d %s", filePath, resp.StatusCode, http.StatusText(resp.StatusCode))
return fmt.Errorf("wget failed: %v, output: %s", err, string(output))
}
defer resp.Body.Close()

// Create the file
out, err := os.Create(filepath.Clean(filePath))
if err != nil {
return err
}
defer func() {
err := out.Close()
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error closing file: %s", filePath))
}()

// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
return nil
}

// FilterBmhsByProvisioningState returns a filtered list of BaremetalHost objects in certain provisioning state.
Expand Down

0 comments on commit 18c723a

Please sign in to comment.