@@ -25,7 +25,7 @@ use update_engine::StepResult;
2525
2626use crate :: {
2727 ArtifactWriter , WriteDestination ,
28- artifact:: { ArtifactIdOpts , ArtifactsToDownload , LookupIdKind } ,
28+ artifact:: { ArtifactIdOpts , ArtifactsToDownload } ,
2929 fetch:: { FetchArtifactBackend , FetchedArtifact , HttpFetchBackend } ,
3030 peers:: DiscoveryMechanism ,
3131 reporter:: { HttpProgressBackend , ProgressReporter , ReportProgressBackend } ,
@@ -209,121 +209,102 @@ impl InstallOpts {
209209
210210 let engine = UpdateEngine :: new ( log, event_sender) ;
211211
212- let to_download = match lookup_id. kind {
213- LookupIdKind :: Document ( hash) => {
214- engine
215- . new_step (
216- InstallinatorComponent :: InstallinatorDocument ,
217- InstallinatorStepId :: Download ,
218- "Downloading installinator document" ,
219- async move |cx| {
220- let installinator_doc_id = ArtifactHashId {
221- kind : KnownArtifactKind :: InstallinatorDocument
222- . into ( ) ,
223- hash,
224- } ;
225- let installinator_doc = fetch_artifact (
226- & cx,
227- & installinator_doc_id,
228- discovery,
229- log,
230- )
231- . await ?;
212+ let to_download = engine
213+ . new_step (
214+ InstallinatorComponent :: InstallinatorDocument ,
215+ InstallinatorStepId :: Download ,
216+ "Downloading installinator document" ,
217+ async move |cx| {
218+ let installinator_doc_id = ArtifactHashId {
219+ kind : KnownArtifactKind :: InstallinatorDocument . into ( ) ,
220+ hash : lookup_id. document ,
221+ } ;
222+ let installinator_doc = fetch_artifact (
223+ & cx,
224+ & installinator_doc_id,
225+ discovery,
226+ log,
227+ )
228+ . await ?;
232229
233- // Check that the sha256 of the data we got from
234- // wicket matches the data we asked for.
235- //
236- // If this fails, we fail the entire installation
237- // rather than trying to fetch the artifact again,
238- // because we're fetching data from wicketd (cached
239- // in a temp dir) over TCP to ourselves (in memory),
240- // so the only cases where this could fail are
241- // disturbing enough (memory corruption, corruption
242- // under TCP, or wicketd gave us something other
243- // than what we requested) we want to know
244- // immediately and not retry: it's likely an
245- // operator could miss any warnings we emit if a
246- // retry succeeds.
247- check_downloaded_artifact_hash (
248- "installinator document" ,
249- installinator_doc. artifact . clone ( ) ,
250- installinator_doc_id. hash ,
251- )
252- . await ?;
230+ // Check that the sha256 of the data we got from
231+ // wicket matches the data we asked for.
232+ //
233+ // If this fails, we fail the entire installation
234+ // rather than trying to fetch the artifact again,
235+ // because we're fetching data from wicketd (cached
236+ // in a temp dir) over TCP to ourselves (in memory),
237+ // so the only cases where this could fail are
238+ // disturbing enough (memory corruption, corruption
239+ // under TCP, or wicketd gave us something other
240+ // than what we requested) we want to know
241+ // immediately and not retry: it's likely an
242+ // operator could miss any warnings we emit if a
243+ // retry succeeds.
244+ check_downloaded_artifact_hash (
245+ "installinator document" ,
246+ installinator_doc. artifact . clone ( ) ,
247+ installinator_doc_id. hash ,
248+ )
249+ . await ?;
253250
254- // Read the document as JSON.
255- //
256- // Going via the reader is slightly less efficient
257- // than operating purely in-memory, but serde_json
258- // doesn't have a good way to pass in a BufList
259- // directly.
260- let json: InstallinatorDocument =
261- serde_json:: from_reader ( buf_list:: Cursor :: new (
262- & installinator_doc. artifact ,
263- ) )
264- . context (
265- "error deserializing \
251+ // Read the document as JSON.
252+ //
253+ // Going via the reader is slightly less efficient
254+ // than operating purely in-memory, but serde_json
255+ // doesn't have a good way to pass in a BufList
256+ // directly.
257+ let json: InstallinatorDocument = serde_json:: from_reader (
258+ buf_list:: Cursor :: new ( & installinator_doc. artifact ) ,
259+ )
260+ . context (
261+ "error deserializing \
266262 installinator document",
267- ) ?;
268-
269- // Every valid installinator document must have the
270- // host phase 2 and control plane hashes.
271- let mut host_phase_2_hash = None ;
272- let mut control_plane_hash = None ;
273- for artifact in & json. artifacts {
274- match artifact. kind {
275- InstallinatorArtifactKind :: HostPhase2 => {
276- host_phase_2_hash = Some ( artifact. hash ) ;
277- }
278- InstallinatorArtifactKind :: ControlPlane => {
279- control_plane_hash =
280- Some ( artifact. hash ) ;
281- }
282- }
283- }
284-
285- // Return an error if either the host phase 2 or the
286- // control plane artifacts are missing.
287- let mut missing = Vec :: new ( ) ;
288- if host_phase_2_hash. is_none ( ) {
289- missing. push (
290- InstallinatorArtifactKind :: HostPhase2 ,
291- ) ;
263+ ) ?;
264+
265+ // Every valid installinator document must have the
266+ // host phase 2 and control plane hashes.
267+ let mut host_phase_2_hash = None ;
268+ let mut control_plane_hash = None ;
269+ for artifact in & json. artifacts {
270+ match artifact. kind {
271+ InstallinatorArtifactKind :: HostPhase2 => {
272+ host_phase_2_hash = Some ( artifact. hash ) ;
292273 }
293- if control_plane_hash. is_none ( ) {
294- missing. push (
295- InstallinatorArtifactKind :: ControlPlane ,
296- ) ;
274+ InstallinatorArtifactKind :: ControlPlane => {
275+ control_plane_hash = Some ( artifact. hash ) ;
297276 }
298- if !missing. is_empty ( ) {
299- bail ! (
300- "installinator document missing \
277+ }
278+ }
279+
280+ // Return an error if either the host phase 2 or the
281+ // control plane artifacts are missing.
282+ let mut missing = Vec :: new ( ) ;
283+ if host_phase_2_hash. is_none ( ) {
284+ missing. push ( InstallinatorArtifactKind :: HostPhase2 ) ;
285+ }
286+ if control_plane_hash. is_none ( ) {
287+ missing. push ( InstallinatorArtifactKind :: ControlPlane ) ;
288+ }
289+ if !missing. is_empty ( ) {
290+ bail ! (
291+ "installinator document missing \
301292 required artifacts: {:?}",
302- missing
303- ) ;
304- }
293+ missing
294+ ) ;
295+ }
305296
306- StepSuccess :: new ( ArtifactsToDownload {
307- host_phase_2 : host_phase_2_hash. expect (
308- "host phase 2 is Some, checked above" ,
309- ) ,
310- control_plane : control_plane_hash. expect (
311- "control plane is Some, checked above" ,
312- ) ,
313- } )
314- . into ( )
315- } ,
316- )
317- . register ( )
318- }
319- LookupIdKind :: Hashes { host_phase_2, control_plane } => {
320- StepHandle :: ready ( ArtifactsToDownload {
321- host_phase_2,
322- control_plane,
323- } )
324- }
325- }
326- . into_shared ( ) ;
297+ StepSuccess :: new ( ArtifactsToDownload {
298+ host_phase_2 : host_phase_2_hash
299+ . expect ( "host phase 2 is Some, checked above" ) ,
300+ control_plane : control_plane_hash
301+ . expect ( "control plane is Some, checked above" ) ,
302+ } )
303+ . into ( )
304+ } ,
305+ )
306+ . register ( )
307+ . into_shared ( ) ;
327308
328309 let to_download_2 = to_download. clone ( ) ;
329310 let to_download_3 = to_download_2. clone ( ) ;
0 commit comments