@@ -58,3 +58,71 @@ def test_get_no_l2_protocol_tunnel_cmd(self, vlan_templates_mock, cte_mock):
5858 error_map = None ,
5959 )
6060 self .assertEqual (result , cte_mock .return_value )
61+
62+ @patch (
63+ "cloudshell.networking.cisco.command_actions.iface_actions"
64+ ".CommandTemplateExecutor"
65+ )
66+ def test_clean_interface_switchport_config_preserves_vlan_1 (self , cte_mock ):
67+ """Test that switchport trunk allowed vlan 1 is not removed (default state)."""
68+ current_config = """Building configuration...
69+
70+ Current configuration : 144 bytes
71+ !
72+ interface GigabitEthernet110/1/0/6
73+ description KG-255X-06-PT
74+ switchport
75+ switchport trunk allowed vlan 1
76+ switchport mode dynamic auto
77+ end
78+ """
79+ executor_mock = MagicMock ()
80+ cte_mock .return_value = executor_mock
81+
82+ self ._handler .clean_interface_switchport_config (current_config )
83+
84+ # Verify that execute_command was called for other switchport lines but not for vlan 1
85+ calls = executor_mock .execute_command .call_args_list
86+ # Should be called twice: once for "switchport" and once for "switchport mode dynamic auto"
87+ # but NOT for "switchport trunk allowed vlan 1"
88+ self .assertEqual (len (calls ), 2 )
89+
90+ # Verify the commands that were issued
91+ called_commands = [call [1 ]["command" ] for call in calls ]
92+ self .assertIn ("switchport" , called_commands )
93+ 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 )
96+
97+ @patch (
98+ "cloudshell.networking.cisco.command_actions.iface_actions"
99+ ".CommandTemplateExecutor"
100+ )
101+ def test_clean_interface_switchport_config_removes_other_vlans (self , cte_mock ):
102+ """Test that switchport trunk allowed vlan with other VLANs are removed."""
103+ current_config = """Building configuration...
104+
105+ Current configuration : 144 bytes
106+ !
107+ interface GigabitEthernet110/1/0/6
108+ description KG-255X-06-PT
109+ switchport
110+ switchport trunk allowed vlan 100
111+ switchport mode trunk
112+ end
113+ """
114+ executor_mock = MagicMock ()
115+ cte_mock .return_value = executor_mock
116+
117+ self ._handler .clean_interface_switchport_config (current_config )
118+
119+ # Verify that execute_command was called for all switchport lines including vlan 100
120+ 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 )
123+
124+ # Verify the commands that were issued
125+ called_commands = [call [1 ]["command" ] for call in calls ]
126+ self .assertIn ("switchport" , called_commands )
127+ self .assertIn ("switchport trunk allowed vlan" , called_commands )
128+ self .assertIn ("switchport mode trunk" , called_commands )
0 commit comments