Coverage for manila/message/message_field.py: 91%

83 statements  

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

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

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

3# a copy of the License at 

4# 

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

6# 

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

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

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

10# License for the specific language governing permissions and limitations 

11# under the License. 

12 

13from manila import exception 

14from manila.i18n import _ 

15 

16 

17class Resource(object): 

18 

19 SHARE = 'SHARE' 

20 SHARE_GROUP = 'SHARE_GROUP' 

21 SHARE_REPLICA = 'SHARE_REPLICA' 

22 SHARE_SNAPSHOT = 'SHARE_SNAPSHOT' 

23 SECURITY_SERVICE = 'SECURITY_SERVICE' 

24 SHARE_NETWORK_SUBNET = 'SHARE_NETWORK_SUBNET' 

25 

26 

27class Action(object): 

28 

29 ALLOCATE_HOST = ('001', _('allocate host')) 

30 CREATE = ('002', _('create')) 

31 DELETE_ACCESS_RULES = ('003', _('delete access rules')) 

32 PROMOTE = ('004', _('promote')) 

33 UPDATE = ('005', _('update')) 

34 REVERT_TO_SNAPSHOT = ('006', _('revert to snapshot')) 

35 DELETE = ('007', _('delete')) 

36 EXTEND = ('008', _('extend')) 

37 SHRINK = ('009', _('shrink')) 

38 UPDATE_ACCESS_RULES = ('010', _('update access rules')) 

39 ADD_UPDATE_SECURITY_SERVICE = ('011', _('add or update security service')) 

40 TRANSFER_ACCEPT = ('026', _('transfer accept')) 

41 UPDATE_METADATA = ('027', _('update_metadata')) 

42 RESTORE_BACKUP = ('028', _('restore share backup')) 

43 ALL = ( 

44 ALLOCATE_HOST, 

45 CREATE, 

46 DELETE_ACCESS_RULES, 

47 PROMOTE, 

48 UPDATE, 

49 REVERT_TO_SNAPSHOT, 

50 DELETE, 

51 EXTEND, 

52 SHRINK, 

53 UPDATE_ACCESS_RULES, 

54 ADD_UPDATE_SECURITY_SERVICE, 

55 TRANSFER_ACCEPT, 

56 UPDATE_METADATA, 

57 RESTORE_BACKUP 

58 ) 

59 

60 

61class Detail(object): 

62 

63 UNKNOWN_ERROR = ('001', _('An unknown error occurred.')) 

64 NO_VALID_HOST = ( 

65 '002', _("No storage could be allocated for this share request. " 

66 "Trying again with a different size or share type may " 

67 "succeed.")) 

68 UNEXPECTED_NETWORK = ( 

69 '003', _("Driver does not expect share-network to be provided with " 

70 "current configuration.")) 

71 NO_SHARE_SERVER = ( 

72 '004', _("Could not find an existing share server or allocate one on " 

73 "the share network provided. You may use a different share " 

74 "network, or verify the network details in the share network " 

75 "and retry your request. If this doesn't work, contact your " 

76 "administrator to troubleshoot issues with your network.")) 

77 NO_ACTIVE_AVAILABLE_REPLICA = ( 

78 '005', _("An 'active' replica must exist in 'available' state to " 

79 "create a new replica for share.")) 

80 NO_ACTIVE_REPLICA = ( 

81 '006', _("Share has no replica with 'replica_state' set to 'active'.")) 

82 

83 FILTER_MSG = _("No storage could be allocated for this share request, " 

84 "%s filter didn't succeed.") 

85 FILTER_AVAILABILITY = ('007', FILTER_MSG % 'AvailabilityZone') 

86 FILTER_CAPABILITIES = ('008', FILTER_MSG % 'Capabilities') 

87 FILTER_CAPACITY = ('009', FILTER_MSG % 'Capacity') 

88 FILTER_DRIVER = ('010', FILTER_MSG % 'Driver') 

89 FILTER_IGNORE = ('011', FILTER_MSG % 'IgnoreAttemptedHosts') 

90 FILTER_JSON = ('012', FILTER_MSG % 'Json') 

91 FILTER_RETRY = ('013', FILTER_MSG % 'Retry') 

92 FILTER_REPLICATION = ('014', FILTER_MSG % 'ShareReplication') 

93 DRIVER_FAILED_EXTEND = ( 

94 '015', 

95 _("Share Driver failed to extend share, The share status has been " 

96 "set to extending_error. This action cannot be re-attempted until " 

97 "the status has been rectified. Contact your administrator to " 

98 "determine the cause of this failure.")) 

99 FILTER_CREATE_FROM_SNAPSHOT = ('016', FILTER_MSG % 'CreateFromSnapshot') 

100 DRIVER_FAILED_CREATING_FROM_SNAP = ( 

101 '017', 

102 _("Share Driver has failed to create the share from snapshot. This " 

103 "operation can be re-attempted by creating a new share. Contact " 

104 "your administrator to determine the cause of this failure.")) 

105 DRIVER_REFUSED_SHRINK = ( 

106 '018', 

107 _("Share Driver refused to shrink the share. The size to be shrunk is" 

108 " smaller than the current used space. The share status has been" 

109 " set to available. Please select a size greater than the current" 

110 " used space.")) 

111 DRIVER_FAILED_SHRINK = ( 

112 '019', 

113 _("Share Driver does not support shrinking shares." 

114 " Shrinking share operation failed.")) 

115 FORBIDDEN_CLIENT_ACCESS = ( 

116 '020', 

117 _("Failed to grant access to client. The client ID used may be " 

118 "forbidden. You may try again with a different client identifier.")) 

119 UNSUPPORTED_CLIENT_ACCESS = ( 

120 '021', 

121 _("Failed to grant access to client. The access level or type may " 

122 "be unsupported. You may try again with a different access level " 

123 "or access type.")) 

124 UNSUPPORTED_ADD_UDPATE_SECURITY_SERVICE = ( 

125 '022', 

126 _("Share driver has failed to setup one or more security services " 

127 "that are associated with the used share network. The security " 

128 "service may be unsupported or the provided parameters are invalid. " 

129 "You may try again with a different set of configurations.")) 

130 SECURITY_SERVICE_FAILED_AUTH = ( 

131 '023', 

132 _("Share Driver failed to create share due to a security service " 

133 "authentication issue. The security service user has either " 

134 "insufficient privileges or wrong credentials. Please check your " 

135 "user, password, ou and domain.")) 

136 

137 NO_DEFAULT_SHARE_TYPE = ( 

138 '024', 

139 _("No default share type has been made available. " 

140 "You must specify a share type for creating shares.")) 

141 MISSING_SECURITY_SERVICE = ( 

142 '025', 

143 _("Share Driver failed to create share because a security service " 

144 "has not been added to the share network used. Please add a " 

145 "security service to the share network.")) 

146 DRIVER_FAILED_TRANSFER_ACCEPT = ( 

147 '026', 

148 _("Share transfer cannot be accepted without clearing access rules.")) 

149 SHARE_NETWORK_PORT_QUOTA_LIMIT_EXCEEDED = ( 

150 '027', 

151 _("Failed to create a new network port on the share network subnet. " 

152 "The limit of the number of ports has been exceeded. You may " 

153 "increase the network port quotas or free up some ports and retry. " 

154 "If this doesn't work, contact your administrator to troubleshoot " 

155 "issues with your network.")) 

156 SHARE_BACKEND_NOT_READY_YET = ( 

157 '028', 

158 _("No storage could be allocated for this share " 

159 "request. Share back end services are not " 

160 "ready yet. Contact your administrator in case " 

161 "retrying does not help.")) 

162 UPDATE_METADATA_SUCCESS = ( 

163 '029', 

164 _("Metadata passed to share driver successfully performed required " 

165 "operation.")) 

166 UPDATE_METADATA_FAILURE = ( 

167 '030', 

168 _("Metadata passed to share driver failed to perform required " 

169 "operation.")) 

170 UPDATE_METADATA_NOT_DELETED = ( 

171 '031', 

172 _("Metadata delete operation includes driver updatable metadata, and " 

173 "it is not passed to share driver to perform required operation.")) 

174 TARGETED_RESTORE_UNSUPPORTED = ( 

175 '032', 

176 _("Cannot restore a given backup to a target share, not supported by " 

177 "share driver.")) 

178 NEUTRON_SUBNET_FULL = ( 

179 '033', 

180 _("Share Driver failed to create share server on share network " 

181 "due no more free IP addresses in the neutron subnet." 

182 "You may free some IP addresses in the subnet " 

183 "or create a new subnet/share network. If this doesn't work, " 

184 "contact your administrator to troubleshoot " 

185 "issues with your network.")) 

186 

187 ALL = ( 

188 UNKNOWN_ERROR, 

189 NO_VALID_HOST, 

190 UNEXPECTED_NETWORK, 

191 NO_SHARE_SERVER, 

192 NO_ACTIVE_AVAILABLE_REPLICA, 

193 NO_ACTIVE_REPLICA, 

194 FILTER_AVAILABILITY, 

195 FILTER_CAPABILITIES, 

196 FILTER_CAPACITY, 

197 FILTER_DRIVER, 

198 FILTER_IGNORE, 

199 FILTER_JSON, 

200 FILTER_RETRY, 

201 FILTER_REPLICATION, 

202 DRIVER_FAILED_EXTEND, 

203 FILTER_CREATE_FROM_SNAPSHOT, 

204 DRIVER_FAILED_CREATING_FROM_SNAP, 

205 DRIVER_REFUSED_SHRINK, 

206 DRIVER_FAILED_SHRINK, 

207 FORBIDDEN_CLIENT_ACCESS, 

208 UNSUPPORTED_CLIENT_ACCESS, 

209 UNSUPPORTED_ADD_UDPATE_SECURITY_SERVICE, 

210 SECURITY_SERVICE_FAILED_AUTH, 

211 NO_DEFAULT_SHARE_TYPE, 

212 MISSING_SECURITY_SERVICE, 

213 DRIVER_FAILED_TRANSFER_ACCEPT, 

214 SHARE_NETWORK_PORT_QUOTA_LIMIT_EXCEEDED, 

215 SHARE_BACKEND_NOT_READY_YET, 

216 UPDATE_METADATA_SUCCESS, 

217 UPDATE_METADATA_FAILURE, 

218 UPDATE_METADATA_NOT_DELETED, 

219 TARGETED_RESTORE_UNSUPPORTED, 

220 NEUTRON_SUBNET_FULL 

221 ) 

222 

223 # Exception and detail mappings 

224 EXCEPTION_DETAIL_MAPPINGS = { 

225 NO_VALID_HOST: ['NoValidHost'], 

226 } 

227 

228 # Use special code for each filter rather then categorize all as 

229 # NO_VALID_HOST 

230 FILTER_DETAIL_MAPPINGS = { 

231 'AvailabilityZoneFilter': FILTER_AVAILABILITY, 

232 'CapabilitiesFilter': FILTER_CAPABILITIES, 

233 'CapacityFilter': FILTER_CAPACITY, 

234 'DriverFilter': FILTER_DRIVER, 

235 'IgnoreAttemptedHostsFilter': FILTER_IGNORE, 

236 'JsonFilter': FILTER_JSON, 

237 'RetryFilter': FILTER_RETRY, 

238 'ShareReplicationFilter': FILTER_REPLICATION, 

239 'CreateFromSnapshotFilter': FILTER_CREATE_FROM_SNAPSHOT, 

240 } 

241 

242 

243def translate_action(action_id): 

244 action_message = next((action[1] for action in Action.ALL 

245 if action[0] == action_id), None) 

246 return action_message or 'unknown action' 

247 

248 

249def translate_detail(detail_id): 

250 detail_message = next((action[1] for action in Detail.ALL 

251 if action[0] == detail_id), None) 

252 return detail_message or Detail.UNKNOWN_ERROR[1] 

253 

254 

255def translate_detail_id(excep, detail): 

256 if excep is not None: 

257 detail = _translate_exception_to_detail(excep) 

258 if detail in Detail.ALL: 

259 return detail[0] 

260 return Detail.UNKNOWN_ERROR[0] 

261 

262 

263def _translate_exception_to_detail(ex): 

264 if isinstance(ex, exception.NoValidHost): 264 ↛ 272line 264 didn't jump to line 272 because the condition on line 264 was always true

265 # if NoValidHost was raised because a filter failed (a filter 

266 # didn't return any hosts), use a filter-specific detail 

267 details = getattr(ex, 'detail_data', {}) 

268 last_filter = details.get('last_filter') 

269 return Detail.FILTER_DETAIL_MAPPINGS.get( 

270 last_filter, Detail.NO_VALID_HOST) 

271 else: 

272 for key, value in Detail.EXCEPTION_DETAIL_MAPPINGS.items(): 

273 if ex.__class__.__name__ in value: 

274 return key