Skip to content

Commit 6595770

Browse files
Merge pull request #2116 from metal3-io-bot/cherry-pick-2110-to-release-1.7
🌱 Use wget while downloading image
2 parents 62c96e9 + 2dbef38 commit 6595770

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

test/e2e/common.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,14 @@ func EnsureImage(k8sVersion string) (imageURL string, imageChecksum string) {
186186

187187
// DownloadFile will download a url and store it in local filepath.
188188
func DownloadFile(filePath string, url string) error {
189-
// Get the data
190-
/* #nosec G107 */
191-
resp, err := http.Get(url) //nolint:noctx
189+
// TODO: Lets change the wget to use go's native http client when network
190+
// more resilient
191+
cmd := exec.Command("wget", "-O", filePath, url)
192+
output, err := cmd.CombinedOutput()
192193
if err != nil {
193-
return err
194-
}
195-
if resp.StatusCode != http.StatusOK {
196-
return errors.Errorf("failed to download image from %q got %d %s", filePath, resp.StatusCode, http.StatusText(resp.StatusCode))
194+
return fmt.Errorf("wget failed: %v, output: %s", err, string(output))
197195
}
198-
defer resp.Body.Close()
199-
200-
// Create the file
201-
out, err := os.Create(filepath.Clean(filePath))
202-
if err != nil {
203-
return err
204-
}
205-
defer func() {
206-
err := out.Close()
207-
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error closing file: %s", filePath))
208-
}()
209-
210-
// Write the body to file
211-
_, err = io.Copy(out, resp.Body)
212-
return err
196+
return nil
213197
}
214198

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

0 commit comments

Comments
 (0)