forked from internap/fake-switches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cisco_switch_protocol.py
1549 lines (1279 loc) · 56.9 KB
/
test_cisco_switch_protocol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2015-2016 Internap.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from tests.cisco import enable, create_interface_vlan, configuring, configuring_interface_vlan, \
assert_interface_configuration, remove_vlan, create_vlan, set_interface_on_vlan, configuring_interface, \
revert_switchport_mode_access, create_port_channel_interface, configuring_port_channel
from tests.util.protocol_util import SshTester, TelnetTester, with_protocol, ProtocolTest
class TestCiscoSwitchProtocol(ProtocolTest):
__test__ = False
test_switch = "cisco"
@with_protocol
def test_enable_command_requires_a_password(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible(t.conf["extra"]["password"])
t.read("my_switch#")
@with_protocol
def test_wrong_password(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible("hello_world")
t.readln("% Access denied")
t.readln("")
t.read("my_switch>")
@with_protocol
def test_no_password_works_for_legacy_reasons(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible("")
t.read("my_switch#")
@with_protocol
def test_exiting_loses_the_connection(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible(t.conf["extra"]["password"])
t.read("my_switch#")
t.write("exit")
t.read_eof()
@with_protocol
def test_no_such_command_return_to_prompt(self, t):
enable(t)
t.write("shizzle")
t.readln("No such command : shizzle")
t.read("my_switch#")
@with_protocol
@mock.patch("fake_switches.adapters.tftp_reader.read_tftp")
def test_command_copy_failing(self, t, read_tftp):
read_tftp.side_effect = Exception("Stuff")
enable(t)
t.write("copy tftp://1.2.3.4/my-file system:/running-config")
t.read("Destination filename [running-config]? ")
t.write("gneh")
t.readln("Accessing tftp://1.2.3.4/my-file...")
t.readln("Error opening tftp://1.2.3.4/my-file (Timed out)")
t.read("my_switch#")
read_tftp.assert_called_with("1.2.3.4", "my-file")
@with_protocol
@mock.patch("fake_switches.adapters.tftp_reader.read_tftp")
def test_command_copy_success(self, t, read_tftp):
enable(t)
t.write("copy tftp://1.2.3.4/my-file system:/running-config")
t.read("Destination filename [running-config]? ")
t.write_raw("\r")
t.wait_for("\r\n")
t.readln("Accessing tftp://1.2.3.4/my-file...")
t.readln("Done (or some official message...)")
t.read("my_switch#")
read_tftp.assert_called_with("1.2.3.4", "my-file")
@with_protocol
def test_command_show_run_int_vlan_empty(self, t):
enable(t)
t.write("terminal length 0")
t.read("my_switch#")
t.write("show run vlan 120")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("end")
t.readln("")
t.read("my_switch#")
@with_protocol
def test_command_add_vlan(self, t):
enable(t)
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("vlan 123")
t.read("my_switch(config-vlan)#")
t.write("name shizzle")
t.read("my_switch(config-vlan)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
t.write("show run vlan 123")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("!")
t.readln("vlan 123")
t.readln(" name shizzle")
t.readln("end")
t.readln("")
t.read("my_switch#")
remove_vlan(t, "123")
t.write("show running-config vlan 123")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("end")
t.read("")
@with_protocol
def test_command_assign_access_vlan_to_port(self, t):
enable(t)
create_vlan(t, "123")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
" switchport access vlan 123",
" switchport mode access",
"end"])
configuring_interface(t, "FastEthernet0/1", do="no switchport access vlan")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
" switchport mode access",
"end"])
configuring_interface(t, "FastEthernet0/1", do="no switchport mode access")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
"end"])
remove_vlan(t, "123")
@with_protocol
def test_show_vlan_brief(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "3333", "some-name")
create_vlan(t, "2222", "your-name-is-way-too-long-for-this-pretty-printed-interface-man")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
t.write("show vlan brief")
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5")
t.readln(" Fa0/6, Fa0/7, Fa0/8, Fa0/9")
t.readln(" Fa0/10, Fa0/11, Fa0/12")
t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
t.read("my_switch#")
revert_switchport_mode_access(t, "FastEthernet0/1")
remove_vlan(t, "123")
remove_vlan(t, "2222")
remove_vlan(t, "3333")
@with_protocol
def test_show_vlan(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "3333", "some-name")
create_vlan(t, "2222", "your-name-is-way-too-long-for-this-pretty-printed-interface-man")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
t.write("show vlan")
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5")
t.readln(" Fa0/6, Fa0/7, Fa0/8, Fa0/9")
t.readln(" Fa0/10, Fa0/11, Fa0/12")
t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
t.readln("")
t.readln("VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2")
t.readln("---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------")
t.readln("1 enet 100001 1500 - - - - - 0 0")
t.readln("123 enet 100123 1500 - - - - - 0 0")
t.readln("2222 enet 102222 1500 - - - - - 0 0")
t.readln("3333 enet 103333 1500 - - - - - 0 0")
t.readln("")
t.readln("Remote SPAN VLANs")
t.readln("------------------------------------------------------------------------------")
t.readln("")
t.readln("")
t.readln("Primary Secondary Type Ports")
t.readln("------- --------- ----------------- ------------------------------------------")
t.readln("")
t.read("my_switch#")
revert_switchport_mode_access(t, "FastEthernet0/1")
remove_vlan(t, "123")
remove_vlan(t, "2222")
remove_vlan(t, "3333")
@with_protocol
def test_shutting_down(self, t):
enable(t)
configuring_interface(t, "FastEthernet 0/3", do="shutdown")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" shutdown",
"end"])
configuring_interface(t, "FastEthernet 0/3", do="no shutdown")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"])
@with_protocol
def test_configure_trunk_port(self, t):
enable(t)
configuring_interface(t, "Fa0/3", do="switchport mode trunk")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
# not really added because all vlan are in trunk by default on cisco
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 123")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan none")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan none",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 123")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 124,126-128")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123,124,126-128",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan remove 123-124,127")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 126,128",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan all")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan 123-124,127")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123,124,127",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="no switchport trunk allowed vlan")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="no switchport mode")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"])
@with_protocol
def test_configure_native_vlan(self, t):
enable(t)
configuring_interface(t, "FastEthernet0/2", do="switchport trunk native vlan 555")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
" switchport trunk native vlan 555",
"end"])
configuring_interface(t, "FastEthernet0/2", do="no switchport trunk native vlan")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
"end"])
@with_protocol
def test_setup_an_interface(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do="description hey ho")
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.2 255.255.255.0")
configuring_interface_vlan(t, "2999", do="standby 1 ip 1.1.1.1")
configuring_interface_vlan(t, "2999", do='standby 1 timers 5 15')
configuring_interface_vlan(t, "2999", do='standby 1 priority 110')
configuring_interface_vlan(t, "2999", do='standby 1 preempt delay minimum 60')
configuring_interface_vlan(t, "2999", do='standby 1 authentication VLAN2999')
configuring_interface_vlan(t, "2999", do='standby 1 track 10 decrement 50')
configuring_interface_vlan(t, "2999", do='standby 1 track 20 decrement 50')
configuring_interface_vlan(t, "2999", do='no ip proxy-arp')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 1.1.1.2 255.255.255.0",
" no ip proxy-arp",
" standby 1 ip 1.1.1.1",
" standby 1 timers 5 15",
" standby 1 priority 110",
" standby 1 preempt delay minimum 60",
" standby 1 authentication VLAN2999",
" standby 1 track 10 decrement 50",
" standby 1 track 20 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "2999", do="standby 1 ip 2.2.2.1")
configuring_interface_vlan(t, "2999", do="standby 1 ip 2.2.2.3 secondary")
configuring_interface_vlan(t, "2999", do="no standby 1 authentication")
configuring_interface_vlan(t, "2999", do="standby 1 preempt delay minimum 42")
configuring_interface_vlan(t, "2999", do="no standby 1 priority")
configuring_interface_vlan(t, "2999", do="no standby 1 timers")
configuring_interface_vlan(t, "2999", do="no standby 1 track 10")
configuring_interface_vlan(t, "2999", do="ip proxy-arp")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 ip 2.2.2.1",
" standby 1 ip 2.2.2.3 secondary",
" standby 1 preempt delay minimum 42",
" standby 1 track 20 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 ip 2.2.2.3")
configuring_interface_vlan(t, "2999", do="no standby 1 preempt delay")
configuring_interface_vlan(t, "2999", do="no standby 1 track 20")
configuring_interface_vlan(t, "2999", do="")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 ip 2.2.2.1",
" standby 1 preempt",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 ip 2.2.2.1")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 preempt",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1")
configuring_interface_vlan(t, "2999", do="no description")
configuring_interface_vlan(t, "2999", do="")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 2.2.2.2 255.255.255.0",
"end"])
configuring(t, do="no interface vlan 2999")
t.write("show run int vlan 2999")
t.readln("\s*\^", regex=True)
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#")
remove_vlan(t, "2999")
@with_protocol
def test_partial_standby_properties(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do='standby 1 timers 5 15')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 timers 5 15",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 timers")
configuring_interface_vlan(t, "2999", do='standby 1 priority 110')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 priority 110",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 priority")
configuring_interface_vlan(t, "2999", do='standby 1 preempt delay minimum 60')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 preempt delay minimum 60",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 preempt")
configuring_interface_vlan(t, "2999", do='standby 1 authentication VLAN2999')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 authentication VLAN2999",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 authentication")
configuring_interface_vlan(t, "2999", do='standby 1 track 10 decrement 50')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 track 10 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 track 10")
configuring(t, do="no interface vlan 2999")
remove_vlan(t, "2999")
@with_protocol
def test_partial_standby_ip_definition(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do='standby 1 ip')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 ip",
"end"])
configuring_interface_vlan(t, "2999", do='no standby 1 ip')
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 2999")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 1..1.1")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 1.1.1.1")
t.readln("% Warning: address is not within a subnet on this interface")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.2 255.255.255.0")
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 2999")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 2.1.1.1")
t.readln("% Warning: address is not within a subnet on this interface")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring_interface_vlan(t, "2999", do='standby 1 ip 1.1.1.1')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 1.1.1.2 255.255.255.0",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do='standby 1 ip')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 1.1.1.2 255.255.255.0",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do="no ip address 1.1.1.2 255.255.255.0")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do='no standby 1 ip 1.1.1.1')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
remove_vlan(t, "2999")
@with_protocol
def test_creating_a_port_channel(self, t):
enable(t)
create_port_channel_interface(t, '1')
configuring_port_channel(t, '1', 'description HELLO')
configuring_port_channel(t, '1', 'switchport trunk encapsulation dot1q')
configuring_port_channel(t, '1', 'switchport trunk native vlan 998')
configuring_port_channel(t, '1', 'switchport trunk allowed vlan 6,4087-4089,4091,4093')
configuring_port_channel(t, '1', 'switchport mode trunk')
assert_interface_configuration(t, 'Port-channel1', [
"interface Port-channel1",
" description HELLO",
" switchport trunk encapsulation dot1q",
" switchport trunk native vlan 998",
" switchport trunk allowed vlan 6,4087-4089,4091,4093",
" switchport mode trunk",
"end"
])
t.write("show etherchannel summary")
t.readln("Flags: D - down P - bundled in port-channel")
t.readln(" I - stand-alone s - suspended")
t.readln(" H - Hot-standby (LACP only)")
t.readln(" R - Layer3 S - Layer2")
t.readln(" U - in use f - failed to allocate aggregator")
t.readln("")
t.readln(" M - not in use, minimum links not met")
t.readln(" u - unsuitable for bundling")
t.readln(" w - waiting to be aggregated")
t.readln(" d - default port")
t.readln("")
t.readln("")
t.readln("Number of channel-groups in use: 1")
t.readln("Number of aggregators: 1")
t.readln("")
t.readln("Group Port-channel Protocol Ports")
t.readln("------+-------------+-----------+-----------------------------------------------")
t.readln("1 Po1(S) LACP ")
t.readln("")
t.read("my_switch#")
configuring(t, do="no interface port-channel 1")
t.write("show run int po1")
t.readln("\s*\^", regex=True)
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#")
@with_protocol
def test_port_channel_is_automatically_created_when_adding_a_port_to_it(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface FastEthernet0/1")
t.read("my_switch(config-if)#")
t.write("channel-group 2 mode active")
t.readln("Creating a port-channel interface Port-channel 2")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, 'fa0/1', [
"interface FastEthernet0/1",
" channel-group 2 mode active",
"end"
])
assert_interface_configuration(t, 'po2', [
"interface Port-channel2",
"end"
])
t.write("show etherchannel summary")
t.readln("Flags: D - down P - bundled in port-channel")
t.readln(" I - stand-alone s - suspended")
t.readln(" H - Hot-standby (LACP only)")
t.readln(" R - Layer3 S - Layer2")
t.readln(" U - in use f - failed to allocate aggregator")
t.readln("")
t.readln(" M - not in use, minimum links not met")
t.readln(" u - unsuitable for bundling")
t.readln(" w - waiting to be aggregated")
t.readln(" d - default port")
t.readln("")
t.readln("")
t.readln("Number of channel-groups in use: 1")
t.readln("Number of aggregators: 1")
t.readln("")
t.readln("Group Port-channel Protocol Ports")
t.readln("------+-------------+-----------+-----------------------------------------------")
t.readln("2 Po2(SU) LACP Fa0/1(P)")
t.readln("")
t.read("my_switch#")
configuring(t, do="no interface port-channel 2")
configuring_interface(t, interface="fa0/1", do="no channel-group 2 mode on")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
"end"
])
@with_protocol
def test_port_channel_is_not_automatically_created_when_adding_a_port_to_it_if_its_already_created(self, t):
enable(t)
create_port_channel_interface(t, '14')
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface FastEthernet0/1")
t.read("my_switch(config-if)#")
t.write("channel-group 14 mode active")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
" channel-group 14 mode active",
"end"
])
configuring_interface(t, interface="fa0/1", do="no channel-group 14 mode on")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
"end"
])
configuring(t, do="no interface port-channel 14")
@with_protocol
def test_setting_secondary_ips(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="description hey ho")
configuring_interface_vlan(t, "2999", do="no ip redirects")
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.1 255.255.255.0")
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.1 255.255.255.0 secondary")
configuring_interface_vlan(t, "2999", do="ip address 4.4.4.1 255.255.255.0 secondary")
configuring_interface_vlan(t, "2999", do="ip address 3.3.3.1 255.255.255.0 secondary")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.1 255.255.255.0 secondary",
" ip address 4.4.4.1 255.255.255.0 secondary",
" ip address 3.3.3.1 255.255.255.0 secondary",
" ip address 1.1.1.1 255.255.255.0",
" no ip redirects",
"end"])
configuring_interface_vlan(t, "2999", do="no ip address")
configuring_interface_vlan(t, "2999", do="ip redirects")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
@with_protocol
def test_setting_access_group(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="ip access-group SHNITZLE in")
configuring_interface_vlan(t, "2999", do="ip access-group WHIZZLE out")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" ip access-group SHNITZLE in",
" ip access-group WHIZZLE out",
"end"])
configuring_interface_vlan(t, "2999", do="no ip access-group in")
configuring_interface_vlan(t, "2999", do="no ip access-group WHIZZLE out")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
@with_protocol
def test_removing_ip_address(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan2999")
t.read("my_switch(config-if)#")
t.write("ip address 1.1.1.1 255.255.255.0")
t.read("my_switch(config-if)#")
t.write("ip address 2.2.2.2 255.255.255.0 secondary")
t.read("my_switch(config-if)#")
t.write("no ip address 1.1.1.1 255.255.255.0")
t.readln("Must delete secondary before deleting primary")
t.read("my_switch(config-if)#")
t.write("no ip address 2.2.2.2 255.255.255.0 secondary")
t.read("my_switch(config-if)#")
t.write("no ip address 1.1.1.1 255.255.255.0")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
@with_protocol
def test_show_ip_interface(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
create_vlan(t, "2000")
create_vlan(t, "3000")
create_interface_vlan(t, "3000")
configuring_interface_vlan(t, "3000", do="ip address 1.1.1.1 255.255.255.0")
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip vrf forwarding DEFAULT-LAN")
configuring_interface_vlan(t, "4000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "4000", do="ip address 4.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.128 secondary")
configuring_interface_vlan(t, "4000", do="ip access-group shizzle in")
configuring_interface_vlan(t, "4000", do="ip access-group whizzle out")
t.write("show ip interface")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("Vlan3000 is down, line protocol is down")
t.readln(" Internet address is 1.1.1.1/24")
t.readln(" Outgoing access list is not set")
t.readln(" Inbound access list is not set")
t.readln("Vlan4000 is down, line protocol is down")
t.readln(" Internet address is 2.2.2.2/24")
t.readln(" Secondary address 4.2.2.2/24")
t.readln(" Secondary address 3.2.2.2/25")
t.readln(" Outgoing access list is whizzle")
t.readln(" Inbound access list is shizzle")
t.readln(" VPN Routing/Forwarding \"DEFAULT-LAN\"")
t.readln("FastEthernet0/1 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/2 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/3 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/4 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/5 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/6 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/7 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/8 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/9 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/10 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/11 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/12 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.read("my_switch#")
t.write("show ip interface vlan 4000")
t.readln("Vlan4000 is down, line protocol is down")
t.readln(" Internet address is 2.2.2.2/24")
t.readln(" Secondary address 4.2.2.2/24")
t.readln(" Secondary address 3.2.2.2/25")
t.readln(" Outgoing access list is whizzle")
t.readln(" Inbound access list is shizzle")
t.readln(" VPN Routing/Forwarding \"DEFAULT-LAN\"")
t.read("my_switch#")
t.write("show ip interface vlan1000")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.read("my_switch#")
configuring(t, do="no interface vlan 1000")
configuring(t, do="no interface vlan 3000")
configuring(t, do="no interface vlan 4000")
remove_vlan(t, "1000")
remove_vlan(t, "2000")
remove_vlan(t, "3000")
@with_protocol
def test_assigning_a_secondary_ip_as_the_primary_removes_it_from_secondary_and_removes_the_primary(self, t):
enable(t)
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "4000", do="ip address 4.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.128")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" ip address 4.2.2.2 255.255.255.0 secondary",
" ip address 3.2.2.2 255.255.255.128",
"end"])
configuring(t, do="no interface vlan 4000")
@with_protocol
def test_overlapping_ips(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
create_vlan(t, "2000")
create_interface_vlan(t, "2000")
configuring_interface_vlan(t, "1000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "1000", do="ip address 3.3.3.3 255.255.255.0 secondary")
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan2000")
t.read("my_switch(config-if)#")
t.write("ip address 2.2.2.75 255.255.255.128")
t.readln("% 2.2.2.0 overlaps with secondary address on Vlan1000")
t.read("my_switch(config-if)#")
t.write("ip address 3.3.3.4 255.255.255.128")
t.readln("% 3.3.3.0 is assigned as a secondary address on Vlan1000")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring(t, do="no interface vlan 2000")
remove_vlan(t, "2000")
configuring(t, do="no interface vlan 1000")
remove_vlan(t, "1000")
@with_protocol
def test_unknown_ip_interface(self, t):
enable(t)
t.write("show ip interface Vlan2345")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#")
@with_protocol
def test_removing_ip_needs_to_compare_objects_better(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.1 255.255.255.0")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.3 255.255.255.0 secondary")
configuring_interface_vlan(t, "1000", do="no ip address 1.1.1.3 255.255.255.0 secondary")
t.write("show ip interface vlan 1000")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet address is 1.1.1.1/24")
t.readln(" Secondary address 1.1.1.2/24")
t.readln(" Outgoing access list is not set")
t.readln(" Inbound access list is not set")
t.read("my_switch#")
configuring(t, do="no interface vlan 1000")
remove_vlan(t, "1000")
@with_protocol
def test_extreme_vlan_range(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")