python-openstackclient 6.1.0__py3-none-any.whl → 6.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openstackclient/common/project_cleanup.py +3 -5
- openstackclient/common/quota.py +4 -6
- openstackclient/compute/v2/host.py +44 -16
- openstackclient/compute/v2/server.py +18 -24
- openstackclient/compute/v2/server_migration.py +53 -29
- openstackclient/compute/v2/server_volume.py +35 -38
- openstackclient/compute/v2/service.py +5 -5
- openstackclient/identity/common.py +12 -0
- openstackclient/identity/v3/access_rule.py +8 -6
- openstackclient/image/v2/image.py +8 -2
- openstackclient/network/v2/floating_ip_port_forwarding.py +70 -32
- openstackclient/network/v2/network_service_provider.py +16 -10
- openstackclient/tests/functional/compute/v2/test_server.py +0 -3
- openstackclient/tests/unit/compute/v2/fakes.py +122 -207
- openstackclient/tests/unit/compute/v2/test_host.py +63 -42
- openstackclient/tests/unit/compute/v2/test_server.py +1 -2
- openstackclient/tests/unit/compute/v2/test_server_migration.py +92 -95
- openstackclient/tests/unit/compute/v2/test_server_volume.py +103 -83
- openstackclient/tests/unit/identity/v3/test_access_rule.py +11 -11
- openstackclient/tests/unit/network/v2/fakes.py +31 -7
- openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py +213 -18
- openstackclient/tests/unit/volume/v1/test_volume.py +48 -3
- openstackclient/tests/unit/volume/v2/test_consistency_group.py +2 -2
- openstackclient/tests/unit/volume/v2/test_volume.py +50 -3
- openstackclient/tests/unit/volume/v3/test_volume_group.py +47 -8
- openstackclient/volume/v1/volume.py +33 -4
- openstackclient/volume/v2/backup_record.py +8 -6
- openstackclient/volume/v2/consistency_group.py +32 -13
- openstackclient/volume/v2/volume.py +33 -4
- openstackclient/volume/v3/volume_group.py +91 -36
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/AUTHORS +5 -0
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/METADATA +1 -1
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/RECORD +38 -38
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/entry_points.txt +1 -0
- python_openstackclient-6.2.1.dist-info/pbr.json +1 -0
- python_openstackclient-6.1.0.dist-info/pbr.json +0 -1
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/LICENSE +0 -0
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/WHEEL +0 -0
- {python_openstackclient-6.1.0.dist-info → python_openstackclient-6.2.1.dist-info}/top_level.txt +0 -0
|
@@ -11,11 +11,15 @@
|
|
|
11
11
|
# under the License.
|
|
12
12
|
#
|
|
13
13
|
|
|
14
|
+
from unittest import mock
|
|
15
|
+
|
|
14
16
|
from novaclient import api_versions
|
|
17
|
+
from openstack import utils as sdk_utils
|
|
15
18
|
from osc_lib import exceptions
|
|
16
19
|
|
|
17
20
|
from openstackclient.compute.v2 import server_volume
|
|
18
21
|
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
|
22
|
+
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
|
19
23
|
|
|
20
24
|
|
|
21
25
|
class TestServerVolume(compute_fakes.TestComputev2):
|
|
@@ -23,13 +27,11 @@ class TestServerVolume(compute_fakes.TestComputev2):
|
|
|
23
27
|
def setUp(self):
|
|
24
28
|
super().setUp()
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
self.
|
|
28
|
-
self.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
self.servers_volumes_mock = self.app.client_manager.compute.volumes
|
|
32
|
-
self.servers_volumes_mock.reset_mock()
|
|
30
|
+
self.app.client_manager.sdk_connection = mock.Mock()
|
|
31
|
+
self.app.client_manager.sdk_connection.compute = mock.Mock()
|
|
32
|
+
self.app.client_manager.sdk_connection.volume = mock.Mock()
|
|
33
|
+
self.compute_client = self.app.client_manager.sdk_connection.compute
|
|
34
|
+
self.volume_client = self.app.client_manager.sdk_connection.volume
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
class TestServerVolumeList(TestServerVolume):
|
|
@@ -37,20 +39,21 @@ class TestServerVolumeList(TestServerVolume):
|
|
|
37
39
|
def setUp(self):
|
|
38
40
|
super().setUp()
|
|
39
41
|
|
|
40
|
-
self.server = compute_fakes.FakeServer.
|
|
41
|
-
self.volume_attachments = (
|
|
42
|
-
compute_fakes.FakeVolumeAttachment.create_volume_attachments())
|
|
42
|
+
self.server = compute_fakes.FakeServer.create_one_sdk_server()
|
|
43
|
+
self.volume_attachments = compute_fakes.create_volume_attachments()
|
|
43
44
|
|
|
44
|
-
self.
|
|
45
|
-
self.
|
|
45
|
+
self.compute_client.find_server.return_value = self.server
|
|
46
|
+
self.compute_client.volume_attachments.return_value = (
|
|
46
47
|
self.volume_attachments)
|
|
47
48
|
|
|
48
49
|
# Get the command object to test
|
|
49
50
|
self.cmd = server_volume.ListServerVolume(self.app, None)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
53
|
+
def test_server_volume_list(self, sm_mock):
|
|
52
54
|
self.app.client_manager.compute.api_version = \
|
|
53
55
|
api_versions.APIVersion('2.1')
|
|
56
|
+
sm_mock.side_effect = [False, False, False, False]
|
|
54
57
|
|
|
55
58
|
arglist = [
|
|
56
59
|
self.server.id,
|
|
@@ -68,24 +71,25 @@ class TestServerVolumeList(TestServerVolume):
|
|
|
68
71
|
(
|
|
69
72
|
self.volume_attachments[0].id,
|
|
70
73
|
self.volume_attachments[0].device,
|
|
71
|
-
self.volume_attachments[0].
|
|
72
|
-
self.volume_attachments[0].
|
|
74
|
+
self.volume_attachments[0].server_id,
|
|
75
|
+
self.volume_attachments[0].volume_id,
|
|
73
76
|
),
|
|
74
77
|
(
|
|
75
78
|
self.volume_attachments[1].id,
|
|
76
79
|
self.volume_attachments[1].device,
|
|
77
|
-
self.volume_attachments[1].
|
|
78
|
-
self.volume_attachments[1].
|
|
80
|
+
self.volume_attachments[1].server_id,
|
|
81
|
+
self.volume_attachments[1].volume_id,
|
|
79
82
|
),
|
|
80
83
|
),
|
|
81
84
|
tuple(data),
|
|
82
85
|
)
|
|
83
|
-
self.
|
|
84
|
-
self.server
|
|
86
|
+
self.compute_client.volume_attachments.assert_called_once_with(
|
|
87
|
+
self.server,
|
|
88
|
+
)
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
91
|
+
def test_server_volume_list_with_tags(self, sm_mock):
|
|
92
|
+
sm_mock.side_effect = [False, True, False, False]
|
|
89
93
|
|
|
90
94
|
arglist = [
|
|
91
95
|
self.server.id,
|
|
@@ -105,27 +109,27 @@ class TestServerVolumeList(TestServerVolume):
|
|
|
105
109
|
(
|
|
106
110
|
self.volume_attachments[0].id,
|
|
107
111
|
self.volume_attachments[0].device,
|
|
108
|
-
self.volume_attachments[0].
|
|
109
|
-
self.volume_attachments[0].
|
|
112
|
+
self.volume_attachments[0].server_id,
|
|
113
|
+
self.volume_attachments[0].volume_id,
|
|
110
114
|
self.volume_attachments[0].tag,
|
|
111
115
|
),
|
|
112
116
|
(
|
|
113
117
|
self.volume_attachments[1].id,
|
|
114
118
|
self.volume_attachments[1].device,
|
|
115
|
-
self.volume_attachments[1].
|
|
116
|
-
self.volume_attachments[1].
|
|
119
|
+
self.volume_attachments[1].server_id,
|
|
120
|
+
self.volume_attachments[1].volume_id,
|
|
117
121
|
self.volume_attachments[1].tag,
|
|
118
122
|
),
|
|
119
123
|
),
|
|
120
124
|
tuple(data),
|
|
121
125
|
)
|
|
122
|
-
self.
|
|
123
|
-
self.server
|
|
124
|
-
|
|
125
|
-
def test_server_volume_list_with_delete_on_attachment(self):
|
|
126
|
-
self.app.client_manager.compute.api_version = \
|
|
127
|
-
api_versions.APIVersion('2.79')
|
|
126
|
+
self.compute_client.volume_attachments.assert_called_once_with(
|
|
127
|
+
self.server,
|
|
128
|
+
)
|
|
128
129
|
|
|
130
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
131
|
+
def test_server_volume_list_with_delete_on_attachment(self, sm_mock):
|
|
132
|
+
sm_mock.side_effect = [False, True, True, False]
|
|
129
133
|
arglist = [
|
|
130
134
|
self.server.id,
|
|
131
135
|
]
|
|
@@ -148,29 +152,30 @@ class TestServerVolumeList(TestServerVolume):
|
|
|
148
152
|
(
|
|
149
153
|
self.volume_attachments[0].id,
|
|
150
154
|
self.volume_attachments[0].device,
|
|
151
|
-
self.volume_attachments[0].
|
|
152
|
-
self.volume_attachments[0].
|
|
155
|
+
self.volume_attachments[0].server_id,
|
|
156
|
+
self.volume_attachments[0].volume_id,
|
|
153
157
|
self.volume_attachments[0].tag,
|
|
154
158
|
self.volume_attachments[0].delete_on_termination,
|
|
155
159
|
),
|
|
156
160
|
(
|
|
157
161
|
self.volume_attachments[1].id,
|
|
158
162
|
self.volume_attachments[1].device,
|
|
159
|
-
self.volume_attachments[1].
|
|
160
|
-
self.volume_attachments[1].
|
|
163
|
+
self.volume_attachments[1].server_id,
|
|
164
|
+
self.volume_attachments[1].volume_id,
|
|
161
165
|
self.volume_attachments[1].tag,
|
|
162
166
|
self.volume_attachments[1].delete_on_termination,
|
|
163
167
|
),
|
|
164
168
|
),
|
|
165
169
|
tuple(data),
|
|
166
170
|
)
|
|
167
|
-
self.
|
|
168
|
-
self.server
|
|
171
|
+
self.compute_client.volume_attachments.assert_called_once_with(
|
|
172
|
+
self.server,
|
|
173
|
+
)
|
|
169
174
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
api_versions.APIVersion('2.89')
|
|
175
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
176
|
+
def test_server_volume_list_with_attachment_ids(self, sm_mock):
|
|
173
177
|
|
|
178
|
+
sm_mock.side_effect = [True, True, True, True]
|
|
174
179
|
arglist = [
|
|
175
180
|
self.server.id,
|
|
176
181
|
]
|
|
@@ -193,28 +198,29 @@ class TestServerVolumeList(TestServerVolume):
|
|
|
193
198
|
(
|
|
194
199
|
(
|
|
195
200
|
self.volume_attachments[0].device,
|
|
196
|
-
self.volume_attachments[0].
|
|
197
|
-
self.volume_attachments[0].
|
|
201
|
+
self.volume_attachments[0].server_id,
|
|
202
|
+
self.volume_attachments[0].volume_id,
|
|
198
203
|
self.volume_attachments[0].tag,
|
|
199
204
|
self.volume_attachments[0].delete_on_termination,
|
|
200
205
|
self.volume_attachments[0].attachment_id,
|
|
201
|
-
self.volume_attachments[0].
|
|
206
|
+
self.volume_attachments[0].bdm_id
|
|
202
207
|
|
|
203
208
|
),
|
|
204
209
|
(
|
|
205
210
|
self.volume_attachments[1].device,
|
|
206
|
-
self.volume_attachments[1].
|
|
207
|
-
self.volume_attachments[1].
|
|
211
|
+
self.volume_attachments[1].server_id,
|
|
212
|
+
self.volume_attachments[1].volume_id,
|
|
208
213
|
self.volume_attachments[1].tag,
|
|
209
214
|
self.volume_attachments[1].delete_on_termination,
|
|
210
215
|
self.volume_attachments[1].attachment_id,
|
|
211
|
-
self.volume_attachments[1].
|
|
216
|
+
self.volume_attachments[1].bdm_id
|
|
212
217
|
),
|
|
213
218
|
),
|
|
214
219
|
tuple(data),
|
|
215
220
|
)
|
|
216
|
-
self.
|
|
217
|
-
self.server
|
|
221
|
+
self.compute_client.volume_attachments.assert_called_once_with(
|
|
222
|
+
self.server,
|
|
223
|
+
)
|
|
218
224
|
|
|
219
225
|
|
|
220
226
|
class TestServerVolumeUpdate(TestServerVolume):
|
|
@@ -222,21 +228,23 @@ class TestServerVolumeUpdate(TestServerVolume):
|
|
|
222
228
|
def setUp(self):
|
|
223
229
|
super().setUp()
|
|
224
230
|
|
|
225
|
-
self.server = compute_fakes.FakeServer.
|
|
226
|
-
self.
|
|
231
|
+
self.server = compute_fakes.FakeServer.create_one_sdk_server()
|
|
232
|
+
self.compute_client.find_server.return_value = self.server
|
|
233
|
+
|
|
234
|
+
self.volume = volume_fakes.create_one_sdk_volume()
|
|
235
|
+
self.volume_client.find_volume.return_value = self.volume
|
|
227
236
|
|
|
228
237
|
# Get the command object to test
|
|
229
238
|
self.cmd = server_volume.UpdateServerVolume(self.app, None)
|
|
230
239
|
|
|
231
240
|
def test_server_volume_update(self):
|
|
232
|
-
|
|
233
241
|
arglist = [
|
|
234
242
|
self.server.id,
|
|
235
|
-
|
|
243
|
+
self.volume.id,
|
|
236
244
|
]
|
|
237
245
|
verifylist = [
|
|
238
246
|
('server', self.server.id),
|
|
239
|
-
('volume',
|
|
247
|
+
('volume', self.volume.id),
|
|
240
248
|
('delete_on_termination', None),
|
|
241
249
|
]
|
|
242
250
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
@@ -244,67 +252,73 @@ class TestServerVolumeUpdate(TestServerVolume):
|
|
|
244
252
|
result = self.cmd.take_action(parsed_args)
|
|
245
253
|
|
|
246
254
|
# This is a no-op
|
|
247
|
-
self.
|
|
255
|
+
self.compute_client.update_volume_attachment.assert_not_called()
|
|
248
256
|
self.assertIsNone(result)
|
|
249
257
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
258
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
259
|
+
def test_server_volume_update_with_delete_on_termination(self, sm_mock):
|
|
260
|
+
sm_mock.return_value = True
|
|
253
261
|
|
|
254
262
|
arglist = [
|
|
255
263
|
self.server.id,
|
|
256
|
-
|
|
264
|
+
self.volume.id,
|
|
257
265
|
'--delete-on-termination',
|
|
258
266
|
]
|
|
259
267
|
verifylist = [
|
|
260
268
|
('server', self.server.id),
|
|
261
|
-
('volume',
|
|
269
|
+
('volume', self.volume.id),
|
|
262
270
|
('delete_on_termination', True),
|
|
263
271
|
]
|
|
264
272
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
265
273
|
|
|
266
274
|
result = self.cmd.take_action(parsed_args)
|
|
267
275
|
|
|
268
|
-
self.
|
|
269
|
-
self.server
|
|
270
|
-
|
|
276
|
+
self.compute_client.update_volume_attachment.assert_called_once_with(
|
|
277
|
+
self.server,
|
|
278
|
+
self.volume,
|
|
279
|
+
delete_on_termination=True,
|
|
280
|
+
)
|
|
271
281
|
self.assertIsNone(result)
|
|
272
282
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
283
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
284
|
+
def test_server_volume_update_with_preserve_on_termination(self, sm_mock):
|
|
285
|
+
sm_mock.return_value = True
|
|
276
286
|
|
|
277
287
|
arglist = [
|
|
278
288
|
self.server.id,
|
|
279
|
-
|
|
289
|
+
self.volume.id,
|
|
280
290
|
'--preserve-on-termination',
|
|
281
291
|
]
|
|
282
292
|
verifylist = [
|
|
283
293
|
('server', self.server.id),
|
|
284
|
-
('volume',
|
|
294
|
+
('volume', self.volume.id),
|
|
285
295
|
('delete_on_termination', False),
|
|
286
296
|
]
|
|
287
297
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
288
298
|
|
|
289
299
|
result = self.cmd.take_action(parsed_args)
|
|
290
300
|
|
|
291
|
-
self.
|
|
292
|
-
self.server
|
|
293
|
-
|
|
301
|
+
self.compute_client.update_volume_attachment.assert_called_once_with(
|
|
302
|
+
self.server,
|
|
303
|
+
self.volume,
|
|
304
|
+
delete_on_termination=False
|
|
305
|
+
)
|
|
294
306
|
self.assertIsNone(result)
|
|
295
307
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
308
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
309
|
+
def test_server_volume_update_with_delete_on_termination_pre_v285(
|
|
310
|
+
self, sm_mock,
|
|
311
|
+
):
|
|
312
|
+
sm_mock.return_value = False
|
|
299
313
|
|
|
300
314
|
arglist = [
|
|
301
315
|
self.server.id,
|
|
302
|
-
|
|
316
|
+
self.volume.id,
|
|
303
317
|
'--delete-on-termination',
|
|
304
318
|
]
|
|
305
319
|
verifylist = [
|
|
306
320
|
('server', self.server.id),
|
|
307
|
-
('volume',
|
|
321
|
+
('volume', self.volume.id),
|
|
308
322
|
('delete_on_termination', True),
|
|
309
323
|
]
|
|
310
324
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
@@ -312,20 +326,24 @@ class TestServerVolumeUpdate(TestServerVolume):
|
|
|
312
326
|
self.assertRaises(
|
|
313
327
|
exceptions.CommandError,
|
|
314
328
|
self.cmd.take_action,
|
|
315
|
-
parsed_args
|
|
329
|
+
parsed_args,
|
|
330
|
+
)
|
|
331
|
+
self.compute_client.update_volume_attachment.assert_not_called()
|
|
316
332
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
333
|
+
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
334
|
+
def test_server_volume_update_with_preserve_on_termination_pre_v285(
|
|
335
|
+
self, sm_mock,
|
|
336
|
+
):
|
|
337
|
+
sm_mock.return_value = False
|
|
320
338
|
|
|
321
339
|
arglist = [
|
|
322
340
|
self.server.id,
|
|
323
|
-
|
|
341
|
+
self.volume.id,
|
|
324
342
|
'--preserve-on-termination',
|
|
325
343
|
]
|
|
326
344
|
verifylist = [
|
|
327
345
|
('server', self.server.id),
|
|
328
|
-
('volume',
|
|
346
|
+
('volume', self.volume.id),
|
|
329
347
|
('delete_on_termination', False),
|
|
330
348
|
]
|
|
331
349
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
@@ -333,4 +351,6 @@ class TestServerVolumeUpdate(TestServerVolume):
|
|
|
333
351
|
self.assertRaises(
|
|
334
352
|
exceptions.CommandError,
|
|
335
353
|
self.cmd.take_action,
|
|
336
|
-
parsed_args
|
|
354
|
+
parsed_args,
|
|
355
|
+
)
|
|
356
|
+
self.compute_client.update_volume_attachment.assert_not_called()
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
#
|
|
15
15
|
|
|
16
16
|
import copy
|
|
17
|
-
from unittest import mock
|
|
18
17
|
|
|
18
|
+
from keystoneclient import exceptions as identity_exc
|
|
19
19
|
from osc_lib import exceptions
|
|
20
|
-
from osc_lib import utils
|
|
21
20
|
|
|
22
21
|
from openstackclient.identity.v3 import access_rule
|
|
23
22
|
from openstackclient.tests.unit import fakes
|
|
@@ -69,10 +68,13 @@ class TestAccessRuleDelete(TestAccessRule):
|
|
|
69
68
|
)
|
|
70
69
|
self.assertIsNone(result)
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
def test_delete_multi_access_rules_with_exception(self):
|
|
72
|
+
# mock returns for common.get_resource_by_id
|
|
73
|
+
mock_get = self.access_rules_mock.get
|
|
74
|
+
mock_get.side_effect = [
|
|
75
|
+
mock_get.return_value,
|
|
76
|
+
identity_exc.NotFound,
|
|
77
|
+
]
|
|
76
78
|
arglist = [
|
|
77
79
|
identity_fakes.access_rule_id,
|
|
78
80
|
'nonexistent_access_rule',
|
|
@@ -89,12 +91,10 @@ class TestAccessRuleDelete(TestAccessRule):
|
|
|
89
91
|
self.assertEqual('1 of 2 access rules failed to'
|
|
90
92
|
' delete.', str(e))
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
find_mock.assert_any_call(self.access_rules_mock,
|
|
95
|
-
'nonexistent_access_rule')
|
|
94
|
+
mock_get.assert_any_call(identity_fakes.access_rule_id)
|
|
95
|
+
mock_get.assert_any_call('nonexistent_access_rule')
|
|
96
96
|
|
|
97
|
-
self.assertEqual(2,
|
|
97
|
+
self.assertEqual(2, mock_get.call_count)
|
|
98
98
|
self.access_rules_mock.delete.assert_called_once_with(
|
|
99
99
|
identity_fakes.access_rule_id)
|
|
100
100
|
|
|
@@ -1066,11 +1066,13 @@ class FakeFloatingIPPortForwarding(object):
|
|
|
1066
1066
|
""""Fake one or more Port forwarding"""
|
|
1067
1067
|
|
|
1068
1068
|
@staticmethod
|
|
1069
|
-
def create_one_port_forwarding(attrs=None):
|
|
1069
|
+
def create_one_port_forwarding(attrs=None, use_range=False):
|
|
1070
1070
|
"""Create a fake Port Forwarding.
|
|
1071
1071
|
|
|
1072
1072
|
:param Dictionary attrs:
|
|
1073
1073
|
A dictionary with all attributes
|
|
1074
|
+
:param Boolean use_range:
|
|
1075
|
+
A boolean which defines if we will use ranges or not
|
|
1074
1076
|
:return:
|
|
1075
1077
|
A FakeResource object with name, id, etc.
|
|
1076
1078
|
"""
|
|
@@ -1084,13 +1086,29 @@ class FakeFloatingIPPortForwarding(object):
|
|
|
1084
1086
|
'floatingip_id': floatingip_id,
|
|
1085
1087
|
'internal_port_id': 'internal-port-id-' + uuid.uuid4().hex,
|
|
1086
1088
|
'internal_ip_address': '192.168.1.2',
|
|
1087
|
-
'internal_port': randint(1, 65535),
|
|
1088
|
-
'external_port': randint(1, 65535),
|
|
1089
1089
|
'protocol': 'tcp',
|
|
1090
1090
|
'description': 'some description',
|
|
1091
1091
|
'location': 'MUNCHMUNCHMUNCH',
|
|
1092
1092
|
}
|
|
1093
1093
|
|
|
1094
|
+
if use_range:
|
|
1095
|
+
port_range = randint(0, 100)
|
|
1096
|
+
internal_start = randint(1, 65535 - port_range)
|
|
1097
|
+
internal_end = internal_start + port_range
|
|
1098
|
+
internal_range = ':'.join(map(str, [internal_start, internal_end]))
|
|
1099
|
+
external_start = randint(1, 65535 - port_range)
|
|
1100
|
+
external_end = external_start + port_range
|
|
1101
|
+
external_range = ':'.join(map(str, [external_start, external_end]))
|
|
1102
|
+
port_forwarding_attrs['internal_port_range'] = internal_range
|
|
1103
|
+
port_forwarding_attrs['external_port_range'] = external_range
|
|
1104
|
+
port_forwarding_attrs['internal_port'] = None
|
|
1105
|
+
port_forwarding_attrs['external_port'] = None
|
|
1106
|
+
else:
|
|
1107
|
+
port_forwarding_attrs['internal_port'] = randint(1, 65535)
|
|
1108
|
+
port_forwarding_attrs['external_port'] = randint(1, 65535)
|
|
1109
|
+
port_forwarding_attrs['internal_port_range'] = ''
|
|
1110
|
+
port_forwarding_attrs['external_port_range'] = ''
|
|
1111
|
+
|
|
1094
1112
|
# Overwrite default attributes.
|
|
1095
1113
|
port_forwarding_attrs.update(attrs)
|
|
1096
1114
|
|
|
@@ -1101,25 +1119,28 @@ class FakeFloatingIPPortForwarding(object):
|
|
|
1101
1119
|
return port_forwarding
|
|
1102
1120
|
|
|
1103
1121
|
@staticmethod
|
|
1104
|
-
def create_port_forwardings(attrs=None, count=2):
|
|
1122
|
+
def create_port_forwardings(attrs=None, count=2, use_range=False):
|
|
1105
1123
|
"""Create multiple fake Port Forwarding.
|
|
1106
1124
|
|
|
1107
1125
|
:param Dictionary attrs:
|
|
1108
1126
|
A dictionary with all attributes
|
|
1109
1127
|
:param int count:
|
|
1110
1128
|
The number of Port Forwarding rule to fake
|
|
1129
|
+
:param Boolean use_range:
|
|
1130
|
+
A boolean which defines if we will use ranges or not
|
|
1111
1131
|
:return:
|
|
1112
1132
|
A list of FakeResource objects faking the Port Forwardings
|
|
1113
1133
|
"""
|
|
1114
1134
|
port_forwardings = []
|
|
1115
1135
|
for i in range(0, count):
|
|
1116
1136
|
port_forwardings.append(
|
|
1117
|
-
FakeFloatingIPPortForwarding.create_one_port_forwarding(
|
|
1137
|
+
FakeFloatingIPPortForwarding.create_one_port_forwarding(
|
|
1138
|
+
attrs, use_range=use_range)
|
|
1118
1139
|
)
|
|
1119
1140
|
return port_forwardings
|
|
1120
1141
|
|
|
1121
1142
|
@staticmethod
|
|
1122
|
-
def get_port_forwardings(port_forwardings=None, count=2):
|
|
1143
|
+
def get_port_forwardings(port_forwardings=None, count=2, use_range=False):
|
|
1123
1144
|
"""Get a list of faked Port Forwardings.
|
|
1124
1145
|
|
|
1125
1146
|
If port forwardings list is provided, then initialize the Mock object
|
|
@@ -1129,13 +1150,16 @@ class FakeFloatingIPPortForwarding(object):
|
|
|
1129
1150
|
A list of FakeResource objects faking port forwardings
|
|
1130
1151
|
:param int count:
|
|
1131
1152
|
The number of Port Forwardings to fake
|
|
1153
|
+
:param Boolean use_range:
|
|
1154
|
+
A boolean which defines if we will use ranges or not
|
|
1132
1155
|
:return:
|
|
1133
1156
|
An iterable Mock object with side_effect set to a list of faked
|
|
1134
1157
|
Port Forwardings
|
|
1135
1158
|
"""
|
|
1136
1159
|
if port_forwardings is None:
|
|
1137
1160
|
port_forwardings = (
|
|
1138
|
-
FakeFloatingIPPortForwarding.create_port_forwardings(
|
|
1161
|
+
FakeFloatingIPPortForwarding.create_port_forwardings(
|
|
1162
|
+
count, use_range=use_range)
|
|
1139
1163
|
)
|
|
1140
1164
|
|
|
1141
1165
|
return mock.Mock(side_effect=port_forwardings)
|