rbeapi 0.5.1 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/CHANGELOG.md +211 -76
  2. data/Gemfile +14 -3
  3. data/README.md +74 -38
  4. data/Rakefile +38 -17
  5. data/gems/inifile/inifile.spec.tmpl +31 -4
  6. data/gems/net_http_unix/net_http_unix.spec.tmpl +34 -8
  7. data/gems/netaddr/netaddr.spec.tmpl +31 -5
  8. data/guide/getting-started.rst +95 -64
  9. data/guide/installation.rst +27 -6
  10. data/guide/release-notes.rst +5 -1
  11. data/guide/testing.rst +5 -2
  12. data/guide/upgrading.rst +2 -0
  13. data/lib/rbeapi/api/dns.rb +8 -2
  14. data/lib/rbeapi/api/interfaces.rb +107 -21
  15. data/lib/rbeapi/api/ipinterfaces.rb +48 -0
  16. data/lib/rbeapi/api/prefixlists.rb +53 -23
  17. data/lib/rbeapi/api/routemaps.rb +11 -0
  18. data/lib/rbeapi/api/stp.rb +6 -3
  19. data/lib/rbeapi/api/switchports.rb +5 -11
  20. data/lib/rbeapi/api/system.rb +1 -1
  21. data/lib/rbeapi/api/users.rb +2 -0
  22. data/lib/rbeapi/api/varp.rb +6 -0
  23. data/lib/rbeapi/api/vlans.rb +44 -0
  24. data/lib/rbeapi/api/vrrp.rb +13 -0
  25. data/lib/rbeapi/client.rb +19 -4
  26. data/lib/rbeapi/switchconfig.rb +330 -0
  27. data/lib/rbeapi/version.rb +1 -1
  28. data/rbeapi.gemspec +2 -0
  29. data/rbeapi.spec.tmpl +30 -3
  30. data/spec/fixtures/.gitignore +1 -0
  31. data/spec/support/matchers/switch_config_sections.rb +80 -0
  32. data/spec/system/rbeapi/api/interfaces_base_spec.rb +32 -3
  33. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +56 -8
  34. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +33 -1
  35. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +27 -0
  36. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +34 -1
  37. data/spec/system/rbeapi/api/prefixlists_spec.rb +198 -0
  38. data/spec/system/rbeapi/api/stp_instances_spec.rb +49 -5
  39. data/spec/system/rbeapi/api/switchports_spec.rb +15 -9
  40. data/spec/system/rbeapi/api/vlans_spec.rb +46 -0
  41. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +1 -1
  42. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +1 -1
  43. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +9 -2
  44. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +1 -1
  45. data/spec/unit/rbeapi/api/prefixlists/default_spec.rb +202 -0
  46. data/spec/unit/rbeapi/api/prefixlists/fixture_prefixlists.text +11 -0
  47. data/spec/unit/rbeapi/api/routemaps/default_spec.rb +5 -0
  48. data/spec/unit/rbeapi/api/switchports/default_spec.rb +4 -4
  49. data/spec/unit/rbeapi/api/system/default_spec.rb +5 -0
  50. data/spec/unit/rbeapi/api/system/fixture_system.text +1 -0
  51. data/spec/unit/rbeapi/api/vlans/default_spec.rb +30 -0
  52. data/spec/unit/rbeapi/api/vrrp/default_spec.rb +10 -0
  53. data/spec/unit/rbeapi/client_spec.rb +42 -0
  54. data/spec/unit/rbeapi/switchconfig2_spec.rb +119 -0
  55. data/spec/unit/rbeapi/switchconfig3_spec.rb +125 -0
  56. data/spec/unit/rbeapi/switchconfig_spec.rb +335 -0
  57. metadata +21 -7
@@ -0,0 +1,125 @@
1
+ #
2
+ # Copyright (c) 2016, 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
+ require 'rbeapi/switchconfig'
35
+
36
+ include FixtureHelpers
37
+ include Rbeapi::SwitchConfig
38
+
39
+ describe Rbeapi::SwitchConfig::SwitchConfig do
40
+ test_config = <<-EOS
41
+ ! Test on multi-level children sections
42
+ ! Test with negated commands
43
+ no snmp-server enable traps bgp
44
+ management api http-commands
45
+ no shutdown
46
+ vrf cloud-mgmt
47
+ no shutdown
48
+ !
49
+ end
50
+ EOS
51
+ test_config_global = ['no snmp-server enable traps bgp',
52
+ 'management api http-commands']
53
+ cmds = [[' no shutdown',
54
+ ' vrf cloud-mgmt'],
55
+ [' no shutdown']]
56
+
57
+ subject { described_class.new(test_config) }
58
+
59
+ # SwitchConfig class methods
60
+ describe '#initialize' do
61
+ it 'returns the processed configuration' do
62
+ sc = subject.global
63
+ # Validate the global section
64
+ expect(sc.line).to eq('')
65
+ expect(sc.parent).to eq(nil)
66
+ expect(sc.cmds).to eq(test_config_global)
67
+ expect(sc.children.length).to eq(1)
68
+
69
+ # Validate the child of global
70
+ expect(sc.children[0].line).to eq(test_config_global[1])
71
+ expect(sc.children[0].parent).to eq(sc)
72
+ expect(sc.children[0].cmds).to eq(cmds[0])
73
+ expect(sc.children[0].children.length).to eq(1)
74
+
75
+ # Validate the child of global
76
+ child = sc.children[0].children
77
+ expect(child[0].line).to eq(cmds[0][1])
78
+ expect(child[0].parent).to eq(sc.children[0])
79
+ expect(child[0].cmds).to eq(cmds[1])
80
+ expect(child[0].children.length).to eq(0)
81
+ end
82
+ end
83
+
84
+ describe '#compare' do
85
+ it 'Verify compare returns array of 2 Sections' do
86
+ expect(subject.compare(subject)).to be_instance_of(Array)
87
+ expect(subject.compare(subject)[0]).to be_instance_of(Section)
88
+ expect(subject.compare(subject)[1]).to be_instance_of(Section)
89
+ end
90
+
91
+ it 'Verify compare of same switch configs' do
92
+ expect(subject.compare(subject)[0].line).to eq('')
93
+ expect(subject.compare(subject)[0].cmds).to eq([])
94
+ expect(subject.compare(subject)[0].children).to eq([])
95
+ expect(subject.compare(subject)[1].line).to eq('')
96
+ expect(subject.compare(subject)[1].cmds).to eq([])
97
+ expect(subject.compare(subject)[1].children).to eq([])
98
+ end
99
+
100
+ it 'Verify compare of shutdown management vrf' do
101
+ new_conf = <<-EOS
102
+ management api http-commands
103
+ no shutdown
104
+ vrf cloud-mgmt
105
+ shutdown
106
+ EOS
107
+ org_new_diff = <<-EOS
108
+ no snmp-server enable traps bgp
109
+ management api http-commands
110
+ vrf cloud-mgmt
111
+ no shutdown
112
+ EOS
113
+ new_org_diff = <<-EOS
114
+ management api http-commands
115
+ vrf cloud-mgmt
116
+ shutdown
117
+ EOS
118
+ swc_new = Rbeapi::SwitchConfig::SwitchConfig.new(new_conf)
119
+ swc_org_new = Rbeapi::SwitchConfig::SwitchConfig.new(org_new_diff)
120
+ swc_new_org = Rbeapi::SwitchConfig::SwitchConfig.new(new_org_diff)
121
+ expect(subject.compare(swc_new)[0]).to section_equal(swc_org_new.global)
122
+ expect(subject.compare(swc_new)[1]).to section_equal(swc_new_org.global)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,335 @@
1
+ #
2
+ # Copyright (c) 2016, 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
+ require 'rbeapi/switchconfig'
35
+
36
+ include FixtureHelpers
37
+ include Rbeapi::SwitchConfig
38
+
39
+ describe Rbeapi::SwitchConfig::SwitchConfig do
40
+ # rubocop:disable Style/TrailingWhitespace
41
+ test_config = <<-EOS
42
+ ! Config Description Comment
43
+ vlan 100
44
+ !
45
+ interface Ethernet 2
46
+ switchport mode trunk
47
+ switchport trunk allowed vlan 100,200
48
+ !
49
+ banner motd
50
+ This is my
51
+ multiline
52
+ banner
53
+ ends here
54
+
55
+ EOF
56
+ !
57
+ username fred privilege 0 role network-operator secret 5 $1$u4TDdWKN$VC7cZmeGn/sgNM0RMNwhR.
58
+ username fred sshkey ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrjGuhFeJz76Z5f3perh/R2s8XmnPcWF1uByHOqDDp53bggS9CZ7n67/QYVjbhyP70HMxY8R5Z4AevNtZTnSUQZmEgnuHvvAGNC63qrItE1i/sXKLvB1r8v0plcK35laNvJMYqGcGpjQ7T4Ufmn54zssiq1CBx6GfEX0+zKWD/5vnVDH9MMDolawILFb2a67VngzEZ0BCeRgLTg2ZEEEQt2hEKdglx87GBf7UIBFYM5xvywZRzHWta0dO1WDXCLD67kdqP52zucFXo7U3EUK/8X9Qltg5Pjr4mxf/U+hbO/K7xZJ+neAJDYA7bSXh8LkCuz00VxI5mAwo2PRMKaSp fred@localhost
59
+ !
60
+ router ospf 1
61
+ !! this
62
+ !! is a
63
+ !! routing
64
+ !! instance comment
65
+ !! that ends hereEOF
66
+ redistribute static
67
+ max-lsa 12000
68
+ !
69
+ management cim-provider
70
+ ssl certificate
71
+ -----BEGIN CERTIFICATE-----
72
+ MIIENzCCAx+gAwIBAgIJAOYfYfw7NCOcMA0GCSqGSIb3DQEBBQUAMIGxMQswCQYD
73
+ r5p9FrBgavAw5bKO54C0oQKpN/5fta5l6Ws0
74
+ -----END CERTIFICATE-----
75
+ -----BEGIN PRIVATE KEY-----
76
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
77
+ rdPUV9/uQkdx8VrShxlD8A==
78
+ -----END PRIVATE KEY-----
79
+ EOF
80
+ ssl key
81
+ -----BEGIN PRIVATE KEY-----
82
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
83
+ rdPUV9/uQkdx8VrShxlD8A==
84
+ -----END PRIVATE KEY-----
85
+ EOF
86
+ !
87
+ EOS
88
+ # rubocop:enable Style/TrailingWhitespace
89
+ test_config_global = [
90
+ 'vlan 100',
91
+ 'interface Ethernet 2',
92
+ "banner motd\nThis is my \n multiline\n banner\nends here\n\nEOF",
93
+ 'username fred privilege 0 role network-operator secret 5 $1$u4TDdWKN$VC7cZmeGn/sgNM0RMNwhR.',
94
+ 'username fred sshkey ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrjGuhFeJz76Z5f3perh/R2s8XmnPcWF1uByHOqDDp53bggS9CZ7n67/QYVjbhyP70HMxY8R5Z4AevNtZTnSUQZmEgnuHvvAGNC63qrItE1i/sXKLvB1r8v0plcK35laNvJMYqGcGpjQ7T4Ufmn54zssiq1CBx6GfEX0+zKWD/5vnVDH9MMDolawILFb2a67VngzEZ0BCeRgLTg2ZEEEQt2hEKdglx87GBf7UIBFYM5xvywZRzHWta0dO1WDXCLD67kdqP52zucFXo7U3EUK/8X9Qltg5Pjr4mxf/U+hbO/K7xZJ+neAJDYA7bSXh8LkCuz00VxI5mAwo2PRMKaSp fred@localhost',
95
+ 'router ospf 1',
96
+ 'management cim-provider']
97
+ cmds = [' switchport mode trunk',
98
+ ' switchport trunk allowed vlan 100,200']
99
+
100
+ bad_indent = <<-EOS
101
+ ! Vxlan without CVX
102
+ vlan 100
103
+ interface Ethernet 1
104
+ switchport access vlan 100
105
+ !
106
+ EOS
107
+ # rubocop:disable Style/TrailingWhitespace
108
+ awkward_indent = <<-EOS
109
+ !
110
+ banner motd
111
+ This is my
112
+ multiline
113
+ banner
114
+ that ends here
115
+
116
+ EOF
117
+ !
118
+ end
119
+ EOS
120
+ # rubocop:enable Style/TrailingWhitespace
121
+
122
+ subject { described_class.new(test_config) }
123
+
124
+ # SwitchConfig class methods
125
+ describe '#initialize' do
126
+ it 'returns the processed configuration' do
127
+ sc = subject.global
128
+ # Validate the global section
129
+ expect(sc).to be_instance_of(Section)
130
+ expect(sc.line).to eq('')
131
+ expect(sc.parent).to eq(nil)
132
+ expect(sc.cmds).to eq(test_config_global)
133
+ expect(sc.children.length).to eq(3)
134
+
135
+ # Validate the children of global
136
+ expect(sc.children[0].line).to eq(test_config_global[1])
137
+ expect(sc.children[0].parent).to eq(sc)
138
+ expect(sc.children[0].cmds).to eq(cmds)
139
+ expect(sc.children[0].children.length).to eq(0)
140
+ end
141
+
142
+ it 'returns error for invalid indentation' do
143
+ expect \
144
+ { Rbeapi::SwitchConfig::SwitchConfig.new(bad_indent) }.to\
145
+ raise_error ArgumentError
146
+ end
147
+
148
+ it 'does not return an error for tricky indentation' do
149
+ expect \
150
+ { Rbeapi::SwitchConfig::SwitchConfig.new(awkward_indent) }.not_to\
151
+ raise_error
152
+ end
153
+ end
154
+
155
+ describe '#compare' do
156
+ it 'Verify compare returns array of 2 Sections' do
157
+ expect(subject.compare(subject)).to be_instance_of(Array)
158
+ expect(subject.compare(subject)[0]).to be_instance_of(Section)
159
+ expect(subject.compare(subject)[1]).to be_instance_of(Section)
160
+ end
161
+
162
+ it 'Verify compare of same switch configs' do
163
+ expect(subject.compare(subject)[0].line).to eq('')
164
+ expect(subject.compare(subject)[0].cmds).to eq([])
165
+ expect(subject.compare(subject)[0].children).to eq([])
166
+ expect(subject.compare(subject)[1].line).to eq('')
167
+ expect(subject.compare(subject)[1].cmds).to eq([])
168
+ expect(subject.compare(subject)[1].children).to eq([])
169
+ end
170
+
171
+ it 'Verify compare of same switch configs without comment' do
172
+ # rubocop:disable Style/TrailingWhitespace
173
+ conf = <<-EOS
174
+ vlan 100
175
+ interface Ethernet 2
176
+ switchport mode trunk
177
+ switchport trunk allowed vlan 100,200
178
+ banner motd
179
+ This is my
180
+ multiline
181
+ banner
182
+ ends here
183
+
184
+ EOF
185
+ username fred privilege 0 role network-operator secret 5 $1$u4TDdWKN$VC7cZmeGn/sgNM0RMNwhR.
186
+ username fred sshkey ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrjGuhFeJz76Z5f3perh/R2s8XmnPcWF1uByHOqDDp53bggS9CZ7n67/QYVjbhyP70HMxY8R5Z4AevNtZTnSUQZmEgnuHvvAGNC63qrItE1i/sXKLvB1r8v0plcK35laNvJMYqGcGpjQ7T4Ufmn54zssiq1CBx6GfEX0+zKWD/5vnVDH9MMDolawILFb2a67VngzEZ0BCeRgLTg2ZEEEQt2hEKdglx87GBf7UIBFYM5xvywZRzHWta0dO1WDXCLD67kdqP52zucFXo7U3EUK/8X9Qltg5Pjr4mxf/U+hbO/K7xZJ+neAJDYA7bSXh8LkCuz00VxI5mAwo2PRMKaSp fred@localhost
187
+ router ospf 1
188
+ !! this
189
+ !! is a
190
+ !! routing
191
+ !! instance comment
192
+ !! that ends hereEOF
193
+ redistribute static
194
+ max-lsa 12000
195
+ !
196
+ management cim-provider
197
+ ssl certificate
198
+ -----BEGIN CERTIFICATE-----
199
+ MIIENzCCAx+gAwIBAgIJAOYfYfw7NCOcMA0GCSqGSIb3DQEBBQUAMIGxMQswCQYD
200
+ r5p9FrBgavAw5bKO54C0oQKpN/5fta5l6Ws0
201
+ -----END CERTIFICATE-----
202
+ -----BEGIN PRIVATE KEY-----
203
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
204
+ rdPUV9/uQkdx8VrShxlD8A==
205
+ -----END PRIVATE KEY-----
206
+ EOF
207
+ ssl key
208
+ -----BEGIN PRIVATE KEY-----
209
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
210
+ rdPUV9/uQkdx8VrShxlD8A==
211
+ -----END PRIVATE KEY-----
212
+ EOF
213
+ EOS
214
+ # rubocop:enable Style/TrailingWhitespace
215
+ sw_config = Rbeapi::SwitchConfig::SwitchConfig.new(conf)
216
+ expect(subject.compare(sw_config)[0].line).to eq('')
217
+ expect(subject.compare(sw_config)[0].cmds).to eq([])
218
+ expect(subject.compare(sw_config)[0].children).to eq([])
219
+ expect(subject.compare(sw_config)[1].line).to eq('')
220
+ expect(subject.compare(sw_config)[1].cmds).to eq([])
221
+ expect(subject.compare(sw_config)[1].children).to eq([])
222
+ end
223
+
224
+ it 'Verify compare of different vlan id' do
225
+ # rubocop:disable Style/TrailingWhitespace
226
+ new_conf = <<-EOS
227
+ vlan 101
228
+ interface Ethernet 2
229
+ switchport mode trunk
230
+ switchport trunk allowed vlan 101,200
231
+ !
232
+ banner motd
233
+ This is my
234
+ multiline
235
+ banner
236
+ ends here
237
+
238
+ EOF
239
+ !
240
+ username fred privilege 0 role network-operator secret 5 $1$u4TDdWKN$VC7cZmeGn/sgNM0RMNwhR.
241
+ username fred sshkey ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrjGuhFeJz76Z5f3perh/R2s8XmnPcWF1uByHOqDDp53bggS9CZ7n67/QYVjbhyP70HMxY8R5Z4AevNtZTnSUQZmEgnuHvvAGNC63qrItE1i/sXKLvB1r8v0plcK35laNvJMYqGcGpjQ7T4Ufmn54zssiq1CBx6GfEX0+zKWD/5vnVDH9MMDolawILFb2a67VngzEZ0BCeRgLTg2ZEEEQt2hEKdglx87GBf7UIBFYM5xvywZRzHWta0dO1WDXCLD67kdqP52zucFXo7U3EUK/8X9Qltg5Pjr4mxf/U+hbO/K7xZJ+neAJDYA7bSXh8LkCuz00VxI5mAwo2PRMKaSp fred@localhost
242
+ !
243
+ router ospf 1
244
+ !! this
245
+ !! is a
246
+ !! routing
247
+ !! instance comment
248
+ !! that ends here
249
+ redistribute static
250
+ max-lsa 12000
251
+ !
252
+ management cim-provider
253
+ ssl certificate
254
+ -----BEGIN CERTIFICATE-----
255
+ MIIENzCCAx+gAwIBAgIJAOYfYfw7NCOcMA0GCSqGSIb3DQEBBQUAMIGxMQswCQYD
256
+ r5p9FrBgavAw5bKO54C0oQKpN/5fta5l6Ws0
257
+ -----END CERTIFICATE-----
258
+ -----BEGIN PRIVATE KEY-----
259
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
260
+ rdPUV9/uQkdx8VrShxlD8A==
261
+ -----END PRIVATE KEY-----
262
+ EOF
263
+ ssl key
264
+ -----BEGIN PRIVATE KEY-----
265
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
266
+ rdPUV9/uQkdx8VrShxlD8A==
267
+ -----END PRIVATE KEY-----
268
+ EOF
269
+ EOS
270
+ # rubocop:enable Style/TrailingWhitespace
271
+ org_new_diff = <<-EOS
272
+ vlan 100
273
+ interface Ethernet 2
274
+ switchport trunk allowed vlan 100,200
275
+ router ospf 1
276
+ !! that ends hereEOF
277
+ EOS
278
+ new_org_diff = <<-EOS
279
+ vlan 101
280
+ interface Ethernet 2
281
+ switchport trunk allowed vlan 101,200
282
+ router ospf 1
283
+ !! that ends here
284
+ EOS
285
+ swc_new = Rbeapi::SwitchConfig::SwitchConfig.new(new_conf)
286
+ swc_org_new = Rbeapi::SwitchConfig::SwitchConfig.new(org_new_diff)
287
+ swc_new_org = Rbeapi::SwitchConfig::SwitchConfig.new(new_org_diff)
288
+ expect(subject.compare(swc_new)[0]).to section_equal(swc_org_new.global)
289
+ expect(subject.compare(swc_new)[1]).to section_equal(swc_new_org.global)
290
+ end
291
+ end
292
+
293
+ # Section class methods
294
+ describe 'Section Class' do
295
+ parent = Rbeapi::SwitchConfig::Section.new('parent line', nil)
296
+ child = Rbeapi::SwitchConfig::Section.new('child line', parent)
297
+
298
+ describe '#initialize' do
299
+ it 'Verify section intialization' do
300
+ expect(child).to be_instance_of(Section)
301
+ expect(child.line).to be_instance_of(String)
302
+ expect(child.line).to eq('child line')
303
+ expect(child.parent).to be_instance_of(Section)
304
+ expect(child.parent).to eq(parent)
305
+ expect(child.cmds).to be_instance_of(Array)
306
+ expect(child.cmds).to be_empty
307
+ expect(child.children).to be_instance_of(Array)
308
+ expect(child.children).to be_empty
309
+ end
310
+ end
311
+
312
+ describe '#add_child' do
313
+ it 'Verify child added to section' do
314
+ parent.add_child(child)
315
+ expect(parent.children.length).to eq(1)
316
+ expect(parent.children[0]).to eq(child)
317
+ end
318
+ end
319
+
320
+ describe '#add_cmd' do
321
+ it 'Verify command added to section' do
322
+ parent.add_cmd('new command')
323
+ expect(parent.cmds.length).to eq(1)
324
+ expect(parent.cmds[0]).to eq('new command')
325
+ end
326
+ end
327
+
328
+ describe '#get_child' do
329
+ it 'Verify child returned from section' do
330
+ parent.add_child(child)
331
+ expect(parent.get_child('child line')).to eq(child)
332
+ end
333
+ end
334
+ end
335
+ end