rbeapi 0.3.0 → 0.4.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 (39) hide show
  1. data/CHANGELOG.md +16 -0
  2. data/Gemfile +3 -1
  3. data/Guardfile +2 -2
  4. data/README.md +35 -24
  5. data/Rakefile +48 -18
  6. data/gems/inifile/inifile.spec.tmpl +50 -14
  7. data/gems/net_http_unix/net_http_unix.spec.tmpl +48 -15
  8. data/gems/netaddr/netaddr.spec.tmpl +47 -14
  9. data/lib/rbeapi/api/bgp.rb +100 -4
  10. data/lib/rbeapi/api/interfaces.rb +4 -5
  11. data/lib/rbeapi/api/radius.rb +1 -1
  12. data/lib/rbeapi/api/routemaps.rb +405 -37
  13. data/lib/rbeapi/api/system.rb +21 -0
  14. data/lib/rbeapi/api/users.rb +361 -0
  15. data/lib/rbeapi/api/varp.rb +50 -22
  16. data/lib/rbeapi/api/vrrp.rb +1072 -0
  17. data/lib/rbeapi/client.rb +12 -4
  18. data/lib/rbeapi/eapilib.rb +1 -1
  19. data/lib/rbeapi/version.rb +1 -1
  20. data/rbeapi.spec.tmpl +57 -25
  21. data/spec/system/rbeapi/api/dns_spec.rb +2 -2
  22. data/spec/system/rbeapi/api/routemaps_spec.rb +344 -0
  23. data/spec/system/rbeapi/api/switchports_spec.rb +1 -1
  24. data/spec/system/rbeapi/api/system_spec.rb +44 -4
  25. data/spec/system/{api_varp_interfaces_spec.rb → rbeapi/api/varp_interfaces_spec.rb} +25 -16
  26. data/spec/system/rbeapi/api/varp_spec.rb +76 -0
  27. data/spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb +2 -0
  28. data/spec/unit/rbeapi/api/bgp/bgp_spec.rb +54 -1
  29. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +1 -1
  30. data/spec/unit/rbeapi/api/routemaps/default_spec.rb +370 -0
  31. data/spec/unit/rbeapi/api/routemaps/fixture_routemaps.text +27 -0
  32. data/spec/unit/rbeapi/api/system/default_spec.rb +102 -0
  33. data/spec/unit/rbeapi/api/system/fixture_system.text +2 -0
  34. data/spec/unit/rbeapi/api/users/default_spec.rb +280 -0
  35. data/spec/unit/rbeapi/api/users/fixture_users.text +4 -0
  36. data/spec/unit/rbeapi/api/vrrp/default_spec.rb +582 -0
  37. data/spec/unit/rbeapi/api/vrrp/fixture_vrrp.text +186 -0
  38. metadata +28 -8
  39. data/spec/system/api_varp_spec.rb +0 -41
@@ -0,0 +1,582 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/api/vrrp'
4
+
5
+ include FixtureHelpers
6
+
7
+ describe Rbeapi::Api::Vrrp do
8
+ subject { described_class.new(node) }
9
+
10
+ let(:node) { double('node') }
11
+
12
+ def vrrp
13
+ vrrp = Fixtures[:vrrp]
14
+ return vrrp if vrrp
15
+ fixture('vrrp', format: :text, dir: File.dirname(__FILE__))
16
+ end
17
+
18
+ before :all do
19
+ @sec_ips = ['1.2.3.1', '1.2.3.2', '1.2.3.3', '1.2.3.4']
20
+ @tracks = [{ name: 'Ethernet3', action: 'decrement', amount: 33 },
21
+ { name: 'Ethernet2', action: 'decrement', amount: 22 },
22
+ { name: 'Ethernet2', action: 'shutdown' }]
23
+
24
+ # Create the secondary IP commands array
25
+ @sec_ips_cmds = []
26
+ @sec_ips.each do |addr|
27
+ @sec_ips_cmds << "vrrp 9 ip #{addr} secondary"
28
+ end
29
+
30
+ # Create the track commands array
31
+ @track_cmds = []
32
+ @tracks.each do |tk|
33
+ cmd = "vrrp 9 track #{tk[:name]} #{tk[:action]}"
34
+ cmd << " #{tk[:amount]}" if tk.key?(:amount)
35
+ @track_cmds << cmd
36
+ end
37
+ end
38
+
39
+ before :each do
40
+ allow(subject.node).to receive(:running_config).and_return(vrrp)
41
+ end
42
+
43
+ describe '#get' do
44
+ let(:entity) do
45
+ { 30 => { primary_ip: '40.10.5.31', delay_reload: 0,
46
+ description: 'The description', enable: false, ip_version: 2,
47
+ mac_addr_adv_interval: 30, preempt: false, preempt_delay_min: 0,
48
+ preempt_delay_reload: 0, priority: 100, secondary_ip: [],
49
+ timers_advertise: 1,
50
+ track: [
51
+ { name: 'Ethernet1', action: 'decrement', amount: 5 }
52
+ ]
53
+ },
54
+ 40 => { primary_ip: '40.10.5.32', delay_reload: 0, description: nil,
55
+ enable: true, ip_version: 2, mac_addr_adv_interval: 30,
56
+ preempt: true, preempt_delay_min: 0, preempt_delay_reload: 0,
57
+ priority: 200, secondary_ip: [], timers_advertise: 1,
58
+ track: @tracks
59
+ }
60
+ }
61
+ end
62
+
63
+ it 'returns the virtual router resource' do
64
+ expect(subject.get('Vlan150')).to eq(entity)
65
+ end
66
+ end
67
+
68
+ describe '#getall' do
69
+ it 'returns the virtual router collection' do
70
+ expect(subject.getall).to include('Vlan100')
71
+ expect(subject.getall).to include('Vlan150')
72
+ end
73
+
74
+ it 'returns a hash collection' do
75
+ expect(subject.getall).to be_a_kind_of(Hash)
76
+ end
77
+
78
+ it 'has only one entry' do
79
+ expect(subject.getall.size).to eq(2)
80
+ end
81
+ end
82
+
83
+ describe '#create' do
84
+ before :all do
85
+ @values = [
86
+ { option: :enable, value: true, cmd: ['no vrrp 9 shutdown'] },
87
+ { option: :enable, value: false, cmd: ['vrrp 9 shutdown'] },
88
+ { option: :primary_ip, value: '1.2.3.4', cmd: ['vrrp 9 ip 1.2.3.4'] },
89
+ { option: :priority, value: 100, cmd: ['vrrp 9 priority 100'] },
90
+ { option: :description, value: 'Desc',
91
+ cmd: ['vrrp 9 description Desc'] },
92
+ { option: :secondary_ip, value: @sec_ips, cmd: @sec_ips_cmds },
93
+ { option: :ip_version, value: 2, cmd: ['vrrp 9 ip version 2'] },
94
+ { option: :timers_advertise, value: 77,
95
+ cmd: ['vrrp 9 timers advertise 77'] },
96
+ { option: :mac_addr_adv_interval, value: 77,
97
+ cmd: ['vrrp 9 mac-address advertisement-interval 77'] },
98
+ { option: :preempt, value: true, cmd: ['vrrp 9 preempt'] },
99
+ { option: :preempt, value: false, cmd: ['no vrrp 9 preempt'] },
100
+ { option: :preempt_delay_min, value: 100,
101
+ cmd: ['vrrp 9 preempt delay minimum 100'] },
102
+ { option: :preempt_delay_reload, value: 100,
103
+ cmd: ['vrrp 9 preempt delay reload 100'] },
104
+ { option: :delay_reload, value: 100, cmd: ['vrrp 9 delay reload 100'] },
105
+ { option: :track, value: @tracks, cmd: @track_cmds }
106
+ ]
107
+
108
+ # Build the testcases specifying one option per test
109
+ @test_opts1 = []
110
+ @values.each do |entry|
111
+ opts = Hash[entry[:option], entry[:value]]
112
+ @test_opts1.push(opts: opts, cmds: entry[:cmd])
113
+ end
114
+
115
+ # Build the testcases specifying two options per test
116
+ @test_opts2 = []
117
+ @values.each_with_index do |entry1, idx1|
118
+ @values.each_with_index do |entry2, idx2|
119
+ # Skip if both options are the same
120
+ next if entry1[:option] == entry2[:option]
121
+ # Skip if already generated a testcase for this pair
122
+ next if idx2 <= idx1
123
+ opts = Hash[entry1[:option], entry1[:value],
124
+ entry2[:option], entry2[:value]]
125
+ @test_opts2.push(opts: opts, cmds: entry1[:cmd] + entry2[:cmd])
126
+ end
127
+ end
128
+ end
129
+
130
+ it 'creates a new virtual router resource with one option set' do
131
+ @test_opts1.each do |test|
132
+ cmds = ['interface Vlan100']
133
+ cmds += test[:cmds]
134
+
135
+ expect(node).to receive(:config).with(cmds)
136
+ expect(subject.create('Vlan100', 9, test[:opts])).to be_truthy
137
+ end
138
+ end
139
+
140
+ it 'creates a new virtual router resource with two options set' do
141
+ @test_opts2.each do |test|
142
+ cmds = ['interface Vlan100']
143
+ cmds += test[:cmds]
144
+
145
+ expect(node).to receive(:config).with(cmds)
146
+ expect(subject.create('Vlan100', 9, test[:opts])).to be_truthy
147
+ end
148
+ end
149
+
150
+ it 'creates a new virtual router resource with all options set' do
151
+ @test_opts3 = []
152
+ opts = {}
153
+ cmds = ['interface Vlan100']
154
+ @values.each do |entry|
155
+ # Skip boolean pairs in the options that are false because
156
+ # the option can only be set once.
157
+ next unless entry[:value]
158
+ opts[entry[:option]] = entry[:value]
159
+ entry[:cmd].each do |cmd|
160
+ cmds << cmd
161
+ end
162
+ end
163
+
164
+ expect(node).to receive(:config).with(cmds)
165
+ expect(subject.create('Vlan100', 9, opts)).to be_truthy
166
+ end
167
+
168
+ it 'raises ArgumentError for create without options' do
169
+ expect { subject.create('Vlan100', 9) }.to \
170
+ raise_error ArgumentError
171
+ end
172
+ end
173
+
174
+ describe '#delete' do
175
+ it 'deletes a virtual router resource' do
176
+ expect(node).to receive(:config).with(['interface Vlan100',
177
+ 'no vrrp 9'])
178
+ expect(subject.delete('Vlan100', 9)).to be_truthy
179
+ end
180
+ end
181
+
182
+ describe '#default' do
183
+ it 'sets virtual router resource to default' do
184
+ expect(node).to receive(:config).with(['interface Vlan100',
185
+ 'default vrrp 9'])
186
+ expect(subject.default('Vlan100', 9)).to be_truthy
187
+ end
188
+ end
189
+
190
+ describe '#set_shutdown' do
191
+ it 'enable Vlan100 vrid 9' do
192
+ expect(node).to receive(:config).with(['interface Vlan100',
193
+ 'no vrrp 9 shutdown'])
194
+ expect(subject.set_shutdown('Vlan100', 9)).to be_truthy
195
+ end
196
+
197
+ it 'disable Vlan100 vrid 9' do
198
+ expect(node).to receive(:config).with(['interface Vlan100',
199
+ 'vrrp 9 shutdown'])
200
+ expect(subject.set_shutdown('Vlan100', 9, enable: false)).to be_truthy
201
+ end
202
+
203
+ it 'defaults Vlan100 vrid 9' do
204
+ expect(node).to receive(:config).with(['interface Vlan100',
205
+ 'default vrrp 9 shutdown'])
206
+ expect(subject.set_shutdown('Vlan100', 9, default: true)).to be_truthy
207
+ end
208
+
209
+ it 'default option takes precedence' do
210
+ expect(node).to receive(:config).with(['interface Vlan100',
211
+ 'default vrrp 9 shutdown'])
212
+ expect(subject.set_shutdown('Vlan100', 9, enable: false,
213
+ default: true)).to be_truthy
214
+ end
215
+ end
216
+
217
+ describe '#set_primary_ip' do
218
+ it 'set primary IP address' do
219
+ expect(node).to receive(:config).with(['interface Vlan100',
220
+ 'vrrp 9 ip 1.2.3.4'])
221
+ expect(subject.set_primary_ip('Vlan100', 9,
222
+ value: '1.2.3.4')).to be_truthy
223
+ end
224
+
225
+ it 'disable primary IP address' do
226
+ expect(node).to receive(:config).with(['interface Vlan100',
227
+ 'no vrrp 9 ip 1.2.3.4'])
228
+ expect(subject.set_primary_ip('Vlan100', 9, value: '1.2.3.4',
229
+ enable: false)).to be_truthy
230
+ end
231
+
232
+ it 'defaults primary IP address' do
233
+ expect(node).to receive(:config).with(['interface Vlan100',
234
+ 'default vrrp 9 ip 1.2.3.4'])
235
+ expect(subject.set_primary_ip('Vlan100', 9, value: '1.2.3.4',
236
+ default: true)).to be_truthy
237
+ end
238
+
239
+ it 'default option takes precedence' do
240
+ expect(node).to receive(:config).with(['interface Vlan100',
241
+ 'default vrrp 9 ip 1.2.3.4'])
242
+ expect(subject.set_primary_ip('Vlan100', 9, enable: false,
243
+ value: '1.2.3.4',
244
+ default: true)).to be_truthy
245
+ end
246
+ end
247
+
248
+ describe '#set_priority' do
249
+ it 'set priority' do
250
+ expect(node).to receive(:config).with(['interface Vlan100',
251
+ 'vrrp 9 priority 13'])
252
+ expect(subject.set_priority('Vlan100', 9, value: 13)).to be_truthy
253
+ end
254
+
255
+ it 'disable priority' do
256
+ expect(node).to receive(:config).with(['interface Vlan100',
257
+ 'no vrrp 9 priority'])
258
+ expect(subject.set_priority('Vlan100', 9, enable: false)).to be_truthy
259
+ end
260
+
261
+ it 'defaults priority' do
262
+ expect(node).to receive(:config).with(['interface Vlan100',
263
+ 'default vrrp 9 priority'])
264
+ expect(subject.set_priority('Vlan100', 9, default: true)).to be_truthy
265
+ end
266
+
267
+ it 'default option takes precedence' do
268
+ expect(node).to receive(:config).with(['interface Vlan100',
269
+ 'default vrrp 9 priority'])
270
+ expect(subject.set_priority('Vlan100', 9, enable: false,
271
+ default: true)).to be_truthy
272
+ end
273
+ end
274
+
275
+ describe '#set_description' do
276
+ it 'set description' do
277
+ expect(node).to receive(:config).with(['interface Vlan100',
278
+ 'vrrp 9 description Howdy'])
279
+ expect(subject.set_description('Vlan100', 9,
280
+ value: 'Howdy')).to be_truthy
281
+ end
282
+
283
+ it 'disable description' do
284
+ expect(node).to receive(:config).with(['interface Vlan100',
285
+ 'no vrrp 9 description'])
286
+ expect(subject.set_description('Vlan100', 9, enable: false)).to be_truthy
287
+ end
288
+
289
+ it 'defaults description' do
290
+ expect(node).to receive(:config).with(['interface Vlan100',
291
+ 'default vrrp 9 description'])
292
+ expect(subject.set_description('Vlan100', 9, default: true)).to be_truthy
293
+ end
294
+
295
+ it 'default option takes precedence' do
296
+ expect(node).to receive(:config).with(['interface Vlan100',
297
+ 'default vrrp 9 description'])
298
+ expect(subject.set_description('Vlan100', 9, enable: false,
299
+ default: true)).to be_truthy
300
+ end
301
+ end
302
+
303
+ describe '#set_secondary_ip' do
304
+ before :all do
305
+ @cmds = ['interface Vlan100']
306
+ @cmds += @sec_ips_cmds
307
+ end
308
+ it 'set secondary IP addresses' do
309
+ # Set current IP addresses
310
+ expect(node).to receive(:config).with(@cmds)
311
+ expect(subject.set_secondary_ip('Vlan100', 9, @sec_ips)).to be_truthy
312
+ end
313
+
314
+ it 'remove all secondary IP addresses' do
315
+ # Set current IP addresses
316
+ expect(node).to receive(:config).with(@cmds)
317
+ expect(subject.set_secondary_ip('Vlan100', 9, @sec_ips)).to be_truthy
318
+ # Delete all IP addresses
319
+ expect(subject.set_secondary_ip('Vlan100', 9, [])).to be_truthy
320
+ end
321
+ end
322
+
323
+ describe '#set_ip_version' do
324
+ it 'set VRRP version' do
325
+ expect(node).to receive(:config).with(['interface Vlan100',
326
+ 'vrrp 9 ip version 3'])
327
+ expect(subject.set_ip_version('Vlan100', 9, value: 3)).to be_truthy
328
+ end
329
+
330
+ it 'disable VRRP version' do
331
+ expect(node).to receive(:config).with(['interface Vlan100',
332
+ 'no vrrp 9 ip version'])
333
+ expect(subject.set_ip_version('Vlan100', 9, enable: false)).to be_truthy
334
+ end
335
+
336
+ it 'defaults VRRP version' do
337
+ expect(node).to receive(:config).with(['interface Vlan100',
338
+ 'default vrrp 9 ip version'])
339
+ expect(subject.set_ip_version('Vlan100', 9, default: true)).to be_truthy
340
+ end
341
+
342
+ it 'default option takes precedence' do
343
+ expect(node).to receive(:config).with(['interface Vlan100',
344
+ 'default vrrp 9 ip version'])
345
+ expect(subject.set_ip_version('Vlan100', 9, enable: false,
346
+ default: true)).to be_truthy
347
+ end
348
+ end
349
+
350
+ describe '#set_timers_advertise' do
351
+ it 'set advertise timer' do
352
+ expect(node).to receive(:config).with(['interface Vlan100',
353
+ 'vrrp 9 timers advertise 7'])
354
+ expect(subject.set_timers_advertise('Vlan100', 9, value: 7)).to be_truthy
355
+ end
356
+
357
+ it 'disable advertise timer' do
358
+ expect(node).to receive(:config).with(['interface Vlan100',
359
+ 'no vrrp 9 timers advertise'])
360
+ expect(subject.set_timers_advertise('Vlan100', 9,
361
+ enable: false)).to be_truthy
362
+ end
363
+
364
+ it 'defaults advertise timer' do
365
+ expect(node).to receive(:config).with(['interface Vlan100',
366
+ 'default vrrp 9 timers advertise'])
367
+ expect(subject.set_timers_advertise('Vlan100', 9,
368
+ default: true)).to be_truthy
369
+ end
370
+
371
+ it 'default option takes precedence' do
372
+ expect(node).to receive(:config).with(['interface Vlan100',
373
+ 'default vrrp 9 timers advertise'])
374
+ expect(subject.set_timers_advertise('Vlan100', 9,
375
+ enable: false,
376
+ default: true)).to be_truthy
377
+ end
378
+ end
379
+
380
+ describe '#set_mac_addr_adv_interval' do
381
+ it 'set mac address advertisement interval' do
382
+ expect(node).to receive(:config)
383
+ .with(['interface Vlan100',
384
+ 'vrrp 9 mac-address advertisement-interval 12'])
385
+ expect(subject.set_mac_addr_adv_interval('Vlan100', 9,
386
+ value: 12)).to be_truthy
387
+ end
388
+
389
+ it 'disable mac address advertisement interval' do
390
+ expect(node).to receive(:config)
391
+ .with(['interface Vlan100',
392
+ 'no vrrp 9 mac-address advertisement-interval'])
393
+ expect(subject.set_mac_addr_adv_interval('Vlan100', 9,
394
+ enable: false)).to be_truthy
395
+ end
396
+
397
+ it 'defaults mac address advertisement interval' do
398
+ expect(node).to receive(:config)
399
+ .with(['interface Vlan100',
400
+ 'default vrrp 9 mac-address advertisement-interval'])
401
+ expect(subject.set_mac_addr_adv_interval('Vlan100', 9,
402
+ default: true)).to be_truthy
403
+ end
404
+
405
+ it 'default option takes precedence' do
406
+ expect(node).to receive(:config)
407
+ .with(['interface Vlan100',
408
+ 'default vrrp 9 mac-address advertisement-interval'])
409
+ expect(subject.set_mac_addr_adv_interval('Vlan100', 9,
410
+ enable: false,
411
+ default: true)).to be_truthy
412
+ end
413
+ end
414
+
415
+ describe '#set_preempt' do
416
+ it 'enable preempt mode' do
417
+ expect(node).to receive(:config).with(['interface Vlan100',
418
+ 'vrrp 9 preempt'])
419
+ expect(subject.set_preempt('Vlan100', 9)).to be_truthy
420
+ end
421
+
422
+ it 'disable preempt mode' do
423
+ expect(node).to receive(:config).with(['interface Vlan100',
424
+ 'no vrrp 9 preempt'])
425
+ expect(subject.set_preempt('Vlan100', 9, enable: false)).to be_truthy
426
+ end
427
+
428
+ it 'defaults preempt mode' do
429
+ expect(node).to receive(:config).with(['interface Vlan100',
430
+ 'default vrrp 9 preempt'])
431
+ expect(subject.set_preempt('Vlan100', 9, default: true)).to be_truthy
432
+ end
433
+
434
+ it 'default option takes precedence' do
435
+ expect(node).to receive(:config).with(['interface Vlan100',
436
+ 'default vrrp 9 preempt'])
437
+ expect(subject.set_preempt('Vlan100', 9, enable: false,
438
+ default: true)).to be_truthy
439
+ end
440
+ end
441
+
442
+ describe '#set_preempt_delay_min' do
443
+ it 'enable preempt mode' do
444
+ expect(node).to receive(:config).with(['interface Vlan100',
445
+ 'vrrp 9 preempt delay minimum 8'])
446
+ expect(subject.set_preempt_delay_min('Vlan100', 9, value: 8)).to be_truthy
447
+ end
448
+
449
+ it 'disable preempt mode' do
450
+ expect(node).to receive(:config).with(['interface Vlan100',
451
+ 'no vrrp 9 preempt delay minimum'])
452
+ expect(subject.set_preempt_delay_min('Vlan100', 9,
453
+ enable: false)).to be_truthy
454
+ end
455
+
456
+ it 'defaults preempt mode' do
457
+ expect(node).to receive(:config)
458
+ .with(['interface Vlan100', 'default vrrp 9 preempt delay minimum'])
459
+ expect(subject.set_preempt_delay_min('Vlan100', 9,
460
+ default: true)).to be_truthy
461
+ end
462
+
463
+ it 'default option takes precedence' do
464
+ expect(node).to receive(:config)
465
+ .with(['interface Vlan100', 'default vrrp 9 preempt delay minimum'])
466
+ expect(subject.set_preempt_delay_min('Vlan100', 9,
467
+ enable: false,
468
+ default: true)).to be_truthy
469
+ end
470
+ end
471
+
472
+ describe '#set_preempt_delay_reload' do
473
+ it 'enable preempt delay reload' do
474
+ expect(node).to receive(:config).with(['interface Vlan100',
475
+ 'vrrp 9 preempt delay reload 8'])
476
+ expect(subject.set_preempt_delay_reload('Vlan100', 9,
477
+ value: 8)).to be_truthy
478
+ end
479
+
480
+ it 'disable preempt delay reload' do
481
+ expect(node).to receive(:config).with(['interface Vlan100',
482
+ 'no vrrp 9 preempt delay reload'])
483
+ expect(subject.set_preempt_delay_reload('Vlan100', 9,
484
+ enable: false)).to be_truthy
485
+ end
486
+
487
+ it 'defaults preempt delay reload' do
488
+ expect(node).to receive(:config)
489
+ .with(['interface Vlan100', 'default vrrp 9 preempt delay reload'])
490
+ expect(subject.set_preempt_delay_reload('Vlan100', 9,
491
+ default: true)).to be_truthy
492
+ end
493
+
494
+ it 'default option takes precedence' do
495
+ expect(node).to receive(:config)
496
+ .with(['interface Vlan100', 'default vrrp 9 preempt delay reload'])
497
+ expect(subject.set_preempt_delay_reload('Vlan100', 9,
498
+ enable: false,
499
+ default: true)).to be_truthy
500
+ end
501
+ end
502
+
503
+ describe '#set_delay_reload' do
504
+ it 'enable delay reload' do
505
+ expect(node).to receive(:config).with(['interface Vlan100',
506
+ 'vrrp 9 delay reload 8'])
507
+ expect(subject.set_delay_reload('Vlan100', 9, value: 8)).to be_truthy
508
+ end
509
+
510
+ it 'disable delay reload' do
511
+ expect(node).to receive(:config).with(['interface Vlan100',
512
+ 'no vrrp 9 delay reload'])
513
+ expect(subject.set_delay_reload('Vlan100', 9, enable: false)).to be_truthy
514
+ end
515
+
516
+ it 'defaults delay reload' do
517
+ expect(node).to receive(:config)
518
+ .with(['interface Vlan100', 'default vrrp 9 delay reload'])
519
+ expect(subject.set_delay_reload('Vlan100', 9, default: true)).to be_truthy
520
+ end
521
+
522
+ it 'default option takes precedence' do
523
+ expect(node).to receive(:config)
524
+ .with(['interface Vlan100', 'default vrrp 9 delay reload'])
525
+ expect(subject.set_delay_reload('Vlan100', 9,
526
+ enable: false,
527
+ default: true)).to be_truthy
528
+ end
529
+ end
530
+
531
+ describe '#set_tracks' do
532
+ before :all do
533
+ @cmds = ['interface Vlan100']
534
+ @cmds += @track_cmds
535
+
536
+ @bad_key = [{ nombre: 'Ethernet3', action: 'decrement', amount: 33 }]
537
+ @miss_key = [{ action: 'decrement', amount: 33 }]
538
+ @bad_action = [{ name: 'Ethernet3', action: 'dec', amount: 33 }]
539
+ @sem_key = [{ name: 'Ethernet3', action: 'shutdown', amount: 33 }]
540
+ @bad_amount = [{ name: 'Ethernet3', action: 'decrement', amount: -1 }]
541
+ end
542
+
543
+ it 'set tracks' do
544
+ # Set current IP addresses
545
+ expect(node).to receive(:config).with(@cmds)
546
+ expect(subject.set_tracks('Vlan100', 9, @tracks)).to be_truthy
547
+ end
548
+
549
+ it 'remove all tracks' do
550
+ # Set current IP addresses
551
+ expect(node).to receive(:config).with(@cmds)
552
+ expect(subject.set_tracks('Vlan100', 9, @tracks)).to be_truthy
553
+ # Delete all IP addresses
554
+ expect(subject.set_tracks('Vlan100', 9, [])).to be_truthy
555
+ end
556
+
557
+ it 'raises ArgumentError for track hash with a bad key' do
558
+ expect { subject.set_tracks('Vlan100', 9, @bad_key) }.to \
559
+ raise_error ArgumentError
560
+ end
561
+
562
+ it 'raises ArgumentError for track hash with missing required key' do
563
+ expect { subject.set_tracks('Vlan100', 9, @miss_key) }.to \
564
+ raise_error ArgumentError
565
+ end
566
+
567
+ it 'raises ArgumentError for track hash with invalid action' do
568
+ expect { subject.set_tracks('Vlan100', 9, @bad_action) }.to \
569
+ raise_error ArgumentError
570
+ end
571
+
572
+ it 'raises ArgumentError for track hash with shutdown and amount' do
573
+ expect { subject.set_tracks('Vlan100', 9, @sem_key) }.to \
574
+ raise_error ArgumentError
575
+ end
576
+
577
+ it 'raises ArgumentError for track hash with negative amount' do
578
+ expect { subject.set_tracks('Vlan100', 9, @bad_amount) }.to \
579
+ raise_error ArgumentError
580
+ end
581
+ end
582
+ end