forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_tests.py
More file actions
392 lines (325 loc) · 15.7 KB
/
block_tests.py
File metadata and controls
392 lines (325 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
"""
SoftLayer.tests.CLI.modules.block_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
from SoftLayer import testing
import json
import mock
class BlockTests(testing.TestCase):
def test_access_list(self):
result = self.run_command(['block', 'access-list', '1234'])
self.assert_no_fail(result)
self.assertEqual([
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'VIRTUAL',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.1',
'id': 1234,
},
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'HARDWARE',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.2',
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1/24 (backend subnet)',
'type': 'SUBNET',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1 (backend ip)',
'type': 'IP',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
}],
json.loads(result.output),)
def test_volume_cancel(self):
result = self.run_command([
'--really', 'block', 'volume-cancel', '1234'])
self.assert_no_fail(result)
self.assertEqual('Block volume with id 1234 has been marked'
' for cancellation\n', result.output)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
args=(False, True, None))
def test_volume_detail(self):
result = self.run_command(['block', 'volume-detail', '1234'])
self.assert_no_fail(result)
self.assertEqual({
'Username': 'username',
'LUN Id': '2',
'Endurance Tier': '2 IOPS per GB',
'IOPs': 1000,
'Snapshot Capacity (GB)': '10',
'Snapshot Used (Bytes)': 1024,
'Capacity (GB)': '20GB',
'Target IP': '10.1.2.3',
'Data Center': 'dal05',
'Type': 'ENDURANCE',
'ID': 100,
'# of Active Transactions': '0',
'Replicant Count': '1',
'Replication Status': 'Replicant Volume Provisioning '
'has completed.',
'Replicant Volumes': [[
{'Replicant ID': 'Volume Name', '1784': 'TEST_REP_1'},
{'Replicant ID': 'Target IP', '1784': '10.3.174.79'},
{'Replicant ID': 'Data Center', '1784': 'wdc01'},
{'Replicant ID': 'Schedule', '1784': 'REPLICATION_HOURLY'},
], [
{'Replicant ID': 'Volume Name', '1785': 'TEST_REP_2'},
{'Replicant ID': 'Target IP', '1785': '10.3.177.84'},
{'Replicant ID': 'Data Center', '1785': 'dal01'},
{'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'},
]]
}, json.loads(result.output))
def test_volume_list(self):
result = self.run_command(['block', 'volume-list'])
self.assert_no_fail(result)
self.assertEqual([
{
'bytes_used': None,
'capacity_gb': 20,
'datacenter': None,
'id': 100,
'ip_addr': '10.1.2.3',
'lunId': None,
'storage_type': 'ENDURANCE',
'username': 'username',
'active_transactions': None
}],
json.loads(result.output))
def test_volume_order_performance_iops_not_given(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--os-type=linux', '--location=dal05'])
self.assertEqual(2, result.exit_code)
def test_volume_order_performance_iops_out_of_range(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=80000', '--os-type=linux',
'--location=dal05'])
self.assertEqual(2, result.exit_code)
def test_volume_order_performance_iops_not_multiple_of_100(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=122', '--os-type=linux',
'--location=dal05'])
self.assertEqual(2, result.exit_code)
def test_volume_order_performance_snapshot_error(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05', '--snapshot-size=10'])
self.assertEqual(2, result.exit_code)
@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_performance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [
{'description': 'Performance Storage'},
{'description': 'Block Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'}]
}
}
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Performance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n')
def test_volume_order_endurance_tier_not_given(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--os-type=linux', '--location=dal05'])
self.assertEqual(2, result.exit_code)
@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_endurance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [
{'description': 'Endurance Storage'},
{'description': 'Block Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'},
{'description': '10 GB Storage Space (Snapshot Space)'}]
}
}
result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05', '--snapshot-size=10'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Endurance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')
@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_order_not_placed(self, order_mock):
order_mock.return_value = {}
result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order could not be placed! Please verify '
'your options and try again.\n')
def test_enable_snapshots(self):
result = self.run_command(['block', 'snapshot-enable', '12345678',
'--schedule-type=HOURLY', '--minute=10',
'--retention-count=5'])
self.assert_no_fail(result)
def test_disable_snapshots(self):
result = self.run_command(['block', 'snapshot-disable', '12345678',
'--schedule-type=HOURLY'])
self.assert_no_fail(result)
def test_create_snapshot(self):
result = self.run_command(['block', 'snapshot-create', '12345678'])
self.assert_no_fail(result)
@mock.patch('SoftLayer.BlockStorageManager.create_snapshot')
def test_create_snapshot_unsuccessful(self, snapshot_mock):
snapshot_mock.return_value = []
result = self.run_command(['block', 'snapshot-create', '8', '-n=note'])
self.assertEqual('Error occurred while creating snapshot.\n'
'Ensure volume is not failed over or in another '
'state which prevents taking snapshots.\n',
result.output)
def test_snapshot_list(self):
result = self.run_command(['block', 'snapshot-list', '12345678'])
self.assert_no_fail(result)
self.assertEqual([
{
'id': 470,
'name': 'unit_testing_note',
'created': '2016-07-06T07:41:19-05:00',
'size_bytes': '42',
}],
json.loads(result.output))
def test_snapshot_cancel(self):
result = self.run_command(['--really',
'block', 'snapshot-cancel', '1234'])
self.assert_no_fail(result)
self.assertEqual('Block volume with id 1234 has been marked'
' for snapshot cancellation\n', result.output)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
args=(False, True, None))
def test_snapshot_restore(self):
result = self.run_command(['block', 'snapshot-restore', '12345678',
'--snapshot-id=87654321'])
self.assert_no_fail(result)
self.assertEqual(result.output, 'Block volume 12345678 is being'
' restored using snapshot 87654321\n')
@mock.patch('SoftLayer.BlockStorageManager.order_snapshot_space')
def test_snapshot_order(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 8702,
'items': [{'description':
'10 GB Storage Space (Snapshot Space)'}],
'status': 'PENDING_APPROVAL',
}
}
result = self.run_command(['block', 'snapshot-order', '1234',
'--capacity=10', '--tier=0.25'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #8702 placed successfully!\n'
' > 10 GB Storage Space (Snapshot Space)\n'
' > Order status: PENDING_APPROVAL\n')
def test_authorize_host_to_volume(self):
result = self.run_command(['block', 'access-authorize', '12345678',
'--hardware-id=100', '--virtual-id=10',
'--ip-address-id=192',
'--ip-address=192.3.2.1'])
self.assert_no_fail(result)
def test_deauthorize_host_to_volume(self):
result = self.run_command(['block', 'access-revoke', '12345678',
'--hardware-id=100', '--virtual-id=10',
'--ip-address-id=192',
'--ip-address=192.3.2.1'])
self.assert_no_fail(result)
def test_replicant_failover(self):
result = self.run_command(['block', 'replica-failover', '12345678',
'--replicant-id=5678', '--immediate'])
self.assert_no_fail(result)
self.assertEqual('Failover to replicant is now in progress.\n',
result.output)
@mock.patch('SoftLayer.BlockStorageManager.failover_to_replicant')
def test_replicant_failover_unsuccessful(self, failover_mock):
failover_mock.return_value = False
result = self.run_command(['block', 'replica-failover', '12345678',
'--replicant-id=5678'])
self.assertEqual('Failover operation could not be initiated.\n',
result.output)
def test_replicant_failback(self):
result = self.run_command(['block', 'replica-failback', '12345678',
'--replicant-id=5678'])
self.assert_no_fail(result)
self.assertEqual('Failback from replicant is now in progress.\n',
result.output)
@mock.patch('SoftLayer.BlockStorageManager.failback_from_replicant')
def test_replicant_failback_unsuccessful(self, failback_mock):
failback_mock.return_value = False
result = self.run_command(['block', 'replica-failback', '12345678',
'--replicant-id=5678'])
self.assertEqual('Failback operation could not be initiated.\n',
result.output)
@mock.patch('SoftLayer.BlockStorageManager.order_replicant_volume')
def test_replicant_order_order_not_placed(self, order_mock):
order_mock.return_value = {}
result = self.run_command(['block', 'replica-order', '100',
'--snapshot-schedule=DAILY',
'--location=dal05'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order could not be placed! Please verify '
'your options and try again.\n')
@mock.patch('SoftLayer.BlockStorageManager.order_replicant_volume')
def test_replicant_order(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 91604,
'items': [
{'description': 'Endurance Storage'},
{'description': '2 IOPS per GB'},
{'description': 'Block Storage'},
{'description': '20 GB Storage Space'},
{'description': '10 GB Storage Space (Snapshot Space)'},
{'description': '20 GB Storage Space Replicant of: TEST'},
],
}
}
result = self.run_command(['block', 'replica-order', '100',
'--snapshot-schedule=DAILY',
'--location=dal05', '--tier=2'])
self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #91604 placed successfully!\n'
' > Endurance Storage\n'
' > 2 IOPS per GB\n'
' > Block Storage\n'
' > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n'
' > 20 GB Storage Space Replicant of: TEST\n')