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,228 @@
|
|
|
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_vlan).provider(:eos) do
|
|
37
|
+
# Puppet RAL memoized methods
|
|
38
|
+
let(:resource) do
|
|
39
|
+
resource_hash = {
|
|
40
|
+
ensure: :present,
|
|
41
|
+
name: '1234',
|
|
42
|
+
vlanid: '1234',
|
|
43
|
+
vlan_name: 'VLAN1234',
|
|
44
|
+
enable: true,
|
|
45
|
+
trunk_groups: [],
|
|
46
|
+
provider: described_class.name
|
|
47
|
+
}
|
|
48
|
+
Puppet::Type.type(:eos_vlan).new(resource_hash)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
let(:provider) { resource.provider }
|
|
52
|
+
|
|
53
|
+
let(:api) { double('vlans') }
|
|
54
|
+
|
|
55
|
+
def vlans
|
|
56
|
+
vlans = Fixtures[:vlans]
|
|
57
|
+
return vlans if vlans
|
|
58
|
+
fixture('vlans', dir: File.dirname(__FILE__))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
before :each do
|
|
62
|
+
allow(described_class.node).to receive(:api).with('vlans').and_return(api)
|
|
63
|
+
allow(provider.node).to receive(:api).with('vlans').and_return(api)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'class methods' do
|
|
67
|
+
before { allow(api).to receive(:getall).and_return(vlans) }
|
|
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 VLAN 1' do
|
|
79
|
+
instance = subject.find { |p| p.name == '1' }
|
|
80
|
+
expect(instance).to be_a described_class
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context 'eos_vlan { 1: }' do
|
|
84
|
+
subject { described_class.instances.find { |p| p.name == '1' } }
|
|
85
|
+
|
|
86
|
+
include_examples 'provider resource methods',
|
|
87
|
+
ensure: :present,
|
|
88
|
+
vlanid: '1',
|
|
89
|
+
vlan_name: 'default',
|
|
90
|
+
enable: :true,
|
|
91
|
+
exists?: true,
|
|
92
|
+
trunk_groups: []
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe '.prefetch' do
|
|
97
|
+
let :resources do
|
|
98
|
+
{
|
|
99
|
+
'1' => Puppet::Type.type(:eos_vlan).new(vlanid: '1'),
|
|
100
|
+
'2' => Puppet::Type.type(:eos_vlan).new(vlanid: '2')
|
|
101
|
+
}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
subject { described_class.prefetch(resources) }
|
|
105
|
+
|
|
106
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
|
107
|
+
resources.values.each do |rsrc|
|
|
108
|
+
expect(rsrc.provider.vlanid).to eq(:absent)
|
|
109
|
+
expect(rsrc.provider.vlan_name).to eq(:absent)
|
|
110
|
+
expect(rsrc.provider.trunk_groups).to eq(:absent)
|
|
111
|
+
expect(rsrc.provider.enable).to eq(:absent)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'sets the provider instance of the managed resource' do
|
|
116
|
+
subject
|
|
117
|
+
expect(resources['1'].provider.vlanid).to eq '1'
|
|
118
|
+
expect(resources['1'].provider.vlan_name).to eq 'default'
|
|
119
|
+
expect(resources['1'].provider.enable).to eq :true
|
|
120
|
+
expect(resources['1'].provider.trunk_groups).to eq []
|
|
121
|
+
expect(resources['1'].provider.exists?).to be_truthy
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
|
125
|
+
subject
|
|
126
|
+
expect(resources['2'].provider.vlanid).to eq :absent
|
|
127
|
+
expect(resources['2'].provider.vlan_name).to eq :absent
|
|
128
|
+
expect(resources['2'].provider.enable).to eq :absent
|
|
129
|
+
expect(resources['2'].provider.trunk_groups).to eq :absent
|
|
130
|
+
expect(resources['2'].provider.exists?).to be_falsey
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'resource (instance) methods' do
|
|
136
|
+
describe '#exists?' do
|
|
137
|
+
subject { provider.exists? }
|
|
138
|
+
|
|
139
|
+
context 'when the resource does not exist on the system' do
|
|
140
|
+
it { is_expected.to be_falsey }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context 'when the resource exists on the system' do
|
|
144
|
+
let(:provider) do
|
|
145
|
+
allow(api).to receive(:getall).and_return(vlans)
|
|
146
|
+
described_class.instances.first
|
|
147
|
+
end
|
|
148
|
+
it { is_expected.to be_truthy }
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe '#create' do
|
|
153
|
+
let(:vid) { resource[:name] }
|
|
154
|
+
|
|
155
|
+
before do
|
|
156
|
+
allow(api).to receive_messages(
|
|
157
|
+
set_state: true,
|
|
158
|
+
set_name: true,
|
|
159
|
+
set_trunk_group: true
|
|
160
|
+
)
|
|
161
|
+
expect(api).to receive(:create).with(resource[:name])
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'sets ensure to :present' do
|
|
165
|
+
provider.create
|
|
166
|
+
expect(provider.ensure).to eq(:present)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'sets enable to the resource value' do
|
|
170
|
+
provider.create
|
|
171
|
+
expect(provider.enable).to be_truthy
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'sets vlan_name to the resource value' do
|
|
175
|
+
provider.create
|
|
176
|
+
expect(provider.vlan_name).to eq(provider.resource[:vlan_name])
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'sets trunk_groups to the resource value array' do
|
|
180
|
+
provider.create
|
|
181
|
+
expect(provider.trunk_groups).to eq(provider.resource[:trunk_groups])
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe '#destroy' do
|
|
186
|
+
it 'sets ensure to :absent' do
|
|
187
|
+
expect(api).to receive(:delete).with(resource[:name])
|
|
188
|
+
provider.destroy
|
|
189
|
+
expect(provider.ensure).to eq(:absent)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe '#vlan_name=(value)' do
|
|
194
|
+
it 'updates vlan_name in the provider' do
|
|
195
|
+
expect(api).to receive(:set_name).with(resource[:name], value: 'foo')
|
|
196
|
+
provider.vlan_name = 'foo'
|
|
197
|
+
expect(provider.vlan_name).to eq('foo')
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe '#enable=(value)' do
|
|
202
|
+
let(:vid) { resource[:name] }
|
|
203
|
+
|
|
204
|
+
it 'updates enable with value :true' do
|
|
205
|
+
expect(api).to receive(:set_state).with(vid, value: 'active')
|
|
206
|
+
provider.enable = :true
|
|
207
|
+
expect(provider.enable).to eq(:true)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it 'updates enable with value :false' do
|
|
211
|
+
expect(api).to receive(:set_state).with(vid, value: 'suspend')
|
|
212
|
+
provider.enable = :false
|
|
213
|
+
expect(provider.enable).to eq(:false)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
describe '#trunk_groups=(value)' do
|
|
218
|
+
let(:vid) { resource[:name] }
|
|
219
|
+
let(:tgs) { %w(tg1 tg2 tg3) }
|
|
220
|
+
|
|
221
|
+
it 'updates trunk_groups with array [tg1, tg2, tg3]' do
|
|
222
|
+
expect(api).to receive(:set_trunk_group).with(vid, value: tgs)
|
|
223
|
+
provider.trunk_groups = tgs
|
|
224
|
+
expect(provider.trunk_groups).to eq(tgs)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,229 @@
|
|
|
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_vxlan).provider(:eos) do
|
|
37
|
+
# Puppet RAL memoized methods
|
|
38
|
+
let(:resource) do
|
|
39
|
+
resource_hash = {
|
|
40
|
+
name: 'Vxlan1',
|
|
41
|
+
description: 'test interface',
|
|
42
|
+
enable: :true,
|
|
43
|
+
source_interface: 'Loopback0',
|
|
44
|
+
multicast_group: '239.10.10.10',
|
|
45
|
+
udp_port: 4789,
|
|
46
|
+
provider: described_class.name
|
|
47
|
+
}
|
|
48
|
+
Puppet::Type.type(:eos_vxlan).new(resource_hash)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
let(:provider) { resource.provider }
|
|
52
|
+
|
|
53
|
+
let(:api) { double('interfaces') }
|
|
54
|
+
|
|
55
|
+
def vxlan
|
|
56
|
+
vxlan = Fixtures[:vxlan]
|
|
57
|
+
return vxlan if vxlan
|
|
58
|
+
fixture('vxlan', dir: File.dirname(__FILE__))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
before :each do
|
|
62
|
+
allow(described_class.node).to receive(:api).with('interfaces')
|
|
63
|
+
.and_return(api)
|
|
64
|
+
|
|
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(vxlan) }
|
|
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 interface Vxlan1' do
|
|
81
|
+
instance = subject.find { |p| p.name == 'Vxlan1' }
|
|
82
|
+
expect(instance).to be_a described_class
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'eos_vxlan { Vxlan1: }' do
|
|
86
|
+
subject { described_class.instances.find { |p| p.name == 'Vxlan1' } }
|
|
87
|
+
|
|
88
|
+
include_examples 'provider resource methods',
|
|
89
|
+
name: 'Vxlan1',
|
|
90
|
+
description: 'test interface',
|
|
91
|
+
enable: :true,
|
|
92
|
+
source_interface: 'Loopback0',
|
|
93
|
+
multicast_group: '239.10.10.10',
|
|
94
|
+
udp_port: 4789
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '.prefetch' do
|
|
99
|
+
let :resources do
|
|
100
|
+
{
|
|
101
|
+
'Vxlan1' => Puppet::Type.type(:eos_vxlan).new(name: 'Vxlan1'),
|
|
102
|
+
'Vxlan2' => Puppet::Type.type(:eos_vxlan).new(name: 'Vxlan2')
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
subject { described_class.prefetch(resources) }
|
|
106
|
+
|
|
107
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
|
108
|
+
resources.values.each do |rsrc|
|
|
109
|
+
expect(rsrc.provider.description).to eq(:absent)
|
|
110
|
+
expect(rsrc.provider.enable).to eq(:absent)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'sets the provider instance of the managed resource' do
|
|
115
|
+
subject
|
|
116
|
+
expect(resources['Vxlan1'].provider.description).to eq('test interface')
|
|
117
|
+
expect(resources['Vxlan1'].provider.enable).to eq :true
|
|
118
|
+
expect(resources['Vxlan1'].provider.source_interface).to eq 'Loopback0'
|
|
119
|
+
expect(resources['Vxlan1'].provider.multicast_group).to \
|
|
120
|
+
eq '239.10.10.10'
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
|
124
|
+
subject
|
|
125
|
+
expect(resources['Vxlan2'].provider.description).to eq :absent
|
|
126
|
+
expect(resources['Vxlan2'].provider.enable).to eq :absent
|
|
127
|
+
expect(resources['Vxlan2'].provider.source_interface).to eq :absent
|
|
128
|
+
expect(resources['Vxlan2'].provider.multicast_group).to eq :absent
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'resource (instance) methods' do
|
|
134
|
+
describe '#create' do
|
|
135
|
+
let(:name) { 'Vxlan1' }
|
|
136
|
+
|
|
137
|
+
before do
|
|
138
|
+
expect(api).to receive(:create).with(resource[:name])
|
|
139
|
+
allow(api).to receive_messages(
|
|
140
|
+
set_shutdown: true,
|
|
141
|
+
set_description: true,
|
|
142
|
+
set_source_interface: true,
|
|
143
|
+
set_multicast_group: true,
|
|
144
|
+
set_udp_port: true
|
|
145
|
+
)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'sets enable on the resource' do
|
|
149
|
+
provider.create
|
|
150
|
+
expect(provider.enable).to be_truthy
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'sets description on the resource' do
|
|
154
|
+
provider.create
|
|
155
|
+
expect(provider.description).to eq(resource[:description])
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'sets source_interface on the resource' do
|
|
159
|
+
provider.create
|
|
160
|
+
expect(provider.source_interface).to eq(resource[:source_interface])
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'sets multicast_group on the resource' do
|
|
164
|
+
provider.create
|
|
165
|
+
expect(provider.multicast_group).to eq(resource[:multicast_group])
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'sets udp_port on the resource' do
|
|
169
|
+
provider.create
|
|
170
|
+
expect(provider.udp_port).to eq(resource[:udp_port])
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe '#destroy' do
|
|
175
|
+
it 'sets ensure to :absent' do
|
|
176
|
+
expect(api).to receive(:delete).with(resource[:name])
|
|
177
|
+
provider.destroy
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe '#description=(value)' do
|
|
182
|
+
it 'updates description in the provider' do
|
|
183
|
+
expect(api).to receive(:set_description)
|
|
184
|
+
.with(resource[:name], value: 'foo')
|
|
185
|
+
provider.description = 'foo'
|
|
186
|
+
expect(provider.description).to eq('foo')
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '#enable=(value)' do
|
|
191
|
+
%w(true false).each do |val|
|
|
192
|
+
let(:value) { !val }
|
|
193
|
+
let(:name) { 'Vxlan1' }
|
|
194
|
+
|
|
195
|
+
it 'updates enable in the provider' do
|
|
196
|
+
expect(api).to receive(:set_shutdown).with(name, value: !val)
|
|
197
|
+
provider.enable = val
|
|
198
|
+
expect(provider.enable).to eq(val)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe '#source_interface=(value)' do
|
|
204
|
+
it 'updates source_interface in the provder' do
|
|
205
|
+
expect(api).to receive(:set_source_interface)
|
|
206
|
+
.with('Vxlan1', value: 'Loopback1')
|
|
207
|
+
provider.source_interface = 'Loopback1'
|
|
208
|
+
expect(provider.source_interface).to eq('Loopback1')
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
describe '#multicast_group=(value)' do
|
|
213
|
+
it 'updates multicast_group in the provder' do
|
|
214
|
+
expect(api).to receive(:set_multicast_group)
|
|
215
|
+
.with('Vxlan1', value: '239.11.11.11')
|
|
216
|
+
provider.multicast_group = '239.11.11.11'
|
|
217
|
+
expect(provider.multicast_group).to eq('239.11.11.11')
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe '#udp_port=(value)' do
|
|
222
|
+
it 'updates udp_port in the provider' do
|
|
223
|
+
expect(api).to receive(:set_udp_port).with('Vxlan1', value: 1024)
|
|
224
|
+
provider.udp_port = 1024
|
|
225
|
+
expect(provider.udp_port).to eq(1024)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|