cisco_node_utils 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +81 -1
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +72 -6
  6. data/CONTRIBUTING.md +32 -7
  7. data/README.md +70 -7
  8. data/Rakefile +17 -0
  9. data/bin/check_metric_limits.rb +109 -0
  10. data/bin/git/hooks/commit-msg/enforce_style +81 -0
  11. data/bin/git/hooks/hook_lib +108 -0
  12. data/bin/git/hooks/hooks-wrapper +38 -0
  13. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  14. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  15. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  16. data/bin/git/hooks/post-merge/update-hooks +6 -0
  17. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  18. data/bin/git/hooks/pre-commit/rubocop +20 -0
  19. data/bin/git/hooks/pre-commit/validate-diffs +31 -0
  20. data/bin/git/hooks/pre-push/check-changelog +24 -0
  21. data/bin/git/hooks/pre-push/rubocop +7 -0
  22. data/bin/git/update-hooks +65 -0
  23. data/cisco_node_utils.gemspec +9 -3
  24. data/docs/README-develop-best-practices.md +404 -0
  25. data/docs/README-develop-node-utils-APIs.md +215 -365
  26. data/docs/README-maintainers.md +33 -3
  27. data/docs/template-router.rb +89 -91
  28. data/docs/template-test_router.rb +52 -55
  29. data/lib/.rubocop.yml +18 -0
  30. data/lib/cisco_node_utils.rb +2 -19
  31. data/lib/cisco_node_utils/README_YAML.md +1 -9
  32. data/lib/cisco_node_utils/bgp.rb +664 -0
  33. data/lib/cisco_node_utils/bgp_af.rb +530 -0
  34. data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
  35. data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
  36. data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
  37. data/lib/cisco_node_utils/command_reference.rb +72 -74
  38. data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
  39. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
  40. data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
  41. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
  42. data/lib/cisco_node_utils/configparser_lib.rb +152 -147
  43. data/lib/cisco_node_utils/dns_domain.rb +79 -0
  44. data/lib/cisco_node_utils/domain_name.rb +71 -0
  45. data/lib/cisco_node_utils/interface.rb +167 -161
  46. data/lib/cisco_node_utils/interface_ospf.rb +78 -81
  47. data/lib/cisco_node_utils/name_server.rb +64 -0
  48. data/lib/cisco_node_utils/node.rb +154 -198
  49. data/lib/cisco_node_utils/node_util.rb +61 -0
  50. data/lib/cisco_node_utils/ntp_config.rb +65 -0
  51. data/lib/cisco_node_utils/ntp_server.rb +76 -0
  52. data/lib/cisco_node_utils/platform.rb +174 -165
  53. data/lib/cisco_node_utils/radius_global.rb +146 -0
  54. data/lib/cisco_node_utils/radius_server.rb +295 -0
  55. data/lib/cisco_node_utils/router_ospf.rb +59 -63
  56. data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
  57. data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
  58. data/lib/cisco_node_utils/snmpgroup.rb +22 -23
  59. data/lib/cisco_node_utils/snmpserver.rb +99 -103
  60. data/lib/cisco_node_utils/snmpuser.rb +294 -274
  61. data/lib/cisco_node_utils/syslog_server.rb +92 -0
  62. data/lib/cisco_node_utils/syslog_settings.rb +69 -0
  63. data/lib/cisco_node_utils/tacacs_server.rb +137 -133
  64. data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
  65. data/lib/cisco_node_utils/version.rb +2 -1
  66. data/lib/cisco_node_utils/vlan.rb +28 -31
  67. data/lib/cisco_node_utils/vrf.rb +80 -0
  68. data/lib/cisco_node_utils/vtp.rb +100 -97
  69. data/lib/cisco_node_utils/yum.rb +15 -17
  70. data/tests/.rubocop.yml +15 -0
  71. data/tests/basetest.rb +81 -36
  72. data/tests/ciscotest.rb +38 -78
  73. data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
  74. data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
  75. data/tests/test_bgp_af.rb +920 -0
  76. data/tests/test_bgp_neighbor.rb +403 -0
  77. data/tests/test_bgp_neighbor_af.rb +589 -0
  78. data/tests/test_command_config.rb +65 -62
  79. data/tests/test_command_reference.rb +31 -45
  80. data/tests/test_dns_domain.rb +113 -0
  81. data/tests/test_domain_name.rb +86 -0
  82. data/tests/test_interface.rb +424 -548
  83. data/tests/test_interface_ospf.rb +248 -432
  84. data/tests/test_interface_svi.rb +56 -79
  85. data/tests/test_interface_switchport.rb +196 -272
  86. data/tests/test_name_server.rb +85 -0
  87. data/tests/test_node.rb +7 -6
  88. data/tests/test_node_ext.rb +133 -186
  89. data/tests/test_ntp_config.rb +49 -0
  90. data/tests/test_ntp_server.rb +74 -0
  91. data/tests/test_platform.rb +58 -37
  92. data/tests/test_radius_global.rb +78 -0
  93. data/tests/test_radius_server.rb +185 -0
  94. data/tests/test_router_bgp.rb +838 -0
  95. data/tests/test_router_ospf.rb +49 -80
  96. data/tests/test_router_ospf_vrf.rb +274 -392
  97. data/tests/test_snmpcommunity.rb +128 -172
  98. data/tests/test_snmpgroup.rb +12 -14
  99. data/tests/test_snmpserver.rb +160 -189
  100. data/tests/test_snmpuser.rb +568 -717
  101. data/tests/test_syslog_server.rb +88 -0
  102. data/tests/test_syslog_settings.rb +54 -0
  103. data/tests/test_tacacs_server.rb +113 -148
  104. data/tests/test_tacacs_server_host.rb +108 -161
  105. data/tests/test_vlan.rb +63 -79
  106. data/tests/test_vrf.rb +92 -0
  107. data/tests/test_vtp.rb +108 -126
  108. data/tests/test_yum.rb +47 -41
  109. metadata +92 -56
  110. data/.rubocop_todo.yml +0 -293
  111. data/docs/.rubocop.yml +0 -13
  112. data/docs/template-feature.rb +0 -45
  113. data/docs/template-test_feature.rb +0 -51
  114. data/tests/test_all_cisco.rb +0 -46
@@ -12,39 +12,37 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require File.expand_path("../ciscotest", __FILE__)
16
- require File.expand_path("../../lib/cisco_node_utils/snmpgroup", __FILE__)
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/snmpgroup'
17
17
 
18
+ # TestSnmpGroup - Minitest for SnmpGroup node utility.
18
19
  class TestSnmpGroup < CiscoTestCase
19
20
  # NXOS snmp groups will not be empty
20
21
  def test_snmpgroup_collection_not_empty
21
22
  snmpgroups = SnmpGroup.groups
22
- assert_equal(false, snmpgroups.empty?(),
23
- "SnmpGroup collection is empty")
24
- snmpgroups = nil
23
+ refute_empty(snmpgroups)
25
24
  end
26
25
 
27
26
  def test_snmpgroup_collection_valid
28
27
  snmpgroups = SnmpGroup.groups
29
- s = @device.cmd("show snmp group | include Role | no-more")
30
- snmpgroups.each do |name, snmpgroup|
28
+ s = @device.cmd('show snmp group | include Role | no-more')
29
+ snmpgroups.each_value do |snmpgroup|
31
30
  line = /Role:\s#{snmpgroup.name}/.match(s)
32
31
  # puts "line: #{line}"
33
32
  assert_equal(false, line.nil?)
34
33
  end
35
- snmpgroups = nil
36
34
  end
37
35
 
38
36
  def test_snmpgroup_exists_with_name_empty
39
37
  assert_raises(ArgumentError) do
40
- SnmpGroup.exists?("")
38
+ SnmpGroup.exists?('')
41
39
  end
42
40
  end
43
41
 
44
42
  def test_snmpgroup_exists_with_name_invalid
45
- name = "group-dummy"
43
+ name = 'group-dummy'
46
44
  exist = SnmpGroup.exists?(name)
47
- s = @device.cmd("show snmp group | in Role | no-more")
45
+ s = @device.cmd('show snmp group | in Role | no-more')
48
46
  line = /Role:\s#{name}/.match(s)
49
47
  assert_equal(exist, !line.nil?)
50
48
  end
@@ -56,15 +54,15 @@ class TestSnmpGroup < CiscoTestCase
56
54
  end
57
55
 
58
56
  def test_snmpgroup_exists_with_name_valid
59
- name = "network-admin"
57
+ name = 'network-admin'
60
58
  exist = SnmpGroup.exists?(name)
61
- s = @device.cmd("show snmp group | in Role | no-more")
59
+ s = @device.cmd('show snmp group | in Role | no-more')
62
60
  line = /Role:\s#{name}/.match(s)
63
61
  assert_equal(exist, !line.nil?)
64
62
  end
65
63
 
66
64
  def test_snmpgroup_get_name
67
- name = "network-operator"
65
+ name = 'network-operator'
68
66
  snmpgroup = SnmpGroup.new(name)
69
67
  assert_equal(snmpgroup.name, name)
70
68
  end
@@ -12,43 +12,57 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require File.expand_path("../ciscotest", __FILE__)
16
- require File.expand_path("../../lib/cisco_node_utils/snmpserver", __FILE__)
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/snmpserver'
17
17
 
18
+ # TestSnmpServer - Minitest for SnmpServer node utility
18
19
  class TestSnmpServer < CiscoTestCase
19
20
  DEFAULT_SNMP_SERVER_AAA_USER_CACHE_TIMEOUT = 3600
20
- DEFAULT_SNMP_SERVER_LOCATION = ""
21
- DEFAULT_SNMP_SERVER_CONTACT = ""
21
+ DEFAULT_SNMP_SERVER_LOCATION = ''
22
+ DEFAULT_SNMP_SERVER_CONTACT = ''
22
23
  DEFAULT_SNMP_SERVER_PACKET_SIZE = 1500
23
24
  DEFAULT_SNMP_SERVER_GLOBAL_ENFORCE_PRIVACY = false
24
25
  DEFAULT_SNMP_SERVER_PROTOCOL_ENABLE = true
25
26
  DEFAULT_SNMP_SERVER_TCP_SESSION_AUTH = true
26
27
 
28
+ def setup
29
+ super
30
+ @default_show_command = 'show run snmp all | no-more'
31
+ # set all commands to defaults
32
+ s = SnmpServer.new
33
+ s.aaa_user_cache_timeout = s.default_aaa_user_cache_timeout
34
+ s.contact = s.default_contact
35
+ s.global_enforce_priv = s.default_global_enforce_priv
36
+ s.location = s.default_location
37
+ s.packet_size = 0
38
+ s.protocol = s.default_protocol
39
+ s.tcp_session_auth = s.default_tcp_session_auth
40
+ end
41
+
27
42
  def test_snmpserver_aaa_user_cache_timeout_set_invalid_upper_range
28
43
  snmpserver = SnmpServer.new
29
44
  assert_raises(Cisco::CliError) do
30
- snmpserver.aaa_user_cache_timeout=86401
45
+ snmpserver.aaa_user_cache_timeout = 86_401
31
46
  end
32
47
  end
33
48
 
34
49
  def test_snmpserver_aaa_user_cache_timeout_set_invalid_lower_range
35
50
  snmpserver = SnmpServer.new
36
51
  assert_raises(Cisco::CliError) do
37
- snmpserver.aaa_user_cache_timeout=0
52
+ snmpserver.aaa_user_cache_timeout = 0
38
53
  end
39
54
  end
40
55
 
41
56
  def test_snmpserver_aaa_user_cache_timeout_set_valid
42
57
  snmpserver = SnmpServer.new
43
58
  newtimeout = 1400
44
- snmpserver.aaa_user_cache_timeout=newtimeout
45
- s = @device.cmd("show run snmp all | no-more")
46
- cmd='snmp-server aaa-user cache-timeout'
47
- line = /#{cmd} (\d+)/.match(s)
48
- timeout = line.to_s.split(" ").last.to_i
59
+ snmpserver.aaa_user_cache_timeout = newtimeout
60
+ line = assert_show_match(
61
+ pattern: /snmp-server aaa-user cache-timeout (\d+)/)
62
+ timeout = line.to_s.split(' ').last.to_i
49
63
  assert_equal(timeout, newtimeout)
50
64
  # set to default
51
- snmpserver.aaa_user_cache_timeout=
65
+ snmpserver.aaa_user_cache_timeout =
52
66
  snmpserver.default_aaa_user_cache_timeout
53
67
  end
54
68
 
@@ -56,161 +70,157 @@ class TestSnmpServer < CiscoTestCase
56
70
  snmpserver = SnmpServer.new
57
71
  snmpserver.aaa_user_cache_timeout =
58
72
  snmpserver.default_aaa_user_cache_timeout
59
- s = @device.cmd("show run snmp all | no-more")
60
- cmd='snmp-server aaa-user cache-timeout'
61
- line = /#{cmd} (\d+)/.match(s)
62
- timeout = line.to_s.split(" ").last.to_i
73
+ line = assert_show_match(
74
+ pattern: /snmp-server aaa-user cache-timeout (\d+)/)
75
+ timeout = line.to_s.split(' ').last.to_i
63
76
  assert_equal(timeout, snmpserver.aaa_user_cache_timeout)
64
77
  end
65
78
 
66
79
  def test_snmpserver_aaa_user_cache_timeout_get
67
80
  snmpserver = SnmpServer.new
68
- s = @device.cmd("show run snmp all | no-more")
69
- cmd='snmp-server aaa-user cache-timeout'
70
- line = /#{cmd} (\d+)/.match(s)
71
- timeout = line.to_s.split(" ").last.to_i
81
+ line = assert_show_match(
82
+ pattern: /snmp-server aaa-user cache-timeout (\d+)/)
83
+ timeout = line.to_s.split(' ').last.to_i
72
84
  assert_equal(timeout, snmpserver.aaa_user_cache_timeout)
73
85
  end
74
86
 
75
87
  def test_snmpserver_sys_contact_get
76
88
  snmpserver = SnmpServer.new
77
- snmpserver.contact = "test-contact"
78
- s = @device.cmd("show snmp | no-more")
79
- line = /sys contact: [^\n\r]+/.match(s)
80
- contact = ""
81
- contact = line.to_s.gsub("sys contact:", "").strip unless line.nil?
89
+ snmpserver.contact = 'test-contact'
90
+ line = assert_show_match(command: 'show snmp | no-more',
91
+ pattern: /sys contact: [^\n\r]+/)
92
+ contact = ''
93
+ contact = line.to_s.gsub('sys contact:', '').strip unless line.nil?
82
94
  # puts "contact : #{line}, #{snmpserver.contact}"
83
95
  assert_equal(contact, snmpserver.contact)
84
96
  # set to default
85
- snmpserver.contact=snmpserver.default_contact
97
+ snmpserver.contact = snmpserver.default_contact
86
98
  end
87
99
 
88
100
  def test_snmpserver_sys_contact_set_invalid
89
101
  snmpserver = SnmpServer.new
90
102
  assert_raises(TypeError) do
91
- snmpserver.contact=123
103
+ snmpserver.contact = 123
92
104
  end
93
105
  end
94
106
 
95
107
  def test_snmpserver_sys_contact_set_zero_length
96
108
  snmpserver = SnmpServer.new
97
- newcontact = ""
98
- snmpserver.contact=newcontact
109
+ newcontact = ''
110
+ snmpserver.contact = newcontact
99
111
  assert_equal(newcontact, snmpserver.contact)
100
112
  # set to default
101
- snmpserver.contact=snmpserver.default_contact
113
+ snmpserver.contact = snmpserver.default_contact
102
114
  end
103
115
 
104
116
  def test_snmpserver_sys_contact_set_valid
105
117
  snmpserver = SnmpServer.new
106
- newcontact = "mvenkata_test# contact"
107
- snmpserver.contact=newcontact
108
- s = @device.cmd("show snmp | no-more")
109
- line = /sys contact: [^\n\r]+/.match(s)
118
+ newcontact = 'mvenkata_test# contact'
119
+ snmpserver.contact = newcontact
120
+ line = assert_show_match(command: 'show snmp | no-more',
121
+ pattern: /sys contact: [^\n\r]+/)
110
122
  # puts "line: #{line}"
111
- contact = line.to_s.gsub("sys contact:", "").strip
123
+ contact = line.to_s.gsub('sys contact:', '').strip
112
124
  assert_equal(contact, newcontact)
113
125
  # set to default
114
- snmpserver.contact=snmpserver.default_contact
126
+ snmpserver.contact = snmpserver.default_contact
115
127
  end
116
128
 
117
129
  def test_snmpserver_sys_contact_set_special_chars
118
130
  snmpserver = SnmpServer.new
119
131
  # newcontact = "Test{}(%tuvy@_cisco contact$#!@1234^&*()_+"
120
- newcontact = "user@example.com @$%&}test ]|[#_@test contact"
121
- snmpserver.contact=newcontact
122
- s = @device.cmd("show snmp | no-more")
123
- line = /sys contact: [^\n\r]+/.match(s)
132
+ newcontact = 'user@example.com @$%&}test ]|[#_@test contact'
133
+ snmpserver.contact = newcontact
134
+ line = assert_show_match(command: 'show snmp | no-more',
135
+ pattern: /sys contact: [^\n\r]+/)
124
136
  # puts "line: #{line}"
125
- contact = line.to_s.gsub("sys contact:", "").strip
137
+ contact = line.to_s.gsub('sys contact:', '').strip
126
138
  assert_equal(contact, newcontact)
127
139
  # set to default
128
- snmpserver.contact=snmpserver.default_contact
140
+ snmpserver.contact = snmpserver.default_contact
129
141
  end
130
142
 
131
143
  def test_snmpserver_sys_contact_set_default
132
144
  snmpserver = SnmpServer.new
133
145
  snmpserver.contact = snmpserver.default_contact
134
- s = @device.cmd("show snmp | no-more")
135
- line = /sys contact: [^\n\r]+/.match(s)
136
- contact = ""
137
- contact = line.to_s.gsub("sys contact:", "").strip unless line.nil?
146
+ line = assert_show_match(command: 'show snmp | no-more',
147
+ pattern: /sys contact: [^\n\r]*/)
148
+ contact = ''
149
+ contact = line.to_s.gsub('sys contact:', '').strip unless line.nil?
138
150
  assert_equal(contact, snmpserver.default_contact)
139
151
  end
140
152
 
141
153
  def test_snmpserver_sys_location_get
142
154
  snmpserver = SnmpServer.new
143
155
  # set location
144
- snmpserver.location = "test-location"
145
- s = @device.cmd("show snmp | no-more")
146
- line = /sys location: [^\n\r]+/.match(s)
147
- location=""
148
- location = line.to_s.gsub("sys location:", "").strip unless line.nil?
156
+ snmpserver.location = 'test-location'
157
+ line = assert_show_match(command: 'show snmp | no-more',
158
+ pattern: /sys location: [^\n\r]+/)
159
+ location = ''
160
+ location = line.to_s.gsub('sys location:', '').strip unless line.nil?
149
161
  # puts "location : #{location}, #{snmpserver.location}"
150
162
  assert_equal(location, snmpserver.location)
151
163
  # set to default
152
- snmpserver.location=snmpserver.default_location
164
+ snmpserver.location = snmpserver.default_location
153
165
  end
154
166
 
155
167
  def test_snmpserver_sys_location_set_invalid
156
168
  snmpserver = SnmpServer.new
157
169
  assert_raises(TypeError) do
158
- snmpserver.location=123
170
+ snmpserver.location = 123
159
171
  end
160
172
  end
161
173
 
162
174
  def test_snmpserver_sys_location_set_zero_length
163
175
  snmpserver = SnmpServer.new
164
- newlocation = ""
165
- snmpserver.location=newlocation
176
+ newlocation = ''
177
+ snmpserver.location = newlocation
166
178
  assert_equal(newlocation, snmpserver.location)
167
179
  end
168
180
 
169
181
  def test_snmpserver_sys_location_set_valid
170
182
  snmpserver = SnmpServer.new
171
- newlocation = "bxb-300-2-1 test location"
172
- snmpserver.location=newlocation
173
- s = @device.cmd("show snmp | no-more")
174
- line = /sys location: [^\n\r]+/.match(s)
175
- location = line.to_s.gsub("sys location:", "").strip
183
+ newlocation = 'bxb-300-2-1 test location'
184
+ snmpserver.location = newlocation
185
+ line = assert_show_match(command: 'show snmp | no-more',
186
+ pattern: /sys location: [^\n\r]+/)
187
+ location = line.to_s.gsub('sys location:', '').strip
176
188
  assert_equal(location, newlocation)
177
189
  # set to default
178
- snmpserver.location=snmpserver.default_location
190
+ snmpserver.location = snmpserver.default_location
179
191
  end
180
192
 
181
193
  def test_snmpserver_sys_location_set_special_chars
182
194
  snmpserver = SnmpServer.new
183
- newlocation = "bxb-300 2nd floor test !$%^33&&*) location"
184
- snmpserver.location=newlocation
185
- s = @device.cmd("show snmp | no-more")
186
- line = /sys location: [^\n\r]+/.match(s)
187
- location = line.to_s.gsub("sys location:", "").strip
195
+ newlocation = 'bxb-300 2nd floor test !$%^33&&*) location'
196
+ snmpserver.location = newlocation
197
+ line = assert_show_match(command: 'show snmp | no-more',
198
+ pattern: /sys location: [^\n\r]+/)
199
+ location = line.to_s.gsub('sys location:', '').strip
188
200
  assert_equal(location, newlocation)
189
201
  # set to default
190
- snmpserver.location=snmpserver.default_location
202
+ snmpserver.location = snmpserver.default_location
191
203
  end
192
204
 
193
205
  def test_snmpserver_sys_location_set_default
194
206
  snmpserver = SnmpServer.new
195
207
  # snmpserver.location = snmpserver.default_location
196
- snmpserver.location = "FOO"
197
- s = @device.cmd("show snmp | no-more")
198
- line = /sys location: [^\n\r]+/.match(s)
199
- location = ""
200
- location = line.to_s.gsub("sys location:", "").strip unless line.nil?
208
+ snmpserver.location = 'FOO'
209
+ line = assert_show_match(command: 'show snmp | no-more',
210
+ pattern: /sys location: [^\n\r]+/)
211
+ location = ''
212
+ location = line.to_s.gsub('sys location:', '').strip unless line.nil?
201
213
  assert_equal(location, snmpserver.location)
202
214
  # set to default
203
- snmpserver.location=snmpserver.default_location
215
+ snmpserver.location = snmpserver.default_location
204
216
  end
205
217
 
206
218
  def test_snmpserver_packetsize_get
207
219
  snmpserver = SnmpServer.new
208
- snmpserver.packet_size=2000
209
- s = @device.cmd("show run snmp all | no-more")
210
- cmd='snmp-server packetsize'
211
- line = /#{cmd} (\d+)/.match(s)
220
+ snmpserver.packet_size = 2000
221
+ line = assert_show_match(pattern: /snmp-server packetsize (\d+)/)
212
222
  packetsize = 0
213
- packetsize = line.to_s.split(" ").last.to_i unless line.nil?
223
+ packetsize = line.to_s.split(' ').last.to_i unless line.nil?
214
224
  assert_equal(packetsize, snmpserver.packet_size)
215
225
  # unset to default
216
226
  snmpserver.packet_size = 0
@@ -218,9 +228,9 @@ class TestSnmpServer < CiscoTestCase
218
228
 
219
229
  def test_snmpserver_packetsize_set_invalid_upper_range
220
230
  snmpserver = SnmpServer.new
221
- newpacketsize = 17383
231
+ newpacketsize = 17_383
222
232
  assert_raises(Cisco::CliError) do
223
- snmpserver.packet_size=newpacketsize
233
+ snmpserver.packet_size = newpacketsize
224
234
  end
225
235
  end
226
236
 
@@ -228,18 +238,16 @@ class TestSnmpServer < CiscoTestCase
228
238
  snmpserver = SnmpServer.new
229
239
  newpacketsize = 480
230
240
  assert_raises(Cisco::CliError) do
231
- snmpserver.packet_size=newpacketsize
241
+ snmpserver.packet_size = newpacketsize
232
242
  end
233
243
  end
234
244
 
235
245
  def test_snmpserver_packetsize_set_valid
236
246
  snmpserver = SnmpServer.new
237
247
  newpacketsize = 1600
238
- snmpserver.packet_size=newpacketsize
239
- s = @device.cmd("show run snmp all | no-more")
240
- cmd='snmp-server packetsize'
241
- line = /#{cmd} (\d+)/.match(s)
242
- packetsize = line.to_s.split(" ").last.to_i
248
+ snmpserver.packet_size = newpacketsize
249
+ line = assert_show_match(pattern: /snmp-server packetsize (\d+)/)
250
+ packetsize = line.to_s.split(' ').last.to_i
243
251
  assert_equal(packetsize, newpacketsize)
244
252
  # unset to default
245
253
  snmpserver.packet_size = 0
@@ -247,30 +255,22 @@ class TestSnmpServer < CiscoTestCase
247
255
 
248
256
  def test_snmpserver_packetsize_set_default
249
257
  snmpserver = SnmpServer.new
250
-
251
- packetsize = DEFAULT_SNMP_SERVER_PACKET_SIZE
252
- s = @device.cmd("show run snmp all | no-more")
253
- cmd='snmp-server packetsize'
254
- line = /#{cmd} (\d+)/.match(s)
255
- packetsize = line.to_s.split(" ").last.to_i
256
- assert_equal(packetsize, snmpserver.packet_size,
257
- "Error: Snmp Server, packet size not default")
258
+ refute_show_match(pattern: /snmp-server packetsize (\d+)/)
259
+ assert_equal(0, snmpserver.packet_size,
260
+ 'Error: Snmp Server, packet size not default')
258
261
 
259
262
  snmpserver.packet_size = 850
260
- s = @device.cmd("show run snmp all | no-more")
261
- cmd='snmp-server packetsize'
262
- line = /#{cmd} (\d+)/.match(s)
263
- packetsize = line.to_s.split(" ").last.to_i
263
+ line = assert_show_match(pattern: /snmp-server packetsize (\d+)/)
264
+ packetsize = line.to_s.split(' ').last.to_i
264
265
  assert_equal(packetsize, snmpserver.packet_size,
265
- "Error: Snmp Server, packet size not default")
266
+ 'Error: Snmp Server, packet size not default')
266
267
 
267
268
  snmpserver.packet_size = snmpserver.default_packet_size
268
- s = @device.cmd("show run snmp all | no-more")
269
- cmd='snmp-server packetsize'
270
- line = /#{cmd} (\d+)/.match(s)
271
- packetsize = line.to_s.split(" ").last.to_i
269
+ # TODO: this seems weird, why is default_packet_size not 0 as above?
270
+ line = assert_show_match(pattern: /snmp-server packetsize (\d+)/)
271
+ packetsize = line.to_s.split(' ').last.to_i
272
272
  assert_equal(packetsize, snmpserver.packet_size,
273
- "Error: Snmp Server, packet size not default")
273
+ 'Error: Snmp Server, packet size not default')
274
274
  # set to default
275
275
  snmpserver.packet_size = 0
276
276
  end
@@ -281,17 +281,14 @@ class TestSnmpServer < CiscoTestCase
281
281
  # Get orginal packet size
282
282
  org_packet_size = snmpserver.packet_size
283
283
  snmpserver.packet_size = 0
284
- s = @device.cmd("show run snmp all | no-more")
285
- cmd='snmp-server packetsize'
286
- line = /#{cmd} (\d+)/.match(s)
287
- packetsize = line.to_s.split(" ").last.to_i
288
- assert_equal(packetsize, snmpserver.packet_size,
289
- "Error: Snmp Server, packet size not unset")
284
+ refute_show_match(pattern: /snmp-server packetsize (\d+)/)
285
+ assert_equal(0, snmpserver.packet_size,
286
+ 'Error: Snmp Server, packet size not unset')
290
287
 
291
288
  # Restore packet size
292
289
  snmpserver.packet_size = org_packet_size
293
290
  assert_equal(org_packet_size, snmpserver.packet_size,
294
- "Error: Snmp Server, packet size not restored")
291
+ 'Error: Snmp Server, packet size not restored')
295
292
  # set to default
296
293
  snmpserver.packet_size = 0
297
294
  end
@@ -299,145 +296,119 @@ class TestSnmpServer < CiscoTestCase
299
296
  def test_snmpserver_global_enforce_priv_get_default
300
297
  snmpserver = SnmpServer.new
301
298
  # default is false
302
- snmpserver.global_enforce_priv=false
299
+ snmpserver.global_enforce_priv = false
303
300
  device_enabled = snmpserver.global_enforce_priv?
304
- s = @device.cmd("show run snmp all | no-more")
305
- cmd='no snmp-server globalEnforcePriv'
306
- line = /#{cmd}/.match(s)
307
- assert_equal(line.nil?, device_enabled)
301
+ if device_enabled
302
+ refute_show_match(pattern: /no snmp-server globalEnforcePriv/)
303
+ else
304
+ assert_show_match(pattern: /no snmp-server globalEnforcePriv/)
305
+ end
308
306
  # set to default
309
- snmpserver.global_enforce_priv=snmpserver.default_global_enforce_priv
307
+ snmpserver.global_enforce_priv = snmpserver.default_global_enforce_priv
310
308
  end
311
309
 
312
310
  def test_snmpserver_global_enforce_priv_get_enabled
313
311
  snmpserver = SnmpServer.new
314
- snmpserver.global_enforce_priv=true
312
+ snmpserver.global_enforce_priv = true
315
313
  device_enabled = snmpserver.global_enforce_priv?
316
- s = @device.cmd("show run snmp all | no-more")
317
- cmd='snmp-server globalEnforcePriv'
318
- line = /#{cmd}/.match(s)
319
- assert_equal(!line.nil?, device_enabled)
314
+ if device_enabled
315
+ refute_show_match(pattern: /no snmp-server globalEnforcePriv/)
316
+ else
317
+ assert_show_match(pattern: /no snmp-server globalEnforcePriv/)
318
+ end
320
319
  # set to default
321
- snmpserver.global_enforce_priv=snmpserver.default_global_enforce_priv
320
+ snmpserver.global_enforce_priv = snmpserver.default_global_enforce_priv
322
321
  end
323
322
 
324
323
  def test_snmpserver_global_enforce_priv_set_enabled
325
324
  snmpserver = SnmpServer.new
326
- snmpserver.global_enforce_priv=true
327
- s = @device.cmd("show run snmp all | no-more")
328
- cmd='snmp-server globalEnforcePriv'
329
- line = /#{cmd}/.match(s)
330
- # puts "line : #{line}"
331
- assert_equal(!line.nil?, true)
325
+ snmpserver.global_enforce_priv = true
326
+ assert_show_match(pattern: /snmp-server globalEnforcePriv/)
332
327
  # set to default
333
- snmpserver.global_enforce_priv=snmpserver.default_global_enforce_priv
328
+ snmpserver.global_enforce_priv = snmpserver.default_global_enforce_priv
334
329
  end
335
330
 
336
331
  def test_snmpserver_global_enforce_priv_set_disabled
337
332
  snmpserver = SnmpServer.new
338
- snmpserver.global_enforce_priv=false
339
- s = @device.cmd("show run snmp all | no-more")
340
- cmd='no snmp-server globalEnforcePriv'
341
- line = /#{cmd}/.match(s)
342
- assert_equal(line.nil?, false)
333
+ snmpserver.global_enforce_priv = false
334
+ assert_show_match(pattern: /no snmp-server globalEnforcePriv/)
343
335
  # set to default
344
- snmpserver.global_enforce_priv=snmpserver.default_global_enforce_priv
336
+ snmpserver.global_enforce_priv = snmpserver.default_global_enforce_priv
345
337
  end
346
338
 
347
339
  def test_snmpserver_protocol_get_default
348
340
  snmpserver = SnmpServer.new
349
341
  # set default
350
- snmpserver.protocol=true
351
- device_enabled = snmpserver.protocol?
352
- cmd='^snmp-server protocol enable'
353
- s = @device.cmd("show run snmp all | i '#{cmd}'")
354
- assert_match(/#{cmd}/, s)
342
+ snmpserver.protocol = true
343
+ assert_show_match(pattern: /^snmp-server protocol enable/)
355
344
  # set to default
356
- snmpserver.protocol=snmpserver.default_protocol
345
+ snmpserver.protocol = snmpserver.default_protocol
357
346
  end
358
347
 
359
348
  def test_snmpserver_protocol_get_disabled
360
349
  snmpserver = SnmpServer.new
361
- snmpserver.protocol=false
350
+ snmpserver.protocol = false
362
351
  device_enabled = snmpserver.protocol?
363
- s = @device.cmd("show run snmp all | no-more")
364
- cmd='no snmp-server protocol enable'
365
- line = /#{cmd}/.match(s)
366
- # puts "line #{line}"
367
- assert_equal(line.nil?, device_enabled)
352
+ if device_enabled
353
+ assert_show_match(pattern: /^snmp-server protocol enable/)
354
+ else
355
+ assert_show_match(pattern: /no snmp-server protocol enable/)
356
+ end
368
357
  # set to default
369
- snmpserver.protocol=snmpserver.default_protocol
358
+ snmpserver.protocol = snmpserver.default_protocol
370
359
  end
371
360
 
372
361
  def test_snmpserver_protocol_set_enabled
373
362
  snmpserver = SnmpServer.new
374
- snmpserver.protocol=true
375
- s = @device.cmd("show run snmp all | no-more")
376
- cmd='snmp-server protocol enable'
377
- line = /#{cmd}/.match(s)
378
- # puts "line : #{line}"
379
- assert_equal(!line.nil?, true)
363
+ snmpserver.protocol = true
364
+ assert_show_match(pattern: /^snmp-server protocol enable/)
380
365
  # set to default
381
- snmpserver.protocol=snmpserver.default_protocol
366
+ snmpserver.protocol = snmpserver.default_protocol
382
367
  end
383
368
 
384
369
  def test_snmpserver_protocol_set_disabled
385
370
  snmpserver = SnmpServer.new
386
- snmpserver.protocol=false
387
- s = @device.cmd("show run snmp all | no-more")
388
- cmd='no snmp-server protocol enable'
389
- line = /#{cmd}/.match(s)
390
- # puts "line : #{line}"
391
- assert_equal(line.nil?, false)
371
+ snmpserver.protocol = false
372
+ assert_show_match(pattern: /no snmp-server protocol enable/)
392
373
  # set to default
393
- snmpserver.protocol=snmpserver.default_protocol
374
+ snmpserver.protocol = snmpserver.default_protocol
394
375
  end
395
376
 
396
377
  def test_snmpserver_tcp_session_auth_get_default
397
378
  snmpserver = SnmpServer.new
398
379
  # default value is false
399
- snmpserver.tcp_session_auth=false
380
+ snmpserver.tcp_session_auth = false
400
381
  device_enabled = snmpserver.tcp_session_auth?
401
- s = @device.cmd("show run snmp all | no-more")
402
- cmd='no snmp-server tcp-session auth'
403
- line = /#{cmd}/.match(s)
404
- assert_equal(line.nil?, device_enabled)
382
+ if device_enabled
383
+ assert_show_match(pattern: /^snmp-server tcp-session auth/)
384
+ else
385
+ assert_show_match(pattern: /no snmp-server tcp-session auth/)
386
+ end
405
387
  # set to default
406
- snmpserver.tcp_session_auth=snmpserver.default_tcp_session_auth
388
+ snmpserver.tcp_session_auth = snmpserver.default_tcp_session_auth
407
389
  end
408
390
 
409
391
  def test_snmpserver_tcp_session_auth_get_enabled
410
392
  snmpserver = SnmpServer.new
411
- snmpserver.tcp_session_auth=true
412
- device_enabled = snmpserver.tcp_session_auth?
413
- cmd='^snmp-server tcp-session auth'
414
- s = @device.cmd("show run snmp all | i '#{cmd}'")
415
- assert_match(/#{cmd}/, s)
393
+ snmpserver.tcp_session_auth = true
394
+ assert_show_match(pattern: /^snmp-server tcp-session auth/)
416
395
  # set to default
417
- snmpserver.tcp_session_auth=snmpserver.default_tcp_session_auth
396
+ snmpserver.tcp_session_auth = snmpserver.default_tcp_session_auth
418
397
  end
419
398
 
420
399
  def test_snmpserver_tcp_session_auth_set_enabled
421
400
  snmpserver = SnmpServer.new
422
- snmpserver.tcp_session_auth=true
423
- s = @device.cmd("show run snmp all | no-more")
424
- cmd='snmp-server tcp-session auth'
425
- line = /#{cmd}/.match(s)
426
- # puts "line : #{line}"
427
- assert_equal(!line.nil?, true)
401
+ snmpserver.tcp_session_auth = true
402
+ assert_show_match(pattern: /^snmp-server tcp-session auth/)
428
403
  # set to default
429
- snmpserver.tcp_session_auth=snmpserver.default_tcp_session_auth
404
+ snmpserver.tcp_session_auth = snmpserver.default_tcp_session_auth
430
405
  end
431
406
 
432
407
  def test_snmpserver_tcp_session_auth_set_default
433
408
  snmpserver = SnmpServer.new
434
- snmpserver.tcp_session_auth=false
435
- s = @device.cmd("show run snmp all | no-more")
436
- cmd='no snmp-server tcp-session auth'
437
- line = /#{cmd}/.match(s)
438
- # puts "line : #{line}"
439
- assert_equal(line.nil?, false)
409
+ snmpserver.tcp_session_auth = false
410
+ assert_show_match(pattern: /no snmp-server tcp-session auth/)
440
411
  # set to default
441
- snmpserver.tcp_session_auth=snmpserver.default_tcp_session_auth
412
+ snmpserver.tcp_session_auth = snmpserver.default_tcp_session_auth
442
413
  end
443
414
  end