datacrunch 1.14.0__py3-none-any.whl → 1.16.0__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.
- datacrunch/InferenceClient/inference_client.py +200 -65
- datacrunch/__init__.py +2 -0
- datacrunch/_version.py +6 -0
- datacrunch/authentication/authentication.py +7 -14
- datacrunch/balance/balance.py +1 -3
- datacrunch/constants.py +19 -17
- datacrunch/containers/containers.py +151 -123
- datacrunch/datacrunch.py +18 -18
- datacrunch/helpers.py +7 -2
- datacrunch/http_client/http_client.py +14 -14
- datacrunch/images/images.py +9 -3
- datacrunch/instance_types/instance_types.py +42 -35
- datacrunch/instances/instances.py +74 -53
- datacrunch/locations/locations.py +1 -2
- datacrunch/ssh_keys/ssh_keys.py +3 -4
- datacrunch/startup_scripts/startup_scripts.py +10 -8
- datacrunch/volume_types/volume_types.py +10 -8
- datacrunch/volumes/volumes.py +60 -73
- {datacrunch-1.14.0.dist-info → datacrunch-1.16.0.dist-info}/METADATA +46 -72
- datacrunch-1.16.0.dist-info/RECORD +35 -0
- datacrunch-1.16.0.dist-info/WHEEL +4 -0
- datacrunch/__version__.py +0 -1
- datacrunch-1.14.0.dist-info/RECORD +0 -69
- datacrunch-1.14.0.dist-info/WHEEL +0 -5
- datacrunch-1.14.0.dist-info/licenses/LICENSE +0 -21
- datacrunch-1.14.0.dist-info/top_level.txt +0 -2
- tests/__init__.py +0 -0
- tests/integration_tests/__init__.py +0 -0
- tests/integration_tests/conftest.py +0 -20
- tests/integration_tests/test_instances.py +0 -36
- tests/integration_tests/test_locations.py +0 -65
- tests/integration_tests/test_volumes.py +0 -94
- tests/unit_tests/__init__.py +0 -0
- tests/unit_tests/authentication/__init__.py +0 -0
- tests/unit_tests/authentication/test_authentication.py +0 -202
- tests/unit_tests/balance/__init__.py +0 -0
- tests/unit_tests/balance/test_balance.py +0 -25
- tests/unit_tests/conftest.py +0 -21
- tests/unit_tests/containers/__init__.py +0 -1
- tests/unit_tests/containers/test_containers.py +0 -959
- tests/unit_tests/http_client/__init__.py +0 -0
- tests/unit_tests/http_client/test_http_client.py +0 -193
- tests/unit_tests/images/__init__.py +0 -0
- tests/unit_tests/images/test_images.py +0 -41
- tests/unit_tests/instance_types/__init__.py +0 -0
- tests/unit_tests/instance_types/test_instance_types.py +0 -87
- tests/unit_tests/instances/__init__.py +0 -0
- tests/unit_tests/instances/test_instances.py +0 -483
- tests/unit_tests/ssh_keys/__init__.py +0 -0
- tests/unit_tests/ssh_keys/test_ssh_keys.py +0 -198
- tests/unit_tests/startup_scripts/__init__.py +0 -0
- tests/unit_tests/startup_scripts/test_startup_scripts.py +0 -196
- tests/unit_tests/test_datacrunch.py +0 -65
- tests/unit_tests/test_exceptions.py +0 -33
- tests/unit_tests/volume_types/__init__.py +0 -0
- tests/unit_tests/volume_types/test_volume_types.py +0 -50
- tests/unit_tests/volumes/__init__.py +0 -0
- tests/unit_tests/volumes/test_volumes.py +0 -641
|
@@ -1,641 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
import responses # https://github.com/getsentry/responses
|
|
3
|
-
|
|
4
|
-
from datacrunch.exceptions import APIException
|
|
5
|
-
from datacrunch.volumes.volumes import VolumesService, Volume
|
|
6
|
-
from datacrunch.constants import VolumeStatus, VolumeTypes, VolumeActions, ErrorCodes, Locations
|
|
7
|
-
|
|
8
|
-
INVALID_REQUEST = ErrorCodes.INVALID_REQUEST
|
|
9
|
-
INVALID_REQUEST_MESSAGE = 'Your existence is invalid'
|
|
10
|
-
|
|
11
|
-
INSTANCE_ID = "4fee633c-b119-4447-af9c-70ba17675fc5"
|
|
12
|
-
|
|
13
|
-
NVME = "NVMe"
|
|
14
|
-
HDD = "HDD"
|
|
15
|
-
TARGET_VDA = "vda"
|
|
16
|
-
SSH_KEY_ID = '12345dc1-a5d2-4972-ae4e-d429115d055b'
|
|
17
|
-
|
|
18
|
-
NVME_VOL_ID = "cf995e26-ce69-4149-84a3-cdd1e100670f"
|
|
19
|
-
NVME_VOL_STATUS = VolumeStatus.ATTACHED
|
|
20
|
-
NVME_VOL_NAME = "Volume-nxC2tf9F"
|
|
21
|
-
NVME_VOL_SIZE = 50
|
|
22
|
-
NVME_VOL_CREATED_AT = "2021-06-02T12:56:49.582Z"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
HDD_VOL_ID = "ea4edc62-9838-4b7c-bd5b-862f2efec675"
|
|
26
|
-
HDD_VOL_STATUS = VolumeStatus.DETACHED
|
|
27
|
-
HDD_VOL_NAME = "Volume-iHdL4ysR"
|
|
28
|
-
HDD_VOL_SIZE = 100
|
|
29
|
-
HDD_VOL_CREATED_AT = "2021-06-02T12:56:49.582Z"
|
|
30
|
-
|
|
31
|
-
RANDOM_VOL_ID = '07d864ee-ba86-451e-85b3-34ef551bd4a2'
|
|
32
|
-
RANDOM_VOL2_ID = '72c5c082-7fe7-4d13-bd9e-f529c97d63b3'
|
|
33
|
-
|
|
34
|
-
NVME_VOLUME = {
|
|
35
|
-
"id": NVME_VOL_ID,
|
|
36
|
-
"status": NVME_VOL_STATUS,
|
|
37
|
-
"instance_id": INSTANCE_ID,
|
|
38
|
-
"name": NVME_VOL_NAME,
|
|
39
|
-
"size": NVME_VOL_SIZE,
|
|
40
|
-
"type": NVME,
|
|
41
|
-
"location": Locations.FIN_01,
|
|
42
|
-
"is_os_volume": True,
|
|
43
|
-
"created_at": NVME_VOL_CREATED_AT,
|
|
44
|
-
"target": TARGET_VDA,
|
|
45
|
-
"ssh_key_ids": SSH_KEY_ID
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
HDD_VOLUME = {
|
|
49
|
-
"id": HDD_VOL_ID,
|
|
50
|
-
"status": HDD_VOL_STATUS,
|
|
51
|
-
"instance_id": None,
|
|
52
|
-
"name": HDD_VOL_NAME,
|
|
53
|
-
"size": HDD_VOL_SIZE,
|
|
54
|
-
"type": HDD,
|
|
55
|
-
"location": Locations.FIN_01,
|
|
56
|
-
"is_os_volume": False,
|
|
57
|
-
"created_at": HDD_VOL_CREATED_AT,
|
|
58
|
-
"target": None,
|
|
59
|
-
"ssh_key_ids": []
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
PAYLOAD = [NVME_VOLUME, HDD_VOLUME]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class TestVolumesService:
|
|
66
|
-
@pytest.fixture
|
|
67
|
-
def volumes_service(self, http_client):
|
|
68
|
-
return VolumesService(http_client)
|
|
69
|
-
|
|
70
|
-
@pytest.fixture
|
|
71
|
-
def endpoint(self, http_client):
|
|
72
|
-
return http_client._base_url + "/volumes"
|
|
73
|
-
|
|
74
|
-
def test_initialize_a_volume(self):
|
|
75
|
-
volume = Volume(RANDOM_VOL_ID, VolumeStatus.DETACHED, HDD_VOL_NAME, HDD_VOL_SIZE,
|
|
76
|
-
HDD, False, HDD_VOL_CREATED_AT)
|
|
77
|
-
|
|
78
|
-
assert volume.id == RANDOM_VOL_ID
|
|
79
|
-
assert volume.status == VolumeStatus.DETACHED
|
|
80
|
-
assert volume.instance_id == None
|
|
81
|
-
assert volume.name == HDD_VOL_NAME
|
|
82
|
-
assert volume.size == HDD_VOL_SIZE
|
|
83
|
-
assert volume.type == HDD
|
|
84
|
-
assert volume.location == Locations.FIN_01
|
|
85
|
-
assert volume.is_os_volume == False
|
|
86
|
-
assert volume.created_at == HDD_VOL_CREATED_AT
|
|
87
|
-
assert volume.target == None
|
|
88
|
-
assert volume.ssh_key_ids == []
|
|
89
|
-
|
|
90
|
-
def test_get_volumes(self, volumes_service, endpoint):
|
|
91
|
-
# arrange - add response mock
|
|
92
|
-
responses.add(
|
|
93
|
-
responses.GET,
|
|
94
|
-
endpoint,
|
|
95
|
-
json=PAYLOAD,
|
|
96
|
-
status=200
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# act
|
|
100
|
-
volumes = volumes_service.get()
|
|
101
|
-
volume_nvme = volumes[0]
|
|
102
|
-
volume_hdd = volumes[1]
|
|
103
|
-
|
|
104
|
-
# assert
|
|
105
|
-
assert type(volumes) == list
|
|
106
|
-
assert len(volumes) == 2
|
|
107
|
-
assert type(volume_nvme) == Volume
|
|
108
|
-
assert type(volume_hdd) == Volume
|
|
109
|
-
assert volume_nvme.id == NVME_VOL_ID
|
|
110
|
-
assert volume_nvme.status == NVME_VOL_STATUS
|
|
111
|
-
assert volume_nvme.instance_id == INSTANCE_ID
|
|
112
|
-
assert volume_nvme.name == NVME_VOL_NAME
|
|
113
|
-
assert volume_nvme.size == NVME_VOL_SIZE
|
|
114
|
-
assert volume_nvme.type == NVME
|
|
115
|
-
assert volume_nvme.location == Locations.FIN_01
|
|
116
|
-
assert volume_nvme.is_os_volume
|
|
117
|
-
assert volume_nvme.created_at == NVME_VOL_CREATED_AT
|
|
118
|
-
assert volume_nvme.target == TARGET_VDA
|
|
119
|
-
assert volume_nvme.ssh_key_ids == SSH_KEY_ID
|
|
120
|
-
|
|
121
|
-
assert volume_hdd.id == HDD_VOL_ID
|
|
122
|
-
assert volume_hdd.status == HDD_VOL_STATUS
|
|
123
|
-
assert volume_hdd.instance_id is None
|
|
124
|
-
assert volume_hdd.name == HDD_VOL_NAME
|
|
125
|
-
assert volume_hdd.size == HDD_VOL_SIZE
|
|
126
|
-
assert volume_hdd.type == HDD
|
|
127
|
-
assert volume_hdd.location == Locations.FIN_01
|
|
128
|
-
assert volume_hdd.is_os_volume is False
|
|
129
|
-
assert volume_hdd.created_at == HDD_VOL_CREATED_AT
|
|
130
|
-
assert volume_hdd.target is None
|
|
131
|
-
assert volume_hdd.ssh_key_ids == []
|
|
132
|
-
|
|
133
|
-
def test_get_volumes_by_status_successful(self, volumes_service, endpoint):
|
|
134
|
-
# arrange - add response mock
|
|
135
|
-
responses.add(
|
|
136
|
-
responses.GET,
|
|
137
|
-
endpoint + "?status=" + VolumeStatus.ATTACHED,
|
|
138
|
-
json=[NVME_VOLUME],
|
|
139
|
-
status=200
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
# act
|
|
143
|
-
volumes = volumes_service.get(status=VolumeStatus.ATTACHED)
|
|
144
|
-
volume_nvme = volumes[0]
|
|
145
|
-
|
|
146
|
-
# assert
|
|
147
|
-
assert type(volumes) == list
|
|
148
|
-
assert len(volumes) == 1
|
|
149
|
-
assert type(volume_nvme) == Volume
|
|
150
|
-
assert volume_nvme.id == NVME_VOL_ID
|
|
151
|
-
assert volume_nvme.status == NVME_VOL_STATUS
|
|
152
|
-
assert volume_nvme.instance_id == INSTANCE_ID
|
|
153
|
-
assert volume_nvme.name == NVME_VOL_NAME
|
|
154
|
-
assert volume_nvme.size == NVME_VOL_SIZE
|
|
155
|
-
assert volume_nvme.type == NVME
|
|
156
|
-
assert volume_nvme.location == Locations.FIN_01
|
|
157
|
-
assert volume_nvme.is_os_volume
|
|
158
|
-
assert volume_nvme.created_at == NVME_VOL_CREATED_AT
|
|
159
|
-
assert volume_nvme.target == TARGET_VDA
|
|
160
|
-
|
|
161
|
-
def test_get_volumes_by_status_failed(self, volumes_service, endpoint):
|
|
162
|
-
url = endpoint + "?status=flummoxed"
|
|
163
|
-
responses.add(
|
|
164
|
-
responses.GET,
|
|
165
|
-
url,
|
|
166
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
167
|
-
status=400
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
# act
|
|
171
|
-
with pytest.raises(APIException) as excinfo:
|
|
172
|
-
volumes_service.get(status='flummoxed')
|
|
173
|
-
|
|
174
|
-
# assert
|
|
175
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
176
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
177
|
-
assert responses.assert_call_count(url, 1) is True
|
|
178
|
-
|
|
179
|
-
def test_get_volume_by_id_successful(self, volumes_service, endpoint):
|
|
180
|
-
# arrange - add response mock
|
|
181
|
-
url = endpoint + "/" + NVME_VOL_ID
|
|
182
|
-
responses.add(
|
|
183
|
-
responses.GET,
|
|
184
|
-
url,
|
|
185
|
-
json=NVME_VOLUME,
|
|
186
|
-
status=200
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
# act
|
|
190
|
-
volume_nvme = volumes_service.get_by_id(NVME_VOL_ID)
|
|
191
|
-
|
|
192
|
-
# assert
|
|
193
|
-
assert type(volume_nvme) == Volume
|
|
194
|
-
assert volume_nvme.id == NVME_VOL_ID
|
|
195
|
-
assert volume_nvme.status == NVME_VOL_STATUS
|
|
196
|
-
assert volume_nvme.instance_id == INSTANCE_ID
|
|
197
|
-
assert volume_nvme.name == NVME_VOL_NAME
|
|
198
|
-
assert volume_nvme.size == NVME_VOL_SIZE
|
|
199
|
-
assert volume_nvme.type == NVME
|
|
200
|
-
assert volume_nvme.location == Locations.FIN_01
|
|
201
|
-
assert volume_nvme.is_os_volume
|
|
202
|
-
assert volume_nvme.created_at == NVME_VOL_CREATED_AT
|
|
203
|
-
assert volume_nvme.target == TARGET_VDA
|
|
204
|
-
|
|
205
|
-
def test_get_volume_by_id_failed(self, volumes_service, endpoint):
|
|
206
|
-
# arrange - add response mock
|
|
207
|
-
url = endpoint + "/x"
|
|
208
|
-
responses.add(
|
|
209
|
-
responses.GET,
|
|
210
|
-
url,
|
|
211
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
212
|
-
status=400
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
# act
|
|
216
|
-
with pytest.raises(APIException) as excinfo:
|
|
217
|
-
volumes_service.get_by_id('x')
|
|
218
|
-
|
|
219
|
-
# assert
|
|
220
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
221
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
222
|
-
assert responses.assert_call_count(url, 1) is True
|
|
223
|
-
|
|
224
|
-
def test_create_volume_successful(self, volumes_service, endpoint):
|
|
225
|
-
# arrange - add response mock
|
|
226
|
-
responses.add(
|
|
227
|
-
responses.POST,
|
|
228
|
-
endpoint,
|
|
229
|
-
body=NVME_VOL_ID,
|
|
230
|
-
status=202
|
|
231
|
-
)
|
|
232
|
-
responses.add(
|
|
233
|
-
responses.GET,
|
|
234
|
-
endpoint + "/" + NVME_VOL_ID,
|
|
235
|
-
json=NVME_VOLUME,
|
|
236
|
-
status=200
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
# act
|
|
240
|
-
volume = volumes_service.create(
|
|
241
|
-
VolumeTypes.NVMe, NVME_VOL_NAME, NVME_VOL_SIZE)
|
|
242
|
-
|
|
243
|
-
# assert
|
|
244
|
-
assert volume.id == NVME_VOL_ID
|
|
245
|
-
assert type(volume.__str__()) == str
|
|
246
|
-
|
|
247
|
-
def test_create_volume_failed(self, volumes_service, endpoint):
|
|
248
|
-
# arrange - add response mock
|
|
249
|
-
responses.add(
|
|
250
|
-
responses.POST,
|
|
251
|
-
endpoint,
|
|
252
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
253
|
-
status=400
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
# act
|
|
257
|
-
with pytest.raises(APIException) as excinfo:
|
|
258
|
-
volumes_service.create(
|
|
259
|
-
VolumeTypes.NVMe, NVME_VOL_NAME, 100000000000000000000000)
|
|
260
|
-
|
|
261
|
-
# assert
|
|
262
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
263
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
264
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
265
|
-
|
|
266
|
-
def test_attach_volume_successful(self, volumes_service, endpoint):
|
|
267
|
-
# arrange - add response mock
|
|
268
|
-
responses.add(
|
|
269
|
-
responses.PUT,
|
|
270
|
-
endpoint,
|
|
271
|
-
status=202,
|
|
272
|
-
match=[
|
|
273
|
-
responses.json_params_matcher({
|
|
274
|
-
"id": NVME_VOL_ID,
|
|
275
|
-
"action": VolumeActions.ATTACH,
|
|
276
|
-
"instance_id": INSTANCE_ID
|
|
277
|
-
})
|
|
278
|
-
]
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
# act
|
|
282
|
-
result = volumes_service.attach(NVME_VOL_ID, INSTANCE_ID)
|
|
283
|
-
|
|
284
|
-
# assert
|
|
285
|
-
assert result is None
|
|
286
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
287
|
-
|
|
288
|
-
def test_attach_volume_failed(self, volumes_service, endpoint):
|
|
289
|
-
# arrange - add response mock
|
|
290
|
-
responses.add(
|
|
291
|
-
responses.PUT,
|
|
292
|
-
endpoint,
|
|
293
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
294
|
-
status=400,
|
|
295
|
-
match=[
|
|
296
|
-
responses.json_params_matcher({
|
|
297
|
-
"id": NVME_VOL_ID,
|
|
298
|
-
"action": VolumeActions.ATTACH,
|
|
299
|
-
"instance_id": INSTANCE_ID
|
|
300
|
-
})
|
|
301
|
-
]
|
|
302
|
-
)
|
|
303
|
-
|
|
304
|
-
# act
|
|
305
|
-
with pytest.raises(APIException) as excinfo:
|
|
306
|
-
volumes_service.attach(NVME_VOL_ID, INSTANCE_ID)
|
|
307
|
-
|
|
308
|
-
# assert
|
|
309
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
310
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
311
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
312
|
-
|
|
313
|
-
def test_detach_volume_successful(self, volumes_service, endpoint):
|
|
314
|
-
# arrange - add response mock
|
|
315
|
-
responses.add(
|
|
316
|
-
responses.PUT,
|
|
317
|
-
endpoint,
|
|
318
|
-
status=202,
|
|
319
|
-
match=[
|
|
320
|
-
responses.json_params_matcher({
|
|
321
|
-
"id": NVME_VOL_ID,
|
|
322
|
-
"action": VolumeActions.DETACH
|
|
323
|
-
})
|
|
324
|
-
]
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
# act
|
|
328
|
-
result = volumes_service.detach(NVME_VOL_ID)
|
|
329
|
-
|
|
330
|
-
# assert
|
|
331
|
-
assert result is None
|
|
332
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
333
|
-
|
|
334
|
-
def test_detach_volume_failed(self, volumes_service, endpoint):
|
|
335
|
-
# arrange - add response mock
|
|
336
|
-
responses.add(
|
|
337
|
-
responses.PUT,
|
|
338
|
-
endpoint,
|
|
339
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
340
|
-
status=400,
|
|
341
|
-
match=[
|
|
342
|
-
responses.json_params_matcher({
|
|
343
|
-
"id": NVME_VOL_ID,
|
|
344
|
-
"action": VolumeActions.DETACH
|
|
345
|
-
})
|
|
346
|
-
]
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
# act
|
|
350
|
-
with pytest.raises(APIException) as excinfo:
|
|
351
|
-
volumes_service.detach(NVME_VOL_ID)
|
|
352
|
-
|
|
353
|
-
# assert
|
|
354
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
355
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
356
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
357
|
-
|
|
358
|
-
def test_rename_volume_successful(self, volumes_service, endpoint):
|
|
359
|
-
new_name = "bob"
|
|
360
|
-
|
|
361
|
-
# arrange - add response mock
|
|
362
|
-
responses.add(
|
|
363
|
-
responses.PUT,
|
|
364
|
-
endpoint,
|
|
365
|
-
status=202,
|
|
366
|
-
match=[
|
|
367
|
-
responses.json_params_matcher({
|
|
368
|
-
"id": NVME_VOL_ID,
|
|
369
|
-
"action": VolumeActions.RENAME,
|
|
370
|
-
"name": new_name,
|
|
371
|
-
})
|
|
372
|
-
]
|
|
373
|
-
)
|
|
374
|
-
|
|
375
|
-
# act
|
|
376
|
-
result = volumes_service.rename(NVME_VOL_ID, new_name)
|
|
377
|
-
|
|
378
|
-
# assert
|
|
379
|
-
assert result is None
|
|
380
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
381
|
-
|
|
382
|
-
def test_rename_volume_failed(self, volumes_service, endpoint):
|
|
383
|
-
new_name = "bob"
|
|
384
|
-
|
|
385
|
-
# arrange - add response mock
|
|
386
|
-
responses.add(
|
|
387
|
-
responses.PUT,
|
|
388
|
-
endpoint,
|
|
389
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
390
|
-
status=400,
|
|
391
|
-
match=[
|
|
392
|
-
responses.json_params_matcher({
|
|
393
|
-
"id": NVME_VOL_ID,
|
|
394
|
-
"action": VolumeActions.RENAME,
|
|
395
|
-
"name": new_name
|
|
396
|
-
})
|
|
397
|
-
]
|
|
398
|
-
)
|
|
399
|
-
|
|
400
|
-
# act
|
|
401
|
-
with pytest.raises(APIException) as excinfo:
|
|
402
|
-
volumes_service.rename(NVME_VOL_ID, new_name)
|
|
403
|
-
|
|
404
|
-
# assert
|
|
405
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
406
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
407
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
408
|
-
|
|
409
|
-
def test_increase_volume_size_successful(self, volumes_service, endpoint):
|
|
410
|
-
new_size = 100000000000000
|
|
411
|
-
|
|
412
|
-
# arrange - add response mock
|
|
413
|
-
responses.add(
|
|
414
|
-
responses.PUT,
|
|
415
|
-
endpoint,
|
|
416
|
-
status=202,
|
|
417
|
-
match=[
|
|
418
|
-
responses.json_params_matcher({
|
|
419
|
-
"id": NVME_VOL_ID,
|
|
420
|
-
"action": VolumeActions.INCREASE_SIZE,
|
|
421
|
-
"size": new_size,
|
|
422
|
-
})
|
|
423
|
-
]
|
|
424
|
-
)
|
|
425
|
-
|
|
426
|
-
# act
|
|
427
|
-
result = volumes_service.increase_size(NVME_VOL_ID, new_size)
|
|
428
|
-
|
|
429
|
-
# assert
|
|
430
|
-
assert result is None
|
|
431
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
432
|
-
|
|
433
|
-
def test_increase_volume_size_failed(self, volumes_service, endpoint):
|
|
434
|
-
new_size = 100000000000000
|
|
435
|
-
|
|
436
|
-
# arrange - add response mock
|
|
437
|
-
responses.add(
|
|
438
|
-
responses.PUT,
|
|
439
|
-
endpoint,
|
|
440
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
441
|
-
status=400,
|
|
442
|
-
match=[
|
|
443
|
-
responses.json_params_matcher({
|
|
444
|
-
"id": NVME_VOL_ID,
|
|
445
|
-
"action": VolumeActions.INCREASE_SIZE,
|
|
446
|
-
"size": new_size
|
|
447
|
-
})
|
|
448
|
-
]
|
|
449
|
-
)
|
|
450
|
-
|
|
451
|
-
# act
|
|
452
|
-
with pytest.raises(APIException) as excinfo:
|
|
453
|
-
volumes_service.increase_size(NVME_VOL_ID, new_size)
|
|
454
|
-
|
|
455
|
-
# assert
|
|
456
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
457
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
458
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
459
|
-
|
|
460
|
-
def test_delete_volume_successful(self, volumes_service, endpoint):
|
|
461
|
-
# arrange - add response mock
|
|
462
|
-
responses.add(
|
|
463
|
-
responses.PUT,
|
|
464
|
-
endpoint,
|
|
465
|
-
status=202,
|
|
466
|
-
match=[
|
|
467
|
-
responses.json_params_matcher({
|
|
468
|
-
"id": NVME_VOL_ID,
|
|
469
|
-
"action": VolumeActions.DELETE,
|
|
470
|
-
"is_permanent": False
|
|
471
|
-
})
|
|
472
|
-
]
|
|
473
|
-
)
|
|
474
|
-
|
|
475
|
-
# act
|
|
476
|
-
result = volumes_service.delete(NVME_VOL_ID)
|
|
477
|
-
|
|
478
|
-
# assert
|
|
479
|
-
assert result is None
|
|
480
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
481
|
-
|
|
482
|
-
def test_delete_volume_failed(self, volumes_service, endpoint):
|
|
483
|
-
# arrange - add response mock
|
|
484
|
-
responses.add(
|
|
485
|
-
responses.PUT,
|
|
486
|
-
endpoint,
|
|
487
|
-
json={"code": INVALID_REQUEST, "message": INVALID_REQUEST_MESSAGE},
|
|
488
|
-
status=400,
|
|
489
|
-
match=[
|
|
490
|
-
responses.json_params_matcher({
|
|
491
|
-
"id": NVME_VOL_ID,
|
|
492
|
-
"action": VolumeActions.DELETE,
|
|
493
|
-
"is_permanent": False
|
|
494
|
-
})
|
|
495
|
-
]
|
|
496
|
-
)
|
|
497
|
-
|
|
498
|
-
# act
|
|
499
|
-
with pytest.raises(APIException) as excinfo:
|
|
500
|
-
volumes_service.delete(NVME_VOL_ID)
|
|
501
|
-
|
|
502
|
-
# assert
|
|
503
|
-
assert excinfo.value.code == INVALID_REQUEST
|
|
504
|
-
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
|
|
505
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
506
|
-
|
|
507
|
-
def test_clone_volume_with_input_name_successful(self, volumes_service, endpoint):
|
|
508
|
-
# arrange
|
|
509
|
-
CLONED_VOLUME_NAME = "cloned-volume"
|
|
510
|
-
|
|
511
|
-
# mock response for cloning the volume
|
|
512
|
-
responses.add(
|
|
513
|
-
responses.PUT,
|
|
514
|
-
endpoint,
|
|
515
|
-
status=202,
|
|
516
|
-
json=[RANDOM_VOL_ID],
|
|
517
|
-
match=[
|
|
518
|
-
responses.json_params_matcher({
|
|
519
|
-
"id": NVME_VOL_ID,
|
|
520
|
-
"action": VolumeActions.CLONE,
|
|
521
|
-
"name": CLONED_VOLUME_NAME,
|
|
522
|
-
"type": None
|
|
523
|
-
})
|
|
524
|
-
]
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
# mock object for the cloned volume
|
|
528
|
-
CLONED_VOL_GET_MOCK = NVME_VOLUME
|
|
529
|
-
CLONED_VOL_GET_MOCK['id'] = RANDOM_VOL_ID
|
|
530
|
-
CLONED_VOL_GET_MOCK['name'] = CLONED_VOLUME_NAME
|
|
531
|
-
CLONED_VOL_GET_MOCK['status'] = VolumeStatus.CLONING
|
|
532
|
-
|
|
533
|
-
# mock response for getting the cloned volume
|
|
534
|
-
responses.add(
|
|
535
|
-
responses.GET,
|
|
536
|
-
endpoint + "/" + RANDOM_VOL_ID,
|
|
537
|
-
status=200,
|
|
538
|
-
json=CLONED_VOL_GET_MOCK,
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
# act
|
|
542
|
-
cloned_volume = volumes_service.clone(NVME_VOL_ID, CLONED_VOLUME_NAME)
|
|
543
|
-
|
|
544
|
-
# assert
|
|
545
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
546
|
-
assert cloned_volume.name == CLONED_VOLUME_NAME
|
|
547
|
-
|
|
548
|
-
def test_clone_volume_without_input_name_successful(self, volumes_service: VolumesService, endpoint):
|
|
549
|
-
# arrange
|
|
550
|
-
CLONED_VOLUME_NAME = "CLONE-" + NVME_VOL_NAME
|
|
551
|
-
|
|
552
|
-
# mock response for cloning the volume
|
|
553
|
-
responses.add(
|
|
554
|
-
responses.PUT,
|
|
555
|
-
endpoint,
|
|
556
|
-
status=202,
|
|
557
|
-
json=[RANDOM_VOL_ID],
|
|
558
|
-
match=[
|
|
559
|
-
responses.json_params_matcher({
|
|
560
|
-
"id": NVME_VOL_ID,
|
|
561
|
-
"action": VolumeActions.CLONE,
|
|
562
|
-
"name": None,
|
|
563
|
-
"type": None
|
|
564
|
-
})
|
|
565
|
-
]
|
|
566
|
-
)
|
|
567
|
-
|
|
568
|
-
# mock object for the cloned volume
|
|
569
|
-
CLONED_VOL_GET_MOCK = NVME_VOLUME
|
|
570
|
-
CLONED_VOL_GET_MOCK['id'] = RANDOM_VOL_ID
|
|
571
|
-
CLONED_VOL_GET_MOCK['name'] = CLONED_VOLUME_NAME
|
|
572
|
-
CLONED_VOL_GET_MOCK['status'] = VolumeStatus.CLONING
|
|
573
|
-
|
|
574
|
-
# mock response for getting the cloned volume
|
|
575
|
-
responses.add(
|
|
576
|
-
responses.GET,
|
|
577
|
-
endpoint + "/" + RANDOM_VOL_ID,
|
|
578
|
-
status=200,
|
|
579
|
-
json=CLONED_VOL_GET_MOCK,
|
|
580
|
-
)
|
|
581
|
-
|
|
582
|
-
# act
|
|
583
|
-
cloned_volume = volumes_service.clone(NVME_VOL_ID)
|
|
584
|
-
|
|
585
|
-
# assert
|
|
586
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
587
|
-
assert cloned_volume.name == CLONED_VOLUME_NAME
|
|
588
|
-
|
|
589
|
-
def test_clone_two_volumes_successful(self, volumes_service: VolumesService, endpoint):
|
|
590
|
-
# arrange
|
|
591
|
-
CLONED_VOL1_NAME = "CLONE-" + NVME_VOL_NAME
|
|
592
|
-
CLONED_VOL2_NAME = "CLONE-" + HDD_VOL_NAME
|
|
593
|
-
|
|
594
|
-
# mock response for cloning the volumes
|
|
595
|
-
responses.add(
|
|
596
|
-
responses.PUT,
|
|
597
|
-
endpoint,
|
|
598
|
-
status=202,
|
|
599
|
-
json=[RANDOM_VOL_ID, RANDOM_VOL2_ID],
|
|
600
|
-
match=[
|
|
601
|
-
responses.json_params_matcher({
|
|
602
|
-
"id": [NVME_VOL_ID, HDD_VOL_ID],
|
|
603
|
-
"action": VolumeActions.CLONE,
|
|
604
|
-
"name": None,
|
|
605
|
-
"type": None
|
|
606
|
-
})
|
|
607
|
-
]
|
|
608
|
-
)
|
|
609
|
-
|
|
610
|
-
# mock object for the cloned volumes
|
|
611
|
-
CLONED_VOL1_GET_MOCK = NVME_VOLUME
|
|
612
|
-
CLONED_VOL1_GET_MOCK['id'] = RANDOM_VOL_ID
|
|
613
|
-
CLONED_VOL1_GET_MOCK['name'] = CLONED_VOL1_NAME
|
|
614
|
-
CLONED_VOL1_GET_MOCK['status'] = VolumeStatus.CLONING
|
|
615
|
-
|
|
616
|
-
CLONED_VOL2_GET_MOCK = HDD_VOLUME
|
|
617
|
-
CLONED_VOL2_GET_MOCK['id'] = RANDOM_VOL2_ID
|
|
618
|
-
CLONED_VOL2_GET_MOCK['name'] = CLONED_VOL2_NAME
|
|
619
|
-
CLONED_VOL2_GET_MOCK['status'] = VolumeStatus.CLONING
|
|
620
|
-
|
|
621
|
-
# mock response for getting the cloned volumes
|
|
622
|
-
responses.add(
|
|
623
|
-
responses.GET,
|
|
624
|
-
endpoint + "/" + RANDOM_VOL_ID,
|
|
625
|
-
status=200,
|
|
626
|
-
json=CLONED_VOL1_GET_MOCK,
|
|
627
|
-
)
|
|
628
|
-
responses.add(
|
|
629
|
-
responses.GET,
|
|
630
|
-
endpoint + "/" + RANDOM_VOL2_ID,
|
|
631
|
-
status=200,
|
|
632
|
-
json=CLONED_VOL2_GET_MOCK,
|
|
633
|
-
)
|
|
634
|
-
|
|
635
|
-
# act
|
|
636
|
-
cloned_volume = volumes_service.clone([NVME_VOL_ID, HDD_VOL_ID])
|
|
637
|
-
|
|
638
|
-
# assert
|
|
639
|
-
assert responses.assert_call_count(endpoint, 1) is True
|
|
640
|
-
assert cloned_volume[0].name == CLONED_VOL1_NAME
|
|
641
|
-
assert cloned_volume[1].name == CLONED_VOL2_NAME
|