Exemple #1
0
    def test__is_bootloader_loaded(self, mock_execute,
                                   mock_dispatch):
        mock_dispatch.return_value = hardware.BootInfo(
            current_boot_mode='bios')
        parted_output = ('BYT;\n'
                         '/dev/loop1:46.1MB:loopback:512:512:gpt:Loopback '
                         'device:;\n'
                         '15:1049kB:9437kB:8389kB:::boot;\n'
                         '1:9437kB:46.1MB:36.7MB:ext3::;\n')
        disk_file_output = ('/dev/loop1: partition 1: ID=0xee, starthead 0, '
                            'startsector 1, 90111 sectors, extended '
                            'partition table (last)\011, code offset 0x48')

        part_file_output = ('/dev/loop1p15: x86 boot sector, mkdosfs boot '
                            'message display, code offset 0x3c, OEM-ID '
                            '"mkfs.fat", sectors/cluster 8, root entries '
                            '512, sectors 16384 (volumes <=32 MB) , Media '
                            'descriptor 0xf8, sectors/FAT 8, heads 255, '
                            'serial number 0x23a08feb, unlabeled, '
                            'FAT (12 bit)')

        # NOTE(TheJulia): File evaluates this data, so it is pointless to
        # try and embed the raw bytes in the test.
        dd_output = ('')

        file_output = ('/dev/loop1: DOS executable (COM)\n')

        mock_execute.side_effect = iter([(parted_output, ''),
                                         (disk_file_output, ''),
                                         (part_file_output, ''),
                                         (dd_output, ''),
                                         (file_output, '')])

        result = image._is_bootloader_loaded(self.fake_dev)
        self.assertTrue(result)
Exemple #2
0
 def setUp(self):
     super(BaseDiscoverTest, self).setUp()
     self.inventory = {
         'interfaces': [
             hardware.NetworkInterface(name='em1',
                                       mac_addr='aa:bb:cc:dd:ee:ff',
                                       ipv4_address='1.1.1.1'),
             hardware.NetworkInterface(name='em2',
                                       mac_addr='11:22:33:44:55:66',
                                       ipv4_address=None),
         ],
         'cpu': hardware.CPU(model_name='generic', frequency='3000',
                             count=4, architecture='x86_64'),
         'memory': hardware.Memory(total=11998396 * 1024,
                                   physical_mb=12288),
         'disks': [
             hardware.BlockDevice(name='/dev/sdc',
                                  model='Disk 2',
                                  size=500107862016,
                                  rotational=False),
             hardware.BlockDevice(name='/dev/sda',
                                  model='Too Small Disk',
                                  size=4294967295,
                                  rotational=False),
             hardware.BlockDevice(name='/dev/sdb',
                                  model='Disk 1',
                                  size=500107862016,
                                  rotational=True)
         ],
         'bmc_address': '1.2.3.4',
         'boot': hardware.BootInfo(current_boot_mode='bios',
                                   pxe_interface='boot:if')
     }
     self.failures = utils.AccumulatedFailures()
     self.data = {}
Exemple #3
0
    def test__is_bootloader_loaded_uefi_mode(self, mock_execute,
                                             mock_dispatch):

        mock_dispatch.return_value = hardware.BootInfo(
            current_boot_mode='uefi')
        result = image._is_bootloader_loaded(self.fake_dev)
        self.assertFalse(result)
        mock_dispatch.assert_any_call('get_boot_info')
        self.assertEqual(0, mock_execute.call_count)
    def test_list_hardware_info(self):
        self.hardware.list_network_interfaces = mock.Mock()
        self.hardware.list_network_interfaces.return_value = [
            hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'),
            hardware.NetworkInterface('eth1', '00:0c:29:8c:11:b2'),
        ]

        self.hardware.get_cpus = mock.Mock()
        self.hardware.get_cpus.return_value = hardware.CPU(
            'Awesome CPU x14 9001',
            9001,
            14,
            'x86_64')

        self.hardware.get_memory = mock.Mock()
        self.hardware.get_memory.return_value = hardware.Memory(1017012)

        self.hardware.list_block_devices = mock.Mock()
        self.hardware.list_block_devices.return_value = [
            hardware.BlockDevice('/dev/sdj', 'big', 1073741824, True),
            hardware.BlockDevice('/dev/hdaa', 'small', 65535, False),
        ]

        self.hardware.list_physical_devices = mock.Mock()
        self.hardware.list_physical_devices.return_value = [
            arcconf.PhysicalDisk(ID='0 0',
                                 ControllerID='1',
                                 Type='SAS',
                                 Size='558.91 GB'),
            arcconf.PhysicalDisk(ID='0 1',
                                 ControllerID='1',
                                 Type='SAS',
                                 Size='558.91 GB'),
        ]

        self.hardware.get_boot_info = mock.Mock()
        self.hardware.get_boot_info.return_value = hardware.BootInfo(
            current_boot_mode='bios', pxe_interface='boot:if')

        self.hardware.get_bmc_address = mock.Mock()
        self.hardware.get_system_vendor_info = mock.Mock()

        hardware_info = self.hardware.list_hardware_info()
        self.assertEqual(self.hardware.get_memory(),
                         hardware_info['memory'])
        self.assertEqual(self.hardware.get_cpus(), hardware_info['cpu'])
        self.assertEqual(self.hardware.list_block_devices(),
                         hardware_info['disks'])
        self.assertEqual(self.hardware.list_physical_devices(),
                         hardware_info['physical_disks'])
        self.assertEqual(self.hardware.list_network_interfaces(),
                         hardware_info['interfaces'])
        self.assertEqual(self.hardware.get_boot_info(),
                         hardware_info['boot'])
Exemple #5
0
 def test_install_bootloader_failure(self, mock_iscsi_clean, mock_execute,
                                     mock_dispatch):
     mock_dispatch.side_effect = [
         self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
     ]
     mock_execute.side_effect = FileNotFoundError
     self.assertRaises(FileNotFoundError,
                       self.agent_extension.install_bootloader,
                       root_uuid=self.fake_root_uuid,
                       efi_system_part_uuid=None)
     expected = [mock.call('efibootmgr', '--version')]
     mock_execute.assert_has_calls(expected)
Exemple #6
0
 def test__install_bootloader_bios(self, mock_grub2, mock_iscsi_clean,
                                   mock_execute, mock_dispatch):
     mock_dispatch.side_effect = [
         self.fake_dev, hardware.BootInfo(current_boot_mode='bios')
     ]
     self.agent_extension.install_bootloader(root_uuid=self.fake_root_uuid)
     mock_dispatch.assert_any_call('get_os_install_device')
     mock_dispatch.assert_any_call('get_boot_info')
     self.assertEqual(2, mock_dispatch.call_count)
     mock_grub2.assert_called_once_with(
         self.fake_dev, root_uuid=self.fake_root_uuid,
         efi_system_part_uuid=None, prep_boot_part_uuid=None)
     mock_iscsi_clean.assert_called_once_with(self.fake_dev)
Exemple #7
0
    def test__add_multi_bootloaders(
            self, mkdir_mock, mock_utils_efi_part, mock_partition,
            mock_efi_bl, mock_iscsi_clean, mock_execute, mock_dispatch):
        mock_dispatch.side_effect = [
            self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
        ]
        mock_partition.return_value = self.fake_dev
        mock_utils_efi_part.return_value = '1'
        mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI',
                                    '\\WINDOWS\\system32\\winload.efi']

        mock_execute.side_effect = iter([('', ''), ('', ''),
                                         ('', ''), ('', ''),
                                         ('', ''), ('', ''),
                                         ('', ''), ('', ''),
                                         ('', '')])

        expected = [mock.call('efibootmgr', '--version'),
                    mock.call('partx', '-u', '/dev/fake', attempts=3,
                              delay_on_retry=True),
                    mock.call('udevadm', 'settle'),
                    mock.call('mount', self.fake_efi_system_part,
                              self.fake_dir + '/boot/efi'),
                    mock.call('efibootmgr'),
                    mock.call('efibootmgr', '-c', '-d', self.fake_dev,
                              '-p', '1', '-w',
                              '-L', 'ironic1', '-l',
                              '\\EFI\\BOOT\\BOOTX64.EFI'),
                    mock.call('efibootmgr', '-c', '-d', self.fake_dev,
                              '-p', '1', '-w',
                              '-L', 'ironic2', '-l',
                              '\\WINDOWS\\system32\\winload.efi'),
                    mock.call('umount', self.fake_dir + '/boot/efi',
                              attempts=3, delay_on_retry=True),
                    mock.call('sync')]

        self.agent_extension.install_bootloader(
            root_uuid=self.fake_root_uuid,
            efi_system_part_uuid=None)

        mock_dispatch.assert_any_call('get_os_install_device')
        mock_dispatch.assert_any_call('get_boot_info')
        mkdir_mock.assert_called_once_with(self.fake_dir + '/boot/efi')
        mock_efi_bl.assert_called_once_with(self.fake_dir + '/boot/efi')
        mock_execute.assert_has_calls(expected)
        mock_utils_efi_part.assert_called_once_with(self.fake_dev)
        self.assertEqual(9, mock_execute.call_count)
Exemple #8
0
    def test__uefi_bootloader_with_entry_removal(
            self, mkdir_mock, mock_utils_efi_part, mock_partition,
            mock_efi_bl, mock_iscsi_clean, mock_execute, mock_dispatch):
        mock_dispatch.side_effect = [
            self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
        ]
        mock_partition.return_value = self.fake_dev
        mock_utils_efi_part.return_value = '1'
        mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
        stdeer_msg = """
efibootmgr: ** Warning ** : Boot0004 has same label ironic1\n
efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
"""
        mock_execute.side_effect = iter([('', ''), ('', ''),
                                         ('', ''), ('', ''),
                                         ('', ''), ('', stdeer_msg),
                                         ('', ''), ('', ''),
                                         ('', ''), ('', '')])

        expected = [mock.call('efibootmgr', '--version'),
                    mock.call('partx', '-u', '/dev/fake', attempts=3,
                              delay_on_retry=True),
                    mock.call('udevadm', 'settle'),
                    mock.call('mount', self.fake_efi_system_part,
                              self.fake_dir + '/boot/efi'),
                    mock.call('efibootmgr'),
                    mock.call('efibootmgr', '-c', '-d', self.fake_dev,
                              '-p', '1', '-w',
                              '-L', 'ironic1', '-l',
                              '\\EFI\\BOOT\\BOOTX64.EFI'),
                    mock.call('efibootmgr', '-b', '0004', '-B'),
                    mock.call('efibootmgr', '-b', '0005', '-B'),
                    mock.call('umount', self.fake_dir + '/boot/efi',
                              attempts=3, delay_on_retry=True),
                    mock.call('sync')]

        self.agent_extension.install_bootloader(
            root_uuid=self.fake_root_uuid,
            efi_system_part_uuid=None)

        mock_dispatch.assert_any_call('get_os_install_device')
        mock_dispatch.assert_any_call('get_boot_info')
        mkdir_mock.assert_called_once_with(self.fake_dir + '/boot/efi')
        mock_efi_bl.assert_called_once_with(self.fake_dir + '/boot/efi')
        mock_execute.assert_has_calls(expected)
        mock_utils_efi_part.assert_called_once_with(self.fake_dev)
        self.assertEqual(10, mock_execute.call_count)
    def test_install_bootloader_failure(self, mock_iscsi_clean, mock_execute,
                                        mock_dispatch):
        # NOTE(iurygregory): adaptation for py27 since we don't have
        # FileNotFoundError defined.
        try:
            FileNotFoundError
        except NameError:
            FileNotFoundError = OSError

        mock_dispatch.side_effect = [
            self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
        ]
        mock_execute.side_effect = FileNotFoundError
        self.assertRaises(FileNotFoundError,
                          self.agent_extension.install_bootloader,
                          root_uuid=self.fake_root_uuid,
                          efi_system_part_uuid=None)
        expected = [mock.call('efibootmgr', '--version')]
        mock_execute.assert_has_calls(expected)