Exemplo n.º 1
0
    def setUp(self):
        super(CopyFromGlanceToGlanceTestCase, self).setUp()

        self.fake_input_info = {'image_data': {'fake_key': 'fake_value'}}
        self.fake_result_info = {
            'image_data': {
                'image': {
                    'images': [{
                        'image': 'image_body',
                        'meta': {}
                    }]
                }
            }
        }

        self.fake_image = mock.Mock()
        self.fake_image.deploy.return_value = self.fake_result_info
        self.src_cloud = mock.Mock()
        self.dst_cloud = mock.Mock()
        self.dst_cloud.resources = {'image': self.fake_image}

        self.fake_config = utils.ext_dict(
            migrate=utils.ext_dict({'ignore_empty_images': False}))
        self.src_cloud.resources = {'image': self.fake_image}

        self.fake_init = {
            'src_cloud': self.src_cloud,
            'dst_cloud': self.dst_cloud,
            'cfg': self.fake_config
        }
Exemplo n.º 2
0
    def setUp(self):
        super(ConverterVolumeToImageTest, self).setUp()
        self.fake_src_cloud = mock.Mock()
        self.fake_storage = mock.Mock()
        self.fake_storage.deploy = mock.Mock()
        self.fake_storage.upload_volume_to_image.return_value = ('resp',
                                                                 'image_id')
        self.fake_storage.get_backend.return_value = 'ceph'
        self.fake_image = mock.Mock()
        self.fake_image.wait_for_status = mock.Mock()
        self.fake_image.get_image_by_id_converted = mock.Mock()
        self.fake_image.get_image_by_id_converted.return_value = {
            'images': {
                'image_id': {
                    'image': 'image_body',
                    'meta': {}
                }
            }
        }
        self.fake_image.patch_image = mock.Mock()
        self.fake_src_cloud.resources = {
            'storage': self.fake_storage,
            'image': self.fake_image
        }
        self.fake_volumes_info = {
            'volumes': {
                'id1': {
                    'volume': {
                        'id': 'id1',
                        'display_name': 'dis1',
                    },
                    'meta': {
                        'image': 'image',
                    },
                }
            },
        }

        self.fake_dst_cloud = mock.Mock()
        self.fake_config = utils.ext_dict(
            migrate=utils.ext_dict({
                'disk_format': 'qcow',
                'container_format': 'bare'
            }))

        self.fake_init = {
            'src_cloud': self.fake_src_cloud,
            'dst_cloud': self.fake_dst_cloud,
            'cfg': self.fake_config
        }
Exemplo n.º 3
0
    def make_resource_config(config, position, cloud_config, resource_name):
        resource_config = copy.deepcopy(cloud_config)
        resource_config[resource_name] = utils.ext_dict()
        for k, v in getattr(config,
                            '%s_%s' % (position, resource_name)).iteritems():
            resource_config[resource_name][k] = v

        return resource_config
Exemplo n.º 4
0
    def make_resource_config(config, position, cloud_config, resource_name):
        resource_config = copy.deepcopy(cloud_config)
        resource_config[resource_name] = utils.ext_dict()
        for k, v in getattr(config,
                            '%s_%s' % (position, resource_name)).iteritems():
            resource_config[resource_name][k] = v

        return resource_config
Exemplo n.º 5
0
    def setUp(self):
        super(GetInfoImagesTestCase, self).setUp()

        self.fake_info = {'images': {'fake_image_id': {'image': 'image_body',
                                                       'meta': {}}}}
        self.fake_image = mock.Mock()
        self.fake_image.read_info.return_value = self.fake_info
        self.fake_src_cloud = mock.Mock()
        self.fake_dst_cloud = mock.Mock()
        self.fake_config = utils.ext_dict(migrate=utils.ext_dict(
            {'ignore_empty_images': False}))
        self.fake_src_cloud.resources = {'image': self.fake_image}

        self.fake_init = {
            'src_cloud': self.fake_src_cloud,
            'dst_cloud': self.fake_dst_cloud,
            'cfg': self.fake_config
        }
Exemplo n.º 6
0
    def setUp(self):
        super(GetInfoImagesTestCase, self).setUp()

        self.fake_info = {'images': {'fake_image_id': {'image': 'image_body',
                                                       'meta': {}}}}
        self.fake_image = mock.Mock()
        self.fake_image.read_info.return_value = self.fake_info
        self.fake_src_cloud = mock.Mock()
        self.fake_dst_cloud = mock.Mock()
        self.fake_config = utils.ext_dict(migrate=utils.ext_dict(
            {'ignore_empty_images': False}))
        self.fake_src_cloud.resources = {'image': self.fake_image}

        self.fake_init = {
            'src_cloud': self.fake_src_cloud,
            'dst_cloud': self.fake_dst_cloud,
            'cfg': self.fake_config
        }
Exemplo n.º 7
0
    def make_cloud_config(config, position):
        cloud_config = utils.ext_dict(migrate=utils.ext_dict(),
                                      cloud=utils.ext_dict(),
                                      import_rules=utils.ext_dict(),
                                      mail=utils.ext_dict(),
                                      mysql=utils.ext_dict(),
                                      rabbit=utils.ext_dict(),
                                      storage=utils.ext_dict(),
                                      initial_check=utils.ext_dict(),
                                      mysqldump=utils.ext_dict())

        cloud_config['migrate'].update(config.migrate)
        cloud_config['cloud'].update(getattr(config, position))
        cloud_config['mysql'].update(getattr(config, position + '_mysql'))
        cloud_config['rabbit'].update(getattr(config, position + '_rabbit'))
        cloud_config['storage'].update(getattr(config, position + '_storage'))
        cloud_config['initial_check'].update(config.initial_check)
        cloud_config['mysqldump'].update(config.mysqldump)

        return cloud_config
Exemplo n.º 8
0
    def make_cloud_config(config, position):
        cloud_config = utils.ext_dict(migrate=utils.ext_dict(),
                                      cloud=utils.ext_dict(),
                                      import_rules=utils.ext_dict(),
                                      mail=utils.ext_dict(),
                                      mysql=utils.ext_dict(),
                                      rabbit=utils.ext_dict(),
                                      storage=utils.ext_dict(),
                                      initial_check=utils.ext_dict(),
                                      mysqldump=utils.ext_dict())

        cloud_config['migrate'].update(config.migrate)
        cloud_config['cloud'].update(getattr(config, position))
        cloud_config['mysql'].update(getattr(config, position + '_mysql'))
        cloud_config['rabbit'].update(getattr(config, position + '_rabbit'))
        cloud_config['storage'].update(getattr(config, position + '_storage'))
        cloud_config['initial_check'].update(config.initial_check)
        cloud_config['mysqldump'].update(config.mysqldump)

        return cloud_config
Exemplo n.º 9
0
    def setUp(self):
        super(CopyFromGlanceToGlanceTestCase, self).setUp()

        self.fake_input_info = {'image_data': {'fake_key': 'fake_value'}}
        self.fake_result_info = {'image_data': {
            'image': {'images': [{'image': 'image_body', 'meta': {}}]}}}

        self.fake_image = mock.Mock()
        self.fake_image.deploy.return_value = self.fake_result_info
        self.src_cloud = mock.Mock()
        self.dst_cloud = mock.Mock()
        self.dst_cloud.resources = {'image': self.fake_image}

        self.fake_config = utils.ext_dict(migrate=utils.ext_dict(
            {'ignore_empty_images': False}))
        self.src_cloud.resources = {'image': self.fake_image}

        self.fake_init = {
            'src_cloud': self.src_cloud,
            'dst_cloud': self.dst_cloud,
            'cfg': self.fake_config
        }
Exemplo n.º 10
0
class ColdEvacuateTestCase(test.TestCase):
    config = utils.ext_dict(
        cloud=utils.ext_dict(
            ssh_user='******',
            ssh_sudo_password='******',
            ssh_host='ssh_host',
            host='host',
        ),
        migrate=utils.ext_dict(
            ssh_chunk_size=1337,
            retry=42,
        ),
    )

    def setUp(self):
        test.TestCase.setUp(self)

        self.server = self._make_server('fake-instance-id', status='ACTive')
        self.servers = {'fake-instance-id': self.server}

        self._services = {}
        self._make_service('nova-compute', 'fake-host-1', 'enabled')
        self._make_service('nova-compute', 'fake-host-2', 'enabled')
        self._make_service('nova-compute', 'fake-host-3', 'disabled')
        self._make_service('nova-compute', 'fake-host-4', 'disabled')
        self._make_service('nova-compute', 'fake-host-5', 'enabled')

        self.compute_api = mock.Mock()
        self.compute_api.servers.get.side_effect = self._servers_get
        self.compute_api.servers.delete.side_effect = self._servers_delete
        self.compute_api.servers.start.side_effect = self._servers_start
        self.compute_api.servers.stop.side_effect = self._servers_stop
        self.compute_api.servers.migrate.side_effect = self._migrate
        self.compute_api.servers.confirm_resize.side_effect = \
            self._confirm_resize

        self.compute_api.services.list.side_effect = self._services_list
        self.compute_api.services.disable.side_effect = self._service_disable
        self.compute_api.services.enable.side_effect = self._service_enable

        cfglib_conf_patcher = mock.patch('cloudferry.cfglib.CONF')
        self.addCleanup(cfglib_conf_patcher.stop)
        self.cfglib_conf = cfglib_conf_patcher.start()
        self.cfglib_conf.evacuation.state_change_timeout = 1
        self.cfglib_conf.evacuation.nova_home_path = '/fake/home'
        self.cfglib_conf.evacuation.nova_user = '******'

        remote_runner_patcher = mock.patch(
            'cloudferry.lib.utils.remote_runner.RemoteRunner')
        self.addCleanup(remote_runner_patcher.stop)
        self.remote_runner = remote_runner_patcher.start()

    def _servers_get(self, server_id):
        if not isinstance(server_id, str):
            server_id = server_id.id
        if server_id not in self.servers:
            raise nova_exc.NotFound(404)
        return self.servers[server_id]

    def _servers_delete(self, server_id):
        if not isinstance(server_id, str):
            server_id = server_id.id
        if server_id not in self.servers:
            raise nova_exc.NotFound(404)
        del self.servers[server_id]

    def _servers_stop(self, server_id):
        self._servers_get(server_id).status = 'SHUTOFF'

    def _servers_start(self, server_id):
        self._servers_get(server_id).status = 'ACTIVE'

    def _migrate(self, server_id):
        server = self._servers_get(server_id)
        server.status = 'VERIFY_RESIZE'
        services = [
            s for s in list(self._services.values())
            if s.status == 'enabled' and s.binary == 'nova-compute'
            and s.host != getattr(s, cold_evacuate.INSTANCE_HOST_ATTRIBUTE)
        ]
        # concatenate all host names to fail test when there is any choice

        setattr(server, cold_evacuate.INSTANCE_HOST_ATTRIBUTE,
                ','.join(s.host for s in services))

    def _confirm_resize(self, server_id):
        self._servers_get(server_id).status = 'ACTIVE'

    def _make_server(self,
                     instance_id,
                     name='fake-instance',
                     status='active',
                     image='fake-image-id',
                     flavor='fake-flavor-id',
                     availability_zone='fake-az:fake-host',
                     block_device_mapping=None,
                     nics=None):
        if block_device_mapping is None:
            block_device_mapping = {
                '/dev/vdb': 'volume-1',
                '/dev/vdc': 'volume-2'
            }
        _, host = availability_zone.split(':')
        server = mock.Mock()
        server.id = instance_id
        server.name = name
        server.status = status
        server.image = {'id': image}
        server.flavor = {'id': flavor}
        setattr(server, cold_evacuate.INSTANCE_HOST_ATTRIBUTE, host)
        server.block_device_mapping = block_device_mapping
        server.user_id = 'fake-user-id'
        server.nics = nics
        return server

    def _services_list(self, binary=None):
        services = sorted(list(self._services.values()), key=lambda x: x.host)
        return [s for s in services if s.binary == binary]

    def _make_service(self, binary, host, status):
        service = mock.MagicMock()
        service.binary = binary
        service.host = host
        service.status = status
        self._services[(binary, host)] = service

    def _service_disable(self, host, binary):
        self._services[binary, host].status = 'disabled'

    def _service_enable(self, host, binary):
        self._services[binary, host].status = 'enabled'

    def dis_test_cold_evacuate(self):
        cold_evacuate.cold_evacuate(self.config, self.compute_api, self.server,
                                    'fake-host-5')

        # Check that services are restored after migration
        self.assertEqual(self._services['nova-compute', 'fake-host-1'].status,
                         'enabled')
        self.assertEqual(self._services['nova-compute', 'fake-host-2'].status,
                         'enabled')
        self.assertEqual(self._services['nova-compute', 'fake-host-3'].status,
                         'disabled')
        self.assertEqual(self._services['nova-compute', 'fake-host-4'].status,
                         'disabled')
        self.assertEqual(self._services['nova-compute', 'fake-host-5'].status,
                         'enabled')

        # Check that server migrated to right host
        self.assertEqual(
            getattr(self.server, cold_evacuate.INSTANCE_HOST_ATTRIBUTE),
            'fake-host-5')
Exemplo n.º 11
0
from oslotest import mockpatch

from cloudferry import cfglib
from cloudferry.lib.os.identity import keystone
from cloudferry.lib.utils import utils
from tests import test


FAKE_CONFIG = utils.ext_dict(
    cloud=utils.ext_dict({'user': '******',
                          'password': '******',
                          'tenant': 'fake_tenant',
                          'auth_url': 'http://1.1.1.1:35357/v2.0/',
                          'region': None,
                          'service_tenant': 'service',
                          'cacert': '',
                          'insecure': False}),
    migrate=utils.ext_dict({'retry': '7',
                            'time_wait': 5,
                            'keep_user_passwords': False,
                            'overwrite_user_passwords': False,
                            'migrate_users': True,
                            'optimize_user_role_fetch': False}),
    mail=utils.ext_dict({'server': '-'}))


@mock.patch("cloudferry.lib.base.clients.os_cli_cmd", mock.MagicMock())
class KeystoneIdentityTestCase(test.TestCase):
    def setUp(self):
        super(KeystoneIdentityTestCase, self).setUp()
        self.mock_client = mock.MagicMock()
        self.kc_patch = mockpatch.PatchObject(keystone_client, 'Client',
Exemplo n.º 12
0
    def deploy(self, info, *args, **kwargs):
        LOG.info("Glance images deployment started...")
        info = copy.deepcopy(info)
        created_images = []
        delete_container_format, delete_disk_format = [], []
        empty_image_list = {}

        # List for obsolete/broken images IDs, that will not be migrated
        obsolete_images_ids_list = []
        dst_images = self._dst_images()

        view = GlanceImageProgressMigrationView(info['images'], dst_images)
        view.show_info()
        for image_id_src in info['images']:
            img = info['images'][image_id_src]['image']
            meta = info['images'][image_id_src]['meta']
            if img and img['resource']:
                checksum_current = img['checksum']
                name_current = img['name']
                tenant_name = img['owner_name']
                image_key = (name_current, tenant_name, checksum_current,
                             img['is_public'])

                if image_key in dst_images:
                    existing_image = dst_images[image_key]
                    created_images.append((existing_image, meta))
                    image_members = img['members'].get(img['id'], {})
                    self.update_membership(existing_image.id, image_members)
                    msg = ("Image '%s' is already present in destination, "
                           "skipping" % img['name'])
                    LOG.info(msg)
                    self.state_notifier.skip(
                        objects.MigrationObjectType.IMAGE, img, msg)
                    continue

                view.show_progress()
                view.inc_progress(img['size'])

                LOG.debug("Updating owner '%s' of image '%s'",
                          tenant_name, img["name"])
                img["owner"] = \
                    self.identity_client.get_tenant_id_by_name(tenant_name)

                if img["properties"]:
                    # update snapshot metadata
                    metadata = img["properties"]
                    if "owner_id" in metadata:
                        # update tenant id
                        LOG.debug("Updating snapshot metadata for field "
                                  "'owner_id' for image %s", img["id"])
                        metadata["owner_id"] = img["owner"]
                    if "user_name" in metadata:
                        # update user id by specified name
                        LOG.debug("Updating snapshot metadata for field "
                                  "'user_id' for image %s", img["id"])
                        try:
                            ks_client = self.identity_client.keystone_client
                            metadata["user_id"] = ks_client.users.find(
                                username=metadata["user_name"]).id
                            del metadata["user_name"]
                        except keystone_exceptions.NotFound:
                            LOG.warning("Cannot update user name for image %s",
                                        img['name'])
                if img["checksum"] is None:
                    LOG.warning("re-creating image %s from original source "
                                "URL", img["id"])
                    if meta['img_loc'] is not None:
                        new_image = self.create_image(
                            id=img['id'],
                            name=img['name'],
                            disk_format=img['disk_format'] or "qcow2",
                            location=meta['img_loc'],
                            container_format=img['container_format'] or 'bare',
                        )

                        self.state_notifier.success(
                            objects.MigrationObjectType.IMAGE, img,
                            new_image.id, message='Recreated from URL')

                        recreated_image = utl.ext_dict(
                            name=img["name"]
                        )
                        created_images.append((recreated_image, meta))
                    else:
                        msg = ("Failed to re-create image in destination "
                               "because source image URL is missing")
                        LOG.info(msg)
                        self.state_notifier.fail(
                            objects.MigrationObjectType.IMAGE,
                            img, msg)
                    continue

                LOG.debug("Creating image '%s' (%s)", img["name"], img['id'])
                # we can face situation when image has no
                # disk_format and container_format properties
                # this situation appears, when image was created
                # with option --copy-from
                # glance-client cannot create image without this
                # properties, we need to create them artificially
                # and then - delete from database

                try:
                    data = img['resource'].get_ref_image(img['id'])
                    data_proxy = file_proxy.IterProxy(
                        data,
                        name="image %s ('%s')" % (img['name'], img['id']),
                        size=len(data))

                    created_image = self.create_image(
                        id=img['id'],
                        name=img['name'],
                        container_format=(img['container_format'] or "bare"),
                        disk_format=(img['disk_format'] or "qcow2"),
                        is_public=img['is_public'],
                        protected=img['protected'],
                        owner=img['owner'],
                        size=img['size'],
                        properties=img['properties'],
                        data=data_proxy)

                    image_members = img['members'].get(img['id'], {})
                    LOG.debug("new image ID %s", created_image.id)
                    self.update_membership(created_image.id, image_members)
                    created_images.append((created_image, meta))
                    self.state_notifier.success(
                        objects.MigrationObjectType.IMAGE, img,
                        created_image.id)
                except (exception.ImageDownloadError,
                        http.client.IncompleteRead,
                        glance_exceptions.HTTPInternalServerError) as e:
                    LOG.debug(e, exc_info=True)
                    msg = ("Unable to reach image's data due to "
                           "'%s'. Skipping image: %s (%s)" %
                           (e, img['name'], img["id"]))
                    LOG.warning(msg)
                    obsolete_images_ids_list.append(img["id"])
                    self.state_notifier.fail(
                        objects.MigrationObjectType.IMAGE, img, msg)
                    continue

                if not img["container_format"]:
                    delete_container_format.append(created_image.id)
                if not img["disk_format"]:
                    delete_disk_format.append(created_image.id)
            elif img['resource'] is None:
                recreated_image = utl.ext_dict(name=img["name"])
                created_images.append((recreated_image, meta))
            elif not img:
                empty_image_list[image_id_src] = info['images'][image_id_src]

        view.show_progress()
        if obsolete_images_ids_list:
            LOG.warning('List of broken images: %s', obsolete_images_ids_list)
            # Remove obsolete/broken images from info
            for img_id in obsolete_images_ids_list:
                info['images'].pop(img_id)

        return self._new_info(created_images, empty_image_list,
                              delete_disk_format, delete_container_format)
Exemplo n.º 13
0
from novaclient import exceptions as nova_exc
from oslotest import mockpatch

from cloudferry.lib.os.compute import server_groups
from cloudferry.lib.utils import utils

from tests import test


FAKE_CONFIG = utils.ext_dict(
    cloud=utils.ext_dict({'user': '******',
                          'password': '******',
                          'tenant': 'fake_tenant',
                          'region': None,
                          'auth_url': 'http://1.1.1.1:35357/v2.0/',
                          'cacert': '',
                          'insecure': False}),
    mysql=utils.ext_dict({'host': '1.1.1.1'}),
    migrate=utils.ext_dict({'migrate_quotas': True,
                            'speed_limit': '10MB',
                            'retry': '7',
                            'time_wait': 5}))


class ServerGroupTestCase(test.TestCase):

    def setUp(self):
        super(ServerGroupTestCase, self).setUp()

        self.mock_client = mock.MagicMock()
        self.nc_patch = mockpatch.PatchObject(nova_client, 'Client',
Exemplo n.º 14
0
from cloudferry.lib.utils import utils
from tests import test

FAKE_CONFIG = utils.ext_dict(cloud=utils.ext_dict({
    'user':
    '******',
    'password':
    '******',
    'tenant':
    'fake_tenant',
    'auth_url':
    'http://1.1.1.1:35357/v2.0/',
    'region':
    None,
    'service_tenant':
    'services',
    'cacert':
    '',
    'insecure':
    False,
    'endpoint_type':
    'internalURL'
}),
                             migrate=utils.ext_dict({
                                 'ext_net_map': 'fake_ext_net_map.yaml',
                                 'retry': '7',
                                 'time_wait': 5
                             }),
                             network=utils.ext_dict({'get_all_quota': True}))


class NeutronTestCase(test.TestCase):
Exemplo n.º 15
0
import os

import mock
from oslotest import mockpatch

from cloudferry.cloud import grouping, cloud
from cloudferry.lib.utils import utils
from tests import test

RESULT_FILE = 'tests/grouping_result'
FILE_NAME = 'tests/groups'
FAKE_CONFIG = utils.ext_dict(src=utils.ext_dict({
    'user': '******',
    'password': '******',
    'tenant': 'fake_tenant',
    'host': '1.1.1.1'
}),
                             migrate=utils.ext_dict(
                                 {'group_file_path': RESULT_FILE}))


class GroupingTestCase(test.TestCase):
    def setUp(self):
        super(GroupingTestCase, self).setUp()

        self.network = mock.Mock()
        self.compute = mock.Mock()
        self.identity = mock.Mock()

        self.fake_tenant1 = mock.Mock()
        self.fake_tenant1.id = 't1'
Exemplo n.º 16
0
from novaclient import exceptions as nova_exc
from oslotest import mockpatch

from cloudferry.lib.os.compute import server_groups
from cloudferry.lib.utils import utils

from tests import test

FAKE_CONFIG = utils.ext_dict(cloud=utils.ext_dict({
    'user': '******',
    'password': '******',
    'tenant': 'fake_tenant',
    'region': None,
    'auth_url': 'http://1.1.1.1:35357/v2.0/',
    'cacert': '',
    'insecure': False
}),
                             mysql=utils.ext_dict({'host': '1.1.1.1'}),
                             migrate=utils.ext_dict({
                                 'migrate_quotas': True,
                                 'speed_limit': '10MB',
                                 'retry': '7',
                                 'time_wait': 5
                             }))


class ServerGroupTestCase(test.TestCase):
    def setUp(self):
        super(ServerGroupTestCase, self).setUp()

        self.mock_client = mock.MagicMock()
        self.nc_patch = mockpatch.PatchObject(nova_client,
Exemplo n.º 17
0
import mock

from glanceclient.v1 import client as glance_client
from oslotest import mockpatch

from cloudferry.lib.os.image.glance_image import GlanceImage
from cloudferry.lib.utils import utils
from tests import test


FAKE_CONFIG = utils.ext_dict(cloud=utils.ext_dict({'user': '******',
                                                   'password': '******',
                                                   'tenant': 'fake_tenant',
                                                   'region': None,
                                                   'host': '1.1.1.1',
                                                   'ssh_host': '1.1.1.10',
                                                   'ssh_user': '******',
                                                   'cacert': '',
                                                   'insecure': False
                                                   }),
                             migrate=utils.ext_dict({'retry': '7',
                                                     'time_wait': 5}))


class FakeUser(object):
    def __init__(self):
        self.name = 'fake_user_name'


class GlanceImageTestCase(test.TestCase):

    def setUp(self):
Exemplo n.º 18
0
from oslotest import mockpatch

from cloudferry.lib.base import exception
from cloudferry.lib.os.network import neutron
from cloudferry.lib.utils import utils
from tests import test


FAKE_CONFIG = utils.ext_dict(
    cloud=utils.ext_dict({'user': '******',
                          'password': '******',
                          'tenant': 'fake_tenant',
                          'auth_url': 'http://1.1.1.1:35357/v2.0/',
                          'region': None,
                          'service_tenant': 'services',
                          'cacert': '',
                          'insecure': False,
                          'endpoint_type': 'internalURL'}),
    migrate=utils.ext_dict({'ext_net_map': 'fake_ext_net_map.yaml',
                            'retry': '7',
                            'time_wait': 5}),
    network=utils.ext_dict({
        'get_all_quota': True
    }))


class NeutronTestCase(test.TestCase):

    def setUp(self):
        super(NeutronTestCase, self).setUp()

        self.neutron_mock_client = mock.MagicMock()
Exemplo n.º 19
0
from glanceclient.v1 import client as glance_client
from oslotest import mockpatch

from cloudferry.lib.os.image.glance_image import GlanceImage
from cloudferry.lib.utils import utils
from tests import test

FAKE_CONFIG = utils.ext_dict(cloud=utils.ext_dict({
    'user': '******',
    'password': '******',
    'tenant': 'fake_tenant',
    'region': None,
    'host': '1.1.1.1',
    'ssh_host': '1.1.1.10',
    'ssh_user': '******',
    'cacert': '',
    'insecure': False
}),
                             migrate=utils.ext_dict({
                                 'retry': '7',
                                 'time_wait': 5
                             }))


class FakeUser(object):
    def __init__(self):
        self.name = 'fake_user_name'


class GlanceImageTestCase(test.TestCase):
Exemplo n.º 20
0
import mock

from novaclient.v2 import client as nova_client
from oslotest import mockpatch

from cloudferry.lib.os.network.nova_network import NovaNetwork
from cloudferry.lib.utils import utils
from tests import test


FAKE_CONFIG = utils.ext_dict(
    cloud=utils.ext_dict({'user': '******',
                          'password': '******',
                          'tenant': 'fake_tenant',
                          'region': None,
                          'auth_url': 'http://1.1.1.1:35357/v2.0/',
                          'cacert': '',
                          'insecure': False}),
    migrate=utils.ext_dict({'retry': '7',
                            'time_wait': 5}))


class TestNovaNetwork(test.TestCase):
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(
            nova_client,
            'Client',
Exemplo n.º 21
0
    def deploy(self, info, *args, **kwargs):
        LOG.info("Glance images deployment started...")
        info = copy.deepcopy(info)
        created_images = []
        delete_container_format, delete_disk_format = [], []
        empty_image_list = {}

        # List for obsolete/broken images IDs, that will not be migrated
        obsolete_images_ids_list = []
        dst_images = self._dst_images()

        view = GlanceImageProgessMigrationView(info['images'], dst_images)
        view.show_info()
        for image_id_src in info['images']:
            img = info['images'][image_id_src]['image']
            meta = info['images'][image_id_src]['meta']
            if img and img['resource']:
                checksum_current = img['checksum']
                name_current = img['name']
                tenant_name = img['owner_name']
                image_key = (name_current, tenant_name, checksum_current,
                             img['is_public'])

                if image_key in dst_images:
                    existing_image = dst_images[image_key]
                    created_images.append((existing_image, meta))
                    image_members = img['members'].get(img['id'], {})
                    self.update_membership(existing_image.id, image_members)
                    LOG.info("Image '%s' is already present on destination, "
                             "skipping", img['name'])
                    continue

                view.show_progress()
                view.inc_progress(img['size'])

                LOG.debug("Updating owner '%s' of image '%s'",
                          tenant_name, img["name"])
                img["owner"] = \
                    self.identity_client.get_tenant_id_by_name(tenant_name)

                if img["properties"]:
                    # update snapshot metadata
                    metadata = img["properties"]
                    if "owner_id" in metadata:
                        # update tenant id
                        LOG.debug("Updating snapshot metadata for field "
                                  "'owner_id' for image %s", img["id"])
                        metadata["owner_id"] = img["owner"]
                    if "user_name" in metadata:
                        # update user id by specified name
                        LOG.debug("Updating snapshot metadata for field "
                                  "'user_id' for image %s", img["id"])
                        try:
                            ks_client = self.identity_client.keystone_client
                            metadata["user_id"] = ks_client.users.find(
                                username=metadata["user_name"]).id
                            del metadata["user_name"]
                        except keystone_exceptions.NotFound:
                            LOG.warning("Cannot update user name for image %s",
                                        img['name'])
                if img["checksum"] is None:
                    LOG.warning("re-creating image %s from original source "
                                "URL", img["id"])
                    if meta['img_loc'] is not None:
                        self.create_image(
                            id=img['id'],
                            name=img['name'],
                            disk_format=img['disk_format'] or "qcow2",
                            location=meta['img_loc'],
                            container_format=img['container_format'] or 'bare',
                        )

                        recreated_image = utl.ext_dict(
                            name=img["name"]
                        )
                        created_images.append((recreated_image, meta))
                    else:
                        raise exception.AbortMigrationError(
                            "image information has no original source URL")
                    continue

                LOG.debug("Creating image '%s' (%s)", img["name"], img['id'])
                # we can face situation when image has no
                # disk_format and container_format properties
                # this situation appears, when image was created
                # with option --copy-from
                # glance-client cannot create image without this
                # properties, we need to create them artificially
                # and then - delete from database

                try:
                    data = img['resource'].get_ref_image(img['id'])
                    data_proxy = file_proxy.IterProxy(
                        data,
                        name="image %s ('%s')" % (img['name'], img['id']),
                        size=len(data))

                    created_image = self.create_image(
                        id=img['id'],
                        name=img['name'],
                        container_format=(img['container_format'] or "bare"),
                        disk_format=(img['disk_format'] or "qcow2"),
                        is_public=img['is_public'],
                        protected=img['protected'],
                        owner=img['owner'],
                        size=img['size'],
                        properties=img['properties'],
                        data=data_proxy)

                    image_members = img['members'].get(img['id'], {})
                    LOG.debug("new image ID %s", created_image.id)
                    self.update_membership(created_image.id, image_members)
                    created_images.append((created_image, meta))
                except (exception.ImageDownloadError,
                        httplib.IncompleteRead,
                        glance_exceptions.HTTPInternalServerError) as e:
                    LOG.debug(e, exc_info=True)
                    LOG.warning("Unable to reach image's data due to "
                                "Glance HTTPInternalServerError. Skipping "
                                "image: %s (%s)", img['name'], img["id"])
                    obsolete_images_ids_list.append(img["id"])
                    continue

                if not img["container_format"]:
                    delete_container_format.append(created_image.id)
                if not img["disk_format"]:
                    delete_disk_format.append(created_image.id)
            elif img['resource'] is None:
                recreated_image = utl.ext_dict(name=img["name"])
                created_images.append((recreated_image, meta))
            elif not img:
                empty_image_list[image_id_src] = info['images'][image_id_src]

        view.show_progress()
        if obsolete_images_ids_list:
            LOG.warning('List of broken images: %s', obsolete_images_ids_list)
            # Remove obsolete/broken images from info
            for img_id in obsolete_images_ids_list:
                info['images'].pop(img_id)

        return self._new_info(created_images, empty_image_list,
                              delete_disk_format, delete_container_format)
Exemplo n.º 22
0

import os

import mock
from oslotest import mockpatch

from cloudferry.cloud import grouping, cloud
from cloudferry.lib.utils import utils
from tests import test

RESULT_FILE = 'tests/grouping_result'
FILE_NAME = 'tests/groups'
FAKE_CONFIG = utils.ext_dict(src=utils.ext_dict({'user': '******',
                                                 'password': '******',
                                                 'tenant': 'fake_tenant',
                                                 'host': '1.1.1.1'}),
                             migrate=utils.ext_dict(
                                 {'group_file_path': RESULT_FILE}))


class GroupingTestCase(test.TestCase):
    def setUp(self):
        super(GroupingTestCase, self).setUp()

        self.network = mock.Mock()
        self.compute = mock.Mock()
        self.identity = mock.Mock()

        self.fake_tenant1 = mock.Mock()
        self.fake_tenant1.id = 't1'
        self.fake_tenant2 = mock.Mock()