rbeapi 0.4.0 → 0.5.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.
- data/.gitignore +3 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +1 -1
- data/README.md +11 -11
- data/Rakefile +19 -0
- data/guide/Makefile +177 -0
- data/guide/_static/arista_logo_11-trans-w.png +0 -0
- data/guide/_static/arista_logo_jpg-11.jpg +0 -0
- data/guide/_static/favicon.ico +0 -0
- data/guide/conf.py +279 -0
- data/guide/cookbook.rst +4 -0
- data/guide/developing.rst +4 -0
- data/guide/faq.rst +4 -0
- data/guide/index.rst +23 -0
- data/guide/installation.rst +4 -0
- data/guide/license.rst +5 -0
- data/guide/overview.rst +20 -0
- data/guide/quickstart.rst +4 -0
- data/guide/release-notes-0.5.0.rst +60 -0
- data/guide/release-notes.rst +6 -0
- data/guide/testing.rst +4 -0
- data/guide/troubleshooting.rst +1 -0
- data/lib/rbeapi/api/aaa.rb +54 -18
- data/lib/rbeapi/api/acl.rb +60 -2
- data/lib/rbeapi/api/bgp.rb +81 -0
- data/lib/rbeapi/api/dns.rb +48 -2
- data/lib/rbeapi/api/interfaces.rb +97 -32
- data/lib/rbeapi/api/ipinterfaces.rb +13 -2
- data/lib/rbeapi/api/logging.rb +11 -2
- data/lib/rbeapi/api/mlag.rb +20 -10
- data/lib/rbeapi/api/ntp.rb +4 -3
- data/lib/rbeapi/api/ospf.rb +102 -10
- data/lib/rbeapi/api/prefixlists.rb +47 -4
- data/lib/rbeapi/api/radius.rb +9 -9
- data/lib/rbeapi/api/routemaps.rb +7 -5
- data/lib/rbeapi/api/snmp.rb +13 -4
- data/lib/rbeapi/api/staticroutes.rb +1 -1
- data/lib/rbeapi/api/stp.rb +39 -14
- data/lib/rbeapi/api/switchports.rb +126 -2
- data/lib/rbeapi/api/system.rb +24 -3
- data/lib/rbeapi/api/tacacs.rb +9 -10
- data/lib/rbeapi/api/users.rb +12 -3
- data/lib/rbeapi/api/varp.rb +40 -8
- data/lib/rbeapi/api/vlans.rb +15 -5
- data/lib/rbeapi/client.rb +19 -11
- data/lib/rbeapi/eapilib.rb +8 -0
- data/lib/rbeapi/utils.rb +10 -0
- data/lib/rbeapi/version.rb +1 -1
- data/spec/fixtures/eapi.conf.yaml +6 -0
- data/spec/fixtures/empty.conf +0 -0
- data/spec/fixtures/env_path.conf +5 -0
- data/spec/fixtures/test.conf +39 -0
- data/spec/fixtures/wildcard.conf +43 -0
- data/spec/system/rbeapi/api/aaa_groups_spec.rb +122 -0
- data/spec/system/rbeapi/api/aaa_spec.rb +90 -0
- data/spec/system/{api_acl_spec.rb → rbeapi/api/acl_spec.rb} +0 -0
- data/spec/system/rbeapi/api/bgp_neighbors_spec.rb +354 -0
- data/spec/system/rbeapi/api/bgp_spec.rb +275 -0
- data/spec/system/rbeapi/api/dns_spec.rb +17 -1
- data/spec/system/rbeapi/api/interfaces_base_spec.rb +46 -5
- data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +14 -0
- data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +68 -0
- data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +0 -1
- data/spec/system/{api_ospf_interfaces_spec.rb → rbeapi/api/ospf_interfaces_spec.rb} +3 -2
- data/spec/system/{api_ospf_spec.rb → rbeapi/api/ospf_spec.rb} +11 -2
- data/spec/system/rbeapi/api/routemaps_spec.rb +3 -4
- data/spec/system/rbeapi/api/snmp_spec.rb +65 -0
- data/spec/system/rbeapi/api/staticroutes_spec.rb +177 -0
- data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -0
- data/spec/system/rbeapi/api/stp_interfaces_spec.rb +7 -0
- data/spec/system/rbeapi/api/switchports_spec.rb +86 -16
- data/spec/system/rbeapi/api/users_spec.rb +324 -0
- data/spec/system/rbeapi/api/varp_interfaces_spec.rb +34 -0
- data/spec/system/rbeapi/api/vrrp_spec.rb +707 -0
- data/spec/system/rbeapi/client_spec.rb +367 -0
- data/spec/unit/rbeapi/api/aaa/aaa_groups_spec.rb +111 -0
- data/spec/unit/rbeapi/api/aaa/aaa_spec.rb +77 -0
- data/spec/unit/rbeapi/api/aaa/fixture_aaa.text +3 -0
- data/spec/unit/rbeapi/api/switchports/default_spec.rb +249 -0
- data/spec/unit/rbeapi/api/switchports/fixture_switchports.text +284 -0
- data/spec/unit/rbeapi/api/users/default_spec.rb +1 -1
- data/spec/unit/rbeapi/client_spec.rb +211 -0
- metadata +65 -10
@@ -114,11 +114,27 @@ describe Rbeapi::Api::Dns do
|
|
114
114
|
expect(subject.get[:domain_list]).to be_empty
|
115
115
|
end
|
116
116
|
|
117
|
-
it 'default the name servers list' do
|
117
|
+
it 'default true the name servers list' do
|
118
118
|
expect(subject.get[:domain_list]).to be_empty
|
119
|
+
expect(subject.set_domain_list(value: servers)).to be_truthy
|
119
120
|
expect(subject.set_domain_list(default: true)).to be_truthy
|
120
121
|
expect(subject.get[:domain_list]).to be_empty
|
121
122
|
end
|
123
|
+
|
124
|
+
it 'default false the name servers list' do
|
125
|
+
expect(subject.get[:domain_list]).to be_empty
|
126
|
+
expect(subject.set_domain_list(default: false,
|
127
|
+
value: servers)).to be_truthy
|
128
|
+
expect(subject.get[:domain_list]).to eq(servers)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'default the name servers list with previous values' do
|
132
|
+
expect(subject.get[:domain_list]).to be_empty
|
133
|
+
expect(subject.set_domain_list(value: %w(foob bat))).to be_truthy
|
134
|
+
expect(subject.set_domain_list(default: false,
|
135
|
+
value: servers)).to be_truthy
|
136
|
+
expect(subject.get[:domain_list]).to eq(servers)
|
137
|
+
end
|
122
138
|
end
|
123
139
|
|
124
140
|
describe '#add_domain_list' do
|
@@ -11,15 +11,56 @@ describe Rbeapi::Api::Interfaces do
|
|
11
11
|
Rbeapi::Client.connect_to('dut')
|
12
12
|
end
|
13
13
|
|
14
|
+
describe '#respond_to?' do
|
15
|
+
it 'test to validate endpoint' do
|
16
|
+
expect(subject.respond_to?('get', 'Ethernet1')).to be_truthy
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
describe '#get' do
|
15
|
-
|
16
|
-
|
21
|
+
context 'with interface Loopback' do
|
22
|
+
let(:entity) do
|
23
|
+
{ name: 'Loopback0', type: 'generic', description: '', shutdown: false }
|
24
|
+
end
|
25
|
+
|
26
|
+
before { node.config(['no interface Loopback0', 'interface Loopback0']) }
|
27
|
+
|
28
|
+
it 'returns the interface resource' do
|
29
|
+
expect(subject.get('Loopback0')).to eq(entity)
|
30
|
+
end
|
17
31
|
end
|
18
32
|
|
19
|
-
|
33
|
+
context 'with interface Port-Channel' do
|
34
|
+
let(:entity) do
|
35
|
+
{ name: 'Port-Channel1', type: 'portchannel', description: '',
|
36
|
+
shutdown: false, members: [], lacp_mode: 'on', minimum_links: '0',
|
37
|
+
lacp_fallback: 'disabled', lacp_timeout: '90' }
|
38
|
+
end
|
39
|
+
|
40
|
+
before do
|
41
|
+
node.config(['no interface Loopback0', 'no interface Port-Channel1',
|
42
|
+
'interface Port-Channel1'])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns the interface resource' do
|
46
|
+
expect(subject.get('Port-Channel1')).to eq(entity)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with interface Vxlan' do
|
51
|
+
let(:entity) do
|
52
|
+
{ name: 'Vxlan1', type: 'vxlan', description: '',
|
53
|
+
shutdown: false, source_interface: '', multicast_group: '',
|
54
|
+
udp_port: 4789, flood_list: [], vlans: {} }
|
55
|
+
end
|
56
|
+
|
57
|
+
before do
|
58
|
+
node.config(['no interface Vxlan1', 'interface Vxlan1'])
|
59
|
+
end
|
20
60
|
|
21
|
-
|
22
|
-
|
61
|
+
it 'returns the interface resource' do
|
62
|
+
expect(subject.get('Vxlan1')).to eq(entity)
|
63
|
+
end
|
23
64
|
end
|
24
65
|
end
|
25
66
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
require 'rbeapi/client'
|
@@ -85,6 +86,19 @@ describe Rbeapi::Api::Interfaces do
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
89
|
+
describe '#set_speed' do
|
90
|
+
before { node.config(['default interface Ethernet1']) }
|
91
|
+
|
92
|
+
it 'sets default true' do
|
93
|
+
expect(subject.set_speed('Ethernet1', default: true)).to be_truthy
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'sets enable true' do
|
97
|
+
expect(subject.set_speed('Ethernet1', default: false,
|
98
|
+
enable: true)).to be_falsy
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
88
102
|
describe '#set_sflow' do
|
89
103
|
it 'sets the sflow value to true' do
|
90
104
|
node.config(['interface Ethernet1', 'no sflow enable'])
|
@@ -134,6 +134,74 @@ describe Rbeapi::Api::Interfaces do
|
|
134
134
|
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
135
135
|
Ethernet3))
|
136
136
|
end
|
137
|
+
|
138
|
+
it 'updates the member interfaces and mode on existing interface' do
|
139
|
+
node.config(['no interface Port-Channel1', 'interface Ethernet1-2',
|
140
|
+
'channel-group 1 mode on'])
|
141
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
142
|
+
Ethernet2))
|
143
|
+
expect(subject.get('Port-Channel1')[:lacp_mode]).to eq('on')
|
144
|
+
expect(subject.set_members('Port-Channel1',
|
145
|
+
%w(Ethernet1 Ethernet3),
|
146
|
+
'active')).to be_truthy
|
147
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
148
|
+
Ethernet3))
|
149
|
+
expect(subject.get('Port-Channel1')[:lacp_mode]).to eq('active')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '#add_member' do
|
154
|
+
before do
|
155
|
+
node.config(['no interface Port-Channel1',
|
156
|
+
'interface Port-Channel1'])
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'adds new members to the port-channel interface' do
|
160
|
+
node.config(['no interface Port-Channel1', 'interface Port-Channel1'])
|
161
|
+
expect(subject.get('Port-Channel1')[:members]).not_to include('Ethernet1')
|
162
|
+
expect(subject.add_member('Port-Channel1', 'Ethernet1')).to be_truthy
|
163
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(['Ethernet1'])
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'updates the member interfaces on existing interface' do
|
167
|
+
node.config(['no interface Port-Channel1', 'interface Ethernet1-2',
|
168
|
+
'channel-group 1 mode on'])
|
169
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
170
|
+
Ethernet2))
|
171
|
+
expect(subject.add_member('Port-Channel1', 'Ethernet3')).to be_truthy
|
172
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
173
|
+
Ethernet2
|
174
|
+
Ethernet3))
|
175
|
+
expect(subject.get('Port-Channel1')[:lacp_mode]).to eq('on')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'no update to the member interfaces on existing interface' do
|
179
|
+
node.config(['no interface Port-Channel1', 'interface Ethernet1-2',
|
180
|
+
'channel-group 1 mode active'])
|
181
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
182
|
+
Ethernet2))
|
183
|
+
expect(subject.add_member('Port-Channel1', 'Ethernet2')).to be_truthy
|
184
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
185
|
+
Ethernet2))
|
186
|
+
expect(subject.get('Port-Channel1')[:lacp_mode]).to eq('active')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#remove_member' do
|
191
|
+
before do
|
192
|
+
node.config(['no interface Port-Channel1',
|
193
|
+
'interface Port-Channel1'])
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'removes the member interface on existing interface' do
|
197
|
+
node.config(['no interface Port-Channel1', 'interface Ethernet1-2',
|
198
|
+
'channel-group 1 mode on'])
|
199
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(%w(Ethernet1
|
200
|
+
Ethernet2))
|
201
|
+
expect(subject.remove_member('Port-Channel1', 'Ethernet1')).to be_truthy
|
202
|
+
expect(subject.get('Port-Channel1')[:members]).to eq(['Ethernet2'])
|
203
|
+
expect(subject.get('Port-Channel1')[:lacp_mode]).to eq('on')
|
204
|
+
end
|
137
205
|
end
|
138
206
|
|
139
207
|
describe '#set_lacp_mode' do
|
@@ -41,7 +41,6 @@ describe Rbeapi::Api::Interfaces do
|
|
41
41
|
before { node.config('no interface Vxlan1') }
|
42
42
|
|
43
43
|
it 'creates a new interface resource' do
|
44
|
-
expect(subject.get('Vxlan1')).to be_nil
|
45
44
|
expect(subject.create('Vxlan1')).to be_truthy
|
46
45
|
expect(subject.get('Vxlan1')).not_to be_nil
|
47
46
|
end
|
@@ -12,8 +12,9 @@ describe Rbeapi::Api::OspfInterfaces do
|
|
12
12
|
describe '#get' do
|
13
13
|
before do
|
14
14
|
node.config(['default interface Ethernet1', 'interface Ethernet1',
|
15
|
-
'no switchport', 'ip address 88.99.99.99/24',
|
16
|
-
'
|
15
|
+
'no switchport', 'ip address 88.99.99.99/24',
|
16
|
+
'ip ospf network point-to-point',
|
17
|
+
'exit', 'default interface Ethernet2'])
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'returns an ospf interface resource instance' do
|
@@ -10,10 +10,19 @@ describe Rbeapi::Api::Ospf do
|
|
10
10
|
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
11
|
|
12
12
|
describe '#get' do
|
13
|
-
before
|
13
|
+
before do
|
14
|
+
node.config(['no router ospf 1',
|
15
|
+
'router ospf 1',
|
16
|
+
'router-id 1.1.1.1',
|
17
|
+
'redistribute static route-map word',
|
18
|
+
'network 192.168.10.10/24 area 0.0.0.0',
|
19
|
+
'network 192.168.11.10/24 area 0.0.0.0'])
|
20
|
+
end
|
14
21
|
|
15
22
|
let(:entity) do
|
16
|
-
{ 'router_id' => '',
|
23
|
+
{ 'router_id' => '1.1.1.1',
|
24
|
+
'areas' => { '0.0.0.0' => ['192.168.10.0/24', '192.168.11.0/24'] },
|
25
|
+
'redistribute' => { 'static' => { 'route_map' => 'word' } } }
|
17
26
|
end
|
18
27
|
|
19
28
|
it 'returns an ospf resource instance' do
|
@@ -15,8 +15,7 @@ describe Rbeapi::Api::Routemaps do
|
|
15
15
|
let(:resource) { subject.get }
|
16
16
|
|
17
17
|
before do
|
18
|
-
node.config(['no route-map test',
|
19
|
-
'no route-map test2', 'no route-map test3',
|
18
|
+
node.config(['no route-map test',
|
20
19
|
'route-map test permit 10',
|
21
20
|
'route-map test permit 20', 'description descript',
|
22
21
|
'match ip address prefix-list MYLOOPBACK',
|
@@ -90,8 +89,8 @@ describe Rbeapi::Api::Routemaps do
|
|
90
89
|
expect(subject.getall).to be_a_kind_of(Hash)
|
91
90
|
end
|
92
91
|
|
93
|
-
it 'has
|
94
|
-
expect(subject.getall.count).to
|
92
|
+
it 'has at least two entries' do
|
93
|
+
expect(subject.getall.count).to be >= 2
|
95
94
|
end
|
96
95
|
|
97
96
|
it 'returns the routemap collection' do
|
@@ -23,6 +23,30 @@ describe Rbeapi::Api::Snmp do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe '#set_notification' do
|
27
|
+
before { node.config(['default snmp-server']) }
|
28
|
+
|
29
|
+
it 'configures the snmp notification value to on' do
|
30
|
+
expect(subject.set_notification(state: 'on',
|
31
|
+
name: 'bgp')).to be_truthy
|
32
|
+
expect(subject.get[:notifications][0]).to eq(name: 'bgp',
|
33
|
+
state: 'on')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'configures the snmp notification value to off' do
|
37
|
+
expect(subject.set_notification(state: 'off',
|
38
|
+
name: 'bgp')).to be_truthy
|
39
|
+
expect(subject.get[:notifications][0]).to eq(name: 'bgp',
|
40
|
+
state: 'off')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'configures the snmp notification value to default' do
|
44
|
+
expect(subject.set_notification(state: 'default',
|
45
|
+
name: 'all')).to be_truthy
|
46
|
+
expect(subject.get).to include(:notifications)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
26
50
|
describe '#set_location' do
|
27
51
|
before { node.config(['no snmp-server location']) }
|
28
52
|
|
@@ -119,6 +143,47 @@ describe Rbeapi::Api::Snmp do
|
|
119
143
|
end
|
120
144
|
end
|
121
145
|
|
146
|
+
describe '#add_community' do
|
147
|
+
before { node.config('no snmp-server community foo') }
|
148
|
+
|
149
|
+
it 'adds the specified community' do
|
150
|
+
expect(subject.add_community('foo')).to be_truthy
|
151
|
+
expect(subject.get[:communities]['foo'][:access]).to eq('ro')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'adds the specified community ro' do
|
155
|
+
expect(subject.add_community('foo', 'ro')).to be_truthy
|
156
|
+
expect(subject.get[:communities]['foo'][:access]).to eq('ro')
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'adds the specified community rw' do
|
160
|
+
expect(subject.add_community('foo', 'rw')).to be_truthy
|
161
|
+
expect(subject.get[:communities]['foo'][:access]).to eq('rw')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#remove_community' do
|
166
|
+
before { node.config('default snmp-server community foo') }
|
167
|
+
|
168
|
+
it 'removes the specified community foo' do
|
169
|
+
expect(subject.remove_community('foo')).to be_truthy
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#set_community_access' do
|
174
|
+
before { node.config('default snmp-server community foo') }
|
175
|
+
|
176
|
+
it 'sets the community access to ro' do
|
177
|
+
expect(subject.set_community_access('foo', 'ro')).to be_truthy
|
178
|
+
expect(subject.get[:communities]['foo'][:access]).to eq('ro')
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'sets the community access to rw' do
|
182
|
+
expect(subject.set_community_access('foo', 'rw')).to be_truthy
|
183
|
+
expect(subject.get[:communities]['foo'][:access]).to eq('rw')
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
122
187
|
describe '#set_community_acl' do
|
123
188
|
before do
|
124
189
|
node.config(['no snmp-server community foo',
|
@@ -0,0 +1,177 @@
|
|
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/staticroutes'
|
36
|
+
|
37
|
+
describe Rbeapi::Api::Staticroutes 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 '#getall' do
|
46
|
+
let(:resource) { subject.getall }
|
47
|
+
|
48
|
+
before do
|
49
|
+
node.config(['no ip route 1.2.3.4/32',
|
50
|
+
'no ip route 192.0.2.0/24',
|
51
|
+
'no ip route 192.0.3.0/24',
|
52
|
+
'ip route 1.2.3.4/32 Ethernet7 4 tag 3 name frank',
|
53
|
+
'ip route 1.2.3.4/32 Null0 32 tag 3 name fred',
|
54
|
+
'ip route 192.0.2.0/24 Ethernet7 3 tag 0 name dummy1',
|
55
|
+
'ip route 192.0.3.0/24 192.0.3.1 1 tag 0 name dummy2'])
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns the staticroute collection' do
|
59
|
+
expect(subject.getall).to include(destination: '1.2.3.4/32',
|
60
|
+
nexthop: 'Ethernet7',
|
61
|
+
distance: '4',
|
62
|
+
tag: '3',
|
63
|
+
name: 'frank')
|
64
|
+
expect(subject.getall).to include(destination: '1.2.3.4/32',
|
65
|
+
nexthop: 'Null0',
|
66
|
+
distance: '32',
|
67
|
+
tag: '3',
|
68
|
+
name: 'fred')
|
69
|
+
expect(subject.getall).to include(destination: '192.0.2.0/24',
|
70
|
+
nexthop: 'Ethernet7',
|
71
|
+
distance: '3',
|
72
|
+
tag: '0',
|
73
|
+
name: 'dummy1')
|
74
|
+
expect(subject.getall).to include(destination: '192.0.3.0/24',
|
75
|
+
nexthop: '192.0.3.1',
|
76
|
+
distance: '1',
|
77
|
+
tag: '0',
|
78
|
+
name: 'dummy2')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns a hash collection' do
|
82
|
+
expect(subject.getall).to be_a_kind_of(Array)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'has four entries' do
|
86
|
+
expect(subject.getall.size).to eq(4)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#create' do
|
91
|
+
let(:resource) { subject.getall }
|
92
|
+
|
93
|
+
before(:each) do
|
94
|
+
node.config(['no ip route 1.2.3.4/32',
|
95
|
+
'no ip route 192.0.2.0/24',
|
96
|
+
'no ip route 192.0.3.0/24'])
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'creates a new staticroute resoure' do
|
100
|
+
it 'with minimum input' do
|
101
|
+
expect(subject.getall).to eq([])
|
102
|
+
expect(subject.create('192.0.2.0/24', 'Ethernet1')).to be_truthy
|
103
|
+
expect(subject.getall).to eq(resource)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'with a router_ip' do
|
107
|
+
node.config(['ip route 192.0.2.0/24 Ethernet1'])
|
108
|
+
expect(subject.getall).to eq(resource)
|
109
|
+
|
110
|
+
expect(subject.create('192.0.2.0/24', 'Ethernet1',
|
111
|
+
router_ip: '192.168.1.1')).to be_truthy
|
112
|
+
expect(subject.getall).to eq(resource)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'with distance (metric)' do
|
116
|
+
node.config(['ip route 192.0.2.0/24 Ethernet1'])
|
117
|
+
expect(subject.getall).to eq(resource)
|
118
|
+
|
119
|
+
expect(subject.create('192.0.2.0/24', 'Ethernet1', distance: 254))
|
120
|
+
.to be_truthy
|
121
|
+
expect(subject.getall).to include(destination: '192.0.2.0/24',
|
122
|
+
nexthop: 'Ethernet1',
|
123
|
+
distance: '254',
|
124
|
+
tag: '0',
|
125
|
+
name: nil)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'with a tag' do
|
129
|
+
node.config(['ip route 192.0.2.0/24 Ethernet1'])
|
130
|
+
expect(subject.getall).to eq(resource)
|
131
|
+
|
132
|
+
expect(subject.create('192.0.2.0/24', 'Ethernet1', tag: 3))
|
133
|
+
.to be_truthy
|
134
|
+
expect(subject.getall).to include(destination: '192.0.2.0/24',
|
135
|
+
nexthop: 'Ethernet1',
|
136
|
+
distance: '1',
|
137
|
+
tag: '3',
|
138
|
+
name: nil)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'with a name' do
|
142
|
+
node.config(['ip route 192.0.2.0/24 Ethernet1'])
|
143
|
+
expect(subject.getall).to eq(resource)
|
144
|
+
|
145
|
+
expect(subject.create('192.0.2.0/24', 'Ethernet1', name: 'my_route'))
|
146
|
+
.to be_truthy
|
147
|
+
expect(subject.getall).to include(destination: '192.0.2.0/24',
|
148
|
+
nexthop: 'Ethernet1',
|
149
|
+
distance: '1',
|
150
|
+
tag: '0',
|
151
|
+
name: 'my_route')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#delete' do
|
157
|
+
let(:resource) { subject.getall }
|
158
|
+
|
159
|
+
before do
|
160
|
+
node.config(['ip route 192.0.2.0/24 Ethernet1'])
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'deletes a staticroute resource' do
|
164
|
+
it 'given only a destination network' do
|
165
|
+
expect(subject.getall).to eq(resource)
|
166
|
+
expect(subject.delete('192.0.2.0/24')).to be_truthy
|
167
|
+
expect(subject.getall).to eq([])
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'given a destination and nexthop' do
|
171
|
+
expect(subject.getall).to eq(resource)
|
172
|
+
expect(subject.delete('192.0.2.0/24', 'Ethernet1')).to be_truthy
|
173
|
+
expect(subject.getall).to eq([])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|