def test_lio_not_available(self, mock_execute):
     mock_execute.return_value = ('', '')
     expected = [mock.call('tgtadm', '--lld', 'iscsi', '--mode',
                           'target', '--op', 'unbind', '--tid', '1',
                           '--initiator-address', 'ALL'),
                 mock.call('sync'),
                 mock.call('tgtadm', '--lld', 'iscsi', '--mode', 'target',
                           '--op', 'delete', '--tid', '1')]
     iscsi.clean_up(self.fake_dev)
     mock_execute.assert_has_calls(expected)
Пример #2
0
 def test_commands_fail(self, mock_execute):
     mock_execute.side_effect = [
         processutils.ProcessExecutionError(), ('', ''),
         processutils.ProcessExecutionError()
     ]
     expected = [
         mock.call('tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
                   'unbind', '--tid', '1', '--initiator-address', 'ALL'),
         mock.call('sync'),
         mock.call('tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
                   'delete', '--tid', '1')
     ]
     iscsi.clean_up(self.fake_dev)
     mock_execute.assert_has_calls(expected)
Пример #3
0
    def install_bootloader(self, root_uuid, efi_system_part_uuid=None):
        """Install the GRUB2 bootloader on the image.

        :param root_uuid: The UUID of the root partition.
        :param efi_system_part_uuid: The UUID of the efi system partition.
            To be used only for uefi boot mode.  For uefi boot mode, the
            boot loader will be installed here.
        :raises: CommandExecutionError if the installation of the
                 bootloader fails.
        :raises: DeviceNotFound if the root partition is not found.

        """
        device = hardware.dispatch_to_managers("get_os_install_device")
        iscsi.clean_up(device)
        _install_grub2(device, root_uuid=root_uuid, efi_system_part_uuid=efi_system_part_uuid)
Пример #4
0
    def install_bootloader(self,
                           root_uuid,
                           efi_system_part_uuid=None,
                           prep_boot_part_uuid=None,
                           target_boot_mode='bios'):
        """Install the GRUB2 bootloader on the image.

        :param root_uuid: The UUID of the root partition.
        :param efi_system_part_uuid: The UUID of the efi system partition.
            To be used only for uefi boot mode.  For uefi boot mode, the
            boot loader will be installed here.
        :param prep_boot_part_uuid: The UUID of the PReP Boot partition.
            Used only for booting ppc64* partition images locally. In this
            scenario the bootloader will be installed here.
        :param target_boot_mode: bios, uefi. Only taken into account
            for softraid, when no efi partition is explicitely provided
            (happens for whole disk images)
        :raises: CommandExecutionError if the installation of the
                 bootloader fails.
        :raises: DeviceNotFound if the root partition is not found.

        """
        device = hardware.dispatch_to_managers('get_os_install_device')
        if self.agent.iscsi_started:
            iscsi.clean_up(device)
        boot = hardware.dispatch_to_managers('get_boot_info')
        # FIXME(arne_wiebalck): make software RAID work with efibootmgr
        if (boot.current_boot_mode == 'uefi'
                and not hardware.is_md_device(device)):
            has_efibootmgr = True
            try:
                utils.execute('efibootmgr', '--version')
            except FileNotFoundError:
                LOG.warning("efibootmgr is not available in the ramdisk")
                has_efibootmgr = False

            if has_efibootmgr:
                if _manage_uefi(device,
                                efi_system_part_uuid=efi_system_part_uuid):
                    return

        # In case we can't use efibootmgr for uefi we will continue using grub2
        LOG.debug('Using grub2-install to set up boot files')
        _install_grub2(device,
                       root_uuid=root_uuid,
                       efi_system_part_uuid=efi_system_part_uuid,
                       prep_boot_part_uuid=prep_boot_part_uuid,
                       target_boot_mode=target_boot_mode)
Пример #5
0
    def install_bootloader(self, root_uuid, efi_system_part_uuid=None):
        """Install the GRUB2 bootloader on the image.

        :param root_uuid: The UUID of the root partition.
        :param efi_system_part_uuid: The UUID of the efi system partition.
            To be used only for uefi boot mode.  For uefi boot mode, the
            boot loader will be installed here.
        :raises: CommandExecutionError if the installation of the
                 bootloader fails.
        :raises: DeviceNotFound if the root partition is not found.

        """
        device = hardware.dispatch_to_managers('get_os_install_device')
        iscsi.clean_up(device)
        _install_grub2(device,
                       root_uuid=root_uuid,
                       efi_system_part_uuid=efi_system_part_uuid)
Пример #6
0
    def install_bootloader(self, root_uuid, efi_system_part_uuid=None,
                           prep_boot_part_uuid=None):
        """Install the GRUB2 bootloader on the image.

        :param root_uuid: The UUID of the root partition.
        :param efi_system_part_uuid: The UUID of the efi system partition.
            To be used only for uefi boot mode.  For uefi boot mode, the
            boot loader will be installed here.
        :param prep_boot_part_uuid: The UUID of the PReP Boot partition.
            Used only for booting ppc64* partition images locally. In this
            scenario the bootloader will be installed here.
        :raises: CommandExecutionError if the installation of the
                 bootloader fails.
        :raises: DeviceNotFound if the root partition is not found.

        """
        device = hardware.dispatch_to_managers('get_os_install_device')
        if self.agent.iscsi_started:
            iscsi.clean_up(device)
        boot = hardware.dispatch_to_managers('get_boot_info')
        if boot.current_boot_mode == 'uefi':
            has_efibootmgr = True
            # NOTE(iurygregory): adaptation for py27 since we don't have
            # FileNotFoundError defined.
            try:
                FileNotFoundError
            except NameError:
                FileNotFoundError = OSError
            try:
                utils.execute('efibootmgr', '--version')
            except FileNotFoundError:
                LOG.warning("efibootmgr is not available in the ramdisk")
                has_efibootmgr = False

            if has_efibootmgr:
                if _manage_uefi(device,
                                efi_system_part_uuid=efi_system_part_uuid):
                    return

        # In case we can't use efibootmgr for uefi we will continue using grub2
        LOG.debug('Using grub2-install to set up boot files')
        _install_grub2(device,
                       root_uuid=root_uuid,
                       efi_system_part_uuid=efi_system_part_uuid,
                       prep_boot_part_uuid=prep_boot_part_uuid)
Пример #7
0
    def test_ok(self, mock_rtslib):
        mock_rtslib.return_value.storage_objects = [
            mock.Mock(udev_path='wrong path'),
            mock.Mock(udev_path=self.fake_dev),
            mock.Mock(udev_path='wrong path'),
        ]
        # mocks don't play well with name attribute
        for i, fake_storage in enumerate(
                mock_rtslib.return_value.storage_objects):
            fake_storage.name = 'iqn%d' % i

        mock_rtslib.return_value.targets = [
            mock.Mock(wwn='iqn0'),
            mock.Mock(wwn='iqn1'),
        ]

        iscsi.clean_up(self.fake_dev)

        for fake_storage in mock_rtslib.return_value.storage_objects:
            self.assertEqual(fake_storage.udev_path == self.fake_dev,
                             fake_storage.delete.called)
        for fake_target in mock_rtslib.return_value.targets:
            self.assertEqual(fake_target.wwn == 'iqn1',
                             fake_target.delete.called)
Пример #8
0
 def test_device_not_found(self, mock_rtslib):
     mock_rtslib.return_value.storage_objects = []
     iscsi.clean_up(self.fake_dev)
Пример #9
0
 def test_lio_not_available(self, mock_rtslib):
     mock_rtslib.side_effect = IOError()
     iscsi.clean_up(self.fake_dev)
Пример #10
0
    def install_bootloader(self,
                           root_uuid,
                           efi_system_part_uuid=None,
                           prep_boot_part_uuid=None,
                           target_boot_mode='bios',
                           ignore_bootloader_failure=None):
        """Install the GRUB2 bootloader on the image.

        :param root_uuid: The UUID of the root partition.
        :param efi_system_part_uuid: The UUID of the efi system partition.
            To be used only for uefi boot mode.  For uefi boot mode, the
            boot loader will be installed here.
        :param prep_boot_part_uuid: The UUID of the PReP Boot partition.
            Used only for booting ppc64* partition images locally. In this
            scenario the bootloader will be installed here.
        :param target_boot_mode: bios, uefi. Only taken into account
            for softraid, when no efi partition is explicitely provided
            (happens for whole disk images)
        :raises: CommandExecutionError if the installation of the
                 bootloader fails.
        :raises: DeviceNotFound if the root partition is not found.

        """
        device = hardware.dispatch_to_managers('get_os_install_device')
        if self.agent.iscsi_started:
            iscsi.clean_up(device)

        # Always allow the API client to be the final word on if this is
        # overridden or not.
        if ignore_bootloader_failure is None:
            ignore_failure = CONF.ignore_bootloader_failure
        else:
            ignore_failure = ignore_bootloader_failure

        try:
            if _efi_boot_setup(device, efi_system_part_uuid, target_boot_mode):
                return
        except Exception as e:
            LOG.error('Error setting up bootloader. Error %s', e)
            if not ignore_failure:
                raise

        # We don't have a working root UUID detection for whole disk images.
        # Until we can do it, avoid a confusing traceback.
        if root_uuid == '0x00000000' or root_uuid is None:
            LOG.info('Not using grub2-install since root UUID is not provided.'
                     ' Assuming a whole disk image')
            return

        # In case we can't use efibootmgr for uefi we will continue using grub2
        LOG.debug('Using grub2-install to set up boot files')
        try:
            _install_grub2(device,
                           root_uuid=root_uuid,
                           efi_system_part_uuid=efi_system_part_uuid,
                           prep_boot_part_uuid=prep_boot_part_uuid,
                           target_boot_mode=target_boot_mode)
        except Exception as e:
            LOG.error('Error setting up bootloader. Error %s', e)
            if not ignore_failure:
                raise