-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_block_storage_tools.py
More file actions
746 lines (626 loc) · 26.5 KB
/
test_block_storage_tools.py
File metadata and controls
746 lines (626 loc) · 26.5 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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
from unittest.mock import Mock
import pytest
from openstack_mcp_server.tools.block_storage_tools import BlockStorageTools
from openstack_mcp_server.tools.response.block_storage import (
Attachment,
ConnectionInfo,
Volume,
VolumeAttachment,
)
class TestBlockStorageTools:
"""Test cases for BlockStorageTools class."""
def test_get_volumes_success(self, mock_get_openstack_conn_block_storage):
"""Test getting volumes successfully."""
mock_conn = mock_get_openstack_conn_block_storage
# Create mock volume objects
mock_volume1 = Mock()
mock_volume1.name = "web-data-volume"
mock_volume1.id = "abc123-def456-ghi789"
mock_volume1.status = "available"
mock_volume1.size = 10
mock_volume1.volume_type = "ssd"
mock_volume1.availability_zone = "nova"
mock_volume1.created_at = "2024-01-01T12:00:00Z"
mock_volume1.is_bootable = False
mock_volume1.is_encrypted = False
mock_volume1.description = "Web data volume"
mock_volume1.attachments = []
mock_volume2 = Mock()
mock_volume2.name = "db-backup-volume"
mock_volume2.id = "xyz789-uvw456-rst123"
mock_volume2.status = "in-use"
mock_volume2.size = 20
mock_volume2.volume_type = "hdd"
mock_volume2.availability_zone = "nova"
mock_volume2.created_at = "2024-01-02T12:00:00Z"
mock_volume2.is_bootable = True
mock_volume2.is_encrypted = True
mock_volume2.description = "DB backup volume"
mock_volume2.attachments = []
# Configure mock block_storage.volumes()
mock_conn.block_storage.volumes.return_value = [
mock_volume1,
mock_volume2,
]
# Test BlockStorageTools
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volumes()
# Verify results
assert isinstance(result, list)
assert len(result) == 2
assert all(isinstance(vol, Volume) for vol in result)
# Check first volume
vol1 = result[0]
assert vol1.id == "abc123-def456-ghi789"
assert vol1.name == "web-data-volume"
assert vol1.status == "available"
assert vol1.size == 10
# Check second volume
vol2 = result[1]
assert vol2.id == "xyz789-uvw456-rst123"
assert vol2.name == "db-backup-volume"
assert vol2.status == "in-use"
assert vol2.size == 20
# Verify mock calls
mock_conn.block_storage.volumes.assert_called_once()
def test_get_volumes_empty_list(
self,
mock_get_openstack_conn_block_storage,
):
"""Test getting volumes when no volumes exist."""
mock_conn = mock_get_openstack_conn_block_storage
# Empty volume list
mock_conn.block_storage.volumes.return_value = []
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volumes()
# Verify empty list
assert isinstance(result, list)
assert len(result) == 0
mock_conn.block_storage.volumes.assert_called_once()
def test_get_volumes_single_volume(
self,
mock_get_openstack_conn_block_storage,
):
"""Test getting volumes with a single volume."""
mock_conn = mock_get_openstack_conn_block_storage
# Single volume
mock_volume = Mock()
mock_volume.name = "test-volume"
mock_volume.id = "single-123"
mock_volume.status = "creating"
mock_volume.size = 5
mock_volume.volume_type = None
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = False
mock_volume.is_encrypted = False
mock_volume.description = None
mock_volume.attachments = []
mock_conn.block_storage.volumes.return_value = [mock_volume]
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volumes()
assert isinstance(result, list)
assert len(result) == 1
assert result[0].name == "test-volume"
assert result[0].id == "single-123"
assert result[0].status == "creating"
mock_conn.block_storage.volumes.assert_called_once()
def test_get_volumes_multiple_statuses(
self,
mock_get_openstack_conn_block_storage,
):
"""Test volumes with various statuses."""
mock_conn = mock_get_openstack_conn_block_storage
# Volumes with different statuses
volumes_data = [
("volume-available", "id-1", "available"),
("volume-in-use", "id-2", "in-use"),
("volume-error", "id-3", "error"),
("volume-creating", "id-4", "creating"),
("volume-deleting", "id-5", "deleting"),
]
mock_volumes = []
for name, volume_id, status in volumes_data:
mock_volume = Mock()
mock_volume.name = name
mock_volume.id = volume_id
mock_volume.status = status
mock_volume.size = 10
mock_volume.volume_type = "standard"
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = False
mock_volume.is_encrypted = False
mock_volume.description = f"Description for {name}"
mock_volume.attachments = []
mock_volumes.append(mock_volume)
mock_conn.block_storage.volumes.return_value = mock_volumes
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volumes()
# Verify result is a list with correct length
assert isinstance(result, list)
assert len(result) == 5
# Verify each volume is included in the result
result_by_id = {vol.id: vol for vol in result}
for name, volume_id, status in volumes_data:
assert volume_id in result_by_id
vol = result_by_id[volume_id]
assert vol.name == name
assert vol.status == status
mock_conn.block_storage.volumes.assert_called_once()
def test_get_volumes_with_special_characters(
self,
mock_get_openstack_conn_block_storage,
):
"""Test volumes with special characters in names."""
mock_conn = mock_get_openstack_conn_block_storage
# Volume names with special characters
mock_volume1 = Mock()
mock_volume1.name = "web-volume_test-01"
mock_volume1.id = "id-with-dashes"
mock_volume1.status = "available"
mock_volume1.size = 15
mock_volume1.volume_type = "ssd"
mock_volume1.availability_zone = "nova"
mock_volume1.created_at = "2024-01-01T12:00:00Z"
mock_volume1.is_bootable = False
mock_volume1.is_encrypted = False
mock_volume1.description = None
mock_volume1.attachments = []
mock_volume2 = Mock()
mock_volume2.name = "db.volume.prod"
mock_volume2.id = "id.with.dots"
mock_volume2.status = "in-use"
mock_volume2.size = 25
mock_volume2.volume_type = "hdd"
mock_volume2.availability_zone = "nova"
mock_volume2.created_at = "2024-01-02T12:00:00Z"
mock_volume2.is_bootable = True
mock_volume2.is_encrypted = True
mock_volume2.description = "Production DB volume"
mock_volume2.attachments = []
mock_conn.block_storage.volumes.return_value = [
mock_volume1,
mock_volume2,
]
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volumes()
assert isinstance(result, list)
assert len(result) == 2
# Find volumes by name
vol1 = next(vol for vol in result if vol.name == "web-volume_test-01")
vol2 = next(vol for vol in result if vol.name == "db.volume.prod")
assert vol1.id == "id-with-dashes"
assert vol1.status == "available"
assert vol2.id == "id.with.dots"
assert vol2.status == "in-use"
mock_conn.block_storage.volumes.assert_called_once()
def test_get_volume_details_success(
self,
mock_get_openstack_conn_block_storage,
):
"""Test getting volume details successfully."""
mock_conn = mock_get_openstack_conn_block_storage
# Create mock volume with detailed info
mock_volume = Mock()
mock_volume.name = "test-volume"
mock_volume.id = "vol-123"
mock_volume.status = "available"
mock_volume.size = 20
mock_volume.volume_type = "ssd"
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = False
mock_volume.is_encrypted = True
mock_volume.description = "Test volume description"
mock_volume.attachments = []
mock_conn.block_storage.get_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volume_details("vol-123")
# Verify result is a Volume object
assert isinstance(result, Volume)
assert result.name == "test-volume"
assert result.id == "vol-123"
assert result.status == "available"
assert result.size == 20
assert result.volume_type == "ssd"
assert result.availability_zone == "nova"
assert not result.is_bootable
assert result.is_encrypted
assert result.description == "Test volume description"
assert len(result.attachments) == 0
mock_conn.block_storage.get_volume.assert_called_once_with("vol-123")
def test_get_volume_details_with_attachments(
self,
mock_get_openstack_conn_block_storage,
):
"""Test getting volume details with attachments."""
mock_conn = mock_get_openstack_conn_block_storage
# Create mock volume with attachments
mock_volume = Mock()
mock_volume.name = "attached-volume"
mock_volume.id = "vol-attached"
mock_volume.status = "in-use"
mock_volume.size = 10
mock_volume.volume_type = None
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = True
mock_volume.is_encrypted = False
mock_volume.description = "Attached volume"
mock_volume.attachments = [
{
"server_id": "server-123",
"device": "/dev/vdb",
"id": "attach-1",
},
{
"server_id": "server-456",
"device": "/dev/vdc",
"id": "attach-2",
},
]
mock_conn.block_storage.get_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_volume_details("vol-attached")
# Verify result is a Volume object
assert isinstance(result, Volume)
assert result.name == "attached-volume"
assert result.status == "in-use"
assert len(result.attachments) == 2
# Verify attachment details
attach1 = result.attachments[0]
attach2 = result.attachments[1]
assert isinstance(attach1, VolumeAttachment)
assert attach1.server_id == "server-123"
assert attach1.device == "/dev/vdb"
assert attach1.attachment_id == "attach-1"
assert isinstance(attach2, VolumeAttachment)
assert attach2.server_id == "server-456"
assert attach2.device == "/dev/vdc"
assert attach2.attachment_id == "attach-2"
def test_get_volume_details_error(
self,
mock_get_openstack_conn_block_storage,
):
"""Test getting volume details with error."""
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.get_volume.side_effect = Exception(
"Volume not found",
)
block_storage_tools = BlockStorageTools()
# Should raise exception directly
with pytest.raises(Exception, match="Volume not found"):
block_storage_tools.get_volume_details("nonexistent-vol")
def test_create_volume_success(
self,
mock_get_openstack_conn_block_storage,
):
"""Test creating volume successfully."""
mock_conn = mock_get_openstack_conn_block_storage
# Mock created volume
mock_volume = Mock()
mock_volume.name = "new-volume"
mock_volume.id = "vol-new-123"
mock_volume.size = 10
mock_volume.status = "creating"
mock_volume.volume_type = "ssd"
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = False
mock_volume.is_encrypted = False
mock_volume.description = "Test volume"
mock_volume.attachments = []
mock_conn.block_storage.create_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.create_volume(
"new-volume",
10,
"Test volume",
"ssd",
"nova",
)
# Verify result is a Volume object
assert isinstance(result, Volume)
assert result.name == "new-volume"
assert result.id == "vol-new-123"
assert result.size == 10
assert result.status == "creating"
assert result.volume_type == "ssd"
assert result.availability_zone == "nova"
mock_conn.block_storage.create_volume.assert_called_once_with(
size=10,
image=None,
bootable=None,
name="new-volume",
description="Test volume",
volume_type="ssd",
availability_zone="nova",
)
def test_create_volume_minimal_params(
self,
mock_get_openstack_conn_block_storage,
):
"""Test creating volume with minimal parameters."""
mock_conn = mock_get_openstack_conn_block_storage
mock_volume = Mock()
mock_volume.name = "minimal-volume"
mock_volume.id = "vol-minimal"
mock_volume.size = 5
mock_volume.status = "creating"
mock_volume.volume_type = None
mock_volume.availability_zone = None
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = False
mock_volume.is_encrypted = False
mock_volume.description = None
mock_volume.attachments = []
mock_conn.block_storage.create_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.create_volume("minimal-volume", 5)
# Verify result structure
assert isinstance(result, Volume)
assert result.name == "minimal-volume"
assert result.size == 5
mock_conn.block_storage.create_volume.assert_called_once_with(
size=5,
image=None,
bootable=None,
name="minimal-volume",
)
def test_create_volume_with_image_and_bootable(
self,
mock_get_openstack_conn_block_storage,
):
"""Test creating volume with image and bootable parameters."""
mock_conn = mock_get_openstack_conn_block_storage
mock_volume = Mock()
mock_volume.name = "bootable-volume"
mock_volume.id = "vol-bootable"
mock_volume.size = 20
mock_volume.status = "creating"
mock_volume.volume_type = "ssd"
mock_volume.availability_zone = "nova"
mock_volume.created_at = "2024-01-01T12:00:00Z"
mock_volume.is_bootable = True
mock_volume.is_encrypted = False
mock_volume.description = "Bootable volume from image"
mock_volume.attachments = []
mock_conn.block_storage.create_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.create_volume(
"bootable-volume",
20,
"Bootable volume from image",
"ssd",
"nova",
True,
"ubuntu-20.04",
)
assert isinstance(result, Volume)
assert result.name == "bootable-volume"
assert result.id == "vol-bootable"
assert result.size == 20
assert result.is_bootable
mock_conn.block_storage.create_volume.assert_called_once_with(
size=20,
image="ubuntu-20.04",
bootable=True,
name="bootable-volume",
description="Bootable volume from image",
volume_type="ssd",
availability_zone="nova",
)
def test_create_volume_error(self, mock_get_openstack_conn_block_storage):
"""Test creating volume with error."""
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.create_volume.side_effect = Exception(
"Quota exceeded",
)
block_storage_tools = BlockStorageTools()
with pytest.raises(Exception, match="Quota exceeded"):
block_storage_tools.create_volume("fail-volume", 100)
def test_delete_volume_success(
self,
mock_get_openstack_conn_block_storage,
):
"""Test deleting volume successfully."""
mock_conn = mock_get_openstack_conn_block_storage
# Mock volume to be deleted
mock_volume = Mock()
mock_volume.name = "delete-me"
mock_volume.id = "vol-delete"
mock_conn.block_storage.get_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.delete_volume("vol-delete", False)
# Verify result is None
assert result is None
mock_conn.block_storage.delete_volume.assert_called_once_with(
"vol-delete",
force=False,
ignore_missing=False,
)
def test_delete_volume_force(self, mock_get_openstack_conn_block_storage):
"""Test force deleting volume."""
mock_conn = mock_get_openstack_conn_block_storage
mock_volume = Mock()
mock_volume.name = None # Test unnamed volume
mock_volume.id = "vol-force-delete"
mock_conn.block_storage.get_volume.return_value = mock_volume
block_storage_tools = BlockStorageTools()
result = block_storage_tools.delete_volume("vol-force-delete", True)
# Verify result is None
assert result is None
mock_conn.block_storage.delete_volume.assert_called_once_with(
"vol-force-delete",
force=True,
ignore_missing=False,
)
def test_delete_volume_error(self, mock_get_openstack_conn_block_storage):
"""Test deleting volume with error."""
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.delete_volume.side_effect = Exception(
"Volume not found",
)
block_storage_tools = BlockStorageTools()
# Should raise exception directly
with pytest.raises(Exception, match="Volume not found"):
block_storage_tools.delete_volume("nonexistent-vol")
def test_extend_volume_success(
self,
mock_get_openstack_conn_block_storage,
):
"""Test extending volume successfully."""
mock_conn = mock_get_openstack_conn_block_storage
block_storage_tools = BlockStorageTools()
result = block_storage_tools.extend_volume("vol-extend", 20)
# Verify result is None
assert result is None
mock_conn.block_storage.extend_volume.assert_called_once_with(
"vol-extend",
20,
)
def test_extend_volume_invalid_size(
self,
mock_get_openstack_conn_block_storage,
):
"""Test extending volume with invalid size."""
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.extend_volume.side_effect = Exception(
"Invalid size",
)
block_storage_tools = BlockStorageTools()
with pytest.raises(Exception, match="Invalid size"):
block_storage_tools.extend_volume("vol-extend", 15)
def test_extend_volume_error(self, mock_get_openstack_conn_block_storage):
"""Test extending volume with error."""
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.extend_volume.side_effect = Exception(
"Volume busy",
)
block_storage_tools = BlockStorageTools()
with pytest.raises(Exception, match="Volume busy"):
block_storage_tools.extend_volume("vol-busy", 30)
def test_register_tools(self):
"""Test that tools are properly registered with FastMCP."""
# Create FastMCP mock
mock_mcp = Mock()
mock_tool_decorator = Mock()
mock_mcp.tool.return_value = mock_tool_decorator
block_storage_tools = BlockStorageTools()
block_storage_tools.register_tools(mock_mcp)
# Verify mcp.tool() was called for each method
assert mock_mcp.tool.call_count == 6
# Verify all methods were registered
registered_methods = [
call[0][0] for call in mock_tool_decorator.call_args_list
]
expected_methods = [
block_storage_tools.get_volumes,
block_storage_tools.get_volume_details,
block_storage_tools.create_volume,
block_storage_tools.delete_volume,
block_storage_tools.extend_volume,
]
for method in expected_methods:
assert method in registered_methods
def test_block_storage_tools_instantiation(self):
"""Test BlockStorageTools can be instantiated."""
block_storage_tools = BlockStorageTools()
assert block_storage_tools is not None
assert hasattr(block_storage_tools, "register_tools")
assert hasattr(block_storage_tools, "get_volumes")
assert hasattr(block_storage_tools, "get_volume_details")
assert hasattr(block_storage_tools, "create_volume")
assert hasattr(block_storage_tools, "delete_volume")
assert hasattr(block_storage_tools, "extend_volume")
# Verify all methods are callable
assert callable(block_storage_tools.register_tools)
assert callable(block_storage_tools.get_volumes)
assert callable(block_storage_tools.get_volume_details)
assert callable(block_storage_tools.create_volume)
assert callable(block_storage_tools.delete_volume)
assert callable(block_storage_tools.extend_volume)
def test_get_volumes_docstring(self):
"""Test that get_volumes has proper docstring."""
block_storage_tools = BlockStorageTools()
docstring = block_storage_tools.get_volumes.__doc__
assert docstring is not None
assert "Get the list of Block Storage volumes" in docstring
assert "return" in docstring.lower() or "Return" in docstring
assert (
"list[Volume]" in docstring
or "A list of Volume objects" in docstring
)
def test_all_block_storage_methods_have_docstrings(self):
"""Test that all public BlockStorageTools methods have proper docstrings."""
block_storage_tools = BlockStorageTools()
methods_to_check = [
"get_volumes",
"get_volume_details",
"create_volume",
"delete_volume",
"extend_volume",
]
for method_name in methods_to_check:
method = getattr(block_storage_tools, method_name)
docstring = method.__doc__
assert docstring is not None, (
f"{method_name} should have a docstring"
)
assert len(docstring.strip()) > 0, (
f"{method_name} docstring should not be empty"
)
def test_get_attachment_details(
self, mock_get_openstack_conn_block_storage
):
"""Test getting attachment details."""
# Set up the attachment mock object
mock_attachment = Mock()
mock_attachment.id = "attach-123"
mock_attachment.instance = "server-123"
mock_attachment.volume_id = "vol-123"
mock_attachment.attached_at = "2024-01-01T12:00:00Z"
mock_attachment.detached_at = None
mock_attachment.attach_mode = "attach"
mock_attachment.connection_info = {
"access_mode": "rw",
"cacheable": True,
"driver_volume_type": "iscsi",
"encrypted": False,
"qos_specs": None,
"target_discovered": True,
"target_iqn": "iqn.2024-01-01.com.example:volume-123",
"target_lun": 0,
"target_portal": "192.168.1.100:3260",
}
mock_attachment.connector = "connector-123"
# Configure the mock block_storage.get_attachment()
mock_conn = mock_get_openstack_conn_block_storage
mock_conn.block_storage.get_attachment.return_value = mock_attachment
block_storage_tools = BlockStorageTools()
result = block_storage_tools.get_attachment_details("attach-123")
# Verify the result
assert isinstance(result, Attachment)
assert result.id == "attach-123"
assert result.instance == "server-123"
assert result.attached_at == "2024-01-01T12:00:00Z"
assert result.detached_at is None
assert result.attach_mode == "attach"
assert result.connection_info == ConnectionInfo(
access_mode="rw",
cacheable=True,
driver_volume_type="iscsi",
encrypted=False,
qos_specs=None,
target_discovered=True,
target_iqn="iqn.2024-01-01.com.example:volume-123",
target_lun=0,
target_portal="192.168.1.100:3260",
)
assert result.connector == "connector-123"
assert result.volume_id == "vol-123"
# Verify the mock calls
mock_conn.block_storage.get_attachment.assert_called_once_with(
"attach-123"
)