예제 #1
0
    def test_run_new_kernel_and_ram_image(self):
        image_ids = {'kernel': 'test_kernel_id', 'ramdisk': 'test_ramdisk_id'}

        with mock.patch('tripleo_common.utils.glance.create_or_find_kernel_and'
                        '_ramdisk') as mock_find:
            mock_find.return_value = image_ids
            action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
                                                   kernel_name='test_kernel',
                                                   ramdisk_name='test_ramdisk')
            result = action.run(self.context)

        self.assertIsNone(result)

        self.node_update[1:] = [{
            'op': 'add',
            'path': '/driver_info/deploy_ramdisk',
            'value': 'test_ramdisk_id'
        }, {
            'op': 'add',
            'path': '/driver_info/deploy_kernel',
            'value': 'test_kernel_id'
        }, {
            'op': 'add',
            'path': '/driver_info/rescue_ramdisk',
            'value': 'test_ramdisk_id'
        }, {
            'op': 'add',
            'path': '/driver_info/rescue_kernel',
            'value': 'test_kernel_id'
        }]
        self.ironic.node.update.assert_called_once_with(
            mock.ANY, self.node_update)
예제 #2
0
    def test_run_exception_on_node_update(self):
        self.ironic.node.update.side_effect = Exception("Update error")

        action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
        result = action.run(self.context)

        self.assertIn("Update error", str(result.error))
예제 #3
0
    def test_run_instance_boot_option_not_set(self):
        action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
        result = action.run(self.context)
        self.assertIsNone(result)

        self.node_update[0].update({'value': 'boot_option:local'})
        self.ironic.node.update.assert_called_once_with(
            mock.ANY, self.node_update)
예제 #4
0
    def test_run_glance_ids_not_found(self):
        self.glance.images.find = mock.Mock(
            side_effect=glance_exceptions.NotFound)

        action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
                                               kernel_name='unknown_kernel',
                                               ramdisk_name='unknown_ramdisk')
        result = action.run(self.context)
        self.assertIn("not found", str(result.error))
예제 #5
0
    def test_run_instance_boot_option(self):
        action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
                                               instance_boot_option='netboot')
        result = action.run()
        self.assertEqual(result, None)

        self.node_update[0].update({'value': 'boot_option:netboot'})
        self.ironic.node.update.assert_called_once_with(mock.ANY,
                                                        self.node_update)
예제 #6
0
    def test_run_instance_boot_option_already_set_no_overwrite(self):
        node_mock = mock.MagicMock()
        node_mock.properties.get.return_value = ({'boot_option': 'netboot'})
        self.ironic.node.get.return_value = node_mock

        action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
        result = action.run(self.context)
        self.assertIsNone(result)

        self.node_update[0].update({'value': 'boot_option:netboot'})
        self.ironic.node.update.assert_called_once_with(
            mock.ANY, self.node_update)
예제 #7
0
    def baremetal_configure_boot(self, kwargs):
        """Run the action configure boot, and return data.

        :param kwargs: options to pass into the ConfigureBootAction
        :type kwargs: Dictionary

        :returns: Object
        """

        action = baremetal.ConfigureBootAction(**kwargs)
        baremetal_client = ironicclient.Client(1, session=self.sess)
        image_client = glanceclient.Client(2, session=self.sess)
        return action.configure_boot(baremetal_client, image_client)
예제 #8
0
def configure(clients, node_uuids, kernel_name='bm-deploy-kernel',
              ramdisk_name='bm-deploy-ramdisk', instance_boot_option=None,
              root_device=None, root_device_minimum_size=4,
              overwrite_root_device_hints=False):
    """Configure Node boot options.

    :param node_uuids: List of instance UUID(s).
    :type node_uuids: List

    :param kernel_name: Kernel to use
    :type kernel_name: String

    :param ramdisk_name: RAMDISK to use
    :type ramdisk_name: String

    :param instance_boot_option: Boot options to use
    :type instance_boot_option: String

    :param root_device: Path (name) of the root device.
    :type root_device: String

    :param root_device_minimum_size: Size of the given root device.
    :type root_device_minimum_size: Integer

    :param overwrite_root_device_hints: Whether to overwrite existing root
                                        device hints when `root_device` is
                                        used.
    :type overwrite_root_device_hints: Boolean
    """

    context = clients.tripleoclient.create_mistral_context()
    for node_uuid in node_uuids:
        boot_action = baremetal.ConfigureBootAction(
            node_uuid=node_uuid,
            kernel_name=kernel_name,
            ramdisk_name=ramdisk_name,
            instance_boot_option=instance_boot_option
        ).run(context=context)
        if boot_action:
            raise RuntimeError(boot_action)
        root_device_action = baremetal.ConfigureRootDeviceAction(
            node_uuid=node_uuid,
            root_device=root_device,
            minimum_size=root_device_minimum_size,
            overwrite=overwrite_root_device_hints
        )
        root_device_action.run(context=context)
    else:
        print('Successfully configured the nodes.')
예제 #9
0
    def test_run_new_kernel_and_ram_image(self):
        image_ids = {'kernel': 'test_kernel_id', 'ramdisk': 'test_ramdisk_id'}

        with mock.patch('tripleo_common.utils.glance.create_or_find_kernel_and'
                        '_ramdisk') as mock_find:
            mock_find.return_value = image_ids
            action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
                                                   kernel_name='test_kernel',
                                                   ramdisk_name='test_ramdisk')
            result = action.run()

        self.assertEqual(result, None)

        self.node_update[1].update({'value': 'test_ramdisk_id'})
        self.node_update[2].update({'value': 'test_kernel_id'})
        self.ironic.node.update.assert_called_once_with(mock.ANY,
                                                        self.node_update)