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