rbeapi 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -65,5 +65,25 @@ describe Rbeapi::Api::StpInstances do
|
|
65
65
|
expect(subject.set_priority('1', value: '4096')).to be_truthy
|
66
66
|
expect(subject.get('1')[:priority]).to eq('4096')
|
67
67
|
end
|
68
|
+
|
69
|
+
it 'set the instance priority to default' do
|
70
|
+
expect(subject.set_priority('1', value: '4096',
|
71
|
+
default: true)).to be_truthy
|
72
|
+
expect(subject.get('1')[:priority]).to eq('32768')
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'set the instance priority to enable false' do
|
76
|
+
expect(subject.set_priority('1', value: '4096',
|
77
|
+
default: false,
|
78
|
+
enable: false)).to be_truthy
|
79
|
+
expect(subject.get('1')[:priority]).to eq('32768')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'set the instance priority to enable true' do
|
83
|
+
expect(subject.set_priority('1', value: '4096',
|
84
|
+
default: false,
|
85
|
+
enable: true)).to be_truthy
|
86
|
+
expect(subject.get('1')[:priority]).to eq('4096')
|
87
|
+
end
|
68
88
|
end
|
69
89
|
end
|
@@ -89,6 +89,13 @@ describe Rbeapi::Api::StpInterfaces do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe '#set_bpduguard' do
|
92
|
+
it 'sets the bpduguard value to default true' do
|
93
|
+
node.config(['interface Ethernet1', 'no spanning-tree bpduguard'])
|
94
|
+
expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
|
95
|
+
expect(subject.set_bpduguard('Ethernet1', default: true)).to be_truthy
|
96
|
+
expect(subject.get('Ethernet1')[:bpduguard]).to be_falsey
|
97
|
+
end
|
98
|
+
|
92
99
|
it 'sets the bpduguard value to true' do
|
93
100
|
node.config(['interface Ethernet1', 'no spanning-tree bpduguard'])
|
94
101
|
expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
|
@@ -13,29 +13,44 @@ describe Rbeapi::Api::Switchports do
|
|
13
13
|
|
14
14
|
describe '#get' do
|
15
15
|
let(:keys) do
|
16
|
-
[:mode, :access_vlan, :trunk_native_vlan, :trunk_allowed_vlans
|
16
|
+
[:mode, :access_vlan, :trunk_native_vlan, :trunk_allowed_vlans,
|
17
|
+
:trunk_groups]
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
context 'vlan as an integer range' do
|
21
|
+
before do
|
22
|
+
node.config(['default interface Ethernet1', 'interface Ethernet2',
|
23
|
+
'no switchport'])
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
it 'returns the switchport resource' do
|
27
|
+
expect(subject.get('Ethernet1')).not_to be_nil
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
it 'does not return a nonswitchport resource' do
|
31
|
+
expect(subject.get('Ethernet2')).to be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has all required keys' do
|
35
|
+
expect(subject.get('Ethernet1').keys).to eq(keys)
|
36
|
+
end
|
31
37
|
|
32
|
-
|
33
|
-
|
38
|
+
it 'returns allowed_vlans as an array' do
|
39
|
+
expect(subject.get('Ethernet1')[:trunk_allowed_vlans])
|
40
|
+
.to be_a_kind_of(Array)
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
.
|
44
|
+
context 'vlan as an integer' do
|
45
|
+
before do
|
46
|
+
node.config(['default interface Ethernet1',
|
47
|
+
'interface Ethernet1',
|
48
|
+
'switchport trunk allowed vlan 1'])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns the switchport resource' do
|
52
|
+
expect(subject.get('Ethernet1')).not_to be_nil
|
53
|
+
end
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
@@ -206,4 +221,59 @@ describe Rbeapi::Api::Switchports do
|
|
206
221
|
expect(subject.get('Ethernet1')[:trunk_allowed_vlans].length).to eq(4094)
|
207
222
|
end
|
208
223
|
end
|
224
|
+
|
225
|
+
describe '#set_trunk_groups' do
|
226
|
+
before do
|
227
|
+
node.config(['interface Ethernet1', 'default switchport trunk group'])
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'raises an ArgumentError if value is not an array' do
|
231
|
+
expect { subject.set_trunk_groups('Ethernet1', value: 'foo') }
|
232
|
+
.to raise_error(ArgumentError)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'sets trunk group to foo bar bang' do
|
236
|
+
node.config(['interface Ethernet1', 'switchport trunk group bang',
|
237
|
+
'switchport trunk group baz'])
|
238
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to eq(%w(bang baz))
|
239
|
+
expect(subject.set_trunk_groups('Ethernet1', value: %w(foo bar bang)))
|
240
|
+
.to be_truthy
|
241
|
+
expect(subject.get('Ethernet1')[:trunk_groups].sort)
|
242
|
+
.to eq(%w(bang bar foo))
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'clears trunk group if no value specified' do
|
246
|
+
node.config(['interface Ethernet1', 'switchport trunk group bang',
|
247
|
+
'switchport trunk group baz'])
|
248
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to eq(%w(bang baz))
|
249
|
+
expect(subject.set_trunk_groups('Ethernet1')).to be_truthy
|
250
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to be_empty
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'negate switchport trunk group' do
|
254
|
+
node.config(['interface Ethernet1', 'switchport trunk group bang',
|
255
|
+
'switchport trunk group baz'])
|
256
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to eq(%w(bang baz))
|
257
|
+
expect(subject.set_trunk_groups('Ethernet1', value: %w(foo bar bang)))
|
258
|
+
.to be_truthy
|
259
|
+
expect(subject.get('Ethernet1')[:trunk_groups].sort)
|
260
|
+
.to eq(%w(bang bar foo))
|
261
|
+
expect(subject.set_trunk_groups('Ethernet1', enable: false))
|
262
|
+
.to be_truthy
|
263
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to be_empty
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'default switchport trunk group' do
|
267
|
+
node.config(['interface Ethernet1', 'switchport trunk group bang',
|
268
|
+
'switchport trunk group baz'])
|
269
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to eq(%w(bang baz))
|
270
|
+
expect(subject.set_trunk_groups('Ethernet1', value: %w(foo bar bang)))
|
271
|
+
.to be_truthy
|
272
|
+
expect(subject.get('Ethernet1')[:trunk_groups].sort)
|
273
|
+
.to eq(%w(bang bar foo))
|
274
|
+
expect(subject.set_trunk_groups('Ethernet1', default: true))
|
275
|
+
.to be_truthy
|
276
|
+
expect(subject.get('Ethernet1')[:trunk_groups]).to be_empty
|
277
|
+
end
|
278
|
+
end
|
209
279
|
end
|
@@ -0,0 +1,324 @@
|
|
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/users'
|
36
|
+
|
37
|
+
describe Rbeapi::Api::Users 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(:sshkey) do
|
46
|
+
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKL1UtBALa4CvFUsHUipN' \
|
47
|
+
'ymA04qCXuAtTwNcMj84bTUzUI+q7mdzRCTLkllXeVxKuBnaTm2PW7W67K5C' \
|
48
|
+
'Vpl0EVCm6IY7FS7kc4nlnD/tFvTvShy/fzYQRAdM7ZfVtegW8sMSFJzBR/T' \
|
49
|
+
'/Y/sxI16Y/dQb8fC3la9T25XOrzsFrQiKRZmJGwg8d+0RLxpfMg0s/9ATwQ' \
|
50
|
+
'Kp6tPoLE4f3dKlAgSk5eENyVLA3RsypWADHpenHPcB7sa8D38e1TS+n+EUy' \
|
51
|
+
'Adb3Yov+5ESAbgLIJLd52Xv+FyYi0c2L49ByBjcRrupp4zfXn4DNRnEG4K6' \
|
52
|
+
'GcmswHuMEGZv5vjJ9OYaaaaaaa'
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:secret) do
|
56
|
+
'$6$RMxgK5ALGIf.nWEC$tHuKCyfNtJMCY561P52dTzHUmYMmLxb/M' \
|
57
|
+
'xik.j3vMUs8lMCPocM00/NAS.SN6GCWx7d/vQIgxnClyQLAb7n3x0'
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:md5_secret) do
|
61
|
+
'$1$Ehb5lL0D$N3MgrkfMFxmeh0FSZ5sEZ1'
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:test) do
|
65
|
+
{ name: 'rbeapi',
|
66
|
+
privilege: 1,
|
67
|
+
role: nil,
|
68
|
+
nopassword: false,
|
69
|
+
encryption: 'md5',
|
70
|
+
secret: md5_secret,
|
71
|
+
sshkey: sshkey
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#getall' do
|
76
|
+
let(:resource) { subject.getall }
|
77
|
+
|
78
|
+
let(:test1_entries) do
|
79
|
+
{ 'admin' => { name: 'admin', privilege: 1,
|
80
|
+
role: 'network-admin', nopassword: true,
|
81
|
+
encryption: nil, secret: nil, sshkey: nil },
|
82
|
+
'rbeapi' => { name: 'rbeapi', privilege: 1, role: nil,
|
83
|
+
nopassword: false, encryption: 'md5',
|
84
|
+
secret: md5_secret,
|
85
|
+
sshkey: sshkey }
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
before do
|
90
|
+
node.config(['no username rbeapi',
|
91
|
+
'no username user1',
|
92
|
+
'username admin privilege 1 role network-admin nopassword',
|
93
|
+
"username rbeapi privilege 1 secret 5 #{md5_secret}",
|
94
|
+
"username rbeapi sshkey #{sshkey}"])
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the username collection' do
|
98
|
+
expect(subject.getall).to include(test1_entries)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'returns a hash collection' do
|
102
|
+
expect(subject.getall).to be_a_kind_of(Hash)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#get' do
|
107
|
+
it 'returns the user resource for given name' do
|
108
|
+
expect(subject.get('rbeapi')).to eq(test)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns a hash' do
|
112
|
+
expect(subject.get('rbeapi')).to be_a_kind_of(Hash)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'has two entries' do
|
116
|
+
expect(subject.get('rbeapi').size).to eq(7)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#create' do
|
121
|
+
before do
|
122
|
+
node.config(['no username rbeapi'])
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'create a new user name with no password' do
|
126
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
127
|
+
expect(subject.create('rbeapi', nopassword: :true)).to be_truthy
|
128
|
+
expect(subject.get('rbeapi')[:nopassword]).to eq(true)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'create a new user name with no password and privilege' do
|
132
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
133
|
+
expect(subject.create('rbeapi',
|
134
|
+
privilege: 4,
|
135
|
+
nopassword: :true)).to be_truthy
|
136
|
+
expect(subject.get('rbeapi')[:privilege]).to eq(4)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'create a new user name with no password, privilege, and role' do
|
140
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
141
|
+
expect(subject.create('rbeapi',
|
142
|
+
privilege: 4,
|
143
|
+
role: 'net-minion',
|
144
|
+
nopassword: :true)).to be_truthy
|
145
|
+
expect(subject.get('rbeapi')[:privilege]).to eq(4)
|
146
|
+
expect(subject.get('rbeapi')[:role]).to eq('net-minion')
|
147
|
+
expect(subject.get('rbeapi')[:nopassword]).to eq(true)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'create a new user name with a password' do
|
151
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
152
|
+
expect(subject.create('rbeapi', secret: 'icanttellyou')).to be_truthy
|
153
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('md5')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'create a new user name with a password and privilege' do
|
157
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
158
|
+
expect(subject.create('rbeapi',
|
159
|
+
secret: 'icanttellyou',
|
160
|
+
privilege: 5)).to be_truthy
|
161
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('md5')
|
162
|
+
expect(subject.get('rbeapi')[:privilege]).to eq(5)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'create a new user name with a password, privilege, and role' do
|
166
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
167
|
+
expect(subject.create('rbeapi',
|
168
|
+
secret: 'icanttellyou',
|
169
|
+
privilege: 5, role: 'net')).to be_truthy
|
170
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('md5')
|
171
|
+
expect(subject.get('rbeapi')[:privilege]).to eq(5)
|
172
|
+
expect(subject.get('rbeapi')[:role]).to eq('net')
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'create a new user name with a password and md5 encryption' do
|
176
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
177
|
+
expect(subject.create('rbeapi',
|
178
|
+
secret: '$1$Wb4zN5EH$ILNgYb3Ehzs85S9KpoFW4.',
|
179
|
+
encryption: 'md5')).to be_truthy
|
180
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('md5')
|
181
|
+
expect(subject.get('rbeapi')[:secret])
|
182
|
+
.to eq('$1$Wb4zN5EH$ILNgYb3Ehzs85S9KpoFW4.')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'create a new user name with a password and sha512 encryption' do
|
186
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
187
|
+
expect(subject.create('rbeapi',
|
188
|
+
secret: secret,
|
189
|
+
encryption: 'sha512')).to be_truthy
|
190
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('sha512')
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'create a new user name with a password, sha512 encryption, and key' do
|
194
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
195
|
+
expect(subject.create('rbeapi',
|
196
|
+
secret: secret,
|
197
|
+
encryption: 'sha512',
|
198
|
+
sshkey: sshkey)).to be_truthy
|
199
|
+
expect(subject.get('rbeapi')[:encryption]).to eq('sha512')
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'raises ArgumentError for create without required args ' do
|
203
|
+
expect { subject.create('rbeapi') }.to \
|
204
|
+
raise_error ArgumentError
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'raises ArgumentError for invalid encryption value' do
|
208
|
+
expect { subject.create('name', encryption: 'bogus') }.to \
|
209
|
+
raise_error ArgumentError
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#delete' do
|
214
|
+
before do
|
215
|
+
node.config(['username user1 privilege 1 role network-admin nopassword'])
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'delete a username resource' do
|
219
|
+
expect(subject.get('user1')[:name]).to eq('user1')
|
220
|
+
expect(subject.delete('user1')).to be_truthy
|
221
|
+
expect(subject.get('user1')).to eq(nil)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe '#default' do
|
226
|
+
before do
|
227
|
+
node.config(['username user1 privilege 1 role network-admin nopassword'])
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'sets username resource to default value' do
|
231
|
+
expect(subject.get('user1')[:name]).to eq('user1')
|
232
|
+
expect(subject.default('user1')).to be_truthy
|
233
|
+
expect(subject.get('user1')).to eq(nil)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe '#set_privilege' do
|
238
|
+
before do
|
239
|
+
node.config(['no username rbeapi',
|
240
|
+
'username rbeapi role network-admin nopassword'])
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'set the privilege' do
|
244
|
+
expect(subject.set_privilege('rbeapi', value: '13')).to be_truthy
|
245
|
+
expect(subject.get('rbeapi')[:privilege]).to eq(13)
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'remove the privilege without a value' do
|
249
|
+
expect(subject.set_privilege('rbeapi', enable: false)).to be_truthy
|
250
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'remove the privilege with a value' do
|
254
|
+
expect(subject.set_privilege('rbeapi', value: '13', enable: false))
|
255
|
+
.to be_truthy
|
256
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'defaults the privilege without a value' do
|
260
|
+
expect(subject.set_privilege('rbeapi', default: true)).to be_truthy
|
261
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'defaults the privilege with a value' do
|
265
|
+
expect(subject.set_privilege('rbeapi', value: '3', default: true))
|
266
|
+
.to be_truthy
|
267
|
+
expect(subject.get('rbeapi')).to eq(nil)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe '#set_role' do
|
272
|
+
before do
|
273
|
+
node.config(['no username rbeapi', 'username rbeapi nopassword'])
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'set the role' do
|
277
|
+
expect(subject.set_role('rbeapi', value: 'net-minion')).to be_truthy
|
278
|
+
expect(subject.get('rbeapi')[:role]).to eq('net-minion')
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'remove the role without a value' do
|
282
|
+
expect(subject.set_role('rbeapi', enable: false)).to be_truthy
|
283
|
+
expect(subject.get('rbeapi')[:role]).to eq(nil)
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'remove the role with a value' do
|
287
|
+
expect(subject.set_role('rbeapi', value: 'net', enable: false))
|
288
|
+
.to be_truthy
|
289
|
+
expect(subject.get('rbeapi')[:role]).to eq(nil)
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'defaults the role without a value' do
|
293
|
+
expect(subject.set_role('rbeapi', default: true)).to be_truthy
|
294
|
+
expect(subject.get('rbeapi')[:role]).to eq(nil)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'defaults the role with a value' do
|
298
|
+
expect(subject.set_role('rbeapi', value: 'net', default: true))
|
299
|
+
.to be_truthy
|
300
|
+
expect(subject.get('rbeapi')[:role]).to eq(nil)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '#set_sshkey' do
|
305
|
+
before do
|
306
|
+
node.config(['no username rbeapi', 'username rbeapi nopassword'])
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'set the sshkey' do
|
310
|
+
expect(subject.set_sshkey('rbeapi', value: sshkey)).to be_truthy
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'remove the sshkey with a value' do
|
314
|
+
expect(subject.set_sshkey('rbeapi', value: sshkey, enable: false))
|
315
|
+
.to be_truthy
|
316
|
+
expect(subject.get('rbeapi')[:sshkey]).to eq(nil)
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'defaults the sshkey without a value' do
|
320
|
+
expect(subject.set_sshkey('rbeapi', default: true)).to be_truthy
|
321
|
+
expect(subject.get('rbeapi')[:sshkey]).to eq(nil)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|