-
Notifications
You must be signed in to change notification settings - Fork 41
/
test_brocade_switch_protocol.py
1729 lines (1405 loc) · 60.1 KB
/
test_brocade_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
import mock
from tests.util.protocol_util import SshTester, with_protocol, ProtocolTest
class TestBrocadeSwitchProtocol(ProtocolTest):
tester_class = SshTester
test_switch = "brocade"
@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("SSH@my_switch#")
@with_protocol
def test_wrong_password(self, t):
t.write("enable")
t.read("Password:")
t.write_invisible("hello_world")
t.readln("Error - Incorrect username or password.")
t.read("SSH@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("SSH@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("SSH@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("Invalid input -> shizzle")
t.readln("Type ? for a list")
t.read("SSH@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("ncopy tftp 1.2.3.4 my-file running-config")
t.readln("TFTP: Download to running-config failed - Session timed out")
t.read("SSH@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("ncopy tftp 1.2.3.4 my-file running-config")
t.readln("done")
t.read("SSH@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("skip-page-display")
t.read("SSH@my_switch#")
t.write("show running-config vlan | begin vlan 1299")
t.read("SSH@my_switch#")
@with_protocol
def test_command_add_vlan(self, t):
enable(t)
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("vlan 123 name shizzle")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
t.write("show running-config vlan | begin vlan 123")
t.readln("vlan 123 name shizzle")
t.readln("!")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("no vlan 123")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
t.write("show running-config vlan | begin vlan 123")
t.read("SSH@my_switch#")
@with_protocol
def test_command_assign_access_vlan_to_port(self, t):
enable(t)
create_vlan(t, "123")
set_interface_untagged_on_vlan(t, "ethernet 1/1", "123")
t.write("show interfaces ethernet 1/1 | inc Member of")
t.readln(" Member of VLAN 123 (untagged), port is in untagged mode, port state is Disabled")
t.read("SSH@my_switch#")
unset_interface_untagged_on_vlan(t, "ethernet 1/1", "123")
t.write("show interfaces ethe1/1 | inc VLAN 1")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.read("SSH@my_switch#")
remove_vlan(t, "123")
@with_protocol
def test_command_interface_tagged_with_native_default_vlan(self, t):
enable(t)
create_vlan(t, "123")
configuring_vlan(t, "123", do="tagged ethernet 1/1")
t.write("show interfaces ethe 1/1 | inc Member of")
t.readln(" Member of VLAN 1 (untagged), 1 L2 VLANS (tagged), port is in dual mode (default vlan), port state is Disabled")
t.read("SSH@my_switch#")
configuring_vlan(t, "123", do="no tagged ethernet 1/1")
t.write("show interfaces ethe1/1 | inc VLAN 1")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.read("SSH@my_switch#")
remove_vlan(t, "123")
@with_protocol
def test_command_show_interface_invalid_interface_name(self, t):
enable(t)
t.write("show interface ethe 1/25")
t.readln("Error - invalid interface 1/25")
t.read("SSH@my_switch#")
t.write("show interface ethe 1/64")
t.readln("Error - invalid interface 1/64")
t.read("SSH@my_switch#")
t.write("show interface ethe 1/65")
t.readln("Invalid input -> 1/65")
t.readln("Type ? for a list")
t.read("SSH@my_switch#")
t.write("show interface ethe 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch#")
t.write("show interface ethe 2/1")
t.readln("Error - interface 2/1 is not an ETHERNET interface")
t.read("SSH@my_switch#")
@with_protocol
def test_command_no_interface_invalid_interface_name(self, t):
enable(t)
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("no interface ethe 1/25")
t.readln("Error - invalid interface 1/25")
t.read("SSH@my_switch(config)#")
t.write("no interface ethe 1/64")
t.readln("Error - invalid interface 1/64")
t.read("SSH@my_switch(config)#")
t.write("no interface ethe 1/65")
t.readln("Invalid input -> 1/65")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config)#")
t.write("no interface ethe 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config)#")
t.write("no interface ethe 2/1")
t.readln("Error - interface 2/1 is not an ETHERNET interface")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
@with_protocol
def test_command_interface_invalid_interface_name(self, t):
enable(t)
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/25")
t.readln("Error - invalid interface 1/25")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/64")
t.readln("Error - invalid interface 1/64")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/65")
t.readln("Invalid input -> 1/65")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config)#")
t.write("interface ethe nonexistent99")
t.readln("Invalid input -> nonexistent 99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 2/1")
t.readln("Error - interface 2/1 is not an ETHERNET interface")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
@with_protocol
def test_remove_a_ports_from_a_vlan_should_print_an_error(self, t):
enable(t)
create_vlan(t, "123")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("vlan 123")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("no untagged ethernet 1/1")
t.readln("Error: ports ethe 1/1 are not untagged members of vlan 123")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("no tagged ethernet 1/1")
t.readln("Error: ports ethe 1/1 are not tagged members of vlan 123")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
@with_protocol
def test_unknown_ports_when_tagging_prints_an_error(self, t):
enable(t)
create_vlan(t, "123")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("vlan 123")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("untagged ethernet 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("tagged ethernet 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("no untagged ethernet 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("no tagged ethernet 1/99")
t.readln("Invalid input -> 1/99")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-123)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
@with_protocol
def test_command_interface_tagged_with_native_vlan(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "124")
create_vlan(t, "456")
configuring_vlan(t, "123", do="tagged ethernet 1/1")
configuring_vlan(t, "124", do="tagged ethernet 1/1")
configuring_vlan(t, "456", do="untagged ethernet 1/1")
t.write("show interfaces ethernet 1/1 | inc Member of")
t.readln(" Member of VLAN 456 (untagged), 2 L2 VLANS (tagged), port is in dual mode, port state is Disabled")
t.read("SSH@my_switch#")
configuring_vlan(t, "123", do="no tagged ethernet 1/1")
configuring_vlan(t, "124", do="no tagged ethernet 1/1")
configuring_vlan(t, "456", do="no untagged ethernet 1/1")
t.write("show interfaces ethe1/1 | inc VLAN 1")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.read("SSH@my_switch#")
remove_vlan(t, "123")
remove_vlan(t, "124")
remove_vlan(t, "456")
@with_protocol
def test_command_interface_tagged_with_no_native_vlan(self, t):
enable(t)
create_vlan(t, "123")
configuring_vlan(t, "123", do="tagged ethernet 1/1")
configuring_vlan(t, "1", do="no untagged ethernet 1/1")
t.write("show interfaces ethernet 1/1 | inc Member of")
t.readln(" Member of 1 L2 VLAN(S) (tagged), port is in tagged mode, port state is Disabled")
t.read("SSH@my_switch#")
configuring_vlan(t, "123", do="no tagged ethernet 1/1")
# untagged vlan 1 returns by default magically
t.write("show interfaces ethe1/1 | inc VLAN 1")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.read("SSH@my_switch#")
remove_vlan(t, "123")
@with_protocol
def test_show_interfaces(self, t):
enable(t)
configuring_interface(t, "1/2", do="port-name hello")
configuring_interface(t, "1/3", do="enable")
create_interface_vlan(t, "1000")
configuring_interface_vlan(t, "1000", do="port-name Salut")
create_interface_vlan(t, "2000")
configuring_interface_vlan(t, "2000", do="ip address 1.1.1.1/24")
t.write("show interfaces")
t.readln("GigabitEthernet1/1 is disabled, line protocol is down")
t.readln(" Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.readln(" No port name")
t.readln("GigabitEthernet1/2 is disabled, line protocol is down")
t.readln(" Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.readln(" Port name is hello")
t.readln("GigabitEthernet1/3 is down, line protocol is down")
t.readln(" Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.readln(" No port name")
t.readln("GigabitEthernet1/4 is disabled, line protocol is down")
t.readln(" Hardware is GigabitEthernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" Member of VLAN 1 (untagged), port is in untagged mode, port state is Disabled")
t.readln(" No port name")
t.readln("Ve1000 is down, line protocol is down")
t.readln(" Hardware is Virtual Ethernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" Port name is Salut")
t.readln(" Vlan id: 1000")
t.readln(" Internet address is 0.0.0.0/0, IP MTU 1500 bytes, encapsulation ethernet")
t.readln("Ve2000 is down, line protocol is down")
t.readln(" Hardware is Virtual Ethernet, address is 0000.0000.0000 (bia 0000.0000.0000)")
t.readln(" No port name")
t.readln(" Vlan id: 2000")
t.readln(" Internet address is 1.1.1.1/24, IP MTU 1500 bytes, encapsulation ethernet")
t.read("SSH@my_switch#")
configuring_interface(t, "1/2", do="no port-name hello")
configuring_interface(t, "1/3", do="disable")
configuring(t, do="no interface ve 1000")
configuring(t, do="no vlan 1000")
configuring(t, do="no interface ve 2000")
configuring(t, do="no vlan 2000")
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-at-the-maxi-length") # 31 on brocade
set_interface_untagged_on_vlan(t, "ethe1/1", "123")
t.write("show vlan brief")
t.readln("")
t.readln("VLAN Name Encap ESI Ve Pri Ports")
t.readln("---- ---- ----- --- ----- --- -----")
t.readln(
"1 DEFAULT-VL - - Untagged Ports : ethe 1/2 to 1/4")
t.readln("123 [None] - - Untagged Ports : ethe 1/1")
t.readln("2222 your-name- - -")
t.readln("3333 some-name - -")
t.read("SSH@my_switch#")
remove_interface_from_vlan(t, "ethe1/1", "123")
remove_vlan(t, "123")
remove_vlan(t, "1234")
remove_vlan(t, "5555")
@with_protocol
def test_show_running_config_vlan(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "999")
create_vlan(t, "888")
configuring_vlan(t, "123", do="untagged ethernet 1/2")
configuring_vlan(t, "888", do="tagged ethernet 1/2")
configuring_vlan(t, "888", do="router-interface ve 1888")
configuring_vlan(t, "999", do="tagged ethe1/2")
configuring_vlan(t, "999", do="untagged ethe1/1")
t.write("show running-config vlan")
t.readln("spanning-tree")
t.readln("!")
t.readln("!")
t.readln("vlan 1 name DEFAULT-VLAN")
t.readln(" no untagged ethe 1/3 to 1/4")
t.readln("!")
t.readln("vlan 123")
t.readln(" untagged ethe 1/2")
t.readln("!")
t.readln("vlan 888")
t.readln(" tagged ethe 1/2")
t.readln(" router-interface ve 1888")
t.readln("!")
t.readln("vlan 999")
t.readln(" untagged ethe 1/1")
t.readln(" tagged ethe 1/2")
t.readln("!")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
configuring(t, do="no interface ve 1888")
configuring(t, do="no vlan 123")
configuring(t, do="no vlan 888")
configuring(t, do="no vlan 999")
@with_protocol
def test_shutting_down(self, t):
enable(t)
t.write("show run interface ethernet 1/3")
t.readln("")
t.read("SSH@my_switch#")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ethe1/3")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("enable")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
t.write("show run interface ethernet 1/3")
t.readln("interface ethernet 1/3")
t.readln(" enable")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ethe1/3")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("disable")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
t.write("show run interface ethernet 1/3")
t.readln("")
t.read("SSH@my_switch#")
@with_protocol
def test_setup_an_interface(self, t):
enable(t)
t.write("show run int ve 2999")
t.readln("Error - ve 2999 was not configured")
t.read("SSH@my_switch#")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ve 2999")
t.readln("Error - invalid virtual ethernet interface number.")
t.read("SSH@my_switch(config)#")
t.write("vlan 2999")
t.read("SSH@my_switch(config-vlan-2999)#")
t.write("router interface ve 2999")
t.readln("Invalid input -> interface ve 2999")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-2999)#")
t.write("rout patate 2999")
t.readln("Invalid input -> patate 2999")
t.readln("Type ? for a list")
t.read("SSH@my_switch(config-vlan-2999)#")
t.write("router-interface ve 2999")
t.read("SSH@my_switch(config-vlan-2999)#")
t.write("router-interface ve 3000")
t.readln("Error: VLAN: 2999 already has router-interface 2999")
t.read("SSH@my_switch(config-vlan-2999)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
t.write("show running-config vlan | begin vlan 2999")
t.readln("vlan 2999")
t.readln(" router-interface ve 2999")
t.readln("!")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
"!"
])
configuring_interface_vlan(t, "2999", do="port-name hey ho")
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.2/24")
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.1/24")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
" port-name hey ho",
" ip address 1.1.1.1/24",
" ip address 2.2.2.2/24",
"!"])
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ve 2999")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("ip address 1.1.1.1/24")
t.readln("IP/Port: Errno(6) Duplicate ip address")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
configuring(t, do="no interface ve 2999")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
"!"
])
configuring_vlan(t, "2999", do="no router-interface 2999")
t.write("show run int ve 2999")
t.readln("Error - ve 2999 was not configured")
t.read("SSH@my_switch#")
configuring(t, do="no vlan 2999")
@with_protocol
def test_setting_access_group(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_access_group_interface_vlan(t, "2999", do="ip access-group SHNITZLE in")
configuring_access_group_interface_vlan(t, "2999", do="ip access-group WHIZZLE out")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
" ip access-group SHNITZLE in",
" ip access-group WHIZZLE out",
"!"])
configuring_interface_vlan(t, "2999", do="no ip access-group WHIZZLE out")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ve 2999")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("no ip access-group wat in")
t.readln("Error: Wrong Access List Name wat")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("no ip access-group out")
t.readln("Error: Wrong Access List Name out")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("no ip access-group gneh out")
t.readln("Error: Wrong Access List Name gneh")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("no ip access-group SHNITZLE in")
t.read("SSH@my_switch(config-vif-2999)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
"!"])
configuring(t, do="no interface ve 2999")
configuring(t, do="no vlan 2999")
@with_protocol
def test_removing_ip_address(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.2/24")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
" ip address 2.2.2.2/24",
"!"])
configuring_interface_vlan(t, "2999", do="no ip address 2.2.2.2/24")
assert_interface_configuration(t, "ve 2999", [
"interface ve 2999",
"!"])
configuring(t, do="no interface ve 2999")
configuring(t, do="no vlan 2999")
@with_protocol
def test_static_routes(self, t):
enable(t)
configuring(t, do="ip route 100.100.100.100 255.255.255.0 2.2.2.2")
configuring(t, do="ip route 1.1.2.0 255.255.255.0 2.2.2.3")
t.write("show ip route static")
t.readln(" Destination Gateway Port Cost Type Uptime src-vrf")
t.readln("1 100.100.100.100/24 2.2.2.2")
t.readln("2 1.1.2.0/24 2.2.2.3")
t.readln("")
t.read("SSH@my_switch#")
configuring(t, do="no ip route 100.100.100.100 255.255.255.0 2.2.2.2")
t.write("show ip route static")
t.readln(" Destination Gateway Port Cost Type Uptime src-vrf")
t.readln("1 1.1.2.0/24 2.2.2.3")
@with_protocol
def test_show_all_interfaces_in_running(self, t):
enable(t)
create_interface_vlan(t, "2998")
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.2/24")
configuring_access_group_interface_vlan(t, "2999", do="ip access-group SHNITZLE in")
configuring_access_group_interface_vlan(t, "2999", do="ip access-group WHIZZLE out")
create_interface_vlan(t, "3000")
configuring_interface_vlan(t, "3000", do="port-name howdy")
configuring_interface(t, "1/1", do="port-name one one")
configuring_interface(t, "1/3", do="port-name one three")
configuring_interface(t, "1/3", do="enable")
configuring_interface(t, "1/4", do="enable")
t.write("show running-config interface")
t.readln("interface ethernet 1/1")
t.readln(" port-name one one")
t.readln("!")
t.readln("interface ethernet 1/3")
t.readln(" port-name one three")
t.readln(" enable")
t.readln("!")
t.readln("interface ethernet 1/4")
t.readln(" enable")
t.readln("!")
t.readln("interface ve 2998")
t.readln("!")
t.readln("interface ve 2999")
t.readln(" ip address 2.2.2.2/24")
t.readln(" ip access-group SHNITZLE in")
t.readln(" ip access-group WHIZZLE out")
t.readln("!")
t.readln("interface ve 3000")
t.readln(" port-name howdy")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
configuring(t, do="no interface ve 2998")
configuring(t, do="no vlan 2998")
configuring(t, do="no interface ve 2999")
configuring(t, do="no vlan 2999")
configuring(t, do="no interface ve 3000")
configuring(t, do="no vlan 3000")
configuring_interface(t, "1/1", do="no port-name")
configuring_interface(t, "1/3", do="no port-name")
configuring_interface(t, "1/3", do="disable")
configuring(t, do="no interface ethernet 1/4")
t.write("show running-config interface")
t.readln("")
t.read("SSH@my_switch#")
@with_protocol
def test_configuring_no_interface_does_not_remove_interfaces_from_vlans(self, t):
enable(t)
create_vlan(t, "3000")
configuring_vlan(t, "3000", do="untagged ethernet 1/1")
configuring_vlan(t, "3000", do="tagged ethernet 1/2")
create_vlan(t, "3001")
configuring_vlan(t, "3001", do="untagged ethernet 1/3")
configuring(t, do="no interface ethernet 1/1")
configuring(t, do="no interface ethernet 1/2")
t.write("show running-config vlan | begin vlan 3000")
t.readln("vlan 3000")
t.readln(" untagged ethe 1/1")
t.readln(" tagged ethe 1/2")
t.readln("!")
t.readln("vlan 3001")
t.readln(" untagged ethe 1/3")
t.readln("!")
t.readln("!")
t.readln("")
t.read("SSH@my_switch#")
configuring(t, do="no vlan 3000")
configuring(t, do="no vlan 3001")
@with_protocol
def test_overlapping_and_secondary_ips(self, t):
enable(t)
create_interface_vlan(t, "1000")
create_interface_vlan(t, "2000")
configuring_interface_vlan(t, "1000", do="ip address 2.2.2.2/24")
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("interface ve 2000")
t.read("SSH@my_switch(config-vif-2000)#")
t.write("ip address 2.2.2.75/25")
t.readln("IP/Port: Errno(11) ip subnet overlap with another interface")
t.read("SSH@my_switch(config-vif-2000)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("interface ve 1000")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("ip address 2.2.2.4/24")
t.readln("IP/Port: Errno(15) Can only assign one primary ip address per subnet")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("ip address 2.2.2.5/25 secondary")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("ip address 2.2.2.87/30 secondary")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("ip address 2.2.2.72/29 secondary")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("no ip address 2.2.2.2/24")
t.readln("IP/Port: Errno(18) Delete secondary address before deleting primary address")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("no ip address 2.2.2.5/25")
t.read("SSH@my_switch(config-vif-1000)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ve 1000", [
"interface ve 1000",
" ip address 2.2.2.2/24",
" ip address 2.2.2.72/29 secondary",
" ip address 2.2.2.87/30 secondary",
"!"])
configuring(t, do="no interface ve 2000")
configuring(t, do="no vlan 2000")
configuring(t, do="no interface ve 1000")
configuring(t, do="no vlan 1000")
@with_protocol
def test_multiple_secondary_are_listed_at_the_end(self, t):
enable(t)
create_interface_vlan(t, "1000")
configuring_interface_vlan(t, "1000", do="ip address 2.2.2.2/24")
configuring_interface_vlan(t, "1000", do="ip address 2.2.2.3/24 secondary")
configuring_interface_vlan(t, "1000", do="ip address 1.2.2.2/24")
configuring_interface_vlan(t, "1000", do="ip address 1.2.2.3/24 secondary")
assert_interface_configuration(t, "ve 1000", [
"interface ve 1000",
" ip address 1.2.2.2/24",
" ip address 2.2.2.2/24",
" ip address 1.2.2.3/24 secondary",
" ip address 2.2.2.3/24 secondary",
"!"])
configuring(t, do="no interface ve 1000")
configuring(t, do="no vlan 1000")
@with_protocol
def test_ip_vrf(self, t):
enable(t)
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("ip vrf SOME-LAN")
t.read("SSH@my_switch(config-vrf-SOME-LAN)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("no ip vrf SOME-LAN")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
@with_protocol
def test_ip_vrf_forwarding(self, t):
enable(t)
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("ip vrf SOME-LAN")
t.read("SSH@my_switch(config-vrf-SOME-LAN)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/3")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("vrf forwarding NOT-DEFAULT-LAN")
t.readln("Error - VRF(NOT-DEFAULT-LAN) does not exist or Route-Distinguisher not specified or Address Family not configured")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("vrf forwarding SOME-LAN")
t.readln("Warning: All IPv4 and IPv6 addresses (including link-local) on this interface have been removed")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ethernet 1/3", [
"interface ethernet 1/3",
" vrf forwarding SOME-LAN",
"!"])
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("no ip vrf SOME-LAN")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ethernet 1/3", [])
@with_protocol
def test_ip_vrf_default_lan(self, t):
enable(t)
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/3")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("vrf forwarding DEFAULT-LAN")
t.readln("Warning: All IPv4 and IPv6 addresses (including link-local) on this interface have been removed")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ethernet 1/3", [
"interface ethernet 1/3",
" vrf forwarding DEFAULT-LAN",
"!"])
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("interface ethe 1/3")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("no vrf forwarding DEFAULT-LAN")
t.readln("Warning: All IPv4 and IPv6 addresses (including link-local) on this interface have been removed")
t.read("SSH@my_switch(config-if-e1000-1/3)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "ethernet 1/3", [])
@with_protocol
def test_ip_setting_vrf_forwarding_wipes_ip_addresses(self, t):
enable(t)
create_vlan(t, "4000")
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip address 10.10.0.10/24")
configuring_interface_vlan(t, "4000", do="ip address 10.10.1.10/24")
assert_interface_configuration(t, "Vlan4000", [
"interface ve 4000",
" ip address 10.10.0.10/24",
" ip address 10.10.1.10/24",
"!"])
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("interface ve 4000")
t.read("SSH@my_switch(config-vif-4000)#")
t.write("vrf forwarding DEFAULT-LAN")
t.readln("Warning: All IPv4 and IPv6 addresses (including link-local) on this interface have been removed")
t.read("SSH@my_switch(config-vif-4000)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "Vlan4000", [
"interface ve 4000",
" vrf forwarding DEFAULT-LAN",
"!"])
configuring_interface_vlan(t, "4000", do="ip address 10.10.0.10/24")
configuring_interface_vlan(t, "4000", do="ip address 10.10.1.10/24")
t.write("conf t")
t.read("SSH@my_switch(config)#")
t.write("interface ve 4000")
t.read("SSH@my_switch(config-vif-4000)#")
t.write("no vrf forwarding")
t.readln("Incomplete command.")
t.read("SSH@my_switch(config-vif-4000)#")
t.write("no vrf forwarding DEFAULT-LAN")
t.readln("Warning: All IPv4 and IPv6 addresses (including link-local) on this interface have been removed")
t.read("SSH@my_switch(config-vif-4000)#")
t.write("exit")
t.read("SSH@my_switch(config)#")
t.write("exit")
t.read("SSH@my_switch#")
assert_interface_configuration(t, "Vlan4000", [
"interface ve 4000",
"!"])
configuring(t, do="no interface ve 4000")
configuring(t, do="no vlan 4000")
@with_protocol
def test_extreme_vlan_ranges(self, t):
enable(t)
t.write("configure terminal")
t.read("SSH@my_switch(config)#")
t.write("vlan -1")
t.readln("Invalid input -> -1")