From 8f4735dc8dcfe5077c2150c9e45438c83163bc30 Mon Sep 17 00:00:00 2001 From: mikewiebe Date: Thu, 11 Feb 2016 11:35:20 -0500 Subject: [PATCH 1/3] fabric_forwarding_anycast fixes --- lib/cisco_node_utils/feature.rb | 20 ++++++++++---------- lib/cisco_node_utils/interface.rb | 9 ++++++--- lib/cisco_node_utils/overlay_global.rb | 4 +++- tests/test_interface.rb | 20 ++++++++------------ 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/cisco_node_utils/feature.rb b/lib/cisco_node_utils/feature.rb index cdb02e09..4c0f29f3 100644 --- a/lib/cisco_node_utils/feature.rb +++ b/lib/cisco_node_utils/feature.rb @@ -56,7 +56,15 @@ def self.fabric_supported? def self.fabric_forwarding_enable return if fabric_forwarding_enabled? Feature.fabric_enable if Feature.fabric_supported? - config_set('feature', 'fabric_forwarding') + # The feature fabric-forwarding cli is required in some older nxos images + # but is not present in newer images because nv_overlay_evpn handles + # both features; therefore feature fabric-forwarding is best-effort + # and ignored on cli failure. + begin + config_set('feature', 'fabric_forwarding') + rescue Cisco::CliError + CiscoLogger.debug '"feature fabric forwarding" CLI was rejected' + end end def self.fabric_forwarding_enabled? @@ -80,15 +88,7 @@ def self.nv_overlay_enabled? # --------------------------- def self.nv_overlay_evpn_enable - # The feature fabric-forwarding cli is required in some older nxos images - # but is not present in newer images because nv_overlay_evpn handles - # both features; therefore feature fabric-forwarding is best-effort - # and ignored on cli failure. - begin - config_set('feature', 'fabric_forwarding') - rescue Cisco::CliError - CiscoLogger.debug '"feature fabric forwarding" CLI was rejected' - end + return if nv_overlay_evpn_enabled? config_set('feature', 'nv_overlay_evpn') end diff --git a/lib/cisco_node_utils/interface.rb b/lib/cisco_node_utils/interface.rb index f895ea6d..9ff054d0 100644 --- a/lib/cisco_node_utils/interface.rb +++ b/lib/cisco_node_utils/interface.rb @@ -216,12 +216,15 @@ def fabric_forwarding_anycast_gateway=(state) 'fabric_forwarding_anycast_gateway', @name, no_cmd) fail if fabric_forwarding_anycast_gateway.to_s != state.to_s rescue Cisco::CliError => e + info = "[#{@name}] '#{e.command}' : #{e.clierror}" + raise "#{info} 'fabric_forwarding_anycast_gateway' can ony be " \ + 'configured on a vlan interface' unless /vlan/.match(@name) anycast_gateway_mac = OverlayGlobal.new.anycast_gateway_mac if anycast_gateway_mac.nil? || anycast_gateway_mac.empty? - raise "[#{@name}] '#{e.command}' : #{e.clierror} - Anycast gateway mac needs to be configured - before configuring forwarding mode under interface" + raise "#{info} Anycast gateway mac needs to be configured " \ + 'before configuring forwarding mode under interface' end + raise info end def default_fabric_forwarding_anycast_gateway diff --git a/lib/cisco_node_utils/overlay_global.rb b/lib/cisco_node_utils/overlay_global.rb index dcd4412e..1fb03df5 100644 --- a/lib/cisco_node_utils/overlay_global.rb +++ b/lib/cisco_node_utils/overlay_global.rb @@ -131,7 +131,9 @@ def anycast_gateway_mac def anycast_gateway_mac=(mac_addr) fail TypeError unless mac_addr.is_a?(String) - Feature.nv_overlay_evpn_enable + Feature.nv_overlay_evpn_enable unless Feature.nv_overlay_evpn_enabled? + Feature.fabric_forwarding_enable unless + Feature.fabric_forwarding_enabled? if mac_addr == default_anycast_gateway_mac state = 'no' mac_addr = '' diff --git a/tests/test_interface.rb b/tests/test_interface.rb index cf0380d9..0ce5125a 100755 --- a/tests/test_interface.rb +++ b/tests/test_interface.rb @@ -961,14 +961,14 @@ def test_interface_ipv4_arp_timeout def test_interface_fabric_forwarding_anycast_gateway # Setup + config('no nv overlay evpn') + config('no feature fabric forwarding') config('no interface vlan11') int = Interface.new('vlan11') foo = OverlayGlobal.new foo.anycast_gateway_mac = '1223.3445.5668' - # 1. Testing default - int.fabric_forwarding_anycast_gateway = - int.default_fabric_forwarding_anycast_gateway + # 1. Testing default for newly created vlan assert_equal(int.default_fabric_forwarding_anycast_gateway, int.fabric_forwarding_anycast_gateway) @@ -980,19 +980,15 @@ def test_interface_fabric_forwarding_anycast_gateway int.fabric_forwarding_anycast_gateway = false refute(int.fabric_forwarding_anycast_gateway) - # 4. Removing fabric forwarding anycast gateway mac - foo.anycast_gateway_mac = foo.default_anycast_gateway_mac - assert_raises(RuntimeError) { int.fabric_forwarding_anycast_gateway = true } - - # 5. Removing feature fabric forwarding - config('no feature fabric forwarding') - assert_raises(RuntimeError) { int.fabric_forwarding_anycast_gateway = true } - - # 6. Attempting to configure on a non-vlan interface + # 4. Attempt to configure on a non-vlan interface nonvlanint = create_interface assert_raises(RuntimeError) do nonvlanint.fabric_forwarding_anycast_gateway = true end + + # 5. Removing fabric forwarding anycast gateway mac + foo.anycast_gateway_mac = foo.default_anycast_gateway_mac + assert_raises(RuntimeError) { int.fabric_forwarding_anycast_gateway = true } end def test_interface_ipv4_proxy_arp From b6e75b43da01286683491900fabf3cb6f3838bf5 Mon Sep 17 00:00:00 2001 From: mikewiebe Date: Thu, 11 Feb 2016 12:05:51 -0500 Subject: [PATCH 2/3] Addressed comments --- lib/cisco_node_utils/interface.rb | 4 ++-- lib/cisco_node_utils/overlay_global.rb | 7 +++---- tests/test_interface.rb | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/cisco_node_utils/interface.rb b/lib/cisco_node_utils/interface.rb index 9ff054d0..ad012e7a 100644 --- a/lib/cisco_node_utils/interface.rb +++ b/lib/cisco_node_utils/interface.rb @@ -217,11 +217,11 @@ def fabric_forwarding_anycast_gateway=(state) fail if fabric_forwarding_anycast_gateway.to_s != state.to_s rescue Cisco::CliError => e info = "[#{@name}] '#{e.command}' : #{e.clierror}" - raise "#{info} 'fabric_forwarding_anycast_gateway' can ony be " \ + raise "#{info} 'fabric_forwarding_anycast_gateway' can only be " \ 'configured on a vlan interface' unless /vlan/.match(@name) anycast_gateway_mac = OverlayGlobal.new.anycast_gateway_mac if anycast_gateway_mac.nil? || anycast_gateway_mac.empty? - raise "#{info} Anycast gateway mac needs to be configured " \ + raise "#{info} Anycast gateway mac must to be configured " \ 'before configuring forwarding mode under interface' end raise info diff --git a/lib/cisco_node_utils/overlay_global.rb b/lib/cisco_node_utils/overlay_global.rb index 1fb03df5..f5333c31 100644 --- a/lib/cisco_node_utils/overlay_global.rb +++ b/lib/cisco_node_utils/overlay_global.rb @@ -50,7 +50,7 @@ def dup_host_ip_addr_detection_timeout end def dup_host_ip_addr_detection_set(host_moves, timeout) - Feature.nv_overlay_evpn_enable unless Feature.nv_overlay_evpn_enabled? + Feature.nv_overlay_evpn_enable if host_moves == default_dup_host_ip_addr_detection_host_moves && timeout == default_dup_host_ip_addr_detection_timeout state = 'no' @@ -131,9 +131,8 @@ def anycast_gateway_mac def anycast_gateway_mac=(mac_addr) fail TypeError unless mac_addr.is_a?(String) - Feature.nv_overlay_evpn_enable unless Feature.nv_overlay_evpn_enabled? - Feature.fabric_forwarding_enable unless - Feature.fabric_forwarding_enabled? + Feature.nv_overlay_evpn_enable + Feature.fabric_forwarding_enable if mac_addr == default_anycast_gateway_mac state = 'no' mac_addr = '' diff --git a/tests/test_interface.rb b/tests/test_interface.rb index 0ce5125a..596b9ecc 100755 --- a/tests/test_interface.rb +++ b/tests/test_interface.rb @@ -961,8 +961,6 @@ def test_interface_ipv4_arp_timeout def test_interface_fabric_forwarding_anycast_gateway # Setup - config('no nv overlay evpn') - config('no feature fabric forwarding') config('no interface vlan11') int = Interface.new('vlan11') foo = OverlayGlobal.new @@ -986,7 +984,8 @@ def test_interface_fabric_forwarding_anycast_gateway nonvlanint.fabric_forwarding_anycast_gateway = true end - # 5. Removing fabric forwarding anycast gateway mac + # 5. Attempt to set 'fabric forwarding anycast gateway' while the + # overlay gateway mac is not set. foo.anycast_gateway_mac = foo.default_anycast_gateway_mac assert_raises(RuntimeError) { int.fabric_forwarding_anycast_gateway = true } end From 8183015da21d11074b4bc82c805fe009c671ae3c Mon Sep 17 00:00:00 2001 From: mikewiebe Date: Thu, 11 Feb 2016 12:09:22 -0500 Subject: [PATCH 3/3] Typo fix --- lib/cisco_node_utils/interface.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cisco_node_utils/interface.rb b/lib/cisco_node_utils/interface.rb index ad012e7a..2bcf0686 100644 --- a/lib/cisco_node_utils/interface.rb +++ b/lib/cisco_node_utils/interface.rb @@ -221,7 +221,7 @@ def fabric_forwarding_anycast_gateway=(state) 'configured on a vlan interface' unless /vlan/.match(@name) anycast_gateway_mac = OverlayGlobal.new.anycast_gateway_mac if anycast_gateway_mac.nil? || anycast_gateway_mac.empty? - raise "#{info} Anycast gateway mac must to be configured " \ + raise "#{info} Anycast gateway mac must be configured " \ 'before configuring forwarding mode under interface' end raise info