cisco_node_utils 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +4 -1
  6. data/CHANGELOG.md +81 -2
  7. data/CONTRIBUTING.md +2 -17
  8. data/Gemfile +5 -0
  9. data/README.md +92 -47
  10. data/Rakefile +23 -1
  11. data/bin/git/hooks/hook_lib +7 -0
  12. data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
  13. data/bin/git/hooks/pre-commit/rubocop +7 -2
  14. data/bin/git/hooks/pre-commit/validate-diffs +18 -4
  15. data/bin/git/hooks/pre-commit/validate-yaml +18 -0
  16. data/bin/git/update-hooks +64 -6
  17. data/cisco_node_utils.gemspec +9 -6
  18. data/docs/README-develop-best-practices.md +149 -50
  19. data/docs/README-develop-node-utils-APIs.md +92 -42
  20. data/docs/README-maintainers.md +7 -4
  21. data/docs/README-test-execution.md +57 -0
  22. data/docs/cisco_node_utils.yaml.example +30 -0
  23. data/docs/template-router.rb +4 -0
  24. data/ext/mkrf_conf.rb +63 -0
  25. data/lib/.rubocop.yml +2 -2
  26. data/lib/cisco_node_utils.rb +5 -0
  27. data/lib/cisco_node_utils/aaa_authentication_login.rb +5 -6
  28. data/lib/cisco_node_utils/aaa_authorization_service.rb +1 -1
  29. data/lib/cisco_node_utils/ace.rb +165 -12
  30. data/lib/cisco_node_utils/acl.rb +2 -1
  31. data/lib/cisco_node_utils/bgp.rb +184 -21
  32. data/lib/cisco_node_utils/bgp_af.rb +94 -249
  33. data/lib/cisco_node_utils/bgp_neighbor.rb +94 -14
  34. data/lib/cisco_node_utils/bgp_neighbor_af.rb +75 -8
  35. data/lib/cisco_node_utils/bridge_domain.rb +183 -0
  36. data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
  37. data/lib/cisco_node_utils/cisco_cmn_utils.rb +85 -2
  38. data/lib/cisco_node_utils/client.rb +35 -0
  39. data/lib/cisco_node_utils/client/client.rb +234 -0
  40. data/lib/cisco_node_utils/client/grpc.rb +33 -0
  41. data/lib/cisco_node_utils/client/grpc/client.rb +311 -0
  42. data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
  43. data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
  44. data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
  45. data/lib/cisco_node_utils/client/nxapi.rb +31 -0
  46. data/lib/cisco_node_utils/client/nxapi/client.rb +305 -0
  47. data/lib/cisco_node_utils/client/utils.rb +164 -0
  48. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +222 -254
  49. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +11 -8
  50. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +22 -15
  51. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +11 -8
  52. data/lib/cisco_node_utils/cmd_ref/acl.yaml +21 -16
  53. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +239 -109
  54. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +114 -55
  55. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +76 -52
  56. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +106 -62
  57. data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +71 -0
  58. data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
  59. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +35 -14
  60. data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
  61. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +23 -17
  62. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +94 -83
  63. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +22 -17
  64. data/lib/cisco_node_utils/cmd_ref/feature.yaml +76 -26
  65. data/lib/cisco_node_utils/cmd_ref/images.yaml +3 -2
  66. data/lib/cisco_node_utils/cmd_ref/interface.yaml +381 -153
  67. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +21 -11
  68. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +21 -21
  69. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +30 -21
  70. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +18 -13
  71. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +26 -31
  72. data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
  73. data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
  74. data/lib/cisco_node_utils/cmd_ref/memory.yaml +17 -6
  75. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +10 -3
  76. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +17 -5
  77. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +33 -29
  78. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +12 -10
  79. data/lib/cisco_node_utils/cmd_ref/pim.yaml +16 -19
  80. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +40 -25
  81. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +17 -12
  82. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +71 -35
  83. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +10 -5
  84. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +6 -2
  85. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +47 -43
  86. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +13 -11
  87. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +4 -2
  88. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +23 -21
  89. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +26 -22
  90. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +19 -17
  91. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +18 -6
  92. data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +234 -0
  93. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +24 -9
  94. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +5 -3
  95. data/lib/cisco_node_utils/cmd_ref/system.yaml +4 -3
  96. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +22 -20
  97. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +27 -15
  98. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +45 -16
  99. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +21 -11
  100. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +3 -2
  101. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +60 -32
  102. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +118 -101
  103. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +54 -58
  104. data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +118 -0
  105. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +19 -25
  106. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +28 -18
  107. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +34 -17
  108. data/lib/cisco_node_utils/cmd_ref/yum.yaml +6 -4
  109. data/lib/cisco_node_utils/command_reference.rb +261 -142
  110. data/lib/cisco_node_utils/constants.rb +33 -0
  111. data/lib/cisco_node_utils/encapsulation.rb +112 -0
  112. data/lib/cisco_node_utils/environment.rb +102 -0
  113. data/lib/cisco_node_utils/evpn_vni.rb +5 -3
  114. data/lib/cisco_node_utils/exceptions.rb +111 -0
  115. data/lib/cisco_node_utils/fabricpath_global.rb +52 -35
  116. data/lib/cisco_node_utils/fabricpath_topology.rb +44 -57
  117. data/lib/cisco_node_utils/feature.rb +165 -3
  118. data/lib/cisco_node_utils/interface.rb +1051 -260
  119. data/lib/cisco_node_utils/interface_channel_group.rb +11 -10
  120. data/lib/cisco_node_utils/interface_ospf.rb +1 -2
  121. data/lib/cisco_node_utils/interface_portchannel.rb +4 -12
  122. data/lib/cisco_node_utils/interface_service_vni.rb +7 -7
  123. data/lib/cisco_node_utils/itd_device_group.rb +248 -0
  124. data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
  125. data/lib/cisco_node_utils/itd_service.rb +523 -0
  126. data/lib/cisco_node_utils/logger.rb +75 -0
  127. data/lib/cisco_node_utils/node.rb +62 -192
  128. data/lib/cisco_node_utils/node_util.rb +56 -10
  129. data/lib/cisco_node_utils/overlay_global.rb +2 -2
  130. data/lib/cisco_node_utils/pim.rb +2 -13
  131. data/lib/cisco_node_utils/pim_group_list.rb +1 -1
  132. data/lib/cisco_node_utils/pim_rp_address.rb +1 -1
  133. data/lib/cisco_node_utils/platform.rb +52 -21
  134. data/lib/cisco_node_utils/portchannel_global.rb +89 -19
  135. data/lib/cisco_node_utils/radius_server.rb +168 -37
  136. data/lib/cisco_node_utils/router_ospf.rb +20 -35
  137. data/lib/cisco_node_utils/router_ospf_vrf.rb +4 -4
  138. data/lib/cisco_node_utils/snmpserver.rb +1 -6
  139. data/lib/cisco_node_utils/snmpuser.rb +6 -4
  140. data/lib/cisco_node_utils/stp_global.rb +676 -0
  141. data/lib/cisco_node_utils/syslog_server.rb +77 -18
  142. data/lib/cisco_node_utils/syslog_settings.rb +1 -1
  143. data/lib/cisco_node_utils/tacacs_server_group.rb +8 -4
  144. data/lib/cisco_node_utils/tacacs_server_host.rb +115 -25
  145. data/lib/cisco_node_utils/vdc.rb +12 -0
  146. data/lib/cisco_node_utils/version.rb +1 -1
  147. data/lib/cisco_node_utils/vlan.rb +147 -29
  148. data/lib/cisco_node_utils/vpc.rb +55 -3
  149. data/lib/cisco_node_utils/vrf.rb +72 -11
  150. data/lib/cisco_node_utils/vrf_af.rb +114 -29
  151. data/lib/cisco_node_utils/vtp.rb +34 -52
  152. data/lib/cisco_node_utils/vxlan_vtep.rb +34 -8
  153. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +36 -4
  154. data/lib/minitest/environment_plugin.rb +31 -0
  155. data/lib/minitest/log_level_plugin.rb +41 -0
  156. data/spec/client_spec.rb +7 -0
  157. data/spec/environment_spec.rb +263 -0
  158. data/spec/grpc_client_spec.rb +23 -0
  159. data/spec/isolate/all_clients_spec.rb +9 -0
  160. data/spec/isolate/grpc_only_spec.rb +16 -0
  161. data/spec/isolate/no_clients_spec.rb +26 -0
  162. data/spec/isolate/nxapi_only_spec.rb +16 -0
  163. data/spec/nxapi_client_spec.rb +42 -0
  164. data/spec/schema.yaml +75 -0
  165. data/spec/shared_examples_for_clients.rb +14 -0
  166. data/spec/spec_helper.rb +91 -0
  167. data/spec/whitespace_spec.rb +10 -0
  168. data/spec/yaml_spec.rb +42 -0
  169. data/tests/.rubocop.yml +2 -2
  170. data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
  171. data/tests/basetest.rb +96 -36
  172. data/tests/ciscotest.rb +220 -12
  173. data/tests/cmd_config.yaml +71 -49
  174. data/tests/cmd_config_invalid.yaml +1 -1
  175. data/tests/test_aaa_authentication_login.rb +1 -0
  176. data/tests/test_aaa_authentication_login_service.rb +9 -0
  177. data/tests/test_aaa_authorization_service.rb +173 -367
  178. data/tests/test_ace.rb +171 -100
  179. data/tests/test_acl.rb +10 -1
  180. data/tests/test_bgp_af.rb +395 -728
  181. data/tests/test_bgp_neighbor.rb +274 -115
  182. data/tests/test_bgp_neighbor_af.rb +178 -77
  183. data/tests/test_bridge_domain.rb +191 -0
  184. data/tests/test_bridge_domain_vni.rb +116 -0
  185. data/tests/test_client_utils.rb +111 -0
  186. data/tests/test_command_config.rb +9 -5
  187. data/tests/test_command_reference.rb +380 -102
  188. data/tests/test_dns_domain.rb +13 -3
  189. data/tests/test_domain_name.rb +13 -3
  190. data/tests/test_encapsulation.rb +77 -0
  191. data/tests/test_evpn_vni.rb +25 -7
  192. data/tests/test_fabricpath_global.rb +167 -163
  193. data/tests/test_fabricpath_topology.rb +12 -33
  194. data/tests/test_feature.rb +215 -0
  195. data/tests/test_grpc.rb +166 -0
  196. data/tests/test_interface.rb +585 -344
  197. data/tests/test_interface_bdi.rb +80 -0
  198. data/tests/test_interface_channel_group.rb +6 -3
  199. data/tests/test_interface_ospf.rb +26 -24
  200. data/tests/test_interface_portchannel.rb +1 -0
  201. data/tests/test_interface_private_vlan.rb +724 -0
  202. data/tests/test_interface_service_vni.rb +37 -66
  203. data/tests/test_interface_svi.rb +98 -101
  204. data/tests/test_interface_switchport.rb +419 -549
  205. data/tests/test_itd_device_group.rb +145 -0
  206. data/tests/test_itd_device_group_node.rb +199 -0
  207. data/tests/test_itd_service.rb +298 -0
  208. data/tests/test_logger.rb +43 -0
  209. data/tests/test_name_server.rb +11 -2
  210. data/tests/test_node.rb +16 -75
  211. data/tests/test_node_ext.rb +174 -163
  212. data/tests/test_node_util.rb +119 -0
  213. data/tests/test_ntp_config.rb +5 -1
  214. data/tests/test_ntp_server.rb +2 -2
  215. data/tests/test_nxapi.rb +221 -0
  216. data/tests/test_overlay_global.rb +47 -38
  217. data/tests/test_pim.rb +2 -0
  218. data/tests/test_pim_group_list.rb +2 -0
  219. data/tests/test_pim_rp_address.rb +2 -0
  220. data/tests/test_platform.rb +86 -39
  221. data/tests/test_portchannel_global.rb +211 -135
  222. data/tests/test_radius_global.rb +13 -5
  223. data/tests/test_radius_server.rb +256 -104
  224. data/tests/test_radius_server_group.rb +2 -0
  225. data/tests/test_router_bgp.rb +781 -485
  226. data/tests/test_router_ospf.rb +26 -103
  227. data/tests/test_router_ospf_vrf.rb +52 -57
  228. data/tests/test_snmp_notification_receiver.rb +2 -0
  229. data/tests/test_snmpcommunity.rb +2 -0
  230. data/tests/test_snmpgroup.rb +2 -0
  231. data/tests/test_snmpnotification.rb +40 -21
  232. data/tests/test_snmpserver.rb +2 -0
  233. data/tests/test_snmpuser.rb +2 -0
  234. data/tests/test_stp_global.rb +563 -0
  235. data/tests/test_syslog_server.rb +32 -8
  236. data/tests/test_syslog_settings.rb +22 -9
  237. data/tests/test_tacacs_server.rb +32 -27
  238. data/tests/test_tacacs_server_group.rb +100 -45
  239. data/tests/test_tacacs_server_host.rb +135 -43
  240. data/tests/test_vdc.rb +2 -16
  241. data/tests/test_vlan.rb +106 -54
  242. data/tests/test_vlan_mt_full.rb +11 -21
  243. data/tests/test_vlan_private.rb +669 -0
  244. data/tests/test_vpc.rb +312 -159
  245. data/tests/test_vrf.rb +122 -113
  246. data/tests/test_vrf_af.rb +238 -0
  247. data/tests/test_vtp.rb +58 -102
  248. data/tests/test_vxlan_vtep.rb +38 -17
  249. data/tests/test_vxlan_vtep_vni.rb +61 -9
  250. data/tests/test_yum.rb +49 -25
  251. metadata +122 -36
  252. data/lib/cisco_node_utils/cmd_ref/fex.yaml +0 -9
  253. data/lib/cisco_node_utils/cmd_ref/vni.yaml +0 -76
  254. data/lib/cisco_node_utils/vni.rb +0 -227
  255. data/tests/test_vni.rb +0 -106
@@ -0,0 +1,119 @@
1
+ # Copyright (c) 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/node_util'
17
+
18
+ # TestNodeUtil - Minitest for NodeUtil class
19
+ class TestNodeUtil < CiscoTestCase
20
+ attr_reader :nu
21
+ def setup
22
+ @nu = NodeUtil.new
23
+ end
24
+
25
+ def test_node
26
+ assert_equal(node, nu.node)
27
+ assert_equal(node, NodeUtil.node)
28
+ end
29
+
30
+ def test_client
31
+ assert_equal(node.client, nu.client)
32
+ assert_equal(node.client, NodeUtil.client)
33
+ end
34
+
35
+ def test_config_get
36
+ result = node.config_get('show_version', 'system_image')
37
+ result2 = nu.config_get('show_version', 'system_image')
38
+ result3 = NodeUtil.config_get('show_version', 'system_image')
39
+ assert_equal(node.system, result)
40
+ assert_equal(result, result2)
41
+ assert_equal(result, result3)
42
+ end
43
+
44
+ def test_config_get_default
45
+ result = node.config_get_default('bgp', 'graceful_restart_timers_restart')
46
+ result2 = nu.config_get_default('bgp', 'graceful_restart_timers_restart')
47
+ result3 = NodeUtil.config_get_default('bgp',
48
+ 'graceful_restart_timers_restart')
49
+ assert_equal(120, result)
50
+ assert_equal(result, result2)
51
+ assert_equal(result, result3)
52
+ end
53
+
54
+ def test_config_set_error_handling
55
+ # The Node error has no context information
56
+ e = assert_raises(Cisco::CliError) do
57
+ node.config_set('interface', 'shutdown',
58
+ name: interfaces[0], state: 'foobar')
59
+ end
60
+ assert_match(/^The command '.*shutdown' was rejected with error:/,
61
+ e.message)
62
+ rejected_input = e.rejected_input
63
+ clierror = e.clierror
64
+
65
+ # The NodeUtil class error just provides the class name by default...
66
+ e = assert_raises(Cisco::CliError) do
67
+ NodeUtil.config_set('interface', 'shutdown',
68
+ name: interfaces[0], state: 'foobar')
69
+ end
70
+ assert_match(
71
+ /^\[Cisco::NodeUtil\] The command '.*shutdown' was rejected with error:/,
72
+ e.message)
73
+ # Make sure error context from the Node was preserved
74
+ assert_equal(rejected_input, e.rejected_input)
75
+ assert_equal(clierror, e.clierror)
76
+
77
+ # ...but uses self.to_s if implemented
78
+ def NodeUtil.to_s
79
+ 'Hello world'
80
+ end
81
+ e = assert_raises(Cisco::CliError) do
82
+ NodeUtil.config_set('interface', 'shutdown',
83
+ name: interfaces[0], state: 'foobar')
84
+ end
85
+ assert_match(
86
+ /^\[Hello world\] The command '.*shutdown' was rejected with error:/,
87
+ e.message)
88
+ # Make sure error context from the Node was preserved
89
+ assert_equal(rejected_input, e.rejected_input)
90
+ assert_equal(clierror, e.clierror)
91
+
92
+ # Similarly, the nu instance error provides the instance by default...
93
+ e = assert_raises(Cisco::CliError) do
94
+ nu.config_set('interface', 'shutdown',
95
+ name: interfaces[0], state: 'foobar')
96
+ end
97
+ assert_match(
98
+ /^\[#<Cisco::NodeUtil:0x.*>\] The command '.*shutdown' was rejected/,
99
+ e.message)
100
+ # Make sure error context from the Node was preserved
101
+ assert_equal(rejected_input, e.rejected_input)
102
+ assert_equal(clierror, e.clierror)
103
+
104
+ # ...but is happy to use the instance to_s
105
+ def nu.to_s
106
+ 'NodeUtil #1'
107
+ end
108
+ e = assert_raises(Cisco::CliError) do
109
+ nu.config_set('interface', 'shutdown',
110
+ name: interfaces[0], state: 'foobar')
111
+ end
112
+ assert_match(
113
+ /^\[NodeUtil #1\] The command '.*shutdown' was rejected with error:/,
114
+ e.message)
115
+ # Make sure error context from the Node was preserved
116
+ assert_equal(rejected_input, e.rejected_input)
117
+ assert_equal(clierror, e.clierror)
118
+ end
119
+ end
@@ -28,7 +28,11 @@ class TestNtpConfig < CiscoTestCase
28
28
 
29
29
  def no_ntpconfig
30
30
  # Turn the feature off for a clean test.
31
- config("no ntp source-interface #{interfaces[0]}")
31
+ if platform == :ios_xr
32
+ config("no ntp source #{interfaces[0]}")
33
+ else
34
+ config("no ntp source-interface #{interfaces[0]}")
35
+ end
32
36
  end
33
37
 
34
38
  # TESTS
@@ -34,8 +34,8 @@ class TestNtpServer < CiscoTestCase
34
34
 
35
35
  def no_ntpserver_uk
36
36
  # Turn the feature off for a clean test.
37
- config('no ntpserver 130.88.203.12',
38
- 'no ntpserver 2003::5')
37
+ config('no ntp server 130.88.203.12',
38
+ 'no ntp server 2003::5')
39
39
  end
40
40
 
41
41
  # TESTS
@@ -0,0 +1,221 @@
1
+ # November 2014, Glenn F. Matthews
2
+ #
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'basetest'
18
+ require_relative '../lib/cisco_node_utils/node'
19
+
20
+ # TestNxapi - NXAPI client unit tests
21
+ class TestNxapi < TestCase
22
+ @@client = nil # rubocop:disable Style/ClassVars
23
+
24
+ def self.runnable_methods
25
+ # If we're pointed to a gRPC node (as evidenced by presence of a port num)
26
+ # then these tests don't apply
27
+ return [:all_skipped] if Cisco::Environment.environment[:port]
28
+ super
29
+ end
30
+
31
+ def all_skipped
32
+ skip 'Node under test does not appear to use the NXAPI client'
33
+ end
34
+
35
+ def setup
36
+ super
37
+ @product_id = Cisco::Node.new.product_id if @product_id.nil?
38
+ cleanup
39
+ end
40
+
41
+ def teardown
42
+ cleanup
43
+ super
44
+ end
45
+
46
+ def cleanup
47
+ config_no_warn('no interface loopback41', 'no interface loopback42')
48
+ end
49
+
50
+ def client
51
+ unless @@client
52
+ client = Cisco::Client::NXAPI.new(Cisco::Environment.environment)
53
+ client.cache_enable = true
54
+ client.cache_auto = true
55
+ @@client = client # rubocop:disable Style/ClassVars
56
+ end
57
+ @@client
58
+ end
59
+
60
+ # Test cases for new NXAPI client APIs
61
+
62
+ def test_cli_set_string
63
+ client.set(context: 'interface loopback41', values: 'descr panda')
64
+ run = client.get(command: 'show run int loopback41')
65
+ desc = run.match(/description (.*)/)[1]
66
+ assert_equal(desc, 'panda')
67
+ end
68
+
69
+ def test_cli_set_array
70
+ client.set(context: ['int loopback41'], values: ['descr elephant'])
71
+ run = client.get(command: 'show run int loopback41')
72
+ desc = run.match(/description (.*)/)[1]
73
+ assert_equal(desc, 'elephant')
74
+ end
75
+
76
+ def test_cli_set_invalid
77
+ input = ['int loopback41', 'exit', 'int loopback42', 'plover']
78
+ successful = ['int loopback41', 'exit', 'int loopback42']
79
+ rejected = 'plover'
80
+
81
+ msg = case @product_id
82
+ when /N(5|6|7)/
83
+ 'Input CLI command error'
84
+ when /N(3|8|9)/
85
+ 'CLI execution error'
86
+ end
87
+
88
+ e = assert_raises Cisco::CliError do
89
+ client.set(values: input)
90
+ end
91
+
92
+ cli_rcs = "
93
+ cli return codes:
94
+ successful : #{e.successful_input}
95
+ rejected : #{e.rejected_input}
96
+ msg : #{e.msg}
97
+ code : #{e.code}
98
+ clierror : #{e.clierror}
99
+ "
100
+ assert_equal(successful, e.successful_input, cli_rcs)
101
+ assert_equal(rejected, e.rejected_input, cli_rcs)
102
+
103
+ assert_match(msg, e.msg, cli_rcs)
104
+ assert_equal('400', e.code, cli_rcs)
105
+ assert_match('% Invalid command', e.clierror, cli_rcs)
106
+ end
107
+
108
+ def test_get_cli_default
109
+ result = client.get(command: 'show hostname')
110
+ s = @device.cmd('show hostname')
111
+ assert_equal(result.strip, s.split("\n")[1].strip)
112
+ end
113
+
114
+ def test_get_cli_invalid
115
+ assert_raises Cisco::CliError do
116
+ client.get(command: 'show plugh')
117
+ end
118
+ end
119
+
120
+ def test_element_get_cli_incomplete
121
+ assert_raises Cisco::CliError do
122
+ client.get(command: 'show ')
123
+ end
124
+ end
125
+
126
+ def test_get_cli_explicit
127
+ result = client.get(command: 'show hostname', data_format: :cli)
128
+ s = @device.cmd('show hostname')
129
+ assert_equal(result.strip, s.split("\n")[1].strip)
130
+ end
131
+
132
+ def test_get_cli_empty
133
+ result = client.get(command: 'show hostname | incl foo | excl foo',
134
+ data_format: :cli)
135
+ assert_nil(result)
136
+ end
137
+
138
+ def test_get_nxapi_structured
139
+ result = client.get(command: 'show hostname',
140
+ data_format: :nxapi_structured)
141
+ s = @device.cmd('show hostname')
142
+ assert_equal(result['hostname'], s.split("\n")[1].strip)
143
+ end
144
+
145
+ def test_get_nxapi_structured_invalid
146
+ assert_raises Cisco::CliError do
147
+ client.get(command: 'show frobozz', data_format: :nxapi_structured)
148
+ end
149
+ end
150
+
151
+ def test_get_nxapi_structured_unsupported
152
+ cmd = { command: 'show snmp internal globals',
153
+ data_format: :nxapi_structured }
154
+ if @product_id[/N(5|6)/]
155
+ assert_empty(client.get(cmd))
156
+ else
157
+ assert_raises(Cisco::RequestNotSupported) { client.get(cmd) }
158
+ end
159
+ end
160
+
161
+ def test_connection_refused
162
+ @device.cmd('configure terminal')
163
+ @device.cmd('no feature nxapi')
164
+ @device.cmd('end')
165
+ assert_raises Cisco::ConnectionRefused do
166
+ client.cache_flush
167
+ client.get(command: 'show version')
168
+ end
169
+ assert_raises Cisco::ConnectionRefused do
170
+ client.set(values: 'interface loopback41')
171
+ end
172
+ # On the off chance that things behave differently when NXAPI is
173
+ # disabled while we're connected, versus trying to connect afresh...
174
+ @@client = nil # rubocop:disable Style/ClassVars
175
+ assert_raises Cisco::ConnectionRefused do
176
+ client.get(command: 'show version')
177
+ end
178
+ assert_raises Cisco::ConnectionRefused do
179
+ client.set(values: 'interface loopback41')
180
+ end
181
+ ensure
182
+ @device.cmd('configure terminal')
183
+ @device.cmd('feature nxapi')
184
+ @device.cmd('end')
185
+ end
186
+
187
+ def test_unauthorized
188
+ def client.password=(new) # rubocop:disable Style/TrivialAccessors
189
+ @password = new
190
+ end
191
+ client.password = 'wrong_password'
192
+ client.cache_flush
193
+ assert_raises Cisco::AuthenticationFailed do
194
+ client.get(command: 'show version')
195
+ end
196
+ assert_raises Cisco::AuthenticationFailed do
197
+ client.set(values: 'interface loopback41')
198
+ end
199
+ ensure
200
+ client.password = password
201
+ end
202
+
203
+ def test_unsupported
204
+ # Add a method to the NXAPI that sends a request of invalid type
205
+ def client.hello
206
+ req('hello', 'world')
207
+ end
208
+
209
+ assert_raises Cisco::RequestNotSupported do
210
+ client.hello
211
+ end
212
+ end
213
+
214
+ def test_smart_create
215
+ autoclient = Cisco::Client.create
216
+ assert_equal(Cisco::Client::NXAPI, autoclient.class)
217
+ assert(autoclient.supports?(:cli))
218
+ assert(autoclient.supports?(:nxapi_structured))
219
+ assert_equal(:nexus, autoclient.platform)
220
+ end
221
+ end
@@ -21,82 +21,91 @@ include Cisco
21
21
 
22
22
  # TestOverlayGlobal - Minitest for OverlayGlobal node utility
23
23
  class TestOverlayGlobal < CiscoTestCase
24
+ @skip_unless_supported = 'overlay_global'
25
+
24
26
  def setup
25
27
  super
26
- config('no feature fabric forwarding')
27
- config('no nv overlay evpn')
28
- config('l2rib dup-host-mac-detection default')
28
+ vxlan_linecard?
29
+ vdc_lc_state('f3')
30
+ config_no_warn('no feature fabric forwarding')
31
+ config_no_warn('no nv overlay evpn')
32
+ config_no_warn('l2rib dup-host-mac-detection default')
29
33
  end
30
34
 
31
35
  def test_dup_host_ip_addr_detection
32
- overlay_global = OverlayGlobal.new
36
+ o = OverlayGlobal.new
37
+ if validate_property_excluded?('overlay_global',
38
+ 'dup_host_ip_addr_detection')
39
+ assert_raises(Cisco::UnsupportedError) do
40
+ o.dup_host_ip_addr_detection_set(200, 20)
41
+ end
42
+ return
43
+ end
33
44
 
34
45
  # Before enabling 'nv overlay evpn', these properties do not exist
35
- assert_nil(overlay_global.dup_host_ip_addr_detection_host_moves)
36
- assert_nil(overlay_global.dup_host_ip_addr_detection_timeout)
46
+ assert_nil(o.dup_host_ip_addr_detection_host_moves)
47
+ assert_nil(o.dup_host_ip_addr_detection_timeout)
37
48
 
38
49
  # Set them to the default value and they should now be present
39
- default = [overlay_global.default_dup_host_ip_addr_detection_host_moves,
40
- overlay_global.default_dup_host_ip_addr_detection_timeout]
41
- overlay_global.dup_host_ip_addr_detection_set(*default)
42
- assert_equal(default[0],
43
- overlay_global.dup_host_ip_addr_detection_host_moves)
44
- assert_equal(default[1],
45
- overlay_global.dup_host_ip_addr_detection_timeout)
50
+ default = [o.default_dup_host_ip_addr_detection_host_moves,
51
+ o.default_dup_host_ip_addr_detection_timeout]
52
+ o.dup_host_ip_addr_detection_set(*default)
53
+ assert_equal(default[0], o.dup_host_ip_addr_detection_host_moves)
54
+ assert_equal(default[1], o.dup_host_ip_addr_detection_timeout)
46
55
  assert(Feature.nv_overlay_evpn_enabled?)
47
56
 
48
57
  # Set them to non-default values
49
58
  val = [200, 20]
50
- overlay_global.dup_host_ip_addr_detection_set(*val)
51
- assert_equal(val, overlay_global.dup_host_ip_addr_detection)
52
- assert_equal(val[0],
53
- overlay_global.dup_host_ip_addr_detection_host_moves)
54
- assert_equal(val[1],
55
- overlay_global.dup_host_ip_addr_detection_timeout)
59
+ o.dup_host_ip_addr_detection_set(*val)
60
+ assert_equal(val, o.dup_host_ip_addr_detection)
61
+ assert_equal(val[0], o.dup_host_ip_addr_detection_host_moves)
62
+ assert_equal(val[1], o.dup_host_ip_addr_detection_timeout)
56
63
  end
57
64
 
58
65
  def test_dup_host_mac_detection
59
- overlay_global = OverlayGlobal.new
66
+ o = OverlayGlobal.new
60
67
  # These properties always exist, even without 'nv overlay evpn'
61
- default = [overlay_global.default_dup_host_mac_detection_host_moves,
62
- overlay_global.default_dup_host_mac_detection_timeout]
63
- assert_equal(default, overlay_global.dup_host_mac_detection)
68
+ default = [o.default_dup_host_mac_detection_host_moves,
69
+ o.default_dup_host_mac_detection_timeout]
70
+ assert_equal(default, o.dup_host_mac_detection)
64
71
  refute(Feature.nv_overlay_evpn_enabled?)
65
72
 
66
73
  # Set to a non-default value
67
74
  val = [160, 16]
68
- overlay_global.dup_host_mac_detection_set(*val)
69
- assert_equal(val, overlay_global.dup_host_mac_detection)
75
+ o.dup_host_mac_detection_set(*val)
76
+ assert_equal(val, o.dup_host_mac_detection)
70
77
  refute(Feature.nv_overlay_evpn_enabled?)
71
78
 
72
79
  # Use the special defaulter method
73
- overlay_global.dup_host_mac_detection_default
74
- assert_equal(default, overlay_global.dup_host_mac_detection)
80
+ o.dup_host_mac_detection_default
81
+ assert_equal(default, o.dup_host_mac_detection)
75
82
  refute(Feature.nv_overlay_evpn_enabled?)
76
83
 
77
84
  # Set explicitly to default too
78
- overlay_global.dup_host_mac_detection_set(*default)
79
- assert_equal(default, overlay_global.dup_host_mac_detection)
85
+ o.dup_host_mac_detection_set(*default)
86
+ assert_equal(default, o.dup_host_mac_detection)
80
87
  refute(Feature.nv_overlay_evpn_enabled?)
81
88
  end
82
89
 
83
90
  def test_anycast_gateway_mac
84
- overlay_global = OverlayGlobal.new
91
+ o = OverlayGlobal.new
92
+ if validate_property_excluded?('overlay_global', 'anycast_gateway_mac')
93
+ assert_raises(Cisco::UnsupportedError) { o.anycast_gateway_mac = '1.1.1' }
94
+ return
95
+ end
96
+
85
97
  # Before enabling 'nv overlay evpn', this property does not exist
86
- assert_nil(overlay_global.anycast_gateway_mac)
98
+ assert_nil(o.anycast_gateway_mac)
87
99
 
88
100
  # Explicitly set to default and it should be enabled
89
- overlay_global.anycast_gateway_mac = \
90
- overlay_global.default_anycast_gateway_mac
91
- assert_equal(overlay_global.default_anycast_gateway_mac,
92
- overlay_global.anycast_gateway_mac)
101
+ o.anycast_gateway_mac = o.default_anycast_gateway_mac
102
+ assert_equal(o.default_anycast_gateway_mac, o.anycast_gateway_mac)
93
103
  assert(Feature.nv_overlay_evpn_enabled?)
94
104
 
95
105
  # Set to various non-default values
96
106
  %w(1.1.1 55.a10.ffff 1223.3445.5668).each do |mac|
97
- overlay_global.anycast_gateway_mac = mac
98
- assert_equal(Utils.zero_pad_macaddr(mac),
99
- overlay_global.anycast_gateway_mac)
107
+ o.anycast_gateway_mac = mac
108
+ assert_equal(Utils.zero_pad_macaddr(mac), o.anycast_gateway_mac)
100
109
  end
101
110
  end
102
111
  end