cisco_node_utils 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,6 +101,24 @@ module Cisco
101
101
  @@node.config_get_default("interface", "description")
102
102
  end
103
103
 
104
+ def encapsulation_dot1q
105
+ val = @@node.config_get("interface", "encapsulation_dot1q", @name)
106
+ return default_encapsulation_dot1q if val.nil?
107
+ val.shift.strip.to_i
108
+ end
109
+
110
+ def encapsulation_dot1q=(val)
111
+ val.nil? ?
112
+ @@node.config_set("interface", "encapsulation_dot1q", @name, "no", "") :
113
+ @@node.config_set("interface", "encapsulation_dot1q", @name, "", val)
114
+ rescue Cisco::CliError => e
115
+ raise "[#{@name}] '#{e.command}' : #{e.clierror}"
116
+ end
117
+
118
+ def default_encapsulation_dot1q
119
+ @@node.config_get_default("interface", "encapsulation_dot1q")
120
+ end
121
+
104
122
  def fex_feature
105
123
  fex = @@node.config_get("fex", "feature")
106
124
  raise "fex_feature not found" if fex.nil?
@@ -215,6 +233,33 @@ module Cisco
215
233
  @@node.config_get_default("interface", ipv4_redirects_lookup_string)
216
234
  end
217
235
 
236
+ def feature_lacp?
237
+ not @@node.config_get("interface", "feature_lacp").nil?
238
+ end
239
+
240
+ def feature_lacp_set(val)
241
+ return if feature_lacp? == val
242
+ @@node.config_set("interface", "feature_lacp", val ? "" : "no")
243
+ end
244
+
245
+ def mtu
246
+ mtu = @@node.config_get("interface", "mtu", @name)
247
+ return default_mtu if mtu.nil?
248
+ mtu.shift.strip.to_i
249
+ end
250
+
251
+ def mtu=(mtu)
252
+ mtu.nil? ?
253
+ @@node.config_set("interface", "mtu", @name, "no", "") :
254
+ @@node.config_set("interface", "mtu", @name, "", mtu)
255
+ rescue Cisco::CliError => e
256
+ raise "[#{@name}] '#{e.command}' : #{e.clierror}"
257
+ end
258
+
259
+ def default_mtu
260
+ @@node.config_get_default("interface", "mtu")
261
+ end
262
+
218
263
  def negotiate_auto_lookup_string
219
264
  case @name
220
265
  when /Ethernet/i
@@ -401,6 +446,48 @@ module Cisco
401
446
  @@node.config_get_default("interface", switchport_mode_lookup_string))
402
447
  end
403
448
 
449
+ def switchport_trunk_allowed_vlan
450
+ val = @@node.config_get(
451
+ "interface", "switchport_trunk_allowed_vlan", @name)
452
+ return default_switchport_trunk_allowed_vlan if val.nil?
453
+ val.shift.strip
454
+ end
455
+
456
+ def switchport_trunk_allowed_vlan=(val)
457
+ val.nil? ?
458
+ @@node.config_set(
459
+ "interface", "switchport_trunk_allowed_vlan", @name, "no", "") :
460
+ @@node.config_set(
461
+ "interface", "switchport_trunk_allowed_vlan", @name, "", val)
462
+ rescue Cisco::CliError => e
463
+ raise "[#{@name}] '#{e.command}' : #{e.clierror}"
464
+ end
465
+
466
+ def default_switchport_trunk_allowed_vlan
467
+ @@node.config_get_default("interface", "switchport_trunk_allowed_vlan")
468
+ end
469
+
470
+ def switchport_trunk_native_vlan
471
+ val = @@node.config_get(
472
+ "interface", "switchport_trunk_native_vlan", @name)
473
+ return default_switchport_trunk_native_vlan if val.nil?
474
+ val.shift.strip.to_i
475
+ end
476
+
477
+ def switchport_trunk_native_vlan=(val)
478
+ val.nil? ?
479
+ @@node.config_set(
480
+ "interface", "switchport_trunk_native_vlan", @name, "no", "") :
481
+ @@node.config_set(
482
+ "interface", "switchport_trunk_native_vlan", @name, "", val)
483
+ rescue Cisco::CliError => e
484
+ raise "[#{@name}] '#{e.command}' : #{e.clierror}"
485
+ end
486
+
487
+ def default_switchport_trunk_native_vlan
488
+ @@node.config_get_default("interface", "switchport_trunk_native_vlan")
489
+ end
490
+
404
491
  def system_default_switchport
405
492
  # This command is a user-configurable system default.
406
493
  sys_def = @@node.config_get("interface", "system_default_switchport")
@@ -497,5 +584,24 @@ module Cisco
497
584
  raise "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" +
498
585
  " is disabled" unless switchport_mode == :disabled
499
586
  end
587
+
588
+ def vrf
589
+ vrf = @@node.config_get("interface", "vrf", @name)
590
+ return "" if vrf.nil?
591
+ vrf.shift.strip
592
+ end
593
+
594
+ def vrf=(vrf)
595
+ raise TypeError unless vrf.is_a?(String)
596
+ vrf.empty? ?
597
+ @@node.config_set("interface", "vrf", @name, "no", "") :
598
+ @@node.config_set("interface", "vrf", @name, "", vrf)
599
+ rescue Cisco::CliError => e
600
+ raise "[#{@name}] '#{e.command}' : #{e.clierror}"
601
+ end
602
+
603
+ def default_vrf
604
+ @@node.config_get_default("interface", "vrf")
605
+ end
500
606
  end # Class
501
607
  end # Module
@@ -17,6 +17,7 @@
17
17
  # See the License for the specific language governing permissions and
18
18
  # limitations under the License.
19
19
 
20
+ require 'ipaddr'
20
21
  require File.join(File.dirname(__FILE__), 'node')
21
22
  require File.join(File.dirname(__FILE__), 'interface')
22
23
  # Interestingly enough, interface OSPF configuration can exist completely
@@ -24,7 +25,7 @@ require File.join(File.dirname(__FILE__), 'interface')
24
25
 
25
26
  module Cisco
26
27
  class InterfaceOspf
27
- attr_reader :interface, :ospf_name, :area
28
+ attr_reader :interface, :ospf_name
28
29
 
29
30
  @@node = Node.instance
30
31
 
@@ -42,7 +43,6 @@ module Cisco
42
43
  raise "interface #{int_name} does not exist" if @interface.nil?
43
44
 
44
45
  @ospf_name = ospf_name
45
- @area = area
46
46
 
47
47
  if create
48
48
  # enable feature ospf if it isn't
@@ -76,9 +76,23 @@ module Cisco
76
76
  ints
77
77
  end
78
78
 
79
+ def area
80
+ match = @@node.config_get("interface_ospf", "area", @interface.name)
81
+ return nil if match.nil?
82
+ val = match[0][1]
83
+ # Coerce numeric area to the expected dot-decimal format.
84
+ val = IPAddr.new(val.to_i, Socket::AF_INET).to_s unless val.match(/\./)
85
+ val
86
+ end
87
+
88
+ def area=(a)
89
+ @@node.config_set("interface_ospf", "area", @interface.name,
90
+ "", @ospf_name, a)
91
+ end
92
+
79
93
  def destroy
80
94
  @@node.config_set("interface_ospf", "area", @interface.name,
81
- "no", @ospf_name, @area)
95
+ "no", @ospf_name, area)
82
96
  # Reset everything else back to default as well:
83
97
  self.message_digest = default_message_digest
84
98
  message_digest_key_set(default_message_digest_key_id, "", "", "")
@@ -33,11 +33,11 @@ module Cisco
33
33
  attr_reader :command, :clierror, :previous
34
34
  def initialize(command, clierror, previous)
35
35
  @command = command
36
- @clierror = clierror
36
+ @clierror = clierror.rstrip
37
37
  @previous = previous
38
38
  end
39
39
 
40
- def message
40
+ def to_s
41
41
  "CliError: '#{@command}' rejected with message:\n'#{@clierror}'"
42
42
  end
43
43
  end
@@ -201,6 +201,12 @@ class RouterOspfVrf
201
201
  set_args_keys_delete([:start, :hold, :max])
202
202
  end
203
203
 
204
+ def default_timer_throttle_lsa
205
+ [default_timer_throttle_lsa_start,
206
+ default_timer_throttle_lsa_hold,
207
+ default_timer_throttle_lsa_max]
208
+ end
209
+
204
210
  def default_timer_throttle_lsa_start
205
211
  @@node.config_get_default("ospf", "timer_throttle_lsa_start")
206
212
  end
@@ -243,6 +249,12 @@ class RouterOspfVrf
243
249
  set_args_keys_delete([:start, :hold, :max])
244
250
  end
245
251
 
252
+ def default_timer_throttle_spf
253
+ [default_timer_throttle_spf_start,
254
+ default_timer_throttle_spf_hold,
255
+ default_timer_throttle_spf_max]
256
+ end
257
+
246
258
  def default_timer_throttle_spf_start
247
259
  @@node.config_get_default("ospf", "timer_throttle_spf_start")
248
260
  end
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module CiscoNodeUtils
16
- VERSION = "0.9.0"
16
+ VERSION = "1.0.0"
17
17
  end
@@ -47,7 +47,7 @@ class Vtp
47
47
 
48
48
  # Get vtp domain name
49
49
  def Vtp.domain
50
- @@node.config_get("vtp", "domain")
50
+ enabled ? @@node.config_get("vtp", "domain") : ""
51
51
  end
52
52
 
53
53
  def domain
@@ -55,11 +55,12 @@ class Vtp
55
55
  end
56
56
 
57
57
  # Set vtp domain name
58
- def domain=(domain)
59
- raise ArgumentError unless domain and domain.is_a? String and
60
- domain.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
58
+ def domain=(d)
59
+ raise ArgumentError unless d and d.is_a? String and
60
+ d.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
61
+ enable unless Vtp.enabled
61
62
  begin
62
- @@node.config_set("vtp", "domain", domain)
63
+ @@node.config_set("vtp", "domain", d)
63
64
  rescue Cisco::CliError => e
64
65
  # cmd will syntax reject when setting name to same name
65
66
  raise unless e.clierror =~ /ERROR: Domain name already set to /
@@ -69,9 +70,9 @@ class Vtp
69
70
  # Get vtp password
70
71
  def password
71
72
  # Unfortunately nxapi returns "\\" when the password is not set
72
- password = @@node.config_get("vtp", "password")
73
- return '' if password.nil?
74
- password.gsub(/\\/, '')
73
+ password = @@node.config_get("vtp", "password") if Vtp.enabled
74
+ return '' if password.nil? or password == "\\"
75
+ password
75
76
  end
76
77
 
77
78
  # Set vtp password
@@ -79,9 +80,15 @@ class Vtp
79
80
  raise TypeError if password.nil?
80
81
  raise TypeError unless password.is_a? String
81
82
  raise ArgumentError if password.length > MAX_VTP_PASSWORD_SIZE
82
- password == default_password ?
83
- @@node.config_set("vtp", "password", "no", "") :
84
- @@node.config_set("vtp", "password", "", password)
83
+ enable unless Vtp.enabled
84
+ begin
85
+ password == default_password ?
86
+ @@node.config_set("vtp", "password", "no", "") :
87
+ @@node.config_set("vtp", "password", "", password)
88
+ rescue Cisco::CliError => e
89
+ raise unless e.clierror =~ /password cannot be set for NULL domain/
90
+ raise "Setting VTP password requires first setting VTP domain" unless password == default_password
91
+ end
85
92
  end
86
93
 
87
94
  # Get default vtp password
@@ -98,6 +105,7 @@ class Vtp
98
105
  # Set vtp filename
99
106
  def filename=(uri)
100
107
  raise TypeError if uri.nil?
108
+ enable unless Vtp.enabled
101
109
  uri.empty? ?
102
110
  @@node.config_set("vtp", "filename", "no", "") :
103
111
  @@node.config_set("vtp", "filename", "", uri)
@@ -110,12 +118,13 @@ class Vtp
110
118
 
111
119
  # Get vtp version
112
120
  def version
113
- match = @@node.config_get("vtp", "version")
121
+ match = @@node.config_get("vtp", "version") if Vtp.enabled
114
122
  match.nil? ? default_version : match.first.to_i
115
123
  end
116
124
 
117
125
  # Set vtp version
118
126
  def version=(version)
127
+ enable unless Vtp.enabled
119
128
  @@node.config_set("vtp", "version", "#{version}")
120
129
  end
121
130
 
@@ -28,7 +28,7 @@ module Cisco
28
28
  # ex: chef-12.0.0alpha.2+20150319.git.1.b6f-1.el5.x86_64.rpm
29
29
  name_ver_arch_regex = /^([\w\-\+]+)-(\d+\..*)\.(\w{4,})(?:\.rpm)?$/
30
30
 
31
- # ex n9000_sample-1.0.0-7.0.3.x86_64.rpm
31
+ # ex n9000_sample-1.0.0-7.0.3.x86_64.rpm
32
32
  name_ver_arch_regex_nx = /^(.*)-([\d\.]+-[\d\.]+)\.(\w{4,})\.rpm$/
33
33
 
34
34
  # ex: b+z-ip2.x64_64
@@ -52,20 +52,30 @@ module Cisco
52
52
  end
53
53
  end
54
54
  should_ver = pkg_info[2] if pkg_info && pkg_info[3]
55
- ver = self.query(query_name)
55
+ ver = query(query_name)
56
56
  if ver.nil? || (!should_ver.nil? && should_ver != ver)
57
- raise RuntimeError, "Failed to install the requested rpm"
57
+ raise "Failed to install the requested rpm"
58
58
  end
59
59
  end
60
60
 
61
- def self.install(pkg)
62
- @@node.config_set("yum", "install", pkg)
61
+ def self.get_vrf
62
+ # Detect current namespace from agent environment
63
+ inode = File::Stat.new("/proc/self/ns/net").ino
64
+ # -L reqd for guestshell's find command
65
+ vrfname = File.basename(`find -L /var/run/netns/ -inum #{inode}`.chop)
66
+ vrf = "vrf " + vrfname unless vrfname.empty?
67
+ vrf
68
+ end
69
+
70
+ def self.install(pkg, vrf = nil)
71
+ vrf = vrf.nil? ? get_vrf : "vrf #{vrf}"
72
+ @@node.config_set("yum", "install", pkg, vrf)
63
73
 
64
74
  # HACK: The current nxos host installer is a multi-part command
65
75
  # which may fail at a later stage yet return a false positive;
66
76
  # therefore a post-validation check is needed here to verify the
67
77
  # actual outcome.
68
- self.validate(pkg)
78
+ validate(pkg)
69
79
  end
70
80
 
71
81
  # returns version of package, or false if package doesn't exist
@@ -28,6 +28,7 @@ class TestInterface < CiscoTestCase
28
28
  @@debug_validate_ipv4_address = "validate_ipv4_address"
29
29
  @@debug_validate_ipv4_proxy_arp = "validate_ipv4_proxy_arp"
30
30
  @@debug_validate_ipv4_redirects = "validate_ipv4_redirects"
31
+ @@debug_validate_vrf = "validate_vrf"
31
32
  @@debug_test_interface_ipv4_all_interfaces = "test_interface_ipv4_all_interfaces"
32
33
 
33
34
  # Debug flags, globally defined
@@ -63,7 +64,9 @@ SWITCHPORT_SHUTDOWN_HASH = {
63
64
  DEFAULT_IF_IP_NETMASK_LEN = nil
64
65
  DEFAULT_IF_IP_PROXY_ARP = false
65
66
  DEFAULT_IF_IP_REDIRECTS = true
67
+ DEFAULT_IF_VRF = ""
66
68
  IF_DESCRIPTION_SIZE = 243 # SIZE = VSH Max 255 - "description " keyword
69
+ IF_VRF_MAX_LENGTH = 32
67
70
 
68
71
  def interface_ipv4_config(ifname, address, length,
69
72
  config = true, secip = false)
@@ -225,16 +228,16 @@ SWITCHPORT_SHUTDOWN_HASH = {
225
228
 
226
229
  # check of description
227
230
  assert_equal(v[:description], interface.description,
228
- "Error: Description not configured")
231
+ "Error: [#{interface.name}] Description is not configured")
229
232
 
230
233
  # change description
231
234
  interface.description = v[:description_new]
232
235
  assert_equal(v[:description_new], interface.description,
233
- "Error: Description not configured")
236
+ "Error: [#{interface.name}] Description is not changed")
234
237
 
235
238
  # get_default check
236
239
  assert_equal(v[:default_description], interface.default_description,
237
- "Error: Description, default, not configured")
240
+ "Error: [#{interface.name}] Default description is not configured")
238
241
  end
239
242
  end
240
243
 
@@ -413,6 +416,31 @@ SWITCHPORT_SHUTDOWN_HASH = {
413
416
  end
414
417
  end
415
418
 
419
+ def validate_vrf(inttype_h)
420
+ # Validate the vrf
421
+ inttype_h.each do | k, v |
422
+ CiscoTestCase.debug(@@debug_validate_vrf,
423
+ @@debug_group_ipv4_all_interfaces,
424
+ 2,
425
+ "Interface: #{k}")
426
+ interface = v[:interface]
427
+
428
+ CiscoTestCase.debug_detail(@@debug_validate_vrf,
429
+ @@debug_group_ipv4_all_interfaces,
430
+ 4,
431
+ "Value - #{v[:vrf]}")
432
+
433
+ # change vrf
434
+ interface.vrf = v[:vrf_new]
435
+ assert_equal(v[:vrf_new], interface.vrf,
436
+ "Error: [#{interface.name}] vrf is not changed")
437
+
438
+ # set to default vrf
439
+ assert_equal(v[:default_vrf], interface.default_vrf,
440
+ "Error: [#{interface.name}] vrf config found. Should be default vrf")
441
+ end
442
+ end
443
+
416
444
  def test_interface_create_name_nil
417
445
  assert_raises(TypeError) do
418
446
  Interface.new(nil)
@@ -473,6 +501,62 @@ SWITCHPORT_SHUTDOWN_HASH = {
473
501
  interface_ethernet_default(interfaces_id[0])
474
502
  end
475
503
 
504
+ def test_interface_encapsulation_dot1q_change
505
+ interface = Interface.new(interfaces[0])
506
+ interface.switchport_mode = :disabled
507
+ subif = Interface.new(interfaces[0] + ".1")
508
+
509
+ subif.encapsulation_dot1q = 20
510
+ assert_equal(20, subif.encapsulation_dot1q)
511
+ subif.encapsulation_dot1q = 25
512
+ assert_equal(25, subif.encapsulation_dot1q)
513
+ interface_ethernet_default(interfaces_id[0])
514
+ end
515
+
516
+ def test_interface_encapsulation_dot1q_invalid
517
+ interface = Interface.new(interfaces[0])
518
+ interface.switchport_mode = :disabled
519
+ subif = Interface.new(interfaces[0] + ".1")
520
+
521
+ assert_raises(RuntimeError) {
522
+ subif.encapsulation_dot1q = "hello"
523
+ }
524
+ interface_ethernet_default(interfaces_id[0])
525
+ end
526
+
527
+ def test_interface_encapsulation_dot1q_valid
528
+ interface = Interface.new(interfaces[0])
529
+ interface.switchport_mode = :disabled
530
+ subif = Interface.new(interfaces[0] + ".1")
531
+
532
+ subif.encapsulation_dot1q = 20
533
+ assert_equal(20, subif.encapsulation_dot1q)
534
+ interface_ethernet_default(interfaces_id[0])
535
+ end
536
+
537
+ def test_interface_mtu_change
538
+ interface = Interface.new(interfaces[0])
539
+ interface.mtu = 1490
540
+ assert_equal(1490, interface.mtu)
541
+ interface.mtu = 580
542
+ assert_equal(580, interface.mtu)
543
+ interface_ethernet_default(interfaces_id[0])
544
+ end
545
+
546
+ def test_interface_mtu_invalid
547
+ interface = Interface.new(interfaces[0])
548
+ assert_raises(RuntimeError) {
549
+ interface.mtu = "hello"
550
+ }
551
+ end
552
+
553
+ def test_interface_mtu_valid
554
+ interface = Interface.new(interfaces[0])
555
+ interface.mtu = 1490
556
+ assert_equal(1490, interface.mtu)
557
+ interface_ethernet_default(interfaces_id[0])
558
+ end
559
+
476
560
  def test_interface_shutdown_valid
477
561
  interface = Interface.new(interfaces[0])
478
562
  interface.shutdown = true
@@ -906,7 +990,9 @@ SWITCHPORT_SHUTDOWN_HASH = {
906
990
  :switchport => :disabled,
907
991
  :default_switchport => :disabled,
908
992
  :access_vlan => DEFAULT_IF_ACCESS_VLAN,
909
- :default_access_vlan => DEFAULT_IF_ACCESS_VLAN
993
+ :default_access_vlan => DEFAULT_IF_ACCESS_VLAN,
994
+ :vrf_new => "test2",
995
+ :default_vrf => DEFAULT_IF_VRF,
910
996
  }
911
997
  inttype_h["Vlan45"] = {
912
998
  :address_len => "9.7.1.1/15",
@@ -921,7 +1007,9 @@ SWITCHPORT_SHUTDOWN_HASH = {
921
1007
  :switchport => :disabled,
922
1008
  :default_switchport => :disabled,
923
1009
  :access_vlan => DEFAULT_IF_ACCESS_VLAN,
924
- :default_access_vlan => DEFAULT_IF_ACCESS_VLAN
1010
+ :default_access_vlan => DEFAULT_IF_ACCESS_VLAN,
1011
+ :vrf_new => "test2",
1012
+ :default_vrf => DEFAULT_IF_VRF,
925
1013
  }
926
1014
  inttype_h["port-channel48"] = {
927
1015
  :address_len => "10.7.1.1/15",
@@ -936,7 +1024,9 @@ SWITCHPORT_SHUTDOWN_HASH = {
936
1024
  :switchport => :disabled,
937
1025
  :default_switchport => :disabled,
938
1026
  :access_vlan => DEFAULT_IF_ACCESS_VLAN,
939
- :default_access_vlan => DEFAULT_IF_ACCESS_VLAN
1027
+ :default_access_vlan => DEFAULT_IF_ACCESS_VLAN,
1028
+ :vrf_new => "test2",
1029
+ :default_vrf => DEFAULT_IF_VRF,
940
1030
  }
941
1031
  inttype_h["loopback0"] = {
942
1032
  :address_len => "11.7.1.1/15",
@@ -950,7 +1040,9 @@ SWITCHPORT_SHUTDOWN_HASH = {
950
1040
  :switchport => :disabled,
951
1041
  :default_switchport => :disabled,
952
1042
  :access_vlan => DEFAULT_IF_ACCESS_VLAN,
953
- :default_access_vlan => DEFAULT_IF_ACCESS_VLAN
1043
+ :default_access_vlan => DEFAULT_IF_ACCESS_VLAN,
1044
+ :vrf_new => "test2",
1045
+ :default_vrf => DEFAULT_IF_VRF,
954
1046
  }
955
1047
  # Skipping mgmt0 interface since that interface is our 'path' to
956
1048
  # master should revisit this later
@@ -999,6 +1091,7 @@ SWITCHPORT_SHUTDOWN_HASH = {
999
1091
  validate_ipv4_proxy_arp(inttype_h)
1000
1092
  validate_ipv4_redirects(inttype_h)
1001
1093
  validate_interface_shutdown(inttype_h)
1094
+ validate_vrf(inttype_h)
1002
1095
 
1003
1096
  # Cleanup the preload configuration
1004
1097
  s = @device.cmd("configure terminal")
@@ -1014,4 +1107,53 @@ SWITCHPORT_SHUTDOWN_HASH = {
1014
1107
  s = @device.cmd("end")
1015
1108
  node.cache_flush
1016
1109
  end
1110
+
1111
+ def test_interface_vrf_default
1112
+ @device.cmd("conf t ; interface loopback1 ; vrf member foo")
1113
+ node.cache_flush
1114
+ interface = Interface.new("loopback1")
1115
+ interface.vrf = interface.default_vrf
1116
+ assert_equal(DEFAULT_IF_VRF, interface.vrf)
1117
+ end
1118
+
1119
+ def test_interface_vrf_empty
1120
+ @device.cmd("conf t ; interface loopback1 ; vrf member foo")
1121
+ node.cache_flush
1122
+ interface = Interface.new("loopback1")
1123
+ interface.vrf = DEFAULT_IF_VRF
1124
+ assert_equal(DEFAULT_IF_VRF, interface.vrf)
1125
+ end
1126
+
1127
+ def test_interface_vrf_invalid_type
1128
+ interface = Interface.new("loopback1")
1129
+ assert_raises(TypeError) {
1130
+ interface.vrf = 1
1131
+ }
1132
+ end
1133
+
1134
+ def test_interface_vrf_exceeds_max_length
1135
+ interface = Interface.new("loopback1")
1136
+ long_string = "a" * (IF_VRF_MAX_LENGTH + 1)
1137
+ assert_raises(RuntimeError) {
1138
+ interface.vrf = long_string
1139
+ }
1140
+ end
1141
+
1142
+ def test_interface_vrf_override
1143
+ interface = Interface.new("loopback1")
1144
+ vrf1 = "test1"
1145
+ vrf2 = "test2"
1146
+ interface.vrf = vrf1
1147
+ interface.vrf = vrf2
1148
+ assert_equal(vrf2, interface.vrf)
1149
+ interface.destroy
1150
+ end
1151
+
1152
+ def test_interface_vrf_valid
1153
+ interface = Interface.new("loopback1")
1154
+ vrf = "test"
1155
+ interface.vrf = vrf
1156
+ assert_equal(vrf, interface.vrf)
1157
+ interface.destroy
1158
+ end
1017
1159
  end