arista-eos 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.gitignore +41 -0
  2. data/.rubocop.yml +21 -0
  3. data/Gemfile +57 -0
  4. data/Guardfile +21 -0
  5. data/LICENSE +28 -0
  6. data/README.md +178 -0
  7. data/Rakefile +46 -0
  8. data/eos.gemspec +36 -0
  9. data/guide/.gitignore +2 -0
  10. data/guide/Makefile +177 -0
  11. data/guide/_static/arista_logo_jpg-11.jpg +0 -0
  12. data/guide/_static/favicon.ico +0 -0
  13. data/guide/conf.py +282 -0
  14. data/guide/cookbook.rst +135 -0
  15. data/guide/developing.rst +55 -0
  16. data/guide/faq.rst +30 -0
  17. data/guide/index.rst +25 -0
  18. data/guide/installation.rst +174 -0
  19. data/guide/license.rst +5 -0
  20. data/guide/overview.rst +35 -0
  21. data/guide/quickstart.rst +184 -0
  22. data/guide/release-notes-1.0.rst +37 -0
  23. data/guide/release-notes-1.1.rst +25 -0
  24. data/guide/release-notes.rst +10 -0
  25. data/guide/testing.rst +8 -0
  26. data/guide/troubleshooting.rst +26 -0
  27. data/guide/typedoc.rst +928 -0
  28. data/guide/types.rst +44 -0
  29. data/lib/eos.rb +8 -0
  30. data/lib/eos/version.rb +5 -0
  31. data/lib/puppet/provider/eos_acl_entry/default.rb +122 -0
  32. data/lib/puppet/provider/eos_command/default.rb +61 -0
  33. data/lib/puppet/provider/eos_ethernet/default.rb +96 -0
  34. data/lib/puppet/provider/eos_interface/default.rb +89 -0
  35. data/lib/puppet/provider/eos_ipinterface/default.rb +89 -0
  36. data/lib/puppet/provider/eos_mlag/default.rb +86 -0
  37. data/lib/puppet/provider/eos_mlag_interface/default.rb +90 -0
  38. data/lib/puppet/provider/eos_ntp_config/default.rb +68 -0
  39. data/lib/puppet/provider/eos_ntp_server/default.rb +69 -0
  40. data/lib/puppet/provider/eos_portchannel/default.rb +117 -0
  41. data/lib/puppet/provider/eos_snmp/default.rb +77 -0
  42. data/lib/puppet/provider/eos_stp_interface/default.rb +73 -0
  43. data/lib/puppet/provider/eos_switchport/default.rb +100 -0
  44. data/lib/puppet/provider/eos_system/default.rb +63 -0
  45. data/lib/puppet/provider/eos_vlan/default.rb +93 -0
  46. data/lib/puppet/provider/eos_vxlan/default.rb +104 -0
  47. data/lib/puppet/provider/eos_vxlan_vlan/default.rb +89 -0
  48. data/lib/puppet/provider/eos_vxlan_vtep/default.rb +70 -0
  49. data/lib/puppet/type/eos_acl_entry.rb +126 -0
  50. data/lib/puppet/type/eos_command.rb +75 -0
  51. data/lib/puppet/type/eos_ethernet.rb +101 -0
  52. data/lib/puppet/type/eos_interface.rb +79 -0
  53. data/lib/puppet/type/eos_ipinterface.rb +116 -0
  54. data/lib/puppet/type/eos_mlag.rb +133 -0
  55. data/lib/puppet/type/eos_mlag_interface.rb +85 -0
  56. data/lib/puppet/type/eos_ntp_config.rb +70 -0
  57. data/lib/puppet/type/eos_ntp_server.rb +52 -0
  58. data/lib/puppet/type/eos_portchannel.rb +189 -0
  59. data/lib/puppet/type/eos_snmp.rb +127 -0
  60. data/lib/puppet/type/eos_stp_interface.rb +94 -0
  61. data/lib/puppet/type/eos_switchport.rb +150 -0
  62. data/lib/puppet/type/eos_system.rb +69 -0
  63. data/lib/puppet/type/eos_vlan.rb +130 -0
  64. data/lib/puppet/type/eos_vxlan.rb +150 -0
  65. data/lib/puppet/type/eos_vxlan_vlan.rb +78 -0
  66. data/lib/puppet/type/eos_vxlan_vtep.rb +62 -0
  67. data/lib/puppet_x/eos/provider.rb +86 -0
  68. data/lib/puppet_x/eos/utils/helpers.rb +34 -0
  69. data/metadata.json +20 -0
  70. data/spec/fixtures/README +61 -0
  71. data/spec/fixtures/ethernet.json +9 -0
  72. data/spec/fixtures/fixture_stp.yaml +11 -0
  73. data/spec/fixtures/fixture_vxlan_get.yaml +11 -0
  74. data/spec/fixtures/ospf.json +13 -0
  75. data/spec/fixtures/snmp.json +6 -0
  76. data/spec/fixtures/varp.json +11 -0
  77. data/spec/spec_helper.rb +27 -0
  78. data/spec/support/fixtures.rb +74 -0
  79. data/spec/support/shared_examples_for_providers.rb +7 -0
  80. data/spec/support/shared_examples_for_types.rb +451 -0
  81. data/spec/unit/puppet/provider/eos_acl_entry/default_spec.rb +226 -0
  82. data/spec/unit/puppet/provider/eos_acl_entry/fixture_acl_entry.yaml +20 -0
  83. data/spec/unit/puppet/provider/eos_ethernet/default_spec.rb +226 -0
  84. data/spec/unit/puppet/provider/eos_ethernet/fixture_ethernet.yaml +8 -0
  85. data/spec/unit/puppet/provider/eos_interface/default_spec.rb +176 -0
  86. data/spec/unit/puppet/provider/eos_interface/fixture_interfaces.yaml +5 -0
  87. data/spec/unit/puppet/provider/eos_ipinterface/default_spec.rb +223 -0
  88. data/spec/unit/puppet/provider/eos_ipinterface/fixture_ipinterfaces.yaml +5 -0
  89. data/spec/unit/puppet/provider/eos_mlag/default_spec.rb +203 -0
  90. data/spec/unit/puppet/provider/eos_mlag/fixture_mlag.yaml +11 -0
  91. data/spec/unit/puppet/provider/eos_mlag_interface/default_spec.rb +177 -0
  92. data/spec/unit/puppet/provider/eos_mlag_interface/fixture_mlag.yaml +11 -0
  93. data/spec/unit/puppet/provider/eos_ntp_config/default_spec.rb +150 -0
  94. data/spec/unit/puppet/provider/eos_ntp_config/fixture_ntp.yaml +3 -0
  95. data/spec/unit/puppet/provider/eos_ntp_server/default_spec.rb +152 -0
  96. data/spec/unit/puppet/provider/eos_ntp_server/fixture_ntp.yaml +3 -0
  97. data/spec/unit/puppet/provider/eos_portchannel/default_spec.rb +271 -0
  98. data/spec/unit/puppet/provider/eos_portchannel/fixture_portchannels.yaml +10 -0
  99. data/spec/unit/puppet/provider/eos_snmp/default_spec.rb +193 -0
  100. data/spec/unit/puppet/provider/eos_snmp/fixture_snmp.yaml +6 -0
  101. data/spec/unit/puppet/provider/eos_stp_interface/default_spec.rb +138 -0
  102. data/spec/unit/puppet/provider/eos_switchport/default_spec.rb +250 -0
  103. data/spec/unit/puppet/provider/eos_switchport/fixture_switchports.yaml +7 -0
  104. data/spec/unit/puppet/provider/eos_system/default_spec.rb +129 -0
  105. data/spec/unit/puppet/provider/eos_system/fixture_system.yaml +2 -0
  106. data/spec/unit/puppet/provider/eos_vlan/default_spec.rb +228 -0
  107. data/spec/unit/puppet/provider/eos_vlan/fixture_vlans.yaml +6 -0
  108. data/spec/unit/puppet/provider/eos_vxlan/default_spec.rb +229 -0
  109. data/spec/unit/puppet/provider/eos_vxlan/fixture_vxlan.yaml +9 -0
  110. data/spec/unit/puppet/provider/eos_vxlan_vlan/default_spec.rb +148 -0
  111. data/spec/unit/puppet/provider/eos_vxlan_vtep/default_spec.rb +140 -0
  112. data/spec/unit/puppet/type/eos_acl_entry_spec.rb +103 -0
  113. data/spec/unit/puppet/type/eos_command_spec.rb +67 -0
  114. data/spec/unit/puppet/type/eos_ethernet_spec.rb +87 -0
  115. data/spec/unit/puppet/type/eos_interface_spec.rb +67 -0
  116. data/spec/unit/puppet/type/eos_ipinterface_spec.rb +84 -0
  117. data/spec/unit/puppet/type/eos_mlag_interface_spec.rb +62 -0
  118. data/spec/unit/puppet/type/eos_mlag_spec.rb +98 -0
  119. data/spec/unit/puppet/type/eos_ntp_config_spec.rb +58 -0
  120. data/spec/unit/puppet/type/eos_ntp_server_spec.rb +51 -0
  121. data/spec/unit/puppet/type/eos_portchannel_spec.rb +99 -0
  122. data/spec/unit/puppet/type/eos_snmp_spec.rb +87 -0
  123. data/spec/unit/puppet/type/eos_stp_interface_spec.rb +77 -0
  124. data/spec/unit/puppet/type/eos_switchport_spec.rb +88 -0
  125. data/spec/unit/puppet/type/eos_system_spec.rb +57 -0
  126. data/spec/unit/puppet/type/eos_vlan_spec.rb +86 -0
  127. data/spec/unit/puppet/type/eos_vxlan_spec.rb +100 -0
  128. data/spec/unit/puppet/type/eos_vxlan_vlan_spec.rb +73 -0
  129. data/spec/unit/puppet/type/eos_vxlan_vtep_spec.rb +52 -0
  130. data/tests/init.pp +12 -0
  131. metadata +437 -0
@@ -0,0 +1,11 @@
1
+ ---
2
+ :global:
3
+ :domain_id: MLAG-Domain
4
+ :local_interface: Vlan4094
5
+ :peer_address: 1.1.1.1
6
+ :peer_link: Port-Channel1
7
+ :shutdown: false
8
+ :interfaces:
9
+ "Port-Channel1":
10
+ :mlag_id: 1
11
+
@@ -0,0 +1,177 @@
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_mlag_interface).provider(:eos) do
37
+ # Puppet RAL memoized methods
38
+ let(:resource) do
39
+ resource_hash = {
40
+ ensure: :present,
41
+ name: 'Port-Channel1',
42
+ mlag_id: 1,
43
+ provider: described_class.name
44
+ }
45
+ Puppet::Type.type(:eos_mlag_interface).new(resource_hash)
46
+ end
47
+
48
+ let(:provider) { resource.provider }
49
+
50
+ let(:api) { double('mlag') }
51
+
52
+ def mlag
53
+ mlag = Fixtures[:mlag]
54
+ return mlag if mlag
55
+ fixture('mlag', dir: File.dirname(__FILE__))
56
+ end
57
+
58
+ before :each do
59
+ allow(described_class.node).to receive(:api).with('mlag').and_return(api)
60
+ allow(provider.node).to receive(:api).with('mlag').and_return(api)
61
+ end
62
+
63
+ context 'class methods' do
64
+ before { allow(api).to receive(:get).and_return(mlag) }
65
+
66
+ describe '.instances' do
67
+ subject { described_class.instances }
68
+
69
+ it { is_expected.to be_an Array }
70
+
71
+ it 'has one entry' do
72
+ expect(subject.size).to eq 1
73
+ end
74
+
75
+ it 'has an instance for interface Port-Channel1' do
76
+ instance = subject.find { |p| p.name == 'Port-Channel1' }
77
+ expect(instance).to be_a described_class
78
+ end
79
+
80
+ context "eos_mlag_interface { 'Port-Channel1': }" do
81
+ subject do
82
+ described_class.instances.find { |p| p.name == 'Port-Channel1' }
83
+ end
84
+
85
+ include_examples 'provider resource methods',
86
+ ensure: :present,
87
+ name: 'Port-Channel1',
88
+ mlag_id: 1
89
+ end
90
+ end
91
+
92
+ describe '.prefetch' do
93
+ let :resources do
94
+ {
95
+ 'Port-Channel1' => Puppet::Type.type(:eos_mlag_interface)
96
+ .new(name: 'Port-Channel1'),
97
+ 'Port-Channel3' => Puppet::Type.type(:eos_mlag_interface)
98
+ .new(name: 'Port-Channel3')
99
+ }
100
+ end
101
+
102
+ subject { described_class.prefetch(resources) }
103
+
104
+ it 'resource providers are absent prior to calling .prefetch' do
105
+ resources.values.each do |rsrc|
106
+ expect(rsrc.provider.mlag_id).to eq(:absent)
107
+ end
108
+ end
109
+
110
+ it 'sets the provider instance of the managed resource' do
111
+ subject
112
+ expect(resources['Port-Channel1'].provider.name).to eq 'Port-Channel1'
113
+ expect(resources['Port-Channel1'].provider.exists?).to be_truthy
114
+ expect(resources['Port-Channel1'].provider.mlag_id).to eq(1)
115
+ end
116
+
117
+ it 'does not set the provider instance of the unmanaged resource' do
118
+ subject
119
+ expect(resources['Port-Channel3'].provider.name).to eq('Port-Channel3')
120
+ expect(resources['Port-Channel3'].provider.exists?).to be_falsey
121
+ expect(resources['Port-Channel3'].provider.mlag_id).to eq(:absent)
122
+ end
123
+ end
124
+ end
125
+
126
+ context 'resource (instance) methods' do
127
+ describe '#exists?' do
128
+ subject { provider.exists? }
129
+
130
+ context 'when the resource does not exist on the system' do
131
+ it { is_expected.to be_falsey }
132
+ end
133
+
134
+ context 'when the resource exists on the system' do
135
+ let(:provider) do
136
+ allow(api).to receive(:get).and_return(mlag)
137
+ described_class.instances.first
138
+ end
139
+ it { is_expected.to be_truthy }
140
+ end
141
+ end
142
+
143
+ describe '#create' do
144
+ let(:name) { resource[:name] }
145
+
146
+ it 'sets ensure to :present' do
147
+ expect(api).to receive(:set_mlag_id).with(name, value: 1)
148
+ provider.create
149
+ provider.flush
150
+ expect(provider.ensure).to eq(:present)
151
+ end
152
+ end
153
+
154
+ describe '#destroy' do
155
+ let(:name) { resource[:name] }
156
+
157
+ it 'sets ensure to :absent' do
158
+ expect(api).to receive(:set_mlag_id).with(name)
159
+ resource[:ensure] = :absent
160
+ provider.destroy
161
+ provider.flush
162
+ expect(provider.ensure).to eq(:absent)
163
+ end
164
+ end
165
+
166
+ describe '#mlag_id=(val)' do
167
+ let(:name) { resource[:name] }
168
+
169
+ it 'sets mlag_id to value 100' do
170
+ expect(api).to receive(:set_mlag_id).with(name, value: 100)
171
+ provider.mlag_id = 100
172
+ provider.flush
173
+ expect(provider.mlag_id).to eq(100)
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,11 @@
1
+ ---
2
+ :global:
3
+ :domain_id: MLAG-Domain
4
+ :local_interface: Vlan4094
5
+ :peer_address: 1.1.1.1
6
+ :peer_link: Port-Channel1
7
+ :shutdown: false
8
+ :interfaces:
9
+ "Port-Channel1":
10
+ :mlag_id: 1
11
+
@@ -0,0 +1,150 @@
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_ntp_config).provider(:eos) do
37
+ let(:type) { Puppet::Type.type(:eos_ntp_config) }
38
+
39
+ let :resource do
40
+ resource_hash = {
41
+ name: 'settings',
42
+ source_interface: 'Loopback0'
43
+ }
44
+ type.new(resource_hash)
45
+ end
46
+
47
+ let(:provider) { resource.provider }
48
+
49
+ let(:api) { double('ntp') }
50
+
51
+ def ntp
52
+ ntp = Fixtures[:ntp]
53
+ return ntp if ntp
54
+ fixture('ntp', dir: File.dirname(__FILE__))
55
+ end
56
+
57
+ before :each do
58
+ allow(described_class.node).to receive(:api).with('ntp').and_return(api)
59
+ allow(provider.node).to receive(:api).with('ntp').and_return(api)
60
+ end
61
+
62
+ context 'class methods' do
63
+ before { allow(api).to receive(:get).and_return(ntp) }
64
+
65
+ describe '.instances' do
66
+ subject { described_class.instances }
67
+
68
+ it { is_expected.to be_an Array }
69
+
70
+ it 'has one instance' do
71
+ expect(subject.size).to eq(1)
72
+ end
73
+
74
+ it 'contains Eos_ntp_config[settings]' do
75
+ instance = subject.find { |p| p.name == 'settings' }
76
+ expect(instance).to be_a described_class
77
+ end
78
+
79
+ describe 'Eos_ntp_config[settings]' do
80
+ subject do
81
+ described_class.instances.find { |p| p.name == 'settings' }
82
+ end
83
+
84
+ include_examples 'provider resource methods',
85
+ name: 'settings',
86
+ source_interface: 'Loopback0'
87
+ end
88
+ end
89
+
90
+ describe '.prefetch' do
91
+ let(:resources) do
92
+ {
93
+ 'settings' => Puppet::Type.type(:eos_ntp_config)
94
+ .new(name: 'settings'),
95
+ 'alternative' => Puppet::Type.type(:eos_ntp_config)
96
+ .new(name: 'alternative')
97
+ }
98
+ end
99
+
100
+ subject { described_class.prefetch(resources) }
101
+
102
+ it 'resource providers are absent prior to calling .prefetch' do
103
+ resources.values.each do |rsrc|
104
+ expect(rsrc.provider.source_interface).to eq(:absent)
105
+ end
106
+ end
107
+
108
+ it 'sets the provider instane of the managed resource' do
109
+ subject
110
+ expect(resources['settings'].provider.name).to eq 'settings'
111
+ expect(resources['settings'].provider.exists?).to be_truthy
112
+ expect(resources['settings'].provider.source_interface).to \
113
+ eq 'Loopback0'
114
+ end
115
+
116
+ it 'does not set the provider instance of the unmanaged resource' do
117
+ subject
118
+ expect(resources['alternative'].provider.name).to eq 'alternative'
119
+ expect(resources['alternative'].provider.exists?).to be_falsy
120
+ expect(resources['alternative'].provider.source_interface).to eq :absent
121
+ end
122
+ end
123
+ end
124
+
125
+ context 'resource (instance) methods' do
126
+ describe '#exists?' do
127
+ subject { provider.exists? }
128
+
129
+ context 'when the resource does not exist on the system' do
130
+ it { is_expected.to be_falsey }
131
+ end
132
+
133
+ context 'when the resource exists on the system' do
134
+ let(:provider) do
135
+ allow(api).to receive(:get).and_return(ntp)
136
+ described_class.instances.first
137
+ end
138
+ it { is_expected.to be_truthy }
139
+ end
140
+ end
141
+
142
+ describe '#source_interface=(val)' do
143
+ it 'updates source_interace with value "Loopback1"' do
144
+ expect(api).to receive(:set_source_interface).with(value: 'Loopback1')
145
+ provider.source_interface = 'Loopback1'
146
+ expect(provider.source_interface).to eq('Loopback1')
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ :source_interface: Loopback0
3
+ :servers: ['1.2.3.4']
@@ -0,0 +1,152 @@
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_ntp_server).provider(:eos) do
37
+ let :resource do
38
+ resource_hash = {
39
+ name: '1.2.3.4',
40
+ ensure: :present
41
+ }
42
+ Puppet::Type.type(:eos_ntp_server).new(resource_hash)
43
+ end
44
+
45
+ let(:provider) { resource.provider }
46
+
47
+ let(:api) { double('ntp') }
48
+
49
+ def ntp
50
+ ntp = Fixtures[:ntp]
51
+ return ntp if ntp
52
+ fixture('ntp', dir: File.dirname(__FILE__))
53
+ end
54
+
55
+ before :each do
56
+ allow(described_class.node).to receive(:api).with('ntp').and_return(api)
57
+ allow(provider.node).to receive(:api).with('ntp').and_return(api)
58
+ end
59
+
60
+ context 'class methods' do
61
+ before { allow(api).to receive(:get).and_return(ntp) }
62
+
63
+ describe '.instances' do
64
+ subject { described_class.instances }
65
+
66
+ it { is_expected.to be_an Array }
67
+
68
+ it 'has one entry' do
69
+ expect(subject.size).to eq(1)
70
+ end
71
+
72
+ it 'has an instance for server 1.2.3.4' do
73
+ instance = subject.find { |p| p.name == '1.2.3.4' }
74
+ expect(instance).to be_a described_class
75
+ end
76
+
77
+ context 'eos_ntp_config { 1.2.3.4: } ' do
78
+ subject { described_class.instances.find { |p| p.name == '1.2.3.4' } }
79
+
80
+ include_examples 'provider resource methods',
81
+ name: '1.2.3.4',
82
+ ensure: :present
83
+ end
84
+ end
85
+
86
+ describe '.prefetch' do
87
+ let :resources do
88
+ {
89
+ '1.2.3.4' => Puppet::Type.type(:eos_ntp_server).new(name: '1.2.3.4'),
90
+ '5.6.7.8' => Puppet::Type.type(:eos_ntp_server).new(name: '5.6.7.8')
91
+ }
92
+ end
93
+
94
+ subject { described_class.prefetch(resources) }
95
+
96
+ it 'resource providers are absent prior to calling .prefetch' do
97
+ resources.values.each do |rsrc|
98
+ expect(rsrc.provider.exists?).to be_falsey
99
+ end
100
+ end
101
+
102
+ it 'sets the provider instance of the managed resource' do
103
+ subject
104
+ expect(resources['1.2.3.4'].provider.name).to eq '1.2.3.4'
105
+ expect(resources['1.2.3.4'].provider.exists?).to be_truthy
106
+ end
107
+
108
+ it 'does not set the provider instance of the unmanaged resource' do
109
+ subject
110
+ expect(resources['5.6.7.8'].provider.name).to eq('5.6.7.8')
111
+ expect(resources['5.6.7.8'].provider.exists?).to be_falsey
112
+ end
113
+ end
114
+ end
115
+
116
+ context 'resource (instnce) methods' do
117
+ describe '#exists?' do
118
+ subject { provider.exists? }
119
+
120
+ context 'when the reosurce does not exist on the system' do
121
+ it { is_expected.to be_falsey }
122
+ end
123
+
124
+ context 'when the resource exists on the system' do
125
+ let(:provider) do
126
+ allow(api).to receive(:get).and_return(ntp)
127
+ described_class.instances.first
128
+ end
129
+ it { is_expected.to be_truthy }
130
+ end
131
+ end
132
+
133
+ describe '#create' do
134
+ before do
135
+ expect(api).to receive(:add_server).with(resource[:name])
136
+ end
137
+
138
+ it 'sets ensure on :present' do
139
+ provider.create
140
+ expect(provider.ensure).to eq(:present)
141
+ end
142
+ end
143
+
144
+ describe '#destroy' do
145
+ it 'sets ensure to :absent' do
146
+ expect(api).to receive(:remove_server).with(resource[:name])
147
+ provider.destroy
148
+ expect(provider.ensure).to eq(:absent)
149
+ end
150
+ end
151
+ end
152
+ end