~blake-rouse/curtin/uefi-clear-reorder

« back to all changes in this revision

Viewing changes to tests/unittests/test_util.py

  • Committer: Blake Rouse
  • Date: 2017-05-12 00:49:43 UTC
  • Revision ID: blake.rouse@canonical.com-20170512004943-eg8j0iu5tz2pv7h8
Refactor from code review, add more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import stat
5
5
import shutil
6
6
import tempfile
 
7
from textwrap import dedent
7
8
 
8
9
from curtin import util
9
10
from .helpers import simple_mocked_open
683
684
        ])
684
685
 
685
686
 
 
687
class TestGetEFIBootMGR(TestCase):
 
688
 
 
689
    def setUp(self):
 
690
        super(TestGetEFIBootMGR, self).setUp()
 
691
        mock_chroot = mock.patch(
 
692
            'curtin.util.ChrootableTarget', autospec=True)
 
693
        self.mock_chroot = mock_chroot.start()
 
694
        self.addCleanup(mock_chroot.stop)
 
695
        self.mock_in_chroot = mock.MagicMock()
 
696
        self.mock_in_chroot.__enter__.return_value = self.mock_in_chroot
 
697
        self.in_chroot_subp_output = []
 
698
        self.mock_in_chroot_subp = self.mock_in_chroot.subp
 
699
        self.mock_in_chroot_subp.side_effect = self.in_chroot_subp_output
 
700
        self.mock_chroot.return_value = self.mock_in_chroot
 
701
 
 
702
    def test_calls_efibootmgr_verbose(self):
 
703
        self.in_chroot_subp_output.append(('', ''))
 
704
        util.get_efibootmgr('target')
 
705
        self.assertEquals(
 
706
            (['efibootmgr', '-v'],),
 
707
            self.mock_in_chroot_subp.call_args_list[0][0])
 
708
 
 
709
    def test_parses_output(self):
 
710
        self.in_chroot_subp_output.append((dedent(
 
711
            """\
 
712
            BootCurrent: 0000
 
713
            Timeout: 1 seconds
 
714
            BootOrder: 0000,0002,0001,0003,0004,0005
 
715
            Boot0000* ubuntu    HD(1,GPT)/File(\\EFI\\ubuntu\\shimx64.efi)
 
716
            Boot0001* CD/DVD Drive      BBS(CDROM,,0x0)
 
717
            Boot0002* Hard Drive        BBS(HD,,0x0)
 
718
            Boot0003* UEFI:CD/DVD Drive BBS(129,,0x0)
 
719
            Boot0004* UEFI:Removable Device     BBS(130,,0x0)
 
720
            Boot0005* UEFI:Network Device       BBS(131,,0x0)
 
721
            """), ''))
 
722
        observed = util.get_efibootmgr('target')
 
723
        self.assertEquals({
 
724
            'current': '0000',
 
725
            'timeout': '1 seconds',
 
726
            'order': ['0000', '0002', '0001', '0003', '0004', '0005'],
 
727
            'entries': {
 
728
                '0000': {
 
729
                    'name': 'ubuntu',
 
730
                    'path': 'HD(1,GPT)/File(\\EFI\\ubuntu\\shimx64.efi)',
 
731
                },
 
732
                '0001': {
 
733
                    'name': 'CD/DVD Drive',
 
734
                    'path': 'BBS(CDROM,,0x0)',
 
735
                },
 
736
                '0002': {
 
737
                    'name': 'Hard Drive',
 
738
                    'path': 'BBS(HD,,0x0)',
 
739
                },
 
740
                '0003': {
 
741
                    'name': 'UEFI:CD/DVD Drive',
 
742
                    'path': 'BBS(129,,0x0)',
 
743
                },
 
744
                '0004': {
 
745
                    'name': 'UEFI:Removable Device',
 
746
                    'path': 'BBS(130,,0x0)',
 
747
                },
 
748
                '0005': {
 
749
                    'name': 'UEFI:Network Device',
 
750
                    'path': 'BBS(131,,0x0)',
 
751
                },
 
752
            }
 
753
        }, observed)
 
754
 
 
755
 
686
756
# vi: ts=4 expandtab syntax=python