@@ -83,16 +83,17 @@ def test_clean_interface_switchport_config_preserves_vlan_1(self, cte_mock):
8383
8484 # Verify that execute_command was called for other switchport lines but not for vlan 1
8585 calls = executor_mock .execute_command .call_args_list
86- # Should be called twice: once for "switchport" and once for "switchport mode dynamic auto"
86+ # Should be called once for "switchport mode dynamic auto"
8787 # but NOT for "switchport trunk allowed vlan 1"
88- self .assertEqual (len (calls ), 2 )
88+ # Note: "switchport" alone (without trailing space) is not matched by the pattern
89+ self .assertEqual (len (calls ), 1 )
8990
90- # Verify the commands that were issued
91+ # Verify the command that was issued
9192 called_commands = [call [1 ]["command" ] for call in calls ]
92- self .assertIn ("switchport" , called_commands )
9393 self .assertIn ("switchport mode dynamic auto" , called_commands )
94- # Ensure vlan 1 command was NOT called
95- self .assertNotIn ("switchport trunk allowed vlan" , called_commands )
94+ # Ensure vlan 1 line was NOT processed (would appear as "switchport trunk allowed vlan" after regex)
95+ for cmd in called_commands :
96+ self .assertNotIn ("trunk allowed vlan" , cmd )
9697
9798 @patch (
9899 "cloudshell.networking.cisco.command_actions.iface_actions"
@@ -118,11 +119,42 @@ def test_clean_interface_switchport_config_removes_other_vlans(self, cte_mock):
118119
119120 # Verify that execute_command was called for all switchport lines including vlan 100
120121 calls = executor_mock .execute_command .call_args_list
121- # Should be called three times: "switchport", "switchport trunk allowed vlan", "switchport mode trunk"
122- self .assertEqual (len (calls ), 3 )
122+ # Should be called twice: "switchport trunk allowed vlan", "switchport mode trunk"
123+ # Note: "switchport" alone (without trailing space) is not matched by the pattern
124+ self .assertEqual (len (calls ), 2 )
123125
124126 # Verify the commands that were issued
125127 called_commands = [call [1 ]["command" ] for call in calls ]
126- self .assertIn ("switchport" , called_commands )
128+ self .assertIn ("switchport trunk allowed vlan" , called_commands )
129+ self .assertIn ("switchport mode trunk" , called_commands )
130+
131+ @patch (
132+ "cloudshell.networking.cisco.command_actions.iface_actions"
133+ ".CommandTemplateExecutor"
134+ )
135+ def test_clean_interface_switchport_config_removes_vlan_1_in_range (self , cte_mock ):
136+ """Test that VLAN 1 in a range or list is still removed (not default state)."""
137+ current_config = """Building configuration...
138+
139+ Current configuration : 144 bytes
140+ !
141+ interface GigabitEthernet110/1/0/6
142+ description Test Port
143+ switchport trunk allowed vlan 1,2,3
144+ switchport mode trunk
145+ end
146+ """
147+ executor_mock = MagicMock ()
148+ cte_mock .return_value = executor_mock
149+
150+ self ._handler .clean_interface_switchport_config (current_config )
151+
152+ # Verify that execute_command was called for VLAN range including vlan 1
153+ calls = executor_mock .execute_command .call_args_list
154+ # Should be called twice: "switchport trunk allowed vlan", "switchport mode trunk"
155+ self .assertEqual (len (calls ), 2 )
156+
157+ # Verify the commands that were issued - vlan 1,2,3 should be removed
158+ called_commands = [call [1 ]["command" ] for call in calls ]
127159 self .assertIn ("switchport trunk allowed vlan" , called_commands )
128160 self .assertIn ("switchport mode trunk" , called_commands )
0 commit comments