• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-kdump / 3624339857

pending completion
3624339857

Pull #132

github

Unknown Committer
Unknown Commit Message
Pull Request #132: add support for fadump keys in kdumptool calibrate

12 of 12 new or added lines in 1 file covered. (100.0%)

749 of 1831 relevant lines covered (40.91%)

4.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.1
/src/include/kdump/uifunctions.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2006 Novell, Inc. All Rights Reserved.
5
#
6
#
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of version 2 of the GNU General Public License as published by the
9
# Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail, you may find
19
# current contact information at www.novell.com.
20
# ------------------------------------------------------------------------------
21

22
# File:        clients/kdump.ycp
23
# Package:        Configuration of kdump
24
# Summary:        Main file
25
# Authors:        Jozef Uhliarik <juhliarik@suse.com>
26
#
27
# $Id: kdump.ycp 27914 2006-02-13 14:32:08Z locilka $
28
#
29
# Main file for kdump configuration. Uses all other files.
30
module Yast
1✔
31
  module KdumpUifunctionsInclude
1✔
32
    def initialize_kdump_uifunctions(_include_target)
1✔
33
      textdomain "kdump"
14✔
34

35
      Yast.import "Popup"
14✔
36
      Yast.import "Kdump"
14✔
37
      Yast.import "Service"
14✔
38
      Yast.import "Package"
14✔
39
      Yast.import "Package"
14✔
40
      Yast.import "Mode"
14✔
41

42
      # EXAMPLE FUNCTIONS
43
      #    void ExampleInit(string key) {
44
      #        y2milestone("Example Init");
45
      #    }
46
      #
47
      #    symbol ExampleHandle(string key, map event) {
48
      #        any ret = event["ID"]:nil;
49
      #        y2milestone("Example Handle");
50
      #        return nil;
51
      #    }
52
      #
53
      #    void ExampleStore(string key, map event) {
54
      #        any ret = event["ID"]:nil;
55
      #        y2milestone("Example Store");
56
      #    }
57
      #
58

59
      @set_network = false
14✔
60

61
      @set_kdump_append = false
14✔
62

63
      # map of values for "KDUMP_SAVEDIR"
64
      #
65
      # local map <string, string >
66
      @KDUMP_SAVE_TARGET = {
67
        "target"    => "file", # ftp, ssh, nfs, cifs
14✔
68
        "server"    => "",
69
        "dir"       => "",
70
        "user_name" => "", # empty means anonymous
71
        "port"      => "", # deafults ftp: 21 ssh:22
72
        "share"     => "",
73
        "password"  => ""
74
      }
75

76
      @type = "local_filesystem"
14✔
77

78
      # definition UI terms for saveing dump target
79
      #
80
      # terms
81

82
      @local_filesystem = VBox(
14✔
83
        Frame(
84
          _("Local Filesystem"),
85
          HBox(
86
            HSpacing(1),
87
            VBox(
88
              Left(
89
                HBox(
90
                  InputField(Id("dir"), _("&Directory for Saving Dumps")),
91
                  VBox(
92
                    Label(""),
93
                    PushButton(Id("select_dir"), _("B&rowse"))
94
                  )
95
                )
96
              )
97
            )
98
          )
99
        )
100
      )
101

102
      @ftp = VBox(
14✔
103
        Frame(
104
          _("FTP"),
105
          HBox(
106
            HSpacing(1),
107
            VBox(
108
              Left(
109
                HBox(
110
                  Left(InputField(Id("server"), _("Server Nam&e"))),
111
                  HSpacing(1),
112
                  Left(IntField(Id("port"), _("P&ort"), 0, 65536, 21)),
113
                  HStretch()
114
                )
115
              ),
116
              # text entry
117
              Left(InputField(Id("dir"), _("&Directory on Server"))),
118
              Left(
119
                CheckBox(
120
                  Id("anonymous"),
121
                  Opt(:notify),
122
                  _("Enable Anon&ymous FTP")
123
                )
124
              ),
125
              Left(
126
                HBox(
127
                  # text entry
128
                  Left(InputField(Id("user_name"), _("&User Name"))),
129
                  HSpacing(1),
130
                  # password entry
131
                  Left(Password(Id("password"), _("&Password")))
132
                )
133
              )
134
            )
135
          )
136
        )
137
      )
138

139
      @ssh = VBox(
14✔
140
        Frame(
141
          _("SSH / SFTP"),
142
          HBox(
143
            HSpacing(1),
144
            VBox(
145
              Left(
146
                HBox(
147
                  Left(InputField(Id("server"), _("Server Nam&e"))),
148
                  HSpacing(1),
149
                  Left(IntField(Id("port"), _("P&ort"), 0, 65536, 22)),
150
                  HStretch()
151
                )
152
              ),
153
              Left(InputField(Id("dir"), _("&Directory on Server"))),
154
              # text entry
155
              Left(
156
                HBox(
157
                  # text entry
158
                  Left(InputField(Id("user_name"), _("&User Name"))),
159
                  HSpacing(1),
160
                  # password entry
161
                  Left(Password(Id("password"), _("&Password")))
162
                )
163
              )
164
            )
165
          )
166
        )
167
      )
168

169
      @nfs = VBox(
14✔
170
        Frame(
171
          _("NFS"),
172
          HBox(
173
            HSpacing(1),
174
            VBox(
175
              Left(InputField(Id("server"), _("Server Nam&e"))),
176
              # text entry
177
              Left(InputField(Id("dir"), _("&Directory on Server")))
178
            )
179
          )
180
        )
181
      )
182

183
      @cifs = VBox(
14✔
184
        Frame(
185
          _("CIFS (SMB)"),
186
          HBox(
187
            HSpacing(1),
188
            VBox(
189
              Left(InputField(Id("server"), _("Server Nam&e"))),
190
              Left(
191
                HBox(
192
                  # text entries
193
                  Left(InputField(Id("share"), _("Exported Sha&re"))),
194
                  HSpacing(1),
195
                  Left(InputField(Id("dir"), _("&Directory on Server")))
196
                )
197
              ),
198
              Left(
199
                CheckBox(
200
                  Id("anonymous"),
201
                  Opt(:notify),
202
                  _("Use Aut&hentication"),
203
                  true
204
                )
205
              ),
206
              Left(
207
                HBox(
208
                  # text entry
209
                  Left(InputField(Id("user_name"), _("&User Name"))),
210
                  HSpacing(1),
211
                  # password entry
212
                  Left(Password(Id("password"), _("&Password")))
213
                )
214
              )
215
            )
216
          )
217
        )
218
      )
219

220
      # helper list, each bit has its decimal representation
221
      @bit_weight_row = [16, 8, 4, 2, 1]
14✔
222
    end
223

224
    # Function initializes option "Enable/Disable kdump"
225
    def InitEnableDisalbeKdump(_key)
1✔
226
      enable = Kdump.add_crashkernel_param
×
227
      enable &&= Service.enabled?(KdumpClass::KDUMP_SERVICE_NAME) unless Mode.installation
×
228

229
      value = enable ? "enable_kdump" : "disable_kdump"
×
230

231
      UI.ChangeWidget(Id("EnableDisalbeKdump"), :Value, value)
×
232

233
      nil
234
    end
235

236
    # Function stores option "Enable/Disable kdump"
237
    #
238
    def StoreEnableDisalbeKdump(_key, _event)
1✔
239
      radiobut = Convert.to_string(
×
240
        UI.QueryWidget(Id("EnableDisalbeKdump"), :Value)
241
      )
242
      Kdump.add_crashkernel_param = if radiobut == "enable_kdump"
×
243
        true
×
244
      else
245
        false
×
246
      end
247

248
      nil
249
    end
250

251
    # Function for handling map values
252
    #
253
    # local map <string, string > KDUMP_SAVE_TARGET
254

255
    def SetUpKDUMP_SAVE_TARGET(target)
1✔
256
      parse_target = target
×
257
      return false if target == ""
×
258

259
      pos = Builtins.search(parse_target, "/")
×
260
      pos1 = -1
×
261
      if pos.zero? # Support for the old '/var/crash' style
×
262
        Ops.set(@KDUMP_SAVE_TARGET, "target", "file")
×
263
      else
264
        Ops.set(
×
265
          @KDUMP_SAVE_TARGET,
266
          "target",
267
          Builtins.substring(parse_target, 0, Ops.subtract(pos, 1))
268
        )
269
        parse_target = Builtins.substring(parse_target, Ops.add(pos, 2))
×
270
      end
271

272
      # file
273
      if Ops.get(@KDUMP_SAVE_TARGET, "target") == "file"
×
274
        Ops.set(@KDUMP_SAVE_TARGET, "dir", parse_target)
×
275

276
        # nfs
277
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "nfs"
×
278
        pos = Builtins.search(parse_target, "/")
×
279
        # pos1 = pos;
280
        Ops.set(
×
281
          @KDUMP_SAVE_TARGET,
282
          "server",
283
          Builtins.substring(parse_target, 0, pos)
284
        )
285
        # pos = find(parse_target, "/");
286
        # KDUMP_SAVE_TARGET["share"]=substring(parse_target,pos1+1,pos-(pos1+1));
287
        Ops.set(
×
288
          @KDUMP_SAVE_TARGET,
289
          "dir",
290
          Builtins.substring(parse_target, pos)
291
        )
292
      elsif ["ftp", "cifs", "ssh", "sftp"].include?(@KDUMP_SAVE_TARGET["target"])
×
293
        pos = Builtins.search(parse_target, "@")
×
294

295
        if !pos.nil?
×
296
          user_pas = Builtins.substring(parse_target, 0, pos)
×
297
          pos1 = Builtins.search(user_pas, ":")
×
298

299
          if !pos1.nil?
×
300
            Ops.set(
×
301
              @KDUMP_SAVE_TARGET,
302
              "user_name",
303
              Builtins.substring(user_pas, 0, pos1)
304
            )
305
            Ops.set(
×
306
              @KDUMP_SAVE_TARGET,
307
              "password",
308
              Builtins.substring(user_pas, Ops.add(pos1, 1), pos)
309
            )
310
          else
311
            Ops.set(
×
312
              @KDUMP_SAVE_TARGET,
313
              "user_name",
314
              Builtins.substring(user_pas, 0, pos)
315
            )
316
          end
317
          parse_target = Builtins.substring(parse_target, Ops.add(pos, 1))
×
318
        end
319
        # only ftp & ssh
320
        if ["ftp", "ssh", "sftp"].include?(@KDUMP_SAVE_TARGET["target"])
×
321
          pos1 = Builtins.search(parse_target, ":")
×
322
          pos = Builtins.search(parse_target, "/")
×
323

324
          if !pos1.nil?
×
325
            Ops.set(
×
326
              @KDUMP_SAVE_TARGET,
327
              "server",
328
              Builtins.substring(parse_target, 0, pos1)
329
            )
330
            Ops.set(
×
331
              @KDUMP_SAVE_TARGET,
332
              "port",
333
              Builtins.substring(
334
                parse_target,
335
                Ops.add(pos1, 1),
336
                Ops.subtract(pos, Ops.add(pos1, 1))
337
              )
338
            )
339
          else
340
            Ops.set(
×
341
              @KDUMP_SAVE_TARGET,
342
              "server",
343
              Builtins.substring(parse_target, 0, pos)
344
            )
345
          end
346
          # only cifs
347
        else
348
          pos = Builtins.search(parse_target, "/")
×
349
          Ops.set(
×
350
            @KDUMP_SAVE_TARGET,
351
            "server",
352
            Builtins.substring(parse_target, 0, pos)
353
          )
354
          parse_target = Builtins.substring(parse_target, Ops.add(pos, 1))
×
355
          pos = Builtins.search(parse_target, "/")
×
356
          Ops.set(
×
357
            @KDUMP_SAVE_TARGET,
358
            "share",
359
            Builtins.substring(parse_target, 0, pos)
360
          )
361
        end
362

363
        Ops.set(
×
364
          @KDUMP_SAVE_TARGET,
365
          "dir",
366
          Builtins.substring(parse_target, pos)
367
        )
368
      end
369
      debug_KDUMP_SAVE_TARGET = deep_copy(@KDUMP_SAVE_TARGET)
×
370

371
      if Ops.get(debug_KDUMP_SAVE_TARGET, "password", "") != ""
×
372
        Ops.set(debug_KDUMP_SAVE_TARGET, "password", "**********")
×
373
      end
374

375
      Builtins.y2milestone("--------------KDUMP_SAVE_TARGET---------------")
×
376
      Builtins.y2milestone("%1", debug_KDUMP_SAVE_TARGET)
×
377
      Builtins.y2milestone("--------------KDUMP_SAVE_TARGET---------------")
×
378

379
      true
×
380
    end
381

382
    # Function for saving KDUMP_SAVE_TARGET
383
    # to standard outpu for KDUMP_SAVEDIR
384
    #
385
    # e.g. KDUMP_SAVEDIR = "ftp://[user[:pass]]@host[:port]/path
386

387
    def tostringKDUMP_SAVE_TARGET
1✔
388
      result = ""
×
389

390
      # file
391
      if Ops.get(@KDUMP_SAVE_TARGET, "target") == "file"
×
392
        result = "file://"
×
393

394
        if Ops.get(@KDUMP_SAVE_TARGET, "dir") != ""
×
395
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
396
        end
397

398
        # ftp
399
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "ftp"
×
400
        result = "ftp://"
×
401

402
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
403
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "server"))
×
404
        else
405
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "user_name"))
×
406

407
          if Ops.get(@KDUMP_SAVE_TARGET, "password") != ""
×
408
            result = Ops.add(
×
409
              Ops.add(result, ":"),
410
              Ops.get(@KDUMP_SAVE_TARGET, "password")
411
            )
412
          end
413
          result = Ops.add(
×
414
            Ops.add(result, "@"),
415
            Ops.get(@KDUMP_SAVE_TARGET, "server")
416
          )
417
        end
418

419
        # add port if it is set...
420
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
421
          result = Ops.add(
×
422
            Ops.add(Ops.add(result, ":"), Ops.get(@KDUMP_SAVE_TARGET, "port")),
423
            Ops.get(@KDUMP_SAVE_TARGET, "dir")
424
          )
425
        else
426
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
427
        end
428
        # ssh
429
      elsif ["ssh", "sftp"].include?(@KDUMP_SAVE_TARGET["target"])
×
430
        result = @KDUMP_SAVE_TARGET["target"] + "://"
×
431

432
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") != "" &&
×
433
            Ops.get(@KDUMP_SAVE_TARGET, "password") == ""
434
          result = Ops.add(
×
435
            Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "user_name")),
436
            "@"
437
          )
438
        elsif Ops.get(@KDUMP_SAVE_TARGET, "user_name") != "" &&
×
439
            Ops.get(@KDUMP_SAVE_TARGET, "password") != ""
440
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "user_name"))
×
441
          result = Ops.add(
×
442
            Ops.add(
443
              Ops.add(result, ":"),
444
              Ops.get(@KDUMP_SAVE_TARGET, "password")
445
            ),
446
            "@"
447
          )
448
        end
449
        result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "server"))
×
450
        # add port if it is set...
451
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
452
          result = Ops.add(
×
453
            Ops.add(Ops.add(result, ":"), Ops.get(@KDUMP_SAVE_TARGET, "port")),
454
            Ops.get(@KDUMP_SAVE_TARGET, "dir")
455
          )
456
        else
457
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
458
        end
459

460
        # nfs
461
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "nfs"
×
462
        result = Ops.add(
×
463
          Ops.add("nfs://", Ops.get(@KDUMP_SAVE_TARGET, "server")),
464
          Ops.get(@KDUMP_SAVE_TARGET, "dir")
465
        )
466

467
        # cifs
468
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "cifs"
×
469
        result = "cifs://"
×
470

471
        if Builtins.findfirstof(Ops.get(@KDUMP_SAVE_TARGET, "dir", ""), "/") != 0
×
472
          Ops.set(
×
473
            @KDUMP_SAVE_TARGET,
474
            "dir",
475
            Ops.add("/", Ops.get(@KDUMP_SAVE_TARGET, "dir", ""))
476
          )
477
        end
478

479
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
480
          result = Ops.add(
×
481
            Ops.add(
482
              Ops.add(
483
                Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "server")),
484
                "/"
485
              ),
486
              Ops.get(@KDUMP_SAVE_TARGET, "share")
487
            ),
488
            Ops.get(@KDUMP_SAVE_TARGET, "dir")
489
          )
490
        else
491
          result = Ops.add(result, Ops.get(@KDUMP_SAVE_TARGET, "user_name"))
×
492

493
          if Ops.get(@KDUMP_SAVE_TARGET, "password") != ""
×
494
            result = Ops.add(
×
495
              Ops.add(result, ":"),
496
              Ops.get(@KDUMP_SAVE_TARGET, "password")
497
            )
498
          end
499

500
          result = Ops.add(
×
501
            Ops.add(
502
              Ops.add(
503
                Ops.add(
504
                  Ops.add(result, "@"),
505
                  Ops.get(@KDUMP_SAVE_TARGET, "server")
506
                ),
507
                "/"
508
              ),
509
              Ops.get(@KDUMP_SAVE_TARGET, "share")
510
            ),
511
            Ops.get(@KDUMP_SAVE_TARGET, "dir")
512
          )
513
        end
514
      end
515

516
      # Popup::Message(result);
517

518
      # y2milestone("-----------------KDUMP_SAVEDIR--------------------");
519
      # y2milestone("%1",result);
520
      # y2milestone("-----------------KDUMP_SAVEDIR--------------------");
521

522
      result
×
523
    end
524

525
    # Function initializes option "Save Traget for Kdump Images"
526
    #
527

528
    def InitTargetKdump(_key)
1✔
529
      SetUpKDUMP_SAVE_TARGET(Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_SAVEDIR"))
×
530

531
      if Ops.get(@KDUMP_SAVE_TARGET, "target") == "file"
×
532
        # UI::ChangeWidget(`id ("local_filesystem"), `Value, true);
533
        UI.ChangeWidget(Id("TargetKdump"), :Value, "local_filesystem")
×
534
        UI.ReplaceWidget(Id("Targets"), @local_filesystem)
×
535
        UI.ChangeWidget(Id("dir"), :Value, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
536
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "nfs"
×
537
        UI.ReplaceWidget(Id("Targets"), @nfs)
×
538
        # UI::ChangeWidget(`id ("nfs"), `Value, true);
539
        UI.ChangeWidget(Id("TargetKdump"), :Value, "nfs")
×
540
        UI.ChangeWidget(
×
541
          Id("server"),
542
          :Value,
543
          Ops.get(@KDUMP_SAVE_TARGET, "server")
544
        )
545
        UI.ChangeWidget(Id("dir"), :Value, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
546
      elsif ["ssh", "sftp"].include?(@KDUMP_SAVE_TARGET["target"])
×
547
        UI.ReplaceWidget(Id("Targets"), @ssh)
×
548
        UI.ChangeWidget(Id("TargetKdump"), :Value, @KDUMP_SAVE_TARGET["target"])
×
549
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
550
          UI.ChangeWidget(
×
551
            Id("port"),
552
            :Value,
553
            Builtins.tointeger(Ops.get(@KDUMP_SAVE_TARGET, "port"))
554
          )
555
        end
556
        Builtins.foreach(["server", "user_name", "dir", "password"]) do |key2|
×
557
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
558
        end
559
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "ftp"
×
560
        UI.ReplaceWidget(Id("Targets"), @ftp)
×
561
        # UI::ChangeWidget(`id ("ftp"), `Value, true);
562
        UI.ChangeWidget(Id("TargetKdump"), :Value, "ftp")
×
563
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
564
          UI.ChangeWidget(
×
565
            Id("port"),
566
            :Value,
567
            Builtins.tointeger(Ops.get(@KDUMP_SAVE_TARGET, "port"))
568
          )
569
        end
570
        Builtins.foreach(["server", "dir"]) do |key2|
×
571
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
572
        end
573

574
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
575
          UI.ChangeWidget(Id("user_name"), :Enabled, false)
×
576
          UI.ChangeWidget(Id("password"), :Enabled, false)
×
577
          UI.ChangeWidget(Id("anonymous"), :Value, true)
×
578
        else
579
          UI.ChangeWidget(
×
580
            Id("user_name"),
581
            :Value,
582
            Ops.get(@KDUMP_SAVE_TARGET, "user_name")
583
          )
584
          UI.ChangeWidget(
×
585
            Id("password"),
586
            :Value,
587
            Ops.get(@KDUMP_SAVE_TARGET, "password")
588
          )
589
        end
590
      elsif Ops.get(@KDUMP_SAVE_TARGET, "target") == "cifs"
×
591
        UI.ReplaceWidget(Id("Targets"), @cifs)
×
592
        # UI::ChangeWidget(`id ("cifs"), `Value, true);
593
        UI.ChangeWidget(Id("TargetKdump"), :Value, "cifs")
×
594
        Builtins.foreach(["server", "dir", "share"]) do |key2|
×
595
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
596
        end
597

598
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
599
          UI.ChangeWidget(Id("user_name"), :Enabled, false)
×
600
          UI.ChangeWidget(Id("password"), :Enabled, false)
×
601
          UI.ChangeWidget(Id("anonymous"), :Value, false)
×
602
        else
603
          UI.ChangeWidget(
×
604
            Id("user_name"),
605
            :Value,
606
            Ops.get(@KDUMP_SAVE_TARGET, "user_name")
607
          )
608
          UI.ChangeWidget(
×
609
            Id("password"),
610
            :Value,
611
            Ops.get(@KDUMP_SAVE_TARGET, "password")
612
          )
613
        end
614
      end
615

616
      nil
617
    end
618

619
    # Function validates options in
620
    # "Saving Target for Kdump Image"
621

622
    def ValidTargetKdump(_key, _event)
1✔
623
      radiobut = Builtins.tostring(UI.QueryWidget(Id("TargetKdump"), :Value))
×
624
      value = nil
×
625

626
      if radiobut == "local_filesystem"
×
627
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
628

629
        if value.nil? || value == ""
×
630
          Popup.Error(_("You need to specify \"Directory for Saving Dumps\""))
×
631
          UI.SetFocus(Id("dir"))
×
632
          return false
×
633
        end
634
      elsif radiobut == "ftp"
×
635
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
636

637
        if value.nil? || value == ""
×
638
          Popup.Error(_("You need to specify \"Server Name\""))
×
639
          UI.SetFocus(Id("server"))
×
640
          return false
×
641
        end
642
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
643

644
        if value.nil? || value == ""
×
645
          Popup.Error(_("You need to specify \"Directory on Server\""))
×
646
          UI.SetFocus(Id("dir"))
×
647
          return false
×
648
        end
649
        anon = Convert.to_boolean(UI.QueryWidget(Id("anonymous"), :Value))
×
650

651
        if !anon
×
652
          value = Builtins.tostring(UI.QueryWidget(Id("user_name"), :Value))
×
653

654
          if value.nil? || value == ""
×
655
            Popup.Error(_("You need to specify \"User Name\""))
×
656
            UI.SetFocus(Id("user_name"))
×
657
            return false
×
658
          end
659
        end
660
      elsif ["ssh", "sftp", "nfs"].include?(radiobut)
×
661
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
662

663
        if value.nil? || value == ""
×
664
          Popup.Error(_("You need to specify \"Server Name\""))
×
665
          UI.SetFocus(Id("server"))
×
666
          return false
×
667
        end
668
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
669

670
        if value.nil? || value == ""
×
671
          Popup.Error(_("You need to specify \"Directory on Server\""))
×
672
          UI.SetFocus(Id("dir"))
×
673
          return false
×
674
        end
675
      elsif radiobut == "cifs"
×
676
        # fix for bnc #307307 module should check if cifs tools are installed when requested
677
        if Mode.installation || Mode.autoinst
×
678
          Kdump.kdump_packages = Builtins.add(
×
679
            Kdump.kdump_packages,
680
            "cifs-mount"
681
          )
682
          Builtins.y2milestone(
×
683
            "add cifs-mount to selected packages to installation"
684
          )
685
        elsif !Package.Installed("cifs-mount")
×
686
          Builtins.y2milestone(
×
687
            "SMB/CIFS share cannot be mounted, installing missing 'cifs-mount' package..."
688
          )
689
          # install cifs-mount package
690
          Package.CheckAndInstallPackages(["cifs-mount"])
×
691
        end
692

693
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
694

695
        if value.nil? || value == ""
×
696
          Popup.Error(_("You need to specify \"Server Name\""))
×
697
          UI.SetFocus(Id("server"))
×
698
          return false
×
699
        end
700
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
701

702
        if value.nil? || value == ""
×
703
          Popup.Error(_("You need to specify \"Directory on Server\""))
×
704
          UI.SetFocus(Id("dir"))
×
705
          return false
×
706
        end
707
        value = Builtins.tostring(UI.QueryWidget(Id("share"), :Value))
×
708

709
        if value.nil? || value == ""
×
710
          Popup.Error(_("You need to specify \"Exported Share\""))
×
711
          UI.SetFocus(Id("share"))
×
712
          return false
×
713
        end
714
        anon = Convert.to_boolean(UI.QueryWidget(Id("anonymous"), :Value))
×
715

716
        if anon
×
717
          value = Builtins.tostring(UI.QueryWidget(Id("user_name"), :Value))
×
718

719
          if value.nil? || value == ""
×
720
            Popup.Error(_("You need to specify \"User Name\""))
×
721
            UI.SetFocus(Id("user_name"))
×
722
            return false
×
723
          end # end of if ((value == nil) || (value == ""))
724
        end # end of if (anon)
725
      end # end of } else if (radiobut == "cifs")
726

727
      true
×
728
    end
729

730
    # Function handles "Saving Target for Kdump Image"
731
    #
732

733
    def HandleTargetKdump(_key, event)
1✔
734
      event = deep_copy(event)
×
735
      event_name = Ops.get(event, "ID")
×
736
      # StoreTargetKdump ( key, event);
737
      StoreTargetKdumpHandle(@type)
×
738
      radiobut = Builtins.tostring(UI.QueryWidget(Id("TargetKdump"), :Value))
×
739
      @type = radiobut
×
740

741
      if event_name == "anonymous"
×
742
        value = Convert.to_boolean(UI.QueryWidget(Id("anonymous"), :Value))
×
743
        target = Builtins.tostring(UI.QueryWidget(Id("TargetKdump"), :Value))
×
744

745
        if value && target == "ftp" || !value && target == "cifs"
×
746
          UI.ChangeWidget(Id("user_name"), :Enabled, false)
×
747
          UI.ChangeWidget(Id("password"), :Enabled, false)
×
748
          # KDUMP_SAVE_TARGET["user_name"]="";
749
          # KDUMP_SAVE_TARGET["password"]="";
750
        elsif value && target == "cifs" || !value && target == "ftp"
×
751
          UI.ChangeWidget(Id("user_name"), :Enabled, true)
×
752
          UI.ChangeWidget(Id("password"), :Enabled, true)
×
753
        end
754
      elsif radiobut == "local_filesystem"
×
755
        UI.ReplaceWidget(Id("Targets"), @local_filesystem)
×
756
        @set_network = false
×
757
        UI.ChangeWidget(Id("dir"), :Value, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
758
        if event_name == "select_dir"
×
759
          dir = UI.AskForExistingDirectory(
×
760
            "/",
761
            _("Select directory for saving dump images")
762
          )
763
          UI.ChangeWidget(Id("dir"), :Value, dir)
×
764
        end
765
      elsif radiobut == "ftp"
×
766
        UI.ReplaceWidget(Id("Targets"), @ftp)
×
767

768
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
769
          UI.ChangeWidget(
×
770
            Id("port"),
771
            :Value,
772
            Builtins.tointeger(Ops.get(@KDUMP_SAVE_TARGET, "port"))
773
          )
774
        end
775
        Builtins.foreach(["server", "dir"]) do |key2|
×
776
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
777
        end
778

779
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
780
          UI.ChangeWidget(Id("user_name"), :Enabled, false)
×
781
          UI.ChangeWidget(Id("password"), :Enabled, false)
×
782
          UI.ChangeWidget(Id("anonymous"), :Value, true)
×
783
        else
784
          UI.ChangeWidget(
×
785
            Id("user_name"),
786
            :Value,
787
            Ops.get(@KDUMP_SAVE_TARGET, "user_name")
788
          )
789
          UI.ChangeWidget(
×
790
            Id("password"),
791
            :Value,
792
            Ops.get(@KDUMP_SAVE_TARGET, "password")
793
          )
794
        end
795
      elsif ["ssh", "sftp"].include?(radiobut)
×
796
        UI.ReplaceWidget(Id("Targets"), @ssh)
×
797

798
        if Ops.get(@KDUMP_SAVE_TARGET, "port") != ""
×
799
          UI.ChangeWidget(
×
800
            Id("port"),
801
            :Value,
802
            Builtins.tointeger(Ops.get(@KDUMP_SAVE_TARGET, "port"))
803
          )
804
        end
805
        Builtins.foreach(["server", "user_name", "dir", "password"]) do |key2|
×
806
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
807
        end
808
      elsif radiobut == "nfs"
×
809
        UI.ReplaceWidget(Id("Targets"), @nfs)
×
810
        UI.ChangeWidget(
×
811
          Id("server"),
812
          :Value,
813
          Ops.get(@KDUMP_SAVE_TARGET, "server")
814
        )
815
        UI.ChangeWidget(Id("dir"), :Value, Ops.get(@KDUMP_SAVE_TARGET, "dir"))
×
816
      elsif radiobut == "cifs"
×
817
        UI.ReplaceWidget(Id("Targets"), @cifs)
×
818
        Builtins.foreach(["server", "dir", "share", "user_name", "password"]) do |key2|
×
819
          UI.ChangeWidget(Id(key2), :Value, Ops.get(@KDUMP_SAVE_TARGET, key2))
×
820
        end
821

822
        if Ops.get(@KDUMP_SAVE_TARGET, "user_name") == ""
×
823
          UI.ChangeWidget(Id("user_name"), :Enabled, false)
×
824
          UI.ChangeWidget(Id("password"), :Enabled, false)
×
825
          UI.ChangeWidget(Id("anonymous"), :Value, false)
×
826
        else
827
          UI.ChangeWidget(
×
828
            Id("user_name"),
829
            :Value,
830
            Ops.get(@KDUMP_SAVE_TARGET, "user_name")
831
          )
832
          UI.ChangeWidget(
×
833
            Id("password"),
834
            :Value,
835
            Ops.get(@KDUMP_SAVE_TARGET, "password")
836
          )
837
        end
838
      end
839
      nil
840
    end
841

842
    def StoreTargetKdumpHandle(type)
1✔
843
      radiobut = type
×
844
      value = nil
×
845

846
      if radiobut == "local_filesystem"
×
847
        Ops.set(@KDUMP_SAVE_TARGET, "target", "file")
×
848
        # directory
849
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
850

851
        if !value.nil?
×
852
          Ops.set(@KDUMP_SAVE_TARGET, "dir", value)
×
853
        else
854
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
855
        end
856
      elsif radiobut == "ftp"
×
857
        Ops.set(@KDUMP_SAVE_TARGET, "target", "ftp")
×
858

859
        # server
860
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
861
        if !value.nil?
×
862
          Ops.set(@KDUMP_SAVE_TARGET, "server", value)
×
863
        else
864
          Ops.set(@KDUMP_SAVE_TARGET, "server", "")
×
865
        end
866

867
        # port
868
        if Builtins.tostring(UI.QueryWidget(Id("port"), :Value)) != "21"
×
869
          Ops.set(
×
870
            @KDUMP_SAVE_TARGET,
871
            "port",
872
            Builtins.tostring(UI.QueryWidget(Id("port"), :Value))
873
          )
874
        else
875
          Ops.set(@KDUMP_SAVE_TARGET, "port", "")
×
876
        end
877

878
        # directory
879
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
880
        if !value.nil?
×
881
          Ops.set(@KDUMP_SAVE_TARGET, "dir", value)
×
882
        else
883
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
884
        end
885

886
        # user_name vs. anonymous
887
        value = Builtins.tostring(UI.QueryWidget(Id("user_name"), :Value))
×
888

889
        if Convert.to_boolean(UI.QueryWidget(Id("anonymous"), :Value))
×
890
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", "")
×
891
        elsif !value.nil?
×
892
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", value)
×
893
        else
894
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", "")
×
895
        end
896

897
        # password
898
        value = Builtins.tostring(UI.QueryWidget(Id("password"), :Value))
×
899

900
        if !value.nil? && Ops.get(@KDUMP_SAVE_TARGET, "user_name") != ""
×
901
          Ops.set(@KDUMP_SAVE_TARGET, "password", value)
×
902
        else
903
          Ops.set(@KDUMP_SAVE_TARGET, "password", "")
×
904
        end
905

906
        # directory
907
        if UI.QueryWidget(Id("dir"), :Value)
×
908
          Ops.set(
×
909
            @KDUMP_SAVE_TARGET,
910
            "dir",
911
            Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
912
          )
913
        else
914
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
915
        end
916
      elsif ["ssh", "sftp"].include?(radiobut)
×
917
        @KDUMP_SAVE_TARGET["target"] = radiobut
×
918

919
        # server
920
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
921

922
        if !value.nil?
×
923
          Ops.set(@KDUMP_SAVE_TARGET, "server", value)
×
924
        else
925
          Ops.set(@KDUMP_SAVE_TARGET, "server", "")
×
926
        end
927

928
        # port
929
        if Builtins.tostring(UI.QueryWidget(Id("port"), :Value)) != "22"
×
930
          Ops.set(
×
931
            @KDUMP_SAVE_TARGET,
932
            "port",
933
            Builtins.tostring(UI.QueryWidget(Id("port"), :Value))
934
          )
935
        else
936
          Ops.set(@KDUMP_SAVE_TARGET, "port", "")
×
937
        end
938

939
        # directory
940
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
941

942
        if !value.nil?
×
943
          Ops.set(@KDUMP_SAVE_TARGET, "dir", value)
×
944
        else
945
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
946
        end
947

948
        # user_name
949
        value = Builtins.tostring(UI.QueryWidget(Id("user_name"), :Value))
×
950

951
        if !value.nil?
×
952
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", value)
×
953
        else
954
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", "")
×
955
        end
956

957
        # password
958
        value = Builtins.tostring(UI.QueryWidget(Id("password"), :Value))
×
959

960
        if !value.nil? && Ops.get(@KDUMP_SAVE_TARGET, "user_name") != ""
×
961
          Ops.set(@KDUMP_SAVE_TARGET, "password", value)
×
962
        else
963
          Ops.set(@KDUMP_SAVE_TARGET, "password", "")
×
964
        end
965
      elsif radiobut == "nfs"
×
966
        Ops.set(@KDUMP_SAVE_TARGET, "target", "nfs")
×
967

968
        # server
969
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
970

971
        if !value.nil?
×
972
          Ops.set(@KDUMP_SAVE_TARGET, "server", value)
×
973
        else
974
          Ops.set(@KDUMP_SAVE_TARGET, "server", "")
×
975
        end
976

977
        # directory
978
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
979

980
        if !value.nil?
×
981
          Ops.set(@KDUMP_SAVE_TARGET, "dir", value)
×
982
        else
983
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
984
        end
985
      elsif radiobut == "cifs"
×
986
        Ops.set(@KDUMP_SAVE_TARGET, "target", "cifs")
×
987

988
        # server
989
        value = Builtins.tostring(UI.QueryWidget(Id("server"), :Value))
×
990

991
        if !value.nil?
×
992
          Ops.set(@KDUMP_SAVE_TARGET, "server", value)
×
993
        else
994
          Ops.set(@KDUMP_SAVE_TARGET, "server", "")
×
995
        end
996

997
        # share
998
        value = Builtins.tostring(UI.QueryWidget(Id("share"), :Value))
×
999

1000
        if !value.nil?
×
1001
          Ops.set(@KDUMP_SAVE_TARGET, "share", value)
×
1002
        else
1003
          Ops.set(@KDUMP_SAVE_TARGET, "share", "")
×
1004
        end
1005

1006
        # directory
1007
        value = Builtins.tostring(UI.QueryWidget(Id("dir"), :Value))
×
1008

1009
        if !value.nil?
×
1010
          Ops.set(@KDUMP_SAVE_TARGET, "dir", value)
×
1011
        else
1012
          Ops.set(@KDUMP_SAVE_TARGET, "dir", "")
×
1013
        end
1014

1015
        # user_name vs. anonymous
1016
        value = Builtins.tostring(UI.QueryWidget(Id("user_name"), :Value))
×
1017

1018
        if !Convert.to_boolean(UI.QueryWidget(Id("anonymous"), :Value))
×
1019
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", "")
×
1020
        elsif !value.nil?
×
1021
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", value)
×
1022
        else
1023
          Ops.set(@KDUMP_SAVE_TARGET, "user_name", "")
×
1024
        end
1025

1026
        # password
1027
        value = Builtins.tostring(UI.QueryWidget(Id("password"), :Value))
×
1028

1029
        if !value.nil? && Ops.get(@KDUMP_SAVE_TARGET, "user_name") != ""
×
1030
          Ops.set(@KDUMP_SAVE_TARGET, "password", value)
×
1031
        else
1032
          Ops.set(@KDUMP_SAVE_TARGET, "password", "")
×
1033
        end
1034
      end
1035
      Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_SAVEDIR", tostringKDUMP_SAVE_TARGET)
×
1036

1037
      nil
1038
    end
1039

1040
    # Function stores option
1041
    # "Saving Target for kdump Image"
1042

1043
    def StoreTargetKdump(_key, _event)
1✔
1044
      @type = Builtins.tostring(UI.QueryWidget(Id("TargetKdump"), :Value))
×
1045

1046
      nil
1047
    end
1048

1049
    # Function initializes option "Kdump Command Line"
1050
    #
1051

1052
    def InitKdumpCommandLine(_key)
1✔
1053
      value = Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_COMMANDLINE")
×
1054
      UI.ChangeWidget(Id("KdumpCommandLine"), :Value, value.nil? ? "" : value)
×
1055

1056
      nil
1057
    end
1058

1059
    # Function stores option "Kdump Command Line"
1060
    #
1061
    def StoreKdumpCommandLine(_key, _event)
1✔
1062
      Ops.set(
×
1063
        Kdump.KDUMP_SETTINGS,
1064
        "KDUMP_COMMANDLINE",
1065
        Builtins.tostring(UI.QueryWidget(Id("KdumpCommandLine"), :Value))
1066
      )
1067

1068
      nil
1069
    end
1070

1071
    # Function initializes option "Kdump Command Line Append"
1072
    #
1073

1074
    def InitKdumpCommandLineAppend(_key)
1✔
1075
      value = Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_COMMANDLINE_APPEND")
×
1076
      UI.ChangeWidget(
×
1077
        Id("KdumpCommandLineAppend"),
1078
        :Value,
1079
        value.nil? ? "" : value
×
1080
      )
1081

1082
      nil
1083
    end
1084

1085
    # Function stores option "Kdump Command Line Append"
1086
    #
1087
    def StoreKdumpCommandLineAppend(_key, _event)
1✔
1088
      Ops.set(
×
1089
        Kdump.KDUMP_SETTINGS,
1090
        "KDUMP_COMMANDLINE_APPEND",
1091
        Builtins.tostring(UI.QueryWidget(Id("KdumpCommandLineAppend"), :Value))
1092
      )
1093

1094
      nil
1095
    end
1096

1097
    # Function initializes option "Number of Old Dumps"
1098
    def InitNumberDumps(_key)
1✔
1099
      UI.ChangeWidget(
×
1100
        Id("NumberDumps"),
1101
        :Value,
1102
        Builtins.tointeger(
1103
          Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_KEEP_OLD_DUMPS")
1104
        )
1105
      )
1106

1107
      nil
1108
    end
1109

1110
    # Function stores option "Number of Old Dumps"
1111
    def StoreNumberDumps(_key, _event)
1✔
1112
      Ops.set(
×
1113
        Kdump.KDUMP_SETTINGS,
1114
        "KDUMP_KEEP_OLD_DUMPS",
1115
        Builtins.tostring(UI.QueryWidget(Id("NumberDumps"), :Value))
1116
      )
1117

1118
      nil
1119
    end
1120

1121
    # Function initializes option
1122
    # "Enable Immediate Reboot After Saving the Core"
1123

1124
    def InitEnableReboot(_key)
1✔
1125
      UI.ChangeWidget(
×
1126
        Id("EnableReboot"),
1127
        :Value,
1128
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_IMMEDIATE_REBOOT") == "yes" ? true : false
×
1129
      )
1130

1131
      nil
1132
    end
1133

1134
    # Function stores option
1135
    # "Enable Immediate Reboot After Saving the Core"
1136

1137
    def StoreEnableReboot(_key, _event)
1✔
1138
      Ops.set(
×
1139
        Kdump.KDUMP_SETTINGS,
1140
        "KDUMP_IMMEDIATE_REBOOT",
1141
        Convert.to_boolean(UI.QueryWidget(Id("EnableReboot"), :Value)) ? "yes" : "no"
×
1142
      )
1143

1144
      nil
1145
    end
1146

1147
    # Function initializes option
1148
    # "Dump Level" - visualization in UI
1149

1150
    def SetDumpLevel(bit_number)
1✔
1151
      counter = -1
×
1152
      Builtins.foreach(
×
1153
        ["free_page", "user_data", "cache_private", "cache_page", "zero_page"]
1154
      ) do |key|
1155
        counter = Ops.add(counter, 1)
×
1156
        one_bit = Builtins.substring(bit_number, counter, 1)
×
1157
        UI.ChangeWidget(Id(key), :Value, one_bit == "1" ? false : true)
×
1158
      end
1159

1160
      nil
1161
    end
1162

1163
    # Function initializes option
1164
    # "Dump Level"
1165

1166
    def InitDumpLevel(_key)
1✔
1167
      value = Builtins.tointeger(
×
1168
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPLEVEL")
1169
      )
1170
      ret = ""
×
1171
      Builtins.foreach(@bit_weight_row) do |try_i|
×
1172
        if Ops.greater_than(Ops.divide(value, try_i), 0)
×
1173
          value = Ops.modulo(value, try_i)
×
1174
          ret = Ops.add(ret, "1")
×
1175
        else
1176
          ret = Ops.add(ret, "0")
×
1177
        end
1178
      end
1179

1180
      # Popup::Message(ret);
1181
      SetDumpLevel(ret)
×
1182

1183
      nil
1184
    end
1185

1186
    # Function store option
1187
    # "Dump Level" - info from UI checkboxes
1188
    # @result string binary code e.g. 11000
1189

1190
    def GetDumpLevel
1✔
1191
      ret = ""
×
1192
      Builtins.foreach(
×
1193
        ["free_page", "user_data", "cache_private", "cache_page", "zero_page"]
1194
      ) do |key|
1195
        ret = if Convert.to_boolean(UI.QueryWidget(Id(key), :Value))
×
1196
          Ops.add(ret, "0")
×
1197
        else
1198
          Ops.add(ret, "1")
×
1199
        end
1200
      end
1201
      # Popup::Message(ret);
1202
      ret
×
1203
    end
1204

1205
    # Function validates options in
1206
    # "Dump Level"
1207
    # install makedumpfile if KDUMP_DUMPLEVEL > 0
1208

1209
    def ValidDumpLevel(_key, _event)
1✔
1210
      result = true
×
1211
      value = GetDumpLevel()
×
1212
      counter = -1
×
1213
      dumplevel = 0
×
1214

1215
      while Ops.less_than(counter, 5)
×
1216
        counter = Ops.add(counter, 1)
×
1217
        one_bit = Builtins.substring(value, counter, 1)
×
1218
        if one_bit == "1"
×
1219
          dumplevel = Ops.add(dumplevel, Ops.get(@bit_weight_row, counter, 0))
×
1220
        end
1221
      end
1222

1223
      if Ops.greater_than(dumplevel, 0) || dumplevel.nil?
×
1224
        if Mode.installation || Mode.autoinst
×
1225
          Kdump.kdump_packages = Builtins.add(
×
1226
            Kdump.kdump_packages,
1227
            "makedumpfile"
1228
          )
1229
          Builtins.y2milestone(
×
1230
            "add makedumpfile to selected packages to installation"
1231
          )
1232
        elsif Package.Installed("makedumpfile")
×
1233
          return true
×
1234
        else
1235
          package_list = []
×
1236
          package_list = Builtins.add(package_list, "makedumpfile")
×
1237

1238
          if !Package.CheckAndInstallPackages(package_list)
×
1239
            result = false
×
1240

1241
            if !Mode.commandline
×
1242
              Popup.Error(Message.CannotContinueWithoutPackagesInstalled)
×
1243
            else
1244
              CommandLine.Error(
×
1245
                Message.CannotContinueWithoutPackagesInstalled
1246
              )
1247
            end
1248
            Builtins.y2error(
×
1249
              "[kdump] (ValidDumpLevel) Installation of package list %1 failed or aborted",
1250
              package_list
1251
            )
1252
          else
1253
            result = true
×
1254
          end
1255
        end
1256
      end # end of if ((dumplevel >0 ) || (dumplevel == nil))
1257
      result
×
1258
    end
1259

1260
    # Function stores option
1261
    # "Dump Level"
1262
    def StoreDumpLevel(_key, _event)
1✔
1263
      value = GetDumpLevel()
×
1264
      counter = -1
×
1265
      int_value = 0
×
1266
      while Ops.less_than(counter, 5)
×
1267
        counter = Ops.add(counter, 1)
×
1268
        one_bit = Builtins.substring(value, counter, 1)
×
1269
        if one_bit == "1"
×
1270
          int_value = Ops.add(int_value, Ops.get(@bit_weight_row, counter, 0))
×
1271
        end
1272
      end
1273

1274
      ret = Builtins.tostring(int_value)
×
1275
      Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPLEVEL", ret)
×
1276
      # Popup::Message(ret);
1277

1278
      nil
1279
    end
1280

1281
    #  Hadle function for option
1282
    # "Dump Level"
1283

1284
    def HandleDumpLevel(_key, event)
1✔
1285
      ret = Ops.get(event, "ID")
×
1286
      if ret == "cache_private"
×
1287
        value_cache_private = Convert.to_boolean(
×
1288
          UI.QueryWidget(Id("cache_private"), :Value)
1289
        )
1290
        value_cache_page = Convert.to_boolean(
×
1291
          UI.QueryWidget(Id("cache_page"), :Value)
1292
        )
1293
        if value_cache_private && !value_cache_page
×
1294
          UI.ChangeWidget(Id("cache_page"), :Value, true)
×
1295
        end
1296
      end
1297

1298
      if ret == "cache_page"
×
1299
        value_cache_private = Convert.to_boolean(
×
1300
          UI.QueryWidget(Id("cache_private"), :Value)
1301
        )
1302
        value_cache_page = Convert.to_boolean(
×
1303
          UI.QueryWidget(Id("cache_page"), :Value)
1304
        )
1305
        if value_cache_private && !value_cache_page
×
1306
          UI.ChangeWidget(Id("cache_private"), :Value, false)
×
1307
        end
1308
      end
1309
      nil
1310
    end
1311

1312
    # Value of the low memory in UI
1313
    # @return [Integer]
1314
    def allocated_low_memory
1✔
1315
      UI.QueryWidget(Id("allocated_low_memory"), :Value).to_i
×
1316
    end
1317

1318
    # Value of the high memory in UI, 0 if not supported
1319
    # @return [Integer]
1320
    def allocated_high_memory
1✔
1321
      if Kdump.high_memory_supported?
×
1322
        UI.QueryWidget(Id("allocated_high_memory"), :Value).to_i
×
1323
      else
1324
        0
×
1325
      end
1326
    end
1327

1328
    # Total allocated memory, according to UI
1329
    # @return [Integer]
1330
    def allocated_memory
1✔
1331
      allocated_low_memory + allocated_high_memory
×
1332
    end
1333

1334
    # Updates the free memory displayed in the UI
1335
    def update_usable_memory
1✔
1336
      value = if UI.QueryWidget(Id(:auto_resize), :Value)
×
1337
        "---"
×
1338
      else
1339
        Kdump.total_memory - allocated_memory
×
1340
      end
1341

1342
      UI.ReplaceWidget(Id("usable_memory_rp"), usable_memory_widget(value))
×
1343
    end
1344

1345
    # Function initializes option
1346
    # "KdumpMemory"
1347
    def InitKdumpMemory(_key)
1✔
1348
      if Kdump.using_fadump?
×
1349
        UI.ChangeWidget(Id(:auto_resize), :Enabled, false)
×
1350
        auto_resize = false
×
1351
      else
1352
        auto_resize = Kdump.KDUMP_SETTINGS["KDUMP_AUTO_RESIZE"] == "yes"
×
1353
      end
1354
      UI.ChangeWidget(Id(:auto_resize), :Value, auto_resize)
×
1355
      if Kdump.total_memory > 0
×
1356
        UI.ChangeWidget(Id(:allocated_memory_box), :Enabled, !auto_resize)
×
1357
        UI.ChangeWidget(
×
1358
          Id("total_memory"),
1359
          :Value,
1360
          Builtins.tostring(Kdump.total_memory)
1361
        )
1362
        UI.ChangeWidget(
×
1363
          Id("allocated_low_memory"),
1364
          :Value,
1365
          Builtins.tointeger(Kdump.allocated_memory[:low])
1366
        )
1367
        if Kdump.high_memory_supported?
×
1368
          UI.ChangeWidget(
×
1369
            Id("allocated_high_memory"),
1370
            :Value,
1371
            Builtins.tointeger(Kdump.allocated_memory[:high])
1372
          )
1373
        end
1374
        update_usable_memory
×
1375
      else
1376
        UI.ChangeWidget(Id(:allocated_memory_box), :Enabled, false)
×
1377
        UI.ChangeWidget(Id("total_memory"), :Value, "0")
×
1378
        UI.ChangeWidget(Id("usable_memory"), :Value, "0")
×
1379
      end
1380

1381
      nil
1382
    end
1383

1384
    #  Handle function for option
1385
    # "KdumpMemory"
1386
    def HandleKdumpMemory(_key, event)
1✔
1387
      event = deep_copy(event)
×
1388
      ret = Ops.get(event, "ID")
×
1389
      if ["allocated_low_memory", "allocated_high_memory"].include?(ret)
×
1390
        remaining = Kdump.total_memory - allocated_memory
×
1391
        if remaining <= 0
×
1392
          # Substract (remaining is negative) the excess from the current value
1393
          UI.ChangeWidget(Id(ret), :Value, send(ret.to_sym) + remaining)
×
1394
        end
1395
        update_usable_memory
×
1396
      elsif ret == :auto_resize
×
1397
        value = UI.QueryWidget(Id(ret), :Value)
×
1398
        UI.ChangeWidget(Id(:allocated_memory_box), :Enabled, !value)
×
1399
        update_usable_memory
×
1400
      end
1401

1402
      nil
1403
    end
1404

1405
    # Function validates if crashkernel option includes
1406
    # several ranges and ask user about rewritting
1407
    #
1408
    # "KdumpMemory"
1409
    def ValidKdumpMemory(_key, _event)
1✔
1410
      if Kdump.crashkernel_list_ranges && Mode.normal
×
1411
        Kdump.crashkernel_list_ranges = !Popup.YesNo(
×
1412
          _("Kernel option includes several ranges or redundant values. Rewrite it?")
1413
        )
1414
      end
1415

1416
      true
×
1417
    end
1418

1419
    #  Store function for option
1420
    # "KdumpMemory"
1421
    def StoreKdumpMemory(_key, _event)
1✔
1422
      Kdump.KDUMP_SETTINGS["KDUMP_AUTO_RESIZE"] =
×
1423
        UI.QueryWidget(Id(:auto_resize), :Value) ? "yes" : "no"
×
1424
      Kdump.allocated_memory[:low] = Builtins.tostring(
×
1425
        UI.QueryWidget(Id("allocated_low_memory"), :Value)
1426
      )
1427
      if Kdump.high_memory_supported?
×
1428
        Kdump.allocated_memory[:high] = Builtins.tostring(
×
1429
          UI.QueryWidget(Id("allocated_high_memory"), :Value)
1430
        )
1431
      end
1432

1433
      nil
1434
    end
1435

1436
    # Initializes FADump settings in UI
1437
    def InitFADump(_key)
1✔
1438
      if Kdump.system.supports_fadump? && UI.WidgetExists(Id("FADump"))
×
1439
        UI.ReplaceWidget(
×
1440
          Id("FADump"),
1441
          VBox(
1442
            CheckBox(
1443
              Id("use_fadump"),
1444
              Opt(:notify),
1445
              # T: Checkbox label
1446
              _("Use &Firmware-Assisted Dump"),
1447
              Kdump.using_fadump?
1448
            ),
1449
            VSpacing(1)
1450
          )
1451
        )
1452
      end
1453
    end
1454

1455
    def HandleFADump(_key, event)
1✔
1456
      return if event["ID"] != "use_fadump"
×
1457

1458
      use_fadump_value = UI.QueryWidget(Id("use_fadump"), :Value)
×
1459

1460
      # If cannot adjust the fadump usage
1461
      if !Kdump.use_fadump(use_fadump_value)
×
1462
        UI.ChangeWidget(Id("use_fadump"), :Value, false)
×
1463
        return
×
1464
      end
1465

1466
      UI.ChangeWidget(Id(:auto_resize), :Value, false)
×
1467
      UI.ChangeWidget(Id(:allocated_memory_box), :Enabled, true)
×
1468
      UI.ChangeWidget(Id(:auto_resize), :Enabled, !use_fadump_value)
×
1469

1470
      update_usable_memory
×
1471
      refresh_kdump_memory
×
1472

1473
      nil
1474
    end
1475

1476
    def refresh_kdump_memory
1✔
1477
      widget_id = Id("allocated_low_memory")
×
1478
      value = UI.QueryWidget(widget_id, :Value)
×
1479
      UI.ReplaceWidget(Id("allocated_low_memory_rp"), low_memory_widget(value))
×
1480
    end
1481

1482
    # Function initializes option
1483
    # "Custom kdump Kernel"
1484

1485
    def InitInitrdKernel(_key)
1✔
1486
      UI.ChangeWidget(
×
1487
        Id("InitrdKernel"),
1488
        :Value,
1489
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_KERNELVER")
1490
      )
1491

1492
      nil
1493
    end
1494

1495
    # Function stores option
1496
    # "Custom kdump Kernel"
1497
    def StoreInitrdKernel(_key, _event)
1✔
1498
      Ops.set(
×
1499
        Kdump.KDUMP_SETTINGS,
1500
        "KDUMP_KERNELVER",
1501
        Builtins.tostring(UI.QueryWidget(Id("InitrdKernel"), :Value))
1502
      )
1503

1504
      nil
1505
    end
1506

1507
    # Function initializes option
1508
    # "Dump Format"
1509

1510
    def InitDumpFormat(_key)
1✔
1511
      if Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT") == "ELF"
×
1512
        UI.ChangeWidget(Id("DumpFormat"), :Value, "elf_format")
×
1513
      elsif Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT") == "compressed"
×
1514
        UI.ChangeWidget(Id("DumpFormat"), :Value, "compressed_format")
×
1515
      elsif Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT") == "lzo"
×
1516
        UI.ChangeWidget(Id("DumpFormat"), :Value, "lzo_format")
×
1517
      else
1518
        UI.ChangeWidget(Id("DumpFormat"), :Value, "none_format")
×
1519
      end
1520

1521
      nil
1522
    end
1523

1524
    # Function validates options in
1525
    # "Dump Format"
1526
    # install makedumpfile if KDUMP_DUMPFORMAT == "compressed"
1527

1528
    def ValidDumpFormat(_key, _event)
1✔
1529
      result = true
×
1530
      value = Builtins.tostring(UI.QueryWidget(Id("DumpFormat"), :Value))
×
1531

1532
      if value != "elf_format" || value.nil?
×
1533
        if Mode.installation || Mode.autoinst
×
1534
          Kdump.kdump_packages = Builtins.add(
×
1535
            Kdump.kdump_packages,
1536
            "makedumpfile"
1537
          )
1538
          Builtins.y2milestone(
×
1539
            "add makedumpfile to selected packages to installation"
1540
          )
1541
        elsif Package.Installed("makedumpfile")
×
1542
          return true
×
1543
        else
1544
          package_list = []
×
1545
          package_list = Builtins.add(package_list, "makedumpfile")
×
1546

1547
          if !Package.CheckAndInstallPackages(package_list)
×
1548
            result = false
×
1549

1550
            if !Mode.commandline
×
1551
              Popup.Error(Message.CannotContinueWithoutPackagesInstalled)
×
1552
            else
1553
              CommandLine.Error(
×
1554
                Message.CannotContinueWithoutPackagesInstalled
1555
              )
1556
            end
1557
            Builtins.y2error(
×
1558
              "[kdump] (ValidDumpFormat) Installation of package list %1 failed or aborted",
1559
              package_list
1560
            )
1561
          else
1562
            result = true
×
1563
          end
1564
        end
1565
      end # end of if ((value != "elf_format") || (value == nil))
1566
      result
×
1567
    end
1568

1569
    # Function stores option
1570
    # "Dump Format"
1571

1572
    def StoreDumpFormat(_key, _event)
1✔
1573
      value = Builtins.tostring(UI.QueryWidget(Id("DumpFormat"), :Value))
×
1574
      if value == "elf_format"
×
1575
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT", "ELF")
×
1576
      elsif value == "compressed_format"
×
1577
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT", "compressed")
×
1578
      elsif value == "lzo_format"
×
1579
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT", "lzo")
×
1580
      else
1581
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_DUMPFORMAT", "none")
×
1582
      end
1583

1584
      nil
1585
    end
1586

1587
    # Function initializes option
1588
    # "Enable Delete Old Dump Images"
1589

1590
    def InitEnableDeleteImages(_key)
1✔
1591
      UI.ChangeWidget(Id("EnableDeleteImages"), :Notify, true)
×
1592
      if Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_KEEP_OLD_DUMPS") != "0"
×
1593
        UI.ChangeWidget(Id("NumberDumps"), :Enabled, true)
×
1594
        UI.ChangeWidget(Id("EnableDeleteImages"), :Value, true)
×
1595
      else
1596
        UI.ChangeWidget(Id("EnableDeleteImages"), :Value, false)
×
1597
        UI.ChangeWidget(Id("NumberDumps"), :Enabled, false)
×
1598
      end
1599

1600
      nil
1601
    end
1602

1603
    #  Hadle function for option
1604
    # "Enable Delete Old Dump Images"
1605

1606
    def HandleEnableDeleteImages(_key, event)
1✔
1607
      ret = Ops.get(event, "ID")
×
1608
      if ret == "EnableDeleteImages"
×
1609
        value = Convert.to_boolean(
×
1610
          UI.QueryWidget(Id("EnableDeleteImages"), :Value)
1611
        )
1612
        if !value
×
1613
          UI.ChangeWidget(Id("NumberDumps"), :Value, Builtins.tointeger("0"))
×
1614
          UI.ChangeWidget(Id("NumberDumps"), :Enabled, false)
×
1615
        else
1616
          UI.ChangeWidget(
×
1617
            Id("NumberDumps"),
1618
            :Value,
1619
            Builtins.tointeger(
1620
              Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_KEEP_OLD_DUMPS")
1621
            )
1622
          )
1623
          UI.ChangeWidget(Id("NumberDumps"), :Enabled, true)
×
1624
        end
1625
      end
1626

1627
      nil
1628
    end
1629

1630
    # Function stores option
1631
    # "Enable Delete Old Dump Images"
1632

1633
    def StoreEnableDeleteImages(_key, _event)
1✔
1634
      value = Convert.to_boolean(
×
1635
        UI.QueryWidget(Id("EnableDeleteImages"), :Value)
1636
      )
1637
      Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_KEEP_OLD_DUMPS", "0") if !value
×
1638

1639
      nil
1640
    end
1641

1642
    # Function initializes option
1643
    # "Enable Copy Kernel into the Dump Directory"
1644

1645
    def InitEnableCopyKernel(_key)
1✔
1646
      if Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_COPY_KERNEL", "no") == "yes"
×
1647
        UI.ChangeWidget(Id("EnableCopyKernel"), :Value, true)
×
1648
      else
1649
        UI.ChangeWidget(Id("EnableCopyKernel"), :Value, false)
×
1650
      end
1651

1652
      nil
1653
    end
1654

1655
    # Function stores option
1656
    # "Enable Copy Kernel into the Dump Directory"
1657

1658
    def StoreEnableCopyKernel(_key, _event)
1✔
1659
      value = Convert.to_boolean(UI.QueryWidget(Id("EnableCopyKernel"), :Value))
×
1660
      if !value
×
1661
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_COPY_KERNEL", "no")
×
1662
      else
1663
        Ops.set(Kdump.KDUMP_SETTINGS, "KDUMP_COPY_KERNEL", "yes")
×
1664
      end
1665

1666
      nil
1667
    end
1668

1669
    # Function initializes option
1670
    # "SMTP Server"
1671
    def InitSMTPServer(_key)
1✔
1672
      UI.ChangeWidget(
×
1673
        Id("SMTPServer"),
1674
        :Value,
1675
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_SMTP_SERVER", "")
1676
      )
1677

1678
      nil
1679
    end
1680

1681
    # Function stores option
1682
    # "SMTP Server"
1683
    def StoreSMTPServer(_key, _event)
1✔
1684
      Ops.set(
×
1685
        Kdump.KDUMP_SETTINGS,
1686
        "KDUMP_SMTP_SERVER",
1687
        Builtins.tostring(UI.QueryWidget(Id("SMTPServer"), :Value))
1688
      )
1689

1690
      nil
1691
    end
1692

1693
    # Function initializes option
1694
    # "User Name" (SMTP Settings)
1695
    def InitSMTPUser(_key)
1✔
1696
      UI.ChangeWidget(
×
1697
        Id("SMTPUser"),
1698
        :Value,
1699
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_SMTP_USER", "")
1700
      )
1701

1702
      nil
1703
    end
1704

1705
    # Function stores option
1706
    # "User Name" (SMTP Settings)
1707
    def StoreSMTPUser(_key, _event)
1✔
1708
      Ops.set(
×
1709
        Kdump.KDUMP_SETTINGS,
1710
        "KDUMP_SMTP_USER",
1711
        Builtins.tostring(UI.QueryWidget(Id("SMTPUser"), :Value))
1712
      )
1713

1714
      nil
1715
    end
1716

1717
    # Function initializes option
1718
    # "Password" (SMTP Settings)
1719
    def InitSMTPPassword(_key)
1✔
1720
      UI.ChangeWidget(
×
1721
        Id("SMTPPassword"),
1722
        :Value,
1723
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_SMTP_PASSWORD", "")
1724
      )
1725

1726
      nil
1727
    end
1728

1729
    # Function stores option
1730
    # "Password" (SMTP Settings)
1731
    def StoreSMTPPassword(_key, _event)
1✔
1732
      Ops.set(
×
1733
        Kdump.KDUMP_SETTINGS,
1734
        "KDUMP_SMTP_PASSWORD",
1735
        Builtins.tostring(UI.QueryWidget(Id("SMTPPassword"), :Value))
1736
      )
1737

1738
      nil
1739
    end
1740

1741
    # Function initializes option
1742
    # "Notification To"
1743
    def InitNotificationTo(_key)
1✔
1744
      UI.ChangeWidget(
×
1745
        Id("NotificationTo"),
1746
        :Value,
1747
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_NOTIFICATION_TO", "")
1748
      )
1749

1750
      nil
1751
    end
1752

1753
    # Function stores option
1754
    # "Notification To"
1755
    def StoreNotificationTo(_key, _event)
1✔
1756
      Ops.set(
×
1757
        Kdump.KDUMP_SETTINGS,
1758
        "KDUMP_NOTIFICATION_TO",
1759
        Builtins.tostring(UI.QueryWidget(Id("NotificationTo"), :Value))
1760
      )
1761

1762
      nil
1763
    end
1764

1765
    # Function initializes option
1766
    # "Notification CC"
1767
    def InitNotificationCC(_key)
1✔
1768
      UI.ChangeWidget(
×
1769
        Id("NotificationCC"),
1770
        :Value,
1771
        Ops.get(Kdump.KDUMP_SETTINGS, "KDUMP_NOTIFICATION_CC", "")
1772
      )
1773

1774
      nil
1775
    end
1776

1777
    # Function stores option
1778
    # "Notification CC"
1779
    def StoreNotificationCC(_key, _event)
1✔
1780
      Ops.set(
×
1781
        Kdump.KDUMP_SETTINGS,
1782
        "KDUMP_NOTIFICATION_CC",
1783
        Builtins.tostring(UI.QueryWidget(Id("NotificationCC"), :Value))
1784
      )
1785

1786
      nil
1787
    end
1788

1789
    # Function validates options in
1790
    # "Dump Format"
1791
    # install makedumpfile if KDUMP_DUMPFORMAT == "compressed"
1792

1793
    def ValidEmail(key, _event)
1✔
1794
      Popup.Message(key)
×
1795
      true
×
1796
    end
1797

1798
    def unsupported_kdump_confirmation
1✔
1799
      text = _(
×
1800
        "Kdump is not supported on this system.\n" \
1801
        "If you continue now, the module may not function properly.\n" \
1802
        "For example, some settings will not be correctly read\n" \
1803
        "and the resulting configuration will probably be useless.\n"
1804
      )
1805
      Popup.ContinueCancelHeadline(_("Kdump not supported"), text)
×
1806
    end
1807
  end
1808
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc