Skip to content

Commit 68124be

Browse files
committed
chore : ruff failure fix
1 parent 62db145 commit 68124be

File tree

6 files changed

+146
-66
lines changed

6 files changed

+146
-66
lines changed

src/openstack_mcp_server/tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def register_tool(mcp: FastMCP):
66
Register Openstack MCP tools.
77
"""
88

9+
from .block_storage_tools import BlockStorageTools
910
from .compute_tools import ComputeTools
1011
from .identity_tools import IdentityTools
1112
from .image_tools import ImageTools
1213
from .network_tools import NetworkTools
13-
from .block_storage_tools import BlockStorageTools
1414

1515
ComputeTools().register_tools(mcp)
1616
ImageTools().register_tools(mcp)

src/openstack_mcp_server/tools/block_storage_tools.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from fastmcp import FastMCP
2+
3+
from .base import get_openstack_conn
14
from .response.block_storage import (
25
Volume,
36
VolumeAttachment,
47
)
5-
from .base import get_openstack_conn
6-
from fastmcp import FastMCP
78

89

910
class BlockStorageTools:
@@ -39,7 +40,7 @@ def get_volumes(self) -> list[Volume]:
3940
server_id=attachment.get("server_id"),
4041
device=attachment.get("device"),
4142
attachment_id=attachment.get("id"),
42-
)
43+
),
4344
)
4445

4546
volume_list.append(
@@ -57,7 +58,7 @@ def get_volumes(self) -> list[Volume]:
5758
is_encrypted=volume.is_encrypted,
5859
description=volume.description,
5960
attachments=attachments,
60-
)
61+
),
6162
)
6263

6364
return volume_list
@@ -80,7 +81,7 @@ def get_volume_details(self, volume_id: str) -> Volume:
8081
server_id=attachment.get("server_id"),
8182
device=attachment.get("device"),
8283
attachment_id=attachment.get("id"),
83-
)
84+
),
8485
)
8586

8687
return Volume(
@@ -133,7 +134,10 @@ def create_volume(
133134
volume_kwargs["availability_zone"] = availability_zone
134135

135136
volume = conn.block_storage.create_volume(
136-
size=size, image=image, bootable=bootable, **volume_kwargs
137+
size=size,
138+
image=image,
139+
bootable=bootable,
140+
**volume_kwargs,
137141
)
138142

139143
volume_obj = Volume(
@@ -162,7 +166,11 @@ def delete_volume(self, volume_id: str, force: bool = False) -> None:
162166
"""
163167
conn = get_openstack_conn()
164168

165-
conn.block_storage.delete_volume(volume_id, force=force, ignore_missing=False)
169+
conn.block_storage.delete_volume(
170+
volume_id,
171+
force=force,
172+
ignore_missing=False,
173+
)
166174

167175
def extend_volume(self, volume_id: str, new_size: int) -> None:
168176
"""
@@ -174,4 +182,4 @@ def extend_volume(self, volume_id: str, new_size: int) -> None:
174182
"""
175183
conn = get_openstack_conn()
176184

177-
conn.block_storage.extend_volume(volume_id, new_size)
185+
conn.block_storage.extend_volume(volume_id, new_size)

src/openstack_mcp_server/tools/identity_tools.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastmcp import FastMCP
22

33
from .base import get_openstack_conn
4-
from .response.identity import Region, Domain
4+
from .response.identity import Domain, Region
55

66

77
class IdentityTools:
@@ -19,7 +19,7 @@ def register_tools(self, mcp: FastMCP):
1919
mcp.tool()(self.create_region)
2020
mcp.tool()(self.delete_region)
2121
mcp.tool()(self.update_region)
22-
22+
2323
mcp.tool()(self.get_domains)
2424
mcp.tool()(self.get_domain)
2525

@@ -103,7 +103,7 @@ def update_region(self, id: str, description: str = "") -> Region:
103103
id=updated_region.id,
104104
description=updated_region.description,
105105
)
106-
106+
107107
def get_domains(self) -> list[Domain]:
108108
"""
109109
Get the list of Identity domains.
@@ -115,7 +115,12 @@ def get_domains(self) -> list[Domain]:
115115
domain_list = []
116116
for domain in conn.identity.domains():
117117
domain_list.append(
118-
Domain(id=domain.id, name=domain.name, description=domain.description, is_enabled=domain.is_enabled),
118+
Domain(
119+
id=domain.id,
120+
name=domain.name,
121+
description=domain.description,
122+
is_enabled=domain.is_enabled,
123+
),
119124
)
120125
return domain_list
121126

@@ -128,8 +133,12 @@ def get_domain(self, id: str) -> Domain:
128133
:return: The Domain object.
129134
"""
130135
conn = get_openstack_conn()
131-
136+
132137
domain = conn.identity.get_domain(domain=id)
133138

134-
return Domain(id=domain.id, name=domain.name, description=domain.description, is_enabled=domain.is_enabled)
135-
139+
return Domain(
140+
id=domain.id,
141+
name=domain.name,
142+
description=domain.description,
143+
is_enabled=domain.is_enabled,
144+
)

tests/tools/test_block_storage_tools.py

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from unittest.mock import Mock
2+
13
import pytest
4+
25
from openstack_mcp_server.tools.block_storage_tools import BlockStorageTools
36
from openstack_mcp_server.tools.response.block_storage import (
47
Volume,
58
VolumeAttachment,
69
)
710

8-
from unittest.mock import Mock
911

1012
class TestBlockStorageTools:
1113
"""Test cases for BlockStorageTools class."""
@@ -74,7 +76,8 @@ def test_get_volumes_success(self, mock_get_openstack_conn_block_storage):
7476
mock_conn.block_storage.volumes.assert_called_once()
7577

7678
def test_get_volumes_empty_list(
77-
self, mock_get_openstack_conn_block_storage
79+
self,
80+
mock_get_openstack_conn_block_storage,
7881
):
7982
"""Test getting volumes when no volumes exist."""
8083
mock_conn = mock_get_openstack_conn_block_storage
@@ -92,7 +95,8 @@ def test_get_volumes_empty_list(
9295
mock_conn.block_storage.volumes.assert_called_once()
9396

9497
def test_get_volumes_single_volume(
95-
self, mock_get_openstack_conn_block_storage
98+
self,
99+
mock_get_openstack_conn_block_storage,
96100
):
97101
"""Test getting volumes with a single volume."""
98102
mock_conn = mock_get_openstack_conn_block_storage
@@ -125,7 +129,8 @@ def test_get_volumes_single_volume(
125129
mock_conn.block_storage.volumes.assert_called_once()
126130

127131
def test_get_volumes_multiple_statuses(
128-
self, mock_get_openstack_conn_block_storage
132+
self,
133+
mock_get_openstack_conn_block_storage,
129134
):
130135
"""Test volumes with various statuses."""
131136
mock_conn = mock_get_openstack_conn_block_storage
@@ -175,7 +180,8 @@ def test_get_volumes_multiple_statuses(
175180
mock_conn.block_storage.volumes.assert_called_once()
176181

177182
def test_get_volumes_with_special_characters(
178-
self, mock_get_openstack_conn_block_storage
183+
self,
184+
mock_get_openstack_conn_block_storage,
179185
):
180186
"""Test volumes with special characters in names."""
181187
mock_conn = mock_get_openstack_conn_block_storage
@@ -229,7 +235,10 @@ def test_get_volumes_with_special_characters(
229235

230236
mock_conn.block_storage.volumes.assert_called_once()
231237

232-
def test_get_volume_details_success(self, mock_get_openstack_conn_block_storage):
238+
def test_get_volume_details_success(
239+
self,
240+
mock_get_openstack_conn_block_storage,
241+
):
233242
"""Test getting volume details successfully."""
234243
mock_conn = mock_get_openstack_conn_block_storage
235244

@@ -268,7 +277,8 @@ def test_get_volume_details_success(self, mock_get_openstack_conn_block_storage)
268277
mock_conn.block_storage.get_volume.assert_called_once_with("vol-123")
269278

270279
def test_get_volume_details_with_attachments(
271-
self, mock_get_openstack_conn_block_storage
280+
self,
281+
mock_get_openstack_conn_block_storage,
272282
):
273283
"""Test getting volume details with attachments."""
274284
mock_conn = mock_get_openstack_conn_block_storage
@@ -323,11 +333,14 @@ def test_get_volume_details_with_attachments(
323333
assert attach2.device == "/dev/vdc"
324334
assert attach2.attachment_id == "attach-2"
325335

326-
def test_get_volume_details_error(self, mock_get_openstack_conn_block_storage):
336+
def test_get_volume_details_error(
337+
self,
338+
mock_get_openstack_conn_block_storage,
339+
):
327340
"""Test getting volume details with error."""
328341
mock_conn = mock_get_openstack_conn_block_storage
329342
mock_conn.block_storage.get_volume.side_effect = Exception(
330-
"Volume not found"
343+
"Volume not found",
331344
)
332345

333346
block_storage_tools = BlockStorageTools()
@@ -336,7 +349,10 @@ def test_get_volume_details_error(self, mock_get_openstack_conn_block_storage):
336349
with pytest.raises(Exception, match="Volume not found"):
337350
block_storage_tools.get_volume_details("nonexistent-vol")
338351

339-
def test_create_volume_success(self, mock_get_openstack_conn_block_storage):
352+
def test_create_volume_success(
353+
self,
354+
mock_get_openstack_conn_block_storage,
355+
):
340356
"""Test creating volume successfully."""
341357
mock_conn = mock_get_openstack_conn_block_storage
342358

@@ -358,7 +374,11 @@ def test_create_volume_success(self, mock_get_openstack_conn_block_storage):
358374

359375
block_storage_tools = BlockStorageTools()
360376
result = block_storage_tools.create_volume(
361-
"new-volume", 10, "Test volume", "ssd", "nova"
377+
"new-volume",
378+
10,
379+
"Test volume",
380+
"ssd",
381+
"nova",
362382
)
363383

364384
# Verify result is a Volume object
@@ -381,7 +401,8 @@ def test_create_volume_success(self, mock_get_openstack_conn_block_storage):
381401
)
382402

383403
def test_create_volume_minimal_params(
384-
self, mock_get_openstack_conn_block_storage
404+
self,
405+
mock_get_openstack_conn_block_storage,
385406
):
386407
"""Test creating volume with minimal parameters."""
387408
mock_conn = mock_get_openstack_conn_block_storage
@@ -410,11 +431,15 @@ def test_create_volume_minimal_params(
410431
assert result.size == 5
411432

412433
mock_conn.block_storage.create_volume.assert_called_once_with(
413-
size=5, image=None, bootable=None, name="minimal-volume"
434+
size=5,
435+
image=None,
436+
bootable=None,
437+
name="minimal-volume",
414438
)
415439

416440
def test_create_volume_with_image_and_bootable(
417-
self, mock_get_openstack_conn_block_storage
441+
self,
442+
mock_get_openstack_conn_block_storage,
418443
):
419444
"""Test creating volume with image and bootable parameters."""
420445
mock_conn = mock_get_openstack_conn_block_storage
@@ -465,15 +490,18 @@ def test_create_volume_error(self, mock_get_openstack_conn_block_storage):
465490
"""Test creating volume with error."""
466491
mock_conn = mock_get_openstack_conn_block_storage
467492
mock_conn.block_storage.create_volume.side_effect = Exception(
468-
"Quota exceeded"
493+
"Quota exceeded",
469494
)
470495

471496
block_storage_tools = BlockStorageTools()
472497

473498
with pytest.raises(Exception, match="Quota exceeded"):
474499
block_storage_tools.create_volume("fail-volume", 100)
475500

476-
def test_delete_volume_success(self, mock_get_openstack_conn_block_storage):
501+
def test_delete_volume_success(
502+
self,
503+
mock_get_openstack_conn_block_storage,
504+
):
477505
"""Test deleting volume successfully."""
478506
mock_conn = mock_get_openstack_conn_block_storage
479507

@@ -490,7 +518,9 @@ def test_delete_volume_success(self, mock_get_openstack_conn_block_storage):
490518
# Verify result is None
491519
assert result is None
492520
mock_conn.block_storage.delete_volume.assert_called_once_with(
493-
"vol-delete", force=False, ignore_missing=False
521+
"vol-delete",
522+
force=False,
523+
ignore_missing=False,
494524
)
495525

496526
def test_delete_volume_force(self, mock_get_openstack_conn_block_storage):
@@ -510,14 +540,16 @@ def test_delete_volume_force(self, mock_get_openstack_conn_block_storage):
510540
assert result is None
511541

512542
mock_conn.block_storage.delete_volume.assert_called_once_with(
513-
"vol-force-delete", force=True, ignore_missing=False
543+
"vol-force-delete",
544+
force=True,
545+
ignore_missing=False,
514546
)
515547

516548
def test_delete_volume_error(self, mock_get_openstack_conn_block_storage):
517549
"""Test deleting volume with error."""
518550
mock_conn = mock_get_openstack_conn_block_storage
519551
mock_conn.block_storage.delete_volume.side_effect = Exception(
520-
"Volume not found"
552+
"Volume not found",
521553
)
522554

523555
block_storage_tools = BlockStorageTools()
@@ -526,7 +558,10 @@ def test_delete_volume_error(self, mock_get_openstack_conn_block_storage):
526558
with pytest.raises(Exception, match="Volume not found"):
527559
block_storage_tools.delete_volume("nonexistent-vol")
528560

529-
def test_extend_volume_success(self, mock_get_openstack_conn_block_storage):
561+
def test_extend_volume_success(
562+
self,
563+
mock_get_openstack_conn_block_storage,
564+
):
530565
"""Test extending volume successfully."""
531566
mock_conn = mock_get_openstack_conn_block_storage
532567

@@ -537,14 +572,18 @@ def test_extend_volume_success(self, mock_get_openstack_conn_block_storage):
537572
assert result is None
538573

539574
mock_conn.block_storage.extend_volume.assert_called_once_with(
540-
"vol-extend", 20
575+
"vol-extend",
576+
20,
541577
)
542578

543-
def test_extend_volume_invalid_size(self, mock_get_openstack_conn_block_storage):
579+
def test_extend_volume_invalid_size(
580+
self,
581+
mock_get_openstack_conn_block_storage,
582+
):
544583
"""Test extending volume with invalid size."""
545584
mock_conn = mock_get_openstack_conn_block_storage
546585
mock_conn.block_storage.extend_volume.side_effect = Exception(
547-
"Invalid size"
586+
"Invalid size",
548587
)
549588

550589
block_storage_tools = BlockStorageTools()
@@ -556,7 +595,7 @@ def test_extend_volume_error(self, mock_get_openstack_conn_block_storage):
556595
"""Test extending volume with error."""
557596
mock_conn = mock_get_openstack_conn_block_storage
558597
mock_conn.block_storage.extend_volume.side_effect = Exception(
559-
"Volume busy"
598+
"Volume busy",
560599
)
561600

562601
block_storage_tools = BlockStorageTools()
@@ -643,4 +682,4 @@ def test_all_block_storage_methods_have_docstrings(self):
643682
)
644683
assert len(docstring.strip()) > 0, (
645684
f"{method_name} docstring should not be empty"
646-
)
685+
)

0 commit comments

Comments
 (0)