@@ -20,6 +20,21 @@ def valid_config_file(self):
20
20
netapp_server_hostname = test-hostname.example.com
21
21
netapp_login = test-user
22
22
netapp_password = test-password-123
23
+ """
24
+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".conf" , delete = False ) as f :
25
+ f .write (config_content )
26
+ f .flush ()
27
+ yield f .name
28
+ os .unlink (f .name )
29
+
30
+ @pytest .fixture
31
+ def config_with_nic_prefix (self ):
32
+ """Create a config file with custom NIC slot prefix."""
33
+ config_content = """[netapp_nvme]
34
+ netapp_server_hostname = test-hostname.example.com
35
+ netapp_login = test-user
36
+ netapp_password = test-password-123
37
+ netapp_nic_slot_prefix = e5
23
38
"""
24
39
with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".conf" , delete = False ) as f :
25
40
f .write (config_content )
@@ -48,6 +63,7 @@ def test_successful_initialization(self, valid_config_file):
48
63
assert config .hostname == "test-hostname.example.com"
49
64
assert config .username == "test-user"
50
65
assert config .password == "test-password-123"
66
+ assert config .netapp_nic_slot_prefix == "e4" # Default value
51
67
assert config .config_path == valid_config_file
52
68
53
69
def test_default_config_path (self ):
@@ -318,6 +334,21 @@ def test_config_with_extra_sections(self, valid_config_file):
318
334
319
335
os .unlink (f .name )
320
336
337
+ def test_netapp_nic_slot_prefix_custom_value (self , config_with_nic_prefix ):
338
+ """Test NetAppConfig with custom NIC slot prefix."""
339
+ config = NetAppConfig (config_with_nic_prefix )
340
+
341
+ assert config .hostname == "test-hostname.example.com"
342
+ assert config .username == "test-user"
343
+ assert config .password == "test-password-123"
344
+ assert config .netapp_nic_slot_prefix == "e5"
345
+
346
+ def test_netapp_nic_slot_prefix_default_value (self , valid_config_file ):
347
+ """Test NetAppConfig uses default NIC slot prefix when not specified."""
348
+ config = NetAppConfig (valid_config_file )
349
+
350
+ assert config .netapp_nic_slot_prefix == "e4"
351
+
321
352
def test_config_with_extra_options (self ):
322
353
"""Test config parsing ignores extra options in netapp_nvme section."""
323
354
config_content = """[netapp_nvme]
@@ -338,3 +369,61 @@ def test_config_with_extra_options(self):
338
369
assert config .password == "test-password"
339
370
340
371
os .unlink (f .name )
372
+ def test_integration_netapp_config_with_from_nautobot_response (self , config_with_nic_prefix ):
373
+ """Test integration between NetAppConfig and NetappIPInterfaceConfig.from_nautobot_response."""
374
+ from unittest .mock import MagicMock
375
+ from understack_workflows .netapp .value_objects import NetappIPInterfaceConfig
376
+ import ipaddress
377
+
378
+ # Create config with custom NIC prefix
379
+ config = NetAppConfig (config_with_nic_prefix )
380
+ assert config .netapp_nic_slot_prefix == "e5"
381
+
382
+ # Create a mock nautobot response
383
+ mock_interface_a = MagicMock ()
384
+ mock_interface_a .name = "N1-test-A"
385
+ mock_interface_a .address = "192.168.1.10/24"
386
+ mock_interface_a .vlan = 100
387
+
388
+ mock_interface_b = MagicMock ()
389
+ mock_interface_b .name = "N1-test-B"
390
+ mock_interface_b .address = "192.168.1.11/24"
391
+ mock_interface_b .vlan = 100
392
+
393
+ mock_response = MagicMock ()
394
+ mock_response .interfaces = [mock_interface_a , mock_interface_b ]
395
+
396
+ # Test that from_nautobot_response uses the custom prefix
397
+ configs = NetappIPInterfaceConfig .from_nautobot_response (mock_response , config )
398
+
399
+ assert len (configs ) == 2
400
+ assert configs [0 ].base_port_name == "e5a"
401
+ assert configs [1 ].base_port_name == "e5b"
402
+ assert configs [0 ].nic_slot_prefix == "e5"
403
+ assert configs [1 ].nic_slot_prefix == "e5"
404
+ def test_from_nautobot_response_default_prefix (self , valid_config_file ):
405
+ """Test that from_nautobot_response uses default prefix when no config provided."""
406
+ from unittest .mock import MagicMock
407
+ from understack_workflows .netapp .value_objects import NetappIPInterfaceConfig
408
+
409
+ # Create a mock nautobot response
410
+ mock_interface = MagicMock ()
411
+ mock_interface .name = "N1-test-A"
412
+ mock_interface .address = "192.168.1.10/24"
413
+ mock_interface .vlan = 100
414
+
415
+ mock_response = MagicMock ()
416
+ mock_response .interfaces = [mock_interface ]
417
+
418
+ # Test without config (should use default)
419
+ configs = NetappIPInterfaceConfig .from_nautobot_response (mock_response )
420
+ assert len (configs ) == 1
421
+ assert configs [0 ].base_port_name == "e4a"
422
+ assert configs [0 ].nic_slot_prefix == "e4"
423
+
424
+ # Test with config that has default prefix
425
+ config = NetAppConfig (valid_config_file )
426
+ configs_with_config = NetappIPInterfaceConfig .from_nautobot_response (mock_response , config )
427
+ assert len (configs_with_config ) == 1
428
+ assert configs_with_config [0 ].base_port_name == "e4a"
429
+ assert configs_with_config [0 ].nic_slot_prefix == "e4"
0 commit comments