'Test volume create from snapshot with types including mistmatch.'

@mock.patch('cinder.volume.flows.api.create_volume.get_flow')
def test_create_volume_from_snapshot_with_types(self, _get_flow):

    volume_api = cinder.volume.api.API()
    foo_type = fake_volume.fake_volume_type_obj(self.context, id=fake.VOLUME_TYPE_ID, name='foo', extra_specs={'volume_backend_name': 'dev_1'})
    biz_type = fake_volume.fake_volume_type_obj(self.context, id=fake.VOLUME_TYPE2_ID, name='foo', extra_specs={'volume_backend_name': 'dev_2'})
    source_vol = fake_volume.fake_volume_obj(self.context, id=fake.VOLUME_ID, status='available', volume_size=10, volume_type_id=biz_type.id)
    source_vol.volume_type = biz_type
    snapshot = {'id': fake.SNAPSHOT_ID, 'status': fields.SnapshotStatus.AVAILABLE, 'volume_size': 10, 'volume_type_id': biz_type.id}
    snapshot_obj = fake_snapshot.fake_snapshot_obj(self.context, **snapshot)
    snapshot_obj.volume = source_vol
    self.assertRaises(exception.InvalidInput, volume_api.create, self.context, size=1, name='fake_name', description='fake_desc', volume_type=foo_type, snapshot=snapshot_obj)
    snapshot_obj.volume_type_id = None
    snapshot_obj.volume.volume_type_id = None
    snapshot_obj.volume.volume_type = None
    self.assertRaises(exception.InvalidInput, volume_api.create, self.context, size=1, name='fake_name', description='fake_desc', volume_type=foo_type, snapshot=snapshot_obj)
    snapshot_obj.volume_type_id = foo_type.id
    snapshot_obj.volume.volume_type_id = foo_type.id
    snapshot_obj.volume.volume_type = foo_type
    volume_api.create(self.context, size=1, name='fake_name', description='fake_desc', volume_type=foo_type, snapshot=snapshot_obj)
