def test_extract_image_volume_type_from_image_invalid_type(
            self, fake_get_type_id, fake_get_def_vol_type, fake_get_qos,
            fake_is_encrypted, fake_db_get_vol_type):

        image_volume_type = 'invalid'
        fake_image_service = fake_image.FakeImageService()
        image_id = 7
        image_meta = {}
        image_meta['id'] = image_id
        image_meta['status'] = 'active'
        image_meta['size'] = 1
        image_meta['properties'] = {}
        image_meta['properties']['cinder_img_volume_type'] = image_volume_type
        fake_image_service.create(self.ctxt, image_meta)
        fake_key_manager = mock_key_manager.MockKeyManager()

        task = create_volume.ExtractVolumeRequestTask(fake_image_service,
                                                      {'nova'})

        fake_is_encrypted.return_value = False
        fake_get_type_id.return_value = 1
        fake_get_def_vol_type.return_value = 'fake_vol_type'
        fake_db_get_vol_type.side_effect = (exception.VolumeTypeNotFoundByName(
            volume_type_name='invalid'))
        fake_get_qos.return_value = {'qos_specs': None}
        result = task.execute(self.ctxt,
                              size=1,
                              snapshot=None,
                              image_id=image_id,
                              source_volume=None,
                              availability_zone='nova',
                              volume_type=None,
                              metadata=None,
                              key_manager=fake_key_manager,
                              source_replica=None,
                              consistencygroup=None,
                              cgsnapshot=None,
                              group=None)
        expected_result = {
            'size': 1,
            'snapshot_id': None,
            'source_volid': None,
            'availability_zone': 'nova',
            'volume_type': 'fake_vol_type',
            'volume_type_id': 1,
            'encryption_key_id': None,
            'qos_specs': None,
            'source_replicaid': None,
            'consistencygroup_id': None,
            'cgsnapshot_id': None,
            'group_id': None,
        }
        self.assertEqual(expected_result, result)
    def test_extract_volume_request_from_image_with_qos_specs(
            self, fake_get_type_id, fake_get_qos, fake_is_encrypted):

        fake_image_service = fake_image.FakeImageService()
        image_id = 5
        image_meta = {}
        image_meta['id'] = image_id
        image_meta['status'] = 'active'
        image_meta['size'] = 1
        fake_image_service.create(self.ctxt, image_meta)
        fake_key_manager = mock_key_manager.MockKeyManager()
        volume_type = 'type1'

        task = create_volume.ExtractVolumeRequestTask(fake_image_service,
                                                      {'nova'})

        fake_is_encrypted.return_value = False
        fake_get_type_id.return_value = 1
        fake_qos_spec = {'specs': {'fake_key': 'fake'}}
        fake_get_qos.return_value = {'qos_specs': fake_qos_spec}
        result = task.execute(self.ctxt,
                              size=1,
                              snapshot=None,
                              image_id=image_id,
                              source_volume=None,
                              availability_zone='nova',
                              volume_type=volume_type,
                              metadata=None,
                              key_manager=fake_key_manager,
                              source_replica=None,
                              consistencygroup=None,
                              cgsnapshot=None,
                              group=None)
        expected_result = {
            'size': 1,
            'snapshot_id': None,
            'source_volid': None,
            'availability_zone': 'nova',
            'volume_type': volume_type,
            'volume_type_id': 1,
            'encryption_key_id': None,
            'qos_specs': {
                'fake_key': 'fake'
            },
            'source_replicaid': None,
            'consistencygroup_id': None,
            'cgsnapshot_id': None,
            'group_id': None,
        }
        self.assertEqual(expected_result, result)
Ejemplo n.º 3
0
 def _create_key_manager(self):
     return mock_key_mgr.MockKeyManager()
Ejemplo n.º 4
0
def fake_api(configuration=None):
    return mock_key_manager.MockKeyManager(configuration)
Ejemplo n.º 5
0
def fake_api():
    return mock_key_manager.MockKeyManager()