Skip to content

Commit 4689dbf

Browse files
authored
chore: Update image roundtrip test (#1469)
- image roundtrip test fails due to the sporadic, but often, 403 returned by the remote. - implement image download retry mechanism. - update cirros image to 0.6.3
1 parent 07b2500 commit 4689dbf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

openstack_cli/tests/image/v2/image/file/roundtrip.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ pub async fn download_with_md5_and_filename(
2929
url: &str,
3030
tmp_dir: &TempDir,
3131
) -> Result<(PathBuf, String), Box<dyn Error>> {
32-
let client = Client::new();
32+
let retries = reqwest::retry::for_host("download.cirros-cloud.net")
33+
.max_retries_per_request(3)
34+
.classify_fn(|req_rep| {
35+
if req_rep.status() == Some(http::StatusCode::FORBIDDEN) {
36+
req_rep.retryable()
37+
} else {
38+
req_rep.success()
39+
}
40+
});
41+
let client = Client::builder().retry(retries).gzip(true).build()?;
3342
let response = client.get(url).send().await?;
3443
response.error_for_status_ref()?; // fail fast on HTTP errors
3544

@@ -88,7 +97,7 @@ fn extract_filename_from_url(url: &str) -> Option<String> {
8897
#[tokio::test]
8998
async fn image_upload_download_roundtrip() -> Result<(), Box<dyn std::error::Error>> {
9099
let tmp_dir = Builder::new().prefix("data").tempdir()?;
91-
let cirros_ver = "0.6.2";
100+
let cirros_ver = "0.6.3";
92101
let target = format!(
93102
"http://download.cirros-cloud.net/{ver}/cirros-{ver}-x86_64-disk.img",
94103
ver = cirros_ver
@@ -97,7 +106,7 @@ async fn image_upload_download_roundtrip() -> Result<(), Box<dyn std::error::Err
97106
.await
98107
.expect("Download failed");
99108
assert_eq!(
100-
"c8fc807773e5354afe61636071771906", checksum,
109+
"87617e24a5e30cb3b87fda8c0764838f", checksum,
101110
"Download checksum matches the expected"
102111
);
103112

0 commit comments

Comments
 (0)