Skip to content

Commit e314350

Browse files
committed
Coverage: add a test for Bootloader.newDefault
Coverage change: xcp.bootloader: 72.8% -> 81.9% total: 65.4% -> 66.6% Signed-off-by: Yann Dirson <[email protected]>
1 parent e1474df commit e314350

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/data/grub-linux.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set default=0
2+
menuentry 'linux' {
3+
linux /boot/vmlinuz-1 ro
4+
initrd /boot/initrd.img-1
5+
}

tests/test_bootloader.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import unittest
22
import os
3+
import shutil
34
import subprocess
4-
from tempfile import NamedTemporaryFile
5+
from tempfile import NamedTemporaryFile, mkdtemp
56

67
from xcp.bootloader import Bootloader
78

@@ -21,6 +22,25 @@ def test_grub2(self):
2122
proc.stdout.close()
2223
proc.wait()
2324

25+
class TestLinuxBootloader(unittest.TestCase):
26+
def setUp(self):
27+
self.tmpdir = mkdtemp(prefix="testbl")
28+
bootdir = os.path.join(self.tmpdir, "boot")
29+
grubdir = os.path.join(bootdir, "grub")
30+
os.makedirs(grubdir)
31+
shutil.copyfile("tests/data/grub-linux.cfg", os.path.join(grubdir, "grub.cfg"))
32+
with open(os.path.join(bootdir, "vmlinuz-1"), "w"):
33+
pass
34+
with open(os.path.join(bootdir, "vmlinuz-2"), "w"):
35+
pass
36+
with open(os.path.join(bootdir, "initrd.img-1"), "w"):
37+
pass
38+
with open(os.path.join(bootdir, "initrd.img-2"), "w"):
39+
pass
40+
def tearDown(self):
41+
shutil.rmtree(self.tmpdir)
42+
def test_grub2_newdefault(self):
43+
Bootloader.newDefault("/boot/vmlinuz-2", "/boot/initrd.img-2", root=self.tmpdir)
2444

2545
class TestBootloaderAdHoc(unittest.TestCase):
2646
def setUp(self):

0 commit comments

Comments
 (0)