示例#1
0
def start_deploy(task, manager, configdrive=None, event='deploy'):
    """Start deployment or rebuilding on a node.

    This function does not check the node suitability for deployment, it's left
    up to the caller.

    :param task: a TaskManager instance.
    :param manager: a ConductorManager to run tasks on.
    :param configdrive: a configdrive, if requested.
    :param event: event to process: deploy or rebuild.
    """
    node = task.node

    if event == 'rebuild':
        # Note(gilliard) Clear these to force the driver to
        # check whether they have been changed in glance
        # NOTE(vdrok): If image_source is not from Glance we should
        # not clear kernel and ramdisk as they're input manually
        if glance_utils.is_glance_image(
                node.instance_info.get('image_source')):
            instance_info = node.instance_info
            instance_info.pop('kernel', None)
            instance_info.pop('ramdisk', None)
            node.instance_info = instance_info

    # Infer the image type to make sure the deploy driver
    # validates only the necessary variables for different
    # image types.
    # NOTE(sirushtim): The iwdi variable can be None. It's up to
    # the deploy driver to validate this.
    iwdi = images.is_whole_disk_image(task.context, node.instance_info)
    driver_internal_info = node.driver_internal_info
    driver_internal_info['is_whole_disk_image'] = iwdi
    node.driver_internal_info = driver_internal_info
    node.save()

    try:
        task.driver.power.validate(task)
        task.driver.deploy.validate(task)
        utils.validate_instance_info_traits(task.node)
        conductor_steps.validate_deploy_templates(task, skip_missing=True)
    except exception.InvalidParameterValue as e:
        raise exception.InstanceDeployFailure(
            _("Failed to validate deploy or power info for node "
              "%(node_uuid)s. Error: %(msg)s") % {
                  'node_uuid': node.uuid,
                  'msg': e
              },
            code=e.code)

    try:
        task.process_event(event,
                           callback=manager._spawn_worker,
                           call_args=(do_node_deploy, task,
                                      manager.conductor.id, configdrive),
                           err_handler=utils.provisioning_error_handler)
    except exception.InvalidState:
        raise exception.InvalidStateRequested(action=event,
                                              node=task.node.uuid,
                                              state=task.node.provision_state)
示例#2
0
 def test_is_whole_disk_image_whole_disk_non_glance(self, mock_igi, mock_gip):
     mock_igi.return_value = False
     instance_info = {"image_source": "whole_disk_image"}
     is_whole_disk_image = images.is_whole_disk_image("context", instance_info)
     self.assertTrue(is_whole_disk_image)
     self.assertFalse(mock_gip.called)
     mock_igi.assert_called_once_with(instance_info["image_source"])
示例#3
0
 def test_is_whole_disk_image_whole_disk_non_glance(self, mock_igi,
                                                    mock_gip):
     mock_igi.return_value = False
     instance_info = {'image_source': 'whole_disk_image'}
     is_whole_disk_image = images.is_whole_disk_image(
         'context', instance_info)
     self.assertTrue(is_whole_disk_image)
     self.assertFalse(mock_gip.called)
     mock_igi.assert_called_once_with(instance_info['image_source'])
示例#4
0
 def test_is_whole_disk_image_whole_disk_non_glance(self, mock_igi,
                                                    mock_gip):
     mock_igi.return_value = False
     instance_info = {'image_source': 'whole_disk_image'}
     is_whole_disk_image = images.is_whole_disk_image('context',
                                                      instance_info)
     self.assertTrue(is_whole_disk_image)
     self.assertFalse(mock_gip.called)
     mock_igi.assert_called_once_with(instance_info['image_source'])
示例#5
0
 def test_is_whole_disk_image_whole_disk_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {}
     instance_info = {"image_source": "glance://whole_disk_image"}
     image_source = instance_info["image_source"]
     is_whole_disk_image = images.is_whole_disk_image("context", instance_info)
     self.assertTrue(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with("context", image_source)
示例#6
0
 def test_is_whole_disk_image_partition_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {"kernel_id": "kernel", "ramdisk_id": "ramdisk"}
     instance_info = {"image_source": "glance://partition_image"}
     image_source = instance_info["image_source"]
     is_whole_disk_image = images.is_whole_disk_image("context", instance_info)
     self.assertFalse(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with("context", image_source)
示例#7
0
 def test_is_whole_disk_image_whole_disk_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {}
     instance_info = {'image_source': 'glance://whole_disk_image'}
     image_source = instance_info['image_source']
     is_whole_disk_image = images.is_whole_disk_image(
         'context', instance_info)
     self.assertTrue(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with('context', image_source)
示例#8
0
 def test_is_whole_disk_image_whole_disk_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {}
     instance_info = {'image_source': 'glance://whole_disk_image'}
     image_source = instance_info['image_source']
     is_whole_disk_image = images.is_whole_disk_image('context',
                                                      instance_info)
     self.assertTrue(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with('context', image_source)
示例#9
0
 def test_is_whole_disk_image_partition_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {'kernel_id': 'kernel',
                              'ramdisk_id': 'ramdisk'}
     instance_info = {'image_source': 'glance://partition_image'}
     image_source = instance_info['image_source']
     is_whole_disk_image = images.is_whole_disk_image('context',
                                                      instance_info)
     self.assertFalse(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with('context', image_source)
示例#10
0
 def test_is_whole_disk_image_partition_image(self, mock_igi, mock_gip):
     mock_igi.return_value = True
     mock_gip.return_value = {'kernel_id': 'kernel',
                              'ramdisk_id': 'ramdisk'}
     instance_info = {'image_source': 'glance://partition_image'}
     image_source = instance_info['image_source']
     is_whole_disk_image = images.is_whole_disk_image('context',
                                                      instance_info)
     self.assertFalse(is_whole_disk_image)
     mock_igi.assert_called_once_with(image_source)
     mock_gip.assert_called_once_with('context', image_source)
示例#11
0
 def test_is_whole_disk_image_no_img_src(self, mock_igi, mock_gip):
     instance_info = {'image_source': ''}
     iwdi = images.is_whole_disk_image('context', instance_info)
     self.assertIsNone(iwdi)
     self.assertFalse(mock_igi.called)
     self.assertFalse(mock_gip.called)
示例#12
0
 def test_is_whole_disk_image_no_img_src(self, mock_igi, mock_gip):
     instance_info = {'image_source': ''}
     iwdi = images.is_whole_disk_image('context', instance_info)
     self.assertIsNone(iwdi)
     self.assertFalse(mock_igi.called)
     self.assertFalse(mock_gip.called)