Coverage for manila/api/schemas/resource_locks.py: 100%
16 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« 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.
13from oslo_config import cfg
15from manila.api.validation import helpers
16from manila.api.validation import parameter_types
17from manila.api.validation import response_types
18from manila.common import constants
20CONF = cfg.CONF
22# TODO(stephenfin): Reject additional properties in a future microversion
23create_request_body = {
24 'type': 'object',
25 'properties': {
26 'resource_lock': {
27 'type': 'object',
28 'properties': {
29 'resource_id': {
30 'type': 'string',
31 'format': 'uuid',
32 'description': helpers.description(
33 'resource_lock_resource_id'
34 ),
35 },
36 'lock_reason': {
37 'type': ['string', 'null'],
38 'maxLength': 1023,
39 'description': helpers.description(
40 'resource_lock_lock_reason_optional'
41 ),
42 },
43 'resource_type': {
44 'type': ['string', 'null'],
45 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES)
46 + [None],
47 'default': constants.SHARE_RESOURCE_TYPE,
48 'description': helpers.description(
49 'resource_lock_resource_type'
50 ),
51 },
52 'resource_action': {
53 'type': ['string', 'null'],
54 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS)
55 + [None],
56 'default': constants.RESOURCE_ACTION_DELETE,
57 'description': helpers.description(
58 'resource_lock_resource_action_create_optional'
59 ),
60 },
61 },
62 'required': ['resource_id'],
63 'additionalProperties': False,
64 'description': helpers.description('resource_lock_object'),
65 },
66 },
67 'required': ['resource_lock'],
68 'additionalProperties': True,
69}
71update_request_body = {
72 'type': 'object',
73 'properties': {
74 'resource_lock': {
75 'type': 'object',
76 'properties': {
77 'resource_action': {
78 'type': ['string', 'null'],
79 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS)
80 + [None],
81 'description': helpers.description(
82 'resource_lock_resource_action_optional'
83 ),
84 },
85 'lock_reason': {
86 'type': ['string', 'null'],
87 'maxLength': 1023,
88 'description': helpers.description(
89 'resource_lock_lock_reason_optional'
90 ),
91 },
92 },
93 'additionalProperties': False,
94 'description': helpers.description('resource_lock_object'),
95 },
96 },
97 'required': ['resource_lock'],
98 'additionalProperties': True,
99}
101index_request_query = {
102 'type': 'object',
103 'properties': {
104 'limit': parameter_types.multi_params({
105 **parameter_types.non_negative_integer,
106 'description': helpers.description('limit'),
107 }),
108 # NOTE(stephenfin): This is parsed by 'common.get_pagination_params'
109 # but we ignore it. We may wish to uncomment this when that is no
110 # longer the case
111 # 'marker': parameter_types.multi_params({
112 # 'type': ['string'],
113 # }),
114 'offset': parameter_types.multi_params({
115 **parameter_types.non_negative_integer,
116 'description': helpers.description('offset'),
117 }),
118 'sort_key': parameter_types.multi_params({
119 'type': 'string',
120 'default': 'created_at',
121 'description': helpers.description('sort_key_resource_locks'),
122 }),
123 'sort_dir': parameter_types.multi_params({
124 'type': 'string',
125 'default': 'desc',
126 # TODO(stephenfin): This should be an enum, but we currently treat
127 # anything != 'desc' as 'asc'. We should make this stricter in a
128 # future microversion.
129 # 'enum': ['asc', 'desc'],
130 'description': helpers.description('sort_dir'),
131 }),
132 'with_count': parameter_types.multi_params(parameter_types.boolean),
133 'created_since': parameter_types.multi_params({
134 'type': 'string',
135 'format': 'date-time',
136 'description': helpers.description('created_since_query'),
137 }),
138 'created_before': parameter_types.multi_params({
139 'type': 'string',
140 'format': 'date-time',
141 'description': helpers.description('created_before_query'),
142 }),
143 'project_id': parameter_types.multi_params({
144 'type': ['string', 'null'],
145 'format': 'uuid',
146 'description': helpers.description(
147 'resource_lock_project_id_query'
148 ),
149 }),
150 'user_id': parameter_types.multi_params({
151 'type': ['string', 'null'],
152 'format': 'uuid',
153 'description': helpers.description('resource_lock_user_id_query'),
154 }),
155 'resource_id': parameter_types.multi_params({
156 'type': ['string', 'null'],
157 'format': 'uuid',
158 'description': helpers.description(
159 'resource_lock_resource_id_query'
160 ),
161 }),
162 'resource_action': parameter_types.multi_params({
163 'type': ['string', 'null'],
164 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS) + [None],
165 'description': helpers.description(
166 'resource_lock_resource_action_query'
167 ),
168 }),
169 'resource_type': parameter_types.multi_params({
170 'type': ['string', 'null'],
171 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES) + [None],
172 'description': helpers.description(
173 'resource_lock_resource_type_query'
174 ),
175 }),
176 'all_projects': parameter_types.multi_params({
177 **parameter_types.boolean,
178 'description': helpers.description(
179 'resource_lock_all_projects_query'
180 ),
181 }),
182 'lock_context': parameter_types.multi_params({
183 'type': ['string', 'null'],
184 'maxLength': 10,
185 'description': helpers.description(
186 'resource_lock_lock_context_query'
187 ),
188 }),
189 'lock_reason': parameter_types.multi_params({
190 'type': ['string', 'null'],
191 'maxLength': 1023,
192 'description': helpers.description(
193 'resource_lock_lock_reason_query'
194 ),
195 }),
196 },
197 # TODO(stephenfin): Exclude additional query string parameters in a future
198 # microversion
199 'additionalProperties': True,
200}
202show_request_query = {
203 'type': 'object',
204 'properties': {},
205 # TODO(stephenfin): Exclude additional query string parameters in a future
206 # microversion
207 'additionalProperties': True,
208}
210_resource_lock_response = {
211 'type': 'object',
212 'properties': {
213 'id': {
214 'type': 'string',
215 'format': 'uuid',
216 'description': helpers.description('resource_lock_id'),
217 },
218 'user_id': {
219 'type': 'string',
220 'format': 'uuid',
221 'description': helpers.description('resource_lock_user_id'),
222 },
223 'project_id': {
224 'type': 'string',
225 'format': 'uuid',
226 'description': helpers.description('resource_lock_project_id'),
227 },
228 'lock_context': {
229 'type': 'string',
230 'description': helpers.description('resource_lock_lock_context'),
231 },
232 'resource_type': {
233 'type': 'string',
234 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES),
235 'description': helpers.description('resource_lock_resource_type'),
236 },
237 'resource_id': {
238 'type': 'string',
239 'format': 'uuid',
240 'description': helpers.description('resource_lock_resource_id'),
241 },
242 'resource_action': {
243 'type': 'string',
244 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS),
245 'description': helpers.description(
246 'resource_lock_resource_action'
247 ),
248 },
249 'lock_reason': {
250 'type': ['string', 'null'],
251 'description': helpers.description('resource_lock_lock_reason'),
252 },
253 'created_at': {
254 'type': 'string',
255 'format': 'date-time',
256 'description': helpers.description('created_at'),
257 },
258 'updated_at': {
259 'type': ['string', 'null'],
260 'format': 'date-time',
261 'description': helpers.description('updated_at'),
262 },
263 'links': response_types.links,
264 },
265 'description': helpers.description('resource_lock_object'),
266 'required': [
267 'id',
268 'user_id',
269 'project_id',
270 'lock_context',
271 'resource_type',
272 'resource_id',
273 'resource_action',
274 'lock_reason',
275 'created_at',
276 'updated_at',
277 'links',
278 ],
279 'additionalProperties': False,
280}
282create_response_body = {
283 'type': 'object',
284 'properties': {
285 'resource_lock': _resource_lock_response,
286 },
287 'required': ['resource_lock'],
288 'additionalProperties': False,
289}
291index_response_body = {
292 'type': 'object',
293 'properties': {
294 'resource_locks': {
295 'type': 'array',
296 'items': _resource_lock_response,
297 },
298 'count': {
299 'type': 'integer',
300 'description': helpers.description('count_without_min_version'),
301 },
302 'resource_locks_links': response_types.collection_links,
303 },
304 'required': ['resource_locks'],
305 'additionalProperties': False,
306}
308show_response_body = {
309 'type': 'object',
310 'properties': {
311 'resource_lock': _resource_lock_response,
312 },
313 'required': ['resource_lock'],
314 'additionalProperties': False,
315}
317update_response_body = {
318 'type': 'object',
319 'properties': {
320 'resource_lock': _resource_lock_response,
321 },
322 'required': ['resource_lock'],
323 'additionalProperties': False,
324}
326delete_response_body = {
327 'type': 'null',
328}