Exemplo n.º 1
0
def image_to_raw(image_href, path, path_tmp):
    with fileutils.remove_path_on_error(path_tmp):
        fmt = get_source_format(image_href, path_tmp)

        if fmt != "raw":
            staged = "%s.converted" % path

            utils.is_memory_insufficent(raise_if_fail=True)
            LOG.debug("%(image)s was %(format)s, converting to raw", {
                'image': image_href,
                'format': fmt
            })
            with fileutils.remove_path_on_error(staged):
                disk_utils.convert_image(path_tmp, staged, 'raw')
                os.unlink(path_tmp)

                data = disk_utils.qemu_img_info(staged)
                if data.file_format != "raw":
                    raise exception.ImageConvertFailed(
                        image_id=image_href,
                        reason=_("Converted to raw, but format is "
                                 "now %s") % data.file_format)

                os.rename(staged, path)
        else:
            os.rename(path_tmp, path)
Exemplo n.º 2
0
    def test_is_memory_insufficent_good(self, mock_vm_check, mock_sleep):
        class vm_check(object):
            available = 3276700000

        mock_vm_check.return_value = vm_check
        self.assertFalse(utils.is_memory_insufficent())
        self.assertEqual(1, mock_vm_check.call_count)
Exemplo n.º 3
0
    def test_is_memory_insufficent_warning_only(self, mock_vm_check,
                                                mock_sleep):
        self.config(minimum_memory_warning_only=True)

        class vm_check_bad(object):
            available = 1023000000

        mock_vm_check.side_effect = vm_check_bad
        self.assertFalse(utils.is_memory_insufficent())
        self.assertEqual(2, mock_vm_check.call_count)
Exemplo n.º 4
0
    def test_is_memory_insufficent_recovers(self, mock_vm_check, mock_sleep):
        class vm_check_bad(object):
            available = 1023000000

        class vm_check_good(object):
            available = 3276700000

        self.config(minimum_memory_warning_only=False)
        mock_vm_check.side_effect = iter(
            [vm_check_bad, vm_check_bad, vm_check_good])
        self.assertFalse(utils.is_memory_insufficent())
        self.assertEqual(3, mock_vm_check.call_count)
Exemplo n.º 5
0
    def write_image(self, task):
        """Method invoked when deployed using iSCSI.

        This method is invoked during a heartbeat from an agent when
        the node is in wait-call-back state. This deploys the image on
        the node and then configures the node to boot according to the
        desired boot option (netboot or localboot).

        :param task: a TaskManager object containing the node.
        :param kwargs: the kwargs passed from the heartbeat method.
        :raises: InstanceDeployFailure, if it encounters some error during
            the deploy.
        """
        if not task.driver.storage.should_write_image(task):
            LOG.debug('Skipping write_image for node %s', task.node.uuid)
            return

        node = task.node
        LOG.debug('Continuing the deployment on node %s', node.uuid)
        if utils.is_memory_insufficent():
            # Insufficent memory, but we can just let the agent heartbeat
            # again in order to initiate deployment when the situation has
            # changed.
            LOG.warning(
                'Insufficent memory to write image for node '
                '%(node)s. Skipping until next heartbeat.',
                {'node': node.uuid})
            info = node.driver_internal_info
            info['skip_current_deploy_step'] = False
            node.driver_internal_info = info
            node.last_error = "Deploy delayed due to insufficent memory"
            node.save()
            return states.DEPLOYWAIT
        uuid_dict_returned = do_agent_iscsi_deploy(task, self._client)
        utils.set_node_nested_field(node, 'driver_internal_info',
                                    'deployment_uuids', uuid_dict_returned)
        node.save()