cisco_node_utils 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -0,0 +1,74 @@
1
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/interface_channel_group'
17
+
18
+ # TestInterface - Minitest for general functionality of the Interface class.
19
+ class TestInterfaceChannelGroup < CiscoTestCase
20
+ @@clean = false # rubocop:disable Style/ClassVars
21
+ def setup
22
+ super
23
+ @intf = InterfaceChannelGroup.new(interfaces[1])
24
+
25
+ # Only pre-clean interface on initial setup
26
+ config("default interface #{@intf}") unless @@clean
27
+ @@clean = true # rubocop:disable Style/ClassVars
28
+ end
29
+
30
+ def teardown
31
+ config("default interface #{@intf}")
32
+ end
33
+
34
+ def test_channel_group
35
+ i = @intf
36
+ group = 200
37
+ i.channel_group = group
38
+ assert_equal(group, i.channel_group)
39
+
40
+ group = 201
41
+ i.channel_group = group
42
+ assert_equal(group, i.channel_group)
43
+
44
+ group = i.default_channel_group
45
+ i.channel_group = group
46
+ assert_equal(group, i.channel_group)
47
+ end
48
+
49
+ def test_description
50
+ i = @intf
51
+ desc = 'test desc'
52
+ i.description = desc
53
+ assert_equal(desc, i.description)
54
+
55
+ desc = 'test desc changed'
56
+ i.description = desc
57
+ assert_equal(desc, i.description)
58
+
59
+ desc = i.default_description
60
+ i.description = desc
61
+ assert_equal(desc, i.description)
62
+ end
63
+
64
+ def test_shutdown
65
+ i = @intf
66
+ i.shutdown = true
67
+ assert(i.shutdown)
68
+ i.shutdown = false
69
+ refute(i.shutdown)
70
+
71
+ i.shutdown = i.default_shutdown
72
+ assert(i.shutdown)
73
+ end
74
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
1
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -40,7 +40,12 @@ class TestInterfaceOspf < CiscoTestCase
40
40
  end
41
41
 
42
42
  def show_cmd(name)
43
- "show run interface #{name} all | no-more"
43
+ case name
44
+ when /ort-channel/
45
+ "show run interface #{name} | no-more"
46
+ else
47
+ "show run interface #{name} all | no-more"
48
+ end
44
49
  end
45
50
 
46
51
  def create_routerospf(ospfname='ospfTest')
@@ -495,14 +500,14 @@ class TestInterfaceOspf < CiscoTestCase
495
500
  assert_show_match(pattern: pattern,
496
501
  msg: 'Error: message digest enable missing in CLI')
497
502
  assert(interface.message_digest,
498
- 'Error: message digest get value mismatch')
503
+ 'Error: message digest is false but should be true')
499
504
 
500
505
  # get default and set
501
506
  interface.message_digest = interface.default_message_digest
502
507
  refute_show_match(pattern: pattern,
503
508
  msg: 'Error: default message digest set failed')
504
509
  refute(interface.message_digest,
505
- 'Error: message digest get value mismatch')
510
+ 'Error: message digest is true but should be false (default)')
506
511
  end
507
512
 
508
513
  def test_interfaceospf_message_digest_key
@@ -0,0 +1,105 @@
1
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/interface'
17
+ require_relative '../lib/cisco_node_utils/interface_portchannel'
18
+
19
+ # TestX__CLASS_NAME__X - Minitest for X__CLASS_NAME__X node utility class
20
+ class TestInterfacePortChannel < CiscoTestCase
21
+ # TESTS
22
+
23
+ DEFAULT_NAME = 'port-channel134'
24
+
25
+ def setup
26
+ super
27
+ config "no interface #{DEFAULT_NAME}"
28
+ end
29
+
30
+ def teardown
31
+ config "no interface #{DEFAULT_NAME}"
32
+ super
33
+ end
34
+
35
+ def n6k_platform?
36
+ /N(5|6)/ =~ node.product_id
37
+ end
38
+
39
+ def create_port_channel(ifname=DEFAULT_NAME)
40
+ InterfacePortChannel.new(ifname)
41
+ end
42
+
43
+ def test_get_set_port_hash_distribution
44
+ skip('Platform does not support this property') if n6k_platform?
45
+ interface = create_port_channel
46
+ interface.port_hash_distribution = 'adaptive'
47
+ assert_equal('adaptive', interface.port_hash_distribution)
48
+ interface.port_hash_distribution = 'fixed'
49
+ assert_equal('fixed', interface.port_hash_distribution)
50
+ interface.port_hash_distribution =
51
+ interface.default_port_hash_distribution
52
+ assert_equal(interface.default_port_hash_distribution,
53
+ interface.port_hash_distribution)
54
+ end
55
+
56
+ def test_get_set_lacp_graceful_convergence
57
+ interface = create_port_channel
58
+ interface.lacp_graceful_convergence = false
59
+ assert_equal(false, interface.lacp_graceful_convergence)
60
+ interface.lacp_graceful_convergence =
61
+ interface.default_lacp_graceful_convergence
62
+ assert_equal(interface.default_lacp_graceful_convergence,
63
+ interface.lacp_graceful_convergence)
64
+ end
65
+
66
+ def test_get_set_lacp_min_links
67
+ interface = create_port_channel
68
+ interface.lacp_min_links = 5
69
+ assert_equal(5, interface.lacp_min_links)
70
+ interface.lacp_min_links = interface.default_lacp_min_links
71
+ assert_equal(interface.default_lacp_min_links,
72
+ interface.lacp_min_links)
73
+ end
74
+
75
+ def test_get_set_lacp_max_bundle
76
+ interface = create_port_channel
77
+ interface.lacp_max_bundle = 10
78
+ assert_equal(10, interface.lacp_max_bundle)
79
+ interface.lacp_max_bundle =
80
+ interface.default_lacp_max_bundle
81
+ assert_equal(interface.default_lacp_max_bundle,
82
+ interface.lacp_max_bundle)
83
+ end
84
+
85
+ def test_get_set_lacp_suspend_individual
86
+ interface = create_port_channel
87
+ interface.lacp_suspend_individual = false
88
+ assert_equal(false, interface.lacp_suspend_individual)
89
+ interface.lacp_suspend_individual =
90
+ interface.default_lacp_suspend_individual
91
+ assert_equal(interface.default_lacp_suspend_individual,
92
+ interface.lacp_suspend_individual)
93
+ end
94
+
95
+ def test_get_set_port_load_defer
96
+ skip('Platform does not support this property') if n6k_platform?
97
+ interface = create_port_channel
98
+ interface.port_load_defer = true
99
+ assert_equal(true, interface.port_load_defer)
100
+ interface.port_load_defer =
101
+ interface.default_port_load_defer
102
+ assert_equal(interface.default_port_load_defer,
103
+ interface.port_load_defer)
104
+ end
105
+ end
@@ -0,0 +1,232 @@
1
+ # Copyright (c) 2013-2016 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/interface'
17
+ require_relative '../lib/cisco_node_utils/interface_service_vni'
18
+ require_relative '../lib/cisco_node_utils/vdc'
19
+
20
+ include Cisco
21
+
22
+ # TestInterfaceServiceVni - Minitest for the InterfaceServiceVni class.
23
+ #
24
+ # Example cli tested by this minitest:
25
+ #
26
+ # encapsulation profile vni vni_500_5000
27
+ # dot1q 500 vni 5000
28
+ # interface Ethernet9/1
29
+ # service instance 5 vni
30
+ # encapsulation profile vni_500_5000 default
31
+ # shutdown
32
+ # service instance 6 vni
33
+ # encapsulation profile vni_600_6000 default
34
+ #
35
+ class TestInterfaceServiceVni < CiscoTestCase
36
+ def setup
37
+ super
38
+ end
39
+
40
+ def teardown
41
+ # Reset the vdc module type back to default
42
+ v = Vdc.new('default')
43
+ v.limit_resource_module_type = '' if v.limit_resource_module_type == 'f3'
44
+ end
45
+
46
+ def compatible_interface?
47
+ # MT-full tests require a specific linecard; either because they need a
48
+ # compatible interface or simply to enable the features. Either way
49
+ # we will provide an appropriate interface name if the linecard is present.
50
+ # Example 'show mod' output to match against:
51
+ # '9 12 10/40 Gbps Ethernet Module N7K-F312FQ-25 ok'
52
+ sh_mod = @device.cmd("sh mod | i '^[0-9]+.*N7K-F3'")[/^(\d+)\s.*N7K-F3/]
53
+ slot = sh_mod.nil? ? nil : Regexp.last_match[1]
54
+ skip('Unable to find compatible interface in chassis') if slot.nil?
55
+
56
+ "ethernet#{slot}/1"
57
+ end
58
+
59
+ def mt_full_env_setup
60
+ skip('Platform does not support MT-full') unless Vni.mt_full_support
61
+ intf = compatible_interface?
62
+ v = Vdc.new('default')
63
+ v.limit_resource_module_type = 'f3' unless
64
+ v.limit_resource_module_type == 'f3'
65
+ config("default int #{intf}")
66
+ intf
67
+ end
68
+
69
+ def global_setup
70
+ # Reset feature to clean up switch
71
+ config('no feature vni', 'feature vni')
72
+
73
+ # Create a global encap config
74
+ config('encapsulation profile vni vni_500_5000', 'dot1q 500 vni 5000',
75
+ 'encapsulation profile vni vni_600_6000', 'dot1q 600 vni 6000',
76
+ 'encapsulation profile vni vni_700_7000', 'dot1q 700 vni 7000',
77
+ 'encapsulation profile vni vni_800_8000', 'dot1q 800 vni 8000')
78
+
79
+ # Configure a bridge-domain
80
+ config('system bridge-domain 100-113', 'bridge-domain 100')
81
+ end
82
+
83
+ def test_create_destroy
84
+ # This property has several dependencies:
85
+ # - VDC support
86
+ # - Specific linecard (F3 or newer)
87
+ # - Bridge Domain Configuration
88
+ # - Feature vni
89
+
90
+ intf = mt_full_env_setup
91
+ global_setup
92
+
93
+ # TEST Create / Destroy and svc_vni_ids hash builder
94
+ i5 = InterfaceServiceVni.new(intf, 5)
95
+ assert_equal(1, InterfaceServiceVni.svc_vni_ids[intf].count)
96
+ i6 = InterfaceServiceVni.new(intf, 6)
97
+ i7 = InterfaceServiceVni.new(intf, 7)
98
+ assert_equal(3, InterfaceServiceVni.svc_vni_ids[intf].count)
99
+ i6.destroy
100
+ assert_equal(2, InterfaceServiceVni.svc_vni_ids[intf].count)
101
+ i5.destroy
102
+ i7.destroy
103
+ end
104
+
105
+ def test_shutdown
106
+ intf = mt_full_env_setup
107
+ global_setup
108
+
109
+ i5 = InterfaceServiceVni.new(intf, 5)
110
+ # Test shutdown
111
+ i5.shutdown = false
112
+ refute(i5.shutdown)
113
+ i5.shutdown = true
114
+ assert(i5.shutdown)
115
+ i5.shutdown = false
116
+ refute(i5.shutdown)
117
+ i5.shutdown = i5.default_shutdown
118
+ assert(i5.shutdown)
119
+ end
120
+
121
+ def test_encapsulation_profile_vni
122
+ intf = mt_full_env_setup
123
+ global_setup
124
+
125
+ i5 = InterfaceServiceVni.new(intf, 5)
126
+
127
+ # Test removal when profile not present
128
+ i5.encapsulation_profile_vni = ''
129
+ assert_empty(i5.encapsulation_profile_vni)
130
+
131
+ # Add one
132
+ i5.encapsulation_profile_vni = 'vni_500_5000'
133
+ assert_equal('vni_500_5000', i5.encapsulation_profile_vni)
134
+
135
+ # Change it
136
+ i5.encapsulation_profile_vni = 'vni_700_7000'
137
+ assert_equal('vni_700_7000', i5.encapsulation_profile_vni)
138
+
139
+ # Test default when profile present
140
+ i5.encapsulation_profile_vni = 'vni_700_7000'
141
+ i5.encapsulation_profile_vni = i5.default_encapsulation_profile_vni
142
+ assert_equal(i5.default_encapsulation_profile_vni,
143
+ i5.encapsulation_profile_vni)
144
+ end
145
+
146
+ # interface vlan_mapping is not technically part of the interface service
147
+ # but it shares most of the same dependencies so it is tested here instead
148
+ # of test_interface.rb
149
+ def test_vlan_mapping
150
+ # This test covers two properties:
151
+ # vlan_mapping & vlan_mapping_enabled
152
+ #
153
+ # This property has several dependencies:
154
+ # - VDC support
155
+ # - Specific linecard (F3)
156
+ # - Bridge Domain Configuration
157
+ # - Feature vni
158
+ intf = mt_full_env_setup
159
+ global_setup
160
+
161
+ i = Interface.new(intf)
162
+ i.switchport_mode = :trunk
163
+ i.vlan_mapping = []
164
+ assert_equal([], i.vlan_mapping, 'Initial cleanup failed')
165
+
166
+ # Initial 'should' state
167
+ # rubocop:disable Style/WordArray
168
+ master = [['20', '21'],
169
+ ['40', '41'],
170
+ ['60', '61'],
171
+ ['80', '81']]
172
+ # rubocop:enable Style/WordArray
173
+
174
+ # Test: Add all mappings when no cmds are present
175
+ should = master.clone
176
+ i.vlan_mapping = should
177
+ result = i.vlan_mapping
178
+ assert_equal(should.sort, result.sort,
179
+ 'Test 1a. From empty, to all mappings')
180
+ i.vlan_mapping_enable = false
181
+ refute(i.vlan_mapping_enable,
182
+ 'Test 1b. Initial test, set to disabled')
183
+
184
+ # Test: remove half of the mappings
185
+ should.shift(2)
186
+ i.vlan_mapping = should
187
+ result = i.vlan_mapping
188
+ assert_equal(should.sort, result.sort,
189
+ 'Test 2a. Remove half of the mappings')
190
+ i.vlan_mapping_enable = true
191
+ assert(i.vlan_mapping_enable,
192
+ 'Test 2b. Back to enabled')
193
+
194
+ # Test: restore the removed mappings
195
+ should = master.clone
196
+ i.vlan_mapping = should
197
+ result = i.vlan_mapping
198
+ assert_equal(should.sort, result.sort,
199
+ 'Test 3a. Restore the removed mappings')
200
+ i.vlan_mapping_enable = false
201
+ refute(i.vlan_mapping_enable,
202
+ 'Test 3b. Back to disabled')
203
+
204
+ # Test: Change original-vlan on existing commands
205
+ should = should.map do |original, translated|
206
+ [original + '1', translated]
207
+ end
208
+ i.vlan_mapping = should
209
+ result = i.vlan_mapping
210
+ assert_equal(should.sort, result.sort,
211
+ 'Test 4. Change original-vlan on existing commands')
212
+
213
+ # Test: Change translated-vlan on existing commands
214
+ should = should.map do |original, translated|
215
+ [original, translated + '1']
216
+ end
217
+ i.vlan_mapping = should
218
+ result = i.vlan_mapping
219
+ assert_equal(should.sort, result.sort,
220
+ 'Test 5. Change translated-vlan on existing commands')
221
+
222
+ # Test: 'default'
223
+ should = i.default_vlan_mapping
224
+ i.vlan_mapping = should
225
+ result = i.vlan_mapping
226
+ assert_equal(should.sort, result.sort,
227
+ "Test 6a. 'default'")
228
+ i.vlan_mapping_enable = i.default_vlan_mapping_enable
229
+ assert(i.vlan_mapping_enable,
230
+ "Test 6b. 'default'")
231
+ end
232
+ end