cisco_node_utils 1.2.0 → 1.3.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.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +4 -1
  6. data/CHANGELOG.md +81 -2
  7. data/CONTRIBUTING.md +2 -17
  8. data/Gemfile +5 -0
  9. data/README.md +92 -47
  10. data/Rakefile +23 -1
  11. data/bin/git/hooks/hook_lib +7 -0
  12. data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
  13. data/bin/git/hooks/pre-commit/rubocop +7 -2
  14. data/bin/git/hooks/pre-commit/validate-diffs +18 -4
  15. data/bin/git/hooks/pre-commit/validate-yaml +18 -0
  16. data/bin/git/update-hooks +64 -6
  17. data/cisco_node_utils.gemspec +9 -6
  18. data/docs/README-develop-best-practices.md +149 -50
  19. data/docs/README-develop-node-utils-APIs.md +92 -42
  20. data/docs/README-maintainers.md +7 -4
  21. data/docs/README-test-execution.md +57 -0
  22. data/docs/cisco_node_utils.yaml.example +30 -0
  23. data/docs/template-router.rb +4 -0
  24. data/ext/mkrf_conf.rb +63 -0
  25. data/lib/.rubocop.yml +2 -2
  26. data/lib/cisco_node_utils.rb +5 -0
  27. data/lib/cisco_node_utils/aaa_authentication_login.rb +5 -6
  28. data/lib/cisco_node_utils/aaa_authorization_service.rb +1 -1
  29. data/lib/cisco_node_utils/ace.rb +165 -12
  30. data/lib/cisco_node_utils/acl.rb +2 -1
  31. data/lib/cisco_node_utils/bgp.rb +184 -21
  32. data/lib/cisco_node_utils/bgp_af.rb +94 -249
  33. data/lib/cisco_node_utils/bgp_neighbor.rb +94 -14
  34. data/lib/cisco_node_utils/bgp_neighbor_af.rb +75 -8
  35. data/lib/cisco_node_utils/bridge_domain.rb +183 -0
  36. data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
  37. data/lib/cisco_node_utils/cisco_cmn_utils.rb +85 -2
  38. data/lib/cisco_node_utils/client.rb +35 -0
  39. data/lib/cisco_node_utils/client/client.rb +234 -0
  40. data/lib/cisco_node_utils/client/grpc.rb +33 -0
  41. data/lib/cisco_node_utils/client/grpc/client.rb +311 -0
  42. data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
  43. data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
  44. data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
  45. data/lib/cisco_node_utils/client/nxapi.rb +31 -0
  46. data/lib/cisco_node_utils/client/nxapi/client.rb +305 -0
  47. data/lib/cisco_node_utils/client/utils.rb +164 -0
  48. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +222 -254
  49. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +11 -8
  50. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +22 -15
  51. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +11 -8
  52. data/lib/cisco_node_utils/cmd_ref/acl.yaml +21 -16
  53. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +239 -109
  54. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +114 -55
  55. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +76 -52
  56. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +106 -62
  57. data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +71 -0
  58. data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
  59. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +35 -14
  60. data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
  61. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +23 -17
  62. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +94 -83
  63. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +22 -17
  64. data/lib/cisco_node_utils/cmd_ref/feature.yaml +76 -26
  65. data/lib/cisco_node_utils/cmd_ref/images.yaml +3 -2
  66. data/lib/cisco_node_utils/cmd_ref/interface.yaml +381 -153
  67. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +21 -11
  68. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +21 -21
  69. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +30 -21
  70. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +18 -13
  71. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +26 -31
  72. data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
  73. data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
  74. data/lib/cisco_node_utils/cmd_ref/memory.yaml +17 -6
  75. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +10 -3
  76. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +17 -5
  77. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +33 -29
  78. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +12 -10
  79. data/lib/cisco_node_utils/cmd_ref/pim.yaml +16 -19
  80. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +40 -25
  81. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +17 -12
  82. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +71 -35
  83. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +10 -5
  84. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +6 -2
  85. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +47 -43
  86. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +13 -11
  87. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +4 -2
  88. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +23 -21
  89. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +26 -22
  90. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +19 -17
  91. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +18 -6
  92. data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +234 -0
  93. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +24 -9
  94. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +5 -3
  95. data/lib/cisco_node_utils/cmd_ref/system.yaml +4 -3
  96. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +22 -20
  97. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +27 -15
  98. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +45 -16
  99. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +21 -11
  100. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +3 -2
  101. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +60 -32
  102. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +118 -101
  103. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +54 -58
  104. data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +118 -0
  105. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +19 -25
  106. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +28 -18
  107. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +34 -17
  108. data/lib/cisco_node_utils/cmd_ref/yum.yaml +6 -4
  109. data/lib/cisco_node_utils/command_reference.rb +261 -142
  110. data/lib/cisco_node_utils/constants.rb +33 -0
  111. data/lib/cisco_node_utils/encapsulation.rb +112 -0
  112. data/lib/cisco_node_utils/environment.rb +102 -0
  113. data/lib/cisco_node_utils/evpn_vni.rb +5 -3
  114. data/lib/cisco_node_utils/exceptions.rb +111 -0
  115. data/lib/cisco_node_utils/fabricpath_global.rb +52 -35
  116. data/lib/cisco_node_utils/fabricpath_topology.rb +44 -57
  117. data/lib/cisco_node_utils/feature.rb +165 -3
  118. data/lib/cisco_node_utils/interface.rb +1051 -260
  119. data/lib/cisco_node_utils/interface_channel_group.rb +11 -10
  120. data/lib/cisco_node_utils/interface_ospf.rb +1 -2
  121. data/lib/cisco_node_utils/interface_portchannel.rb +4 -12
  122. data/lib/cisco_node_utils/interface_service_vni.rb +7 -7
  123. data/lib/cisco_node_utils/itd_device_group.rb +248 -0
  124. data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
  125. data/lib/cisco_node_utils/itd_service.rb +523 -0
  126. data/lib/cisco_node_utils/logger.rb +75 -0
  127. data/lib/cisco_node_utils/node.rb +62 -192
  128. data/lib/cisco_node_utils/node_util.rb +56 -10
  129. data/lib/cisco_node_utils/overlay_global.rb +2 -2
  130. data/lib/cisco_node_utils/pim.rb +2 -13
  131. data/lib/cisco_node_utils/pim_group_list.rb +1 -1
  132. data/lib/cisco_node_utils/pim_rp_address.rb +1 -1
  133. data/lib/cisco_node_utils/platform.rb +52 -21
  134. data/lib/cisco_node_utils/portchannel_global.rb +89 -19
  135. data/lib/cisco_node_utils/radius_server.rb +168 -37
  136. data/lib/cisco_node_utils/router_ospf.rb +20 -35
  137. data/lib/cisco_node_utils/router_ospf_vrf.rb +4 -4
  138. data/lib/cisco_node_utils/snmpserver.rb +1 -6
  139. data/lib/cisco_node_utils/snmpuser.rb +6 -4
  140. data/lib/cisco_node_utils/stp_global.rb +676 -0
  141. data/lib/cisco_node_utils/syslog_server.rb +77 -18
  142. data/lib/cisco_node_utils/syslog_settings.rb +1 -1
  143. data/lib/cisco_node_utils/tacacs_server_group.rb +8 -4
  144. data/lib/cisco_node_utils/tacacs_server_host.rb +115 -25
  145. data/lib/cisco_node_utils/vdc.rb +12 -0
  146. data/lib/cisco_node_utils/version.rb +1 -1
  147. data/lib/cisco_node_utils/vlan.rb +147 -29
  148. data/lib/cisco_node_utils/vpc.rb +55 -3
  149. data/lib/cisco_node_utils/vrf.rb +72 -11
  150. data/lib/cisco_node_utils/vrf_af.rb +114 -29
  151. data/lib/cisco_node_utils/vtp.rb +34 -52
  152. data/lib/cisco_node_utils/vxlan_vtep.rb +34 -8
  153. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +36 -4
  154. data/lib/minitest/environment_plugin.rb +31 -0
  155. data/lib/minitest/log_level_plugin.rb +41 -0
  156. data/spec/client_spec.rb +7 -0
  157. data/spec/environment_spec.rb +263 -0
  158. data/spec/grpc_client_spec.rb +23 -0
  159. data/spec/isolate/all_clients_spec.rb +9 -0
  160. data/spec/isolate/grpc_only_spec.rb +16 -0
  161. data/spec/isolate/no_clients_spec.rb +26 -0
  162. data/spec/isolate/nxapi_only_spec.rb +16 -0
  163. data/spec/nxapi_client_spec.rb +42 -0
  164. data/spec/schema.yaml +75 -0
  165. data/spec/shared_examples_for_clients.rb +14 -0
  166. data/spec/spec_helper.rb +91 -0
  167. data/spec/whitespace_spec.rb +10 -0
  168. data/spec/yaml_spec.rb +42 -0
  169. data/tests/.rubocop.yml +2 -2
  170. data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
  171. data/tests/basetest.rb +96 -36
  172. data/tests/ciscotest.rb +220 -12
  173. data/tests/cmd_config.yaml +71 -49
  174. data/tests/cmd_config_invalid.yaml +1 -1
  175. data/tests/test_aaa_authentication_login.rb +1 -0
  176. data/tests/test_aaa_authentication_login_service.rb +9 -0
  177. data/tests/test_aaa_authorization_service.rb +173 -367
  178. data/tests/test_ace.rb +171 -100
  179. data/tests/test_acl.rb +10 -1
  180. data/tests/test_bgp_af.rb +395 -728
  181. data/tests/test_bgp_neighbor.rb +274 -115
  182. data/tests/test_bgp_neighbor_af.rb +178 -77
  183. data/tests/test_bridge_domain.rb +191 -0
  184. data/tests/test_bridge_domain_vni.rb +116 -0
  185. data/tests/test_client_utils.rb +111 -0
  186. data/tests/test_command_config.rb +9 -5
  187. data/tests/test_command_reference.rb +380 -102
  188. data/tests/test_dns_domain.rb +13 -3
  189. data/tests/test_domain_name.rb +13 -3
  190. data/tests/test_encapsulation.rb +77 -0
  191. data/tests/test_evpn_vni.rb +25 -7
  192. data/tests/test_fabricpath_global.rb +167 -163
  193. data/tests/test_fabricpath_topology.rb +12 -33
  194. data/tests/test_feature.rb +215 -0
  195. data/tests/test_grpc.rb +166 -0
  196. data/tests/test_interface.rb +585 -344
  197. data/tests/test_interface_bdi.rb +80 -0
  198. data/tests/test_interface_channel_group.rb +6 -3
  199. data/tests/test_interface_ospf.rb +26 -24
  200. data/tests/test_interface_portchannel.rb +1 -0
  201. data/tests/test_interface_private_vlan.rb +724 -0
  202. data/tests/test_interface_service_vni.rb +37 -66
  203. data/tests/test_interface_svi.rb +98 -101
  204. data/tests/test_interface_switchport.rb +419 -549
  205. data/tests/test_itd_device_group.rb +145 -0
  206. data/tests/test_itd_device_group_node.rb +199 -0
  207. data/tests/test_itd_service.rb +298 -0
  208. data/tests/test_logger.rb +43 -0
  209. data/tests/test_name_server.rb +11 -2
  210. data/tests/test_node.rb +16 -75
  211. data/tests/test_node_ext.rb +174 -163
  212. data/tests/test_node_util.rb +119 -0
  213. data/tests/test_ntp_config.rb +5 -1
  214. data/tests/test_ntp_server.rb +2 -2
  215. data/tests/test_nxapi.rb +221 -0
  216. data/tests/test_overlay_global.rb +47 -38
  217. data/tests/test_pim.rb +2 -0
  218. data/tests/test_pim_group_list.rb +2 -0
  219. data/tests/test_pim_rp_address.rb +2 -0
  220. data/tests/test_platform.rb +86 -39
  221. data/tests/test_portchannel_global.rb +211 -135
  222. data/tests/test_radius_global.rb +13 -5
  223. data/tests/test_radius_server.rb +256 -104
  224. data/tests/test_radius_server_group.rb +2 -0
  225. data/tests/test_router_bgp.rb +781 -485
  226. data/tests/test_router_ospf.rb +26 -103
  227. data/tests/test_router_ospf_vrf.rb +52 -57
  228. data/tests/test_snmp_notification_receiver.rb +2 -0
  229. data/tests/test_snmpcommunity.rb +2 -0
  230. data/tests/test_snmpgroup.rb +2 -0
  231. data/tests/test_snmpnotification.rb +40 -21
  232. data/tests/test_snmpserver.rb +2 -0
  233. data/tests/test_snmpuser.rb +2 -0
  234. data/tests/test_stp_global.rb +563 -0
  235. data/tests/test_syslog_server.rb +32 -8
  236. data/tests/test_syslog_settings.rb +22 -9
  237. data/tests/test_tacacs_server.rb +32 -27
  238. data/tests/test_tacacs_server_group.rb +100 -45
  239. data/tests/test_tacacs_server_host.rb +135 -43
  240. data/tests/test_vdc.rb +2 -16
  241. data/tests/test_vlan.rb +106 -54
  242. data/tests/test_vlan_mt_full.rb +11 -21
  243. data/tests/test_vlan_private.rb +669 -0
  244. data/tests/test_vpc.rb +312 -159
  245. data/tests/test_vrf.rb +122 -113
  246. data/tests/test_vrf_af.rb +238 -0
  247. data/tests/test_vtp.rb +58 -102
  248. data/tests/test_vxlan_vtep.rb +38 -17
  249. data/tests/test_vxlan_vtep_vni.rb +61 -9
  250. data/tests/test_yum.rb +49 -25
  251. metadata +122 -36
  252. data/lib/cisco_node_utils/cmd_ref/fex.yaml +0 -9
  253. data/lib/cisco_node_utils/cmd_ref/vni.yaml +0 -76
  254. data/lib/cisco_node_utils/vni.rb +0 -227
  255. data/tests/test_vni.rb +0 -106
@@ -20,95 +20,164 @@
20
20
  require_relative 'ciscotest'
21
21
  require_relative '../lib/cisco_node_utils/bgp'
22
22
  require_relative '../lib/cisco_node_utils/bgp_neighbor'
23
+ require_relative '../lib/cisco_node_utils/logger'
23
24
 
24
25
  # TestBgpNeighbor - Minitest for RouterBgpNeighbor node utility class
25
26
  class TestBgpNeighbor < CiscoTestCase
26
- # rubocop:disable Style/ClassVars
27
- @@asn = 55
28
- @@addr = '1.1.1.1'
29
- @@pre_clean_needed = true
30
- # rubocop:enable Style/ClassVars
27
+ ASN = 55
28
+ ADDR = '1.1.1.1'
29
+ REMOTE_ASN = 99
30
+ @@pre_clean_needed = true # rubocop:disable Style/ClassVars
31
31
 
32
32
  def setup
33
33
  super
34
34
  remove_all_bgps if @@pre_clean_needed
35
35
  @@pre_clean_needed = false # rubocop:disable Style/ClassVars
36
36
  # BGP Neighbor requires the presence of a basic bgp global config
37
- RouterBgp.new(@@asn)
37
+ RouterBgp.new(ASN)
38
38
  end
39
39
 
40
40
  def teardown
41
- super
42
41
  remove_all_bgps
42
+ super
43
+ end
44
+
45
+ # Returns some test data for use in several tests.
46
+ def test_data
47
+ test_data = []
48
+ test_data << { vrf: 'default', neighbors: ['1.1.1.1'] }
49
+
50
+ if platform == :ios_xr
51
+ # XR doesn't support prefix/len addresses
52
+ test_data << { vrf: 'red',
53
+ neighbors: ['2.2.2.0', '2000::2'] }
54
+ else
55
+ test_data << { vrf: 'red',
56
+ neighbors: ['2.2.2.0/24', '2000::2', '2000:123:38::/64'] }
57
+ end
58
+ end
59
+
60
+ # Finds and returns the neighbor with the specified address
61
+ # and vrf, or nil if it is not found.
62
+ def find_neighbor(addr, vrf='default',
63
+ bgp_neighbors=RouterBgpNeighbor.neighbors)
64
+ bgp_neighbors.each_value do |vrfs|
65
+ vrfs.each do |vrf_name, neighbors|
66
+ next unless vrf_name == vrf
67
+ neighbors.each_value do |neighbor|
68
+ next unless neighbor.nbr == addr
69
+ Cisco::Logger.debug("neighbor '#{addr}' with vrf '#{vrf}' found")
70
+ return neighbor
71
+ end
72
+ end
73
+ end
74
+ Cisco::Logger.debug("neighbor '#{addr}' with vrf '#{vrf}' not found")
75
+ nil
43
76
  end
44
77
 
78
+ # Does the neighbor with the specified address and vrf exist?
79
+ def neighbor_exists?(addr, vrf='default',
80
+ bgp_neighbors=RouterBgpNeighbor.neighbors)
81
+ find_neighbor(addr, vrf, bgp_neighbors) != nil
82
+ end
83
+
84
+ # Finds the neighbor with the specified address in the
85
+ # output from a show cmd. Returns the matching line of
86
+ # output if found, otherwise nil.
45
87
  def get_bgpneighbor_match_line(addr, vrf='default')
88
+ regex = /neighbor #{addr}/
46
89
  if vrf == 'default'
47
- cmd = "show run bgp all | section 'router bgp' | no-more"
90
+ if platform == :ios_xr
91
+ cmd = 'show run router bgp'
92
+ regex = /^ neighbor #{addr}/
93
+ else
94
+ cmd = "show run bgp all | section 'router bgp' | no-more"
95
+ end
48
96
  else
49
- cmd = "show run bgp all | section 'vrf #{vrf}' | no-more"
97
+ if platform == :ios_xr
98
+ cmd = "show run router bgp #{ASN} vrf #{vrf}"
99
+ else
100
+ cmd = "show run bgp all | section 'vrf #{vrf}' | no-more"
101
+ end
50
102
  end
51
- CiscoLogger.debug("matching #{addr} with vrf #{vrf}")
52
103
  s = @device.cmd("#{cmd}")
53
- line = /neighbor #{addr}/.match(s)
54
- CiscoLogger.debug(line)
104
+ Cisco::Logger.debug("matching '#{addr}' with vrf '#{vrf}', output: \n#{s}")
105
+ line = regex.match(s)
106
+ Cisco::Logger.debug(line)
55
107
  line
56
108
  end
57
109
 
110
+ # Creates a neighbor for use in tests, and sets its remote_as.
111
+ def create_neighbor(vrf, addr=ADDR)
112
+ neighbor = RouterBgpNeighbor.new(ASN, vrf, addr)
113
+
114
+ # XR requires a remote_as in order to set other properties
115
+ # (description, password, etc.)
116
+ neighbor.remote_as = REMOTE_ASN
117
+ neighbor
118
+ end
119
+
58
120
  def test_collection_empty
59
- config('no feature bgp')
121
+ remove_all_bgps
60
122
  neighbors = RouterBgpNeighbor.neighbors
61
123
  assert_empty(neighbors, 'BGP neighbor collection is not empty')
62
124
  end
63
125
 
64
126
  def test_collection_not_empty
65
- config('router bgp 55',
66
- 'neighbor 1.1.1.1',
67
- 'vrf red',
68
- 'neighbor 2.2.2.0/24',
69
- 'neighbor 2000::2',
70
- 'neighbor 2000:123:38::/64')
127
+ test_data_hash = {}
128
+
129
+ cmds = ['router bgp 55']
130
+
131
+ test = test_data
132
+ test.each do |d|
133
+ test_data_hash[d[:vrf]] = d[:neighbors]
134
+ cmds << "vrf #{d[:vrf]}" unless d[:vrf] == 'default'
135
+ d[:neighbors].each do |neighbor|
136
+ cmds << "neighbor #{neighbor}" << "remote-as #{REMOTE_ASN}"
137
+ end
138
+ end
139
+
140
+ config(*cmds)
141
+
71
142
  bgp_neighbors = RouterBgpNeighbor.neighbors
72
143
  refute_empty(bgp_neighbors, 'BGP neighbor collection is empty')
73
- # validate the collection
74
- bgp_neighbors.each_value do |vrfs|
75
- vrfs.each do |vrf, neighbors|
76
- if vrf == 'default'
77
- assert_equal(1, neighbors.size)
78
- else
79
- assert_equal(3, neighbors.size)
80
- end
81
- neighbors.each_value do |neighbor|
82
- assert_equal(vrf, neighbor.vrf)
83
- line = get_bgpneighbor_match_line(neighbor.nbr, vrf)
84
- refute_nil(line)
85
- end
144
+
145
+ # see if all expected neighbors are there
146
+ test.each do |d|
147
+ d[:neighbors].each do |neighbor|
148
+ # see if the neighbor exists in the list returned by the API
149
+ assert(neighbor_exists?(neighbor, d[:vrf], bgp_neighbors),
150
+ 'Did not find in neighbor list: '\
151
+ "nbr '#{neighbor}', vrf '#{d[:vrf]}'")
152
+
153
+ # see if the neighbor exists via show cmd output
154
+ line = get_bgpneighbor_match_line(neighbor, d[:vrf])
155
+ refute_nil(line, 'Did not find in show output: '\
156
+ "nbr '#{neighbor}', vrf '#{d[:vrf]}'")
86
157
  end
87
158
  end
88
159
  end
89
160
 
90
161
  def test_create_destroy
91
- address = { '1.1.1.1' => '1.1.1.1',
92
- '2.2.2.2/24' => '2.2.2.0/24',
93
- '2000::2' => '2000::2',
94
- '2000:123:38::34/64' => '2000:123:38::/64',
95
- }
96
- vrfs = %w(default red)
97
- vrfs.each do |vrf|
98
- address.each do |addr, expected_addr|
99
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, addr)
100
- line = get_bgpneighbor_match_line(expected_addr, vrf)
101
- refute_nil(line, "Error: failed to create bgp neighbor #{addr}")
162
+ test_data.each do |d|
163
+ d[:neighbors].each do |addr|
164
+ neighbor = create_neighbor(d[:vrf], addr)
165
+ exists = neighbor_exists?(addr, d[:vrf])
166
+ assert(exists, "Failed to create bgp neighbor #{addr}")
167
+ line = get_bgpneighbor_match_line(addr, d[:vrf])
168
+ refute_nil(line, "failed to create bgp neighbor #{addr}")
102
169
  neighbor.destroy
103
- line = get_bgpneighbor_match_line(expected_addr, vrf)
104
- assert_nil(line, "Error: failed to delete bgp neighbor #{addr}")
170
+ exists = neighbor_exists?(addr, d[:vrf])
171
+ refute(exists, "Failed to delete bgp neighbor #{addr}")
172
+ line = get_bgpneighbor_match_line(addr, d[:vrf])
173
+ assert_nil(line, "failed to delete bgp neighbor #{addr}")
105
174
  end
106
175
  end
107
176
  end
108
177
 
109
178
  def test_description
110
179
  %w(default test_vrf).each do |vrf|
111
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
180
+ neighbor = create_neighbor(vrf)
112
181
  description = "tested by mini test for vrf #{vrf}"
113
182
  neighbor.description = description
114
183
  assert_equal(description, neighbor.description)
@@ -121,15 +190,14 @@ class TestBgpNeighbor < CiscoTestCase
121
190
  end
122
191
 
123
192
  def test_multiple_descriptions
124
- # First create multiple routers with multiple desriptions.
125
- address = ['1.1.1.1', '2.2.2.0/24', '2000::2', '2000:123:38::/64']
126
- vrfs = %w(default red)
127
- vrfs.each do |vrf|
128
- address.each do |addr|
129
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, addr)
130
- neighbor.description = "#{vrf}:#{addr}"
193
+ # First create multiple routers with multiple descriptions.
194
+ test_data.each do |d|
195
+ d[:neighbors].each do |addr|
196
+ neighbor = create_neighbor(d[:vrf], addr)
197
+ neighbor.description = "#{d[:vrf]}:#{addr}"
131
198
  end
132
199
  end
200
+
133
201
  # Now test if the description has been correctly set
134
202
  RouterBgpNeighbor.neighbors.each_value do |bgp_vrfs|
135
203
  bgp_vrfs.each do |vrf, neighbors|
@@ -147,7 +215,7 @@ class TestBgpNeighbor < CiscoTestCase
147
215
 
148
216
  def test_connected_check
149
217
  %w(default test_vrf).each do |vrf|
150
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
218
+ neighbor = create_neighbor(vrf)
151
219
  check = [true, false, neighbor.default_connected_check]
152
220
  check.each do |value|
153
221
  neighbor.connected_check = value
@@ -159,11 +227,19 @@ class TestBgpNeighbor < CiscoTestCase
159
227
 
160
228
  def test_capability_negotiation
161
229
  %w(default test_vrf).each do |vrf|
162
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
163
- check = [true, false, neighbor.default_capability_negotiation]
164
- check.each do |value|
165
- neighbor.capability_negotiation = value
166
- assert_equal(value, neighbor.capability_negotiation)
230
+ neighbor = create_neighbor(vrf)
231
+ if platform == :ios_xr
232
+ assert_nil(neighbor.capability_negotiation)
233
+ assert_nil(neighbor.default_capability_negotiation)
234
+ assert_raises(Cisco::UnsupportedError) do
235
+ neighbor.capability_negotiation = true
236
+ end
237
+ else
238
+ check = [true, false, neighbor.default_capability_negotiation]
239
+ check.each do |value|
240
+ neighbor.capability_negotiation = value
241
+ assert_equal(value, neighbor.capability_negotiation)
242
+ end
167
243
  end
168
244
  neighbor.destroy
169
245
  end
@@ -171,11 +247,19 @@ class TestBgpNeighbor < CiscoTestCase
171
247
 
172
248
  def test_dynamic_capability
173
249
  %w(default test_vrf).each do |vrf|
174
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
175
- check = [true, false, neighbor.default_dynamic_capability]
176
- check.each do |value|
177
- neighbor.dynamic_capability = value
178
- assert_equal(value, neighbor.dynamic_capability)
250
+ neighbor = create_neighbor(vrf)
251
+ if platform == :ios_xr
252
+ assert_nil(neighbor.dynamic_capability)
253
+ assert_nil(neighbor.default_dynamic_capability)
254
+ assert_raises(Cisco::UnsupportedError) do
255
+ neighbor.dynamic_capability = true
256
+ end
257
+ else
258
+ check = [true, false, neighbor.default_dynamic_capability]
259
+ check.each do |value|
260
+ neighbor.dynamic_capability = value
261
+ assert_equal(value, neighbor.dynamic_capability)
262
+ end
179
263
  end
180
264
  neighbor.destroy
181
265
  end
@@ -183,7 +267,7 @@ class TestBgpNeighbor < CiscoTestCase
183
267
 
184
268
  def test_ebgp_multihop
185
269
  %w(default test_vrf).each do |vrf|
186
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
270
+ neighbor = create_neighbor(vrf)
187
271
  ttls = [24, neighbor.default_ebgp_multihop]
188
272
  ttls.each do |ebgp_multihop|
189
273
  neighbor.ebgp_multihop = ebgp_multihop
@@ -195,8 +279,9 @@ class TestBgpNeighbor < CiscoTestCase
195
279
 
196
280
  def test_local_as
197
281
  %w(default test_vrf).each do |vrf|
198
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
199
- [42, '52', '1.1', neighbor.default_local_as].each do |asnum|
282
+ neighbor = create_neighbor(vrf)
283
+ local_asnum = [42, '52', '1.1', neighbor.default_local_as]
284
+ local_asnum.each do |asnum|
200
285
  neighbor.local_as = asnum
201
286
  assert_equal(asnum.to_s, neighbor.local_as)
202
287
  end
@@ -210,10 +295,20 @@ class TestBgpNeighbor < CiscoTestCase
210
295
  end
211
296
 
212
297
  def test_log_neighbor_changes
298
+ if platform == :ios_xr || node.product_id[/N(5|6|7)/]
299
+ b = create_neighbor('blue')
300
+ assert_nil(b.log_neighbor_changes)
301
+ assert_nil(b.default_log_neighbor_changes)
302
+ assert_raises(Cisco::UnsupportedError) do
303
+ b.log_neighbor_changes = :enable
304
+ end
305
+ return
306
+ end
213
307
  %w(default test_vrf).each do |vrf|
214
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
308
+ neighbor = create_neighbor(vrf)
215
309
  check = [:enable, :disable, :inherit, 'enable', 'disable', 'inherit',
216
310
  neighbor.default_log_neighbor_changes]
311
+
217
312
  check.each do |value|
218
313
  neighbor.log_neighbor_changes = value
219
314
  assert_equal(value.to_sym, neighbor.log_neighbor_changes)
@@ -224,22 +319,32 @@ class TestBgpNeighbor < CiscoTestCase
224
319
 
225
320
  def test_low_memory_exempt
226
321
  %w(default test_vrf).each do |vrf|
227
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
228
- check = [true, false, neighbor.default_low_memory_exempt]
229
- check.each do |value|
230
- neighbor.low_memory_exempt = value
231
- assert_equal(value, neighbor.low_memory_exempt)
322
+ neighbor = create_neighbor(vrf)
323
+ if platform == :ios_xr
324
+ assert_nil(neighbor.low_memory_exempt)
325
+ assert_nil(neighbor.default_low_memory_exempt)
326
+ assert_raises(Cisco::UnsupportedError) do
327
+ neighbor.low_memory_exempt = true
328
+ end
329
+ else
330
+ check = [true, false, neighbor.default_low_memory_exempt]
331
+ check.each do |value|
332
+ neighbor.low_memory_exempt = value
333
+ assert_equal(value, neighbor.low_memory_exempt)
334
+ end
232
335
  end
233
336
  neighbor.destroy
234
337
  end
235
338
  end
236
339
 
237
340
  def test_maximum_peers
341
+ skip('Maximum-peers does not apply to IOS XR') if platform == :ios_xr
342
+
238
343
  # only "address/prefix" type of neighbor address will accept
239
- # maximum_peers command
344
+ # maximum_peers command, so not supported on XR
240
345
  addr = '1.1.1.0/24'
241
346
  %w(default test_vrf).each do |vrf|
242
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, addr)
347
+ neighbor = create_neighbor(vrf, addr)
243
348
  peers = [200, neighbor.default_maximum_peers]
244
349
  peers.each do |num|
245
350
  neighbor.maximum_peers = num
@@ -251,20 +356,39 @@ class TestBgpNeighbor < CiscoTestCase
251
356
 
252
357
  def test_password
253
358
  %w(default test_vrf).each do |vrf|
254
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
359
+ neighbor = create_neighbor(vrf)
255
360
  passwords = {}
256
- passwords[:cleartext] = 'test'
257
- passwords[:"3des"] = '386c0565965f89de'
258
- passwords[:cisco_type_7] = '046E1803362E595C260E0B240619050A2D'
361
+ if platform == :ios_xr
362
+ passwords[:cleartext] = 'test'
363
+ passwords[:md5] = '386c0565965f89de'
364
+ # not currently supporting XR specific 'password inheritance-disable'
365
+ else
366
+ passwords[:cleartext] = 'test'
367
+ passwords[:"3des"] = '386c0565965f89de'
368
+ passwords[:cisco_type_7] = '046E1803362E595C260E0B240619050A2D'
369
+ end
259
370
 
260
371
  passwords.each do |type, password|
261
372
  neighbor.password_set(password, type)
262
- if type == :cleartext
263
- assert_equal(:"3des", neighbor.password_type)
264
- assert_equal(passwords[:"3des"], neighbor.password)
373
+ if platform == :ios_xr
374
+ if type == :cleartext
375
+ # will always be type "encrypted" on XR
376
+ assert_equal(:md5, neighbor.password_type)
377
+ # don't know what the encrypted password will look like
378
+ # so just make sure it is not empty
379
+ refute_empty(neighbor.password)
380
+ else
381
+ assert_equal(type, neighbor.password_type)
382
+ assert_equal(password, neighbor.password)
383
+ end
265
384
  else
266
- assert_equal(type, neighbor.password_type)
267
- assert_equal(password, neighbor.password)
385
+ if type == :cleartext
386
+ assert_equal(:"3des", neighbor.password_type)
387
+ assert_equal(passwords[:"3des"], neighbor.password)
388
+ else
389
+ assert_equal(type, neighbor.password_type)
390
+ assert_equal(password, neighbor.password)
391
+ end
268
392
  end
269
393
  # now test removing the password setting
270
394
  neighbor.password_set(' ')
@@ -277,35 +401,42 @@ class TestBgpNeighbor < CiscoTestCase
277
401
  end
278
402
  end
279
403
 
280
- def test_set_default_password_type
404
+ def test_default_password_type
281
405
  %w(default test_vrf).each do |vrf|
282
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
406
+ neighbor = create_neighbor(vrf)
283
407
  password = 'test'
284
408
  expected_password = '386c0565965f89de'
285
409
 
410
+ test = proc do
411
+ if platform == :ios_xr
412
+ assert_equal(:md5, neighbor.password_type)
413
+ refute_empty(neighbor.password)
414
+ else
415
+ assert_equal(expected_password, neighbor.password)
416
+ assert_equal(:"3des", neighbor.password_type)
417
+ end
418
+ # clear password
419
+ neighbor.password_set('')
420
+ assert(neighbor.password.empty?)
421
+ end
422
+
286
423
  # Test 1: if we don't set password type, default should be cleartext,
287
- # we can verify by checking return type to be :3des, and encrypted text.
424
+ # we can verify by checking return type to be
425
+ # :3des/:md5, and encrypted text.
288
426
  neighbor.password_set(password)
289
- assert_equal(expected_password, neighbor.password)
290
- assert_equal(:"3des", neighbor.password_type)
291
- # clear password
292
- neighbor.password_set('')
293
- assert(neighbor.password.empty?)
427
+ test.call
294
428
 
295
429
  # Test 2: we set explicitly the password type to be default password type:
296
430
  # cleartext, and verify.
297
431
  neighbor.password_set(password, neighbor.default_password_type)
298
- assert_equal(expected_password, neighbor.password)
299
- assert_equal(:"3des", neighbor.password_type)
300
- neighbor.password_set('')
301
- assert(neighbor.password.empty?)
432
+ test.call
302
433
  neighbor.destroy
303
434
  end
304
435
  end
305
436
 
306
437
  def test_remote_as
307
438
  %w(default test_vrf).each do |vrf|
308
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
439
+ neighbor = RouterBgpNeighbor.new(ASN, vrf, ADDR)
309
440
  [42, '1.1', neighbor.default_remote_as].each do |asnum|
310
441
  neighbor.remote_as = asnum
311
442
  assert_equal(asnum.to_s, neighbor.remote_as)
@@ -316,24 +447,33 @@ class TestBgpNeighbor < CiscoTestCase
316
447
 
317
448
  def test_remove_private_as_options
318
449
  %w(default test_vrf).each do |vrf|
319
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
320
- options = [:enable, :disable, :all, :"replace-as", 'enable', 'disable',
321
- 'all', 'replace-as', neighbor.default_remove_private_as]
322
- options.each do |option|
323
- neighbor.remove_private_as = option
324
- assert_equal(option.to_sym, neighbor.remove_private_as)
325
- end
450
+ neighbor = create_neighbor(vrf)
451
+ if platform == :ios_xr
452
+ assert_nil(neighbor.remove_private_as)
453
+ assert_nil(neighbor.default_remove_private_as)
454
+ assert_raises(Cisco::UnsupportedError) do
455
+ neighbor.remove_private_as = :enable
456
+ end
457
+ else
458
+ options = [:enable, :disable, :all, :"replace-as", 'enable', 'disable',
459
+ 'all', 'replace-as', neighbor.default_remove_private_as]
460
+
461
+ options.each do |option|
462
+ neighbor.remove_private_as = option
463
+ assert_equal(option.to_sym, neighbor.remove_private_as)
464
+ end
326
465
 
327
- neighbor.remove_private_as = neighbor.default_remove_private_as
328
- assert_equal(neighbor.default_remove_private_as,
329
- neighbor.remove_private_as)
466
+ neighbor.remove_private_as = neighbor.default_remove_private_as
467
+ assert_equal(neighbor.default_remove_private_as,
468
+ neighbor.remove_private_as)
469
+ end
330
470
  neighbor.destroy
331
471
  end
332
472
  end
333
473
 
334
474
  def test_shutdown
335
475
  %w(default test_vrf).each do |vrf|
336
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
476
+ neighbor = create_neighbor(vrf)
337
477
  check = [true, false, neighbor.default_shutdown]
338
478
  check.each do |value|
339
479
  neighbor.shutdown = value
@@ -345,7 +485,7 @@ class TestBgpNeighbor < CiscoTestCase
345
485
 
346
486
  def test_suppress_4_byte_as
347
487
  %w(default test_vrf).each do |vrf|
348
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
488
+ neighbor = create_neighbor(vrf)
349
489
  check = [true, false, neighbor.default_suppress_4_byte_as]
350
490
  check.each do |value|
351
491
  neighbor.suppress_4_byte_as = value
@@ -357,7 +497,7 @@ class TestBgpNeighbor < CiscoTestCase
357
497
 
358
498
  def test_timers
359
499
  %w(default test_vrf).each do |vrf|
360
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
500
+ neighbor = create_neighbor(vrf)
361
501
  timers = [{ keep: 40, hold: 90 },
362
502
  { keep: neighbor.default_timers_keepalive,
363
503
  hold: neighbor.default_timers_holdtime },
@@ -374,9 +514,28 @@ class TestBgpNeighbor < CiscoTestCase
374
514
  end
375
515
  end
376
516
 
517
+ def test_transport_passive_mode
518
+ %w(default test_vrf).each do |vrf|
519
+ neighbor = create_neighbor(vrf)
520
+ check = []
521
+ if platform == :ios_xr
522
+ check = [:active_only, :passive_only, :both, :none,
523
+ neighbor.default_transport_passive_mode]
524
+ else
525
+ check = [:passive_only, :none,
526
+ neighbor.default_transport_passive_mode]
527
+ end
528
+ check.each do |value|
529
+ neighbor.transport_passive_mode = value
530
+ assert_equal(value, neighbor.transport_passive_mode)
531
+ end
532
+ neighbor.destroy
533
+ end
534
+ end
535
+
377
536
  def test_transport_passive_only
378
537
  %w(default test_vrf).each do |vrf|
379
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
538
+ neighbor = create_neighbor(vrf)
380
539
  check = [true, false, neighbor.default_transport_passive_only]
381
540
  check.each do |value|
382
541
  neighbor.transport_passive_only = value
@@ -388,10 +547,10 @@ class TestBgpNeighbor < CiscoTestCase
388
547
 
389
548
  def test_update_source
390
549
  %w(default test_vrf).each do |vrf|
391
- neighbor = RouterBgpNeighbor.new(@@asn, vrf, @@addr)
392
- interfaces = ['loopback1', 'Ethernet1/1', 'ethernet1/1',
393
- neighbor.default_update_source]
394
- interfaces.each do |interface|
550
+ neighbor = create_neighbor(vrf)
551
+ test_interfaces = ['loopback1', interfaces[0], interfaces[0].downcase,
552
+ neighbor.default_update_source]
553
+ test_interfaces.each do |interface|
395
554
  neighbor.update_source = interface
396
555
  assert_equal(interface.downcase, neighbor.update_source)
397
556
  end