|
7 | 7 | "fmt" |
8 | 8 | "os" |
9 | 9 | "path/filepath" |
| 10 | + "regexp" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "github.com/microsoft/azure-linux-image-tools/toolkit/tools/imagecustomizerapi" |
@@ -652,15 +653,39 @@ func testCustomizeImageKernelCommandLineAddHelper(t *testing.T, testName string, |
652 | 653 | } |
653 | 654 | defer imageConnection.Close() |
654 | 655 |
|
655 | | - // Read the grub.cfg file. |
656 | | - grub2ConfigFilePath := filepath.Join(imageConnection.Chroot().RootDir(), installutils.FedoraGrubCfgFile) |
657 | | - |
658 | | - grub2ConfigFile, err := os.ReadFile(grub2ConfigFilePath) |
659 | | - if !assert.NoError(t, err) { |
660 | | - return |
| 656 | + if baseImageInfo.Version == baseImageVersionAzl4 { |
| 657 | + // AZL4 uses BLS (Boot Loader Specification) entries instead of inline linux lines in grub.cfg. |
| 658 | + blsEntriesDir := filepath.Join(imageConnection.Chroot().RootDir(), "/boot/loader/entries") |
| 659 | + blsEntries, err := os.ReadDir(blsEntriesDir) |
| 660 | + if !assert.NoError(t, err, "read BLS entries dir") { |
| 661 | + return |
| 662 | + } |
| 663 | + |
| 664 | + blsOptionsRegex := regexp.MustCompile(`(?m)^options\s+.* console=tty0 console=ttyS0`) |
| 665 | + entryCount := 0 |
| 666 | + for _, entry := range blsEntries { |
| 667 | + if !entry.IsDir() && filepath.Ext(entry.Name()) == ".conf" { |
| 668 | + entryCount++ |
| 669 | + blsPath := filepath.Join(blsEntriesDir, entry.Name()) |
| 670 | + blsContents, readErr := file.Read(blsPath) |
| 671 | + if !assert.NoError(t, readErr, "read BLS entry %s", entry.Name()) { |
| 672 | + continue |
| 673 | + } |
| 674 | + assert.Regexp(t, blsOptionsRegex, blsContents, |
| 675 | + "BLS entry %s should contain extraCommandLine args", entry.Name()) |
| 676 | + } |
| 677 | + } |
| 678 | + assert.GreaterOrEqual(t, entryCount, 1, "BLS entry files in %s", blsEntriesDir) |
| 679 | + } else { |
| 680 | + // Read the grub.cfg file. |
| 681 | + grub2ConfigFilePath := filepath.Join(imageConnection.Chroot().RootDir(), installutils.FedoraGrubCfgFile) |
| 682 | + grub2ConfigFile, err := os.ReadFile(grub2ConfigFilePath) |
| 683 | + if !assert.NoError(t, err) { |
| 684 | + return |
| 685 | + } |
| 686 | + |
| 687 | + assert.Regexp(t, `linux\s+.*\s+console=tty0 console=ttyS0\s+`, grub2ConfigFile) |
661 | 688 | } |
662 | | - |
663 | | - assert.Regexp(t, `linux\s+.*\s+console=tty0 console=ttyS0\s+`, grub2ConfigFile) |
664 | 689 | } |
665 | 690 |
|
666 | 691 | func TestCustomizeImage_OutputImageFileSelection(t *testing.T) { |
|
0 commit comments