Exemplo n.º 1
0
    def test_create_snapshot_metadata_update_failure_generates_user_message(
            self, fake_notify, fake_init, fake_msg_create):
        manager = vol_manager.VolumeManager()

        fake_driver = mock.MagicMock()
        fake_driver.create_snapshot.return_value = False
        manager.driver = fake_driver

        fake_vol_ref = mock.MagicMock()
        fake_vol_ref.bootable.return_value = True
        fake_db = mock.MagicMock()
        fake_db.volume_get.return_value = fake_vol_ref
        fake_exp = exception.CinderException()
        fake_db.volume_glance_metadata_copy_to_snapshot.side_effect = fake_exp
        manager.db = fake_db

        fake_snapshot = mock.MagicMock(id='86')
        fake_context = mock.MagicMock()
        fake_context.elevated.return_value = fake_context

        self.assertRaises(exception.CinderException, manager.create_snapshot,
                          fake_context, fake_snapshot)

        # make sure a user message was generated
        fake_msg_create.assert_called_once_with(
            fake_context,
            action=message_field.Action.SNAPSHOT_CREATE,
            resource_type=message_field.Resource.VOLUME_SNAPSHOT,
            resource_uuid=fake_snapshot['id'],
            exception=fake_exp,
            detail=message_field.Detail.SNAPSHOT_UPDATE_METADATA_FAILED)
Exemplo n.º 2
0
    def test_cache_configs(self, mock_import_object):
        opts = {
            'image_volume_cache_enabled': True,
            'image_volume_cache_max_size_gb': 100,
            'image_volume_cache_max_count': 20
        }

        def conf_get(option):
            if option in opts:
                return opts[option]
            else:
                return None

        mock_driver = mock.Mock()
        mock_driver.configuration.safe_get.side_effect = conf_get
        mock_driver.configuration.extra_capabilities = 'null'

        def import_obj(*args, **kwargs):
            return mock_driver

        mock_import_object.side_effect = import_obj

        manager = vol_manager.VolumeManager(volume_driver=mock_driver)
        self.assertIsNotNone(manager)
        self.assertIsNotNone(manager.image_volume_cache)
        self.assertEqual(100, manager.image_volume_cache.max_cache_size_gb)
        self.assertEqual(20, manager.image_volume_cache.max_cache_size_count)
Exemplo n.º 3
0
    def test_init_host_with_rpc_clustered_replication(self):
        # These are not OVOs but ORM instances
        cluster = utils.create_cluster(self.context)
        service = utils.create_service(self.context,
                                       {'cluster_name': cluster.name,
                                        'binary': cluster.binary})
        self.assertNotEqual(fields.ReplicationStatus.ENABLED,
                            cluster.replication_status)
        self.assertNotEqual(fields.ReplicationStatus.ENABLED,
                            service.replication_status)

        vol_manager = manager.VolumeManager(
            'cinder.tests.fake_driver.FakeHAReplicatedLoggingVolumeDriver',
            host=service.host, cluster=cluster.name)
        vol_manager.driver = mock.Mock()
        vol_manager.driver.get_volume_stats.return_value = {
            'replication_enabled': True
        }
        vol_manager.init_host_with_rpc()

        cluster_ovo = objects.Cluster.get_by_id(self.context, cluster.id)
        service_ovo = objects.Service.get_by_id(self.context, service.id)

        self.assertEqual(fields.ReplicationStatus.ENABLED,
                         cluster_ovo.replication_status)
        self.assertEqual(fields.ReplicationStatus.ENABLED,
                         service_ovo.replication_status)
Exemplo n.º 4
0
    def test_delete_snapshot_general_exception_generates_user_message(
            self, fake_notify, fake_init, fake_msg_create):
        manager = vol_manager.VolumeManager()

        fake_snapshot = mock.MagicMock(id='0', project_id='1')
        fake_context = mock.MagicMock()
        fake_context.elevated.return_value = fake_context

        class LocalException(Exception):
            pass

        fake_exp = LocalException()
        # yeah, this isn't where it would be coming from in real life,
        # but it saves mocking out a bunch more stuff
        fake_init.side_effect = fake_exp

        self.assertRaises(LocalException, manager.delete_snapshot,
                          fake_context, fake_snapshot)

        # make sure a user message was generated
        fake_msg_create.assert_called_once_with(
            fake_context,
            action=message_field.Action.SNAPSHOT_DELETE,
            resource_type=message_field.Resource.VOLUME_SNAPSHOT,
            resource_uuid=fake_snapshot['id'],
            exception=fake_exp,
            detail=message_field.Detail.SNAPSHOT_DELETE_ERROR)
Exemplo n.º 5
0
 def setUp(self,
           enforce_scope=False,
           enforce_new_defaults=False,
           *args,
           **kwargs):
     super().setUp(enforce_scope, enforce_new_defaults, *args, **kwargs)
     self.controller = group_snapshots.GroupSnapshotsController()
     self.manager = volume_manager.VolumeManager()
     self.api_path = '/v3/%s/group_snapshots' % (self.project_id)
     self.api_version = mv.GROUP_GROUPSNAPSHOT_PROJECT_ID
Exemplo n.º 6
0
    def setUp(self, enforce_scope=False, enforce_new_defaults=False,
              *args, **kwargs):
        super().setUp(enforce_scope, enforce_new_defaults, *args, **kwargs)

        self.controller = attachments.AttachmentsController()
        self.manager = volume_manager.VolumeManager()
        self.manager.driver = mock.MagicMock()
        self.manager.driver.initialize_connection = mock.MagicMock()
        self.manager.driver.initialize_connection.side_effect = (
            self._initialize_connection)

        self.api_path = '/v3/%s/attachments' % (self.project_id)
        self.api_version = mv.NEW_ATTACH
Exemplo n.º 7
0
    def test_extra_capabilities(self):
        # Test valid extra_capabilities.
        fake_capabilities = {'key1': 1, 'key2': 2}

        with mock.patch.object(jsonutils, 'loads') as mock_loads:
            mock_loads.return_value = fake_capabilities
            manager = vol_manager.VolumeManager()
            manager.stats = {'pools': {}}
            manager.driver.set_initialized()
            manager.publish_service_capabilities(self.context)
            self.assertTrue(mock_loads.called)
            volume_stats = manager.last_capabilities
            self.assertEqual(fake_capabilities['key1'], volume_stats['key1'])
            self.assertEqual(fake_capabilities['key2'], volume_stats['key2'])
Exemplo n.º 8
0
    def test_delete_snapshot_when_busy_generates_user_message(
            self, fake_notify, fake_init, fake_msg_create):
        manager = vol_manager.VolumeManager()

        fake_snapshot = mock.MagicMock(id='0', project_id='1')
        fake_context = mock.MagicMock()
        fake_context.elevated.return_value = fake_context
        fake_exp = exception.SnapshotIsBusy(snapshot_name='Fred')
        fake_init.side_effect = fake_exp

        manager.delete_snapshot(fake_context, fake_snapshot)

        # make sure a user message was generated
        fake_msg_create.assert_called_once_with(
            fake_context,
            action=message_field.Action.SNAPSHOT_DELETE,
            resource_type=message_field.Resource.VOLUME_SNAPSHOT,
            resource_uuid=fake_snapshot['id'],
            exception=fake_exp)
Exemplo n.º 9
0
    def test_attach_volume_local(self, mock_api):
        manager = vol_manager.VolumeManager()

        mock_initialize = self.mock_object(manager, 'initialize_connection')
        mock_connect = self.mock_object(manager, '_connect_device')

        ctxt = mock.sentinel.context
        vol = fake_volume.fake_volume_obj(ctxt)

        result = manager._attach_volume(ctxt,
                                        vol,
                                        mock.sentinel.properties,
                                        remote=False)

        mock_api.assert_not_called()
        mock_initialize.assert_called_once_with(ctxt, vol,
                                                mock.sentinel.properties)
        mock_connect.assert_called_once_with(mock_initialize.return_value)
        self.assertEqual(mock_connect.return_value, result)
Exemplo n.º 10
0
    def test_create_snapshot_driver_not_initialized_generates_user_message(
            self, fake_notify, fake_init, fake_msg_create):
        manager = vol_manager.VolumeManager()

        fake_init.side_effect = exception.CinderException()
        fake_snapshot = mock.MagicMock(id='22')
        fake_context = mock.MagicMock()
        fake_context.elevated.return_value = fake_context

        ex = self.assertRaises(exception.CinderException,
                               manager.create_snapshot, fake_context,
                               fake_snapshot)

        # make sure a user message was generated
        fake_msg_create.assert_called_once_with(
            fake_context,
            action=message_field.Action.SNAPSHOT_CREATE,
            resource_type=message_field.Resource.VOLUME_SNAPSHOT,
            resource_uuid=fake_snapshot['id'],
            exception=ex,
            detail=message_field.Detail.SNAPSHOT_CREATE_ERROR)
Exemplo n.º 11
0
    def test_attach_volume_fail_decrypt(self, mock_api, mock_is_encrypted,
                                        mock_attach_encryptor):
        mock_initialize = mock_api.return_value.initialize_connection

        manager = vol_manager.VolumeManager()
        mock_detach = self.mock_object(manager, '_detach_volume')
        mock_connect = self.mock_object(manager, '_connect_device')
        mock_db = self.mock_object(manager.db,
                                   'volume_encryption_metadata_get')
        mock_attach_encryptor.side_effect = ValueError

        ctxt = mock.Mock()
        vol = fake_volume.fake_volume_obj(ctxt)

        self.assertRaises(ValueError,
                          manager._attach_volume,
                          ctxt,
                          vol,
                          mock.sentinel.properties,
                          mock.sentinel.remote,
                          attach_encryptor=True)

        mock_initialize.assert_called_once_with(ctxt, vol,
                                                mock.sentinel.properties)
        mock_connect.assert_called_once_with(mock_initialize.return_value)
        mock_is_encrypted.assert_called_once_with(ctxt, vol.volume_type_id)
        mock_db.assert_called_once_with(ctxt.elevated.return_value, vol.id)
        mock_attach_encryptor.assert_called_once_with(
            ctxt, mock_connect.return_value, mock_db.return_value)

        mock_detach.assert_called_once_with(ctxt,
                                            mock_connect.return_value,
                                            vol,
                                            mock.sentinel.properties,
                                            force=True,
                                            remote=mock.sentinel.remote)
Exemplo n.º 12
0
    def test_attach_volume_fail_connect(self, mock_api):
        mock_initialize = mock_api.return_value.initialize_connection

        manager = vol_manager.VolumeManager()
        mock_detach = self.mock_object(manager, '_detach_volume')
        mock_connect = self.mock_object(manager,
                                        '_connect_device',
                                        side_effect=ValueError)

        ctxt = mock.sentinel.context
        vol = fake_volume.fake_volume_obj(ctxt)

        self.assertRaises(ValueError, manager._attach_volume, ctxt, vol,
                          mock.sentinel.properties, mock.sentinel.remote)

        mock_initialize.assert_called_once_with(ctxt, vol,
                                                mock.sentinel.properties)
        mock_connect.assert_called_once_with(mock_initialize.return_value)
        mock_detach.assert_called_once_with(ctxt,
                                            None,
                                            vol,
                                            mock.sentinel.properties,
                                            force=True,
                                            remote=mock.sentinel.remote)
Exemplo n.º 13
0
    def test_parse_connection_options_cacheable(self, mock_get_qos,
                                                mock_get_extra_specs):
        ctxt = mock.Mock()
        manager = vol_manager.VolumeManager()
        vol = fake_volume.fake_volume_obj(ctxt)
        vol.volume_type_id = fake.VOLUME_TYPE_ID

        # no 'cacheable' set by driver, should be extra spec
        conn_info = {"data": {}}
        mock_get_extra_specs.return_value = '<is> True'
        manager._parse_connection_options(ctxt, vol, conn_info)
        self.assertIn('cacheable', conn_info['data'])
        self.assertIs(conn_info['data']['cacheable'], True)

        # driver sets 'cacheable' False, should override extra spec
        conn_info = {"data": {"cacheable": False}}
        mock_get_extra_specs.return_value = '<is> True'
        manager._parse_connection_options(ctxt, vol, conn_info)
        self.assertIn('cacheable', conn_info['data'])
        self.assertIs(conn_info['data']['cacheable'], False)

        # driver sets 'cacheable' True, nothing in extra spec,
        # extra spec should override driver
        conn_info = {"data": {"cacheable": True}}
        mock_get_extra_specs.return_value = None
        manager._parse_connection_options(ctxt, vol, conn_info)
        self.assertIn('cacheable', conn_info['data'])
        self.assertIs(conn_info['data']['cacheable'], False)

        # driver sets 'cacheable' True, extra spec has False,
        # extra spec should override driver
        conn_info = {"data": {"cacheable": True}}
        mock_get_extra_specs.return_value = '<is> False'
        manager._parse_connection_options(ctxt, vol, conn_info)
        self.assertIn('cacheable', conn_info['data'])
        self.assertIs(conn_info['data']['cacheable'], False)
Exemplo n.º 14
0
 def setUp(self):
     super(ReplicationTestCase, self).setUp()
     self.host = 'host@backend#pool'
     self.manager = manager.VolumeManager(host=self.host)
Exemplo n.º 15
0
 def setUp(self):
     super(ManageVolumeTestCase, self).setUp()
     self.context = context.RequestContext(fake.USER_ID, fake.PROJECT_ID,
                                           True)
     self.manager = manager.VolumeManager()
     self.manager.stats = {'allocated_capacity_gb': 0, 'pools': {}}