puppet_x_eos_eapi 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +24 -0
- data/LICENSE.txt +202 -0
- data/README.md +87 -0
- data/Rakefile +1 -0
- data/lib/puppet_x/eos/autoload.rb +57 -0
- data/lib/puppet_x/eos/eapi.rb +259 -0
- data/lib/puppet_x/eos/module_base.rb +37 -0
- data/lib/puppet_x/eos/modules/daemon.rb +109 -0
- data/lib/puppet_x/eos/modules/extension.rb +167 -0
- data/lib/puppet_x/eos/modules/interface.rb +180 -0
- data/lib/puppet_x/eos/modules/ipinterface.rb +133 -0
- data/lib/puppet_x/eos/modules/mlag.rb +268 -0
- data/lib/puppet_x/eos/modules/ntp.rb +129 -0
- data/lib/puppet_x/eos/modules/ospf.rb +129 -0
- data/lib/puppet_x/eos/modules/portchannel.rb +277 -0
- data/lib/puppet_x/eos/modules/radius.rb +367 -0
- data/lib/puppet_x/eos/modules/snmp.rb +177 -0
- data/lib/puppet_x/eos/modules/switchport.rb +255 -0
- data/lib/puppet_x/eos/modules/system.rb +138 -0
- data/lib/puppet_x/eos/modules/tacacs.rb +302 -0
- data/lib/puppet_x/eos/modules/vlan.rb +179 -0
- data/lib/puppet_x/eos/modules/vxlan.rb +132 -0
- data/lib/puppet_x/eos/provider.rb +71 -0
- data/lib/puppet_x/eos/version.rb +41 -0
- data/lib/puppet_x/net_dev/eos_api.rb +1011 -0
- data/lib/puppet_x/net_dev/eos_api/common_methods.rb +27 -0
- data/lib/puppet_x/net_dev/eos_api/snmp_methods.rb +647 -0
- data/lib/puppet_x/net_dev/eos_api/version.rb +8 -0
- data/lib/puppet_x_eos_eapi.rb +4 -0
- data/puppet_x_eos_eapi.gemspec +31 -0
- data/spec/fixtures/fixture_all_portchannel_modes.json +8 -0
- data/spec/fixtures/fixture_all_portchannels_detailed.json +15 -0
- data/spec/fixtures/fixture_create_vlan_error.json +17 -0
- data/spec/fixtures/fixture_create_vlan_success.json +12 -0
- data/spec/fixtures/fixture_eapi_conf.yaml +4 -0
- data/spec/fixtures/fixture_enable_configure_vlan_3111_name_foo.json +14 -0
- data/spec/fixtures/fixture_enable_configure_vlan_foo_name_bar.json +19 -0
- data/spec/fixtures/fixture_get_snmp_communities_non_existent_acl.yaml +2 -0
- data/spec/fixtures/fixture_get_snmp_location_westeros.json +5 -0
- data/spec/fixtures/fixture_portchannel_min_links_1.json +8 -0
- data/spec/fixtures/fixture_portchannel_min_links_2.json +8 -0
- data/spec/fixtures/fixture_running_config.yaml +1 -0
- data/spec/fixtures/fixture_running_configuration_radius_configured.yaml +30 -0
- data/spec/fixtures/fixture_running_configuration_radius_default.yaml +29 -0
- data/spec/fixtures/fixture_running_configuration_radius_server_groups.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_radius_servers.yaml +34 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_configured.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_default.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_groups.yaml +1 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_groups_3.yaml +43 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_servers.yaml +41 -0
- data/spec/fixtures/fixture_s4_show_etherchannel_detailed.json +9 -0
- data/spec/fixtures/fixture_show_flowcontrol_et1.json +5 -0
- data/spec/fixtures/fixture_show_interfaces.json +297 -0
- data/spec/fixtures/fixture_show_interfaces_switchport_format_text.json +9 -0
- data/spec/fixtures/fixture_show_port_channel_summary_2_lags.json +9 -0
- data/spec/fixtures/fixture_show_port_channel_summary_static.json +9 -0
- data/spec/fixtures/fixture_show_snmp_community.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_contact_empty.json +5 -0
- data/spec/fixtures/fixture_show_snmp_contact_name.json +5 -0
- data/spec/fixtures/fixture_show_snmp_disabled.json +5 -0
- data/spec/fixtures/fixture_show_snmp_enabled.json +5 -0
- data/spec/fixtures/fixture_show_snmp_host.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_host_duplicates.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_host_more_duplicates.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_location_empty.json +5 -0
- data/spec/fixtures/fixture_show_snmp_trap.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_user.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_user_raw_text.yaml +1 -0
- data/spec/fixtures/fixture_show_vlan.json +37 -0
- data/spec/fixtures/fixture_show_vlan_3110.json +18 -0
- data/spec/fixtures/fixture_show_vlan_4000.json +18 -0
- data/spec/fixtures/fixture_snmp_host_opts.yaml +11 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/fixtures.rb +104 -0
- data/spec/unit/puppet_x/eos/eapi_spec.rb +182 -0
- data/spec/unit/puppet_x/eos/module_base_spec.rb +26 -0
- data/spec/unit/puppet_x/eos/modules/daemon_spec.rb +110 -0
- data/spec/unit/puppet_x/eos/modules/extension_spec.rb +197 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/daemon_getall.json +3 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/extension_getall.json +28 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/hostname.json +6 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/interface_getall.json +509 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ipinterface_getall.json +56 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get.json +21 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get_interfaces.json +18 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ntp_get.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ospf_instance_getall.json +58 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_get.json +54 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getlacpmode.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getmembers.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_po1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/snmp_get.json +14 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get_et1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_getall_interfaces.json +230 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_list.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_name.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_hostname.json +6 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_name_servers.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/vlan_getall.json +123 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/vxlan_get.json +24 -0
- data/spec/unit/puppet_x/eos/modules/interface_spec.rb +281 -0
- data/spec/unit/puppet_x/eos/modules/ipinterface_spec.rb +143 -0
- data/spec/unit/puppet_x/eos/modules/mlag_spec.rb +349 -0
- data/spec/unit/puppet_x/eos/modules/ntp_spec.rb +136 -0
- data/spec/unit/puppet_x/eos/modules/ospf_spec.rb +143 -0
- data/spec/unit/puppet_x/eos/modules/portchannel_spec.rb +357 -0
- data/spec/unit/puppet_x/eos/modules/radius_spec.rb +509 -0
- data/spec/unit/puppet_x/eos/modules/snmp_spec.rb +202 -0
- data/spec/unit/puppet_x/eos/modules/switchport_get_et1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/switchport_spec.rb +307 -0
- data/spec/unit/puppet_x/eos/modules/system_spec.rb +170 -0
- data/spec/unit/puppet_x/eos/modules/tacacs_spec.rb +448 -0
- data/spec/unit/puppet_x/eos/modules/vlan_spec.rb +244 -0
- data/spec/unit/puppet_x/eos/modules/vxlan_spec.rb +189 -0
- data/spec/unit/puppet_x/eos/provider_spec.rb +35 -0
- data/spec/unit/puppet_x/net_dev/eos_api/common_methods_spec.rb +34 -0
- data/spec/unit/puppet_x/net_dev/eos_api/snmp_methods_spec.rb +842 -0
- data/spec/unit/puppet_x/net_dev/eos_api_spec.rb +1000 -0
- metadata +369 -0
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
require 'puppet_x/eos/modules/snmp'
|
|
34
|
+
|
|
35
|
+
describe PuppetX::Eos::Snmp do
|
|
36
|
+
let(:eapi) { double }
|
|
37
|
+
let(:instance) { PuppetX::Eos::Snmp.new eapi }
|
|
38
|
+
|
|
39
|
+
context 'when initializing a new Snmp instance' do
|
|
40
|
+
subject { instance }
|
|
41
|
+
it { is_expected.to be_a_kind_of PuppetX::Eos::Snmp }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with Eapi#enable' do
|
|
45
|
+
before :each do
|
|
46
|
+
allow(eapi).to receive(:enable)
|
|
47
|
+
.with(commands, format: 'text')
|
|
48
|
+
.and_return(api_response)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context '#get' do
|
|
52
|
+
subject { instance.get }
|
|
53
|
+
|
|
54
|
+
let(:commands) do
|
|
55
|
+
['show snmp contact', 'show snmp location',
|
|
56
|
+
'show snmp chassis', 'show snmp source-interface']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
let :api_response do
|
|
60
|
+
dir = File.dirname(__FILE__)
|
|
61
|
+
file = File.join(dir, 'fixtures/snmp_get.json')
|
|
62
|
+
JSON.load(File.read(file))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe 'snmp configuration' do
|
|
66
|
+
it { is_expected.to be_a_kind_of Hash }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'with Eapi#config' do
|
|
72
|
+
before :each do
|
|
73
|
+
allow(eapi).to receive(:config)
|
|
74
|
+
.with(commands)
|
|
75
|
+
.and_return(api_response)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context '#set_contact' do
|
|
79
|
+
subject { instance.set_contact(opts) }
|
|
80
|
+
|
|
81
|
+
let(:opts) { { value: value, default: default } }
|
|
82
|
+
let(:default) { false }
|
|
83
|
+
let(:value) { nil }
|
|
84
|
+
|
|
85
|
+
describe 'configure snmp contact' do
|
|
86
|
+
let(:value) { 'foo' }
|
|
87
|
+
let(:commands) { "snmp contact #{value}" }
|
|
88
|
+
let(:api_response) { [{}] }
|
|
89
|
+
|
|
90
|
+
it { is_expected.to be_truthy }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe 'negate snmp contact' do
|
|
94
|
+
let(:commands) { 'no snmp contact' }
|
|
95
|
+
let(:api_response) { [{}] }
|
|
96
|
+
|
|
97
|
+
it { is_expected.to be_truthy }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe 'default snmp contact' do
|
|
101
|
+
let(:default) { true }
|
|
102
|
+
let(:commands) { 'default snmp contact' }
|
|
103
|
+
let(:api_response) { [{}] }
|
|
104
|
+
|
|
105
|
+
it { is_expected.to be_truthy }
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context '#set_location' do
|
|
110
|
+
subject { instance.set_location(opts) }
|
|
111
|
+
|
|
112
|
+
let(:opts) { { value: value, default: default } }
|
|
113
|
+
let(:default) { false }
|
|
114
|
+
let(:value) { nil }
|
|
115
|
+
|
|
116
|
+
describe 'configure snmp location' do
|
|
117
|
+
let(:value) { 'foo' }
|
|
118
|
+
let(:commands) { "snmp location #{value}" }
|
|
119
|
+
let(:api_response) { [{}] }
|
|
120
|
+
|
|
121
|
+
it { is_expected.to be_truthy }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe 'negate snmp location' do
|
|
125
|
+
let(:commands) { 'no snmp location' }
|
|
126
|
+
let(:api_response) { [{}] }
|
|
127
|
+
|
|
128
|
+
it { is_expected.to be_truthy }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe 'default snmp location' do
|
|
132
|
+
let(:default) { true }
|
|
133
|
+
let(:commands) { 'default snmp location' }
|
|
134
|
+
let(:api_response) { [{}] }
|
|
135
|
+
|
|
136
|
+
it { is_expected.to be_truthy }
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
context '#set_chassis_id' do
|
|
141
|
+
subject { instance.set_chassis_id(opts) }
|
|
142
|
+
|
|
143
|
+
let(:opts) { { value: value, default: default } }
|
|
144
|
+
let(:default) { false }
|
|
145
|
+
let(:value) { nil }
|
|
146
|
+
|
|
147
|
+
describe 'configure snmp chassis id' do
|
|
148
|
+
let(:value) { 'foo' }
|
|
149
|
+
let(:commands) { "snmp chassis #{value}" }
|
|
150
|
+
let(:api_response) { [{}] }
|
|
151
|
+
|
|
152
|
+
it { is_expected.to be_truthy }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe 'negate snmp chassis id' do
|
|
156
|
+
let(:commands) { 'no snmp chassis' }
|
|
157
|
+
let(:api_response) { [{}] }
|
|
158
|
+
|
|
159
|
+
it { is_expected.to be_truthy }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe 'default snmp chassis id' do
|
|
163
|
+
let(:default) { true }
|
|
164
|
+
let(:commands) { 'default snmp chassis' }
|
|
165
|
+
let(:api_response) { [{}] }
|
|
166
|
+
|
|
167
|
+
it { is_expected.to be_truthy }
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context '#set_source_interface' do
|
|
172
|
+
subject { instance.set_source_interface(opts) }
|
|
173
|
+
|
|
174
|
+
let(:opts) { { value: value, default: default } }
|
|
175
|
+
let(:default) { false }
|
|
176
|
+
let(:value) { nil }
|
|
177
|
+
|
|
178
|
+
describe 'configure snmp source-interface' do
|
|
179
|
+
let(:value) { 'Loopback0' }
|
|
180
|
+
let(:commands) { "snmp source-interface #{value}" }
|
|
181
|
+
let(:api_response) { [{}] }
|
|
182
|
+
|
|
183
|
+
it { is_expected.to be_truthy }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe 'negate snmp source-interface' do
|
|
187
|
+
let(:commands) { 'no snmp source-interface' }
|
|
188
|
+
let(:api_response) { [{}] }
|
|
189
|
+
|
|
190
|
+
it { is_expected.to be_truthy }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe 'default snmp source-interface' do
|
|
194
|
+
let(:default) { true }
|
|
195
|
+
let(:commands) { 'default snmp source-interface' }
|
|
196
|
+
let(:api_response) { [{}] }
|
|
197
|
+
|
|
198
|
+
it { is_expected.to be_truthy }
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,307 @@
|
|
|
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
|
+
require 'puppet_x/eos/modules/switchport'
|
|
34
|
+
|
|
35
|
+
describe PuppetX::Eos::Switchport do
|
|
36
|
+
let(:eapi) { double }
|
|
37
|
+
let(:instance) { PuppetX::Eos::Switchport.new eapi }
|
|
38
|
+
|
|
39
|
+
context 'when initializing a new Switchport instance' do
|
|
40
|
+
subject { instance }
|
|
41
|
+
it { is_expected.to be_a_kind_of PuppetX::Eos::Switchport }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with Eapi#enable' do
|
|
45
|
+
|
|
46
|
+
context '#get' do
|
|
47
|
+
subject { instance.get(name) }
|
|
48
|
+
|
|
49
|
+
let(:name) { 'Ethernet1' }
|
|
50
|
+
let(:commands) { 'show interfaces Ethernet1 switchport' }
|
|
51
|
+
|
|
52
|
+
let :api_response do
|
|
53
|
+
dir = File.dirname(__FILE__)
|
|
54
|
+
file = File.join(dir, 'fixtures/switchport_get.json')
|
|
55
|
+
JSON.load(File.read(file))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
before :each do
|
|
59
|
+
allow(eapi).to receive(:enable)
|
|
60
|
+
.with(commands, format: 'text')
|
|
61
|
+
.and_return(api_response)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it { is_expected.to be_a_kind_of Hash }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context '#getall' do
|
|
68
|
+
subject { instance.getall }
|
|
69
|
+
|
|
70
|
+
let :interfaces do
|
|
71
|
+
dir = File.dirname(__FILE__)
|
|
72
|
+
file = File.join(dir, 'fixtures/switchport_getall_interfaces.json')
|
|
73
|
+
JSON.load(File.read(file))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
let :switchport_et1 do
|
|
77
|
+
dir = File.dirname(__FILE__)
|
|
78
|
+
file = File.join(dir, 'fixtures/switchport_get_et1.json')
|
|
79
|
+
JSON.load(File.read(file))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
before :each do
|
|
83
|
+
allow(eapi).to receive(:enable)
|
|
84
|
+
.and_return(interfaces)
|
|
85
|
+
|
|
86
|
+
allow(instance).to receive(:get).with('Ethernet1')
|
|
87
|
+
.and_return(switchport_et1)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it { is_expected.to be_a_kind_of Array }
|
|
91
|
+
|
|
92
|
+
it 'has only one entry' do
|
|
93
|
+
expect(subject.size).to eq 1
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'contains Ethernet1' do
|
|
97
|
+
expect(subject[0]['name']).to eq 'Ethernet1'
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'with Eapi#config' do
|
|
103
|
+
before :each do
|
|
104
|
+
allow(eapi).to receive(:config)
|
|
105
|
+
.with(commands)
|
|
106
|
+
.and_return(api_response)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context '#create' do
|
|
110
|
+
subject { instance.create(name) }
|
|
111
|
+
|
|
112
|
+
let(:commands) { ["interface #{name}", 'no ip address', 'switchport'] }
|
|
113
|
+
|
|
114
|
+
describe 'a new switchport in the running-config' do
|
|
115
|
+
let(:name) { 'Ethernet1' }
|
|
116
|
+
let(:api_response) { [{}, {}, {}] }
|
|
117
|
+
it { is_expected.to be_truthy }
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context '#delete' do
|
|
122
|
+
subject { instance.delete(name) }
|
|
123
|
+
|
|
124
|
+
let(:commands) { ["interface #{name}", 'no switchport'] }
|
|
125
|
+
|
|
126
|
+
describe 'an existing switchport from the running-config' do
|
|
127
|
+
let(:name) { 'Ethernet1' }
|
|
128
|
+
let(:api_response) { [{}, {}] }
|
|
129
|
+
|
|
130
|
+
it { is_expected.to be_truthy }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context '#default' do
|
|
135
|
+
subject { instance.default(name) }
|
|
136
|
+
|
|
137
|
+
let(:commands) { ["interface #{name}", 'default switchport'] }
|
|
138
|
+
|
|
139
|
+
describe 'a logical switchport interface' do
|
|
140
|
+
let(:name) { 'Ethernet1' }
|
|
141
|
+
let(:api_response) { [{}, {}] }
|
|
142
|
+
|
|
143
|
+
it { is_expected.to be_truthy }
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context '#set_mode' do
|
|
148
|
+
subject { instance.set_mode(name, opts) }
|
|
149
|
+
|
|
150
|
+
let(:opts) { { value: value, default: default } }
|
|
151
|
+
let(:default) { false }
|
|
152
|
+
let(:value) { nil }
|
|
153
|
+
|
|
154
|
+
%w(access trunk).each do |mode|
|
|
155
|
+
describe "configure switchport mode=#{mode}" do
|
|
156
|
+
let(:name) { 'Ethernet1' }
|
|
157
|
+
let(:value) { mode }
|
|
158
|
+
let(:commands) { ["interface #{name}", "switchport mode #{mode}"] }
|
|
159
|
+
let(:api_response) { [{}, {}] }
|
|
160
|
+
|
|
161
|
+
it { is_expected.to be_truthy }
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe 'negate switchport mode' do
|
|
166
|
+
let(:name) { 'Ethernet1' }
|
|
167
|
+
let(:commands) do
|
|
168
|
+
['interface Ethernet1', 'no switchport mode']
|
|
169
|
+
end
|
|
170
|
+
let(:api_response) { [{}, {}] }
|
|
171
|
+
|
|
172
|
+
it { is_expected.to be_truthy }
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
describe 'default switchport mode' do
|
|
176
|
+
let(:name) { 'Ethernet1' }
|
|
177
|
+
let(:default) { true }
|
|
178
|
+
let(:commands) do
|
|
179
|
+
['interface Ethernet1', 'default switchport mode']
|
|
180
|
+
end
|
|
181
|
+
let(:api_response) { [{}, {}] }
|
|
182
|
+
|
|
183
|
+
it { is_expected.to be_truthy }
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
context '#set_trunk_allowed_vlans' do
|
|
188
|
+
subject { instance.set_trunk_allowed_vlans(name, opts) }
|
|
189
|
+
|
|
190
|
+
let(:opts) { { value: value, default: default } }
|
|
191
|
+
let(:default) { false }
|
|
192
|
+
let(:value) { nil }
|
|
193
|
+
|
|
194
|
+
describe 'configure trunk allowed vlans' do
|
|
195
|
+
let(:name) { 'Ethernet1' }
|
|
196
|
+
let(:value) { '1,10-20,30' }
|
|
197
|
+
let(:commands) do
|
|
198
|
+
["interface #{name}", "switchport trunk allowed vlan #{value}"]
|
|
199
|
+
end
|
|
200
|
+
let(:api_response) { [{}, {}] }
|
|
201
|
+
|
|
202
|
+
it { is_expected.to be_truthy }
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe 'negate switchport trunk allowed vlans' do
|
|
206
|
+
let(:name) { 'Ethernet1' }
|
|
207
|
+
let(:commands) do
|
|
208
|
+
["interface #{name}", 'no switchport trunk allowed vlan']
|
|
209
|
+
end
|
|
210
|
+
let(:api_response) { [{}, {}] }
|
|
211
|
+
|
|
212
|
+
it { is_expected.to be_truthy }
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe 'default switchport trunk allowed vlans' do
|
|
216
|
+
let(:name) { 'Ethernet1' }
|
|
217
|
+
let(:default) { true }
|
|
218
|
+
let(:commands) do
|
|
219
|
+
["interface #{name}", 'default switchport trunk allowed vlan']
|
|
220
|
+
end
|
|
221
|
+
let(:api_response) { [{}, {}] }
|
|
222
|
+
|
|
223
|
+
it { is_expected.to be_truthy }
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
context '#set_trunk_native_vlan' do
|
|
228
|
+
subject { instance.set_trunk_native_vlan(name, opts) }
|
|
229
|
+
|
|
230
|
+
let(:opts) { { value: value, default: default } }
|
|
231
|
+
let(:default) { false }
|
|
232
|
+
let(:value) { nil }
|
|
233
|
+
|
|
234
|
+
describe 'configure trunk native vlan' do
|
|
235
|
+
let(:name) { 'Ethernet1' }
|
|
236
|
+
let(:value) { '10' }
|
|
237
|
+
let(:commands) do
|
|
238
|
+
["interface #{name}", "switchport trunk native vlan #{value}"]
|
|
239
|
+
end
|
|
240
|
+
let(:api_response) { [{}, {}] }
|
|
241
|
+
|
|
242
|
+
it { is_expected.to be_truthy }
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe 'negate switchport trunk native vlan' do
|
|
246
|
+
let(:name) { 'Ethernet1' }
|
|
247
|
+
let(:commands) do
|
|
248
|
+
["interface #{name}", 'no switchport trunk native vlan']
|
|
249
|
+
end
|
|
250
|
+
let(:api_response) { [{}, {}] }
|
|
251
|
+
|
|
252
|
+
it { is_expected.to be_truthy }
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
describe 'default switchport trunk native vlan' do
|
|
256
|
+
let(:name) { 'Ethernet1' }
|
|
257
|
+
let(:default) { true }
|
|
258
|
+
let(:commands) do
|
|
259
|
+
["interface #{name}", 'default switchport trunk native vlan']
|
|
260
|
+
end
|
|
261
|
+
let(:api_response) { [{}, {}] }
|
|
262
|
+
|
|
263
|
+
it { is_expected.to be_truthy }
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
context '#set_access_vlan' do
|
|
268
|
+
subject { instance.set_access_vlan(name, opts) }
|
|
269
|
+
|
|
270
|
+
let(:opts) { { value: value, default: default } }
|
|
271
|
+
let(:default) { false }
|
|
272
|
+
let(:value) { nil }
|
|
273
|
+
|
|
274
|
+
describe 'configure access vlan' do
|
|
275
|
+
let(:name) { 'Ethernet1' }
|
|
276
|
+
let(:value) { '10' }
|
|
277
|
+
let(:commands) do
|
|
278
|
+
["interface #{name}", "switchport access vlan #{value}"]
|
|
279
|
+
end
|
|
280
|
+
let(:api_response) { [{}, {}] }
|
|
281
|
+
|
|
282
|
+
it { is_expected.to be_truthy }
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
describe 'negate switchport access vlan' do
|
|
286
|
+
let(:name) { 'Ethernet1' }
|
|
287
|
+
let(:commands) do
|
|
288
|
+
["interface #{name}", 'no switchport access vlan']
|
|
289
|
+
end
|
|
290
|
+
let(:api_response) { [{}, {}] }
|
|
291
|
+
|
|
292
|
+
it { is_expected.to be_truthy }
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
describe 'default switchport access vlan' do
|
|
296
|
+
let(:name) { 'Ethernet1' }
|
|
297
|
+
let(:default) { true }
|
|
298
|
+
let(:commands) do
|
|
299
|
+
["interface #{name}", 'default switchport access vlan']
|
|
300
|
+
end
|
|
301
|
+
let(:api_response) { [{}, {}] }
|
|
302
|
+
|
|
303
|
+
it { is_expected.to be_truthy }
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
end
|