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,1958 @@
1
+ # Copyright (c) 2013-2018 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/acl'
17
+ require_relative '../lib/cisco_node_utils/interface'
18
+ require_relative '../lib/cisco_node_utils/interface_channel_group'
19
+ require_relative '../lib/cisco_node_utils/cisco_cmn_utils'
20
+ require_relative '../lib/cisco_node_utils/overlay_global'
21
+
22
+ include Cisco
23
+
24
+ # TestInterface - Minitest for general functionality of the Interface class.
25
+ class TestInterface < CiscoTestCase
26
+ DEFAULT_IF_ACCESS_VLAN = 1
27
+ DEFAULT_IF_DESCRIPTION = ''
28
+ DEFAULT_IF_IP_ADDRESS = nil
29
+ DEFAULT_IF_IP_NETMASK_LEN = nil
30
+ DEFAULT_IF_IP_PROXY_ARP = false
31
+ DEFAULT_IF_IP_REDIRECTS = true
32
+ DEFAULT_IF_VRF = ''
33
+ IF_VRF_MAX_LENGTH = 32
34
+
35
+ def setup
36
+ super
37
+ interface_ethernet_default(interfaces[0])
38
+ if platform == :nexus
39
+ @port_channel = 'port-channel'
40
+ # rubocop:disable Style/AlignHash
41
+ @switchport_shutdown_hash = {
42
+ 'shutdown_ethernet_switchport_shutdown' =>
43
+ ['system default switchport',
44
+ 'system default switchport shutdown'],
45
+ 'shutdown_ethernet_switchport_noshutdown' =>
46
+ ['system default switchport',
47
+ 'no system default switchport shutdown'],
48
+ 'shutdown_ethernet_noswitchport_shutdown' =>
49
+ ['no system default switchport',
50
+ 'system default switchport shutdown'],
51
+ 'shutdown_ethernet_noswitchport_noshutdown' =>
52
+ ['no system default switchport',
53
+ 'no system default switchport shutdown'],
54
+ }
55
+ # rubocop:enable Style/AlignHash
56
+ elsif platform == :ios_xr
57
+ @port_channel = 'Bundle-Ether'
58
+ @switchport_shutdown_hash = {
59
+ # Not really applicable to XR
60
+ 'shutdown_ethernet_noswitchport_shutdown' => []
61
+ }
62
+ end
63
+ end
64
+
65
+ def teardown
66
+ interface_ethernet_default(interfaces[0])
67
+ if first_or_last_teardown
68
+ config_no_warn('no feature pim')
69
+ config_no_warn('no feature dhcp')
70
+ config_no_warn('no feature bfd')
71
+ config_no_warn('no feature interface-vlan')
72
+ config_no_warn('no feature-set fabric')
73
+ config_no_warn('no install feature-set fabric')
74
+ end
75
+ super
76
+ end
77
+
78
+ def ipv4
79
+ if platform == :nexus
80
+ 'ip'
81
+ elsif platform == :ios_xr
82
+ 'ipv4'
83
+ end
84
+ end
85
+
86
+ def ipv4_address_pattern(address, length, secondary=false)
87
+ if platform == :nexus
88
+ if secondary
89
+ %r{^\s+ip address #{address}/#{length} secondary$}
90
+ else
91
+ %r{^\s+ip address #{address}/#{length}$}
92
+ end
93
+ elsif platform == :ios_xr
94
+ mask = Utils.length_to_bitmask(length)
95
+ if secondary
96
+ /^\s+ipv4 address #{address} #{mask} secondary$/
97
+ else
98
+ /^\s+ipv4 address #{address} #{mask}$/
99
+ end
100
+ end
101
+ end
102
+
103
+ def interface_ipv4_config(ifname, address, length,
104
+ do_config=true, secip=false)
105
+ if do_config
106
+ config_no_warn("interface #{ifname}",
107
+ 'no switchport') if platform == :nexus
108
+ if !secip
109
+ config("interface #{ifname}",
110
+ "#{ipv4} address #{address}/#{length}")
111
+ else
112
+ config("interface #{ifname}",
113
+ "#{ipv4} address #{address}/#{length} secondary")
114
+ end
115
+ else
116
+ config("interface #{ifname}",
117
+ "no #{ipv4} address", # This will remove both primary and secondary
118
+ )
119
+ config("interface #{ifname}",
120
+ 'switchport') if platform == :nexus
121
+ end
122
+ end
123
+
124
+ def show_cmd(name)
125
+ if platform == :nexus
126
+ all = (name =~ /port-channel\d/ && node.product_id =~ /N7/) ? '' : 'all'
127
+ "show run interface #{name} #{all} | no-more"
128
+ else
129
+ "show run interface #{name}"
130
+ end
131
+ end
132
+
133
+ def interface_count
134
+ if platform == :nexus
135
+ cmd = 'show run interface all | inc interface | no-more'
136
+ elsif platform == :ios_xr
137
+ cmd = 'show run interface | inc interface'
138
+ end
139
+ output = @device.cmd(cmd)
140
+ # Next line needs to be done because sh run interface all also shows
141
+ # ospf interface related config
142
+ arr = output.split("\n").select { |str| str.start_with?('interface') }
143
+ refute_empty(arr, "Found no matching lines in:\n#{output}")
144
+ refute_equal(1, arr.count, "Found only one interface in:\n#{output}")
145
+ arr.count
146
+ end
147
+
148
+ def test_capabilities
149
+ if validate_property_excluded?('interface', 'capabilities')
150
+ assert_empty(Interface.capabilities(interfaces[0]))
151
+ else
152
+ refute_empty(Interface.capabilities(interfaces[0], :hash),
153
+ 'A valid interface should return a non-empty hash')
154
+ assert_empty(Interface.capabilities('foo', :hash),
155
+ 'An Invalid interface should return an empty hash')
156
+
157
+ refute_empty(Interface.capabilities(interfaces[0], :raw),
158
+ 'A valid interface should return a non-empty array')
159
+ assert_empty(Interface.capabilities('foo', :raw),
160
+ 'An Invalid interface should return an empty array')
161
+ end
162
+ end
163
+
164
+ def test_non_existent_intf
165
+ # pre-clean: remove intf if it exists
166
+ Interface.new('loopback100').destroy
167
+
168
+ # Create from non-exist
169
+ interface = Interface.new('loopback100')
170
+ refute_nil(interface.name)
171
+ interface.destroy
172
+ end
173
+
174
+ def test_interface_apis
175
+ # N7K: verify show_name pattern
176
+ {
177
+ 'etherNET1/1.42' => 'Ethernet1/1.42$',
178
+ 'LOOPback23' => 'loopback23$',
179
+ 'Port-Channel19' => 'port-channel19$',
180
+ 'MONGOsonet12' => '.ongosonet12$',
181
+ }.each do |k, v|
182
+ assert_equal(v, Utils.normalize_intf_pattern(k),
183
+ "pattern should be #{v}")
184
+ end if node.product_id[/N7/]
185
+
186
+ # Verify intf counter
187
+ assert_equal(Interface.interface_count, interface_count,
188
+ 'Interface.interface_count did not return the expected count')
189
+
190
+ # Verify raise rescued when loopback does not exist ('Invalid range' rescued)
191
+ Interface.new('loopback100').destroy
192
+ no_loopback = Interface.interfaces(nil, 'loopback100')
193
+ assert_empty(no_loopback,
194
+ 'Return value should be empty hash when non existent loopback')
195
+
196
+ # Verify show_name usage
197
+ intf = interfaces[0]
198
+ one = Interface.interfaces(nil, intf)
199
+ assert_equal(1, one.length,
200
+ 'Invalid number of keys returned, should be 1')
201
+ assert_equal(Utils.normalize_intf_pattern(intf), one[intf].show_name,
202
+ ':show_name should be intf name when intf specified')
203
+
204
+ # Verify 'all' interfaces returned
205
+ all = Interface.interfaces
206
+ assert_operator(all.length, :>, 1,
207
+ 'Invalid number of keys returned, should exceed 1')
208
+ assert_empty(all[intf].show_name,
209
+ ':show_name should be empty string when intf is nil')
210
+
211
+ # Verify filter operations
212
+ eth_count = all.keys.join.scan(/ethernet/).count
213
+ filtered = Interface.interfaces(:ethernet)
214
+ assert_equal(eth_count, filtered.length,
215
+ 'filter returned invalid number of ethernet interfaces')
216
+
217
+ filtered = Interface.interfaces(:mgmt)
218
+ assert_equal(1, filtered.length,
219
+ 'filter returned invalid number of mgmt interfaces')
220
+ assert_equal('mgmt0', filtered.keys[0],
221
+ 'filter returned incorrect interface name')
222
+
223
+ filtered = Interface.interfaces(:mgmt, intf)
224
+ assert_empty(filtered,
225
+ 'mgmt filter returned interface when it should be an empty hash')
226
+
227
+ filtered = Interface.interfaces(:invalid_intf_pattern)
228
+ assert_empty(filtered,
229
+ 'invalid filter returned interface when it should be an empty hash')
230
+
231
+ filtered = Interface.interfaces(:ethernet, intf)
232
+ assert_equal(1, filtered.length,
233
+ 'Invalid number of keys returned by ethernet filter with intf specified')
234
+ assert_equal(intf, filtered.keys[0],
235
+ 'filter returned incorrect interface name')
236
+ end
237
+
238
+ # Helper to get valid speeds for port
239
+ def capable_speed_values(interface)
240
+ speed_capa = Interface.capabilities(interface.name)['Speed']
241
+ return [] if speed_capa.nil?
242
+ speed_capa.split(',')
243
+ end
244
+
245
+ # Helper to get valid duplex values for port
246
+ def capable_duplex_values(interface)
247
+ duplex_capa = Interface.capabilities(interface.name)['Duplex']
248
+ return [] if duplex_capa.nil?
249
+ duplex_capa.split(',')
250
+ end
251
+
252
+ def create_interface(ifname=interfaces[0])
253
+ @default_show_command = show_cmd(ifname)
254
+ Interface.new(ifname)
255
+ end
256
+
257
+ def interface_ethernet_default(ethernet_intf)
258
+ config("default interface #{ethernet_intf}")
259
+ end
260
+
261
+ def interface_supports_property?(intf, message)
262
+ patterns = ['requested config change not allowed',
263
+ '% Invalid command']
264
+ skip("Interface '#{intf}' does not support property") if
265
+ message[Regexp.union(patterns)]
266
+ flunk(message)
267
+ end
268
+
269
+ # Helper to find all configurable speeds for an interface
270
+ def valid_speeds(interface)
271
+ speeds = []
272
+ capable_speed_values(interface).each do |value|
273
+ begin
274
+ interface.speed = value
275
+ assert_equal(value, interface.speed)
276
+ rescue Cisco::CliError => e
277
+ next if speed_change_disallowed?(e.message)
278
+ raise
279
+ end
280
+ speeds << value
281
+ end
282
+ speeds
283
+ end
284
+
285
+ # Helper to check for misc speed change disallowed error messages.
286
+ def speed_change_disallowed?(message)
287
+ patterns = ['port doesn t support this speed',
288
+ 'Changing interface speed is not permitted',
289
+ 'requested config change not allowed',
290
+ /does not match the (transceiver speed|port capability)/,
291
+ 'but the transceiver doesn t support this speed',
292
+ '% Ambiguous parameter',
293
+ '% Invalid parameter']
294
+ message[Regexp.union(patterns)]
295
+ end
296
+
297
+ def validate_interfaces_not_empty
298
+ interfaces = Interface.interfaces
299
+ refute_empty(interfaces, 'Error: interfaces collection empty')
300
+
301
+ # Get number of interfaces
302
+ int_size = interface_count
303
+ assert_equal(int_size, interfaces.size,
304
+ 'Error: Interfaces collection size not correct')
305
+ end
306
+
307
+ def system_default_switchport_shutdown
308
+ state = []
309
+ return state if platform == :ios_xr
310
+ s = @device.cmd("sh run all | in \"system default switchport\"")
311
+
312
+ s.split("\n")[1..-2].each do |line|
313
+ state << line unless line.include?('fabricpath')
314
+ end
315
+ state
316
+ end
317
+
318
+ def validate_interface_shutdown(inttype_h)
319
+ state = system_default_switchport_shutdown
320
+
321
+ # Validate the collection
322
+ inttype_h.each do |k, v|
323
+ interface = v[:interface]
324
+
325
+ @switchport_shutdown_hash.each do |lookup_string, config_array|
326
+ # puts "lookup_string: #{lookup_string}"
327
+
328
+ # Configure the system default shwitchport and shutdown settings
329
+ config(*config_array)
330
+
331
+ interface.shutdown = false
332
+ refute(interface.shutdown,
333
+ "Error: #{interface.name} shutdown is not false")
334
+
335
+ interface.shutdown = true
336
+ # On some platforms, a small delay is needed after setting the
337
+ # shutdown property before the new state can be retrieved by
338
+ # the getter.
339
+ # TBD: Likely a bug in nxapi, but it's not reproducible using
340
+ # the nxapi sandbox.
341
+ begin
342
+ assert(interface.shutdown,
343
+ "Error: #{interface.name} shutdown is not true")
344
+ rescue Minitest::Assertion
345
+ sleep 1
346
+ node.cache_flush
347
+ tries ||= 1
348
+ retry unless (tries += 1) > 5
349
+ raise
350
+ end
351
+
352
+ # Test default shutdown state
353
+ if k.downcase.include?('ethernet') # Ethernet interfaces
354
+
355
+ ref = cmd_ref.lookup('interface', lookup_string)
356
+ assert(ref, "Error, reference not found for #{lookup_string}")
357
+
358
+ result = interface.default_shutdown
359
+ assert_equal(ref.default_value, result, "Error: #{interface.name}, " \
360
+ "(#{lookup_string}), shutdown is #{result}, incorrect")
361
+ else # Port-channel and loopback interfaces
362
+ assert_equal(interface.default_shutdown, v[:default_shutdown],
363
+ "default shutdown state (#{lookup_string}), incorrect")
364
+ end
365
+ end
366
+ end
367
+ config(*state)
368
+ end
369
+
370
+ # set_switchport is handled else where since it changes the
371
+ # interface to L2 and that would affect the idea of this test.
372
+ def validate_get_switchport(inttype_h)
373
+ # Validate the collection
374
+ inttype_h.each_value do |v|
375
+ interface = v[:interface]
376
+
377
+ # Adding a check for getting the switchport_mode on a interfaces
378
+ # that does not support switchport. This used to fail with
379
+ # exception and was first found in end-to-end testing due to how
380
+ # the provider, by default, invokes the getter methods for an
381
+ # interface.
382
+ assert_equal(v[:switchport],
383
+ interface.switchport_mode,
384
+ "Error: #{interface.name}, switchport mode not correct")
385
+
386
+ # get_default check
387
+ assert_equal(v[:default_switchport],
388
+ interface.default_switchport_mode,
389
+ "Error: #{interface.name}, switchport mode, default, " \
390
+ 'not correct')
391
+ end
392
+ rescue Cisco::CliError => e
393
+ skip('NX-OS defect: system default switchport nvgens twice') if
394
+ e.message[/Expected zero.one value/]
395
+ flunk(e.message)
396
+ end
397
+
398
+ def validate_description(inttype_h)
399
+ # Validate the description
400
+ inttype_h.each_value do |v|
401
+ interface = v[:interface]
402
+
403
+ # Check of description
404
+ assert_equal(v[:description], interface.description,
405
+ "Error: [#{interface.name}] Description is not configured")
406
+
407
+ # Change description
408
+ interface.description = v[:description_new]
409
+ assert_equal(v[:description_new], interface.description,
410
+ "Error: [#{interface.name}] Description is not changed")
411
+
412
+ # get_default check
413
+ assert_equal(v[:default_description], interface.default_description,
414
+ "Error: [#{interface.name}] Default description " \
415
+ 'is not configured')
416
+ end
417
+ end
418
+
419
+ def validate_get_access_vlan(inttype_h)
420
+ # Validate the collection
421
+ inttype_h.each_value do |v|
422
+ interface = v[:interface]
423
+ next if interface.name[/vlan|loopback/]
424
+ interface.switchport_mode = :access
425
+
426
+ assert_equal(v[:access_vlan], interface.access_vlan,
427
+ 'Error: Access vlan value not correct')
428
+
429
+ # get_default check
430
+ assert_equal(v[:default_access_vlan], interface.default_access_vlan,
431
+ 'Error: Access vlan, default, value not correct')
432
+ interface.switchport_mode = :disabled
433
+ end
434
+ end
435
+
436
+ def validate_ipv4_address(inttype_h)
437
+ # Validate the collection
438
+ inttype_h.each do |k, v|
439
+ interface = v[:interface]
440
+
441
+ # Verify existing value
442
+ address = v[:address_len].split('/').first
443
+ length = v[:address_len].split('/').last.to_i
444
+
445
+ pattern = ipv4_address_pattern(address, length)
446
+ assert_show_match(command: show_cmd(interface.name),
447
+ pattern: pattern)
448
+ assert_equal(address, interface.ipv4_address,
449
+ "Error: ipv4 address get value mismatch for #{k}")
450
+ assert_equal(length, interface.ipv4_netmask_length,
451
+ "Error: ipv4 netmask length get value mismatch for #{k}")
452
+
453
+ # Get default
454
+ assert_equal(DEFAULT_IF_IP_ADDRESS, interface.default_ipv4_address,
455
+ "Error: ipv4 address get default value mismatch for #{k}")
456
+
457
+ # get_default_netmask
458
+ assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
459
+ interface.default_ipv4_netmask_length,
460
+ "Error: ipv4 netmask length default mismatch for #{k}")
461
+
462
+ # Unconfigure ipaddress
463
+ interface.ipv4_addr_mask_set(interface.default_ipv4_address,
464
+ interface.default_ipv4_netmask_length)
465
+ refute_show_match(command: show_cmd(interface.name),
466
+ pattern: pattern,
467
+ msg: "ipv4 address still present in CLI for #{k}")
468
+ assert_equal(DEFAULT_IF_IP_ADDRESS, interface.ipv4_address,
469
+ "Error: ipv4 address value mismatch after unconfig for #{k}")
470
+ assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
471
+ interface.ipv4_netmask_length,
472
+ "Error: ipv4 netmask length default mismatch for #{k}")
473
+ end
474
+ end
475
+
476
+ def validate_ipv4_proxy_arp(inttype_h)
477
+ # Validate the collection
478
+ inttype_h.each do |k, v|
479
+ # Skipping loopback, proxy arp not supported
480
+ next if k == 'loopback0'
481
+
482
+ interface = v[:interface]
483
+ cmd = show_cmd(interface.name)
484
+
485
+ # puts "value - #{v[:proxy_arp]}"
486
+ if platform == :nexus
487
+ pattern = /^\s+ip proxy-arp/
488
+ elsif platform == :ios_xr
489
+ pattern = /^\s+proxy-arp/
490
+ end
491
+ if v[:proxy_arp]
492
+ assert_show_match(command: cmd, pattern: pattern)
493
+ else
494
+ refute_show_match(command: cmd, pattern: pattern)
495
+ end
496
+ assert_equal(v[:proxy_arp], interface.ipv4_proxy_arp,
497
+ "Error: ip proxy-arp get value 'true' mismatch")
498
+
499
+ # puts "value reverse- #{!v[:proxy_arp]}"
500
+ interface.ipv4_proxy_arp = !v[:proxy_arp]
501
+ if v[:proxy_arp]
502
+ refute_show_match(command: cmd, pattern: pattern)
503
+ else
504
+ assert_show_match(command: cmd, pattern: pattern)
505
+ end
506
+ assert_equal(!v[:proxy_arp], interface.ipv4_proxy_arp,
507
+ "Error: ip proxy-arp get value 'false' mismatch")
508
+
509
+ # Get default
510
+ assert_equal(DEFAULT_IF_IP_PROXY_ARP,
511
+ interface.default_ipv4_proxy_arp,
512
+ 'Error: ip proxy arp get default value mismatch')
513
+
514
+ # Get default and set
515
+ interface.ipv4_proxy_arp = interface.default_ipv4_proxy_arp
516
+ refute_show_match(command: cmd, pattern: pattern,
517
+ msg: 'Error: default ip proxy-arp set failed')
518
+ assert_equal(DEFAULT_IF_IP_PROXY_ARP,
519
+ interface.ipv4_proxy_arp,
520
+ 'Error: ip proxy-arp default get value mismatch')
521
+ end
522
+ end
523
+
524
+ def validate_ipv4_redirects(inttype_h)
525
+ # Validate the collection
526
+ inttype_h.each do |k, v|
527
+ interface = v[:interface]
528
+
529
+ if k.include?('loopback')
530
+ lookup_name = 'ipv4_redirects_loopback'
531
+ else
532
+ lookup_name = 'ipv4_redirects_other_interfaces'
533
+ end
534
+
535
+ ref = cmd_ref.lookup('interface', lookup_name)
536
+ assert(ref, 'Error, reference not found')
537
+
538
+ # Check default
539
+ assert_equal(ref.default_value, interface.default_ipv4_redirects,
540
+ "ipv4 redirects default incorrect for interface #{k}")
541
+
542
+ if ref.setter?
543
+ cmd = show_cmd(interface.name)
544
+ interface.ipv4_redirects = true
545
+ assert(interface.ipv4_redirects, "Couldn't set redirects to true")
546
+ refute_show_match(command: cmd, pattern: /^\s+no #{ipv4} redirects/)
547
+
548
+ interface.ipv4_redirects = false
549
+ refute(interface.ipv4_redirects, "Couldn't set redirects to false")
550
+ refute_show_match(command: cmd, pattern: /^#{ipv4} redirects/)
551
+ else
552
+ # Getter should return same value as default if setter isn't supported
553
+ assert_equal(interface.ipv4_redirects, interface.default_ipv4_redirects,
554
+ 'ipv4 redirects default incorrect')
555
+
556
+ # Make sure setter fails
557
+ assert_raises(Cisco::UnsupportedError) do
558
+ interface.ipv4_redirects = true
559
+ end
560
+ assert_raises(Cisco::UnsupportedError) do
561
+ interface.ipv4_redirects = false
562
+ end
563
+ end
564
+ end
565
+ end
566
+
567
+ def validate_vrf(inttype_h)
568
+ # Validate the vrf
569
+ inttype_h.each_value do |v|
570
+ interface = v[:interface]
571
+
572
+ # Change vrf
573
+ interface.vrf = v[:vrf_new]
574
+ assert_equal(v[:vrf_new], interface.vrf,
575
+ "Error: [#{interface.name}] vrf is not changed")
576
+
577
+ # Set to default vrf
578
+ assert_equal(v[:default_vrf], interface.default_vrf,
579
+ "Error: [#{interface.name}] vrf config found. " \
580
+ 'Should be default vrf')
581
+ end
582
+ end
583
+
584
+ def test_create_name_nil
585
+ assert_raises(TypeError) do
586
+ Interface.new(nil)
587
+ end
588
+ end
589
+
590
+ def test_create_name_invalid
591
+ assert_raises(TypeError) do
592
+ Interface.new(node)
593
+ end
594
+ end
595
+
596
+ def test_create_does_not_exist
597
+ assert_raises(CliError) do
598
+ Interface.new('bogus')
599
+ end
600
+ end
601
+
602
+ def test_create_valid
603
+ interface = Interface.new(interfaces[0])
604
+ assert_equal(interfaces[0].downcase, interface.name)
605
+ end
606
+
607
+ def test_description_nil
608
+ interface = Interface.new(interfaces[0])
609
+ assert_raises(TypeError) do
610
+ interface.description = nil
611
+ end
612
+ end
613
+
614
+ def test_description_zero_length
615
+ interface = Interface.new(interfaces[0])
616
+ interface.description = ''
617
+ assert_equal('', interface.description)
618
+ end
619
+
620
+ def test_description_valid
621
+ interface = Interface.new(interfaces[0])
622
+ description = 'This is a test description ! '
623
+ interface.description = description
624
+ assert_equal(description.rstrip, interface.description)
625
+ end
626
+
627
+ def test_encapsulation_dot1q
628
+ interface = Interface.new(interfaces[0])
629
+ interface.switchport_mode = :disabled if platform == :nexus
630
+ subif = Interface.new(interfaces[0] + '.1')
631
+ assert_raises(Cisco::CliError) { subif.encapsulation_dot1q = 'hello' }
632
+ subif.encapsulation_dot1q = 20
633
+ assert_equal(20, subif.encapsulation_dot1q)
634
+ subif.encapsulation_dot1q = 25
635
+ assert_equal(25, subif.encapsulation_dot1q)
636
+ subif.destroy
637
+ end
638
+
639
+ def test_bfd_echo
640
+ interface = Interface.new(interfaces[0])
641
+ if validate_property_excluded?('interface', 'bfd_echo')
642
+ assert_nil(interface.bfd_echo)
643
+ assert_raises(Cisco::UnsupportedError) { interface.bfd_echo = false }
644
+ return
645
+ end
646
+ interface.switchport_mode = :disabled
647
+ assert_equal(interface.default_bfd_echo,
648
+ interface.bfd_echo)
649
+ interface.bfd_echo = false
650
+ assert_equal(false, interface.bfd_echo)
651
+ interface.bfd_echo = interface.default_bfd_echo
652
+ assert_equal(interface.default_bfd_echo,
653
+ interface.bfd_echo)
654
+ # Clean up any stale config first
655
+ inf_name = "#{@port_channel}10"
656
+ Interface.new(inf_name).destroy
657
+
658
+ interface = Interface.new(inf_name)
659
+
660
+ # The newly created port-channel interface
661
+ # will default to switchport in some cases
662
+ # so we need to disable it.
663
+ interface.switchport_mode = :disabled
664
+ assert_equal(interface.default_bfd_echo,
665
+ interface.bfd_echo)
666
+ interface.bfd_echo = false
667
+ assert_equal(false, interface.bfd_echo)
668
+ interface.bfd_echo = interface.default_bfd_echo
669
+ assert_equal(interface.default_bfd_echo,
670
+ interface.bfd_echo)
671
+ end
672
+
673
+ def test_mtu_change
674
+ interface = Interface.new(interfaces[0])
675
+ interface.switchport_mode = :disabled
676
+ interface.mtu = 1520
677
+ assert_equal(1520, interface.mtu)
678
+ interface.mtu = 1580
679
+ assert_equal(1580, interface.mtu)
680
+ interface.mtu = interface.default_mtu
681
+ assert_equal(interface.default_mtu, interface.mtu)
682
+ end
683
+
684
+ def test_mtu_invalid
685
+ interface = Interface.new(interfaces[0])
686
+ interface.switchport_mode = :disabled
687
+ assert_raises(Cisco::CliError) { interface.mtu = 'hello' }
688
+ end
689
+
690
+ def test_mtu_valid
691
+ interface = Interface.new(interfaces[0])
692
+ interface.switchport_mode = :disabled
693
+ interface.mtu = 1550
694
+ assert_equal(1550, interface.mtu)
695
+ interface.mtu = interface.default_mtu
696
+ assert_equal(interface.default_mtu, interface.mtu)
697
+ end
698
+
699
+ def test_mtu_invalid_loopback
700
+ # Loopback interfaces don't permit MTU configuration
701
+ interface = Interface.new('loopback100')
702
+ assert_nil(interface.mtu)
703
+ assert_nil(interface.default_mtu)
704
+ assert_raises(Cisco::UnsupportedError) { interface.mtu = 1550 }
705
+ interface.destroy
706
+ end
707
+
708
+ def test_speed
709
+ skip_legacy_defect?('7.0.3.I5|7.0.3.F3', 'CSCvd41419')
710
+ interface = Interface.new(interfaces[0])
711
+ if validate_property_excluded?('interface', 'speed')
712
+ assert_nil(interface.speed)
713
+ assert_nil(interface.default_speed)
714
+ assert_raises(Cisco::UnsupportedError) { interface.speed = 1000 }
715
+ return
716
+ end
717
+
718
+ # Test invalid speed
719
+ assert_raises(RuntimeError, Cisco::CliError) { interface.speed = 'hello' }
720
+
721
+ # Test up to two non-default values
722
+ speed_values = capable_speed_values(interface)
723
+ warn("No valid speeds found on #{interface.name}") if speed_values.empty?
724
+ successful_runs = 0
725
+ speed_values.each do |value|
726
+ break if successful_runs >= 2
727
+ begin
728
+ interface.speed = value
729
+ assert_equal(value, interface.speed)
730
+ successful_runs += 1
731
+ rescue Cisco::CliError => e
732
+ # Many of the 'capable' speeds are actually not valid values
733
+ # Try next available speed value if CLI rejects current value
734
+ next if speed_change_disallowed?(e.message)
735
+ raise
736
+ end
737
+ end
738
+
739
+ # Test default speed value
740
+ interface.speed = interface.default_speed
741
+ assert_equal(interface.speed, interface.default_speed)
742
+ end
743
+
744
+ def test_duplex
745
+ skip_legacy_defect?('7.0.3.I5|7.0.3.F3', 'CSCvd41419')
746
+ interface = Interface.new(interfaces[0])
747
+ if validate_property_excluded?('interface', 'duplex')
748
+ assert_nil(interface.duplex)
749
+ assert_nil(interface.default_duplex)
750
+ assert_raises(Cisco::UnsupportedError) { interface.duplex = 'full' }
751
+ return
752
+ end
753
+
754
+ # Test invalid duplex
755
+ assert_raises(RuntimeError, Cisco::CliError) { interface.duplex = 'hello' }
756
+
757
+ # Ensure speed is non-auto value
758
+ if interface.default_speed == 'auto'
759
+ valid_speed = valid_speeds(interface).select { |v| v != 'auto' }.shift
760
+ skip('Cannot configure non-auto speed') if valid_speed.nil?
761
+ interface.speed = valid_speed
762
+ end
763
+
764
+ # Test non-default values
765
+ duplex_values = capable_duplex_values(interface)
766
+ warn("No valid duplex found on #{interface.name}") if duplex_values.empty?
767
+ duplex_values.each do |value|
768
+ interface.duplex = value
769
+ assert_equal(value, interface.duplex)
770
+ end
771
+
772
+ # Test default duplex value
773
+ interface.duplex = interface.default_duplex
774
+ assert_equal(interface.duplex, interface.default_duplex)
775
+ end
776
+
777
+ def test_shutdown_valid
778
+ interface = Interface.new(interfaces[0])
779
+ interface.shutdown = true
780
+ assert(interface.shutdown, 'Error: shutdown state is not true')
781
+
782
+ interface.shutdown = false
783
+ refute(interface.shutdown, 'Error: shutdown state is not false')
784
+ end
785
+
786
+ def test_svi_prop_nil_when_ethernet
787
+ intf = Interface.new(interfaces[0])
788
+ assert_nil(intf.svi_autostate,
789
+ 'Error: svi_autostate should be nil when interface is ethernet')
790
+ assert_nil(intf.svi_management,
791
+ 'Error: svi_management should be nil when interface is ethernet')
792
+ end
793
+
794
+ # def test_prefix_list_when_switchport
795
+ # interface = Interface.new(interfaces[0])
796
+ # interface.switchport_mode = :access
797
+ # addresses = interface.prefixes
798
+ # assert_empty(addresses)
799
+ # end
800
+ #
801
+ # def test_prefix_list_with_ipv4
802
+ # interface = Interface.new(interfaces[0])
803
+ # interface.switchport_mode = :access
804
+ # interface.switchport_mode = :disabled if platform == :nexus
805
+ # config("interface #{interfaces[0]}",
806
+ # 'ip address 192.168.1.100 255.255.255.0')
807
+ # prefixes = interface.prefixes
808
+ # assert_equal(1, prefixes.size)
809
+ # assert(prefixes.has_key?("192.168.1.100"))
810
+ # interface.switchport_mode = :access
811
+ # prefixes = nil
812
+ # end
813
+ #
814
+ # def test_prefix_list_with_ipv6
815
+ # interface = Interface.new(interfaces[0] )
816
+ # interface.switchport_mode = :access
817
+ # interface.switchport_mode = :disabled if platform == :nexus
818
+ # config("interface #{interfaces[0]}",
819
+ # 'ipv6 address fd56:31f7:e4ad:5585::1/64")
820
+ # prefixes = interface.prefixes
821
+ # assert_equal(2, prefixes.size)
822
+ # assert(prefixes.has_key?("fd56:31f7:e4ad:5585::1"))
823
+ # interface.switchport_mode = :access
824
+ # prefixes = nil
825
+ # end
826
+ #
827
+ # def test_prefix_list_with_ipv4_ipv6
828
+ # interface = Interface.new(interfaces[0])
829
+ # interface.switchport_mode = :access
830
+ # interface.switchport_mode = :disabled if platform == :nexus
831
+ # config("interface #{interfaces[0]}",
832
+ # 'ip address 192.168.1.100 255.255.255.0',
833
+ # 'ipv6 address fd56:31f7:e4ad:5585::1/64')
834
+ # prefixes = interface.prefixes
835
+ # assert_equal(3, prefixes.size)
836
+ # assert(prefixes.has_key?("192.168.1.100"))
837
+ # assert(prefixes.has_key?("fd56:31f7:e4ad:5585::1"))
838
+ # interface.switchport_mode = :access
839
+ # prefixes = nil
840
+ # end
841
+
842
+ def negotiate_auto_helper(interface, speed)
843
+ if validate_property_excluded?('interface',
844
+ interface.negotiate_auto_lookup_string)
845
+ assert_raises(Cisco::UnsupportedError) { interface.negotiate_auto = true }
846
+ return
847
+ end
848
+
849
+ # Note that 'speed' and 'negotiate auto' are tightly coupled
850
+ # When speed is 'auto', set negotiate auto to 'true'
851
+ # When speed is static value, turn off negotiate auto
852
+ interface.speed = speed
853
+ if speed == 'auto'
854
+ interface.negotiate_auto = true
855
+ assert(interface.negotiate_auto,
856
+ "#{interface.name} negotiate auto value should be true")
857
+ else
858
+ interface.negotiate_auto = false
859
+ refute(interface.negotiate_auto,
860
+ "#{interface.name} negotiate auto value should be false")
861
+ end
862
+ end
863
+
864
+ def test_negotiate_auto_portchannel
865
+ if validate_property_excluded?('interface_channel_group', 'channel_group')
866
+ member = InterfaceChannelGroup.new(interfaces[0])
867
+ assert_raises(Cisco::UnsupportedError) do
868
+ member.channel_group_mode_set(10)
869
+ end
870
+ return
871
+ end
872
+
873
+ # Clean up any stale config first
874
+ inf_name = "#{@port_channel}10"
875
+ Interface.new(inf_name).destroy
876
+
877
+ interface = Interface.new(inf_name)
878
+ if validate_property_excluded?('interface', 'negotiate_auto_portchannel')
879
+ assert_nil(interface.negotiate_auto)
880
+ assert_nil(interface.default_negotiate_auto)
881
+ assert_raises(Cisco::UnsupportedError) do
882
+ interface.negotiate_auto = false
883
+ end
884
+ else
885
+ @default_show_command = show_cmd(inf_name)
886
+
887
+ # Platforms raise error unless speed is properly configured first
888
+ speeds = valid_speeds(interface)
889
+ negotiate_auto_helper(interface, 'auto') if speeds.delete('auto')
890
+
891
+ non_auto = speeds.shift
892
+ negotiate_auto_helper(interface, non_auto) unless non_auto.nil?
893
+ end
894
+
895
+ # Cleanup
896
+ interface.destroy
897
+ end
898
+
899
+ def test_negotiate_auto_ethernet
900
+ # negotiate auto is LC dependent configuration.
901
+ # On some line cards it could fail with error for ex:
902
+ # Cisco::CliError: [interface ethernet8/1] The command 'no negotiate auto' was rejected with error:
903
+ # ERROR: Ethernet8/1: requested config change not allowed
904
+ skip_legacy_defect?('7.0.3.I5|7.0.3.F3', 'CSCvd41419')
905
+ inf_name = interfaces[0]
906
+ interface = Interface.new(inf_name)
907
+
908
+ if validate_property_excluded?('interface', 'negotiate_auto_ethernet')
909
+ assert_nil(interface.negotiate_auto)
910
+ assert_nil(interface.default_negotiate_auto)
911
+ assert_raises(Cisco::UnsupportedError) do
912
+ interface.negotiate_auto = false
913
+ end
914
+ return
915
+ end
916
+
917
+ @default_show_command = show_cmd(inf_name)
918
+
919
+ # Platforms raise error unless speed is properly configured first
920
+ speeds = valid_speeds(interface)
921
+ negotiate_auto_helper(interface, 'auto') if speeds.delete('auto')
922
+
923
+ non_auto = speeds.shift
924
+ negotiate_auto_helper(interface, non_auto) unless non_auto.nil?
925
+ end
926
+
927
+ def test_negotiate_auto_loopback
928
+ ref = cmd_ref.lookup('interface',
929
+ 'negotiate_auto_other_interfaces')
930
+ assert(ref, 'Error, reference not found')
931
+
932
+ int = 'loopback2'
933
+ config("interface #{int}")
934
+ interface = Interface.new(int)
935
+
936
+ assert_nil(interface.negotiate_auto)
937
+
938
+ assert_raises(Cisco::UnsupportedError) do
939
+ interface.negotiate_auto = true
940
+ end
941
+ assert_raises(Cisco::UnsupportedError) do
942
+ interface.negotiate_auto = false
943
+ end
944
+
945
+ # Cleanup
946
+ config("no interface #{int}")
947
+ end
948
+
949
+ def test_interfaces_not_empty
950
+ refute_empty(Interface.interfaces, 'Error: interfaces collection empty')
951
+ end
952
+
953
+ def test_ipv4_addr_mask_set_inv
954
+ interface = create_interface
955
+ interface.switchport_mode = :disabled if platform == :nexus
956
+ assert_raises(Cisco::CliError) do
957
+ interface.ipv4_addr_mask_set('', 14)
958
+ end
959
+ end
960
+
961
+ def test_ipv4_addr_mask_set_inv_mask
962
+ interface = create_interface
963
+ interface.switchport_mode = :disabled if platform == :nexus
964
+ assert_raises(Cisco::CliError) do
965
+ interface.ipv4_addr_mask_set('8.1.1.2', DEFAULT_IF_IP_NETMASK_LEN)
966
+ end
967
+ end
968
+
969
+ def test_ipv4_acl
970
+ # Sample cli:
971
+ #
972
+ # interface Ethernet1/1
973
+ # ip access-group v4acl1 in
974
+ # ip access-group v4acl2 out
975
+ #
976
+
977
+ # create acls first
978
+ %w(v4acl1 v4acl2 v4acl3 v4acl4).each do |acl_name|
979
+ if platform == :nexus
980
+ Acl.new('ipv4', acl_name)
981
+ else
982
+ # TODO: Acl is not yet supported on XR
983
+ config("ipv4 access-list #{acl_name} 1 permit any")
984
+ end
985
+ end
986
+ intf = Interface.new(interfaces[0])
987
+
988
+ intf.ipv4_acl_in = 'v4acl1'
989
+ assert_equal('v4acl1', intf.ipv4_acl_in)
990
+ intf.ipv4_acl_out = 'v4acl2'
991
+ assert_equal('v4acl2', intf.ipv4_acl_out)
992
+
993
+ intf.ipv4_acl_in = 'v4acl3'
994
+ assert_equal('v4acl3', intf.ipv4_acl_in)
995
+ intf.ipv4_acl_out = 'v4acl4'
996
+ assert_equal('v4acl4', intf.ipv4_acl_out)
997
+
998
+ intf.ipv4_acl_in = intf.default_ipv4_acl_in
999
+ assert_equal('', intf.ipv4_acl_in)
1000
+ intf.ipv4_acl_out = intf.default_ipv4_acl_out
1001
+ assert_equal('', intf.ipv4_acl_out)
1002
+
1003
+ # delete acls
1004
+ %w(v4acl1 v4acl2 v4acl3 v4acl4).each do |acl_name|
1005
+ config("no #{ipv4} access-list #{acl_name}")
1006
+ end
1007
+ end
1008
+
1009
+ def test_ipv6_acl
1010
+ # Sample cli:
1011
+ #
1012
+ # interface Ethernet1/1
1013
+ # ipv6 traffic-filter v6acl1 in
1014
+ # ipv6 traffic-filter v6acl2 out
1015
+ #
1016
+ intf = Interface.new(interfaces[0])
1017
+
1018
+ # create acls first
1019
+ %w(v6acl1 v6acl2 v6acl3 v6acl4).each do |acl_name|
1020
+ if platform == :nexus
1021
+ Acl.new('ipv6', acl_name)
1022
+ else
1023
+ # TODO: Acl is not yet supported on XR
1024
+ config("ipv6 access-list #{acl_name} 1 permit any any")
1025
+ end
1026
+ end
1027
+
1028
+ intf.ipv6_acl_in = 'v6acl1'
1029
+ assert_equal('v6acl1', intf.ipv6_acl_in)
1030
+ intf.ipv6_acl_out = 'v6acl2'
1031
+ assert_equal('v6acl2', intf.ipv6_acl_out)
1032
+
1033
+ intf.ipv6_acl_in = 'v6acl3'
1034
+ assert_equal('v6acl3', intf.ipv6_acl_in)
1035
+ intf.ipv6_acl_out = 'v6acl4'
1036
+ assert_equal('v6acl4', intf.ipv6_acl_out)
1037
+
1038
+ intf.ipv6_acl_in = intf.default_ipv6_acl_in
1039
+ assert_equal('', intf.ipv6_acl_in)
1040
+ intf.ipv6_acl_out = intf.default_ipv6_acl_out
1041
+ assert_equal('', intf.ipv6_acl_out)
1042
+
1043
+ # delete acls
1044
+ %w(v6acl1 v6acl2 v6acl3 v6acl4).each do |acl_name|
1045
+ config('no ipv6 access-list ' + acl_name)
1046
+ end
1047
+ end
1048
+
1049
+ def test_ipv4_address
1050
+ interface = create_interface
1051
+ interface.switchport_mode = :disabled if platform == :nexus
1052
+ address = '8.7.1.1'
1053
+ sec_addr = '10.5.5.1'
1054
+ secondary = true
1055
+ length = 15
1056
+
1057
+ # Primary: setter, getter
1058
+ interface.ipv4_addr_mask_set(address, length)
1059
+ pattern = ipv4_address_pattern(address, length)
1060
+ assert_show_match(pattern: pattern,
1061
+ msg: 'Error: ipv4 address missing in CLI')
1062
+ assert_equal(address, interface.ipv4_address,
1063
+ 'Error: ipv4 address get value mismatch')
1064
+ assert_equal(length, interface.ipv4_netmask_length,
1065
+ 'Error: ipv4 netmask length get value mismatch')
1066
+
1067
+ # Secondary: setter, getter
1068
+ interface.ipv4_addr_mask_set(sec_addr, length, secondary)
1069
+ pattern = ipv4_address_pattern(sec_addr, length, secondary)
1070
+ assert_show_match(pattern: pattern,
1071
+ msg: 'Error: ipv4 address missing in CLI')
1072
+ assert_equal(sec_addr, interface.ipv4_address_secondary,
1073
+ 'Error: ipv4 address get value mismatch')
1074
+ assert_equal(length, interface.ipv4_netmask_length_secondary,
1075
+ 'Error: ipv4 netmask length get value mismatch')
1076
+
1077
+ # get default
1078
+ assert_equal(DEFAULT_IF_IP_ADDRESS, interface.default_ipv4_address,
1079
+ 'Error: ipv4 address get default value mismatch')
1080
+
1081
+ # get_default_netmask
1082
+ assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
1083
+ interface.default_ipv4_netmask_length,
1084
+ 'Error: ipv4 netmask length get default value mismatch')
1085
+
1086
+ # unconfigure ipaddress - secondary must be removed first
1087
+ interface.ipv4_addr_mask_set(interface.default_ipv4_address, length,
1088
+ secondary)
1089
+ interface.ipv4_addr_mask_set(interface.default_ipv4_address, length)
1090
+ # unconfigure should be safely idempotent
1091
+ interface.ipv4_addr_mask_set(interface.default_ipv4_address, length,
1092
+ secondary)
1093
+ interface.ipv4_addr_mask_set(interface.default_ipv4_address, length)
1094
+ pattern = (/^\s+ip(v4)? address (.*)/)
1095
+ refute_show_match(pattern: pattern,
1096
+ msg: 'Error: ipv4 address still present in CLI')
1097
+ assert_equal(DEFAULT_IF_IP_ADDRESS, interface.ipv4_address,
1098
+ 'Error: ipv4 address value mismatch after unconfig')
1099
+ assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
1100
+ interface.ipv4_netmask_length,
1101
+ 'Error: ipv4 netmask length default get value mismatch')
1102
+ end
1103
+
1104
+ def test_ipv4_addr_preconfig
1105
+ address = '8.7.1.1'
1106
+ length = 15
1107
+ ifname = interfaces[0]
1108
+ # preconfigure
1109
+ interface_ipv4_config(ifname, address, length)
1110
+ # create interface
1111
+ interface = create_interface(ifname)
1112
+ # getter
1113
+ assert_equal(address, interface.ipv4_address,
1114
+ 'Error: ipv4 address get value mismatch')
1115
+ assert_equal(length, interface.ipv4_netmask_length,
1116
+ 'Error: ipv4 netmask length get value mismatch')
1117
+ # unconfigure ipaddress
1118
+ interface_ipv4_config(ifname, address, length, false)
1119
+ end
1120
+
1121
+ def test_ipv4_addr_preconfig_sec
1122
+ address = '8.7.1.1'
1123
+ length = 15
1124
+ sec_address = '1.1.2.5'
1125
+ sec_length = 10
1126
+ ifname = interfaces[0]
1127
+ # preconfigure primary and secondary
1128
+ interface_ipv4_config(ifname, address, length)
1129
+ interface_ipv4_config(ifname, sec_address, sec_length, true, true)
1130
+
1131
+ # create interface
1132
+ interface = create_interface(ifname)
1133
+ # getter
1134
+ assert_equal(address, interface.ipv4_address,
1135
+ 'Error: ipv4 address get value mismatch')
1136
+ assert_equal(length, interface.ipv4_netmask_length,
1137
+ 'Error: ipv4 netmask length get value mismatch')
1138
+ # unconfigure ipaddress includign secondary
1139
+ interface_ipv4_config(ifname, address, length, false, false)
1140
+ end
1141
+
1142
+ def test_ipv4_arp_timeout
1143
+ unless platform == :ios_xr
1144
+ # Setup
1145
+ config_no_warn('no interface vlan11')
1146
+ svi = Interface.new('vlan11')
1147
+
1148
+ # Test default
1149
+ assert_equal(svi.default_ipv4_arp_timeout, svi.ipv4_arp_timeout)
1150
+ # Test non-default
1151
+ svi.ipv4_arp_timeout = 300
1152
+ assert_equal(300, svi.ipv4_arp_timeout)
1153
+ # Set back to default
1154
+ svi.ipv4_arp_timeout = svi.default_ipv4_arp_timeout
1155
+ assert_equal(svi.default_ipv4_arp_timeout, svi.ipv4_arp_timeout)
1156
+ end
1157
+ # Attempt to configure on a non-vlan interface
1158
+ nonsvi = create_interface
1159
+ assert_raises(RuntimeError) { nonsvi.ipv4_arp_timeout = 300 }
1160
+ end
1161
+
1162
+ def test_ipv4_forwarding
1163
+ intf = interfaces[0]
1164
+ i = Interface.new(intf)
1165
+
1166
+ if platform == :ios_xr
1167
+ assert_nil(i.default_ipv4_forwarding)
1168
+ assert_nil(i.ipv4_forwarding)
1169
+ assert_raises(Cisco::UnsupportedError) { i.ipv4_forwarding = false }
1170
+ return
1171
+ end
1172
+
1173
+ assert_equal(i.default_ipv4_forwarding, i.ipv4_forwarding)
1174
+ begin
1175
+ i.switchport_mode = :disabled
1176
+ i.ipv4_forwarding = true
1177
+ rescue RuntimeError, CliError => e
1178
+ # RuntimeError when switchport_mode fails (some lc's, e.g. N7K-F248XP-25E)
1179
+ # CliError when ipv4_forwarding fails
1180
+ interface_supports_property?(intf, e.message)
1181
+ end
1182
+ assert(i.ipv4_forwarding)
1183
+
1184
+ i.ipv4_forwarding = false
1185
+ refute(i.ipv4_forwarding)
1186
+
1187
+ i.ipv4_forwarding = true
1188
+ assert(i.ipv4_forwarding)
1189
+ i.ipv4_forwarding = i.default_ipv4_forwarding
1190
+ assert_equal(i.default_ipv4_forwarding, i.ipv4_forwarding)
1191
+ end
1192
+
1193
+ def test_ff_anycast_gateway_mac
1194
+ # Ensure N7k has compatible interface
1195
+ mt_full_interface? if node.product_id[/N7/]
1196
+
1197
+ if validate_property_excluded?('overlay_global', 'anycast_gateway_mac')
1198
+ assert_raises(Cisco::UnsupportedError) do
1199
+ OverlayGlobal.new.anycast_gateway_mac = '1223.3445.5668'
1200
+ end
1201
+ return
1202
+ end
1203
+ if validate_property_excluded?('interface',
1204
+ 'fabric_forwarding_anycast_gateway')
1205
+ int = Interface.new('vlan11')
1206
+ OverlayGlobal.new.anycast_gateway_mac = '1223.3445.5668'
1207
+ assert_raises(Cisco::UnsupportedError) do
1208
+ int.fabric_forwarding_anycast_gateway = true
1209
+ end
1210
+ return
1211
+ end
1212
+
1213
+ # Setup
1214
+ config_no_warn('no interface vlan11')
1215
+ int = Interface.new('vlan11')
1216
+ foo = OverlayGlobal.new
1217
+ foo.anycast_gateway_mac = '1223.3445.5668'
1218
+
1219
+ # 1. Testing default for newly created vlan
1220
+ assert_equal(int.default_fabric_forwarding_anycast_gateway,
1221
+ int.fabric_forwarding_anycast_gateway)
1222
+
1223
+ # 2. Testing non-default:true
1224
+ int.fabric_forwarding_anycast_gateway = true
1225
+ assert(int.fabric_forwarding_anycast_gateway)
1226
+
1227
+ # 3. Setting back to false
1228
+ int.fabric_forwarding_anycast_gateway = false
1229
+ refute(int.fabric_forwarding_anycast_gateway)
1230
+
1231
+ # 4. Attempt to configure on a non-vlan interface
1232
+ nonvlanint = create_interface
1233
+ assert_raises(RuntimeError) do
1234
+ nonvlanint.fabric_forwarding_anycast_gateway = true
1235
+ end
1236
+
1237
+ # 5. Attempt to set 'fabric forwarding anycast gateway' while the
1238
+ # overlay gateway mac is not set.
1239
+ int.destroy
1240
+ int = Interface.new('vlan11')
1241
+ bar = OverlayGlobal.new
1242
+ bar.anycast_gateway_mac = bar.default_anycast_gateway_mac
1243
+ assert_raises(RuntimeError) do
1244
+ int.fabric_forwarding_anycast_gateway = true
1245
+ end
1246
+ end
1247
+
1248
+ def test_ipv4_proxy_arp
1249
+ interface = create_interface
1250
+ interface.switchport_mode = :disabled if platform == :nexus
1251
+
1252
+ # set with value true
1253
+ interface.ipv4_proxy_arp = true
1254
+ if platform == :nexus
1255
+ pattern = /^\s+ip proxy-arp/
1256
+ elsif platform == :ios_xr
1257
+ pattern = /^\s+proxy-arp/
1258
+ end
1259
+ assert_show_match(pattern: pattern,
1260
+ msg: 'Error: ip proxy-arp enable missing in CLI')
1261
+ assert(interface.ipv4_proxy_arp,
1262
+ "Error: ip proxy-arp get value 'true' mismatch")
1263
+
1264
+ # set with value false
1265
+ interface.ipv4_proxy_arp = false
1266
+ refute_show_match(pattern: pattern,
1267
+ msg: 'Error: ip proxy-arp disable missing in CLI')
1268
+ refute(interface.ipv4_proxy_arp,
1269
+ "Error: ip proxy-arp get value 'false' mismatch")
1270
+
1271
+ # get default
1272
+ assert_equal(DEFAULT_IF_IP_PROXY_ARP,
1273
+ interface.default_ipv4_proxy_arp,
1274
+ 'Error: ip proxy arp get default value mismatch')
1275
+
1276
+ # get default and set
1277
+ interface.ipv4_proxy_arp = interface.default_ipv4_proxy_arp
1278
+ refute_show_match(pattern: pattern,
1279
+ msg: 'Error: default ip proxy-arp set failed')
1280
+ assert_equal(DEFAULT_IF_IP_PROXY_ARP,
1281
+ interface.ipv4_proxy_arp,
1282
+ 'Error: ip proxy-arp default get value mismatch')
1283
+ end
1284
+
1285
+ def test_ipv4_redirects
1286
+ interface = create_interface
1287
+ interface.switchport_mode = :disabled if platform == :nexus
1288
+
1289
+ ref = cmd_ref.lookup('interface', 'ipv4_redirects_other_interfaces')
1290
+ assert(ref, 'Error, reference not found')
1291
+
1292
+ # check default value
1293
+ assert_equal(interface.default_ipv4_redirects, interface.ipv4_redirects,
1294
+ 'Error: ip redirects default get value mismatch')
1295
+
1296
+ # set with value false
1297
+ interface.ipv4_redirects = false
1298
+ if interface.default_ipv4_redirects == true
1299
+ assert_show_match(pattern: /^\s+no #{ipv4} redirects/,
1300
+ msg: 'Error: ip redirects disable missing in CLI')
1301
+ end
1302
+ refute_show_match(pattern: /^\s+#{ipv4} redirects/)
1303
+ refute(interface.ipv4_redirects,
1304
+ "Error: ip redirects get value 'false' mismatch")
1305
+
1306
+ # set with value true
1307
+ interface.ipv4_redirects = true
1308
+ if interface.default_ipv4_redirects == false
1309
+ assert_show_match(pattern: /^\s+#{ipv4} redirects/)
1310
+ end
1311
+ refute_show_match(pattern: /^\s+no #{ipv4} redirects/,
1312
+ msg: 'Error: ip redirects enable missing in CLI')
1313
+ assert(interface.ipv4_redirects,
1314
+ "Error: ip redirects get value 'true' mismatch")
1315
+
1316
+ # get default and set
1317
+ interface.ipv4_redirects = interface.default_ipv4_redirects
1318
+ if interface.default_ipv4_redirects
1319
+ pat = /^\s+no #{ipv4} redirects/
1320
+ else
1321
+ pat = /^\s+#{ipv4} redirects/
1322
+ end
1323
+ refute_show_match(pattern: pat,
1324
+ msg: 'Error: default ip redirects set failed')
1325
+ assert_equal(interface.default_ipv4_redirects, interface.ipv4_redirects,
1326
+ 'Error: ip redirects default get value mismatch')
1327
+ end
1328
+
1329
+ def test_ipv6_redirects
1330
+ interface = create_interface
1331
+ interface.switchport_mode = :disabled if platform == :nexus
1332
+
1333
+ # check default value
1334
+ assert_equal(interface.default_ipv6_redirects, interface.ipv6_redirects,
1335
+ 'Error: ipv6 redirects default get value mismatch')
1336
+
1337
+ # set with value false
1338
+ interface.ipv6_redirects = false
1339
+ assert_equal(interface.ipv6_redirects, false)
1340
+
1341
+ # set with value true
1342
+ interface.ipv6_redirects = true
1343
+ assert_equal(interface.ipv6_redirects, true)
1344
+
1345
+ # get default and set
1346
+ interface.ipv6_redirects = interface.default_ipv6_redirects
1347
+ assert_equal(interface.ipv6_redirects, interface.default_ipv6_redirects)
1348
+ end
1349
+
1350
+ def config_from_hash(inttype_h)
1351
+ inttype_h.each do |k, v|
1352
+ config('feature interface-vlan') if (/^Vlan\d./).match(k.to_s)
1353
+
1354
+ cfg = ["interface #{k}"]
1355
+
1356
+ switchport_intfs = Regexp.union(/ethernet/i, @port_channel)
1357
+ cfg << 'no switchport' if platform == :nexus && k =~ switchport_intfs
1358
+
1359
+ cfg << "#{ipv4} address #{v[:address_len]}" unless v[:address_len].nil?
1360
+ if platform == :nexus
1361
+ cfg << 'ip proxy-arp' if v[:proxy_arp]
1362
+ elsif platform == :ios_xr
1363
+ cfg << 'proxy-arp' if v[:proxy_arp]
1364
+ end
1365
+ cfg << '#{ipv4} redirects' if v[:redirects]
1366
+ cfg << "description #{v[:description]}" unless v[:description].nil?
1367
+ config(*cfg)
1368
+
1369
+ # Create an Interface instance and associate it
1370
+ v[:interface] = Interface.new(k, false)
1371
+ end
1372
+ inttype_h
1373
+ end
1374
+
1375
+ def interface_test_data
1376
+ inttype_h = {}
1377
+ inttype_h[interfaces[0]] = {
1378
+ address_len: '8.7.1.1/15',
1379
+ proxy_arp: true,
1380
+ redirects: false,
1381
+ description: 'This is a test',
1382
+ description_new: 'Testing Testing',
1383
+ default_description: DEFAULT_IF_DESCRIPTION,
1384
+ shutdown: false,
1385
+ change_shutdown: true,
1386
+ default_shutdown: false,
1387
+ switchport: platform == :ios_xr ? nil : :disabled,
1388
+ default_switchport: platform == :ios_xr ? nil : :disabled,
1389
+ access_vlan: DEFAULT_IF_ACCESS_VLAN,
1390
+ default_access_vlan: DEFAULT_IF_ACCESS_VLAN,
1391
+ vrf_new: 'test2',
1392
+ default_vrf: DEFAULT_IF_VRF,
1393
+ }
1394
+ unless platform == :ios_xr
1395
+ inttype_h['Vlan45'] = {
1396
+ address_len: '9.7.1.1/15',
1397
+ proxy_arp: true,
1398
+ redirects: false,
1399
+ description: 'Company A',
1400
+ description_new: 'Mini Me',
1401
+ default_description: DEFAULT_IF_DESCRIPTION,
1402
+ shutdown: true,
1403
+ change_shutdown: false,
1404
+ default_shutdown: true,
1405
+ switchport: :disabled,
1406
+ default_switchport: :disabled,
1407
+ vrf_new: 'test2',
1408
+ default_vrf: DEFAULT_IF_VRF,
1409
+ }
1410
+ end
1411
+ inttype_h["#{@port_channel}48"] = {
1412
+ address_len: '10.7.1.1/15',
1413
+ proxy_arp: false,
1414
+ redirects: false,
1415
+ description: 'Company B',
1416
+ description_new: 'Dr. Bond',
1417
+ default_description: DEFAULT_IF_DESCRIPTION,
1418
+ shutdown: false,
1419
+ change_shutdown: true,
1420
+ default_shutdown: false,
1421
+ switchport: platform == :ios_xr ? nil : :disabled,
1422
+ default_switchport: platform == :ios_xr ? nil : :disabled,
1423
+ access_vlan: DEFAULT_IF_ACCESS_VLAN,
1424
+ default_access_vlan: DEFAULT_IF_ACCESS_VLAN,
1425
+ vrf_new: 'test2',
1426
+ default_vrf: DEFAULT_IF_VRF,
1427
+ }
1428
+ inttype_h['loopback0'] = {
1429
+ address_len: '11.7.1.1/15',
1430
+ redirects: false, # (not supported on loopback)
1431
+ description: '233KLDK',
1432
+ description_new: 'Back to the Future',
1433
+ default_description: DEFAULT_IF_DESCRIPTION,
1434
+ shutdown: false,
1435
+ change_shutdown: true,
1436
+ default_shutdown: false,
1437
+ switchport: platform == :ios_xr ? nil : :disabled,
1438
+ default_switchport: platform == :ios_xr ? nil : :disabled,
1439
+ vrf_new: 'test2',
1440
+ default_vrf: DEFAULT_IF_VRF,
1441
+ }
1442
+ # Skipping mgmt0 interface since that interface is our 'path' to
1443
+ # master should revisit this later
1444
+ inttype_h
1445
+ end
1446
+
1447
+ # NOTE - Changes to this method may require new validation methods
1448
+ # to be created or existing ones to be modified.
1449
+ def test_ipv4_all_interfaces
1450
+ inttype_h = interface_test_data
1451
+
1452
+ # Set system defaults to "factory" values prior to initial test.
1453
+ config(*
1454
+ @switchport_shutdown_hash['shutdown_ethernet_noswitchport_shutdown'])
1455
+
1456
+ # pre-configure
1457
+ begin
1458
+ interface_ethernet_default(interfaces[1])
1459
+ InterfaceChannelGroup.new(interfaces[1]).channel_group_mode_set(48)
1460
+ rescue Cisco::UnsupportedError
1461
+ raise unless platform == :ios_xr
1462
+ # Some XR platform/version combos don't support port-channels
1463
+ inttype_h.delete("#{@port_channel}48")
1464
+ end
1465
+
1466
+ inttype_h = config_from_hash(inttype_h)
1467
+
1468
+ # Steps to cleanup the preload configuration
1469
+ cfg = []
1470
+ inttype_h.each_key do |k|
1471
+ if /ethernet/.match(k)
1472
+ # leave interface there, but unconfigure it
1473
+ cfg.push(*get_interface_cleanup_config(k))
1474
+ else
1475
+ # remove interface
1476
+ cfg << "no interface #{k}"
1477
+ end
1478
+ end
1479
+ cfg << 'no feature interface-vlan' unless platform == :ios_xr
1480
+
1481
+ begin
1482
+ # Validate the collection
1483
+ validate_interfaces_not_empty
1484
+ validate_get_switchport(inttype_h)
1485
+ validate_description(inttype_h)
1486
+ validate_ipv4_address(inttype_h)
1487
+ validate_ipv4_proxy_arp(inttype_h)
1488
+ validate_ipv4_redirects(inttype_h)
1489
+ validate_interface_shutdown(inttype_h)
1490
+ validate_vrf(inttype_h)
1491
+ validate_get_access_vlan(inttype_h) unless platform == :ios_xr
1492
+ config(*cfg)
1493
+ interface_ethernet_default(interfaces[1])
1494
+ rescue Minitest::Assertion
1495
+ # clean up before failing
1496
+ config(*cfg)
1497
+ interface_ethernet_default(interfaces[1])
1498
+ raise
1499
+ end
1500
+ end
1501
+
1502
+ def test_vrf_default
1503
+ interface = Interface.new('loopback1')
1504
+ assert_empty(interface.vrf)
1505
+ interface.vrf = 'foo'
1506
+ assert_equal(interface.vrf, 'foo')
1507
+ interface.vrf = interface.default_vrf
1508
+ assert_equal(interface.vrf, interface.default_vrf)
1509
+ end
1510
+
1511
+ def test_vrf_invalid_type
1512
+ interface = Interface.new('loopback1')
1513
+ assert_raises(TypeError) { interface.vrf = 1 }
1514
+ end
1515
+
1516
+ def test_vrf_exceeds_max_length
1517
+ interface = Interface.new('loopback1')
1518
+ long_string = 'a' * (IF_VRF_MAX_LENGTH + 1)
1519
+ assert_raises(Cisco::CliError) { interface.vrf = long_string }
1520
+ end
1521
+
1522
+ def test_vrf_override
1523
+ interface = Interface.new('loopback1')
1524
+ vrf1 = 'test1'
1525
+ vrf2 = 'test2'
1526
+ interface.vrf = vrf1
1527
+ interface.vrf = vrf2
1528
+ assert_equal(vrf2, interface.vrf)
1529
+ interface.destroy
1530
+ end
1531
+
1532
+ def test_vrf_valid
1533
+ interface = Interface.new('loopback1')
1534
+ vrf = 'test'
1535
+ interface.vrf = vrf
1536
+ assert_equal(vrf, interface.vrf)
1537
+ interface.destroy
1538
+ end
1539
+
1540
+ def test_vrf_change_with_ip_addr
1541
+ interface = Interface.new('loopback1')
1542
+ address = '192.168.100.1'
1543
+ length = 24
1544
+ interface_ipv4_config('loopback1', address, length)
1545
+ assert_equal(address, interface.ipv4_address)
1546
+ assert_equal(length, interface.ipv4_netmask_length)
1547
+
1548
+ vrf1 = 'test1'
1549
+ interface.vrf = vrf1
1550
+ assert_equal(address, interface.ipv4_address,
1551
+ 'IPv4 address wrong after changing from vrf default => test1')
1552
+ assert_equal(length, interface.ipv4_netmask_length,
1553
+ 'IPv4 mask wrong after changing from vrf default => test1')
1554
+ assert_equal(vrf1, interface.vrf)
1555
+
1556
+ vrf2 = 'test2'
1557
+ interface.vrf = vrf2
1558
+ assert_equal(address, interface.ipv4_address,
1559
+ 'IPv4 address wrong after changing from vrf test1 => test2')
1560
+ assert_equal(length, interface.ipv4_netmask_length,
1561
+ 'IPv4 mask wrong after changing from vrf test1 => test2')
1562
+ assert_equal(vrf2, interface.vrf)
1563
+
1564
+ interface.vrf = DEFAULT_IF_VRF
1565
+ assert_equal(address, interface.ipv4_address,
1566
+ 'IPv4 address wrong after changing from vrf test2 => default')
1567
+ assert_equal(length, interface.ipv4_netmask_length,
1568
+ 'IPv4 mask wrong after changing from vrf test2 => default')
1569
+ assert_equal(DEFAULT_IF_VRF, interface.vrf)
1570
+ end
1571
+
1572
+ def test_ipv4_pim_sparse_mode
1573
+ config('no feature pim') if platform == :nexus
1574
+ i = Interface.new(interfaces[0])
1575
+ if platform == :ios_xr
1576
+ assert_nil(i.ipv4_pim_sparse_mode)
1577
+ assert_nil(i.default_ipv4_pim_sparse_mode)
1578
+ assert_raises(Cisco::UnsupportedError) { i.ipv4_pim_sparse_mode = true }
1579
+ return
1580
+ end
1581
+ begin
1582
+ i.switchport_mode = :disabled
1583
+ rescue Cisco::CliError => e
1584
+ skip_message = 'Interface does not support switchport disable'
1585
+ skip(skip_message) if e.message['requested config change not allowed']
1586
+ raise
1587
+ end
1588
+ # Sample cli:
1589
+ #
1590
+ # interface Ethernet1/1
1591
+ # ip pim sparse-mode
1592
+ #
1593
+ i.ipv4_pim_sparse_mode = false
1594
+ refute(i.ipv4_pim_sparse_mode)
1595
+
1596
+ i.ipv4_pim_sparse_mode = true
1597
+ assert(i.ipv4_pim_sparse_mode)
1598
+
1599
+ i.ipv4_pim_sparse_mode = i.default_ipv4_pim_sparse_mode
1600
+ assert_equal(i.default_ipv4_pim_sparse_mode, i.ipv4_pim_sparse_mode)
1601
+ end
1602
+
1603
+ def test_storm_control_broadcast
1604
+ interface = Interface.new(interfaces[0])
1605
+ interface.switchport_enable(true)
1606
+ if validate_property_excluded?('interface', 'storm_control_broadcast')
1607
+ assert_nil(interface.storm_control_broadcast)
1608
+ assert_raises(Cisco::UnsupportedError) do
1609
+ interface.storm_control_broadcast = '20.12'
1610
+ end
1611
+ return
1612
+ end
1613
+ assert_equal(interface.default_storm_control_broadcast,
1614
+ interface.storm_control_broadcast)
1615
+ interface.storm_control_broadcast = '20.12'
1616
+ assert_equal('20.12', interface.storm_control_broadcast)
1617
+ interface.storm_control_broadcast =
1618
+ interface.default_storm_control_broadcast
1619
+ assert_equal(interface.default_storm_control_broadcast,
1620
+ interface.storm_control_broadcast)
1621
+ end
1622
+
1623
+ def test_storm_control_multicast
1624
+ interface = Interface.new(interfaces[0])
1625
+ interface.switchport_enable(true)
1626
+ if validate_property_excluded?('interface', 'storm_control_multicast')
1627
+ assert_nil(interface.storm_control_multicast)
1628
+ assert_raises(Cisco::UnsupportedError) do
1629
+ interface.storm_control_multicast = '33.33'
1630
+ end
1631
+ return
1632
+ end
1633
+ assert_equal(interface.default_storm_control_multicast,
1634
+ interface.storm_control_multicast)
1635
+ interface.storm_control_multicast = '33.33'
1636
+ assert_equal('33.33', interface.storm_control_multicast)
1637
+ interface.storm_control_multicast =
1638
+ interface.default_storm_control_multicast
1639
+ assert_equal(interface.default_storm_control_multicast,
1640
+ interface.storm_control_multicast)
1641
+ end
1642
+
1643
+ def test_storm_control_unicast
1644
+ interface = Interface.new(interfaces[0])
1645
+ interface.switchport_enable(true)
1646
+ if validate_property_excluded?('interface', 'storm_control_unicast')
1647
+ assert_nil(interface.storm_control_unicast)
1648
+ assert_raises(Cisco::UnsupportedError) do
1649
+ interface.storm_control_unicast = '44.44'
1650
+ end
1651
+ return
1652
+ end
1653
+ assert_equal(interface.default_storm_control_unicast,
1654
+ interface.storm_control_unicast)
1655
+ interface.storm_control_unicast = '44.44'
1656
+ assert_equal('44.44', interface.storm_control_unicast)
1657
+ interface.storm_control_unicast =
1658
+ interface.default_storm_control_unicast
1659
+ assert_equal(interface.default_storm_control_unicast,
1660
+ interface.storm_control_unicast)
1661
+ end
1662
+
1663
+ def test_ipv4_dhcp_relay_addr
1664
+ interface = Interface.new(interfaces[0])
1665
+ interface.switchport_enable(false)
1666
+ list = ['1.1.1.1', '2.2.2.2']
1667
+ if validate_property_excluded?('interface', 'ipv4_dhcp_relay_addr')
1668
+ assert_nil(interface.ipv4_dhcp_relay_addr)
1669
+ assert_raises(Cisco::UnsupportedError) do
1670
+ interface.ipv4_dhcp_relay_addr = list
1671
+ end
1672
+ return
1673
+ end
1674
+ assert_equal(interface.default_ipv4_dhcp_relay_addr,
1675
+ interface.ipv4_dhcp_relay_addr)
1676
+ interface.ipv4_dhcp_relay_addr = list
1677
+ assert_equal(list, interface.ipv4_dhcp_relay_addr)
1678
+ interface.ipv4_dhcp_relay_addr =
1679
+ interface.default_ipv4_dhcp_relay_addr
1680
+ assert_equal(interface.default_ipv4_dhcp_relay_addr,
1681
+ interface.ipv4_dhcp_relay_addr)
1682
+ end
1683
+
1684
+ def test_ipv4_dhcp_relay_info_trust
1685
+ interface = Interface.new(interfaces[0])
1686
+ interface.switchport_enable(false)
1687
+ if validate_property_excluded?('interface', 'ipv4_dhcp_relay_info_trust')
1688
+ assert_nil(interface.ipv4_dhcp_relay_info_trust)
1689
+ assert_raises(Cisco::UnsupportedError) do
1690
+ interface.ipv4_dhcp_relay_info_trust = true
1691
+ end
1692
+ return
1693
+ end
1694
+ assert_equal(interface.default_ipv4_dhcp_relay_info_trust,
1695
+ interface.ipv4_dhcp_relay_info_trust)
1696
+ interface.ipv4_dhcp_relay_info_trust = true
1697
+ assert_equal(true, interface.ipv4_dhcp_relay_info_trust)
1698
+ interface.ipv4_dhcp_relay_info_trust =
1699
+ interface.default_ipv4_dhcp_relay_info_trust
1700
+ assert_equal(interface.default_ipv4_dhcp_relay_info_trust,
1701
+ interface.ipv4_dhcp_relay_info_trust)
1702
+ end
1703
+
1704
+ def test_ipv4_dhcp_relay_src_addr_hsrp
1705
+ interface = Interface.new(interfaces[0])
1706
+ interface.switchport_enable(false)
1707
+ if validate_property_excluded?('interface', 'ipv4_dhcp_relay_src_addr_hsrp')
1708
+ assert_nil(interface.ipv4_dhcp_relay_src_addr_hsrp)
1709
+ assert_raises(Cisco::UnsupportedError) do
1710
+ interface.ipv4_dhcp_relay_src_addr_hsrp = true
1711
+ end
1712
+ return
1713
+ end
1714
+ assert_equal(interface.default_ipv4_dhcp_relay_src_addr_hsrp,
1715
+ interface.ipv4_dhcp_relay_src_addr_hsrp)
1716
+ interface.ipv4_dhcp_relay_src_addr_hsrp = true
1717
+ assert_equal(true, interface.ipv4_dhcp_relay_src_addr_hsrp)
1718
+ interface.ipv4_dhcp_relay_src_addr_hsrp =
1719
+ interface.default_ipv4_dhcp_relay_src_addr_hsrp
1720
+ assert_equal(interface.default_ipv4_dhcp_relay_src_addr_hsrp,
1721
+ interface.ipv4_dhcp_relay_src_addr_hsrp)
1722
+ end
1723
+
1724
+ def test_ipv4_dhcp_relay_src_intf
1725
+ interface = Interface.new(interfaces[0])
1726
+ interface.switchport_enable(false)
1727
+ if validate_property_excluded?('interface', 'ipv4_dhcp_relay_src_intf')
1728
+ assert_nil(interface.ipv4_dhcp_relay_src_intf)
1729
+ assert_raises(Cisco::UnsupportedError) do
1730
+ interface.ipv4_dhcp_relay_src_intf = 'port-channel200'
1731
+ end
1732
+ return
1733
+ end
1734
+ assert_equal(interface.default_ipv4_dhcp_relay_src_intf,
1735
+ interface.ipv4_dhcp_relay_src_intf)
1736
+ interface.ipv4_dhcp_relay_src_intf = 'port-channel200'
1737
+ assert_equal('port-channel200', interface.ipv4_dhcp_relay_src_intf)
1738
+ interface.ipv4_dhcp_relay_src_intf =
1739
+ interface.default_ipv4_dhcp_relay_src_intf
1740
+ assert_equal(interface.default_ipv4_dhcp_relay_src_intf,
1741
+ interface.ipv4_dhcp_relay_src_intf)
1742
+ end
1743
+
1744
+ def test_ipv4_dhcp_relay_subnet_broadcast
1745
+ interface = Interface.new(interfaces[0])
1746
+ interface.switchport_enable(false)
1747
+ if validate_property_excluded?('interface', 'ipv4_dhcp_relay_subnet_broadcast')
1748
+ assert_nil(interface.ipv4_dhcp_relay_subnet_broadcast)
1749
+ assert_raises(Cisco::UnsupportedError) do
1750
+ interface.ipv4_dhcp_relay_subnet_broadcast = true
1751
+ end
1752
+ return
1753
+ end
1754
+ assert_equal(interface.default_ipv4_dhcp_relay_subnet_broadcast,
1755
+ interface.ipv4_dhcp_relay_subnet_broadcast)
1756
+ interface.ipv4_dhcp_relay_subnet_broadcast = true
1757
+ assert_equal(true, interface.ipv4_dhcp_relay_subnet_broadcast)
1758
+ interface.ipv4_dhcp_relay_subnet_broadcast =
1759
+ interface.default_ipv4_dhcp_relay_subnet_broadcast
1760
+ assert_equal(interface.default_ipv4_dhcp_relay_subnet_broadcast,
1761
+ interface.ipv4_dhcp_relay_subnet_broadcast)
1762
+ end
1763
+
1764
+ def test_ipv4_dhcp_smart_relay
1765
+ interface = Interface.new(interfaces[0])
1766
+ interface.switchport_enable(false)
1767
+ if validate_property_excluded?('interface', 'ipv4_dhcp_smart_relay')
1768
+ assert_nil(interface.ipv4_dhcp_smart_relay)
1769
+ assert_raises(Cisco::UnsupportedError) do
1770
+ interface.ipv4_dhcp_smart_relay = true
1771
+ end
1772
+ return
1773
+ end
1774
+ assert_equal(interface.default_ipv4_dhcp_smart_relay,
1775
+ interface.ipv4_dhcp_smart_relay)
1776
+ interface.ipv4_dhcp_smart_relay = true
1777
+ assert_equal(true, interface.ipv4_dhcp_smart_relay)
1778
+ interface.ipv4_dhcp_smart_relay =
1779
+ interface.default_ipv4_dhcp_smart_relay
1780
+ assert_equal(interface.default_ipv4_dhcp_smart_relay,
1781
+ interface.ipv4_dhcp_smart_relay)
1782
+ end
1783
+
1784
+ def test_ipv6_dhcp_relay_addr
1785
+ interface = Interface.new(interfaces[0])
1786
+ interface.switchport_enable(false)
1787
+ list = ['2000::11', '2000::12']
1788
+ if validate_property_excluded?('interface', 'ipv6_dhcp_relay_addr')
1789
+ assert_nil(interface.ipv6_dhcp_relay_addr)
1790
+ assert_raises(Cisco::UnsupportedError) do
1791
+ interface.ipv6_dhcp_relay_addr = list
1792
+ end
1793
+ return
1794
+ end
1795
+ assert_equal(interface.default_ipv6_dhcp_relay_addr,
1796
+ interface.ipv6_dhcp_relay_addr)
1797
+ interface.ipv6_dhcp_relay_addr = list
1798
+ assert_equal(list, interface.ipv6_dhcp_relay_addr)
1799
+ interface.ipv6_dhcp_relay_addr =
1800
+ interface.default_ipv6_dhcp_relay_addr
1801
+ assert_equal(interface.default_ipv6_dhcp_relay_addr,
1802
+ interface.ipv6_dhcp_relay_addr)
1803
+ end
1804
+
1805
+ def test_ipv6_dhcp_relay_src_intf
1806
+ inf_name = interfaces[0]
1807
+ interface = Interface.new(inf_name)
1808
+ interface.switchport_enable(false)
1809
+ if validate_property_excluded?('interface', 'ipv6_dhcp_relay_src_intf')
1810
+ assert_nil(interface.ipv6_dhcp_relay_src_intf)
1811
+ assert_raises(Cisco::UnsupportedError) do
1812
+ interface.ipv6_dhcp_relay_src_intf = inf_name
1813
+ end
1814
+ return
1815
+ end
1816
+ assert_equal(interface.default_ipv6_dhcp_relay_src_intf,
1817
+ interface.ipv6_dhcp_relay_src_intf)
1818
+ interface.ipv6_dhcp_relay_src_intf = inf_name
1819
+ assert_equal(inf_name, interface.ipv6_dhcp_relay_src_intf)
1820
+ interface.ipv6_dhcp_relay_src_intf =
1821
+ interface.default_ipv6_dhcp_relay_src_intf
1822
+ assert_equal(interface.default_ipv6_dhcp_relay_src_intf,
1823
+ interface.ipv6_dhcp_relay_src_intf)
1824
+ end
1825
+
1826
+ def test_pim_bfd
1827
+ inf_name = interfaces[0]
1828
+ interface = Interface.new(inf_name)
1829
+ interface.switchport_enable(false)
1830
+ if validate_property_excluded?('interface', 'pim_bfd')
1831
+ assert_nil(interface.pim_bfd)
1832
+ assert_raises(Cisco::UnsupportedError) do
1833
+ interface.pim_bfd = true
1834
+ end
1835
+ return
1836
+ end
1837
+ assert_equal(interface.default_pim_bfd, interface.pim_bfd)
1838
+ interface.pim_bfd = true
1839
+ assert_equal(true, interface.pim_bfd)
1840
+ interface.pim_bfd = interface.default_pim_bfd
1841
+ assert_equal(interface.default_pim_bfd, interface.pim_bfd)
1842
+ end
1843
+
1844
+ def test_load_interval_counter_1_delay
1845
+ inf_name = interfaces[0]
1846
+ interface = Interface.new(inf_name)
1847
+ if validate_property_excluded?('interface',
1848
+ 'load_interval_counter_1_delay')
1849
+ assert_nil(interface.load_interval_counter_1_delay)
1850
+ assert_raises(Cisco::UnsupportedError) do
1851
+ interface.load_interval_counter_1_delay = 100
1852
+ end
1853
+ return
1854
+ end
1855
+ assert_equal(interface.default_load_interval_counter_1_delay,
1856
+ interface.load_interval_counter_1_delay)
1857
+ interface.load_interval_counter_1_delay = 100
1858
+ assert_equal(100, interface.load_interval_counter_1_delay)
1859
+ interface.load_interval_counter_1_delay =
1860
+ interface.default_load_interval_counter_1_delay
1861
+ assert_equal(interface.default_load_interval_counter_1_delay,
1862
+ interface.load_interval_counter_1_delay)
1863
+ # check nil for subintf and loopback
1864
+ interface.switchport_mode = :disabled if platform == :nexus
1865
+ subif = Interface.new(interfaces[0] + '.1')
1866
+ assert_nil(subif.load_interval_counter_1_delay)
1867
+ assert_raises(ArgumentError) { subif.load_interval_counter_1_delay = 100 }
1868
+ lb = Interface.new('loopback0')
1869
+ assert_nil(lb.load_interval_counter_1_delay)
1870
+ assert_raises(ArgumentError) { lb.load_interval_counter_1_delay = 100 }
1871
+ subif.destroy
1872
+ lb.destroy
1873
+ end
1874
+
1875
+ def test_load_interval_counter_2_delay
1876
+ inf_name = interfaces[0]
1877
+ interface = Interface.new(inf_name)
1878
+ if validate_property_excluded?('interface',
1879
+ 'load_interval_counter_2_delay')
1880
+ assert_nil(interface.load_interval_counter_2_delay)
1881
+ assert_raises(Cisco::UnsupportedError) do
1882
+ interface.load_interval_counter_2_delay = 200
1883
+ end
1884
+ return
1885
+ end
1886
+ assert_equal(interface.default_load_interval_counter_2_delay,
1887
+ interface.load_interval_counter_2_delay)
1888
+ interface.load_interval_counter_2_delay = 200
1889
+ assert_equal(200, interface.load_interval_counter_2_delay)
1890
+ interface.load_interval_counter_2_delay =
1891
+ interface.default_load_interval_counter_2_delay
1892
+ assert_equal(interface.default_load_interval_counter_2_delay,
1893
+ interface.load_interval_counter_2_delay)
1894
+ # check nil for subintf and loopback
1895
+ interface.switchport_mode = :disabled if platform == :nexus
1896
+ subif = Interface.new(interfaces[0] + '.1')
1897
+ assert_nil(subif.load_interval_counter_2_delay)
1898
+ assert_raises(ArgumentError) { subif.load_interval_counter_2_delay = 100 }
1899
+ lb = Interface.new('loopback0')
1900
+ assert_nil(lb.load_interval_counter_2_delay)
1901
+ assert_raises(ArgumentError) { lb.load_interval_counter_2_delay = 100 }
1902
+ subif.destroy
1903
+ lb.destroy
1904
+ end
1905
+
1906
+ def test_load_interval_counter_3_delay
1907
+ inf_name = interfaces[0]
1908
+ interface = Interface.new(inf_name)
1909
+ if validate_property_excluded?('interface',
1910
+ 'load_interval_counter_3_delay')
1911
+ assert_nil(interface.load_interval_counter_3_delay)
1912
+ assert_raises(Cisco::UnsupportedError) do
1913
+ interface.load_interval_counter_3_delay = 150
1914
+ end
1915
+ return
1916
+ end
1917
+ assert_equal(interface.default_load_interval_counter_3_delay,
1918
+ interface.load_interval_counter_3_delay)
1919
+ interface.load_interval_counter_3_delay = 150
1920
+ assert_equal(150, interface.load_interval_counter_3_delay)
1921
+ interface.load_interval_counter_3_delay =
1922
+ interface.default_load_interval_counter_3_delay
1923
+ assert_equal(interface.default_load_interval_counter_3_delay,
1924
+ interface.load_interval_counter_3_delay)
1925
+ # check nil for subintf and loopback
1926
+ interface.switchport_mode = :disabled if platform == :nexus
1927
+ subif = Interface.new(interfaces[0] + '.1')
1928
+ assert_nil(subif.load_interval_counter_3_delay)
1929
+ assert_raises(ArgumentError) { subif.load_interval_counter_3_delay = 100 }
1930
+ lb = Interface.new('loopback0')
1931
+ assert_nil(lb.load_interval_counter_3_delay)
1932
+ assert_raises(ArgumentError) { lb.load_interval_counter_3_delay = 100 }
1933
+ subif.destroy
1934
+ lb.destroy
1935
+ end
1936
+
1937
+ def test_default_physical
1938
+ name = interfaces[0]
1939
+ int = Interface.new(name)
1940
+ int.switchport_mode = :disabled
1941
+
1942
+ # Verify l3 -> default
1943
+ int.description = 'default_pysical'
1944
+ int.ipv4_addr_mask_set('192.168.0.1', '24')
1945
+ refute(int.default?)
1946
+
1947
+ int.destroy
1948
+ assert(int.default?)
1949
+
1950
+ # Verify l2 trunk -> default
1951
+ int.switchport_mode = :access
1952
+ int.switchport_autostate_exclude = true
1953
+ refute(int.default?)
1954
+
1955
+ int.destroy
1956
+ assert(int.default?)
1957
+ end
1958
+ end