rbeapi 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG.md +20 -0
  3. data/Gemfile +1 -1
  4. data/README.md +11 -11
  5. data/Rakefile +19 -0
  6. data/guide/Makefile +177 -0
  7. data/guide/_static/arista_logo_11-trans-w.png +0 -0
  8. data/guide/_static/arista_logo_jpg-11.jpg +0 -0
  9. data/guide/_static/favicon.ico +0 -0
  10. data/guide/conf.py +279 -0
  11. data/guide/cookbook.rst +4 -0
  12. data/guide/developing.rst +4 -0
  13. data/guide/faq.rst +4 -0
  14. data/guide/index.rst +23 -0
  15. data/guide/installation.rst +4 -0
  16. data/guide/license.rst +5 -0
  17. data/guide/overview.rst +20 -0
  18. data/guide/quickstart.rst +4 -0
  19. data/guide/release-notes-0.5.0.rst +60 -0
  20. data/guide/release-notes.rst +6 -0
  21. data/guide/testing.rst +4 -0
  22. data/guide/troubleshooting.rst +1 -0
  23. data/lib/rbeapi/api/aaa.rb +54 -18
  24. data/lib/rbeapi/api/acl.rb +60 -2
  25. data/lib/rbeapi/api/bgp.rb +81 -0
  26. data/lib/rbeapi/api/dns.rb +48 -2
  27. data/lib/rbeapi/api/interfaces.rb +97 -32
  28. data/lib/rbeapi/api/ipinterfaces.rb +13 -2
  29. data/lib/rbeapi/api/logging.rb +11 -2
  30. data/lib/rbeapi/api/mlag.rb +20 -10
  31. data/lib/rbeapi/api/ntp.rb +4 -3
  32. data/lib/rbeapi/api/ospf.rb +102 -10
  33. data/lib/rbeapi/api/prefixlists.rb +47 -4
  34. data/lib/rbeapi/api/radius.rb +9 -9
  35. data/lib/rbeapi/api/routemaps.rb +7 -5
  36. data/lib/rbeapi/api/snmp.rb +13 -4
  37. data/lib/rbeapi/api/staticroutes.rb +1 -1
  38. data/lib/rbeapi/api/stp.rb +39 -14
  39. data/lib/rbeapi/api/switchports.rb +126 -2
  40. data/lib/rbeapi/api/system.rb +24 -3
  41. data/lib/rbeapi/api/tacacs.rb +9 -10
  42. data/lib/rbeapi/api/users.rb +12 -3
  43. data/lib/rbeapi/api/varp.rb +40 -8
  44. data/lib/rbeapi/api/vlans.rb +15 -5
  45. data/lib/rbeapi/client.rb +19 -11
  46. data/lib/rbeapi/eapilib.rb +8 -0
  47. data/lib/rbeapi/utils.rb +10 -0
  48. data/lib/rbeapi/version.rb +1 -1
  49. data/spec/fixtures/eapi.conf.yaml +6 -0
  50. data/spec/fixtures/empty.conf +0 -0
  51. data/spec/fixtures/env_path.conf +5 -0
  52. data/spec/fixtures/test.conf +39 -0
  53. data/spec/fixtures/wildcard.conf +43 -0
  54. data/spec/system/rbeapi/api/aaa_groups_spec.rb +122 -0
  55. data/spec/system/rbeapi/api/aaa_spec.rb +90 -0
  56. data/spec/system/{api_acl_spec.rb → rbeapi/api/acl_spec.rb} +0 -0
  57. data/spec/system/rbeapi/api/bgp_neighbors_spec.rb +354 -0
  58. data/spec/system/rbeapi/api/bgp_spec.rb +275 -0
  59. data/spec/system/rbeapi/api/dns_spec.rb +17 -1
  60. data/spec/system/rbeapi/api/interfaces_base_spec.rb +46 -5
  61. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +14 -0
  62. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +68 -0
  63. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +0 -1
  64. data/spec/system/{api_ospf_interfaces_spec.rb → rbeapi/api/ospf_interfaces_spec.rb} +3 -2
  65. data/spec/system/{api_ospf_spec.rb → rbeapi/api/ospf_spec.rb} +11 -2
  66. data/spec/system/rbeapi/api/routemaps_spec.rb +3 -4
  67. data/spec/system/rbeapi/api/snmp_spec.rb +65 -0
  68. data/spec/system/rbeapi/api/staticroutes_spec.rb +177 -0
  69. data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -0
  70. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +7 -0
  71. data/spec/system/rbeapi/api/switchports_spec.rb +86 -16
  72. data/spec/system/rbeapi/api/users_spec.rb +324 -0
  73. data/spec/system/rbeapi/api/varp_interfaces_spec.rb +34 -0
  74. data/spec/system/rbeapi/api/vrrp_spec.rb +707 -0
  75. data/spec/system/rbeapi/client_spec.rb +367 -0
  76. data/spec/unit/rbeapi/api/aaa/aaa_groups_spec.rb +111 -0
  77. data/spec/unit/rbeapi/api/aaa/aaa_spec.rb +77 -0
  78. data/spec/unit/rbeapi/api/aaa/fixture_aaa.text +3 -0
  79. data/spec/unit/rbeapi/api/switchports/default_spec.rb +249 -0
  80. data/spec/unit/rbeapi/api/switchports/fixture_switchports.text +284 -0
  81. data/spec/unit/rbeapi/api/users/default_spec.rb +1 -1
  82. data/spec/unit/rbeapi/client_spec.rb +211 -0
  83. metadata +65 -10
@@ -0,0 +1,354 @@
1
+ #
2
+ # Copyright (c) 2015, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'spec_helper'
33
+
34
+ require 'rbeapi/client'
35
+ require 'rbeapi/api/bgp'
36
+
37
+ describe Rbeapi::Api::BgpNeighbors do
38
+ subject { described_class.new(node) }
39
+
40
+ let(:node) do
41
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
42
+ Rbeapi::Client.connect_to('dut')
43
+ end
44
+
45
+ describe '#get' do
46
+ let(:entity) do
47
+ { peer_group: nil,
48
+ remote_as: nil,
49
+ send_community: false,
50
+ shutdown: false,
51
+ description: nil,
52
+ next_hop_self: false,
53
+ route_map_in: nil,
54
+ route_map_out: nil }
55
+ end
56
+
57
+ before do
58
+ node.config(['no router bgp 64600', 'router bgp 64600',
59
+ 'neighbor eBGP_GROUP peer-group'])
60
+ end
61
+
62
+ it 'returns the BGP neighbor resource' do
63
+ expect(subject.get('eBGP_GROUP')).to eq(entity)
64
+ end
65
+ end
66
+
67
+ describe '#getall' do
68
+ let(:entity) do
69
+ {
70
+ 'eBGP_GROUP' => {
71
+ peer_group: nil, remote_as: nil, send_community: false,
72
+ shutdown: false, description: nil, next_hop_self: false,
73
+ route_map_in: nil, route_map_out: nil
74
+ },
75
+ '192.168.255.1' => {
76
+ peer_group: 'eBGP_GROUP', remote_as: '65000', send_community: true,
77
+ shutdown: true, description: nil, next_hop_self: true,
78
+ route_map_in: nil, route_map_out: nil
79
+ },
80
+ '192.168.255.3' => {
81
+ peer_group: 'eBGP_GROUP', remote_as: '65001', send_community: true,
82
+ shutdown: true, description: nil, next_hop_self: true,
83
+ route_map_in: nil, route_map_out: nil
84
+ }
85
+ }
86
+ end
87
+
88
+ before do
89
+ node.config(['no router bgp 64600', 'router bgp 64600',
90
+ 'neighbor 192.168.255.1 peer-group eBGP_GROUP',
91
+ 'neighbor 192.168.255.1 remote-as 65000',
92
+ 'neighbor 192.168.255.3 peer-group eBGP_GROUP',
93
+ 'neighbor 192.168.255.3 remote-as 65001'])
94
+ end
95
+
96
+ it 'returns all the neighbors' do
97
+ expect(subject.getall).to eq(entity)
98
+ end
99
+
100
+ it 'returns a hash collection' do
101
+ expect(subject.getall).to be_a_kind_of(Hash)
102
+ end
103
+
104
+ it 'has three entries' do
105
+ expect(subject.getall.size).to eq(3)
106
+ end
107
+ end
108
+
109
+ describe '#create' do
110
+ let(:before) do
111
+ { peer_group: nil,
112
+ remote_as: nil,
113
+ send_community: true,
114
+ shutdown: true,
115
+ description: nil,
116
+ next_hop_self: true,
117
+ route_map_in: nil,
118
+ route_map_out: nil }
119
+ end
120
+
121
+ let(:after) do
122
+ { peer_group: nil,
123
+ remote_as: nil,
124
+ send_community: false,
125
+ shutdown: true,
126
+ description: nil,
127
+ next_hop_self: false,
128
+ route_map_in: nil,
129
+ route_map_out: nil }
130
+ end
131
+
132
+ before { node.config(['no router bgp 64600', 'router bgp 64600']) }
133
+
134
+ it 'create a new BGP neighbor' do
135
+ expect(subject.get('edge')).to eq(before)
136
+ expect(subject.create('edge')).to be_truthy
137
+
138
+ expect(subject.get('edge')).to eq(after)
139
+ end
140
+ end
141
+
142
+ describe '#delete' do
143
+ let(:before) do
144
+ { peer_group: nil,
145
+ remote_as: nil,
146
+ send_community: false,
147
+ shutdown: true,
148
+ description: nil,
149
+ next_hop_self: false,
150
+ route_map_in: nil,
151
+ route_map_out: nil }
152
+ end
153
+
154
+ let(:after) do
155
+ { peer_group: nil,
156
+ remote_as: nil,
157
+ send_community: true,
158
+ shutdown: true,
159
+ description: nil,
160
+ next_hop_self: true,
161
+ route_map_in: nil,
162
+ route_map_out: nil }
163
+ end
164
+
165
+ it 'delete a BGP resource' do
166
+ expect(subject.get('edge')).to eq(before)
167
+ expect(subject.delete('edge')).to be_truthy
168
+
169
+ expect(subject.get('edge')).to eq(after)
170
+ end
171
+ end
172
+
173
+ describe '#set_peer_group' do
174
+ before do
175
+ node.config(['no router bgp 64600', 'router bgp 64600',
176
+ 'neighbor eBGP_GROUP peer-group'])
177
+ end
178
+
179
+ it 'set the peer group' do
180
+ expect(subject.get('192.168.255.1')[:peer_group]).to eq(nil)
181
+ expect(subject.set_peer_group('192.168.255.1', value: 'eBGP_GROUP'))
182
+ .to be_truthy
183
+ expect(subject.get('192.168.255.1')[:peer_group]).to eq('eBGP_GROUP')
184
+ end
185
+
186
+ it 'remove the peer group value' do
187
+ expect(subject.set_peer_group('192.168.255.1', value: 'eBGP_GROUP'))
188
+ .to be_truthy
189
+ expect(subject.get('192.168.255.1')[:peer_group]).to eq('eBGP_GROUP')
190
+ expect(subject.set_peer_group('192.168.255.1', enable: false))
191
+ .to be_truthy
192
+ expect(subject.get('192.168.255.1')[:peer_group]).to eq(nil)
193
+ end
194
+
195
+ it 'defaults the peer group value' do
196
+ expect(subject.set_peer_group('192.168.255.1', value: 'eBGP_GROUP'))
197
+ .to be_truthy
198
+ expect(subject.set_peer_group('192.168.255.1', default: true))
199
+ .to be_truthy
200
+ expect(subject.get('192.168.255.1')[:peer_group]).to eq(nil)
201
+ end
202
+ end
203
+
204
+ describe '#set_remote_as' do
205
+ it 'set the remote AS value' do
206
+ expect(subject.get('eng')[:remote_as]).to eq(nil)
207
+ expect(subject.set_remote_as('eng', value: '10')).to be_truthy
208
+ expect(subject.get('eng')[:remote_as]).to eq('10')
209
+ end
210
+
211
+ it 'remove the remote AS value' do
212
+ expect(subject.get('eng')[:remote_as]).to eq('10')
213
+ expect(subject.set_remote_as('eng', enable: false))
214
+ .to be_truthy
215
+ expect(subject.get('eng')[:remote_as]).to eq(nil)
216
+ end
217
+
218
+ it 'defaults the remote AS value' do
219
+ expect(subject.set_remote_as('eng', value: '10')).to be_truthy
220
+ expect(subject.set_remote_as('eng', default: true))
221
+ .to be_truthy
222
+ expect(subject.get('eng')[:remote_as]).to eq(nil)
223
+ end
224
+ end
225
+
226
+ describe '#set_shutdown' do
227
+ it 'shutdown neighbor' do
228
+ expect(subject.get('eng')[:shutdown]).to eq(false)
229
+ expect(subject.set_shutdown('eng')).to be_truthy
230
+ expect(subject.get('eng')[:shutdown]).to eq(true)
231
+ end
232
+
233
+ it 'negate shutdown neighbor' do
234
+ expect(subject.get('eng')[:shutdown]).to eq(true)
235
+ expect(subject.set_shutdown('eng', enable: false)).to be_truthy
236
+ expect(subject.get('eng')[:shutdown]).to eq(true)
237
+ end
238
+
239
+ it 'default shutdown neighbor' do
240
+ expect(subject.get('eng')[:shutdown]).to eq(true)
241
+ expect(subject.set_shutdown('eng', default: true)).to be_truthy
242
+ expect(subject.get('eng')[:shutdown]).to eq(false)
243
+ end
244
+ end
245
+
246
+ describe '#set_send_community' do
247
+ it 'enable neighbor send community' do
248
+ expect(subject.get('eng')[:send_community]).to eq(false)
249
+ expect(subject.set_send_community('eng')).to be_truthy
250
+ expect(subject.get('eng')[:send_community]).to eq(true)
251
+ end
252
+
253
+ it 'negate neighbor send community' do
254
+ expect(subject.get('eng')[:send_community]).to eq(true)
255
+ expect(subject.set_send_community('eng', enable: false)).to be_truthy
256
+ expect(subject.get('eng')[:send_community]).to eq(false)
257
+ end
258
+
259
+ it 'default neighbor send community' do
260
+ expect(subject.set_send_community('eng')).to be_truthy
261
+ expect(subject.get('eng')[:send_community]).to eq(true)
262
+ expect(subject.set_send_community('eng', default: true)).to be_truthy
263
+ expect(subject.get('eng')[:send_community]).to eq(false)
264
+ end
265
+ end
266
+
267
+ describe '#set_next_hop_self' do
268
+ it 'enable neighbor next hop self' do
269
+ expect(subject.get('eng')[:next_hop_self]).to eq(false)
270
+ expect(subject.set_next_hop_self('eng')).to be_truthy
271
+ expect(subject.get('eng')[:next_hop_self]).to eq(true)
272
+ end
273
+
274
+ it 'negate neighbor next hop self' do
275
+ expect(subject.get('eng')[:next_hop_self]).to eq(true)
276
+ expect(subject.set_next_hop_self('eng', enable: false)).to be_truthy
277
+ expect(subject.get('eng')[:next_hop_self]).to eq(false)
278
+ end
279
+
280
+ it 'default neighbor next hop self' do
281
+ expect(subject.set_next_hop_self('eng')).to be_truthy
282
+ expect(subject.get('eng')[:next_hop_self]).to eq(true)
283
+ expect(subject.set_next_hop_self('eng', default: true)).to be_truthy
284
+ expect(subject.get('eng')[:next_hop_self]).to eq(false)
285
+ end
286
+ end
287
+
288
+ describe '#set_route_map_in' do
289
+ it 'set route map in value' do
290
+ expect(subject.get('eng')[:route_map_in]).to eq(nil)
291
+ expect(subject.set_route_map_in('eng', value: 'edge')).to be_truthy
292
+ expect(subject.get('eng')[:route_map_in]).to eq('edge')
293
+ end
294
+
295
+ it 'negate route map in value' do
296
+ expect(subject.get('eng')[:route_map_in]).to eq('edge')
297
+ expect(subject.set_route_map_in('eng', value: 'edge', enable: false))
298
+ .to be_truthy
299
+ expect(subject.get('eng')[:route_map_in]).to eq(nil)
300
+ end
301
+
302
+ it 'default route map in value' do
303
+ expect(subject.set_route_map_in('eng', value: 'edge')).to be_truthy
304
+ expect(subject.get('eng')[:route_map_in]).to eq('edge')
305
+ expect(subject.set_route_map_in('eng', value: 'edge', default: true))
306
+ .to be_truthy
307
+ expect(subject.get('eng')[:route_map_in]).to eq(nil)
308
+ end
309
+ end
310
+
311
+ describe '#set_route_map_out' do
312
+ it 'set route map out value' do
313
+ expect(subject.get('eng')[:route_map_out]).to eq(nil)
314
+ expect(subject.set_route_map_out('eng', value: 'edge')).to be_truthy
315
+ expect(subject.get('eng')[:route_map_out]).to eq('edge')
316
+ end
317
+
318
+ it 'negate route map out value' do
319
+ expect(subject.get('eng')[:route_map_out]).to eq('edge')
320
+ expect(subject.set_route_map_out('eng', value: 'edge', enable: false))
321
+ .to be_truthy
322
+ expect(subject.get('eng')[:route_map_out]).to eq(nil)
323
+ end
324
+
325
+ it 'default route map out value' do
326
+ expect(subject.set_route_map_out('eng', value: 'edge')).to be_truthy
327
+ expect(subject.get('eng')[:route_map_out]).to eq('edge')
328
+ expect(subject.set_route_map_out('eng', value: 'edge', default: true))
329
+ .to be_truthy
330
+ expect(subject.get('eng')[:route_map_out]).to eq(nil)
331
+ end
332
+ end
333
+
334
+ describe '#set_description' do
335
+ it 'set the description value' do
336
+ expect(subject.get('eng')[:description]).to eq(nil)
337
+ expect(subject.set_description('eng', value: 'text')).to be_truthy
338
+ expect(subject.get('eng')[:description]).to eq('text')
339
+ end
340
+
341
+ it 'negate the description value' do
342
+ expect(subject.get('eng')[:description]).to eq('text')
343
+ expect(subject.set_description('eng', enable: false)).to be_truthy
344
+ expect(subject.get('eng')[:description]).to eq(nil)
345
+ end
346
+
347
+ it 'defaults the description value' do
348
+ expect(subject.set_description('eng', value: 'text')).to be_truthy
349
+ expect(subject.get('eng')[:description]).to eq('text')
350
+ expect(subject.set_description('eng', default: true)).to be_truthy
351
+ expect(subject.get('eng')[:description]).to eq(nil)
352
+ end
353
+ end
354
+ end
@@ -0,0 +1,275 @@
1
+ #
2
+ # Copyright (c) 2015, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'spec_helper'
33
+
34
+ require 'rbeapi/client'
35
+ require 'rbeapi/api/bgp'
36
+
37
+ describe Rbeapi::Api::Bgp do
38
+ subject { described_class.new(node) }
39
+
40
+ let(:node) do
41
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
42
+ Rbeapi::Client.connect_to('dut')
43
+ end
44
+
45
+ let(:test) do
46
+ { bgp_as: '64600',
47
+ router_id: '192.168.254.1',
48
+ shutdown: false,
49
+ maximum_paths: 32,
50
+ maximum_ecmp_paths: 32,
51
+ networks: [
52
+ { prefix: '192.168.254.1', masklen: 32, route_map: nil },
53
+ { prefix: '192.168.254.2', masklen: 32, route_map: 'rmap' }
54
+ ],
55
+ neighbors: {
56
+ 'eBGP_GROUP' => {
57
+ peer_group: nil, remote_as: nil, send_community: false,
58
+ shutdown: false, description: nil, next_hop_self: false,
59
+ route_map_in: nil, route_map_out: nil
60
+ },
61
+ '192.168.255.1' => {
62
+ peer_group: 'eBGP_GROUP', remote_as: '65000', send_community: true,
63
+ shutdown: true, description: nil, next_hop_self: true,
64
+ route_map_in: nil, route_map_out: nil
65
+ },
66
+ '192.168.255.3' => {
67
+ peer_group: 'eBGP_GROUP', remote_as: '65001', send_community: true,
68
+ shutdown: true, description: nil, next_hop_self: true,
69
+ route_map_in: nil, route_map_out: nil
70
+ }
71
+ }
72
+ }
73
+ end
74
+
75
+ let(:response) do
76
+ {
77
+ bgp_as: '1000',
78
+ router_id: nil,
79
+ shutdown: false,
80
+ maximum_paths: 1,
81
+ maximum_ecmp_paths: 128,
82
+ networks: [],
83
+ neighbors: {}
84
+ }
85
+ end
86
+
87
+ describe '#get' do
88
+ before do
89
+ node.config(['no router bgp 64600', 'router bgp 64600',
90
+ 'router-id 192.168.254.1', 'maximum-paths 32 ecmp 32',
91
+ 'neighbor 192.168.255.1 peer-group eBGP_GROUP',
92
+ 'neighbor 192.168.255.1 remote-as 65000',
93
+ 'neighbor 192.168.255.3 peer-group eBGP_GROUP',
94
+ 'neighbor 192.168.255.3 remote-as 65001',
95
+ 'network 192.168.254.1/32',
96
+ 'network 192.168.254.2/32 route-map rmap',
97
+ 'aggregate-address 192.168.255.0/28 summary-only'])
98
+ end
99
+
100
+ it 'returns the BGP resource' do
101
+ expect(subject.get).to eq(test)
102
+ end
103
+ end
104
+
105
+ describe '#create' do
106
+ before do
107
+ node.config(['no router bgp 64600'])
108
+ end
109
+
110
+ it 'create a new BGP resource' do
111
+ expect(subject.get).to eq(nil)
112
+ expect(subject.create('1000')).to be_truthy
113
+ expect(subject.get).to eq(response)
114
+ end
115
+
116
+ it 'create with enable' do
117
+ expect(subject.get).to eq(nil)
118
+ expect(subject.create('1000', enable: true)).to be_truthy
119
+ expect(subject.get).to eq(response)
120
+ end
121
+
122
+ it 'create with router_id' do
123
+ expect(subject.get).to eq(nil)
124
+ expect(subject.create('1000', router_id: '1.2.3.4')).to be_truthy
125
+ expect(subject.get[:router_id]).to eq('1.2.3.4')
126
+ end
127
+
128
+ it 'create with maximum paths' do
129
+ expect(subject.get).to eq(nil)
130
+ expect(subject.create('1000', maximum_paths: 3)).to be_truthy
131
+ expect(subject.get[:maximum_paths]).to eq(3)
132
+ end
133
+
134
+ it 'create with maximum paths and ecmp paths' do
135
+ expect(subject.get).to eq(nil)
136
+ expect(subject.create('1000', maximum_paths: 13,
137
+ maximum_ecmp_paths: 13)).to be_truthy
138
+ expect(subject.get[:maximum_paths]).to eq(13)
139
+ expect(subject.get[:maximum_ecmp_paths]).to eq(13)
140
+ end
141
+
142
+ it 'raises ArgumentError for create with ecmp paths only' do
143
+ expect { subject.create('1000', maximum_ecmp_paths: 13) }.to \
144
+ raise_error ArgumentError
145
+ end
146
+
147
+ it 'create with all options set' do
148
+ expect(subject.create('1000', enable: true, router_id: '1.2.3.4',
149
+ maximum_paths: 13,
150
+ maximum_ecmp_paths: 13)).to be_truthy
151
+ expect(subject.get[:router_id]).to eq('1.2.3.4')
152
+ expect(subject.get[:maximum_paths]).to eq(13)
153
+ expect(subject.get[:maximum_ecmp_paths]).to eq(13)
154
+ end
155
+ end
156
+
157
+ describe '#delete' do
158
+ before do
159
+ node.config(['no router bgp 1000', 'router bgp 1000'])
160
+ end
161
+
162
+ it 'delete a BGP resource' do
163
+ expect(subject.get).to eq(response)
164
+ expect(subject.delete).to be_truthy
165
+ expect(subject.get).to eq(nil)
166
+ end
167
+ end
168
+
169
+ describe '#default' do
170
+ before do
171
+ node.config(['no router bgp 1000', 'router bgp 1000',
172
+ 'maximum-paths 13 ecmp 15'])
173
+ end
174
+
175
+ let(:before) do
176
+ {
177
+ bgp_as: '1000',
178
+ router_id: nil,
179
+ shutdown: false,
180
+ maximum_paths: 13,
181
+ maximum_ecmp_paths: 15,
182
+ networks: [],
183
+ neighbors: {}
184
+ }
185
+ end
186
+
187
+ it 'sets router to default value' do
188
+ expect(subject.get).to eq(before)
189
+ expect(subject.default).to be_truthy
190
+ expect(subject.get).to eq(nil)
191
+ end
192
+ end
193
+
194
+ describe '#set_router_id' do
195
+ before do
196
+ node.config(['no router bgp 1000', 'router bgp 1000'])
197
+ end
198
+
199
+ it 'set the router id' do
200
+ expect(subject.set_router_id(value: '1.2.3.4')).to be_truthy
201
+ expect(subject.get[:router_id]).to eq('1.2.3.4')
202
+ end
203
+
204
+ it 'remove the router-id without a value' do
205
+ expect(subject.set_router_id(enable: false)).to be_truthy
206
+ expect(subject.get[:router_id]).to eq(nil)
207
+ end
208
+
209
+ it 'remove the router-id with a value' do
210
+ expect(subject.set_router_id(value: '1.2.3.4', enable: false))
211
+ .to be_truthy
212
+ expect(subject.get[:router_id]).to eq(nil)
213
+ end
214
+
215
+ it 'defaults the router-id without a value' do
216
+ expect(subject.set_router_id(value: '1.2.3.4')).to be_truthy
217
+ expect(subject.set_router_id(default: true)).to be_truthy
218
+ expect(subject.get[:router_id]).to eq(nil)
219
+ end
220
+
221
+ it 'defaults the router-id with a value' do
222
+ expect(subject.set_router_id(value: '1.2.3.4', default: true))
223
+ .to be_truthy
224
+ expect(subject.get[:router_id]).to eq(nil)
225
+ end
226
+ end
227
+
228
+ describe '#set_shutdown' do
229
+ it 'enable BGP routing process' do
230
+ expect(subject.set_shutdown(enable: true)).to be_truthy
231
+ end
232
+
233
+ it 'disable BGP routing process' do
234
+ expect(subject.set_shutdown(enable: false)).to be_truthy
235
+ end
236
+
237
+ it 'default BGP routing process state' do
238
+ expect(subject.set_shutdown(default: true)).to be_truthy
239
+ end
240
+ end
241
+
242
+ describe '#set_maximum_paths' do
243
+ it 'set the maximum paths and ecmp paths' do
244
+ expect(subject.set_maximum_paths(13, 16)).to be_truthy
245
+ end
246
+
247
+ it 'remove the maximum paths' do
248
+ expect(subject.set_maximum_paths(0, 0, enable: false)).to be_truthy
249
+ end
250
+
251
+ it 'defaults the maximum paths' do
252
+ expect(subject.set_maximum_paths(0, 0, default: true)).to be_truthy
253
+ end
254
+ end
255
+
256
+ describe '#add_network' do
257
+ it 'add a BGP network with a route map' do
258
+ expect(subject.add_network('1.2.3.0', 24, 'eng')).to be_truthy
259
+ end
260
+
261
+ it 'add a BGP network without a route map' do
262
+ expect(subject.add_network('1.2.3.0', 24)).to be_truthy
263
+ end
264
+ end
265
+
266
+ describe '#remove_network' do
267
+ it 'remove a BGP network with a route map' do
268
+ expect(subject.remove_network('1.2.3.0', 24, 'eng')).to be_truthy
269
+ end
270
+
271
+ it 'remove a BGP network without a route map' do
272
+ expect(subject.remove_network('1.2.3.0', 24)).to be_truthy
273
+ end
274
+ end
275
+ end