Skip to content

Commit

Permalink
Merge pull request #2116 from metal3-io-bot/cherry-pick-2110-to-relea…
Browse files Browse the repository at this point in the history
…se-1.7

🌱 Use wget while downloading image
  • Loading branch information
metal3-io-bot authored Nov 28, 2024
2 parents 62c96e9 + 2dbef38 commit 6595770
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 @@ -186,30 +186,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 6595770

Please sign in to comment.