puppet_x_eos_eapi 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +24 -0
  4. data/LICENSE.txt +202 -0
  5. data/README.md +87 -0
  6. data/Rakefile +1 -0
  7. data/lib/puppet_x/eos/autoload.rb +57 -0
  8. data/lib/puppet_x/eos/eapi.rb +259 -0
  9. data/lib/puppet_x/eos/module_base.rb +37 -0
  10. data/lib/puppet_x/eos/modules/daemon.rb +109 -0
  11. data/lib/puppet_x/eos/modules/extension.rb +167 -0
  12. data/lib/puppet_x/eos/modules/interface.rb +180 -0
  13. data/lib/puppet_x/eos/modules/ipinterface.rb +133 -0
  14. data/lib/puppet_x/eos/modules/mlag.rb +268 -0
  15. data/lib/puppet_x/eos/modules/ntp.rb +129 -0
  16. data/lib/puppet_x/eos/modules/ospf.rb +129 -0
  17. data/lib/puppet_x/eos/modules/portchannel.rb +277 -0
  18. data/lib/puppet_x/eos/modules/radius.rb +367 -0
  19. data/lib/puppet_x/eos/modules/snmp.rb +177 -0
  20. data/lib/puppet_x/eos/modules/switchport.rb +255 -0
  21. data/lib/puppet_x/eos/modules/system.rb +138 -0
  22. data/lib/puppet_x/eos/modules/tacacs.rb +302 -0
  23. data/lib/puppet_x/eos/modules/vlan.rb +179 -0
  24. data/lib/puppet_x/eos/modules/vxlan.rb +132 -0
  25. data/lib/puppet_x/eos/provider.rb +71 -0
  26. data/lib/puppet_x/eos/version.rb +41 -0
  27. data/lib/puppet_x/net_dev/eos_api.rb +1011 -0
  28. data/lib/puppet_x/net_dev/eos_api/common_methods.rb +27 -0
  29. data/lib/puppet_x/net_dev/eos_api/snmp_methods.rb +647 -0
  30. data/lib/puppet_x/net_dev/eos_api/version.rb +8 -0
  31. data/lib/puppet_x_eos_eapi.rb +4 -0
  32. data/puppet_x_eos_eapi.gemspec +31 -0
  33. data/spec/fixtures/fixture_all_portchannel_modes.json +8 -0
  34. data/spec/fixtures/fixture_all_portchannels_detailed.json +15 -0
  35. data/spec/fixtures/fixture_create_vlan_error.json +17 -0
  36. data/spec/fixtures/fixture_create_vlan_success.json +12 -0
  37. data/spec/fixtures/fixture_eapi_conf.yaml +4 -0
  38. data/spec/fixtures/fixture_enable_configure_vlan_3111_name_foo.json +14 -0
  39. data/spec/fixtures/fixture_enable_configure_vlan_foo_name_bar.json +19 -0
  40. data/spec/fixtures/fixture_get_snmp_communities_non_existent_acl.yaml +2 -0
  41. data/spec/fixtures/fixture_get_snmp_location_westeros.json +5 -0
  42. data/spec/fixtures/fixture_portchannel_min_links_1.json +8 -0
  43. data/spec/fixtures/fixture_portchannel_min_links_2.json +8 -0
  44. data/spec/fixtures/fixture_running_config.yaml +1 -0
  45. data/spec/fixtures/fixture_running_configuration_radius_configured.yaml +30 -0
  46. data/spec/fixtures/fixture_running_configuration_radius_default.yaml +29 -0
  47. data/spec/fixtures/fixture_running_configuration_radius_server_groups.yaml +38 -0
  48. data/spec/fixtures/fixture_running_configuration_radius_servers.yaml +34 -0
  49. data/spec/fixtures/fixture_running_configuration_tacacs_configured.yaml +38 -0
  50. data/spec/fixtures/fixture_running_configuration_tacacs_default.yaml +38 -0
  51. data/spec/fixtures/fixture_running_configuration_tacacs_groups.yaml +1 -0
  52. data/spec/fixtures/fixture_running_configuration_tacacs_groups_3.yaml +43 -0
  53. data/spec/fixtures/fixture_running_configuration_tacacs_servers.yaml +41 -0
  54. data/spec/fixtures/fixture_s4_show_etherchannel_detailed.json +9 -0
  55. data/spec/fixtures/fixture_show_flowcontrol_et1.json +5 -0
  56. data/spec/fixtures/fixture_show_interfaces.json +297 -0
  57. data/spec/fixtures/fixture_show_interfaces_switchport_format_text.json +9 -0
  58. data/spec/fixtures/fixture_show_port_channel_summary_2_lags.json +9 -0
  59. data/spec/fixtures/fixture_show_port_channel_summary_static.json +9 -0
  60. data/spec/fixtures/fixture_show_snmp_community.yaml +2 -0
  61. data/spec/fixtures/fixture_show_snmp_contact_empty.json +5 -0
  62. data/spec/fixtures/fixture_show_snmp_contact_name.json +5 -0
  63. data/spec/fixtures/fixture_show_snmp_disabled.json +5 -0
  64. data/spec/fixtures/fixture_show_snmp_enabled.json +5 -0
  65. data/spec/fixtures/fixture_show_snmp_host.yaml +2 -0
  66. data/spec/fixtures/fixture_show_snmp_host_duplicates.yaml +2 -0
  67. data/spec/fixtures/fixture_show_snmp_host_more_duplicates.yaml +2 -0
  68. data/spec/fixtures/fixture_show_snmp_location_empty.json +5 -0
  69. data/spec/fixtures/fixture_show_snmp_trap.yaml +2 -0
  70. data/spec/fixtures/fixture_show_snmp_user.yaml +2 -0
  71. data/spec/fixtures/fixture_show_snmp_user_raw_text.yaml +1 -0
  72. data/spec/fixtures/fixture_show_vlan.json +37 -0
  73. data/spec/fixtures/fixture_show_vlan_3110.json +18 -0
  74. data/spec/fixtures/fixture_show_vlan_4000.json +18 -0
  75. data/spec/fixtures/fixture_snmp_host_opts.yaml +11 -0
  76. data/spec/spec_helper.rb +21 -0
  77. data/spec/support/fixtures.rb +104 -0
  78. data/spec/unit/puppet_x/eos/eapi_spec.rb +182 -0
  79. data/spec/unit/puppet_x/eos/module_base_spec.rb +26 -0
  80. data/spec/unit/puppet_x/eos/modules/daemon_spec.rb +110 -0
  81. data/spec/unit/puppet_x/eos/modules/extension_spec.rb +197 -0
  82. data/spec/unit/puppet_x/eos/modules/fixtures/daemon_getall.json +3 -0
  83. data/spec/unit/puppet_x/eos/modules/fixtures/extension_getall.json +28 -0
  84. data/spec/unit/puppet_x/eos/modules/fixtures/hostname.json +6 -0
  85. data/spec/unit/puppet_x/eos/modules/fixtures/interface_getall.json +509 -0
  86. data/spec/unit/puppet_x/eos/modules/fixtures/ipinterface_getall.json +56 -0
  87. data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get.json +21 -0
  88. data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get_interfaces.json +18 -0
  89. data/spec/unit/puppet_x/eos/modules/fixtures/ntp_get.json +5 -0
  90. data/spec/unit/puppet_x/eos/modules/fixtures/ospf_instance_getall.json +58 -0
  91. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_get.json +54 -0
  92. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getlacpmode.json +5 -0
  93. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getmembers.json +5 -0
  94. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_po1.json +7 -0
  95. data/spec/unit/puppet_x/eos/modules/fixtures/snmp_get.json +14 -0
  96. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get.json +5 -0
  97. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get_et1.json +7 -0
  98. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_getall_interfaces.json +230 -0
  99. data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_list.json +5 -0
  100. data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_name.json +5 -0
  101. data/spec/unit/puppet_x/eos/modules/fixtures/system_hostname.json +6 -0
  102. data/spec/unit/puppet_x/eos/modules/fixtures/system_name_servers.json +5 -0
  103. data/spec/unit/puppet_x/eos/modules/fixtures/vlan_getall.json +123 -0
  104. data/spec/unit/puppet_x/eos/modules/fixtures/vxlan_get.json +24 -0
  105. data/spec/unit/puppet_x/eos/modules/interface_spec.rb +281 -0
  106. data/spec/unit/puppet_x/eos/modules/ipinterface_spec.rb +143 -0
  107. data/spec/unit/puppet_x/eos/modules/mlag_spec.rb +349 -0
  108. data/spec/unit/puppet_x/eos/modules/ntp_spec.rb +136 -0
  109. data/spec/unit/puppet_x/eos/modules/ospf_spec.rb +143 -0
  110. data/spec/unit/puppet_x/eos/modules/portchannel_spec.rb +357 -0
  111. data/spec/unit/puppet_x/eos/modules/radius_spec.rb +509 -0
  112. data/spec/unit/puppet_x/eos/modules/snmp_spec.rb +202 -0
  113. data/spec/unit/puppet_x/eos/modules/switchport_get_et1.json +7 -0
  114. data/spec/unit/puppet_x/eos/modules/switchport_spec.rb +307 -0
  115. data/spec/unit/puppet_x/eos/modules/system_spec.rb +170 -0
  116. data/spec/unit/puppet_x/eos/modules/tacacs_spec.rb +448 -0
  117. data/spec/unit/puppet_x/eos/modules/vlan_spec.rb +244 -0
  118. data/spec/unit/puppet_x/eos/modules/vxlan_spec.rb +189 -0
  119. data/spec/unit/puppet_x/eos/provider_spec.rb +35 -0
  120. data/spec/unit/puppet_x/net_dev/eos_api/common_methods_spec.rb +34 -0
  121. data/spec/unit/puppet_x/net_dev/eos_api/snmp_methods_spec.rb +842 -0
  122. data/spec/unit/puppet_x/net_dev/eos_api_spec.rb +1000 -0
  123. metadata +369 -0
@@ -0,0 +1,509 @@
1
+ require 'spec_helper'
2
+
3
+ describe PuppetX::Eos::Radius do
4
+ let(:eapi) { PuppetX::Eos::Eapi.new }
5
+ let(:instance) { described_class.new(eapi) }
6
+
7
+ describe '#getall' do
8
+ context 'when all radius settings are the default' do
9
+ before :each do
10
+ allow(instance).to receive(:running_configuration)
11
+ .and_return(fixture(:running_configuration_radius_default))
12
+ end
13
+
14
+ describe 'the return value' do
15
+ subject { instance.getall }
16
+
17
+ it { is_expected.to be_an Array }
18
+ it 'has only one resource hash' do
19
+ expect(subject.size).to eq(1)
20
+ end
21
+ end
22
+
23
+ describe 'the single resource hash' do
24
+ subject { instance.getall.first }
25
+
26
+ it { is_expected.to include(name: 'settings') }
27
+ it { is_expected.to include(enable: true) }
28
+ it { is_expected.to_not include(:key) }
29
+ it { is_expected.to_not include(:key_format) }
30
+ it { is_expected.to include(timeout: 5) }
31
+ it { is_expected.to include(retransmit_count: 3) }
32
+ end
33
+ end
34
+
35
+ context 'when key, timeout, and retransmit are configured' do
36
+ before :each do
37
+ allow(instance).to receive(:running_configuration)
38
+ .and_return(fixture(:running_configuration_radius_configured))
39
+ end
40
+ subject { instance.getall.first }
41
+
42
+ it { is_expected.to include(name: 'settings') }
43
+ it { is_expected.to include(enable: true) }
44
+ it { is_expected.to include(key: '070E234F1F5B4A') }
45
+ it { is_expected.to include(key_format: 7) }
46
+ it { is_expected.to include(timeout: 50) }
47
+ it { is_expected.to include(retransmit_count: 5) }
48
+ end
49
+ end
50
+
51
+ describe '#servers' do
52
+ context 'with radius servers configured' do
53
+ before :each do
54
+ allow(instance).to receive(:running_configuration)
55
+ .and_return(fixture(:running_configuration_radius_servers))
56
+ end
57
+
58
+ describe 'the return value' do
59
+ subject { instance.servers }
60
+
61
+ it 'parses 6 results' do
62
+ expect(subject.size).to eq(6)
63
+ end
64
+ it { is_expected.to be_an Array }
65
+ it 'includes only Hashes as elements of the Array' do
66
+ subject.each { |result| expect(result).to be_a Hash }
67
+ end
68
+ it 'includes hostname in every result' do
69
+ subject.each { |result| expect(result).to include(:hostname) }
70
+ end
71
+ it 'includes auth_port in every result' do
72
+ subject.each { |result| expect(result).to include(:auth_port) }
73
+ end
74
+ it 'includes acct_port in every result' do
75
+ subject.each { |result| expect(result).to include(:acct_port) }
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#server_groups' do
82
+ before :each do
83
+ allow(instance).to receive(:running_configuration)
84
+ .and_return(fixture(:running_configuration_radius_server_groups))
85
+ end
86
+
87
+ describe 'the return value' do
88
+ subject { instance.server_groups }
89
+
90
+ it { is_expected.to be_an Array }
91
+ it 'returns 3 server groups' do
92
+ expect(subject.size).to eq 3
93
+ end
94
+
95
+ describe 'each value of the return Array' do
96
+ it 'each value is a hash' do
97
+ subject.each {|v| expect(v).to be_a Hash }
98
+ end
99
+ it 'each value has a name attribute' do
100
+ subject.each {|v| expect(v).to include(name: /RAD-SV/) }
101
+ end
102
+ it 'each value has a servers attribute' do
103
+ subject.each {|v| expect(v).to include(servers: Array) }
104
+ end
105
+ end
106
+
107
+ describe 'each server attribute' do
108
+ it 'is a hash' do
109
+ subject.each do |group|
110
+ group[:servers].each do |server|
111
+ expect(server).to be_a Hash
112
+ end
113
+ end
114
+ end
115
+ it 'includes the hostname, auth_port, acct_port attributes' do
116
+ subject.each do |group|
117
+ group[:servers].each do |server|
118
+ expect(server).to include(hostname: String,
119
+ auth_port: Fixnum,
120
+ acct_port: Fixnum)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ describe '#update_server_group' do
129
+ before :each do
130
+ allow(instance.api).to receive(:config).and_return([{}])
131
+ end
132
+
133
+ subject { instance.update_server_group(opts) }
134
+
135
+ context 'with no servers specified' do
136
+ let :opts do
137
+ { name: 'RAD-SV9', servers: [] }
138
+ end
139
+
140
+ it { is_expected.to eq(true) }
141
+
142
+ it 're-creates the server group after clearing it' do
143
+ expect(instance.api).to receive(:config)
144
+ .with('no aaa group server radius RAD-SV9').ordered
145
+ expect(instance.api).to receive(:config)
146
+ .with(['aaa group server radius RAD-SV9']).ordered
147
+ subject
148
+ end
149
+ end
150
+
151
+ context 'with two servers specified' do
152
+ let :opts do
153
+ { name: 'RAD-SV9',
154
+ servers: [
155
+ { hostname: 'one' },
156
+ { hostname: 'two', auth_port: 1234, acct_port: 5678 }
157
+ ]
158
+ }
159
+ end
160
+
161
+ it { is_expected.to eq(true) }
162
+ it 'uses the default auth and acct ports when not provided' do
163
+ expect(instance.api).to receive(:config)
164
+ .with([/RAD-SV9/, 'server one auth-port 1812 acct-port 1813', String ])
165
+ subject
166
+ end
167
+ it 'creates the group of servers using a single config call' do
168
+ expect(instance.api).to receive(:config)
169
+ .with([/RAD-SV9/, /server one/, /server two/])
170
+ subject
171
+ end
172
+ end
173
+ end
174
+
175
+ describe '#remove_server_group' do
176
+ let :opts do
177
+ { name: 'RAD-SV9' }
178
+ end
179
+
180
+ subject { instance.remove_server_group(opts) }
181
+
182
+ before :each do
183
+ allow(instance.api).to receive(:config).and_return([{}])
184
+ end
185
+
186
+ it { is_expected.to eq true }
187
+ it 'removes the group specified by name' do
188
+ expect(instance.api).to receive(:config)
189
+ .with('no aaa group server radius RAD-SV9')
190
+ subject
191
+ end
192
+ end
193
+
194
+ describe '#set_global_key' do
195
+ let :opts do
196
+ { key: '070E234F1F5B4A', key_format: 7 }
197
+ end
198
+
199
+ before :each do
200
+ allow(instance.api).to receive(:config)
201
+ end
202
+
203
+ subject { instance.set_global_key(opts) }
204
+
205
+ context 'when key_format is 7 (hashed)' do
206
+ it 'uses Eapi#config to set the global key' do
207
+ expect(instance.api).to receive(:config)
208
+ .with('radius-server key 7 070E234F1F5B4A')
209
+ subject
210
+ end
211
+ end
212
+
213
+ context 'when key_format is not provided' do
214
+ let :opts do
215
+ { key: '070E234F1F5B4A' }
216
+ end
217
+
218
+ it 'assumes a default format of 7' do
219
+ expect(instance.api).to receive(:config)
220
+ .with('radius-server key 7 070E234F1F5B4A')
221
+ subject
222
+ end
223
+ end
224
+
225
+ context 'when key is not provided' do
226
+ let :opts do
227
+ { key_format: 7 }
228
+ end
229
+
230
+ it 'raises ArgumentError that key is required' do
231
+ expect { subject }
232
+ .to raise_error ArgumentError, /key option is required/
233
+ end
234
+ end
235
+
236
+ context 'when the API call returns [{}]' do
237
+ before :each do
238
+ allow(instance.api).to receive(:config)
239
+ .and_return([{}])
240
+ end
241
+
242
+ it { is_expected.to eq true }
243
+ end
244
+
245
+ context 'when the API call does not return [{}]' do
246
+ before :each do
247
+ allow(instance.api).to receive(:config)
248
+ .and_return([{'errors' => ['blarg']}])
249
+ end
250
+
251
+ it { is_expected.to eq false }
252
+ end
253
+ end
254
+
255
+ describe '#set_timeout' do
256
+ let :opts do
257
+ { timeout: 50 }
258
+ end
259
+
260
+ before :each do
261
+ allow(instance.api).to receive(:config).and_return([{}])
262
+ end
263
+
264
+ subject { instance.set_timeout(opts) }
265
+
266
+ context 'when timeout is not provided' do
267
+ let :opts do
268
+ {}
269
+ end
270
+
271
+ it 'raises ArgumentError' do
272
+ expect { subject }
273
+ .to raise_error ArgumentError, /timeout option is required/
274
+ end
275
+ end
276
+
277
+ context 'when timeout is provided' do
278
+ it 'calls Eapi#config to configure radius-server timeout' do
279
+ expect(instance.api).to receive(:config)
280
+ .with('radius-server timeout 50')
281
+ .and_return([{}])
282
+ subject
283
+ end
284
+ end
285
+
286
+ context 'when the API call returns [{}]' do
287
+ it { is_expected.to eq true }
288
+ end
289
+
290
+ context 'when the API call does not return [{}]' do
291
+ before :each do
292
+ allow(instance.api).to receive(:config)
293
+ .and_return([{'errors' => ['blarg']}])
294
+ end
295
+
296
+ it { is_expected.to eq false }
297
+ end
298
+ end
299
+
300
+ describe '#set_retransmit_count' do
301
+ let :opts do
302
+ { retransmit_count: 5 }
303
+ end
304
+
305
+ before :each do
306
+ allow(instance.api).to receive(:config).and_return([{}])
307
+ end
308
+
309
+ subject { instance.set_retransmit_count(opts) }
310
+
311
+ context 'when retransmit_count is not provided' do
312
+ let :opts do
313
+ {}
314
+ end
315
+
316
+ it 'raises ArgumentError' do
317
+ expect { subject }
318
+ .to raise_error ArgumentError, /retransmit_count option is required/
319
+ end
320
+ end
321
+
322
+ context 'when retransmit_count is provided' do
323
+ it 'calls Eapi#config to configure radius-server retransmit' do
324
+ expect(instance.api).to receive(:config)
325
+ .with('radius-server retransmit 5')
326
+ .and_return([{}])
327
+ subject
328
+ end
329
+ end
330
+
331
+ context 'when the API call returns [{}]' do
332
+ it { is_expected.to eq true }
333
+ end
334
+
335
+ context 'when the API call does not return [{}]' do
336
+ before :each do
337
+ allow(instance.api).to receive(:config)
338
+ .and_return([{'errors' => ['blarg']}])
339
+ end
340
+
341
+ it { is_expected.to eq false }
342
+ end
343
+ end
344
+
345
+ describe '#update_server' do
346
+ let :opts do
347
+ { hostname: '10.11.12.13' }
348
+ end
349
+
350
+ before :each do
351
+ allow(instance.api).to receive(:config).and_return([{}])
352
+ end
353
+
354
+ subject { instance.update_server(opts) }
355
+
356
+ context 'when only hostname is provided' do
357
+ it 'calls Eapi#config to configure radius-server host' do
358
+ expect(instance.api).to receive(:config)
359
+ .with('radius-server host 10.11.12.13')
360
+ .and_return([{}])
361
+ subject
362
+ end
363
+ end
364
+
365
+ context 'when hostname, auth_port are provided' do
366
+ let :opts do
367
+ { hostname: '10.11.12.13', auth_port: 1024 }
368
+ end
369
+
370
+ it 'calls Eapi#config to configure radius-server host' do
371
+ expect(instance.api).to receive(:config)
372
+ .with('radius-server host 10.11.12.13 auth-port 1024')
373
+ .and_return([{}])
374
+ subject
375
+ end
376
+ end
377
+
378
+ context 'when hostname, acct_port are provided' do
379
+ let :opts do
380
+ { hostname: '10.11.12.13', acct_port: 2048 }
381
+ end
382
+
383
+ it 'calls Eapi#config to configure radius-server host' do
384
+ expect(instance.api).to receive(:config)
385
+ .with('radius-server host 10.11.12.13 acct-port 2048')
386
+ .and_return([{}])
387
+ subject
388
+ end
389
+ end
390
+
391
+ context 'when hostname, auth_port, acct_port are provided' do
392
+ let :opts do
393
+ { hostname: '10.11.12.13', auth_port: 1024, acct_port: 2048 }
394
+ end
395
+
396
+ it 'calls Eapi#config to configure radius-server host' do
397
+ expect(instance.api).to receive(:config)
398
+ .with('radius-server host 10.11.12.13 auth-port 1024 acct-port 2048')
399
+ .and_return([{}])
400
+ subject
401
+ end
402
+ end
403
+
404
+ context 'when hostname, timeout are provided' do
405
+ let :opts do
406
+ { hostname: '10.11.12.13', timeout: 10 }
407
+ end
408
+
409
+ it 'calls Eapi#config to configure radius-server host with timeout' do
410
+ expect(instance.api).to receive(:config)
411
+ .with('radius-server host 10.11.12.13 timeout 10')
412
+ .and_return([{}])
413
+ subject
414
+ end
415
+ end
416
+
417
+ context 'when hostname, auth_port, acct_port timeout are provided' do
418
+ let :opts do
419
+ {
420
+ hostname: '10.11.12.13',
421
+ auth_port: 1024,
422
+ acct_port: 2048,
423
+ timeout: 10
424
+ }
425
+ end
426
+
427
+ it 'calls Eapi#config with auth-port first' do
428
+ expect(instance.api).to receive(:config)
429
+ .with('radius-server host 10.11.12.13 auth-port 1024 '\
430
+ 'acct-port 2048 timeout 10')
431
+ .and_return([{}])
432
+ subject
433
+ end
434
+ end
435
+
436
+ context 'when hostname, key and no key_format are provided' do
437
+ let :opts do
438
+ { hostname: '10.11.12.13', key: 'abc123' }
439
+ end
440
+
441
+ it 'calls Eapi#config with key format 7 as the default' do
442
+ expect(instance.api).to receive(:config)
443
+ .with('radius-server host 10.11.12.13 key 7 abc123')
444
+ .and_return([{}])
445
+ subject
446
+ end
447
+ end
448
+
449
+ context 'when the API call returns [{}]' do
450
+ it { is_expected.to eq true }
451
+ end
452
+
453
+ context 'when the API call does not return [{}]' do
454
+ before :each do
455
+ allow(instance.api).to receive(:config)
456
+ .and_return([{'errors' => ['blarg']}])
457
+ end
458
+
459
+ it { is_expected.to eq false }
460
+ end
461
+ end
462
+
463
+ describe '#remove_server' do
464
+ let :opts do
465
+ { hostname: '10.11.12.13' }
466
+ end
467
+
468
+ before :each do
469
+ allow(instance.api).to receive(:config).and_return([{}])
470
+ end
471
+
472
+ subject { instance.remove_server(opts) }
473
+
474
+ context 'when hostname is provided' do
475
+ it 'calls Eapi#config to configure no radius-server host ...' do
476
+ expect(instance.api).to receive(:config)
477
+ .with('no radius-server host 10.11.12.13')
478
+ .and_return([{}])
479
+ subject
480
+ end
481
+ end
482
+
483
+ context 'when hostname, auth_port, acct_port are provided' do
484
+ let :opts do
485
+ { hostname: '10.11.12.13', auth_port: 1024, acct_port: 2048 }
486
+ end
487
+
488
+ it 'calls Eapi#config with host, auth-port, acct-port in order' do
489
+ expect(instance.api).to receive(:config)
490
+ .with('no radius-server host 10.11.12.13 auth-port 1024 acct-port 2048')
491
+ .and_return([{}])
492
+ subject
493
+ end
494
+ end
495
+
496
+ context 'when the API call returns [{}]' do
497
+ it { is_expected.to eq true }
498
+ end
499
+
500
+ context 'when the API call does not return [{}]' do
501
+ before :each do
502
+ allow(instance.api).to receive(:config)
503
+ .and_return([{'errors' => ['blarg']}])
504
+ end
505
+
506
+ it { is_expected.to eq false }
507
+ end
508
+ end
509
+ end