cisco_node_utils 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,6 +79,37 @@ class TestInterfaceOspf < CiscoTestCase
79
79
  node.cache_flush
80
80
  end
81
81
 
82
+ def test_get_set_area
83
+ # setup a loopback to use
84
+ @device.cmd("configure terminal")
85
+ @device.cmd("interface loopback12")
86
+ @device.cmd("end")
87
+ node.cache_flush
88
+
89
+ int_ospf = InterfaceOspf.new("loopback12", "12", "0.0.0.0")
90
+
91
+ # test invalid
92
+ assert_raises(CliError) do
93
+ int_ospf.area = "Blue"
94
+ end
95
+
96
+ # test get/set ip address form
97
+ int_ospf.area = "0.0.0.4"
98
+ assert_equal(int_ospf.area, "0.0.0.4")
99
+
100
+ # test get/set integer form.
101
+ # Note: the area getter will munge the value to dotted decimal.
102
+ int_ospf.area = "3"
103
+ assert_equal(int_ospf.area, "0.0.0.3")
104
+
105
+ # cleanup
106
+ int_ospf.destroy
107
+ @device.cmd("configure terminal")
108
+ @device.cmd("no interface loopback12")
109
+ @device.cmd("end")
110
+ node.cache_flush
111
+ end
112
+
82
113
  def test_interfaceospf_collection_empty
83
114
  @device.cmd("configure terminal")
84
115
  @device.cmd("no feature ospf")
@@ -746,7 +777,8 @@ class TestInterfaceOspf < CiscoTestCase
746
777
  node.cache_flush
747
778
  interface = InterfaceOspf.new("loopback122", "nonexistentOspf", "0")
748
779
 
749
- assert_equal(interface.area, "0")
780
+ # Note: the area getter will munge the value to dotted decimal.
781
+ assert_equal(interface.area, "0.0.0.0")
750
782
  assert_equal(interface.hello_interval, interface.default_hello_interval)
751
783
 
752
784
  interface.destroy
@@ -19,11 +19,20 @@ require File.expand_path("../../lib/cisco_node_utils/vtp", __FILE__)
19
19
  include Cisco
20
20
 
21
21
  class TestInterfaceSwitchport < CiscoTestCase
22
- def interface_ethernet_default(ethernet_id)
22
+ DEFAULT_IF_SWITCHPORT_ALLOWED_VLAN = "1-4094"
23
+ DEFAULT_IF_SWITCHPORT_NATIVE_VLAN = 1
24
+
25
+ def setup
26
+ super
23
27
  s = @device.cmd("configure terminal")
24
28
  s = @device.cmd("no feature vtp")
25
29
  s = @device.cmd("no feature interface-vlan")
30
+ s = @device.cmd("end")
31
+ node.cache_flush
32
+ end
26
33
 
34
+ def interface_ethernet_default(ethernet_id)
35
+ s = @device.cmd("configure terminal")
27
36
  s = @device.cmd("default interface ethernet #{ethernet_id}")
28
37
  s = @device.cmd("end")
29
38
  node.cache_flush
@@ -642,6 +651,100 @@ class TestInterfaceSwitchport < CiscoTestCase
642
651
  interface_ethernet_default(interfaces_id[0])
643
652
  end
644
653
 
654
+ def test_interface_switchport_trunk_allowed_vlan_all
655
+ interface = Interface.new(interfaces[0])
656
+ interface.switchport_enable
657
+ interface.switchport_trunk_allowed_vlan = "all"
658
+ assert_equal(
659
+ DEFAULT_IF_SWITCHPORT_ALLOWED_VLAN,
660
+ interface.switchport_trunk_allowed_vlan)
661
+ interface_ethernet_default(interfaces_id[0])
662
+ end
663
+
664
+ def test_interface_switchport_trunk_allowed_vlan_change
665
+ interface = Interface.new(interfaces[0])
666
+ interface.switchport_enable
667
+ interface.switchport_trunk_allowed_vlan = "20"
668
+ assert_equal("20", interface.switchport_trunk_allowed_vlan)
669
+ interface.switchport_trunk_allowed_vlan = "30"
670
+ assert_equal("30", interface.switchport_trunk_allowed_vlan)
671
+ interface_ethernet_default(interfaces_id[0])
672
+ end
673
+
674
+ def test_interface_switchport_trunk_allowed_vlan_default
675
+ interface = Interface.new(interfaces[0])
676
+ interface.switchport_enable
677
+ interface.switchport_trunk_allowed_vlan =
678
+ interface.default_switchport_trunk_allowed_vlan
679
+ assert_equal(
680
+ DEFAULT_IF_SWITCHPORT_ALLOWED_VLAN,
681
+ interface.switchport_trunk_allowed_vlan)
682
+ interface_ethernet_default(interfaces_id[0])
683
+ end
684
+
685
+ def test_interface_switchport_trunk_allowed_vlan_invalid
686
+ interface = Interface.new(interfaces[0])
687
+ interface.switchport_enable
688
+ assert_raises(RuntimeError) {
689
+ interface.switchport_trunk_allowed_vlan = "hello"
690
+ }
691
+ interface_ethernet_default(interfaces_id[0])
692
+ end
693
+
694
+ def test_interface_switchport_trunk_allowed_vlan_none
695
+ interface = Interface.new(interfaces[0])
696
+ interface.switchport_enable
697
+ interface.switchport_trunk_allowed_vlan = "none"
698
+ assert_equal("none", interface.switchport_trunk_allowed_vlan)
699
+ interface_ethernet_default(interfaces_id[0])
700
+ end
701
+
702
+ def test_interface_switchport_trunk_allowed_vlan_valid
703
+ interface = Interface.new(interfaces[0])
704
+ interface.switchport_enable
705
+ interface.switchport_trunk_allowed_vlan = "20, 30"
706
+ assert_equal("20,30", interface.switchport_trunk_allowed_vlan)
707
+ interface_ethernet_default(interfaces_id[0])
708
+ end
709
+
710
+ def test_interface_switchport_trunk_native_vlan_change
711
+ interface = Interface.new(interfaces[0])
712
+ interface.switchport_enable
713
+ interface.switchport_trunk_native_vlan = 20
714
+ assert_equal(20, interface.switchport_trunk_native_vlan)
715
+ interface.switchport_trunk_native_vlan = 30
716
+ assert_equal(30, interface.switchport_trunk_native_vlan)
717
+ interface_ethernet_default(interfaces_id[0])
718
+ end
719
+
720
+ def test_interface_switchport_trunk_native_vlan_default
721
+ interface = Interface.new(interfaces[0])
722
+ interface.switchport_enable
723
+ interface.switchport_trunk_native_vlan =
724
+ interface.default_switchport_trunk_native_vlan
725
+ assert_equal(
726
+ DEFAULT_IF_SWITCHPORT_NATIVE_VLAN,
727
+ interface.switchport_trunk_native_vlan)
728
+ interface_ethernet_default(interfaces_id[0])
729
+ end
730
+
731
+ def test_interface_switchport_trunk_native_vlan_invalid
732
+ interface = Interface.new(interfaces[0])
733
+ interface.switchport_enable
734
+ assert_raises(RuntimeError) {
735
+ interface.switchport_trunk_native_vlan = "20, 30"
736
+ }
737
+ interface_ethernet_default(interfaces_id[0])
738
+ end
739
+
740
+ def test_interface_switchport_trunk_native_vlan_valid
741
+ interface = Interface.new(interfaces[0])
742
+ interface.switchport_enable
743
+ interface.switchport_trunk_native_vlan = 20
744
+ assert_equal(20, interface.switchport_trunk_native_vlan)
745
+ interface_ethernet_default(interfaces_id[0])
746
+ end
747
+
645
748
  =begin
646
749
  # Run this test at your peril as it can cause timeouts for this test and
647
750
  # others - 'no feature-set fex' states:
@@ -750,4 +750,16 @@ class TestRouterOspfVrf < CiscoTestCase
750
750
  "Error: #{vrf.name} vrf, max timer throttle spf not correct")
751
751
  vrf.parent.destroy
752
752
  end
753
+
754
+ def test_routerospfvrf_noninstantiated
755
+ routerospf = create_routerospf
756
+ vrf = RouterOspfVrf.new("absent", "absent", false)
757
+ vrf.auto_cost
758
+ vrf.default_metric
759
+ vrf.log_adjacency
760
+ vrf.router_id
761
+ vrf.timer_throttle_lsa
762
+ vrf.timer_throttle_spf
763
+ routerospf.destroy
764
+ end
753
765
  end
@@ -640,7 +640,7 @@ class TestSnmpUser < CiscoTestCase
640
640
  # puts "line: #{line}"
641
641
  refute(line.nil?)
642
642
  snmpuser.destroy
643
- end
643
+ end
644
644
 
645
645
  def test_snmpuser_create_with_single_group_auth_sha_priv_aes128_pw_localized
646
646
  name = "userv3testauth"
data/tests/test_vtp.rb CHANGED
@@ -21,6 +21,11 @@ class TestVtp < CiscoTestCase
21
21
  no_feature_vtp
22
22
  end
23
23
 
24
+ def teardown
25
+ no_feature_vtp
26
+ super
27
+ end
28
+
24
29
  def no_feature_vtp
25
30
  # VTP will raise an error if the domain is configured twice so we need to
26
31
  # turn the feature off for a clean test.
@@ -34,26 +39,58 @@ class TestVtp < CiscoTestCase
34
39
  vtp
35
40
  end
36
41
 
42
+ def test_vtp_disabled
43
+ vtp = Vtp.new(false)
44
+ assert_empty(vtp.domain)
45
+ assert_equal(vtp.default_password, vtp.password)
46
+ assert_equal(vtp.default_filename, vtp.filename)
47
+ assert_equal(vtp.default_version, vtp.version)
48
+ refute(Vtp.enabled, "VTP feature was unexpectedly enabled?")
49
+ end
50
+
51
+ def test_vtp_enabled_but_no_domain
52
+ vtp = Vtp.new(false)
53
+ @device.cmd("conf t ; feature vtp ; end")
54
+ node.cache_flush()
55
+ assert(Vtp.enabled)
56
+ assert_empty(vtp.domain)
57
+ assert_equal(vtp.default_password, vtp.password)
58
+ assert_equal(vtp.default_filename, vtp.filename)
59
+ assert_equal(vtp.default_version, vtp.version)
60
+ # Can set these without setting domain
61
+ vtp.filename = "bootflash:/foo.bar"
62
+ assert_equal("bootflash:/foo.bar", vtp.filename)
63
+ vtp.version = 1
64
+ assert_equal(1, vtp.version)
65
+ # Can't set any of the below without setting a domain first
66
+ assert_raises(RuntimeError) do
67
+ vtp.password = "hello"
68
+ end
69
+ end
70
+
71
+ def test_vtp_domain_enable_disable
72
+ assert_empty(Vtp.domain)
73
+ vtp = vtp_domain("enable")
74
+ assert_equal("enable", Vtp.domain)
75
+ vtp.destroy
76
+ assert_empty(Vtp.domain)
77
+ end
78
+
37
79
  def test_vtp_create_valid
38
- no_feature_vtp
39
80
  vtp = vtp_domain("accounting")
40
81
  s = @device.cmd("show run vtp | incl '^vtp domain'")
41
82
  assert_match(/^vtp domain accounting/, s,
42
83
  "Error: failed to create vtp domain")
43
- vtp.destroy
44
84
  end
45
85
 
46
86
  def test_vtp_domain_name_change
47
- no_feature_vtp
48
87
  vtp = vtp_domain("accounting")
49
88
  vtp_new = vtp_domain("uplink")
50
89
  assert_equal("uplink", vtp.domain,
51
90
  "Error: vtp domain name incorrect")
52
- vtp_new.destroy
53
91
  end
54
92
 
55
93
  def test_vtp_create_preconfig_no_change
56
- no_feature_vtp
57
94
  s = @device.cmd("configure terminal")
58
95
  s = @device.cmd("feature vtp")
59
96
  s = @device.cmd("vtp domain accounting")
@@ -65,11 +102,9 @@ class TestVtp < CiscoTestCase
65
102
  vtp = vtp_domain("accounting")
66
103
  assert_equal("accounting", vtp.domain,
67
104
  "Error: vtp domain wrong")
68
- vtp.destroy
69
105
  end
70
106
 
71
107
  def test_vtp_create_double
72
- no_feature_vtp
73
108
  vtp = vtp_domain("accounting")
74
109
  vtp_new = vtp_domain("accounting")
75
110
 
@@ -77,32 +112,27 @@ class TestVtp < CiscoTestCase
77
112
  "Error: vtp domain wrong")
78
113
  assert_equal("accounting", vtp_new.domain,
79
114
  "Error: vtp_new domain wrong")
80
- vtp_new.destroy
81
115
  end
82
116
 
83
117
  def test_vtp_create_domain_invalid
84
- no_feature_vtp
85
118
  assert_raises(ArgumentError) do
86
119
  vtp_domain(node)
87
120
  end
88
121
  end
89
122
 
90
123
  def test_vtp_create_domain_nil
91
- no_feature_vtp
92
124
  assert_raises(ArgumentError) do
93
125
  vtp_domain(nil)
94
126
  end
95
127
  end
96
128
 
97
129
  def test_vtp_create_domain_empty
98
- no_feature_vtp
99
130
  assert_raises(ArgumentError) do
100
131
  vtp_domain("")
101
132
  end
102
133
  end
103
134
 
104
135
  def test_vtp_assignment
105
- no_feature_vtp
106
136
  vtp = vtp_domain("accounting")
107
137
  vtp.password = "copy_test"
108
138
  assert_equal("copy_test", vtp.password,
@@ -110,28 +140,22 @@ class TestVtp < CiscoTestCase
110
140
  vtp_extra = vtp
111
141
  assert_equal("copy_test", vtp_extra.password,
112
142
  "Error: vtp password not set")
113
- vtp.destroy
114
143
  end
115
144
 
116
145
  def test_vtp_domain_get
117
- no_feature_vtp
118
146
  vtp = vtp_domain("accounting")
119
147
  assert_equal("accounting", vtp.domain,
120
148
  "Error: vtp domain incorrect")
121
- vtp.destroy
122
149
  end
123
150
 
124
151
  def test_vtp_password_nil
125
- no_feature_vtp
126
152
  vtp = vtp_domain("accounting")
127
153
  assert_raises(TypeError) do
128
154
  vtp.password = nil
129
155
  end
130
- vtp.destroy
131
156
  end
132
157
 
133
158
  def test_vtp_password_default
134
- no_feature_vtp
135
159
  vtp = vtp_domain("accounting")
136
160
  vtp.password = "test_me"
137
161
  assert_equal("test_me", vtp.password,
@@ -140,21 +164,16 @@ class TestVtp < CiscoTestCase
140
164
  vtp.password = vtp.default_password
141
165
  assert_equal(node.config_get_default("vtp", "password"), vtp.password,
142
166
  "Error: vtp password not correct")
143
-
144
- vtp.destroy
145
167
  end
146
168
 
147
169
  def test_vtp_password_zero_length
148
- no_feature_vtp
149
170
  vtp = vtp_domain("accounting")
150
171
  vtp.password = ""
151
172
  assert_equal("", vtp.password,
152
173
  "Error: vtp password not empty")
153
- vtp.destroy
154
174
  end
155
175
 
156
176
  def test_vtp_password_get
157
- no_feature_vtp
158
177
  vtp = vtp_domain("accounting")
159
178
 
160
179
  s = @device.cmd("configure terminal")
@@ -164,19 +183,15 @@ class TestVtp < CiscoTestCase
164
183
  node.cache_flush()
165
184
  assert_equal("cisco123", vtp.password,
166
185
  "Error: vtp password not correct")
167
- vtp.destroy
168
186
  end
169
187
 
170
188
  def test_vtp_password_get_not_set
171
- no_feature_vtp
172
189
  vtp = vtp_domain("accounting")
173
190
  assert_equal("", vtp.password,
174
191
  "Error: vtp password not empty")
175
- vtp.destroy
176
192
  end
177
193
 
178
194
  def test_vtp_password_clear
179
- no_feature_vtp
180
195
  vtp = vtp_domain("accounting")
181
196
  vtp.password = "cisco123"
182
197
  assert_equal("cisco123", vtp.password,
@@ -185,12 +200,9 @@ class TestVtp < CiscoTestCase
185
200
  vtp.password = ""
186
201
  assert_equal("", vtp.password,
187
202
  "Error: vtp default password not set")
188
-
189
- vtp.destroy
190
203
  end
191
204
 
192
205
  def test_vtp_password_valid
193
- no_feature_vtp
194
206
  vtp = vtp_domain("accounting")
195
207
  alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
196
208
  password = ""
@@ -202,11 +214,9 @@ class TestVtp < CiscoTestCase
202
214
  "Error: vtp password not set")
203
215
  end
204
216
  }
205
- vtp.destroy
206
217
  end
207
218
 
208
219
  def test_vtp_password_too_long
209
- no_feature_vtp
210
220
  vtp = vtp_domain("accounting")
211
221
  password = "a"
212
222
  Vtp::MAX_VTP_PASSWORD_SIZE.times {
@@ -215,29 +225,29 @@ class TestVtp < CiscoTestCase
215
225
  assert_raises(ArgumentError) {
216
226
  vtp.password = password
217
227
  }
218
- vtp.destroy
228
+ end
229
+
230
+ def test_vtp_password_special_characters
231
+ vtp = vtp_domain("password")
232
+ vtp.password = 'hello!//\\#%$x'
233
+ assert_equal('hello!//\\#%$x', vtp.password)
219
234
  end
220
235
 
221
236
  def test_vtp_filename_nil
222
- no_feature_vtp
223
237
  vtp = vtp_domain("accounting")
224
238
  assert_raises(TypeError) do
225
239
  vtp.filename = nil
226
240
  end
227
- vtp.destroy
228
241
  end
229
242
 
230
243
  def test_vtp_filename_valid
231
- no_feature_vtp
232
244
  vtp = vtp_domain("accounting")
233
245
  vtp.filename = "bootflash:/test.dat"
234
246
  assert_equal("bootflash:/test.dat", vtp.filename,
235
247
  "Error: vtp file content wrong")
236
- vtp.destroy
237
248
  end
238
249
 
239
250
  def test_vtp_filename_zero_length
240
- no_feature_vtp
241
251
  vtp = vtp_domain("accounting")
242
252
  vtp.filename = vtp.default_filename
243
253
  assert_equal(node.config_get_default("vtp", "filename"), vtp.filename,
@@ -248,20 +258,24 @@ class TestVtp < CiscoTestCase
248
258
  vtp.filename = ""
249
259
  assert_equal(node.config_get_default("vtp", "filename"), vtp.filename,
250
260
  "Error: vtp file content wrong")
251
- vtp.destroy
261
+ end
262
+
263
+ def test_vtp_filename_auto_enable
264
+ vtp = Vtp.new(false)
265
+ refute(Vtp.enabled, "VTP should not be enabled")
266
+ vtp.filename = "bootflash:/foo.bar"
267
+ assert(Vtp.enabled)
268
+ assert_equal("bootflash:/foo.bar", vtp.filename)
252
269
  end
253
270
 
254
271
  def test_vtp_version_valid
255
- no_feature_vtp
256
272
  vtp = vtp_domain("accounting")
257
273
  vtp.version = vtp.default_version
258
274
  assert_equal(node.config_get_default("vtp", "version"), vtp.version,
259
275
  "Error: vtp version not default")
260
- vtp.destroy
261
276
  end
262
277
 
263
278
  def test_vtp_version3_valid
264
- no_feature_vtp
265
279
  vtp = vtp_domain("accounting")
266
280
 
267
281
  ref = cmd_ref.lookup("vtp", "version")
@@ -273,7 +287,6 @@ class TestVtp < CiscoTestCase
273
287
  }
274
288
 
275
289
  ref = nil
276
- vtp.destroy
277
290
  end
278
291
 
279
292
  # Decides whether to check for a raised Exception or an equal value.
@@ -288,16 +301,13 @@ class TestVtp < CiscoTestCase
288
301
  end
289
302
 
290
303
  def test_vtp_version_invalid
291
- no_feature_vtp
292
304
  vtp = vtp_domain("accounting")
293
305
  assert_raises(Cisco::CliError) do
294
306
  vtp.version = 34
295
307
  end
296
- vtp.destroy
297
308
  end
298
309
 
299
310
  def test_vtp_version_default
300
- no_feature_vtp
301
311
  vtp = vtp_domain("accounting")
302
312
  vtp.version = 2
303
313
  assert_equal(2, vtp.version,
@@ -305,11 +315,17 @@ class TestVtp < CiscoTestCase
305
315
  vtp.version = vtp.default_version
306
316
  assert_equal(node.config_get_default("vtp", "version"), vtp.version,
307
317
  "Error: vtp version not default")
308
- vtp.destroy
318
+ end
319
+
320
+ def test_vtp_version_auto_enable
321
+ vtp = Vtp.new(false)
322
+ refute(Vtp.enabled, "VTP should not be enabled")
323
+ vtp.version = 1
324
+ assert(Vtp.enabled)
325
+ assert_equal(1, vtp.version)
309
326
  end
310
327
 
311
328
  def test_vtp_feature_enable_disable
312
- no_feature_vtp
313
329
  Vtp.new.enable
314
330
  assert(Vtp.enabled, "Error: vtp is not enabled")
315
331