cisco_node_utils 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Michael Wiebe, December 2014
4
4
  #
5
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
5
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ class TestCommandConfig < CiscoTestCase
67
67
  config_cmd_hash.each do |k, v|
68
68
  v.each_value do |v1|
69
69
  # Send commands
70
- cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, ' ')}\n end\n"
70
+ cfg_cmd_str = "#{v1.gsub(/^/, ' ')}"
71
71
  cfg_string = remove_whitespace(cfg_cmd_str)
72
72
  # puts "cfg_string: \n||\n#{cfg_string}||\n"
73
73
  begin
@@ -120,7 +120,7 @@ class TestCommandConfig < CiscoTestCase
120
120
  sleep 30 # long-running command
121
121
  curr = @device.cmd('show int brief | count')[/^(\d+)$/]
122
122
  flunk('Timeout while creating 1024 loopback interfaces' \
123
- "(pre:#{pre} curr:#{curr}") unless (pre == curr - 1024)
123
+ "(pre:#{pre} curr:#{curr}") unless pre == curr - 1024
124
124
  end
125
125
 
126
126
  # Remove 1024 loopback interfaces
@@ -134,7 +134,7 @@ class TestCommandConfig < CiscoTestCase
134
134
  sleep 30 # long-running: n95 can take 70+ sec to remove all of these
135
135
  curr = @device.cmd(show_int_count)[/^(\d+)$/]
136
136
  flunk('Timeout while deleting 1024 loopback interfaces ' \
137
- "(pre:#{pre} curr:#{curr}") unless (pre == curr)
137
+ "(pre:#{pre} curr:#{curr}") unless pre == curr
138
138
  end
139
139
  end
140
140
 
@@ -142,7 +142,7 @@ class TestCommandConfig < CiscoTestCase
142
142
  cfg_hash = load_yaml(:negative)
143
143
  cfg_hash.each_value do |v|
144
144
  v.each_value do |v1|
145
- cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, ' ')}\n end\n"
145
+ cfg_cmd_str = "#{v1.gsub(/^/, ' ')}\n"
146
146
  cfg_string = remove_whitespace(cfg_cmd_str)
147
147
  assert_raises(CliError) { node.config(cfg_string) }
148
148
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # November 2014, Glenn F. Matthews
4
4
  #
5
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
5
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
@@ -17,13 +17,14 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'minitest/autorun'
20
+ require_relative 'basetest'
21
+
21
22
  require 'tempfile'
22
23
  require_relative '../lib/cisco_node_utils/command_reference'
23
24
 
24
25
  # TestCmdRef - Minitest for CommandReference and CmdRef classes.
25
- class TestCmdRef < MiniTest::Test
26
- include CommandReference
26
+ class TestCmdRef < Minitest::Test
27
+ include Cisco
27
28
 
28
29
  def setup
29
30
  @input_file = Tempfile.new('test.yaml')
@@ -33,8 +34,19 @@ class TestCmdRef < MiniTest::Test
33
34
  @input_file.close!
34
35
  end
35
36
 
36
- def load_file
37
- CommandReference.new('', [@input_file.path])
37
+ # Extend standard Minitest error handling to report UnsupportedError as skip
38
+ def capture_exceptions
39
+ super do
40
+ begin
41
+ yield
42
+ rescue Cisco::UnsupportedError => e
43
+ skip(e.to_s)
44
+ end
45
+ end
46
+ end
47
+
48
+ def load_file(**args)
49
+ CommandReference.new(**args, :files => [@input_file.path])
38
50
  end
39
51
 
40
52
  def write(string)
@@ -42,44 +54,39 @@ class TestCmdRef < MiniTest::Test
42
54
  @input_file.flush
43
55
  end
44
56
 
57
+ def test_data_sanity
58
+ # Make sure the actual YAML in our library loads for various platforms
59
+ CommandReference.new
60
+ CommandReference.new(platform: :nexus, cli: true)
61
+ CommandReference.new(platform: :nexus, product: 'N9K-C9396PX', cli: true)
62
+ CommandReference.new(platform: :nexus, product: 'N7K-C7010', cli: true)
63
+ CommandReference.new(platform: :nexus, product: 'N3K-C3064PQ-10GE',
64
+ cli: true)
65
+ end
66
+
45
67
  def test_load_empty_file
46
68
  # should load successfully but yield an empty hash
47
69
  reference = load_file
48
- assert(reference.empty?)
70
+ assert_empty(reference)
49
71
  end
50
72
 
51
73
  def test_load_whitespace_only
52
74
  write(' ')
53
75
  reference = load_file
54
- assert(reference.empty?)
76
+ assert_empty(reference)
55
77
  end
56
78
 
57
79
  def test_load_not_valid_yaml
58
80
  # The control characters embedded below are not permitted in YAML.
59
- # Syck (in older Ruby versions) will incorrectly accept these
60
- # while parsing the file, but our CmdRef constructor will eventually
61
- # reject the data.
62
- # Psych (in newer Ruby versions) will correctly reject
63
- # this data at parse time.
64
81
  write("
65
- feature\a\e:
66
- name\b\f:
67
- default_value:\vtrue")
82
+ name\a\e\b\f:
83
+ default_value:\vtrue")
68
84
  assert_raises(RuntimeError) { load_file }
69
85
  end
70
86
 
71
- def test_load_feature_no_name
72
- # should error out
73
- write('feature:')
74
- assert_raises(RuntimeError) do
75
- load_file
76
- end
77
- end
78
-
79
87
  def test_load_feature_name_no_data
80
88
  write("
81
- feature:
82
- name:")
89
+ name:")
83
90
  assert_raises(RuntimeError) do
84
91
  load_file
85
92
  end
@@ -87,122 +94,298 @@ feature:
87
94
 
88
95
  def test_load_feature_name_default
89
96
  write("
90
- feature:
91
- name:
92
- default_value: true")
97
+ name:
98
+ default_value: true")
93
99
  reference = load_file
94
100
  assert(!reference.empty?)
95
- ref = reference.lookup('feature', 'name')
101
+ ref = reference.lookup('test', 'name')
96
102
  assert_equal(true, ref.default_value)
97
103
  end
98
104
 
99
- def test_load_duplicate_feature
100
- write("
101
- feature:
102
- name:
103
- default_value: false
104
- feature:
105
- name:
106
- config_get: 'show feature'
107
- ")
108
- assert_raises(RuntimeError) { load_file }
109
- end
110
-
111
105
  def test_load_duplicate_name
112
106
  write("
113
- feature:
114
- name:
115
- default_value: false
116
- name:
117
- config_get: 'show feature'")
107
+ name:
108
+ default_value: false
109
+ name:
110
+ config_get: 'show feature'")
118
111
  assert_raises(RuntimeError) { load_file }
119
112
  end
120
113
 
121
114
  def test_load_duplicate_param
122
115
  write("
123
- feature:
124
- name:
125
- default_value: false
126
- default_value: true")
116
+ name:
117
+ default_value: false
118
+ default_value: true")
127
119
  assert_raises(RuntimeError) { load_file }
128
120
  end
129
121
 
130
122
  def test_load_unsupported_key
131
123
  write("
132
- feature:
133
- name:
134
- config_get: 'show feature'
135
- what_is_this: \"I don't even\"")
124
+ name:
125
+ config_get: 'show feature'
126
+ what_is_this: \"I don't even\"")
136
127
  assert_raises(RuntimeError) { load_file }
137
128
  end
138
129
 
139
- # # Alphabetization of features is not enforced at this time.
140
- # def test_load_features_unalphabetized
141
- # write("
142
- # zzz:
143
- # name:
144
- # default_value: true
145
- # zzy:
146
- # name:
147
- # default_value: false")
148
- # self.assert_raises(RuntimeError) { load_file }
149
- # end
130
+ def test_load_unalphabetized
131
+ write("
132
+ name_b:
133
+ default_value: true
134
+ name_a:
135
+ default_value: false")
136
+ assert_raises(RuntimeError) { load_file }
137
+ end
150
138
 
151
139
  def type_check(obj, cls)
152
140
  assert(obj.is_a?(cls), "#{obj} should be #{cls} but is #{obj.class}")
153
141
  end
154
142
 
155
143
  def test_load_types
156
- write("
157
- feature:
158
- name:
159
- default_value: true
160
- config_get: show hello
161
- config_get_token: !ruby/regexp '/hello world/'
162
- config_set: [ \"hello\", \"world\" ]
163
- test_config_get_regex: !ruby/regexp '/hello world/'
164
- ")
144
+ write(%q(
145
+ name:
146
+ default_value: true
147
+ config_get: show hello
148
+ config_get_token: '/hello world/'
149
+ config_set: [ \"hello\", \"world\" ]
150
+ test_config_get_regex: '/hello world/'
151
+ test_config_result:
152
+ false: RuntimeError
153
+ 32: "Long VLAN name knob is not enabled"
154
+ nil: ~
155
+ ))
165
156
  reference = load_file
166
- ref = reference.lookup('feature', 'name')
157
+ ref = reference.lookup('test', 'name')
167
158
  type_check(ref.default_value, TrueClass)
168
159
  type_check(ref.config_get, String)
169
- type_check(ref.config_get_token, Regexp)
160
+ type_check(ref.config_get_token, Array)
161
+ type_check(ref.config_get_token[0], Regexp)
170
162
  type_check(ref.config_set, Array)
171
163
  type_check(ref.test_config_get_regex, Regexp)
164
+ assert_raises(IndexError) { ref.test_config_get }
165
+ type_check(ref.test_config_result(false), RuntimeError.class)
166
+ type_check(ref.test_config_result(32), String)
167
+ type_check(ref.test_config_result('nil'), NilClass)
168
+
169
+ assert(ref.default_value?)
170
+ assert(ref.config_get?)
171
+ assert(ref.config_get_token?)
172
+ assert(ref.config_set?)
172
173
  end
173
174
 
174
- def test_load_common
175
- reference = CommandReference.new('')
176
- assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
177
- refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
178
- refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
179
- refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
180
- # Some spot checks
181
- type_check(reference.lookup('vtp', 'feature').config_get_token, String)
182
- type_check(reference.lookup('vtp', 'version').default_value, Integer)
175
+ def write_variants
176
+ write("
177
+ name:
178
+ default_value: 'generic'
179
+ cli_nexus:
180
+ default_value: 'NXAPI base'
181
+ /N7K/:
182
+ default_value: ~
183
+ /N9K/:
184
+ default_value: 'NXAPI N9K'
185
+ ")
186
+ end
187
+
188
+ def test_load_generic
189
+ write_variants
190
+ reference = load_file
191
+ assert_equal('generic', reference.lookup('test', 'name').default_value)
183
192
  end
184
193
 
185
194
  def test_load_n9k
186
- reference = CommandReference.new('N9K-C9396PX')
187
- assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
188
- assert(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
189
- refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
190
- refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
195
+ write_variants
196
+ reference = load_file(platform: :nexus, product: 'N9K-C9396PX', cli: true)
197
+ assert_equal('NXAPI N9K', reference.lookup('test', 'name').default_value)
191
198
  end
192
199
 
193
200
  def test_load_n7k
194
- reference = CommandReference.new('N7K-C7010')
195
- assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
196
- refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
197
- assert(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
198
- refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
201
+ write_variants
202
+ reference = load_file(platform: :nexus, product: 'N7K-C7010', cli: true)
203
+ assert_equal(nil, reference.lookup('test', 'name').default_value)
199
204
  end
200
205
 
201
206
  def test_load_n3k_3064
202
- reference = CommandReference.new('N3K-C3064PQ-10GE')
203
- assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
204
- refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
205
- refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
206
- assert(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
207
+ write_variants
208
+ reference = load_file(platform: :nexus, product: 'N3K-C3064PQ-10GE',
209
+ cli: true)
210
+ assert_equal('NXAPI base', reference.lookup('test', 'name').default_value)
211
+ end
212
+
213
+ def write_exclusions
214
+ write("
215
+ _exclude:
216
+ - /N9K/
217
+
218
+ name:
219
+ _exclude: [/C30../, /C31../]
220
+ default_value: hello
221
+
222
+ rank:
223
+ default_value: 27
224
+ ")
225
+ end
226
+
227
+ def test_exclude_whole_file
228
+ write_exclusions
229
+ reference = load_file(product: 'N9K-C9396PX')
230
+
231
+ ref = reference.lookup('test', 'name')
232
+ # default_value is nil for an unsupported property
233
+ assert(ref.default_value?, 'default_value? returned false')
234
+ assert_nil(ref.default_value)
235
+ refute(ref.config_get?)
236
+ assert_raises(Cisco::UnsupportedError) { ref.config_get }
237
+
238
+ # Because the whole file is excluded, we don't know which
239
+ # attributes are 'valid' - so any attribute name is permitted:
240
+ ref = reference.lookup('test', 'foobar')
241
+ assert(ref.default_value?)
242
+ assert_nil(ref.default_value)
243
+ refute(ref.config_get?)
244
+ assert_raises(Cisco::UnsupportedError) { ref.config_get }
245
+ end
246
+
247
+ def test_exclude_whole_item
248
+ write_exclusions
249
+ reference = load_file(product: 'N3K-C3172PQ')
250
+ assert_equal(27, reference.lookup('test', 'rank').default_value)
251
+
252
+ ref = reference.lookup('test', 'name')
253
+ assert(ref.default_value?)
254
+ assert_nil(ref.default_value)
255
+ refute(ref.config_get?)
256
+ assert_raises(Cisco::UnsupportedError) { ref.config_get }
257
+ end
258
+
259
+ def test_exclude_no_exclusion
260
+ write_exclusions
261
+ reference = load_file(product: 'N7K-C7010')
262
+ assert_equal('hello', reference.lookup('test', 'name').default_value)
263
+ assert_equal(27, reference.lookup('test', 'rank').default_value)
264
+ end
265
+
266
+ def test_exclude_implicit
267
+ write("
268
+ name:
269
+ cli_nexus:
270
+ default_value: 1
271
+ ")
272
+ reference = load_file(platform: 'nexus', cli: false)
273
+ ref = reference.lookup('test', 'name')
274
+ assert(ref.default_value?)
275
+ assert_nil(ref.default_value)
276
+ end
277
+
278
+ def test_default_only
279
+ write("
280
+ name:
281
+ default_only: 'x'
282
+ ")
283
+ reference = load_file
284
+ ref = reference.lookup('test', 'name')
285
+ assert(ref.default_only?)
286
+ assert(ref.default_value?)
287
+ assert_equal('x', ref.default_value)
288
+ refute(ref.config_set?)
289
+ assert_raises(Cisco::UnsupportedError) { ref.config_set }
290
+ end
291
+
292
+ def test_default_only_cleanup
293
+ write("
294
+ name:
295
+ default_only: 'x'
296
+ config_set: 'foo'
297
+ ")
298
+ reference = load_file
299
+ ref = reference.lookup('test', 'name')
300
+ assert(ref.default_only?)
301
+ assert(ref.default_value?)
302
+ assert_equal('x', ref.default_value)
303
+ refute(ref.config_set?)
304
+ assert_raises(Cisco::UnsupportedError) { ref.config_set }
305
+
306
+ write("
307
+ name2:
308
+ config_set: 'foo'
309
+ default_only: 'x'
310
+ ")
311
+ reference = load_file
312
+ ref = reference.lookup('test', 'name2')
313
+ assert(ref.default_only?)
314
+ assert(ref.default_value?)
315
+ assert_equal('x', ref.default_value)
316
+ refute(ref.config_set?)
317
+ assert_raises(Cisco::UnsupportedError) { ref.config_set }
318
+ end
319
+
320
+ def test_default_only_default_value
321
+ write("
322
+ name:
323
+ kind: int
324
+ cli_nexus:
325
+ default_value: 10
326
+ config_set: 'hello'
327
+ default_only: 0
328
+ ")
329
+ reference = load_file
330
+ ref = reference.lookup('test', 'name')
331
+ assert(ref.default_only?)
332
+ assert(ref.default_value?)
333
+ assert_equal(0, ref.default_value)
334
+ refute(ref.config_set?)
335
+ assert_raises(Cisco::UnsupportedError) { ref.config_set }
336
+
337
+ reference = load_file(cli: true, platform: 'nexus')
338
+ ref = reference.lookup('test', 'name')
339
+ refute(ref.default_only?)
340
+ assert(ref.default_value?)
341
+ assert_equal(10, ref.default_value)
342
+ assert(ref.config_set?)
343
+ assert_raises(IndexError) { ref.config_get }
344
+ end
345
+
346
+ def test_config_get_token_hash_substitution
347
+ write(%q(
348
+ name:
349
+ config_get_token:
350
+ ['/^router ospf <name>$/',
351
+ '/^vrf <vrf>$/',
352
+ '/^router-id (\S+)$/']
353
+ test2:
354
+ config_get_token:
355
+ ['abc <val1> def',
356
+ 'xyz <val2>']
357
+ ))
358
+ reference = load_file
359
+ ref = reference.lookup('test', 'name')
360
+ token = ref.config_get_token(name: 'red')
361
+ assert_equal([/^router ospf red$/, /^router-id (\S+)$/],
362
+ token)
363
+ token = ref.config_get_token(name: 'blue', vrf: 'green')
364
+ assert_equal([/^router ospf blue$/, /^vrf green$/, /^router-id (\S+)$/],
365
+ token)
366
+ ref = reference.lookup('test', 'test2')
367
+ token = ref.config_get_token(val1: '1', val2: '2')
368
+ assert_equal(['abc 1 def', 'xyz 2'], token)
369
+ token = ref.config_get_token(val1: '1', extra_val: 'asdf')
370
+ assert_equal(['abc 1 def'], token)
371
+ token = ref.config_get_token(val2: '2')
372
+ assert_equal(['xyz 2'], token)
373
+ assert_raises(ArgumentError) { token = ref.config_get_token }
374
+ assert_raises(ArgumentError) { token = ref.config_get_token(extra: 'x') }
375
+ end
376
+
377
+ def test_config_get_token_printf_substitution
378
+ write("
379
+ name:
380
+ config_get_token: ['/^interface %s$/i', '/^description (.*)/']
381
+ ")
382
+ reference = load_file
383
+ ref = reference.lookup('test', 'name')
384
+ token = ref.config_get_token('Ethernet1/1')
385
+ assert_equal([%r{^interface Ethernet1/1$}i, /^description (.*)/],
386
+ token)
387
+ # Negative tests - wrong # of args
388
+ assert_raises(ArgumentError) { ref.config_get_token }
389
+ assert_raises(ArgumentError) { ref.config_get_token('eth1/1', 'foo') }
207
390
  end
208
391
  end