Class: Yast::InstDeployImageClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/lib/installation/clients/inst_deploy_image.rb

Instance Method Summary collapse

Instance Method Details

#mainObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 24

def main
  Yast.import "Pkg"
  Yast.import "Installation"
  Yast.import "ImageInstallation"
  Yast.import "Progress"
  Yast.import "Wizard"
  Yast.import "SourceManager"
  Yast.import "String"
  Yast.import "PackageCallbacks"
  Yast.import "SlideShow"
  Yast.import "Report"
  Yast.import "ProductFeatures"
  Yast.import "PackagesUI"
  Yast.import "Misc"

  textdomain "installation"

  # OEM image if target disk is defined
  oem_image = !InstData.image_target_disk.nil?

  if oem_image
    path = ProductFeatures.GetStringFeature("globals", "oem_image")
    ImageInstallation.PrepareOEMImage(path)
    Misc.boot_msg = _("The system will reboot now...")
  # There is nothing to do
  elsif !Installation.image_installation
    Builtins.y2milestone("No images have been selected")
    # bnc #395030
    # Use less memory
    ImageInstallation.FreeInternalVariables
    return :auto
  end

  Builtins.y2milestone("Deploying images")

  SlideShow.MoveToStage("images")

  @images = ImageInstallation.ImageOrder

  @last_image = nil

  @_last_download_progress = -1

  @_current_overall_progress = 0
  @_last_overall_progress = -1

  @_current_subprogress_start = 0
  @_current_subprogress_steps = 0
  @_current_subprogress_total = 0

  @_current_step_in_subprogress = 0

  @_previous_id = nil

  @_steps_for_one_image = 100
  @download_handler_hit = false
  @_last_image_downloading = nil
  @report_image_downloading = false

  @_last_progress = -1
  @_last_image_id = nil

  ImageInstallation.SetDeployTarImageProgress(
    fun_ref(method(:SetOneImageProgress), "void (integer)")
  )
  ImageInstallation.SetDownloadTarImageProgress(
    fun_ref(
      method(:MyProgressDownloadHandler),
      "boolean (integer, integer, integer)"
    )
  )
  ImageInstallation.SetStartDownloadImageProgress(
    fun_ref(method(:MyStartDownloadHandler), "void (string, string)")
  )
  ImageInstallation.SetOverallDeployingProgress(
    fun_ref(method(:OverallProgressHandler), "void (string, integer)")
  )

  ImageInstallation.AdjustProgressLayout(
    "deploying_images",
    Ops.multiply(@_steps_for_one_image, Builtins.size(@images)),
    _("Deploying Images...")
  )

  # Wizard::SetContents (
  #     _("Deploying Installation Images"),
  #     `VBox (
  #   `ProgressBar (
  #       `id ("one_image"),
  #       _("Initializing..."),
  #       100,
  #       0
  #   ),
  #   `ProgressBar (
  #       `id ("deploying_progress"),
  #       _("Deploying Images..."),
  #       100,
  #       0
  #   )
  #     ),
  #     // TRANSLATORS: help idi#1
  #     _("<p>System images are being deployed. Please wait...</p>") +
  #
  #     // TRANSLATORS: help idi#2
  #     _("<p>Installation images are part of the installation media.</p>") +
  #
  #     // TRANSLATORS: help idi#3
  #     _("<p>Installation from images is faster than installation from RPM packages
  # because it does not need to interact with a RPM database, locks etc.
  # One of the images also contains the joint RPM database and other metadata.</p>
  # ") +
  #
  #     // TRANSLATORS: help idi#4
  #     _("<p>If there is no direct access to installation images,
  # the installation program has to download them first before they are deployed.</p>
  # "),
  #     false, false
  # );

  # Stores all states of resolvables
  ImageInstallation.StoreAllChanges

  # Reset libzypp
  Pkg.TargetFinish

  # in case of OEM image deployment, there is no disk available
  if oem_image
    target = InstData.image_target_disk
  else
    # Set where the images will be downloaded
    SourceManager.InstInitSourceMoveDownloadArea
    target = Installation.destdir
  end
  @dep_ret = ImageInstallation.DeployImages(@images, target, nil)
  Builtins.y2milestone("DeployImages returned: %1", @dep_ret)

  # BNC #444209
  # false == error
  if @dep_ret == false
    Report.Error(
      _("Deploying images has failed.\nAborting the installation...\n")
    )
    Builtins.y2milestone("Aborting...")
    return :abort
    # nil   == aborted
  elsif @dep_ret.nil?
    Builtins.y2milestone("Aborting...")
    return :abort
  end

  Builtins.y2milestone("Target image for package selector prepared")

  # Load the libzypp state from the system (with images deployed)
  PackageCallbacks.RegisterEmptyProgressCallbacks
  if oem_image
    # TODO: later when adding more functionality: mount the deployed image for inst_finish
  else
    Pkg.TargetInitialize(Installation.destdir)
    Pkg.TargetLoad
    PackageCallbacks.RestorePreviousProgressCallbacks
  end

  # Restore the states stored by StoreAllChanges()
  if ImageInstallation.RestoreAllChanges != true
    Builtins.y2warning("Aborting...")
    return :abort
  end

  # BNC #436842 - debug feature in control file
  if ProductFeatures.GetBooleanFeature("globals", "debug_deploying") == true
    # TRANSLATORS: pop-up message
    Report.Message(
      _(
        "Debugging has been turned on.\n" \
        "YaST will open a software manager for you to check the current status of packages."
      )
    )
    RunPackageManager()
  end

  # bnc #395030
  # Use less memory
  ImageInstallation.FreeInternalVariables

  :next
end

#MyProgressDownloadHandler(percent, _bps_avg, bps_current) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 332

def MyProgressDownloadHandler(percent, _bps_avg, bps_current)
  # changing settings on the fly
  # ... first when download handler is hit
  #
  # if a repository is remote, there are twice more steps to do (download, deploy)
  # local (or NFS, SMB, ...) access do not use downloader
  if !@download_handler_hit
    Builtins.y2milestone("DownloadHandler - first hit")
    # twice more steps
    ImageInstallation.AdjustProgressLayout(
      "deploying_images",
      Ops.multiply(
        Ops.multiply(2, @_steps_for_one_image),
        Builtins.size(@images)
      ),
      _("Deploying Images...")
    )
    @download_handler_hit = true
  end

  # See MyStartDownloadHandler
  # BNC #449792
  return true if @report_image_downloading != true

  current_image = ImageInstallation.GetCurrentImageDetails

  if Ops.less_than(@_last_download_progress, percent)
    image_info = Ops.get_string(current_image, "name", "")

    # BNC 442286, new image
    # Sometimes it happens that the same image is logged twice
    if @_last_image_downloading != image_info
      Builtins.y2milestone("Downloading image: %1", image_info)
      @_last_image_downloading = image_info
    end

    # unknown image
    image_info = if image_info == ""
      Builtins.sformat(
        _("Downloading image at speed %1/s"),
        String.FormatSize(bps_current)
      )
    else
      Builtins.sformat(
        _("Downloading image %1 at speed %2/s"),
        image_info,
        String.FormatSize(bps_current)
      )
    end

    SlideShow.SubProgress(percent, image_info)

    current_image_nr = Ops.get_integer(current_image, "image_nr", 0)
    current_steps = if @download_handler_hit
      Ops.add(
        Ops.multiply(
          Ops.multiply(current_image_nr, 2),
          @_steps_for_one_image
        ),
        percent
      )
    else
      Ops.add(
        Ops.multiply(current_image_nr, @_steps_for_one_image),
        percent
      )
    end

    OverallProgressHandler("deploying_images", current_steps)
  end

  @_last_download_progress = percent

  true
end

#MyStartDownloadHandler(url, _localfile) ⇒ Object

Not only images but also some helper files are downloaded Image installation should report only images BNC #449792



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 301

def MyStartDownloadHandler(url, _localfile)
  current_image = ImageInstallation.GetCurrentImageDetails
  current_image_file = Ops.get_string(current_image, "file", "")

  # Fetches is (additionally) downloading some other file
  if current_image_file.nil? || current_image_file == ""
    Builtins.y2warning("Uknown image being downloaded: %1", current_image)
    @report_image_downloading = false
    return
  end

  image_filename_length = Builtins.size(current_image_file)
  # 'http://some.url/directory/image.name' vs. 'directory/image.name'
  image_url_download = Builtins.substring(
    url,
    Ops.subtract(Builtins.size(url), image_filename_length),
    image_filename_length
  )

  # downloading progress is reported only if
  @report_image_downloading = image_url_download == current_image_file

  Builtins.y2milestone(
    "Downloading started %1, showing progress %2",
    url,
    @report_image_downloading
  )

  nil
end

#OverallProgressHandler(id, current_step) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 221

def OverallProgressHandler(id, current_step)
  # new set of steps
  if @_previous_id != id
    # reset steps in subprogress
    @_current_step_in_subprogress = 0

    # new settings for new step
    @_current_subprogress_start = ImageInstallation.GetProgressLayoutDetails(
      id,
      "steps_start_at"
    )
    @_current_subprogress_steps = ImageInstallation.GetProgressLayoutDetails(
      id,
      "steps_reserved"
    )
    @_current_subprogress_total = ImageInstallation.GetProgressLayoutDetails(
      id,
      "steps_total"
    )

    # div by zero!
    if @_current_subprogress_total == 0
      Builtins.y2error("steps_total=0")
      @_current_subprogress_total = 1
    end

    Builtins.y2milestone(
      "New overall progress ID: %1 (steps_start_at: %2, steps_reserved: %3, steps_total: %4)",
      id,
      @_current_subprogress_start,
      @_current_subprogress_steps,
      @_current_subprogress_total
    )

    # when deploying images, label is handled separately
    if id != "deploying_images"
      new_label = ImageInstallation.GetProgressLayoutLabel(id)
      SlideShow.SubProgressStart(new_label)
    end

    @_previous_id = id
  end

  # incremental
  @_current_step_in_subprogress = if current_step.nil?
    Ops.add(
      @_current_step_in_subprogress,
      1
    )
    # set to exact number
  else
    current_step
  end

  SetProgress() if ["storing_user_prefs", "restoring_user_prefs"].include?(id)

  # Should be 0 - 100%
  @_current_overall_progress = Ops.add(
    @_current_subprogress_start,
    Ops.divide(
      Ops.multiply(
        @_current_subprogress_steps,
        @_current_step_in_subprogress
      ),
      @_current_subprogress_total
    )
  )

  # update UI only if nr% has changed
  if Ops.greater_than(@_current_overall_progress, @_last_overall_progress)
    @_last_overall_progress = @_current_overall_progress
    SlideShow.StageProgress(@_current_overall_progress, nil)
  end

  nil
end

#RunPackageManagerObject



485
486
487
488
489
490
491
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 485

def RunPackageManager
  Builtins.y2milestone("--- running the package manager ---")
  PackagesUI.RunPackageSelector("mode" => :summaryMode)
  Builtins.y2milestone("--- running the package manager ---")

  nil
end

#SetOneImageProgress(current_progress) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 408

def SetOneImageProgress(current_progress)
  current_image = ImageInstallation.GetCurrentImageDetails
  max_progress = Ops.get_integer(current_image, "max_progress", 0)

  another_image = false

  # another file than the previous one
  if Ops.get_string(current_image, "file", "") != @_last_image_id
    another_image = true
    @_last_image_id = Ops.get_string(current_image, "file", "")
    @_last_download_progress = -1
    @_last_progress = -1
  end

  if max_progress.nil? || max_progress == 0
    Builtins.y2milestone("Can't find max_progress: %1", current_image)
    return
  end

  # current progress 0 - 100
  x_progress = Ops.divide(Ops.multiply(100, current_progress), max_progress)
  x_progress = 100 if Ops.greater_than(x_progress, 100)

  # reset the label
  if x_progress == 0
    current_image_name = Ops.get_string(current_image, "name", "")

    current_image_name = if current_image_name == ""
      _("Deploying image...")
    else
      Builtins.sformat(
        _("Deploying image %1..."),
        current_image_name
      )
    end

    if another_image == true
      # one image done (another than the previous one)
      # BNC #442286
      SlideShow.SubProgressStart(current_image_name)
      SlideShow.AppendMessageToInstLog(current_image_name)
    else
      Builtins.y2warning(
        "The same image name again: %1 (100 * %2 / %3)",
        current_image_name,
        current_progress,
        max_progress
      )
    end
  end

  # set current step
  if Ops.greater_than(x_progress, @_last_progress)
    SlideShow.SubProgress(x_progress, nil)
    @_last_progress = x_progress
    current_image_nr = Ops.get_integer(current_image, "image_nr", 0)
    current_steps = if @download_handler_hit
      Ops.add(
        Ops.multiply(
          Ops.add(Ops.multiply(current_image_nr, 2), 1),
          @_steps_for_one_image
        ),
        x_progress
      )
    else
      Ops.add(
        Ops.multiply(current_image_nr, @_steps_for_one_image),
        x_progress
      )
    end

    OverallProgressHandler("deploying_images", current_steps)
  end

  nil
end

#SetProgressObject



211
212
213
214
215
216
217
218
219
# File 'src/lib/installation/clients/inst_deploy_image.rb', line 211

def SetProgress
  percent = Ops.divide(
    Ops.multiply(100, @_current_step_in_subprogress),
    @_current_subprogress_total
  )
  SlideShow.SubProgress(percent, nil)

  nil
end