diff options
author | Steven Rostedt <srostedt@redhat.com> | 2012-11-13 14:30:37 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2012-11-13 14:30:37 -0500 |
commit | a15ba91361d46b4cc71d76d5712fb6420b517d8a (patch) | |
tree | cd19df83d9631fea30a7f21f0b00aa987d027e32 /tools | |
parent | 77b67063bb6bce6d475e910d3b886a606d0d91f7 (diff) |
ktest: Add support for grub2
As only grub or 'script' is supported for rebooting to a new kernel,
and Fedora 17 has dropped support for grub, I decided to add grub2
support as well (I also plan on adding syslinux/extlinux support too).
The options GRUB_FILE and GRUB_REBOOT were added to allow the user
to specify where to find the grub.cfg and what tool to use to reboot
into the next kernel respectively.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 69 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 26 |
2 files changed, 91 insertions, 4 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index c7ba7614061b..63245a56aca3 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -53,6 +53,7 @@ my %default = ( | |||
53 | "STOP_AFTER_FAILURE" => 60, | 53 | "STOP_AFTER_FAILURE" => 60, |
54 | "STOP_TEST_AFTER" => 600, | 54 | "STOP_TEST_AFTER" => 600, |
55 | "MAX_MONITOR_WAIT" => 1800, | 55 | "MAX_MONITOR_WAIT" => 1800, |
56 | "GRUB_REBOOT" => "grub2-reboot", | ||
56 | 57 | ||
57 | # required, and we will ask users if they don't have them but we keep the default | 58 | # required, and we will ask users if they don't have them but we keep the default |
58 | # value something that is common. | 59 | # value something that is common. |
@@ -105,7 +106,9 @@ my $scp_to_target; | |||
105 | my $scp_to_target_install; | 106 | my $scp_to_target_install; |
106 | my $power_off; | 107 | my $power_off; |
107 | my $grub_menu; | 108 | my $grub_menu; |
109 | my $grub_file; | ||
108 | my $grub_number; | 110 | my $grub_number; |
111 | my $grub_reboot; | ||
109 | my $target; | 112 | my $target; |
110 | my $make; | 113 | my $make; |
111 | my $pre_install; | 114 | my $pre_install; |
@@ -232,6 +235,8 @@ my %option_map = ( | |||
232 | "ADD_CONFIG" => \$addconfig, | 235 | "ADD_CONFIG" => \$addconfig, |
233 | "REBOOT_TYPE" => \$reboot_type, | 236 | "REBOOT_TYPE" => \$reboot_type, |
234 | "GRUB_MENU" => \$grub_menu, | 237 | "GRUB_MENU" => \$grub_menu, |
238 | "GRUB_FILE" => \$grub_file, | ||
239 | "GRUB_REBOOT" => \$grub_reboot, | ||
235 | "PRE_INSTALL" => \$pre_install, | 240 | "PRE_INSTALL" => \$pre_install, |
236 | "POST_INSTALL" => \$post_install, | 241 | "POST_INSTALL" => \$post_install, |
237 | "NO_INSTALL" => \$no_install, | 242 | "NO_INSTALL" => \$no_install, |
@@ -368,7 +373,7 @@ EOF | |||
368 | ; | 373 | ; |
369 | $config_help{"REBOOT_TYPE"} = << "EOF" | 374 | $config_help{"REBOOT_TYPE"} = << "EOF" |
370 | Way to reboot the box to the test kernel. | 375 | Way to reboot the box to the test kernel. |
371 | Only valid options so far are "grub" and "script". | 376 | Only valid options so far are "grub", "grub2", and "script". |
372 | 377 | ||
373 | If you specify grub, it will assume grub version 1 | 378 | If you specify grub, it will assume grub version 1 |
374 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU | 379 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU |
@@ -378,11 +383,14 @@ $config_help{"REBOOT_TYPE"} = << "EOF" | |||
378 | 383 | ||
379 | The entry in /boot/grub/menu.lst must be entered in manually. | 384 | The entry in /boot/grub/menu.lst must be entered in manually. |
380 | The test will not modify that file. | 385 | The test will not modify that file. |
386 | |||
387 | If you specify grub2, then you also need to specify both \$GRUB_MENU | ||
388 | and \$GRUB_FILE. | ||
381 | EOF | 389 | EOF |
382 | ; | 390 | ; |
383 | $config_help{"GRUB_MENU"} = << "EOF" | 391 | $config_help{"GRUB_MENU"} = << "EOF" |
384 | The grub title name for the test kernel to boot | 392 | The grub title name for the test kernel to boot |
385 | (Only mandatory if REBOOT_TYPE = grub) | 393 | (Only mandatory if REBOOT_TYPE = grub or grub2) |
386 | 394 | ||
387 | Note, ktest.pl will not update the grub menu.lst, you need to | 395 | Note, ktest.pl will not update the grub menu.lst, you need to |
388 | manually add an option for the test. ktest.pl will search | 396 | manually add an option for the test. ktest.pl will search |
@@ -393,6 +401,17 @@ $config_help{"GRUB_MENU"} = << "EOF" | |||
393 | title Test Kernel | 401 | title Test Kernel |
394 | kernel vmlinuz-test | 402 | kernel vmlinuz-test |
395 | GRUB_MENU = Test Kernel | 403 | GRUB_MENU = Test Kernel |
404 | |||
405 | For grub2, a search of \$GRUB_FILE is performed for the lines | ||
406 | that begin with "menuentry". It will not detect submenus. The | ||
407 | menu must be a non-nested menu. Add the quotes used in the menu | ||
408 | to guarantee your selection, as the first menuentry with the content | ||
409 | of \$GRUB_MENU that is found will be used. | ||
410 | EOF | ||
411 | ; | ||
412 | $config_help{"GRUB_FILE"} = << "EOF" | ||
413 | If grub2 is used, the full path for the grub.cfg file is placed | ||
414 | here. Use something like /boot/grub2/grub.cfg to search. | ||
396 | EOF | 415 | EOF |
397 | ; | 416 | ; |
398 | $config_help{"REBOOT_SCRIPT"} = << "EOF" | 417 | $config_help{"REBOOT_SCRIPT"} = << "EOF" |
@@ -521,6 +540,11 @@ sub get_ktest_configs { | |||
521 | if ($rtype eq "grub") { | 540 | if ($rtype eq "grub") { |
522 | get_ktest_config("GRUB_MENU"); | 541 | get_ktest_config("GRUB_MENU"); |
523 | } | 542 | } |
543 | |||
544 | if ($rtype eq "grub2") { | ||
545 | get_ktest_config("GRUB_MENU"); | ||
546 | get_ktest_config("GRUB_FILE"); | ||
547 | } | ||
524 | } | 548 | } |
525 | 549 | ||
526 | sub process_variables { | 550 | sub process_variables { |
@@ -1452,8 +1476,44 @@ sub run_scp_mod { | |||
1452 | return run_scp($src, $dst, $cp_scp); | 1476 | return run_scp($src, $dst, $cp_scp); |
1453 | } | 1477 | } |
1454 | 1478 | ||
1479 | sub get_grub2_index { | ||
1480 | |||
1481 | return if (defined($grub_number)); | ||
1482 | |||
1483 | doprint "Find grub2 menu ... "; | ||
1484 | $grub_number = -1; | ||
1485 | |||
1486 | my $ssh_grub = $ssh_exec; | ||
1487 | $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g; | ||
1488 | |||
1489 | open(IN, "$ssh_grub |") | ||
1490 | or die "unable to get $grub_file"; | ||
1491 | |||
1492 | my $found = 0; | ||
1493 | |||
1494 | while (<IN>) { | ||
1495 | if (/^menuentry.*$grub_menu/) { | ||
1496 | $grub_number++; | ||
1497 | $found = 1; | ||
1498 | last; | ||
1499 | } elsif (/^menuentry\s/) { | ||
1500 | $grub_number++; | ||
1501 | } | ||
1502 | } | ||
1503 | close(IN); | ||
1504 | |||
1505 | die "Could not find '$grub_menu' in $grub_file on $machine" | ||
1506 | if (!$found); | ||
1507 | doprint "$grub_number\n"; | ||
1508 | } | ||
1509 | |||
1455 | sub get_grub_index { | 1510 | sub get_grub_index { |
1456 | 1511 | ||
1512 | if ($reboot_type eq "grub2") { | ||
1513 | get_grub2_index; | ||
1514 | return; | ||
1515 | } | ||
1516 | |||
1457 | if ($reboot_type ne "grub") { | 1517 | if ($reboot_type ne "grub") { |
1458 | return; | 1518 | return; |
1459 | } | 1519 | } |
@@ -1524,6 +1584,8 @@ sub reboot_to { | |||
1524 | 1584 | ||
1525 | if ($reboot_type eq "grub") { | 1585 | if ($reboot_type eq "grub") { |
1526 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; | 1586 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; |
1587 | } elsif ($reboot_type eq "grub2") { | ||
1588 | run_ssh "$grub_reboot $grub_number"; | ||
1527 | } elsif (defined $reboot_script) { | 1589 | } elsif (defined $reboot_script) { |
1528 | run_command "$reboot_script"; | 1590 | run_command "$reboot_script"; |
1529 | } | 1591 | } |
@@ -3700,6 +3762,9 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3700 | $target = "$ssh_user\@$machine"; | 3762 | $target = "$ssh_user\@$machine"; |
3701 | if ($reboot_type eq "grub") { | 3763 | if ($reboot_type eq "grub") { |
3702 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); | 3764 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
3765 | } elsif ($reboot_type eq "grub2") { | ||
3766 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); | ||
3767 | dodie "GRUB_FILE not defined" if (!defined($grub_file)); | ||
3703 | } | 3768 | } |
3704 | } | 3769 | } |
3705 | 3770 | ||
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index de28a0a3b8fc..57617ec88c3b 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -332,8 +332,18 @@ | |||
332 | # from other linux builds on the system. | 332 | # from other linux builds on the system. |
333 | #LOCALVERSION = -test | 333 | #LOCALVERSION = -test |
334 | 334 | ||
335 | # For REBOOT_TYPE = grub2, you must specify where the grub.cfg | ||
336 | # file is. This is the file that is searched to find the menu | ||
337 | # option to boot to with GRUB_REBOOT | ||
338 | #GRUB_FILE = /boot/grub2/grub.cfg | ||
339 | |||
340 | # The tool for REBOOT_TYPE = grub2 to set the next reboot kernel | ||
341 | # to boot into (one shot mode). | ||
342 | # (default grub2_reboot) | ||
343 | #GRUB_REBOOT = grub2_reboot | ||
344 | |||
335 | # The grub title name for the test kernel to boot | 345 | # The grub title name for the test kernel to boot |
336 | # (Only mandatory if REBOOT_TYPE = grub) | 346 | # (Only mandatory if REBOOT_TYPE = grub or grub2) |
337 | # | 347 | # |
338 | # Note, ktest.pl will not update the grub menu.lst, you need to | 348 | # Note, ktest.pl will not update the grub menu.lst, you need to |
339 | # manually add an option for the test. ktest.pl will search | 349 | # manually add an option for the test. ktest.pl will search |
@@ -343,6 +353,15 @@ | |||
343 | # For example, if in the /boot/grub/menu.lst the test kernel title has: | 353 | # For example, if in the /boot/grub/menu.lst the test kernel title has: |
344 | # title Test Kernel | 354 | # title Test Kernel |
345 | # kernel vmlinuz-test | 355 | # kernel vmlinuz-test |
356 | # | ||
357 | # For grub2, a search of top level "menuentry"s are done. No | ||
358 | # submenu is searched. The menu is found by searching for the | ||
359 | # contents of GRUB_MENU in the line that starts with "menuentry". | ||
360 | # You may want to include the quotes around the option. For example: | ||
361 | # for: menuentry 'Test Kernel' | ||
362 | # do a: GRUB_MENU = 'Test Kernel' | ||
363 | # For customizing, add your entry in /etc/grub.d/40_custom. | ||
364 | # | ||
346 | #GRUB_MENU = Test Kernel | 365 | #GRUB_MENU = Test Kernel |
347 | 366 | ||
348 | # A script to reboot the target into the test kernel | 367 | # A script to reboot the target into the test kernel |
@@ -497,7 +516,7 @@ | |||
497 | #POST_BUILD_DIE = 1 | 516 | #POST_BUILD_DIE = 1 |
498 | 517 | ||
499 | # Way to reboot the box to the test kernel. | 518 | # Way to reboot the box to the test kernel. |
500 | # Only valid options so far are "grub" and "script" | 519 | # Only valid options so far are "grub", "grub2" and "script" |
501 | # (default grub) | 520 | # (default grub) |
502 | # If you specify grub, it will assume grub version 1 | 521 | # If you specify grub, it will assume grub version 1 |
503 | # and will search in /boot/grub/menu.lst for the title $GRUB_MENU | 522 | # and will search in /boot/grub/menu.lst for the title $GRUB_MENU |
@@ -505,6 +524,9 @@ | |||
505 | # your setup, then specify "script" and have a command or script | 524 | # your setup, then specify "script" and have a command or script |
506 | # specified in REBOOT_SCRIPT to boot to the target. | 525 | # specified in REBOOT_SCRIPT to boot to the target. |
507 | # | 526 | # |
527 | # For REBOOT_TYPE = grub2, you must define both GRUB_MENU and | ||
528 | # GRUB_FILE. | ||
529 | # | ||
508 | # The entry in /boot/grub/menu.lst must be entered in manually. | 530 | # The entry in /boot/grub/menu.lst must be entered in manually. |
509 | # The test will not modify that file. | 531 | # The test will not modify that file. |
510 | #REBOOT_TYPE = grub | 532 | #REBOOT_TYPE = grub |