cisco_node_utils_mgx 2.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (357) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +96 -0
  5. data/.travis.yml +17 -0
  6. data/CHANGELOG.md +676 -0
  7. data/CONTRIBUTING.md +43 -0
  8. data/Gemfile +10 -0
  9. data/LICENSE +201 -0
  10. data/README.md +246 -0
  11. data/Rakefile +44 -0
  12. data/SUPPORT.md +3 -0
  13. data/bin/.rubocop.yml +18 -0
  14. data/bin/check_metric_limits.rb +109 -0
  15. data/bin/git/hooks/commit-msg/enforce_style +89 -0
  16. data/bin/git/hooks/hook_lib +115 -0
  17. data/bin/git/hooks/hooks-wrapper +38 -0
  18. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  19. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  20. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  21. data/bin/git/hooks/post-merge/update-hooks +6 -0
  22. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  23. data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
  24. data/bin/git/hooks/pre-commit/rubocop +25 -0
  25. data/bin/git/hooks/pre-commit/validate-diffs +45 -0
  26. data/bin/git/hooks/pre-commit/validate-yaml +18 -0
  27. data/bin/git/hooks/pre-push/check-changelog +24 -0
  28. data/bin/git/hooks/pre-push/rubocop +7 -0
  29. data/bin/git/update-hooks +123 -0
  30. data/bin/show_running_yang.rb +233 -0
  31. data/cisco_node_utils.gemspec +41 -0
  32. data/docs/README-develop-best-practices.md +521 -0
  33. data/docs/README-develop-node-utils-APIs.md +570 -0
  34. data/docs/README-maintainers.md +77 -0
  35. data/docs/README-test-execution.md +57 -0
  36. data/docs/README-utilities.md +14 -0
  37. data/docs/agent_files.png +0 -0
  38. data/docs/cisco_node_utils.yaml.example +36 -0
  39. data/docs/template-router.rb +123 -0
  40. data/docs/template-test_router.rb +104 -0
  41. data/ext/mkrf_conf.rb +63 -0
  42. data/lib/.rubocop.yml +18 -0
  43. data/lib/cisco_node_utils/aaa_authentication_login.rb +95 -0
  44. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +138 -0
  45. data/lib/cisco_node_utils/aaa_authorization_service.rb +156 -0
  46. data/lib/cisco_node_utils/ace.rb +467 -0
  47. data/lib/cisco_node_utils/acl.rb +101 -0
  48. data/lib/cisco_node_utils/banner.rb +63 -0
  49. data/lib/cisco_node_utils/bfd_global.rb +305 -0
  50. data/lib/cisco_node_utils/bgp.rb +988 -0
  51. data/lib/cisco_node_utils/bgp_af.rb +545 -0
  52. data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
  53. data/lib/cisco_node_utils/bgp_neighbor.rb +527 -0
  54. data/lib/cisco_node_utils/bgp_neighbor_af.rb +780 -0
  55. data/lib/cisco_node_utils/bridge_domain.rb +178 -0
  56. data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
  57. data/lib/cisco_node_utils/cisco_cmn_utils.rb +444 -0
  58. data/lib/cisco_node_utils/client/client.rb +238 -0
  59. data/lib/cisco_node_utils/client/grpc/client.rb +395 -0
  60. data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
  61. data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
  62. data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
  63. data/lib/cisco_node_utils/client/grpc.rb +33 -0
  64. data/lib/cisco_node_utils/client/nxapi/client.rb +368 -0
  65. data/lib/cisco_node_utils/client/nxapi.rb +31 -0
  66. data/lib/cisco_node_utils/client/utils.rb +180 -0
  67. data/lib/cisco_node_utils/client.rb +35 -0
  68. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +590 -0
  69. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +25 -0
  70. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +38 -0
  71. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +40 -0
  72. data/lib/cisco_node_utils/cmd_ref/acl.yaml +48 -0
  73. data/lib/cisco_node_utils/cmd_ref/banner.yaml +11 -0
  74. data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +117 -0
  75. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +383 -0
  76. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +223 -0
  77. data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
  78. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +174 -0
  79. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +236 -0
  80. data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +49 -0
  81. data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
  82. data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +128 -0
  83. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +55 -0
  84. data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
  85. data/lib/cisco_node_utils/cmd_ref/evpn_multicast.yaml +12 -0
  86. data/lib/cisco_node_utils/cmd_ref/evpn_multisite.yaml +18 -0
  87. data/lib/cisco_node_utils/cmd_ref/evpn_stormcontrol.yaml +18 -0
  88. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +48 -0
  89. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +183 -0
  90. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +40 -0
  91. data/lib/cisco_node_utils/cmd_ref/feature.yaml +126 -0
  92. data/lib/cisco_node_utils/cmd_ref/hostname.yaml +8 -0
  93. data/lib/cisco_node_utils/cmd_ref/hsrp_global.yaml +25 -0
  94. data/lib/cisco_node_utils/cmd_ref/images.yaml +8 -0
  95. data/lib/cisco_node_utils/cmd_ref/interface.yaml +781 -0
  96. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +45 -0
  97. data/lib/cisco_node_utils/cmd_ref/interface_evpn_multisite.yaml +17 -0
  98. data/lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml +120 -0
  99. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +112 -0
  100. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +87 -0
  101. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +42 -0
  102. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  103. data/lib/cisco_node_utils/cmd_ref/ip_multicast.yaml +22 -0
  104. data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
  105. data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
  106. data/lib/cisco_node_utils/cmd_ref/memory.yaml +24 -0
  107. data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
  108. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +27 -0
  109. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +34 -0
  110. data/lib/cisco_node_utils/cmd_ref/object_group.yaml +32 -0
  111. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +91 -0
  112. data/lib/cisco_node_utils/cmd_ref/ospf_area.yaml +91 -0
  113. data/lib/cisco_node_utils/cmd_ref/ospf_area_vlink.yaml +88 -0
  114. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +37 -0
  115. data/lib/cisco_node_utils/cmd_ref/pim.yaml +43 -0
  116. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +86 -0
  117. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +37 -0
  118. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +100 -0
  119. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +19 -0
  120. data/lib/cisco_node_utils/cmd_ref/route_map.yaml +601 -0
  121. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +9 -0
  122. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +84 -0
  123. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +81 -0
  124. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +9 -0
  125. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +74 -0
  126. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +91 -0
  127. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +57 -0
  128. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +23 -0
  129. data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
  130. data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +235 -0
  131. data/lib/cisco_node_utils/cmd_ref/syslog_facility.yaml +10 -0
  132. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +34 -0
  133. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +45 -0
  134. data/lib/cisco_node_utils/cmd_ref/system.yaml +7 -0
  135. data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +37 -0
  136. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +63 -0
  137. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +45 -0
  138. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +64 -0
  139. data/lib/cisco_node_utils/cmd_ref/upgrade.yaml +38 -0
  140. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +52 -0
  141. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +8 -0
  142. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +106 -0
  143. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +233 -0
  144. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +86 -0
  145. data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +139 -0
  146. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +32 -0
  147. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +114 -0
  148. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +71 -0
  149. data/lib/cisco_node_utils/cmd_ref/yang.yaml +7 -0
  150. data/lib/cisco_node_utils/cmd_ref/yum.yaml +68 -0
  151. data/lib/cisco_node_utils/command_reference.rb +724 -0
  152. data/lib/cisco_node_utils/configparser_lib.rb +195 -0
  153. data/lib/cisco_node_utils/constants.rb +40 -0
  154. data/lib/cisco_node_utils/dhcp_relay_global.rb +302 -0
  155. data/lib/cisco_node_utils/dns_domain.rb +93 -0
  156. data/lib/cisco_node_utils/domain_name.rb +82 -0
  157. data/lib/cisco_node_utils/encapsulation.rb +112 -0
  158. data/lib/cisco_node_utils/environment.rb +110 -0
  159. data/lib/cisco_node_utils/evpn_multicast.rb +66 -0
  160. data/lib/cisco_node_utils/evpn_multisite.rb +96 -0
  161. data/lib/cisco_node_utils/evpn_stormcontrol.rb +84 -0
  162. data/lib/cisco_node_utils/evpn_vni.rb +159 -0
  163. data/lib/cisco_node_utils/exceptions.rb +140 -0
  164. data/lib/cisco_node_utils/fabricpath_global.rb +405 -0
  165. data/lib/cisco_node_utils/fabricpath_topology.rb +137 -0
  166. data/lib/cisco_node_utils/feature.rb +377 -0
  167. data/lib/cisco_node_utils/hostname.rb +62 -0
  168. data/lib/cisco_node_utils/hsrp_global.rb +97 -0
  169. data/lib/cisco_node_utils/interface.rb +2128 -0
  170. data/lib/cisco_node_utils/interface_channel_group.rb +142 -0
  171. data/lib/cisco_node_utils/interface_evpn_multisite.rb +72 -0
  172. data/lib/cisco_node_utils/interface_hsrp_group.rb +557 -0
  173. data/lib/cisco_node_utils/interface_ospf.rb +378 -0
  174. data/lib/cisco_node_utils/interface_portchannel.rb +180 -0
  175. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  176. data/lib/cisco_node_utils/ip_multicast.rb +90 -0
  177. data/lib/cisco_node_utils/itd_device_group.rb +228 -0
  178. data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
  179. data/lib/cisco_node_utils/itd_service.rb +511 -0
  180. data/lib/cisco_node_utils/logger.rb +78 -0
  181. data/lib/cisco_node_utils/name_server.rb +64 -0
  182. data/lib/cisco_node_utils/node.rb +443 -0
  183. data/lib/cisco_node_utils/node_util.rb +111 -0
  184. data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
  185. data/lib/cisco_node_utils/ntp_config.rb +83 -0
  186. data/lib/cisco_node_utils/ntp_server.rb +86 -0
  187. data/lib/cisco_node_utils/object_group.rb +75 -0
  188. data/lib/cisco_node_utils/object_group_entry.rb +143 -0
  189. data/lib/cisco_node_utils/overlay_global.rb +142 -0
  190. data/lib/cisco_node_utils/pim.rb +131 -0
  191. data/lib/cisco_node_utils/pim_group_list.rb +109 -0
  192. data/lib/cisco_node_utils/pim_rp_address.rb +103 -0
  193. data/lib/cisco_node_utils/platform.rb +217 -0
  194. data/lib/cisco_node_utils/portchannel_global.rb +347 -0
  195. data/lib/cisco_node_utils/radius_global.rb +165 -0
  196. data/lib/cisco_node_utils/radius_server.rb +421 -0
  197. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  198. data/lib/cisco_node_utils/route_map.rb +2540 -0
  199. data/lib/cisco_node_utils/router_ospf.rb +77 -0
  200. data/lib/cisco_node_utils/router_ospf_area.rb +416 -0
  201. data/lib/cisco_node_utils/router_ospf_area_vlink.rb +313 -0
  202. data/lib/cisco_node_utils/router_ospf_vrf.rb +342 -0
  203. data/lib/cisco_node_utils/snmp_notification_receiver.rb +176 -0
  204. data/lib/cisco_node_utils/snmpcommunity.rb +109 -0
  205. data/lib/cisco_node_utils/snmpgroup.rb +54 -0
  206. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  207. data/lib/cisco_node_utils/snmpserver.rb +132 -0
  208. data/lib/cisco_node_utils/snmpuser.rb +403 -0
  209. data/lib/cisco_node_utils/span_session.rb +149 -0
  210. data/lib/cisco_node_utils/stp_global.rb +676 -0
  211. data/lib/cisco_node_utils/syslog_facility.rb +64 -0
  212. data/lib/cisco_node_utils/syslog_server.rb +146 -0
  213. data/lib/cisco_node_utils/syslog_settings.rb +174 -0
  214. data/lib/cisco_node_utils/tacacs_global.rb +137 -0
  215. data/lib/cisco_node_utils/tacacs_server.rb +173 -0
  216. data/lib/cisco_node_utils/tacacs_server_group.rb +149 -0
  217. data/lib/cisco_node_utils/tacacs_server_host.rb +216 -0
  218. data/lib/cisco_node_utils/upgrade.rb +122 -0
  219. data/lib/cisco_node_utils/vdc.rb +118 -0
  220. data/lib/cisco_node_utils/version.rb +21 -0
  221. data/lib/cisco_node_utils/vlan.rb +301 -0
  222. data/lib/cisco_node_utils/vpc.rb +466 -0
  223. data/lib/cisco_node_utils/vrf.rb +192 -0
  224. data/lib/cisco_node_utils/vrf_af.rb +327 -0
  225. data/lib/cisco_node_utils/vtp.rb +125 -0
  226. data/lib/cisco_node_utils/vxlan_vtep.rb +286 -0
  227. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +331 -0
  228. data/lib/cisco_node_utils/yang.rb +160 -0
  229. data/lib/cisco_node_utils/yum.rb +213 -0
  230. data/lib/cisco_node_utils.rb +21 -0
  231. data/lib/minitest/environment_plugin.rb +31 -0
  232. data/lib/minitest/log_level_plugin.rb +41 -0
  233. data/spec/client_spec.rb +7 -0
  234. data/spec/environment_spec.rb +384 -0
  235. data/spec/grpc_client_spec.rb +23 -0
  236. data/spec/isolate/all_clients_spec.rb +9 -0
  237. data/spec/isolate/grpc_only_spec.rb +16 -0
  238. data/spec/isolate/no_clients_spec.rb +26 -0
  239. data/spec/isolate/nxapi_only_spec.rb +16 -0
  240. data/spec/nxapi_client_spec.rb +42 -0
  241. data/spec/schema.yaml +82 -0
  242. data/spec/shared_examples_for_clients.rb +14 -0
  243. data/spec/spec_helper.rb +91 -0
  244. data/spec/whitespace_spec.rb +10 -0
  245. data/spec/yaml_spec.rb +42 -0
  246. data/tests/.rubocop.yml +18 -0
  247. data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
  248. data/tests/basetest.rb +243 -0
  249. data/tests/ciscotest.rb +577 -0
  250. data/tests/cmd_config.yaml +75 -0
  251. data/tests/cmd_config_invalid.yaml +16 -0
  252. data/tests/n9000_sample-1.0.0-7.0.3.x86_64.rpm +0 -0
  253. data/tests/noop.rb +7 -0
  254. data/tests/platform_info.rb +63 -0
  255. data/tests/tacacs_server.yaml.example +6 -0
  256. data/tests/test_aaa_authentication_login.rb +243 -0
  257. data/tests/test_aaa_authentication_login_service.rb +761 -0
  258. data/tests/test_aaa_authorization_service.rb +874 -0
  259. data/tests/test_ace.rb +304 -0
  260. data/tests/test_acl.rb +185 -0
  261. data/tests/test_banner.rb +85 -0
  262. data/tests/test_bfd_global.rb +272 -0
  263. data/tests/test_bgp_af.rb +875 -0
  264. data/tests/test_bgp_af_aa.rb +108 -0
  265. data/tests/test_bgp_neighbor.rb +596 -0
  266. data/tests/test_bgp_neighbor_af.rb +781 -0
  267. data/tests/test_bridge_domain.rb +198 -0
  268. data/tests/test_bridge_domain_vni.rb +109 -0
  269. data/tests/test_client_utils.rb +111 -0
  270. data/tests/test_cmn_utils.rb +76 -0
  271. data/tests/test_command_config.rb +206 -0
  272. data/tests/test_command_reference.rb +669 -0
  273. data/tests/test_dhcp_relay_global.rb +286 -0
  274. data/tests/test_dns_domain.rb +123 -0
  275. data/tests/test_domain_name.rb +96 -0
  276. data/tests/test_encapsulation.rb +75 -0
  277. data/tests/test_evpn_multicast.rb +65 -0
  278. data/tests/test_evpn_multisite.rb +70 -0
  279. data/tests/test_evpn_stormcontrol.rb +56 -0
  280. data/tests/test_evpn_vni.rb +131 -0
  281. data/tests/test_fabricpath_global.rb +246 -0
  282. data/tests/test_fabricpath_topology.rb +77 -0
  283. data/tests/test_feature.rb +272 -0
  284. data/tests/test_grpc.rb +166 -0
  285. data/tests/test_hostname.rb +64 -0
  286. data/tests/test_hsrp_global.rb +79 -0
  287. data/tests/test_interface.rb +1958 -0
  288. data/tests/test_interface_bdi.rb +80 -0
  289. data/tests/test_interface_channel_group.rb +131 -0
  290. data/tests/test_interface_evpn_multisite.rb +94 -0
  291. data/tests/test_interface_hsrp.rb +134 -0
  292. data/tests/test_interface_hsrp_group.rb +570 -0
  293. data/tests/test_interface_ospf.rb +820 -0
  294. data/tests/test_interface_portchannel.rb +135 -0
  295. data/tests/test_interface_private_vlan.rb +365 -0
  296. data/tests/test_interface_service_vni.rb +203 -0
  297. data/tests/test_interface_svi.rb +210 -0
  298. data/tests/test_interface_switchport.rb +468 -0
  299. data/tests/test_ip_multicast.rb +80 -0
  300. data/tests/test_itd_device_group.rb +145 -0
  301. data/tests/test_itd_device_group_node.rb +199 -0
  302. data/tests/test_itd_service.rb +314 -0
  303. data/tests/test_logger.rb +43 -0
  304. data/tests/test_name_server.rb +94 -0
  305. data/tests/test_node.rb +50 -0
  306. data/tests/test_node_ext.rb +406 -0
  307. data/tests/test_node_util.rb +119 -0
  308. data/tests/test_ntp_auth_key.rb +77 -0
  309. data/tests/test_ntp_config.rb +100 -0
  310. data/tests/test_ntp_server.rb +146 -0
  311. data/tests/test_nxapi.rb +236 -0
  312. data/tests/test_object_group.rb +122 -0
  313. data/tests/test_overlay_global.rb +108 -0
  314. data/tests/test_pim.rb +203 -0
  315. data/tests/test_pim_group_list.rb +147 -0
  316. data/tests/test_pim_rp_address.rb +155 -0
  317. data/tests/test_platform.rb +254 -0
  318. data/tests/test_portchannel_global.rb +322 -0
  319. data/tests/test_radius_global.rb +108 -0
  320. data/tests/test_radius_server.rb +377 -0
  321. data/tests/test_radius_server_group.rb +151 -0
  322. data/tests/test_route_map.rb +1479 -0
  323. data/tests/test_router_bgp.rb +1325 -0
  324. data/tests/test_router_ospf.rb +56 -0
  325. data/tests/test_router_ospf_area.rb +433 -0
  326. data/tests/test_router_ospf_area_vlink.rb +298 -0
  327. data/tests/test_router_ospf_vrf.rb +690 -0
  328. data/tests/test_snmp_notification_receiver.rb +169 -0
  329. data/tests/test_snmpcommunity.rb +422 -0
  330. data/tests/test_snmpgroup.rb +71 -0
  331. data/tests/test_snmpnotification.rb +91 -0
  332. data/tests/test_snmpserver.rb +251 -0
  333. data/tests/test_snmpuser.rb +666 -0
  334. data/tests/test_span_session.rb +155 -0
  335. data/tests/test_stp_global.rb +575 -0
  336. data/tests/test_syslog_facility.rb +80 -0
  337. data/tests/test_syslog_server.rb +119 -0
  338. data/tests/test_syslog_settings.rb +123 -0
  339. data/tests/test_tacacs_global.rb +109 -0
  340. data/tests/test_tacacs_server.rb +436 -0
  341. data/tests/test_tacacs_server_group.rb +434 -0
  342. data/tests/test_tacacs_server_host.rb +427 -0
  343. data/tests/test_upgrade.rb +105 -0
  344. data/tests/test_vdc.rb +64 -0
  345. data/tests/test_vlan.rb +386 -0
  346. data/tests/test_vlan_private.rb +656 -0
  347. data/tests/test_vpc.rb +548 -0
  348. data/tests/test_vrf.rb +248 -0
  349. data/tests/test_vrf_af.rb +288 -0
  350. data/tests/test_vtp.rb +278 -0
  351. data/tests/test_vxlan_vtep.rb +327 -0
  352. data/tests/test_vxlan_vtep_vni.rb +326 -0
  353. data/tests/test_yang.rb +369 -0
  354. data/tests/test_yum.rb +109 -0
  355. data/tests/upgrade_info.yaml.example +3 -0
  356. data/tests/yum_package.yaml +94 -0
  357. metadata +534 -0
@@ -0,0 +1,820 @@
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/cisco_cmn_utils'
17
+ require_relative '../lib/cisco_node_utils/interface_ospf'
18
+ require_relative '../lib/cisco_node_utils/router_ospf'
19
+
20
+ include Cisco
21
+
22
+ # TestInterfaceOspf - Minitest for InterfaceOspf node utility class.
23
+ class TestInterfaceOspf < CiscoTestCase
24
+ @skip_unless_supported = 'interface_ospf'
25
+
26
+ def setup
27
+ super
28
+ config 'no feature ospf'
29
+ end
30
+
31
+ def teardown
32
+ config 'no feature ospf'
33
+ super
34
+ end
35
+
36
+ def interface_switchport_enable(ifname, enable)
37
+ if enable == true
38
+ config("interface #{ifname}", 'switchport')
39
+ else
40
+ config("interface #{ifname}", 'no switchport')
41
+ end
42
+ end
43
+
44
+ def show_cmd(name)
45
+ case name
46
+ when /ort-channel/
47
+ "show run interface #{name} | no-more"
48
+ else
49
+ "show run interface #{name} all | no-more"
50
+ end
51
+ end
52
+
53
+ def create_routerospf(ospfname='ospfTest')
54
+ config('feature ospf')
55
+ RouterOspf.new(ospfname, false)
56
+ end
57
+
58
+ def create_interfaceospf(routerospf, ifname=interfaces[0], area='0.0.0.0')
59
+ @default_show_command = show_cmd(ifname)
60
+ interface_switchport_enable(ifname, false)
61
+ InterfaceOspf.new(ifname, routerospf.name, area)
62
+ end
63
+
64
+ # Test InterfaceOspf.interfaces class method api
65
+ def test_interface_apis
66
+ intf = interfaces[0]
67
+ intf2 = interfaces[1]
68
+
69
+ # Verify show_name usage when no ospf config on intf
70
+ none = InterfaceOspf.interfaces(nil, intf)
71
+ assert_equal(0, none.length,
72
+ 'Invalid number of keys returned, should be 0')
73
+
74
+ # Verify show_name usage when ospf config present on intf
75
+ InterfaceOspf.new(intf, 'ospf_test', '0')
76
+ one = InterfaceOspf.interfaces(nil, intf)
77
+ assert_equal(1, one.length,
78
+ 'Invalid number of keys returned, should be 1')
79
+ assert_equal(Utils.normalize_intf_pattern(intf), one[intf].show_name,
80
+ ':show_name should be intf name when show_name param specified')
81
+
82
+ # Verify 'all' interfaces returned
83
+ Interface.new(intf2)
84
+ InterfaceOspf.new(intf2, 'ospf_test', '0')
85
+ all = InterfaceOspf.interfaces
86
+ assert_operator(all.length, :>, 1,
87
+ 'Invalid number of keys returned, should exceed 1')
88
+ assert_empty(all[intf2].show_name,
89
+ ':show_name should be empty string when show_name param is nil')
90
+
91
+ # Test with ospf_name parameter specified
92
+ all = InterfaceOspf.interfaces('ospf_test')
93
+ assert_operator(all.length, :>, 1,
94
+ 'Invalid number of keys returned, should exceed 1')
95
+ assert_empty(all[intf2].show_name,
96
+ ':show_name should be empty string when show_name param is nil')
97
+
98
+ one = InterfaceOspf.interfaces('ospf_test', intf2)
99
+ assert_equal(one.length, 1,
100
+ 'Invalid number of keys returned, should be 1')
101
+ assert_equal(Utils.normalize_intf_pattern(intf2), one[intf2].show_name,
102
+ ':show_name should be intf2 name when show_name param specified')
103
+
104
+ # Test non-existent loopback raises fail when calling initialize
105
+ Interface.new('loopback543', false).destroy if
106
+ Interface.interfaces(nil, 'loopback543').any?
107
+ assert_raises(RuntimeError) do
108
+ InterfaceOspf.new('loopback543', 'ospf_test', '0', false)
109
+ end
110
+
111
+ # Test non-existent loopback does NOT raise when calling interfaces
112
+ one = InterfaceOspf.interfaces('ospf_test', 'loopback543')
113
+ assert_empty(one, 'InterfaceOspf.interfaces hash should be empty')
114
+ end
115
+
116
+ def test_get_set_area
117
+ # setup a loopback to use
118
+ config('interface loopback12')
119
+
120
+ int_ospf = InterfaceOspf.new('loopback12', '12', '0.0.0.0')
121
+
122
+ # test invalid
123
+ assert_raises(CliError) do
124
+ int_ospf.area = 'Blue'
125
+ end
126
+
127
+ # test get/set ip address form
128
+ int_ospf.area = '0.0.0.4'
129
+ assert_equal(int_ospf.area, '0.0.0.4')
130
+
131
+ # test get/set integer form.
132
+ # Note: the area getter will munge the value to dotted decimal.
133
+ int_ospf.area = '3'
134
+ assert_equal(int_ospf.area, '0.0.0.3')
135
+
136
+ # cleanup
137
+ config('no interface loopback12')
138
+ end
139
+
140
+ def test_collection_empty
141
+ config('no feature ospf', 'feature ospf', 'router ospf TestOSPF')
142
+
143
+ routers = RouterOspf.routers()
144
+ routers.each_value do |router|
145
+ interfaces = InterfaceOspf.interfaces(router.name)
146
+ assert_empty(interfaces,
147
+ 'InterfaceOspf collection is not empty')
148
+ end
149
+ end
150
+
151
+ def test_collection_not_empty
152
+ ifname1 = interfaces[1].downcase
153
+ ifname2 = interfaces[2].downcase
154
+ ospf1 = 'TestOSPF'
155
+ ospf2 = 'bxb300'
156
+ # pre-configure
157
+ interface_switchport_enable(ifname1, false)
158
+ interface_switchport_enable(ifname2, false)
159
+ config('no feature ospf',
160
+ 'feature ospf',
161
+ "router ospf #{ospf1}",
162
+ "interface #{ifname1}",
163
+ "ip router ospf #{ospf1} area 0.0.0.0",
164
+ "router ospf #{ospf2}",
165
+ "interface #{ifname2}",
166
+ "ip router ospf #{ospf2} area 10.6.6.1",
167
+ )
168
+
169
+ routers = RouterOspf.routers()
170
+ # validate the collection
171
+ routers.each_value do |router|
172
+ interfaces = InterfaceOspf.interfaces(router.name)
173
+ refute_empty(interfaces,
174
+ 'InterfaceOspf collection is empty')
175
+ assert_equal(1, interfaces.size,
176
+ "InterfaceOspf collection (#{interfaces}) size is not 1")
177
+ interfaces.each do |ifname, interface|
178
+ pattern = (/\s+ip router ospf #{router.name} area #{interface.area}/)
179
+ assert_show_match(command: show_cmd(ifname),
180
+ pattern: pattern)
181
+ # using default check, since not configured anything
182
+ assert_equal(node.config_get_default('interface_ospf', 'cost'),
183
+ interface.cost,
184
+ 'Error: get cost failed')
185
+ assert_equal(node.config_get_default('interface_ospf',
186
+ 'hello_interval'),
187
+ interface.hello_interval,
188
+ 'Error: get hello interval failed')
189
+ assert_equal(node.config_get_default('interface_ospf',
190
+ 'dead_interval'),
191
+ interface.dead_interval,
192
+ 'Error: get dead interval failed')
193
+ assert_equal(node.config_get_default('interface_ospf',
194
+ 'bfd'),
195
+ interface.bfd,
196
+ 'Error: bfd get failed')
197
+ assert_equal(node.config_get_default('interface_ospf',
198
+ 'mtu_ignore'),
199
+ interface.mtu_ignore,
200
+ 'Error: mtu_ignore get failed')
201
+ assert_equal(node.config_get_default('interface_ospf',
202
+ 'priority'),
203
+ interface.priority,
204
+ 'Error: priority get failed')
205
+ assert_equal(node.config_get_default('interface_ospf',
206
+ 'network_type_default'),
207
+ interface.network_type,
208
+ 'Error: network type get failed')
209
+ assert_equal(node.config_get_default('interface_ospf',
210
+ 'shutdown'),
211
+ interface.shutdown,
212
+ 'Error: shutdown get failed')
213
+ assert_equal(node.config_get_default('interface_ospf',
214
+ 'transmit_delay'),
215
+ interface.transmit_delay,
216
+ 'Error: transmit_delay get failed')
217
+ assert_equal(node.config_get_default('interface_ospf',
218
+ 'passive_interface'),
219
+ interface.passive_interface,
220
+ 'Error: passive interface get failed')
221
+ assert_equal(node.config_get_default('interface_ospf',
222
+ 'message_digest'),
223
+ interface.message_digest,
224
+ 'Error: message digest get failed')
225
+ assert_equal(node.config_get_default('interface_ospf',
226
+ 'message_digest_key_id'),
227
+ interface.message_digest_key_id,
228
+ 'Error: message digest key get failed')
229
+ end
230
+ end
231
+ end
232
+
233
+ def test_routerospf_nil
234
+ assert_raises(TypeError) do
235
+ InterfaceOspf.new(interfaces[0], nil, '0.0.0.0')
236
+ end
237
+ end
238
+
239
+ def test_name_zero_length
240
+ name = 'ospfTest'
241
+ ospf = RouterOspf.new(name)
242
+ assert_raises(ArgumentError) do
243
+ InterfaceOspf.new('', ospf.name, '0.0.0.0')
244
+ end
245
+ end
246
+
247
+ def test_area_zero_length
248
+ name = 'ospfTest'
249
+ ospf = RouterOspf.new(name)
250
+ assert_raises(ArgumentError) do
251
+ InterfaceOspf.new(interfaces[0], ospf.name, '')
252
+ end
253
+ end
254
+
255
+ def test_routerospf
256
+ ospf = create_routerospf
257
+ ifname = interfaces[1]
258
+ area = '0.0.0.0'
259
+ interface_switchport_enable(ifname, false)
260
+ interface = InterfaceOspf.new(ifname, ospf.name, area)
261
+ pattern = (/\s+ip router ospf #{ospf.name} area #{area}/)
262
+ assert_show_match(command: show_cmd(ifname),
263
+ pattern: pattern)
264
+ assert_equal(ifname.downcase, interface.intf_name,
265
+ 'Error: interface name get value mismatch ')
266
+ assert_equal(area, interface.area,
267
+ 'Error: area get value mismatch ')
268
+ end
269
+
270
+ def test_destroy
271
+ ifname = interfaces[1]
272
+ area = '0.0.0.0'
273
+ ospf = create_routerospf
274
+ interface = create_interfaceospf(ospf, ifname, area)
275
+ interface.destroy
276
+ refute_show_match(pattern: /\s+ip router ospf #{ospf.name} area #{area}/,
277
+ msg: "'ip router ospf #{ospf.name} area #{area}' " \
278
+ 'not destroyed')
279
+ # check all the attributes are set to default.
280
+ refute_show_match(pattern: /^\s+ip ospf cost \S+/,
281
+ msg: "'cost' not removed")
282
+
283
+ refute_show_match(pattern: /^\s+ip ospf hello-interval \S+/,
284
+ msg: "'hello-interval' not removed")
285
+
286
+ # with default CLI still shows the value
287
+ refute_show_match(pattern: /^\s+ip ospf dead-interval \S+/,
288
+ msg: "'dead-interval' not removed")
289
+
290
+ refute_show_match(pattern: /^\s+ip ospf bfd \S+/,
291
+ msg: "'bfd' not removed")
292
+
293
+ refute_show_match(pattern: /^\s+ip ospf mtu-ignore \S+/,
294
+ msg: "'mtu_ignore' not removed")
295
+
296
+ refute_show_match(pattern: /^\s+ip ospf shutdown \S+/,
297
+ msg: "'shutdown' not removed")
298
+
299
+ refute_show_match(pattern: /^\s+ip ospf transmit-delay \S+/,
300
+ msg: "'transmit_delay' not removed")
301
+
302
+ refute_show_match(pattern: /^\s+ip ospf priority \S+/,
303
+ msg: "'priority' not removed")
304
+
305
+ refute_show_match(pattern: /^\s+ip ospf network point-to-point/,
306
+ msg: "'network_type' not removed")
307
+
308
+ refute_show_match(pattern: /^\s+ip ospf passive-interface/,
309
+ msg: "'passive interface' not removed")
310
+ end
311
+
312
+ def test_get_parent
313
+ ospf = create_routerospf
314
+ interface = create_interfaceospf(ospf)
315
+ assert_equal(ospf.name, interface.ospf_name)
316
+ end
317
+
318
+ def test_cost_inv
319
+ ospf = create_routerospf
320
+ interface = create_interfaceospf(ospf)
321
+ # upper range
322
+ assert_raises(CliError) do
323
+ interface.cost = 65_536
324
+ end
325
+ # lower range just removes the config.
326
+ # assert_raises(RuntimeError) do
327
+ # interface.cost = 0
328
+ # end
329
+ end
330
+
331
+ def test_cost
332
+ ospf = create_routerospf
333
+ interface = create_interfaceospf(ospf)
334
+ cost = 1000
335
+ # set with value
336
+ interface.cost = cost
337
+ assert_show_match(pattern: /\s+ip ospf cost #{cost}/,
338
+ msg: 'Error: cost missing in CLI')
339
+ assert_equal(cost, interface.cost,
340
+ 'Error: cost get value mismatch')
341
+ # set default
342
+ interface.cost = interface.default_cost
343
+ refute_show_match(pattern: /\s+ip ospf cost(.*)/,
344
+ msg: 'Error: default cost set failed')
345
+ end
346
+
347
+ def test_hello_inv
348
+ ospf = create_routerospf
349
+ interface = create_interfaceospf(ospf)
350
+ # upper range
351
+ assert_raises(CliError) do
352
+ interface.hello_interval = 65_536
353
+ end
354
+ # lower range
355
+ assert_raises(CliError) do
356
+ interface.hello_interval = 0
357
+ end
358
+ end
359
+
360
+ def test_hello
361
+ ospf = create_routerospf
362
+ interface = create_interfaceospf(ospf)
363
+ interval = 90
364
+ # set with value
365
+ interface.hello_interval = interval
366
+ assert_show_match(pattern: /\s+ip ospf hello-interval #{interval}/,
367
+ msg: 'Error: hello-interval missing in CLI')
368
+ assert_equal(interval, interface.hello_interval,
369
+ 'Error: hello-interval get value mismatch')
370
+
371
+ # set default, when we set default CLI does not show it
372
+ interface.hello_interval = interface.default_hello_interval
373
+ refute_show_match(pattern: /\s+ip ospf hello-interval(.*)/,
374
+ msg: 'Error: default hello-interval set failed')
375
+
376
+ # Test destroy_interval helper method
377
+ interface.hello_interval = interval
378
+ interface.destroy_interval('hello_interval')
379
+ refute_show_match(
380
+ command: show_cmd(interface.intf_name),
381
+ pattern: /\s+ip ospf hello-interval/,
382
+ msg: 'ip ospf hello-interval not removed')
383
+ end
384
+
385
+ def test_dead_inv
386
+ ospf = create_routerospf
387
+ interface = create_interfaceospf(ospf)
388
+
389
+ ref = cmd_ref.lookup('interface_ospf', 'dead_interval')
390
+ assert(ref, 'Error, reference not found for dead_interval')
391
+
392
+ # upper range
393
+ assert_raises(CliError) do
394
+ interface.dead_interval = 262_141
395
+ end
396
+ # lower range
397
+ assert_raises(CliError) do
398
+ interface.dead_interval = 0
399
+ end
400
+ end
401
+
402
+ def test_dead
403
+ ospf = create_routerospf
404
+ interface = create_interfaceospf(ospf)
405
+ interval = 150
406
+ # set with value
407
+ interface.dead_interval = interval
408
+ assert_show_match(pattern: /\s+ip ospf dead-interval #{interval}/,
409
+ msg: 'Error: dead-interval missing in CLI')
410
+ assert_equal(interval, interface.dead_interval,
411
+ 'Error: dead-interval get value mismatch')
412
+ # set default, the CLI shows with default value
413
+ interface.dead_interval = interface.default_dead_interval
414
+ assert_show_match(
415
+ pattern: /^\s+ip ospf dead-interval #{interface.default_dead_interval}/,
416
+ msg: 'Error: default dead-interval set failed')
417
+
418
+ # Test destroy_interval helper method
419
+ interface.dead_interval = interval
420
+ interface.destroy_interval('dead_interval')
421
+ refute_show_match(
422
+ command: show_cmd(interface.intf_name),
423
+ pattern: /\s+ip ospf dead-interval/,
424
+ msg: 'ip ospf dead-interval not removed')
425
+ end
426
+
427
+ def test_bfd
428
+ ospf = create_routerospf
429
+ interface = create_interfaceospf(ospf)
430
+ assert_equal(interface.default_bfd, interface.bfd)
431
+ interface.bfd = true
432
+ assert_equal(true, interface.bfd)
433
+ interface.bfd = false
434
+ assert_equal(false, interface.bfd)
435
+ interface.bfd = interface.default_bfd
436
+ assert_equal(interface.default_bfd, interface.bfd)
437
+ end
438
+
439
+ def test_mtu_ignore
440
+ ospf = create_routerospf
441
+ interface = create_interfaceospf(ospf)
442
+ assert_equal(interface.default_mtu_ignore, interface.mtu_ignore)
443
+ interface.mtu_ignore = true
444
+ assert_equal(true, interface.mtu_ignore)
445
+ interface.mtu_ignore = interface.default_mtu_ignore
446
+ assert_equal(interface.default_mtu_ignore, interface.mtu_ignore)
447
+ end
448
+
449
+ def test_network_type
450
+ ospf = create_routerospf
451
+ interface = create_interfaceospf(ospf)
452
+
453
+ assert_equal(interface.default_network_type, interface.network_type)
454
+ interface.network_type = 'p2p'
455
+ assert_equal('p2p', interface.network_type)
456
+ interface.network_type = interface.default_network_type
457
+ assert_equal(interface.default_network_type, interface.network_type)
458
+
459
+ # setup a loopback to use
460
+ config('interface loopback12')
461
+ interface = InterfaceOspf.new('loopback12', '12', '0.0.0.0')
462
+ assert_equal(interface.default_network_type, interface.network_type)
463
+ interface.network_type = 'p2p'
464
+ assert_equal('p2p', interface.network_type)
465
+ interface.network_type = interface.default_network_type
466
+ assert_equal(interface.default_network_type, interface.network_type)
467
+ # cleanup
468
+ config('no interface loopback12')
469
+ end
470
+
471
+ def test_passive
472
+ ospf = create_routerospf
473
+ interface = create_interfaceospf(ospf)
474
+
475
+ # set with value
476
+ interface.passive_interface = true
477
+ assert_show_match(pattern: /\s+ip ospf passive-interface/,
478
+ msg: 'passive interface enable missing in CLI')
479
+ assert(interface.passive_interface,
480
+ 'Error: passive interface get value mismatch')
481
+
482
+ # get default and set
483
+ interface.passive_interface = interface.default_passive_interface
484
+ assert_show_match(pattern: /\s+no ip ospf passive-interface/,
485
+ msg: 'default passive interface set failed')
486
+ end
487
+
488
+ def test_priority
489
+ ospf = create_routerospf
490
+ interface = create_interfaceospf(ospf)
491
+ assert_equal(interface.default_priority, interface.priority)
492
+ interface.priority = 100
493
+ assert_equal(100, interface.priority)
494
+ interface.priority = interface.default_priority
495
+ assert_equal(interface.default_priority, interface.priority)
496
+ end
497
+
498
+ def test_shutdown
499
+ ospf = create_routerospf
500
+ interface = create_interfaceospf(ospf)
501
+ assert_equal(interface.default_shutdown, interface.shutdown)
502
+ interface.shutdown = true
503
+ assert_equal(true, interface.shutdown)
504
+ interface.shutdown = interface.default_shutdown
505
+ assert_equal(interface.default_shutdown, interface.shutdown)
506
+ end
507
+
508
+ def test_transmit_delay
509
+ ospf = create_routerospf
510
+ interface = create_interfaceospf(ospf)
511
+ assert_equal(interface.default_transmit_delay, interface.transmit_delay)
512
+ interface.transmit_delay = 400
513
+ assert_equal(400, interface.transmit_delay)
514
+ interface.transmit_delay = interface.default_transmit_delay
515
+ assert_equal(interface.default_transmit_delay, interface.transmit_delay)
516
+ end
517
+
518
+ def test_mult
519
+ # ospf and interfaces[0]
520
+ ospf = create_routerospf
521
+ interface = create_interfaceospf(ospf)
522
+ assert_show_match(
523
+ pattern: /\s+ip router ospf #{ospf.name} area #{interface.area}/,
524
+ msg: "'ip router ospf #{ospf.name} default area' not configured")
525
+
526
+ ifname = interfaces[2]
527
+ area = '1.1.1.1'
528
+ create_interfaceospf(ospf, ifname, area)
529
+ assert_show_match(
530
+ pattern: /\s+ip router ospf #{ospf.name} area #{area}/,
531
+ msg: "'ip router ospf #{ospf.name} area #{area}' is not configured")
532
+ end
533
+
534
+ def test_mult_delete_one
535
+ # ospf and interfaces[0]
536
+ ospf = create_routerospf
537
+ interface = create_interfaceospf(ospf)
538
+
539
+ ifname = interfaces[2]
540
+ area = '1.1.1.1'
541
+ interface1 = create_interfaceospf(ospf, ifname, area)
542
+ assert_equal(ifname.downcase, interface1.intf_name,
543
+ "Error: 'ip router ospf #{ospf.name} area #{area}' " \
544
+ 'not configured')
545
+
546
+ interface1.destroy
547
+ refute_show_match(
548
+ command: show_cmd(ifname),
549
+ pattern: /\s+ip router ospf #{ospf.name} area #{area}/,
550
+ msg: "'ip router ospf #{ospf.name} area #{area}' not deleted")
551
+
552
+ # check other interface association still exist.
553
+ assert_show_match(
554
+ command: show_cmd(interface.intf_name),
555
+ pattern: /\s+ip router ospf #{ospf.name} area #{interface.area}/,
556
+ msg: "'ip router ospf #{ospf.name} default area' not configured")
557
+ end
558
+
559
+ def configure_from_hash(hash)
560
+ hash.each do |k, v|
561
+ # puts "TEST: pre-config hash key : #{k}"
562
+ config("router ospf #{k}")
563
+ v.each do |k1, v1|
564
+ # puts "TEST: pre-config k1: v1 '#{k1} : #{v1}'"
565
+ cfg = ["interface #{k1}"]
566
+ if !(/^ethernet\d.\d/).match(k1.to_s).nil? ||
567
+ !(/^port-channel\d/).match(k1.to_s).nil?
568
+ cfg << 'no switchport'
569
+ # puts "switchport disable: #{k1}"
570
+ end
571
+ # puts "k1: #{k1}, k: #{k}, area #{v1[:area]}"
572
+ cfg << "ip router ospf #{k} area #{v1[:area]}"
573
+ cfg << 'ip ospf bfd' if v1[:bfd]
574
+ cfg << 'ip ospf bfd disable' if v1[:bfd] == false
575
+ cfg << 'no ip ospf bfd' if v1[:bfd].nil?
576
+ cfg << "ip ospf cost #{v1[:cost]}" unless v1[:cost] == 0
577
+ cfg << "ip ospf hello-interval #{v1[:hello]}" unless v1[:hello].nil?
578
+ cfg << "ip ospf dead-interval #{v1[:dead]}" unless v1[:dead].nil?
579
+ cfg << 'ip ospf network point-to-point' if v1[:net] == 'p2p'
580
+ cfg << 'no ip ospf network' if v1[:net] == 'broadcast'
581
+ cfg << 'ip ospf passive-interface' if !v1[:pass].nil? &&
582
+ v1[:pass] == true
583
+ config(*cfg)
584
+ end
585
+ end
586
+ end
587
+
588
+ def multiple_interface_config_hash
589
+ # rubocop:disable Style/AlignHash
590
+ hash = {
591
+ 'ospfTest' => {
592
+ interfaces[0].downcase => {
593
+ area: '0.0.0.0', bfd: true, cost: 10, hello: 30,
594
+ dead: 120, net: 'p2p', pass: true },
595
+ interfaces[1].downcase => {
596
+ area: '1.1.1.38', bfd: false, dead: 40, net: 'p2p', pass: false },
597
+ 'vlan101' => {
598
+ area: '2.2.2.101', bfd: true, cost: 5, hello: 20, dead: 80,
599
+ net: 'p2p', pass: true },
600
+ },
601
+ 'TestOspfInt' => {
602
+ interfaces[2].downcase => {
603
+ area: '0.0.0.19' },
604
+ 'vlan290' => {
605
+ area: '2.2.2.29', bfd: true, cost: 200, hello: 30,
606
+ dead: 120, net: 'broadcast', pass: true },
607
+ 'port-channel100' => {
608
+ area: '3.2.2.29', bfd: false, cost: 25, hello: 50, dead: 200,
609
+ net: 'p2p', pass: false },
610
+ },
611
+ }
612
+ # rubocop:enable Style/AlignHash
613
+ # Set defaults
614
+ hash.each_key do |name|
615
+ hash[name].each_value do |hv|
616
+ hv[:bfd] ||= node.config_get_default('interface_ospf', 'bfd')
617
+ hv[:cost] ||= node.config_get_default('interface_ospf', 'cost')
618
+ hv[:hello] ||= node.config_get_default('interface_ospf',
619
+ 'hello_interval')
620
+ hv[:dead] ||= node.config_get_default('interface_ospf',
621
+ 'dead_interval')
622
+ hv[:net] ||= node.config_get_default('interface_ospf',
623
+ 'network_type_default')
624
+ hv[:pass] ||= node.config_get_default('interface_ospf',
625
+ 'passive_interface')
626
+ end
627
+ end
628
+ end
629
+
630
+ def test_collect_mult_intf
631
+ s = config('int port-channel 42', 'descr foo')
632
+ known_failure = s[/ERROR:.*port channel not present/]
633
+ refute(known_failure, 'ERROR: port channel not present')
634
+
635
+ ospf_h = multiple_interface_config_hash
636
+
637
+ # enable feature ospf
638
+ config('no feature ospf',
639
+ 'feature ospf',
640
+ 'feature bfd',
641
+ 'feature interface-vlan',
642
+ "default interface #{interfaces[0]}",
643
+ "default interface #{interfaces[1]}",
644
+ "default interface #{interfaces[2]}",
645
+ )
646
+
647
+ # pre-configure
648
+ configure_from_hash(ospf_h)
649
+
650
+ routers = RouterOspf.routers()
651
+ # validate the collection
652
+ routers.each do |name, router|
653
+ interfaces = InterfaceOspf.interfaces(router.name)
654
+ refute_empty(interfaces, 'InterfaceOspf collection is empty')
655
+ assert_includes(ospf_h, name)
656
+ ospfh = ospf_h.fetch(name)
657
+ assert_equal(ospfh.size, interfaces.size,
658
+ "InterfaceOspf #{name} collection size mismatch")
659
+ interfaces.each do |ifname, interface|
660
+ assert_includes(ospfh, ifname)
661
+ hv = ospfh.fetch(ifname)
662
+ assert_show_match(
663
+ command: show_cmd(ifname),
664
+ pattern: /\s+ip router ospf #{name} area #{hv[:area]}/,
665
+ msg: "Error: ip router ospf #{name} area #{hv[:area]} "\
666
+ "not found under #{ifname}")
667
+
668
+ if hv[:bfd].nil?
669
+ assert_nil(interface.bfd, 'Error: get bfd is not nil')
670
+ else
671
+ assert_equal(hv[:bfd], interface.bfd, 'Error: get bfd failed')
672
+ end
673
+ assert_equal(hv[:cost], interface.cost, 'Error: get cost failed')
674
+ assert_equal(hv[:hello], interface.hello_interval,
675
+ 'Error: get hello interval failed')
676
+ assert_equal(hv[:dead], interface.dead_interval,
677
+ 'Error: get dead interval failed')
678
+ assert_equal(hv[:net], interface.network_type,
679
+ 'Error: network_type get failed')
680
+ assert_equal(hv[:pass], interface.passive_interface,
681
+ 'Error: passive interface get failed')
682
+ end
683
+ end # interfaces hash
684
+ # clean up
685
+
686
+ # disable feature interface-vlan
687
+ config('no feature interface-vlan')
688
+ config('no feature bfd')
689
+ # clean up port channel
690
+ ospf_h.each_value do |v|
691
+ v.each_key do |k1|
692
+ config("no interface #{k1}") if (/^port-channel\d/).match(k1)
693
+ end # v each
694
+ end # ospf_h each
695
+ end
696
+
697
+ def test_message_digest
698
+ ospf = create_routerospf
699
+ interface = create_interfaceospf(ospf)
700
+
701
+ # set with value
702
+ interface.message_digest = true
703
+ pattern = (/^\s+ip ospf authentication message-digest$/)
704
+ assert_show_match(pattern: pattern,
705
+ msg: 'Error: message digest enable missing in CLI')
706
+ assert(interface.message_digest,
707
+ 'Error: message digest is false but should be true')
708
+
709
+ # get default and set
710
+ interface.message_digest = interface.default_message_digest
711
+ refute_show_match(pattern: pattern,
712
+ msg: 'Error: default message digest set failed')
713
+ refute(interface.message_digest,
714
+ 'Error: message digest is true but should be false (default)')
715
+ end
716
+
717
+ def test_message_digest_key
718
+ ospf = create_routerospf
719
+ interface = create_interfaceospf(ospf)
720
+ # auth params
721
+ keyid = 1
722
+ algo = :md5
723
+ encr = :cleartext
724
+
725
+ # set with value
726
+ interface.message_digest_key_set(keyid, algo, encr, 'test123')
727
+ # need to revist TODO
728
+ line = assert_show_match(
729
+ pattern: /^\s+ip ospf message-digest-key #{keyid} md5 \S \S+$/,
730
+ msg: 'message digest authentication with cleartext missing in CLI')
731
+ # TODO: assert(interface.message_digest,
732
+ # "Error: message digest get value mismatch")
733
+ # check key id exist
734
+ assert_equal(keyid, interface.message_digest_key_id,
735
+ "Error: message digest key #{keyid} not present")
736
+ # save encrypted password
737
+ md = /3 (\S+)$/.match(line.to_s)
738
+ encrypted_password = md.to_s.split(' ').last
739
+ assert_equal(encrypted_password, interface.message_digest_password)
740
+
741
+ # Check other attributes:
742
+ assert_equal(algo, interface.message_digest_algorithm_type)
743
+ assert_equal(:"3des", interface.message_digest_encryption_type)
744
+
745
+ # unconfigure auth
746
+ keyid = interface.default_message_digest_key_id
747
+ encr = :cleartext
748
+ interface.message_digest_key_set(keyid, algo, encr, 'test123')
749
+ refute_show_match(pattern: /^\s+ip ospf message-digest-key #{keyid} .+/,
750
+ msg: 'message digest auth still present in CLI')
751
+ assert_equal(interface.message_digest_key_id,
752
+ interface.default_message_digest_key_id)
753
+ assert_equal(interface.message_digest_algorithm_type,
754
+ interface.default_message_digest_algorithm_type)
755
+ assert_equal(interface.message_digest_encryption_type,
756
+ interface.default_message_digest_encryption_type)
757
+
758
+ # update enc with 3DES
759
+ keyid = 1
760
+ encr = :"3des"
761
+ interface.message_digest_key_set(keyid, algo, encr, encrypted_password)
762
+ assert_show_match(
763
+ pattern: /^\s+ip ospf message-digest-key #{keyid} md5 3 \S+$/,
764
+ msg: 'message digest authentication with 3DES missing in CLI')
765
+ assert_equal(keyid, interface.message_digest_key_id)
766
+ assert_equal(algo, interface.message_digest_algorithm_type)
767
+ assert_equal(encr, interface.message_digest_encryption_type)
768
+ assert_equal(encrypted_password, interface.message_digest_password)
769
+
770
+ # update enc with cisco type 7
771
+ keyid = 1
772
+ encr = :cisco_type_7
773
+ interface.message_digest_key_set(keyid, algo, encr, encrypted_password)
774
+ assert_show_match(
775
+ pattern: /^\s+ip ospf message-digest-key #{keyid} md5 7 \S+$/,
776
+ msg: 'message digest authentication with cisco type 7 missing in CLI')
777
+ assert_equal(keyid, interface.message_digest_key_id)
778
+ assert_equal(algo, interface.message_digest_algorithm_type)
779
+ assert_equal(encr, interface.message_digest_encryption_type)
780
+ end
781
+
782
+ def test_message_digest_key_inv
783
+ ospf = create_routerospf
784
+ interface = create_interfaceospf(ospf)
785
+
786
+ # blank password
787
+ keyid = 1
788
+ algo = :md5
789
+ encr = :cleartext
790
+ password = ''
791
+ assert_raises(ArgumentError) do
792
+ interface.message_digest_key_set(keyid, algo, encr, password)
793
+ end
794
+
795
+ # mismatch password and encryption
796
+ encr = :"3des"
797
+ password = 'test123'
798
+ assert_raises(CliError) do
799
+ interface.message_digest_key_set(keyid, algo, encr, password)
800
+ end
801
+ end
802
+
803
+ def test_nonexistent
804
+ # If the interface does exist but the OSPF instance does not, this is OK
805
+ config('interface loopback122')
806
+ interface = InterfaceOspf.new('loopback122', 'nonexistentOspf', '0')
807
+
808
+ # Note: the area getter will munge the value to dotted decimal.
809
+ assert_equal(interface.area, '0.0.0.0')
810
+ assert_equal(interface.hello_interval, interface.default_hello_interval)
811
+
812
+ interface.destroy
813
+
814
+ # If the interface doesn't exist, InterfaceOspf should raise an error
815
+ config('no interface loopback122')
816
+ assert_raises(RuntimeError) do
817
+ interface = InterfaceOspf.new('loopback122', 'nonexistentOspf', '0')
818
+ end
819
+ end
820
+ end