Coverage for manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2015 Mirantis, Inc. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15"""Add required extra spec 

16 

17Revision ID: 59eb64046740 

18Revises: 162a3e673105 

19Create Date: 2015-01-29 15:33:25.348140 

20 

21""" 

22 

23# revision identifiers, used by Alembic. 

24revision = '59eb64046740' 

25down_revision = '4ee2cf4be19a' 

26 

27from alembic import op 

28from oslo_utils import timeutils 

29import sqlalchemy as sa 

30from sqlalchemy.sql import table 

31 

32 

33def upgrade(): 

34 with sa.orm.Session(bind=op.get_bind()) as session: 

35 

36 es_table = table( 

37 'share_type_extra_specs', 

38 sa.Column('created_at', sa.DateTime), 

39 sa.Column('deleted', sa.Integer), 

40 sa.Column('share_type_id', sa.String(length=36)), 

41 sa.Column('spec_key', sa.String(length=255)), 

42 sa.Column('spec_value', sa.String(length=255))) 

43 

44 st_table = table( 

45 'share_types', 

46 sa.Column('deleted', sa.Integer), 

47 sa.Column('id', sa.Integer)) 

48 

49 # NOTE(vponomaryov): field 'deleted' is integer here. 

50 existing_required_extra_specs = ( 

51 session.query(es_table).filter( 

52 es_table.c.spec_key == 

53 'driver_handles_share_servers' 

54 ).filter(es_table.c.deleted == 0).all() 

55 ) 

56 exclude_st_ids = [ 

57 es.share_type_id for es in existing_required_extra_specs] 

58 

59 # NOTE(vponomaryov): field 'deleted' is string here. 

60 share_types = ( 

61 session.query(st_table). 

62 filter(st_table.c.deleted.in_(('0', 'False', ))). 

63 filter(st_table.c.id.notin_(exclude_st_ids)). 

64 all() 

65 ) 

66 

67 extra_specs = [] 

68 for st in share_types: 

69 extra_specs.append({ 

70 'spec_key': 'driver_handles_share_servers', 

71 'spec_value': 'True', 

72 'deleted': 0, 

73 'created_at': timeutils.utcnow(), 

74 'share_type_id': st.id, 

75 }) 

76 

77 op.bulk_insert(es_table, extra_specs) 

78 

79 

80def downgrade(): 

81 """Downgrade method. 

82 

83 We can't determine, which extra specs should be removed after insertion, 

84 that's why do nothing here. 

85 """