Skip to content

Commit cd9363c

Browse files
committed
split address before calling NetApp API
Turns out they require the address and netmask to be provided separately, otherwise it silently changes to 0.0.0.0/0
1 parent 4195520 commit cd9363c

File tree

7 files changed

+131
-81
lines changed

7 files changed

+131
-81
lines changed

python/understack-workflows/tests/test_netapp_client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for NetAppClient abstraction layer."""
22

3+
import ipaddress
34
from unittest.mock import MagicMock
45
from unittest.mock import Mock
56
from unittest.mock import patch
@@ -532,21 +533,24 @@ def test_create_route_success(self, mock_route_class, netapp_client):
532533
route_spec = RouteSpec(
533534
svm_name="os-test-project",
534535
gateway="100.127.0.17",
535-
destination="100.126.0.0/17",
536+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
536537
)
537538

538539
result = netapp_client.create_route(route_spec)
539540

540541
# Verify route configuration
541542
assert mock_route_instance.svm == {"name": "os-test-project"}
542543
assert mock_route_instance.gateway == "100.127.0.17"
543-
assert mock_route_instance.destination == "100.126.0.0/17"
544+
assert mock_route_instance.destination == {
545+
"address": "100.126.0.0",
546+
"netmask": "255.255.128.0",
547+
}
544548
mock_route_instance.post.assert_called_once_with(hydrate=True)
545549

546550
# Verify result
547551
assert result.uuid == "route-uuid-123"
548552
assert result.gateway == "100.127.0.17"
549-
assert result.destination == "100.126.0.0/17"
553+
assert result.destination == ipaddress.IPv4Network("100.126.0.0/17")
550554
assert result.svm_name == "os-test-project"
551555

552556
@patch("understack_workflows.netapp.client.NetworkRoute")
@@ -568,7 +572,7 @@ def test_create_route_netapp_rest_error(self, mock_route_class, netapp_client):
568572
route_spec = RouteSpec(
569573
svm_name="os-nonexistent-project",
570574
gateway="100.127.0.17",
571-
destination="100.126.0.0/17",
575+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
572576
)
573577

574578
with pytest.raises(NetworkOperationError):
@@ -581,7 +585,7 @@ def test_create_route_netapp_rest_error(self, mock_route_class, netapp_client):
581585
assert call_args[0][1] == "Route creation"
582586
assert call_args[0][2]["svm_name"] == "os-nonexistent-project"
583587
assert call_args[0][2]["gateway"] == "100.127.0.17"
584-
assert call_args[0][2]["destination"] == "100.126.0.0/17"
588+
assert call_args[0][2]["destination"] == ipaddress.IPv4Network("100.126.0.0/17")
585589

586590
@patch("understack_workflows.netapp.client.NetworkRoute")
587591
def test_create_route_invalid_svm_error(self, mock_route_class, netapp_client):
@@ -604,7 +608,7 @@ def test_create_route_invalid_svm_error(self, mock_route_class, netapp_client):
604608
route_spec = RouteSpec(
605609
svm_name="os-invalid-svm",
606610
gateway="100.127.0.17",
607-
destination="100.126.0.0/17",
611+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
608612
)
609613

610614
with pytest.raises(NetworkOperationError):
@@ -637,7 +641,7 @@ def test_create_route_gateway_unreachable_error(
637641
route_spec = RouteSpec(
638642
svm_name="os-test-project",
639643
gateway="192.168.1.1", # Invalid gateway for this network
640-
destination="100.126.0.0/17",
644+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
641645
)
642646

643647
with pytest.raises(NetworkOperationError):
@@ -646,7 +650,7 @@ def test_create_route_gateway_unreachable_error(
646650
# Verify error context includes gateway information
647651
call_args = netapp_client._error_handler.handle_netapp_error.call_args
648652
assert call_args[0][2]["gateway"] == "192.168.1.1"
649-
assert call_args[0][2]["destination"] == "100.126.0.0/17"
653+
assert call_args[0][2]["destination"] == ipaddress.IPv4Network("100.126.0.0/17")
650654

651655
@patch("understack_workflows.netapp.client.NetworkRoute")
652656
def test_create_route_logging_behavior(self, mock_route_class, netapp_client):
@@ -658,7 +662,7 @@ def test_create_route_logging_behavior(self, mock_route_class, netapp_client):
658662
route_spec = RouteSpec(
659663
svm_name="os-logging-test",
660664
gateway="100.127.128.17",
661-
destination="100.126.128.0/17",
665+
destination=ipaddress.IPv4Network("100.126.128.0/17"),
662666
)
663667

664668
netapp_client.create_route(route_spec)
@@ -687,7 +691,9 @@ def test_create_route_logging_behavior(self, mock_route_class, netapp_client):
687691
# Verify route start log
688692
assert len(route_start_logs) == 1
689693
start_log = route_start_logs[0]
690-
assert start_log[0][1]["destination"] == "100.126.128.0/17"
694+
assert start_log[0][1]["destination"] == ipaddress.IPv4Network(
695+
"100.126.128.0/17"
696+
)
691697
assert start_log[0][1]["gateway"] == "100.127.128.17"
692698
assert start_log[0][1]["svm_name"] == "os-logging-test"
693699

python/understack-workflows/tests/test_netapp_configure_net_integration.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import pathlib
3+
from ipaddress import IPv4Network
34
from unittest.mock import Mock
45
from unittest.mock import patch
56

@@ -954,13 +955,13 @@ def test_complete_route_creation_workflow_with_complex_sample(
954955
RouteResult(
955956
uuid="route-uuid-1",
956957
gateway="100.127.0.17",
957-
destination="100.126.0.0/17",
958+
destination=IPv4Network("100.126.0.0/17"),
958959
svm_name="os-12345678123456789abc123456789012",
959960
),
960961
RouteResult(
961962
uuid="route-uuid-2",
962963
gateway="100.127.128.17",
963-
destination="100.126.128.0/17",
964+
destination=IPv4Network("100.126.128.0/17"),
964965
svm_name="os-12345678123456789abc123456789012",
965966
),
966967
]
@@ -1054,13 +1055,13 @@ def test_route_creation_with_mocked_netapp_sdk(
10541055
RouteResult(
10551056
uuid="route-uuid-1",
10561057
gateway="100.127.0.17",
1057-
destination="100.126.0.0/17",
1058+
destination=IPv4Network("100.126.0.0/17"),
10581059
svm_name="os-12345678123456789abc123456789012",
10591060
),
10601061
RouteResult(
10611062
uuid="route-uuid-2",
10621063
gateway="100.127.128.17",
1063-
destination="100.126.128.0/17",
1064+
destination=IPv4Network("100.126.128.0/17"),
10641065
svm_name="os-12345678123456789abc123456789012",
10651066
),
10661067
]
@@ -1469,13 +1470,13 @@ def test_route_creation_logging_verification(
14691470
RouteResult(
14701471
uuid="route-uuid-1",
14711472
gateway="100.127.0.17",
1472-
destination="100.126.0.0/17",
1473+
destination=IPv4Network("100.126.0.0/17"),
14731474
svm_name="os-12345678123456789abc123456789012",
14741475
),
14751476
RouteResult(
14761477
uuid="route-uuid-2",
14771478
gateway="100.127.128.17",
1478-
destination="100.126.128.0/17",
1479+
destination=IPv4Network("100.126.128.0/17"),
14791480
svm_name="os-12345678123456789abc123456789012",
14801481
),
14811482
]
@@ -1548,7 +1549,7 @@ def test_route_creation_with_single_interface_sample(
15481549
RouteResult(
15491550
uuid="route-uuid-1",
15501551
gateway="100.127.0.17",
1551-
destination="100.126.0.0/17",
1552+
destination=IPv4Network("100.126.0.0/17"),
15521553
svm_name="os-12345678123456789abc123456789012",
15531554
),
15541555
]

python/understack-workflows/tests/test_netapp_manager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ def test_create_routes_for_project_delegates_to_service(
448448
RouteResult(
449449
uuid="route-uuid-1",
450450
gateway="100.127.0.17",
451-
destination="100.126.0.0/17",
451+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
452452
svm_name="os-test-project",
453453
),
454454
RouteResult(
455455
uuid="route-uuid-2",
456456
gateway="100.127.128.17",
457-
destination="100.126.128.0/17",
457+
destination=ipaddress.IPv4Network("100.126.128.0/17"),
458458
svm_name="os-test-project",
459459
),
460460
]
@@ -500,8 +500,6 @@ def test_create_routes_for_project_error_handling(
500500
"test-project", sample_interface_configs
501501
)
502502

503-
504-
505503
@patch("understack_workflows.netapp.manager.config")
506504
@patch("understack_workflows.netapp.manager.HostConnection")
507505
def test_create_routes_for_project_empty_interfaces(

python/understack-workflows/tests/test_netapp_route_service.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def test_create_routes_from_interfaces_success(
7373
RouteResult(
7474
uuid="route-uuid-1",
7575
gateway="100.127.0.17",
76-
destination="100.126.0.0/17",
76+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
7777
svm_name=expected_svm_name,
7878
),
7979
RouteResult(
8080
uuid="route-uuid-2",
8181
gateway="100.127.128.17",
82-
destination="100.126.128.0/17",
82+
destination=ipaddress.IPv4Network("100.126.128.0/17"),
8383
svm_name=expected_svm_name,
8484
),
8585
]
@@ -104,13 +104,19 @@ 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 [ipaddress.IPv4Network("100.126.0.0/17"), ipaddress.IPv4Network("100.126.128.0/17")]
107+
assert route_specs[0].destination in [
108+
ipaddress.IPv4Network("100.126.0.0/17"),
109+
ipaddress.IPv4Network("100.126.128.0/17"),
110+
]
108111

109112
# Check second route spec
110113
assert isinstance(route_specs[1], RouteSpec)
111114
assert route_specs[1].svm_name == expected_svm_name
112115
assert route_specs[1].gateway in ["100.127.0.17", "100.127.128.17"]
113-
assert route_specs[1].destination in [ipaddress.IPv4Network("100.126.0.0/17"), ipaddress.IPv4Network("100.126.128.0/17")]
116+
assert route_specs[1].destination in [
117+
ipaddress.IPv4Network("100.126.0.0/17"),
118+
ipaddress.IPv4Network("100.126.128.0/17"),
119+
]
114120

115121
# Verify different gateways were used
116122
gateways = {spec.gateway for spec in route_specs}
@@ -148,7 +154,7 @@ def test_create_routes_from_interfaces_single_route(
148154
route_result = RouteResult(
149155
uuid="route-uuid-1",
150156
gateway="100.127.0.17",
151-
destination="100.126.0.0/17",
157+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
152158
svm_name=expected_svm_name,
153159
)
154160
mock_client.create_route.return_value = route_result
@@ -219,7 +225,7 @@ def test_create_routes_from_interfaces_partial_failure(
219225
route_result = RouteResult(
220226
uuid="route-uuid-1",
221227
gateway="100.127.0.17",
222-
destination="100.126.0.0/17",
228+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
223229
svm_name=expected_svm_name,
224230
)
225231
mock_client.create_route.side_effect = [
@@ -323,7 +329,7 @@ def test_svm_name_generation(
323329
route_result = RouteResult(
324330
uuid="route-uuid-1",
325331
gateway="100.127.0.17",
326-
destination="100.126.0.0/17",
332+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
327333
svm_name=expected_svm_name,
328334
)
329335
mock_client.create_route.return_value = route_result
@@ -365,13 +371,13 @@ def test_route_spec_creation_from_nexthop(
365371
RouteResult(
366372
uuid="route-uuid-1",
367373
gateway="100.127.0.17",
368-
destination="100.126.0.0/17",
374+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
369375
svm_name=expected_svm_name,
370376
),
371377
RouteResult(
372378
uuid="route-uuid-2",
373379
gateway="100.127.128.17",
374-
destination="100.126.128.0/17",
380+
destination=ipaddress.IPv4Network("100.126.128.0/17"),
375381
svm_name=expected_svm_name,
376382
),
377383
]
@@ -403,13 +409,13 @@ def test_logging_behavior(
403409
RouteResult(
404410
uuid="route-uuid-1",
405411
gateway="100.127.0.17",
406-
destination="100.126.0.0/17",
412+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
407413
svm_name=expected_svm_name,
408414
),
409415
RouteResult(
410416
uuid="route-uuid-2",
411417
gateway="100.127.128.17",
412-
destination="100.126.128.0/17",
418+
destination=ipaddress.IPv4Network("100.126.128.0/17"),
413419
svm_name=expected_svm_name,
414420
),
415421
]
@@ -544,7 +550,7 @@ def test_create_routes_partial_success_with_error(
544550
route_result = RouteResult(
545551
uuid="route-uuid-1",
546552
gateway="100.127.0.17",
547-
destination="100.126.0.0/17",
553+
destination=ipaddress.IPv4Network("100.126.0.0/17"),
548554
svm_name=expected_svm_name,
549555
)
550556
netapp_error = NetAppRestError("Second route creation failed")

0 commit comments

Comments
 (0)