arista-eos 1.1.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 +41 -0
- data/.rubocop.yml +21 -0
- data/Gemfile +57 -0
- data/Guardfile +21 -0
- data/LICENSE +28 -0
- data/README.md +178 -0
- data/Rakefile +46 -0
- data/eos.gemspec +36 -0
- data/guide/.gitignore +2 -0
- data/guide/Makefile +177 -0
- data/guide/_static/arista_logo_jpg-11.jpg +0 -0
- data/guide/_static/favicon.ico +0 -0
- data/guide/conf.py +282 -0
- data/guide/cookbook.rst +135 -0
- data/guide/developing.rst +55 -0
- data/guide/faq.rst +30 -0
- data/guide/index.rst +25 -0
- data/guide/installation.rst +174 -0
- data/guide/license.rst +5 -0
- data/guide/overview.rst +35 -0
- data/guide/quickstart.rst +184 -0
- data/guide/release-notes-1.0.rst +37 -0
- data/guide/release-notes-1.1.rst +25 -0
- data/guide/release-notes.rst +10 -0
- data/guide/testing.rst +8 -0
- data/guide/troubleshooting.rst +26 -0
- data/guide/typedoc.rst +928 -0
- data/guide/types.rst +44 -0
- data/lib/eos.rb +8 -0
- data/lib/eos/version.rb +5 -0
- data/lib/puppet/provider/eos_acl_entry/default.rb +122 -0
- data/lib/puppet/provider/eos_command/default.rb +61 -0
- data/lib/puppet/provider/eos_ethernet/default.rb +96 -0
- data/lib/puppet/provider/eos_interface/default.rb +89 -0
- data/lib/puppet/provider/eos_ipinterface/default.rb +89 -0
- data/lib/puppet/provider/eos_mlag/default.rb +86 -0
- data/lib/puppet/provider/eos_mlag_interface/default.rb +90 -0
- data/lib/puppet/provider/eos_ntp_config/default.rb +68 -0
- data/lib/puppet/provider/eos_ntp_server/default.rb +69 -0
- data/lib/puppet/provider/eos_portchannel/default.rb +117 -0
- data/lib/puppet/provider/eos_snmp/default.rb +77 -0
- data/lib/puppet/provider/eos_stp_interface/default.rb +73 -0
- data/lib/puppet/provider/eos_switchport/default.rb +100 -0
- data/lib/puppet/provider/eos_system/default.rb +63 -0
- data/lib/puppet/provider/eos_vlan/default.rb +93 -0
- data/lib/puppet/provider/eos_vxlan/default.rb +104 -0
- data/lib/puppet/provider/eos_vxlan_vlan/default.rb +89 -0
- data/lib/puppet/provider/eos_vxlan_vtep/default.rb +70 -0
- data/lib/puppet/type/eos_acl_entry.rb +126 -0
- data/lib/puppet/type/eos_command.rb +75 -0
- data/lib/puppet/type/eos_ethernet.rb +101 -0
- data/lib/puppet/type/eos_interface.rb +79 -0
- data/lib/puppet/type/eos_ipinterface.rb +116 -0
- data/lib/puppet/type/eos_mlag.rb +133 -0
- data/lib/puppet/type/eos_mlag_interface.rb +85 -0
- data/lib/puppet/type/eos_ntp_config.rb +70 -0
- data/lib/puppet/type/eos_ntp_server.rb +52 -0
- data/lib/puppet/type/eos_portchannel.rb +189 -0
- data/lib/puppet/type/eos_snmp.rb +127 -0
- data/lib/puppet/type/eos_stp_interface.rb +94 -0
- data/lib/puppet/type/eos_switchport.rb +150 -0
- data/lib/puppet/type/eos_system.rb +69 -0
- data/lib/puppet/type/eos_vlan.rb +130 -0
- data/lib/puppet/type/eos_vxlan.rb +150 -0
- data/lib/puppet/type/eos_vxlan_vlan.rb +78 -0
- data/lib/puppet/type/eos_vxlan_vtep.rb +62 -0
- data/lib/puppet_x/eos/provider.rb +86 -0
- data/lib/puppet_x/eos/utils/helpers.rb +34 -0
- data/metadata.json +20 -0
- data/spec/fixtures/README +61 -0
- data/spec/fixtures/ethernet.json +9 -0
- data/spec/fixtures/fixture_stp.yaml +11 -0
- data/spec/fixtures/fixture_vxlan_get.yaml +11 -0
- data/spec/fixtures/ospf.json +13 -0
- data/spec/fixtures/snmp.json +6 -0
- data/spec/fixtures/varp.json +11 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/fixtures.rb +74 -0
- data/spec/support/shared_examples_for_providers.rb +7 -0
- data/spec/support/shared_examples_for_types.rb +451 -0
- data/spec/unit/puppet/provider/eos_acl_entry/default_spec.rb +226 -0
- data/spec/unit/puppet/provider/eos_acl_entry/fixture_acl_entry.yaml +20 -0
- data/spec/unit/puppet/provider/eos_ethernet/default_spec.rb +226 -0
- data/spec/unit/puppet/provider/eos_ethernet/fixture_ethernet.yaml +8 -0
- data/spec/unit/puppet/provider/eos_interface/default_spec.rb +176 -0
- data/spec/unit/puppet/provider/eos_interface/fixture_interfaces.yaml +5 -0
- data/spec/unit/puppet/provider/eos_ipinterface/default_spec.rb +223 -0
- data/spec/unit/puppet/provider/eos_ipinterface/fixture_ipinterfaces.yaml +5 -0
- data/spec/unit/puppet/provider/eos_mlag/default_spec.rb +203 -0
- data/spec/unit/puppet/provider/eos_mlag/fixture_mlag.yaml +11 -0
- data/spec/unit/puppet/provider/eos_mlag_interface/default_spec.rb +177 -0
- data/spec/unit/puppet/provider/eos_mlag_interface/fixture_mlag.yaml +11 -0
- data/spec/unit/puppet/provider/eos_ntp_config/default_spec.rb +150 -0
- data/spec/unit/puppet/provider/eos_ntp_config/fixture_ntp.yaml +3 -0
- data/spec/unit/puppet/provider/eos_ntp_server/default_spec.rb +152 -0
- data/spec/unit/puppet/provider/eos_ntp_server/fixture_ntp.yaml +3 -0
- data/spec/unit/puppet/provider/eos_portchannel/default_spec.rb +271 -0
- data/spec/unit/puppet/provider/eos_portchannel/fixture_portchannels.yaml +10 -0
- data/spec/unit/puppet/provider/eos_snmp/default_spec.rb +193 -0
- data/spec/unit/puppet/provider/eos_snmp/fixture_snmp.yaml +6 -0
- data/spec/unit/puppet/provider/eos_stp_interface/default_spec.rb +138 -0
- data/spec/unit/puppet/provider/eos_switchport/default_spec.rb +250 -0
- data/spec/unit/puppet/provider/eos_switchport/fixture_switchports.yaml +7 -0
- data/spec/unit/puppet/provider/eos_system/default_spec.rb +129 -0
- data/spec/unit/puppet/provider/eos_system/fixture_system.yaml +2 -0
- data/spec/unit/puppet/provider/eos_vlan/default_spec.rb +228 -0
- data/spec/unit/puppet/provider/eos_vlan/fixture_vlans.yaml +6 -0
- data/spec/unit/puppet/provider/eos_vxlan/default_spec.rb +229 -0
- data/spec/unit/puppet/provider/eos_vxlan/fixture_vxlan.yaml +9 -0
- data/spec/unit/puppet/provider/eos_vxlan_vlan/default_spec.rb +148 -0
- data/spec/unit/puppet/provider/eos_vxlan_vtep/default_spec.rb +140 -0
- data/spec/unit/puppet/type/eos_acl_entry_spec.rb +103 -0
- data/spec/unit/puppet/type/eos_command_spec.rb +67 -0
- data/spec/unit/puppet/type/eos_ethernet_spec.rb +87 -0
- data/spec/unit/puppet/type/eos_interface_spec.rb +67 -0
- data/spec/unit/puppet/type/eos_ipinterface_spec.rb +84 -0
- data/spec/unit/puppet/type/eos_mlag_interface_spec.rb +62 -0
- data/spec/unit/puppet/type/eos_mlag_spec.rb +98 -0
- data/spec/unit/puppet/type/eos_ntp_config_spec.rb +58 -0
- data/spec/unit/puppet/type/eos_ntp_server_spec.rb +51 -0
- data/spec/unit/puppet/type/eos_portchannel_spec.rb +99 -0
- data/spec/unit/puppet/type/eos_snmp_spec.rb +87 -0
- data/spec/unit/puppet/type/eos_stp_interface_spec.rb +77 -0
- data/spec/unit/puppet/type/eos_switchport_spec.rb +88 -0
- data/spec/unit/puppet/type/eos_system_spec.rb +57 -0
- data/spec/unit/puppet/type/eos_vlan_spec.rb +86 -0
- data/spec/unit/puppet/type/eos_vxlan_spec.rb +100 -0
- data/spec/unit/puppet/type/eos_vxlan_vlan_spec.rb +73 -0
- data/spec/unit/puppet/type/eos_vxlan_vtep_spec.rb +52 -0
- data/tests/init.pp +12 -0
- metadata +437 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2014, 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
|
+
include FixtureHelpers
|
|
35
|
+
|
|
36
|
+
describe Puppet::Type.type(:eos_portchannel).provider(:eos) do
|
|
37
|
+
# Puppet RAL memoized methods
|
|
38
|
+
let(:resource) do
|
|
39
|
+
resource_hash = {
|
|
40
|
+
ensure: :present,
|
|
41
|
+
name: 'Port-Channel1',
|
|
42
|
+
lacp_mode: :active,
|
|
43
|
+
members: %w(Ethernet1 Ethernet2),
|
|
44
|
+
minimum_links: 2,
|
|
45
|
+
lacp_fallback: :static,
|
|
46
|
+
lacp_timeout: 100,
|
|
47
|
+
provider: described_class.name
|
|
48
|
+
}
|
|
49
|
+
Puppet::Type.type(:eos_portchannel).new(resource_hash)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
let(:provider) { resource.provider }
|
|
53
|
+
|
|
54
|
+
let(:api) { double('interfaces') }
|
|
55
|
+
|
|
56
|
+
def portchannels
|
|
57
|
+
portchannels = Fixtures[:portchannels]
|
|
58
|
+
return portchannels if portchannels
|
|
59
|
+
fixture('portchannels', dir: File.dirname(__FILE__))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
before :each do
|
|
63
|
+
allow(described_class.node).to receive(:api).with('interfaces')
|
|
64
|
+
.and_return(api)
|
|
65
|
+
allow(provider.node).to receive(:api).with('interfaces').and_return(api)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'class methods' do
|
|
69
|
+
before { allow(api).to receive(:getall).and_return(portchannels) }
|
|
70
|
+
|
|
71
|
+
describe '.instances' do
|
|
72
|
+
subject { described_class.instances }
|
|
73
|
+
|
|
74
|
+
it { is_expected.to be_an Array }
|
|
75
|
+
|
|
76
|
+
it 'has one entry' do
|
|
77
|
+
expect(subject.size).to eq 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'has an instance for Port-Channel1' do
|
|
81
|
+
instance = subject.find { |p| p.name == 'Port-Channel1' }
|
|
82
|
+
expect(instance).to be_a described_class
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "eos_portchannel { 'Port-Channel1': }" do
|
|
86
|
+
subject do
|
|
87
|
+
described_class.instances.find { |p| p.name == 'Port-Channel1' }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
include_examples 'provider resource methods',
|
|
91
|
+
ensure: :present,
|
|
92
|
+
name: 'Port-Channel1',
|
|
93
|
+
lacp_mode: :active,
|
|
94
|
+
members: %w(Ethernet1 Ethernet2),
|
|
95
|
+
minimum_links: '2',
|
|
96
|
+
lacp_fallback: :static,
|
|
97
|
+
lacp_timeout: '100'
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '.prefetch' do
|
|
102
|
+
let :resources do
|
|
103
|
+
{
|
|
104
|
+
'Port-Channel1' => Puppet::Type.type(:eos_portchannel)
|
|
105
|
+
.new(name: 'Port-Channel1'),
|
|
106
|
+
'Port-Channel5' => Puppet::Type.type(:eos_portchannel)
|
|
107
|
+
.new(name: 'Port-Channel5')
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
subject { described_class.prefetch(resources) }
|
|
112
|
+
|
|
113
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
|
114
|
+
resources.values.each do |rsrc|
|
|
115
|
+
expect(rsrc.provider.lacp_mode).to eq(:absent)
|
|
116
|
+
expect(rsrc.provider.members).to eq(:absent)
|
|
117
|
+
expect(rsrc.provider.minimum_links).to eq(:absent)
|
|
118
|
+
expect(rsrc.provider.lacp_fallback).to eq(:absent)
|
|
119
|
+
expect(rsrc.provider.lacp_timeout).to eq(:absent)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'sets the provider instance of the managed resource' do
|
|
124
|
+
subject
|
|
125
|
+
expect(resources['Port-Channel1'].provider.name).to eq 'Port-Channel1'
|
|
126
|
+
expect(resources['Port-Channel1'].provider.exists?).to be_truthy
|
|
127
|
+
expect(resources['Port-Channel1'].provider.lacp_mode).to eq :active
|
|
128
|
+
expect(resources['Port-Channel1'].provider.members).to \
|
|
129
|
+
eq %w(Ethernet1 Ethernet2)
|
|
130
|
+
expect(resources['Port-Channel1'].provider.minimum_links).to eq '2'
|
|
131
|
+
expect(resources['Port-Channel1'].provider.lacp_fallback).to eq :static
|
|
132
|
+
expect(resources['Port-Channel1'].provider.lacp_timeout).to eq '100'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
|
136
|
+
subject
|
|
137
|
+
expect(resources['Port-Channel5'].provider.name).to eq('Port-Channel5')
|
|
138
|
+
expect(resources['Port-Channel5'].provider.exists?).to be_falsey
|
|
139
|
+
expect(resources['Port-Channel5'].provider.lacp_mode).to eq :absent
|
|
140
|
+
expect(resources['Port-Channel5'].provider.members).to eq :absent
|
|
141
|
+
expect(resources['Port-Channel5'].provider.minimum_links).to eq :absent
|
|
142
|
+
expect(resources['Port-Channel5'].provider.lacp_fallback).to eq :absent
|
|
143
|
+
expect(resources['Port-Channel5'].provider.lacp_timeout).to eq :absent
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context 'resource (instance) methods' do
|
|
149
|
+
describe '#exists?' do
|
|
150
|
+
subject { provider.exists? }
|
|
151
|
+
|
|
152
|
+
context 'when the resource does not exist on the system' do
|
|
153
|
+
it { is_expected.to be_falsey }
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context 'when the resource exists on the system' do
|
|
157
|
+
let(:provider) do
|
|
158
|
+
allow(api).to receive(:getall).and_return(portchannels)
|
|
159
|
+
described_class.instances.first
|
|
160
|
+
end
|
|
161
|
+
it { is_expected.to be_truthy }
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe '#create' do
|
|
166
|
+
let(:name) { resource[:name] }
|
|
167
|
+
|
|
168
|
+
before do
|
|
169
|
+
expect(api).to receive(:create).with(name)
|
|
170
|
+
allow(api).to receive_messages(
|
|
171
|
+
set_lacp_mode: true,
|
|
172
|
+
set_members: true,
|
|
173
|
+
set_minimum_links: true,
|
|
174
|
+
set_lacp_fallback: true,
|
|
175
|
+
set_lacp_timeout: true
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'sets ensure to :present' do
|
|
180
|
+
provider.create
|
|
181
|
+
expect(provider.ensure).to eq(:present)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'sets lacp_mode to the resource value' do
|
|
185
|
+
provider.create
|
|
186
|
+
expect(provider.lacp_mode).to eq resource[:lacp_mode]
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'sets members to the resource value' do
|
|
190
|
+
provider.create
|
|
191
|
+
expect(provider.members).to eq resource[:members]
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it 'sets minimum_links to the resource value' do
|
|
195
|
+
provider.create
|
|
196
|
+
expect(provider.minimum_links).to eq resource[:minimum_links]
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it 'sets lacp_fallback to the resource value' do
|
|
200
|
+
provider.create
|
|
201
|
+
expect(provider.lacp_fallback).to eq resource[:lacp_fallback]
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it 'sets lacp_timeout to the resource value' do
|
|
205
|
+
provider.create
|
|
206
|
+
expect(provider.lacp_timeout).to eq resource[:lacp_timeout]
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
describe '#destroy' do
|
|
211
|
+
it 'sets ensure to :absent' do
|
|
212
|
+
expect(api).to receive(:delete).with(resource[:name])
|
|
213
|
+
provider.destroy
|
|
214
|
+
expect(provider.ensure).to eq(:absent)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe '#lacp_mode=(val)' do
|
|
219
|
+
let(:name) { resource[:name] }
|
|
220
|
+
%w(active passive on).each do |value|
|
|
221
|
+
let(:value) { value }
|
|
222
|
+
|
|
223
|
+
it 'updates lacp_mode on the provider' do
|
|
224
|
+
expect(api).to receive(:set_lacp_mode).with(name, value)
|
|
225
|
+
provider.lacp_mode = value
|
|
226
|
+
expect(provider.lacp_mode).to eq value
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
describe '#members=(val)' do
|
|
232
|
+
let(:value) { %w(Ethernet1 Ethernet2 Ethernet3) }
|
|
233
|
+
it 'updates members on the provider' do
|
|
234
|
+
expect(api).to receive(:set_members) .with(resource[:name], value)
|
|
235
|
+
provider.members = value
|
|
236
|
+
expect(provider.members).to eq value
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
describe '#minimum_links=(val)' do
|
|
241
|
+
it 'updates minimum_links on the provider' do
|
|
242
|
+
expect(api).to receive(:set_minimum_links)
|
|
243
|
+
.with(resource[:name], value: 4)
|
|
244
|
+
provider.minimum_links = 4
|
|
245
|
+
expect(provider.minimum_links).to eq 4
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
describe '#lacp_fallback=(val)' do
|
|
250
|
+
%w(static individual).each do |value|
|
|
251
|
+
let(:value) { value }
|
|
252
|
+
|
|
253
|
+
it 'updates lacp_fallback on the provider' do
|
|
254
|
+
expect(api).to receive(:set_lacp_fallback)
|
|
255
|
+
.with(resource[:name], value: value)
|
|
256
|
+
provider.lacp_fallback = value
|
|
257
|
+
expect(provider.lacp_fallback).to eq value
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
describe '#lacp_timeout=(val)' do
|
|
263
|
+
it 'updates lacp_timeout on the provider' do
|
|
264
|
+
expect(api).to receive(:set_lacp_timeout)
|
|
265
|
+
.with(resource[:name], value: 900)
|
|
266
|
+
provider.lacp_timeout = 900
|
|
267
|
+
expect(provider.lacp_timeout).to eq 900
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
end
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2014, 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
|
+
include FixtureHelpers
|
|
35
|
+
|
|
36
|
+
describe Puppet::Type.type(:eos_snmp).provider(:eos) do
|
|
37
|
+
# Puppet RAL memoized methods
|
|
38
|
+
let(:resource) do
|
|
39
|
+
resource_hash = {
|
|
40
|
+
name: 'settings',
|
|
41
|
+
contact: 'network operations',
|
|
42
|
+
location: 'data center',
|
|
43
|
+
chassis_id: '1234567890',
|
|
44
|
+
source_interface: 'Loopback0',
|
|
45
|
+
provider: described_class.name
|
|
46
|
+
}
|
|
47
|
+
Puppet::Type.type(:eos_snmp).new(resource_hash)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
let(:provider) { resource.provider }
|
|
51
|
+
|
|
52
|
+
let(:api) { double('snmp') }
|
|
53
|
+
|
|
54
|
+
def snmp
|
|
55
|
+
snmp = Fixtures[:snmp]
|
|
56
|
+
return snmp if snmp
|
|
57
|
+
fixture('snmp', dir: File.dirname(__FILE__))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Stub the Api method class to obtain all vlans.
|
|
61
|
+
before :each do
|
|
62
|
+
allow(described_class.node).to receive(:api).with('snmp').and_return(api)
|
|
63
|
+
allow(provider.node).to receive(:api).with('snmp').and_return(api)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'class methods' do
|
|
67
|
+
before { allow(api).to receive(:get).and_return(snmp) }
|
|
68
|
+
|
|
69
|
+
describe '.instances' do
|
|
70
|
+
subject { described_class.instances }
|
|
71
|
+
|
|
72
|
+
it { is_expected.to be_an Array }
|
|
73
|
+
|
|
74
|
+
it 'has only one entry' do
|
|
75
|
+
expect(subject.size).to eq 1
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'has an instance for snmp settings' do
|
|
79
|
+
instance = subject.find { |p| p.name == 'settings' }
|
|
80
|
+
expect(instance).to be_a described_class
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "eos_snmp { 'settings': }" do
|
|
84
|
+
subject do
|
|
85
|
+
described_class.instances.find do |p|
|
|
86
|
+
p.name == 'settings'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
include_examples 'provider resource methods',
|
|
91
|
+
name: 'settings',
|
|
92
|
+
contact: 'network operations',
|
|
93
|
+
location: 'data center',
|
|
94
|
+
chassis_id: '1234567890',
|
|
95
|
+
source_interface: 'Loopback0'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '.prefetch' do
|
|
100
|
+
let :resources do
|
|
101
|
+
{
|
|
102
|
+
'settings' => Puppet::Type.type(:eos_snmp)
|
|
103
|
+
.new(name: 'settings'),
|
|
104
|
+
'alternative' => Puppet::Type.type(:eos_snmp)
|
|
105
|
+
.new(name: 'alternative')
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
subject { described_class.prefetch(resources) }
|
|
110
|
+
|
|
111
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
|
112
|
+
resources.values.each do |rsrc|
|
|
113
|
+
expect(rsrc.provider.contact).to eq(:absent)
|
|
114
|
+
expect(rsrc.provider.location).to eq(:absent)
|
|
115
|
+
expect(rsrc.provider.chassis_id).to eq(:absent)
|
|
116
|
+
expect(rsrc.provider.source_interface).to eq(:absent)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'sets the provider instance of the managed resource' do
|
|
121
|
+
subject
|
|
122
|
+
expect(resources['settings'].provider.name).to eq 'settings'
|
|
123
|
+
expect(resources['settings'].provider.exists?).to be_truthy
|
|
124
|
+
expect(resources['settings'].provider.contact).to \
|
|
125
|
+
eq 'network operations'
|
|
126
|
+
expect(resources['settings'].provider.location).to eq 'data center'
|
|
127
|
+
expect(resources['settings'].provider.chassis_id).to eq '1234567890'
|
|
128
|
+
expect(resources['settings'].provider.source_interface).to \
|
|
129
|
+
eq 'Loopback0'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
|
133
|
+
subject
|
|
134
|
+
expect(resources['alternative'].provider.name).to eq('alternative')
|
|
135
|
+
expect(resources['alternative'].provider.exists?).to be_falsey
|
|
136
|
+
expect(resources['alternative'].provider.contact).to eq :absent
|
|
137
|
+
expect(resources['alternative'].provider.location).to eq :absent
|
|
138
|
+
expect(resources['alternative'].provider.chassis_id).to eq :absent
|
|
139
|
+
expect(resources['alternative'].provider.source_interface).to eq :absent
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context 'resource (instance) methods' do
|
|
145
|
+
describe '#exists?' do
|
|
146
|
+
subject { provider.exists? }
|
|
147
|
+
|
|
148
|
+
context 'when the resource does not exist on the system' do
|
|
149
|
+
it { is_expected.to be_falsey }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context 'when the resource exists on the system' do
|
|
153
|
+
let(:provider) do
|
|
154
|
+
allow(api).to receive(:get).and_return(snmp)
|
|
155
|
+
described_class.instances.first
|
|
156
|
+
end
|
|
157
|
+
it { is_expected.to be_truthy }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe '#contact=(val)' do
|
|
162
|
+
it 'updates contact in the provider' do
|
|
163
|
+
expect(api).to receive(:set_contact).with(value: 'foo')
|
|
164
|
+
provider.contact = 'foo'
|
|
165
|
+
expect(provider.contact).to eq('foo')
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe '#location=(val)' do
|
|
170
|
+
it 'updates location in the provider' do
|
|
171
|
+
expect(api).to receive(:set_location).with(value: 'foo')
|
|
172
|
+
provider.location = 'foo'
|
|
173
|
+
expect(provider.location).to eq('foo')
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe '#source_interface=(val)' do
|
|
178
|
+
it 'updates source_interface in the provider' do
|
|
179
|
+
expect(api).to receive(:set_source_interface).with(value: 'foo')
|
|
180
|
+
provider.source_interface = 'foo'
|
|
181
|
+
expect(provider.source_interface).to eq('foo')
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe '#chassis_id=(val)' do
|
|
186
|
+
it 'updates chassis_id in the provider' do
|
|
187
|
+
expect(api).to receive(:set_chassis_id).with(value: 'foo')
|
|
188
|
+
provider.chassis_id = 'foo'
|
|
189
|
+
expect(provider.chassis_id).to eq('foo')
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|