Skip to content

Commit 4195520

Browse files
committed
fix: duplicate logging
1 parent 91aec73 commit 4195520

File tree

6 files changed

+12
-83
lines changed

6 files changed

+12
-83
lines changed

python/understack-workflows/tests/test_netapp_configure_net.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,6 @@ def test_netapp_create_interfaces_logs_interface_creation(self):
15421542
# Verify logging was called with correct messages
15431543
expected_calls = [
15441544
(("Creating LIF %s for project %s", "test-interface", project_id),),
1545-
(("Creating routes for project %s", project_id),),
1546-
(("Successfully created %d routes for project %s", 0, project_id),),
15471545
]
15481546
mock_logger.info.assert_has_calls(expected_calls, any_order=False)
15491547

python/understack-workflows/tests/test_netapp_manager.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -500,49 +500,7 @@ def test_create_routes_for_project_error_handling(
500500
"test-project", sample_interface_configs
501501
)
502502

503-
@patch("understack_workflows.netapp.manager.config")
504-
@patch("understack_workflows.netapp.manager.HostConnection")
505-
def test_create_routes_for_project_logging(
506-
self,
507-
mock_host_connection,
508-
mock_config,
509-
mock_config_file,
510-
sample_interface_configs,
511-
):
512-
"""Test create_routes_for_project logging behavior."""
513-
from understack_workflows.netapp.value_objects import RouteResult
514-
515-
manager = NetAppManager(mock_config_file)
516-
517-
# Mock route service
518-
expected_results = [
519-
RouteResult(
520-
uuid="route-uuid-1",
521-
gateway="100.127.0.17",
522-
destination="100.126.0.0/17",
523-
svm_name="os-test-project",
524-
),
525-
]
526-
manager._route_service.create_routes_from_interfaces = MagicMock(
527-
return_value=expected_results
528-
)
529-
530-
with patch("understack_workflows.netapp.manager.logger") as mock_logger:
531-
result = manager.create_routes_for_project(
532-
"test-project", sample_interface_configs
533-
)
534503

535-
# Verify logging calls
536-
mock_logger.info.assert_any_call(
537-
"Creating routes for project %(project_id)s with %(count)d interfaces",
538-
{"project_id": "test-project", "count": 3},
539-
)
540-
mock_logger.info.assert_any_call(
541-
"Successfully created %(count)d routes for project %(project_id)s",
542-
{"count": 1, "project_id": "test-project"},
543-
)
544-
545-
assert result == expected_results
546504

547505
@patch("understack_workflows.netapp.manager.config")
548506
@patch("understack_workflows.netapp.manager.HostConnection")

python/understack-workflows/tests/test_netapp_route_service.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ def test_create_routes_from_interfaces_success(
104104
assert isinstance(route_specs[0], RouteSpec)
105105
assert route_specs[0].svm_name == expected_svm_name
106106
assert route_specs[0].gateway in ["100.127.0.17", "100.127.128.17"]
107-
assert route_specs[0].destination in ["100.126.0.0/17", "100.126.128.0/17"]
107+
assert route_specs[0].destination in [ipaddress.IPv4Network("100.126.0.0/17"), ipaddress.IPv4Network("100.126.128.0/17")]
108108

109109
# Check second route spec
110110
assert isinstance(route_specs[1], RouteSpec)
111111
assert route_specs[1].svm_name == expected_svm_name
112112
assert route_specs[1].gateway in ["100.127.0.17", "100.127.128.17"]
113-
assert route_specs[1].destination in ["100.126.0.0/17", "100.126.128.0/17"]
113+
assert route_specs[1].destination in [ipaddress.IPv4Network("100.126.0.0/17"), ipaddress.IPv4Network("100.126.128.0/17")]
114114

115115
# Verify different gateways were used
116116
gateways = {spec.gateway for spec in route_specs}
@@ -169,7 +169,7 @@ def test_create_routes_from_interfaces_single_route(
169169
assert isinstance(call_args, RouteSpec)
170170
assert call_args.svm_name == expected_svm_name
171171
assert call_args.gateway == "100.127.0.17"
172-
assert call_args.destination == "100.126.0.0/17"
172+
assert call_args.destination == ipaddress.IPv4Network("100.126.0.0/17")
173173

174174
def test_create_routes_from_interfaces_empty_list(
175175
self, route_service, mock_client, mock_error_handler
@@ -185,8 +185,8 @@ def test_create_routes_from_interfaces_empty_list(
185185
# Verify client was not called
186186
mock_client.create_route.assert_not_called()
187187

188-
# Verify logging
189-
mock_error_handler.log_info.assert_called()
188+
# Verify logging - no logging expected for empty list
189+
mock_error_handler.log_info.assert_not_called()
190190

191191
def test_create_routes_from_interfaces_route_creation_error(
192192
self, route_service, mock_client, mock_error_handler, sample_interface_configs
@@ -385,9 +385,9 @@ def test_route_spec_creation_from_nexthop(
385385
# Find specs by gateway to verify destinations
386386
for spec in route_specs:
387387
if spec.gateway == "100.127.0.17":
388-
assert spec.destination == "100.126.0.0/17"
388+
assert spec.destination == ipaddress.IPv4Network("100.126.0.0/17")
389389
elif spec.gateway == "100.127.128.17":
390-
assert spec.destination == "100.126.128.0/17"
390+
assert spec.destination == ipaddress.IPv4Network("100.126.128.0/17")
391391
else:
392392
pytest.fail(f"Unexpected gateway: {spec.gateway}")
393393

@@ -423,17 +423,15 @@ def test_logging_behavior(
423423
log_info_calls = mock_error_handler.log_info.call_args_list
424424
log_debug_calls = mock_error_handler.log_debug.call_args_list
425425

426-
# Should have info logs for: start, each route creation, completion
427-
assert len(log_info_calls) >= 4 # start + 2 routes + completion
426+
# Should have info logs for: each route creation (no start/completion logs)
427+
assert len(log_info_calls) >= 2 # 2 routes created
428428

429429
# Should have debug logs for nexthop extraction
430430
assert len(log_debug_calls) >= 1
431431

432432
# Verify specific log messages
433433
log_messages = [call[0][0] for call in log_info_calls]
434-
assert any("Creating routes for project" in msg for msg in log_messages)
435434
assert any("Created route:" in msg for msg in log_messages)
436-
assert any("Successfully created" in msg for msg in log_messages)
437435

438436
def test_create_routes_netapp_rest_error_handling(
439437
self, route_service, mock_client, mock_error_handler, sample_interface_configs

python/understack-workflows/understack_workflows/main/netapp_configure_net.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,13 @@ def netapp_create_interfaces_and_routes(
359359
nautobot_response, mgr.config
360360
)
361361

362-
# Create LIF interfaces (existing functionality)
362+
# Create LIF interfaces
363363
for interface_config in configs:
364364
logger.info("Creating LIF %s for project %s", interface_config.name, project_id)
365365
mgr.create_lif(project_id, interface_config)
366366

367-
# Create routes (new functionality)
368-
logger.info("Creating routes for project %s", project_id)
369-
route_results = mgr.create_routes_for_project(project_id, configs)
370-
371-
logger.info(
372-
"Successfully created %d routes for project %s", len(route_results), project_id
373-
)
367+
# Create routes
368+
mgr.create_routes_for_project(project_id, configs)
374369
return
375370

376371

python/understack-workflows/understack_workflows/netapp/manager.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,21 +476,11 @@ def create_routes_for_project(
476476
Raises:
477477
NetworkOperationError: If route creation fails
478478
"""
479-
logger.info(
480-
"Creating routes for project %(project_id)s with %(count)d interfaces",
481-
{"project_id": project_id, "count": len(interface_configs)},
482-
)
483-
484479
try:
485480
results = self._route_service.create_routes_from_interfaces(
486481
project_id, interface_configs
487482
)
488483

489-
logger.info(
490-
"Successfully created %(count)d routes for project %(project_id)s",
491-
{"count": len(results), "project_id": project_id},
492-
)
493-
494484
return results
495485

496486
except Exception as e:

python/understack-workflows/understack_workflows/netapp/route_service.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ def create_routes_from_interfaces(
4545
NetworkOperationError: If route creation fails
4646
"""
4747
try:
48-
self._error_handler.log_info(
49-
"Creating routes for project %(project_id)s",
50-
{"project_id": project_id},
51-
)
52-
5348
# Extract unique nexthop addresses
5449
unique_nexthops = self._extract_unique_nexthops(interface_configs)
5550

@@ -89,11 +84,6 @@ def create_routes_from_interfaces(
8984
},
9085
)
9186

92-
self._error_handler.log_info(
93-
"Successfully created %(count)d routes for project %(project_id)s",
94-
{"count": len(results), "project_id": project_id},
95-
)
96-
9787
return results
9888

9989
except Exception as e:

0 commit comments

Comments
 (0)