@@ -164,8 +164,88 @@ def test_mirror_session_span_add():
164
164
assert result .exit_code != 0
165
165
assert ERR_MSG_VALUE_FAILURE in result .stdout
166
166
167
+ # Verify invalid dst port
168
+ result = runner .invoke (
169
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
170
+ ["test_session" , "Ethern" , "Ethernet4" , "rx" , "100" ])
171
+ assert result .exit_code != 0
172
+ assert "Error: Destination Interface Ethern is invalid" in result .stdout
173
+
174
+ # Verify destination port not have vlan config
175
+ result = runner .invoke (
176
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
177
+ ["test_session" , "Ethernet24" , "Ethernet4" , "rx" , "100" ])
178
+ assert result .exit_code != 0
179
+ assert "Error: Destination Interface Ethernet24 has vlan config" in result .stdout
180
+
181
+ # Verify destination port is not part of portchannel
182
+ result = runner .invoke (
183
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
184
+ ["test_session" , "Ethernet116" , "Ethernet4" , "rx" , "100" ])
185
+ assert result .exit_code != 0
186
+ assert "Error: Destination Interface Ethernet116 has portchannel config" in result .stdout
187
+
188
+ # Verify destination port not router interface
189
+ result = runner .invoke (
190
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
191
+ ["test_session" , "Ethernet0" , "Ethernet4" , "rx" , "100" ])
192
+ assert result .exit_code != 0
193
+ assert "Error: Destination Interface Ethernet0 is a L3 interface" in result .stdout
194
+
195
+ # Verify destination port not Portchannel
196
+ result = runner .invoke (
197
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
198
+ ["test_session" , "PortChannel1001" ])
199
+ assert result .exit_code != 0
200
+ assert "Error: Destination Interface PortChannel1001 is not supported" in result .output
201
+
202
+ # Verify source interface is invalid
203
+ result = runner .invoke (
204
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
205
+ ["test_session" , "Ethernet52" , "Ethern" , "rx" , "100" ])
206
+ assert result .exit_code != 0
207
+ assert "Error: Source Interface Ethern is invalid" in result .stdout
208
+
209
+ # Verify source interface is not same as destination
210
+ result = runner .invoke (
211
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
212
+ ["test_session" , "Ethernet52" , "Ethernet52" , "rx" , "100" ])
213
+ assert result .exit_code != 0
214
+ assert "Error: Destination Interface cant be same as Source Interface" in result .stdout
215
+
216
+ # Verify destination port not have mirror config
217
+ result = runner .invoke (
218
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
219
+ ["test_session" , "Ethernet44" , "Ethernet56" , "rx" , "100" ])
220
+ assert result .exit_code != 0
221
+ assert "Error: Destination Interface Ethernet44 already has mirror config" in result .output
222
+
223
+ # Verify source port is not configured as dstport in other session
224
+ result = runner .invoke (
225
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
226
+ ["test_session" , "Ethernet52" , "Ethernet44" , "rx" , "100" ])
227
+ assert result .exit_code != 0
228
+ assert "Error: Source Interface Ethernet44 already has mirror config" in result .output
229
+
230
+ # Verify source port is not configured in same direction
231
+ result = runner .invoke (
232
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
233
+ ["test_session" , "Ethernet52" , "Ethernet8,Ethernet40" , "rx" , "100" ])
234
+ assert result .exit_code != 0
235
+ assert "Error: Source Interface Ethernet40 already has mirror config in same direction" in result .output
236
+
237
+ # Verify direction is invalid
238
+ result = runner .invoke (
239
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
240
+ ["test_session" , "Ethernet52" , "Ethernet56" , "px" , "100" ])
241
+ assert result .exit_code != 0
242
+ assert "Error: Direction px is invalid" in result .stdout
243
+
167
244
# Positive case
168
245
with mock .patch ('config.main.add_span' ) as mocked :
246
+ result = runner .invoke (
247
+ config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
248
+ ["test_session" , "Ethernet8" , "Ethernet4" , "tx" , "100" ])
169
249
result = runner .invoke (
170
250
config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
171
251
["test_session" , "Ethernet0" , "Ethernet4" , "rx" , "100" ])
0 commit comments