arista-eos 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,138 @@
|
|
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_stp_interface).provider(:eos) do
|
37
|
+
# Puppet RAL memoized methods
|
38
|
+
let(:resource) do
|
39
|
+
resource_hash = {
|
40
|
+
name: 'Ethernet1',
|
41
|
+
portfast: :true,
|
42
|
+
portfast_type: :network,
|
43
|
+
bpduguard: :true,
|
44
|
+
provider: described_class.name
|
45
|
+
}
|
46
|
+
Puppet::Type.type(:eos_stp_interface).new(resource_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:provider) { resource.provider }
|
50
|
+
|
51
|
+
let(:api) { double('stp') }
|
52
|
+
let(:interfaces) { double('stp.interfaces') }
|
53
|
+
|
54
|
+
def stp
|
55
|
+
stp = Fixtures[:stp]
|
56
|
+
return stp if stp
|
57
|
+
fixture('stp')
|
58
|
+
end
|
59
|
+
|
60
|
+
before :each do
|
61
|
+
allow(described_class.node).to receive(:api).with('stp').and_return(api)
|
62
|
+
allow(api).to receive(:interfaces).and_return(interfaces)
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'class methods' do
|
66
|
+
before { allow(api).to receive(:get).and_return(stp) }
|
67
|
+
|
68
|
+
describe '.instances' do
|
69
|
+
subject { described_class.instances }
|
70
|
+
|
71
|
+
it { is_expected.to be_an Array }
|
72
|
+
|
73
|
+
it 'has two entries' do
|
74
|
+
expect(subject.size).to eq(2)
|
75
|
+
end
|
76
|
+
|
77
|
+
%w(Ethernet1 Ethernet2).each do |name|
|
78
|
+
it "has an instance for interface #{name}" do
|
79
|
+
instance = subject.find { |p| p.name == name }
|
80
|
+
expect(instance).to be_a described_class
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'eos_stp_interface { Ethernet1: }' do
|
85
|
+
subject { described_class.instances.find { |p| p.name == 'Ethernet1' } }
|
86
|
+
|
87
|
+
include_examples 'provider resource methods',
|
88
|
+
name: 'Ethernet1',
|
89
|
+
portfast: :true,
|
90
|
+
portfast_type: :network,
|
91
|
+
bpduguard: :true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '.prefetch' do
|
96
|
+
let :resources do
|
97
|
+
{
|
98
|
+
'Ethernet1' => Puppet::Type.type(:eos_stp_interface)
|
99
|
+
.new(name: 'Ethernet1'),
|
100
|
+
'Ethernet2' => Puppet::Type.type(:eos_stp_interface)
|
101
|
+
.new(name: 'Ethernet2'),
|
102
|
+
'Ethernet3' => Puppet::Type.type(:eos_stp_interface)
|
103
|
+
.new(name: 'Ethernet3')
|
104
|
+
}
|
105
|
+
end
|
106
|
+
subject { described_class.prefetch(resources) }
|
107
|
+
|
108
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
109
|
+
resources.values.each do |rsrc|
|
110
|
+
expect(rsrc.provider.portfast).to eq(:absent)
|
111
|
+
expect(rsrc.provider.portfast_type).to eq(:absent)
|
112
|
+
expect(rsrc.provider.bpduguard).to eq(:absent)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'sets the provider instance of the managed resource' do
|
117
|
+
subject
|
118
|
+
res = resources['Ethernet1']
|
119
|
+
expect(res.provider.portfast).to eq(:true)
|
120
|
+
expect(res.provider.portfast_type).to eq(:network)
|
121
|
+
expect(res.provider.bpduguard).to eq(:true)
|
122
|
+
|
123
|
+
res = resources['Ethernet2']
|
124
|
+
expect(res.provider.portfast).to eq(:true)
|
125
|
+
expect(res.provider.portfast_type).to eq(:normal)
|
126
|
+
expect(res.provider.bpduguard).to eq(:false)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
130
|
+
subject
|
131
|
+
res = resources['Ethernet3']
|
132
|
+
expect(res.provider.portfast).to eq :absent
|
133
|
+
expect(res.provider.portfast_type).to eq :absent
|
134
|
+
expect(res.provider.bpduguard).to eq :absent
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,250 @@
|
|
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_switchport).provider(:eos) do
|
37
|
+
# Puppet RAL memoized methods
|
38
|
+
let(:resource) do
|
39
|
+
resource_hash = {
|
40
|
+
ensure: :present,
|
41
|
+
name: 'Ethernet1',
|
42
|
+
mode: :trunk,
|
43
|
+
trunk_allowed_vlans: %w(1 10 100 1000),
|
44
|
+
trunk_native_vlan: '1',
|
45
|
+
access_vlan: '1',
|
46
|
+
provider: described_class.name
|
47
|
+
}
|
48
|
+
Puppet::Type.type(:eos_switchport).new(resource_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:provider) { resource.provider }
|
52
|
+
|
53
|
+
let(:api) { double('switchports') }
|
54
|
+
|
55
|
+
def switchports
|
56
|
+
switchports = Fixtures[:switchports]
|
57
|
+
return switchports if switchports
|
58
|
+
fixture('switchports', dir: File.dirname(__FILE__))
|
59
|
+
end
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
allow(described_class.node).to receive(:api)
|
63
|
+
.with('switchports')
|
64
|
+
.and_return(api)
|
65
|
+
|
66
|
+
allow(provider.node).to receive(:api).with('switchports').and_return(api)
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'class methods' do
|
70
|
+
before { allow(api).to receive(:getall).and_return(switchports) }
|
71
|
+
|
72
|
+
describe '.instances' do
|
73
|
+
subject { described_class.instances }
|
74
|
+
|
75
|
+
it { is_expected.to be_an Array }
|
76
|
+
|
77
|
+
it 'has one entry' do
|
78
|
+
expect(subject.size).to eq 1
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'has an instance for Ethernet1' do
|
82
|
+
instance = subject.find { |p| p.name == 'Ethernet1' }
|
83
|
+
expect(instance).to be_a described_class
|
84
|
+
end
|
85
|
+
|
86
|
+
context "eos_switchport { 'Ethernet1': }" do
|
87
|
+
subject { described_class.instances.find { |p| p.name == 'Ethernet1' } }
|
88
|
+
|
89
|
+
include_examples 'provider resource methods',
|
90
|
+
ensure: :present,
|
91
|
+
name: 'Ethernet1',
|
92
|
+
mode: :trunk,
|
93
|
+
trunk_allowed_vlans: [1, 10, 100, 1000],
|
94
|
+
trunk_native_vlan: '1',
|
95
|
+
access_vlan: '1'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '.prefetch' do
|
100
|
+
let :resources do
|
101
|
+
{
|
102
|
+
'Ethernet1' => Puppet::Type.type(:eos_switchport)
|
103
|
+
.new(name: 'Ethernet1'),
|
104
|
+
'Ethernet2' => Puppet::Type.type(:eos_switchport)
|
105
|
+
.new(name: 'Ethernet2')
|
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.mode).to eq(:absent)
|
114
|
+
expect(rsrc.provider.trunk_native_vlan).to eq(:absent)
|
115
|
+
expect(rsrc.provider.access_vlan).to eq(:absent)
|
116
|
+
expect(rsrc.provider.trunk_allowed_vlans).to eq(:absent)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'sets the provider instance of the managed resource' do
|
121
|
+
subject
|
122
|
+
expect(resources['Ethernet1'].provider.name).to eq 'Ethernet1'
|
123
|
+
expect(resources['Ethernet1'].provider.exists?).to be_truthy
|
124
|
+
expect(resources['Ethernet1'].provider.mode).to eq :trunk
|
125
|
+
expect(resources['Ethernet1'].provider.access_vlan).to eq '1'
|
126
|
+
expect(resources['Ethernet1'].provider.trunk_native_vlan).to eq '1'
|
127
|
+
expect(resources['Ethernet1'].provider.trunk_allowed_vlans).to \
|
128
|
+
eq [1, 10, 100, 1000]
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
132
|
+
subject
|
133
|
+
expect(resources['Ethernet2'].provider.name).to eq('Ethernet2')
|
134
|
+
expect(resources['Ethernet2'].provider.exists?).to be_falsey
|
135
|
+
expect(resources['Ethernet2'].provider.mode).to eq :absent
|
136
|
+
expect(resources['Ethernet2'].provider.access_vlan).to eq :absent
|
137
|
+
expect(resources['Ethernet2'].provider.trunk_native_vlan).to eq :absent
|
138
|
+
expect(resources['Ethernet2'].provider.trunk_allowed_vlans).to \
|
139
|
+
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(:getall).and_return(switchports)
|
155
|
+
described_class.instances.first
|
156
|
+
end
|
157
|
+
it { is_expected.to be_truthy }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '#create' do
|
162
|
+
let(:name) { resource[:name] }
|
163
|
+
|
164
|
+
before do
|
165
|
+
expect(api).to receive(:create).with(name)
|
166
|
+
allow(api).to receive_messages(
|
167
|
+
set_mode: true,
|
168
|
+
set_access_vlan: true,
|
169
|
+
set_trunk_native_vlan: true,
|
170
|
+
set_trunk_allowed_vlans: true
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'sets ensure to :present' do
|
175
|
+
provider.create
|
176
|
+
expect(provider.ensure).to eq(:present)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'sets mode to the resource value' do
|
180
|
+
provider.create
|
181
|
+
expect(provider.mode).to eq provider.resource[:mode]
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'sets trunk_allowed_vlans to the resource value' do
|
185
|
+
provider.create
|
186
|
+
expect(provider.trunk_allowed_vlans).to eq \
|
187
|
+
resource[:trunk_allowed_vlans]
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'sets trunk_native_vlan to the resource value' do
|
191
|
+
provider.create
|
192
|
+
expect(provider.trunk_native_vlan).to eq resource[:trunk_native_vlan]
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'sets access_vlan to the resource value' do
|
196
|
+
provider.create
|
197
|
+
expect(provider.access_vlan).to eq resource[:access_vlan]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#destroy' do
|
202
|
+
it 'sets ensure to :absent' do
|
203
|
+
expect(api).to receive(:delete).with(resource[:name])
|
204
|
+
provider.destroy
|
205
|
+
expect(provider.ensure).to eq(:absent)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#mode=(val)' do
|
210
|
+
%w(access trunk).each do |value|
|
211
|
+
let(:value) { value }
|
212
|
+
|
213
|
+
it 'updates mode in the provider' do
|
214
|
+
expect(api).to receive(:set_mode).with(resource[:name], value: value)
|
215
|
+
provider.mode = value
|
216
|
+
expect(provider.mode).to eq(value)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#trunk_native_vlan=(val)' do
|
222
|
+
it 'updates trunk_native_vlan in the provider' do
|
223
|
+
expect(api).to receive(:set_trunk_native_vlan)
|
224
|
+
.with(resource[:name], value: '100')
|
225
|
+
provider.trunk_native_vlan = '100'
|
226
|
+
expect(provider.trunk_native_vlan).to eq('100')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe '#trunk_allowed_vlans=(val)' do
|
231
|
+
let(:vlans) { %w(1 10 100 1000) }
|
232
|
+
|
233
|
+
it 'updates trunk_allowed_vlans in the provider' do
|
234
|
+
expect(api).to receive(:set_trunk_allowed_vlans)
|
235
|
+
.with(resource[:name], value: vlans)
|
236
|
+
provider.trunk_allowed_vlans = vlans
|
237
|
+
expect(provider.trunk_allowed_vlans).to eq(vlans)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#access_vlan=(val)' do
|
242
|
+
it 'updates access_vlan in the provider' do
|
243
|
+
expect(api).to receive(:set_access_vlan)
|
244
|
+
.with(resource[:name], value: 1000)
|
245
|
+
provider.access_vlan = 1000
|
246
|
+
expect(provider.access_vlan).to eq(1000)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
@@ -0,0 +1,129 @@
|
|
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_system).provider(:eos) do
|
37
|
+
# Puppet RAL memoized methods
|
38
|
+
let(:resource) do
|
39
|
+
resource_hash = {
|
40
|
+
name: 'settings',
|
41
|
+
hostname: 'localhost',
|
42
|
+
provider: described_class.name
|
43
|
+
}
|
44
|
+
Puppet::Type.type(:eos_system).new(resource_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:provider) { resource.provider }
|
48
|
+
let(:api) { double('system') }
|
49
|
+
|
50
|
+
def system
|
51
|
+
system = Fixtures[:system]
|
52
|
+
return system if system
|
53
|
+
fixture('system', dir: File.dirname(__FILE__))
|
54
|
+
end
|
55
|
+
|
56
|
+
before :each do
|
57
|
+
allow(described_class.node).to receive(:api).with('system').and_return(api)
|
58
|
+
allow(provider.node).to receive(:api).with('system').and_return(api)
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'class methods' do
|
62
|
+
before { allow(api).to receive(:get).and_return(system) }
|
63
|
+
|
64
|
+
describe '.instances' do
|
65
|
+
subject { described_class.instances }
|
66
|
+
|
67
|
+
it { is_expected.to be_an Array }
|
68
|
+
|
69
|
+
it 'has only one entry' do
|
70
|
+
expect(subject.size).to eq 1
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'has an instance for settings' do
|
74
|
+
instance = subject.find { |p| p.name == 'settings' }
|
75
|
+
expect(instance).to be_a described_class
|
76
|
+
end
|
77
|
+
|
78
|
+
context "eos_system { 'settings': }" do
|
79
|
+
subject { described_class.instances.find { |p| p.name == 'settings' } }
|
80
|
+
|
81
|
+
include_examples 'provider resource methods',
|
82
|
+
name: 'settings',
|
83
|
+
hostname: 'localhost'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.prefetch' do
|
88
|
+
let :resources do
|
89
|
+
{
|
90
|
+
'settings' => Puppet::Type.type(:eos_system).new(name: 'settings'),
|
91
|
+
'alternative' => Puppet::Type.type(:eos_system)
|
92
|
+
.new(name: 'alternative')
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
subject { described_class.prefetch(resources) }
|
97
|
+
|
98
|
+
it 'resource providers are absent prior to calling .prefetch' do
|
99
|
+
resources.values.each do |rsrc|
|
100
|
+
expect(rsrc.provider.hostname).to eq(:absent)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'sets the provider instance of the managed resource' do
|
105
|
+
subject
|
106
|
+
expect(resources['settings'].provider.name).to eq('settings')
|
107
|
+
expect(resources['settings'].provider.exists?).to be_truthy
|
108
|
+
expect(resources['settings'].provider.hostname).to eq('localhost')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'does not set the provider instance of the unmanaged resource' do
|
112
|
+
subject
|
113
|
+
expect(resources['alternative'].provider.name).to eq('alternative')
|
114
|
+
expect(resources['alternative'].provider.exists?).to be_falsey
|
115
|
+
expect(resources['alternative'].provider.hostname).to eq(:absent)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'resource (instance) methods' do
|
121
|
+
describe '#hostname=(value)' do
|
122
|
+
it 'updates hostname with value=foo' do
|
123
|
+
expect(api).to receive(:set_hostname).with(value: 'foo')
|
124
|
+
provider.hostname = 'foo'
|
125
|
+
expect(provider.hostname).to eq('foo')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|