Coverage for manila/tests/api/v1/stubs.py: 0%

51 statements  

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

1# Copyright 2010 OpenStack LLC. 

2# All Rights Reserved. 

3# 

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

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

6# a copy of the License at 

7# 

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

9# 

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

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

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

13# License for the specific language governing permissions and limitations 

14# under the License. 

15 

16import datetime 

17 

18from manila.common import constants 

19from manila import exception as exc 

20 

21FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' 

22FAKE_UUIDS = {} 

23 

24 

25def stub_volume(id, **kwargs): 

26 volume = { 

27 'id': id, 

28 'user_id': 'fakeuser', 

29 'project_id': 'fakeproject', 

30 'host': 'fakehost', 

31 'size': 1, 

32 'availability_zone': 'fakeaz', 

33 'instance_uuid': 'fakeuuid', 

34 'mountpoint': '/', 

35 'status': 'fakestatus', 

36 'attach_status': 'attached', 

37 'bootable': 'false', 

38 'name': 'vol name', 

39 'display_name': 'displayname', 

40 'display_description': 'displaydesc', 

41 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), 

42 'snapshot_id': None, 

43 'source_volid': None, 

44 'share_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66', 

45 'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66', 

46 'volume_metadata': [], 

47 'share_type': {'name': 'share_type_name'}, 

48 'volume_type': {'name': 'share_type_name'}} 

49 

50 volume.update(kwargs) 

51 return volume 

52 

53 

54def stub_volume_create(self, context, size, name, description, snapshot, 

55 **param): 

56 vol = stub_volume('1') 

57 vol['size'] = size 

58 vol['display_name'] = name 

59 vol['display_description'] = description 

60 vol['source_volid'] = None 

61 try: 

62 vol['snapshot_id'] = snapshot['id'] 

63 except (KeyError, TypeError): 

64 vol['snapshot_id'] = None 

65 vol['availability_zone'] = param.get('availability_zone', 'fakeaz') 

66 return vol 

67 

68 

69def stub_volume_create_from_image(self, context, size, name, description, 

70 snapshot, volume_type, metadata, 

71 availability_zone): 

72 vol = stub_volume('1') 

73 vol['status'] = 'creating' 

74 vol['size'] = size 

75 vol['display_name'] = name 

76 vol['display_description'] = description 

77 vol['availability_zone'] = 'manila' 

78 return vol 

79 

80 

81def stub_volume_update(self, context, *args, **param): 

82 pass 

83 

84 

85def stub_volume_delete(self, context, *args, **param): 

86 pass 

87 

88 

89def stub_volume_get(self, context, volume_id): 

90 return stub_volume(volume_id) 

91 

92 

93def stub_volume_get_notfound(self, context, volume_id): 

94 raise exc.NotFound 

95 

96 

97def stub_volume_get_all(context, search_opts=None): 

98 return [stub_volume(100, project_id='fake'), 

99 stub_volume(101, project_id='superfake'), 

100 stub_volume(102, project_id='superduperfake')] 

101 

102 

103def stub_volume_get_all_by_project(self, context, search_opts=None): 

104 return [stub_volume_get(self, context, '1')] 

105 

106 

107def stub_snapshot(id, **kwargs): 

108 snapshot = {'id': id, 

109 'volume_id': 12, 

110 'status': constants.STATUS_AVAILABLE, 

111 'volume_size': 100, 

112 'created_at': None, 

113 'display_name': 'Default name', 

114 'display_description': 'Default description', 

115 'project_id': 'fake'} 

116 

117 snapshot.update(kwargs) 

118 return snapshot 

119 

120 

121def stub_snapshot_get_all(self): 

122 return [stub_snapshot(100, project_id='fake'), 

123 stub_snapshot(101, project_id='superfake'), 

124 stub_snapshot(102, project_id='superduperfake')] 

125 

126 

127def stub_snapshot_get_all_by_project(self, context): 

128 return [stub_snapshot(1)] 

129 

130 

131def stub_snapshot_update(self, context, *args, **param): 

132 pass