|
4 | 4 |
|
5 | 5 | from openstack_mcp_server.tools.block_storage_tools import BlockStorageTools |
6 | 6 | from openstack_mcp_server.tools.response.block_storage import ( |
| 7 | + Attachment, |
| 8 | + ConnectionInfo, |
7 | 9 | Volume, |
8 | 10 | VolumeAttachment, |
9 | 11 | ) |
@@ -613,9 +615,6 @@ def test_register_tools(self): |
613 | 615 | block_storage_tools = BlockStorageTools() |
614 | 616 | block_storage_tools.register_tools(mock_mcp) |
615 | 617 |
|
616 | | - # Verify mcp.tool() was called for each method |
617 | | - assert mock_mcp.tool.call_count == 5 |
618 | | - |
619 | 618 | # Verify all methods were registered |
620 | 619 | registered_methods = [ |
621 | 620 | call[0][0] for call in mock_tool_decorator.call_args_list |
@@ -683,3 +682,62 @@ def test_all_block_storage_methods_have_docstrings(self): |
683 | 682 | assert len(docstring.strip()) > 0, ( |
684 | 683 | f"{method_name} docstring should not be empty" |
685 | 684 | ) |
| 685 | + |
| 686 | + def test_get_attachment_details( |
| 687 | + self, mock_get_openstack_conn_block_storage |
| 688 | + ): |
| 689 | + """Test getting attachment details.""" |
| 690 | + |
| 691 | + # Set up the attachment mock object |
| 692 | + mock_attachment = Mock() |
| 693 | + mock_attachment.id = "attach-123" |
| 694 | + mock_attachment.instance = "server-123" |
| 695 | + mock_attachment.volume_id = "vol-123" |
| 696 | + mock_attachment.attached_at = "2024-01-01T12:00:00Z" |
| 697 | + mock_attachment.detached_at = None |
| 698 | + mock_attachment.attach_mode = "attach" |
| 699 | + mock_attachment.connection_info = { |
| 700 | + "access_mode": "rw", |
| 701 | + "cacheable": True, |
| 702 | + "driver_volume_type": "iscsi", |
| 703 | + "encrypted": False, |
| 704 | + "qos_specs": None, |
| 705 | + "target_discovered": True, |
| 706 | + "target_iqn": "iqn.2024-01-01.com.example:volume-123", |
| 707 | + "target_lun": 0, |
| 708 | + "target_portal": "192.168.1.100:3260", |
| 709 | + } |
| 710 | + mock_attachment.connector = "connector-123" |
| 711 | + |
| 712 | + # Configure the mock block_storage.get_attachment() |
| 713 | + mock_conn = mock_get_openstack_conn_block_storage |
| 714 | + mock_conn.block_storage.get_attachment.return_value = mock_attachment |
| 715 | + |
| 716 | + block_storage_tools = BlockStorageTools() |
| 717 | + result = block_storage_tools.get_attachment_details("attach-123") |
| 718 | + |
| 719 | + # Verify the result |
| 720 | + assert isinstance(result, Attachment) |
| 721 | + assert result.id == "attach-123" |
| 722 | + assert result.instance == "server-123" |
| 723 | + assert result.attached_at == "2024-01-01T12:00:00Z" |
| 724 | + assert result.detached_at is None |
| 725 | + assert result.attach_mode == "attach" |
| 726 | + assert result.connection_info == ConnectionInfo( |
| 727 | + access_mode="rw", |
| 728 | + cacheable=True, |
| 729 | + driver_volume_type="iscsi", |
| 730 | + encrypted=False, |
| 731 | + qos_specs=None, |
| 732 | + target_discovered=True, |
| 733 | + target_iqn="iqn.2024-01-01.com.example:volume-123", |
| 734 | + target_lun=0, |
| 735 | + target_portal="192.168.1.100:3260", |
| 736 | + ) |
| 737 | + assert result.connector == "connector-123" |
| 738 | + assert result.volume_id == "vol-123" |
| 739 | + |
| 740 | + # Verify the mock calls |
| 741 | + mock_conn.block_storage.get_attachment.assert_called_once_with( |
| 742 | + "attach-123" |
| 743 | + ) |
0 commit comments