balena-os / takeover

Migrate arbitrary devices to balena
12 stars 8 forks source link

Failed image download not recognized #83

Open kb2ma opened 3 months ago

kb2ma commented 3 months ago

The code to download an OS image does not verify that an image actually is returned. In the example below, the result status is 404. Should at least verify the result status is 2xx. Maybe also display the response body. In the case below it was "Error downloading application image".

$ ./takeover -d -c config.json --version 5.3.4+rev3 --log-level debug
...
17:08:52 INFO  Downloading Balena OS image, selected version is: '5.3.4+rev3'
17:08:53 DEBUG [reqwest::connect] starting new connection: https://api.balena-cloud.com/
17:08:53 DEBUG [takeover::stage1::api_calls] dt_contract_request Result = Response { url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.balena-cloud.com")), port: None, path: "/v6/device_type", query: Some("$orderby=name%20asc&$top=1&$select=contract&$filter=device_type_alias/any(dta:dta/is_referenced_by__alias%20eq%20%27beaglebone-black%27)"), fragment: None }, status: 200, headers: {"date": "Sun, 30 Jun 2024 17:08:53 GMT", "content-type": "application/json; charset=utf-8", "transfer-encoding": "chunked", "connection": "keep-alive", "cache-control": "no-cache", "etag": "W/\"2a39-f9gfLUhNzd0N0jGbXz/ID/w/inE\"", "vary": "Accept-Encoding", "cf-cache-status": "DYNAMIC", "strict-transport-security": "max-age=15552000", "server": "cloudflare", "cf-ray": "89bfc2c86cc2904b-BOS", "alt-svc": "h3=\":443\"; ma=86400"} }
17:08:53 DEBUG [takeover::stage1::api_calls] Device contract for beaglebone-black is DeviceTypeContractInfo { contract: Contract { data: ContractData { media: Media { alt_boot: Some(["sdcard"]), default_boot: "internal" }, flash_protocol: None } } }
17:08:53 DEBUG [takeover::stage1::api_calls] Downloading raw image for device type beaglebone-black
17:08:53 DEBUG [takeover::stage1::api_calls] get_os_image: request_url: 'https://api.balena-cloud.com/download'
17:08:53 DEBUG [takeover::stage1::api_calls] get_os_image: data: 'ImageRequestData { device_type: "beaglebone-black", version: "5.3.4+rev3", file_type: ".gz", image_type: Some("raw") }'
17:08:53 DEBUG [reqwest::connect] starting new connection: https://api.balena-cloud.com/
17:08:53 DEBUG [takeover::stage1::api_calls] Result = Response { url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.balena-cloud.com")), port: None, path: "/download", query: None, fragment: None }, status: 404, headers: {"date": "Sun, 30 Jun 2024 17:08:53 GMT", "content-type": "application/json; charset=utf-8", "content-length": "37", "connection": "keep-alive", "vary": "X-HTTP-Method-Override, Accept-Encoding", "etag": "W/\"25-myxgCtuBvOanXmid4jQRrGznqms\"", "cf-cache-status": "DYNAMIC", "strict-transport-security": "max-age=15552000", "server": "cloudflare", "cf-ray": "89bfc2ca88338f6d-BOS", "alt-svc": "h3=\":443\"; ma=86400"} }
17:08:53 DEBUG [takeover::stage1::image_retrieval] Downloading file '/home/debian/migrate/balena-cloud-beaglebone-black-5.3.4+rev3.img.gz'
17:08:53 INFO  37 B read in 0 seconds @37 B/sec 
17:08:53 INFO  The balena OS image was successfully written to '/home/debian/migrate/balena-cloud-beaglebone-black-5.3.4+rev3.img.gz'