rbeapi 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +5 -0
  2. data/.rubocop.yml +21 -0
  3. data/CHANGELOG.md +24 -0
  4. data/Gemfile +3 -1
  5. data/Guardfile +3 -3
  6. data/README.md +92 -17
  7. data/Rakefile +99 -4
  8. data/gems/README.rst +4 -0
  9. data/gems/inifile/.gitignore +2 -0
  10. data/gems/inifile/README.rst +5 -0
  11. data/gems/inifile/inifile.spec.tmpl +84 -0
  12. data/gems/net_http_unix/.gitignore +2 -0
  13. data/gems/net_http_unix/README.rst +5 -0
  14. data/gems/net_http_unix/net_http_unix.spec.tmpl +54 -0
  15. data/gems/netaddr/README.rst +5 -0
  16. data/gems/netaddr/netaddr.spec.tmpl +50 -0
  17. data/lib/rbeapi/api/aaa.rb +14 -17
  18. data/lib/rbeapi/api/acl.rb +276 -0
  19. data/lib/rbeapi/api/dns.rb +7 -4
  20. data/lib/rbeapi/api/interfaces.rb +239 -239
  21. data/lib/rbeapi/api/ipinterfaces.rb +5 -3
  22. data/lib/rbeapi/api/logging.rb +8 -5
  23. data/lib/rbeapi/api/mlag.rb +45 -127
  24. data/lib/rbeapi/api/ntp.rb +1 -4
  25. data/lib/rbeapi/api/ospf.rb +16 -13
  26. data/lib/rbeapi/api/prefixlists.rb +4 -4
  27. data/lib/rbeapi/api/radius.rb +34 -25
  28. data/lib/rbeapi/api/routemaps.rb +16 -10
  29. data/lib/rbeapi/api/snmp.rb +26 -13
  30. data/lib/rbeapi/api/staticroutes.rb +6 -5
  31. data/lib/rbeapi/api/stp.rb +77 -18
  32. data/lib/rbeapi/api/switchports.rb +20 -12
  33. data/lib/rbeapi/api/system.rb +6 -6
  34. data/lib/rbeapi/api/tacacs.rb +9 -6
  35. data/lib/rbeapi/api/varp.rb +15 -10
  36. data/lib/rbeapi/api/vlans.rb +5 -6
  37. data/lib/rbeapi/api.rb +56 -16
  38. data/lib/rbeapi/client.rb +85 -50
  39. data/lib/rbeapi/eapilib.rb +95 -56
  40. data/lib/rbeapi/netdev/snmp.rb +7 -16
  41. data/lib/rbeapi/utils.rb +3 -5
  42. data/lib/rbeapi/version.rb +1 -1
  43. data/rbeapi.gemspec +4 -2
  44. data/rbeapi.spec.tmpl +72 -0
  45. data/spec/support/fixtures.rb +6 -4
  46. data/spec/support/shared_examples_for_api_modules.rb +3 -18
  47. data/spec/system/api_acl_spec.rb +128 -0
  48. data/spec/system/api_ospf_interfaces_spec.rb +17 -14
  49. data/spec/system/api_ospf_spec.rb +8 -8
  50. data/spec/system/api_varp_interfaces_spec.rb +22 -13
  51. data/spec/system/api_varp_spec.rb +1 -4
  52. data/spec/system/rbeapi/api/interfaces_base_spec.rb +3 -4
  53. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +13 -9
  54. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +43 -26
  55. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +7 -6
  56. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +34 -21
  57. data/spec/system/rbeapi/api/mlag_interfaces_spec.rb +15 -38
  58. data/spec/system/rbeapi/api/mlag_spec.rb +26 -30
  59. data/spec/system/rbeapi/api/snmp_spec.rb +0 -3
  60. data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -12
  61. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +1 -3
  62. data/spec/system/rbeapi/api/switchports_spec.rb +14 -12
  63. data/spec/system/rbeapi/api/system_spec.rb +0 -3
  64. data/spec/system/rbeapi/api/vlans_spec.rb +19 -9
  65. data/spec/unit/rbeapi/api/acl/default_spec.rb +158 -0
  66. data/spec/unit/rbeapi/api/acl/fixture_acl_standard.text +22 -0
  67. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +123 -0
  68. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +89 -0
  69. data/spec/unit/rbeapi/api/interfaces/fixture_interfaces.text +219 -0
  70. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +149 -0
  71. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +243 -0
  72. data/spec/unit/rbeapi/api/mlag/default_spec.rb +218 -0
  73. data/spec/unit/rbeapi/api/mlag/fixture_mlag.text +238 -0
  74. data/spec/unit/rbeapi/api/vlans/default_spec.rb +135 -0
  75. data/spec/unit/rbeapi/api/vlans/fixture_vlans.text +5 -0
  76. metadata +79 -4
  77. data/lib/rbeapi/api/radius.rb.old +0 -399
@@ -12,9 +12,11 @@ describe Rbeapi::Api::StpInstances do
12
12
  end
13
13
 
14
14
  describe '#get' do
15
- before { node.config(['spanning-tree mode mstp',
16
- 'spanning-tree mst configuration',
17
- 'instance 1 vlans 1', 'exit']) }
15
+ before do
16
+ node.config(['spanning-tree mode mstp',
17
+ 'spanning-tree mst configuration',
18
+ 'instance 1 vlans 1', 'exit'])
19
+ end
18
20
 
19
21
  it 'returns the stp instance resource as a hash' do
20
22
  expect(subject.get('1')).to be_a_kind_of(Hash)
@@ -26,8 +28,9 @@ describe Rbeapi::Api::StpInstances do
26
28
  end
27
29
 
28
30
  describe '#getall' do
29
- before { node.config(['no spanning-tree mode mstp',
30
- 'spanning-tree mode mstp']) }
31
+ before do
32
+ node.config(['no spanning-tree mode mstp', 'spanning-tree mode mstp'])
33
+ end
31
34
 
32
35
  it 'returns a kind of hash' do
33
36
  expect(subject.getall).to be_a_kind_of(Hash)
@@ -35,9 +38,11 @@ describe Rbeapi::Api::StpInstances do
35
38
  end
36
39
 
37
40
  describe '#delete' do
38
- before { node.config(['spanning-tree mode mstp',
39
- 'spanning-tree mst configuration',
40
- 'instance 1 vlans 1', 'exit']) }
41
+ before do
42
+ node.config(['spanning-tree mode mstp',
43
+ 'spanning-tree mst configuration',
44
+ 'instance 1 vlans 1', 'exit'])
45
+ end
41
46
 
42
47
  it 'deletes the mst instance' do
43
48
  expect(subject.get('1')).not_to be_nil
@@ -47,10 +52,13 @@ describe Rbeapi::Api::StpInstances do
47
52
  end
48
53
 
49
54
  describe '#set_priority' do
50
- before { node.config(['spanning-tree mode mstp',
51
- 'default spanning-tree mst configuration',
52
- 'spanning-tree mst configuration',
53
- 'instance 1 vlans 1', 'exit']) }
55
+ before do
56
+ node.config(['default spanning-tree mst 1 priority',
57
+ 'spanning-tree mode mstp',
58
+ 'default spanning-tree mst configuration',
59
+ 'spanning-tree mst configuration',
60
+ 'instance 1 vlans 1', 'exit'])
61
+ end
54
62
 
55
63
  it 'set the instance priority' do
56
64
  expect(subject.get('1')[:priority]).to eq('32768')
@@ -12,9 +12,8 @@ describe Rbeapi::Api::StpInterfaces do
12
12
  end
13
13
 
14
14
  describe '#get' do
15
-
16
15
  let(:entity) do
17
- { portfast: false, bpduguard: false }
16
+ { portfast: false, portfast_type: 'normal', bpduguard: false }
18
17
  end
19
18
 
20
19
  before { node.config('default interface Ethernet1') }
@@ -25,7 +24,6 @@ describe Rbeapi::Api::StpInterfaces do
25
24
  end
26
25
 
27
26
  describe '#getall' do
28
-
29
27
  before { node.config('default interface Ethernet1') }
30
28
 
31
29
  it 'includes interface ethernet1' do
@@ -12,13 +12,14 @@ describe Rbeapi::Api::Switchports do
12
12
  end
13
13
 
14
14
  describe '#get' do
15
-
16
15
  let(:keys) do
17
- [ :mode, :access_vlan, :trunk_native_vlan, :trunk_allowed_vlans ]
16
+ [:mode, :access_vlan, :trunk_native_vlan, :trunk_allowed_vlans]
18
17
  end
19
18
 
20
- before { node.config(['default interface Ethernet1', 'interface Ethernet2',
21
- 'no switchport']) }
19
+ before do
20
+ node.config(['default interface Ethernet1', 'interface Ethernet2',
21
+ 'no switchport'])
22
+ end
22
23
 
23
24
  it 'returns the switchport resource' do
24
25
  expect(subject.get('Ethernet1')).not_to be_nil
@@ -33,7 +34,8 @@ describe Rbeapi::Api::Switchports do
33
34
  end
34
35
 
35
36
  it 'returns allowed_vlans as an array' do
36
- expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to be_a_kind_of(Array)
37
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans])
38
+ .to be_a_kind_of(Array)
37
39
  end
38
40
  end
39
41
 
@@ -47,7 +49,7 @@ describe Rbeapi::Api::Switchports do
47
49
  it 'returns a hash collection' do
48
50
  expect(subject.getall).to be_a_kind_of(Hash)
49
51
  end
50
- end
52
+ end
51
53
 
52
54
  describe '#create' do
53
55
  before { node.config(['interface Ethernet1', 'no switchport']) }
@@ -110,7 +112,8 @@ describe Rbeapi::Api::Switchports do
110
112
 
111
113
  it 'sets the trunk native vlan to 100' do
112
114
  expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('1')
113
- expect(subject.set_trunk_native_vlan('Ethernet1', value: '100')).to be_truthy
115
+ expect(subject.set_trunk_native_vlan('Ethernet1', value: '100'))
116
+ .to be_truthy
114
117
  expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('100')
115
118
  end
116
119
  end
@@ -119,17 +122,16 @@ describe Rbeapi::Api::Switchports do
119
122
  before { node.config(['default interface Ethernet1', 'vlan 100']) }
120
123
 
121
124
  it 'raises an ArgumentError if value is not an array' do
122
- expect {
123
- subject.set_trunk_allowed_vlans('Ethernet1', value: '1-100')
124
- }.to raise_error(ArgumentError)
125
+ expect { subject.set_trunk_allowed_vlans('Ethernet1', value: '1-100') }
126
+ .to raise_error(ArgumentError)
125
127
  end
126
128
 
127
129
  it 'sets vlan 100 to the trunk allowed vlans' do
128
130
  node.config(['interface Ethernet1', 'switchport trunk allowed vlan none'])
129
131
  expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to be_empty
130
- expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [100])).to be_truthy
132
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [100]))
133
+ .to be_truthy
131
134
  expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to include(100)
132
135
  end
133
136
  end
134
137
  end
135
-
@@ -12,7 +12,6 @@ describe Rbeapi::Api::System do
12
12
  end
13
13
 
14
14
  describe '#get' do
15
-
16
15
  let(:entity) do
17
16
  { hostname: 'localhost' }
18
17
  end
@@ -34,5 +33,3 @@ describe Rbeapi::Api::System do
34
33
  end
35
34
  end
36
35
  end
37
-
38
-
@@ -11,16 +11,29 @@ describe Rbeapi::Api::Vlans do
11
11
  Rbeapi::Client.connect_to('dut')
12
12
  end
13
13
 
14
- describe '#get' do
14
+ context '#get' do
15
+ describe 'with defaults' do
16
+ let(:entity) do
17
+ { name: 'default', state: 'active', trunk_groups: [] }
18
+ end
15
19
 
16
- let(:entity) do
17
- { name: 'default', state: 'active', trunk_groups: [] }
20
+ before { node.config(['no vlan 1-4094', 'vlan 1']) }
21
+
22
+ it 'returns the vlan resource' do
23
+ expect(subject.get('1')).to eq(entity)
24
+ end
18
25
  end
19
26
 
20
- before { node.config(['no vlan 1-4094', 'vlan 1']) }
27
+ describe 'validate name parser' do
28
+ let(:entity) do
29
+ { name: 'test-vlan', state: 'active', trunk_groups: [] }
30
+ end
31
+
32
+ before { node.config(['no vlan 1-4094', 'vlan 1', 'name test-vlan']) }
21
33
 
22
- it 'returns the vlan resource' do
23
- expect(subject.get('1')).to eq(entity)
34
+ it 'returns the vlan resource' do
35
+ expect(subject.get('1')).to eq(entity)
36
+ end
24
37
  end
25
38
  end
26
39
 
@@ -81,7 +94,6 @@ describe Rbeapi::Api::Vlans do
81
94
  end
82
95
 
83
96
  describe '#set_state' do
84
-
85
97
  it 'sets vlan 1 state to suspend' do
86
98
  node.config(['default vlan 1', 'vlan 1'])
87
99
  expect(subject.get('1')[:state]).to eq('active')
@@ -117,5 +129,3 @@ describe Rbeapi::Api::Vlans do
117
129
  end
118
130
  end
119
131
  end
120
-
121
-
@@ -0,0 +1,158 @@
1
+ #
2
+ # Copyright (c) 2015, 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/api/acl'
35
+
36
+ include FixtureHelpers
37
+
38
+ describe Rbeapi::Api::Acl do
39
+ subject { described_class.new(node) }
40
+
41
+ let(:node) { double('node') }
42
+
43
+ def acls
44
+ acls = Fixtures[:acls]
45
+ return acls if acls
46
+ fixture('acl_standard', format: :text, dir: File.dirname(__FILE__))
47
+ end
48
+
49
+ before :each do
50
+ allow(subject.node).to receive(:running_config).and_return(acls)
51
+ end
52
+
53
+ describe '#get' do
54
+ let(:test1_entries) do
55
+ { '10' => { seqno: '10', action: 'permit', srcaddr: '1.2.3.4',
56
+ srcprefixlen: '255.255.255.255', log: 'log' },
57
+ '20' => { seqno: '20', action: 'permit', srcaddr: '1.2.3.4',
58
+ srcprefixlen: '255.255.0.0', log: 'log' },
59
+ '30' => { seqno: '30', action: 'deny', srcaddr: '0.0.0.0',
60
+ srcprefixlen: '255.255.255.255', log: nil },
61
+ '40' => { seqno: '40', action: 'permit', srcaddr: '5.6.7.0',
62
+ srcprefixlen: '24', log: nil },
63
+ '50' => { seqno: '50', action: 'permit', srcaddr: '16.0.0.0',
64
+ srcprefixlen: '8', log: nil },
65
+ '60' => { seqno: '60', action: 'permit', srcaddr: '9.10.11.0',
66
+ srcprefixlen: '255.255.255.0', log: 'log' }
67
+ }
68
+ end
69
+
70
+ it 'returns the ACL resource' do
71
+ expect(subject.get('test1')).to eq(test1_entries)
72
+ end
73
+ end
74
+
75
+ describe '#getall' do
76
+ it 'returns the ACL collection' do
77
+ expect(subject.getall).to include('test1')
78
+ expect(subject.getall).to include('test2')
79
+ end
80
+
81
+ it 'returns a hash collection' do
82
+ expect(subject.getall).to be_a_kind_of(Hash)
83
+ end
84
+
85
+ it 'has two entries' do
86
+ expect(subject.getall.size).to eq(2)
87
+ end
88
+ end
89
+
90
+ describe '#create' do
91
+ it 'creates a new ACL resource' do
92
+ expect(node).to receive(:config).with('ip access-list standard abc')
93
+ expect(subject.create('abc')).to be_truthy
94
+ end
95
+ end
96
+
97
+ describe '#delete' do
98
+ it 'deletes an ACL resource' do
99
+ expect(node).to receive(:config).with('no ip access-list standard abc')
100
+ expect(subject.delete('abc')).to be_truthy
101
+ end
102
+ end
103
+
104
+ describe '#default' do
105
+ it 'sets ACL abc to default value' do
106
+ expect(node).to receive(:config)
107
+ .with('default ip access-list standard abc')
108
+ expect(subject.default('abc')).to be_truthy
109
+ end
110
+ end
111
+
112
+ describe '#update_entry' do
113
+ let(:update_entry) do
114
+ { seqno: '60', action: 'permit', srcaddr: '0.0.0.0',
115
+ srcprefixlen: '255.255.255.255', log: nil }
116
+ end
117
+
118
+ let(:update_cmd) do
119
+ ['ip access-list standard test2', 'no 60',
120
+ '60 permit 0.0.0.0/255.255.255.255', 'exit']
121
+ end
122
+
123
+ it 'Change entry 60 to values in update_entry' do
124
+ expect(subject.get('test2')['60'][:action]).to eq('deny')
125
+ expect(node).to receive(:config).with(update_cmd)
126
+ expect(subject.update_entry('test2', update_entry)).to be_truthy
127
+ end
128
+ end
129
+
130
+ describe '#add_entry' do
131
+ let(:new_entry) do
132
+ { seqno: '90', action: 'deny', srcaddr: '1.2.3.0',
133
+ srcprefixlen: '255.255.255.0', log: nil }
134
+ end
135
+
136
+ let(:new_cmd) do
137
+ ['ip access-list standard test2', '90 deny 1.2.3.0/255.255.255.0',
138
+ 'exit']
139
+ end
140
+
141
+ it 'Add entry 90 to the test2 ACL' do
142
+ expect(subject.get('test2')['90']).to be_falsy
143
+ expect(node).to receive(:config).with(new_cmd)
144
+ expect(subject.add_entry('test2', new_entry)).to be_truthy
145
+ end
146
+ end
147
+
148
+ describe '#remove_entry' do
149
+ let(:delete_cmd) do
150
+ ['ip access-list standard test2', 'no 30', 'exit']
151
+ end
152
+
153
+ it 'Remove entry 30 from the test2 ACL' do
154
+ expect(node).to receive(:config).with(delete_cmd)
155
+ expect(subject.remove_entry('test2', '30')).to be_truthy
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,22 @@
1
+ ip access-list standard test1
2
+ no statistics per-entry
3
+ fragment-rules
4
+ 10 permit host 1.2.3.4 log
5
+ 20 permit 1.2.3.4 255.255.0.0 log
6
+ 30 deny any
7
+ 40 permit 5.6.7.0/24
8
+ 50 permit 16.0.0.0/8
9
+ 60 permit 9.10.11.0 255.255.255.0 log
10
+ !
11
+ ip access-list standard test2
12
+ no statistics per-entry
13
+ fragment-rules
14
+ 10 permit 100.1.1.0 255.255.0.0
15
+ 20 permit 100.2.1.0 255.255.0.0
16
+ 30 permit 100.3.1.0 255.255.0.0
17
+ 40 permit 100.4.1.0 255.255.0.0
18
+ 50 permit 100.5.1.0 255.255.0.0
19
+ 60 deny 100.6.1.0 255.255.0.0 log
20
+ 70 permit 11.12.13.14
21
+ 80 permit 15.16.17.18
22
+ !
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/api/interfaces'
4
+
5
+ include FixtureHelpers
6
+
7
+ describe Rbeapi::Api::BaseInterface do
8
+ subject { described_class.new(node) }
9
+
10
+ let(:node) { double('node') }
11
+
12
+ def interfaces
13
+ interfaces = Fixtures[:interfaces]
14
+ return interfaces if interfaces
15
+ fixture('interfaces', format: :text, dir: File.dirname(__FILE__))
16
+ end
17
+
18
+ before :each do
19
+ allow(subject.node).to receive(:running_config).and_return(interfaces)
20
+ end
21
+
22
+ describe '#get' do
23
+ let(:resource) { subject.get('Loopback0') }
24
+
25
+ let(:keys) do
26
+ [:type, :shutdown, :description, :name]
27
+ end
28
+
29
+ it 'returns an ethernet resource as a hash' do
30
+ expect(resource).to be_a_kind_of(Hash)
31
+ end
32
+
33
+ it 'returns an interface type of generic' do
34
+ expect(resource[:type]).to eq('generic')
35
+ end
36
+
37
+ it 'has all keys' do
38
+ expect(resource.keys).to match_array(keys)
39
+ end
40
+ end
41
+
42
+ describe '#create' do
43
+ it 'creates the interface in the config' do
44
+ expect(node).to receive(:config).with('interface Loopback0')
45
+ expect(subject.create('Loopback0')).to be_truthy
46
+ end
47
+ end
48
+
49
+ describe '#delete' do
50
+ it 'deletes the interface in the config' do
51
+ expect(node).to receive(:config).with('no interface Loopback0')
52
+ expect(subject.delete('Loopback0')).to be_truthy
53
+ end
54
+ end
55
+
56
+ describe '#default' do
57
+ it 'defaults the interface config' do
58
+ expect(node).to receive(:config).with('default interface Loopback0')
59
+ expect(subject.default('Loopback0')).to be_truthy
60
+ end
61
+ end
62
+
63
+ describe '#set_description' do
64
+ it 'sets the interface description' do
65
+ expect(node).to receive(:config).with(['interface Loopback0',
66
+ 'description test string'])
67
+ expect(subject.set_description('Loopback0', value: 'test string'))
68
+ .to be_truthy
69
+ end
70
+
71
+ it 'negates the interface description' do
72
+ expect(node).to receive(:config).with(['interface Loopback0',
73
+ 'no description'])
74
+ expect(subject.set_description('Loopback0')).to be_truthy
75
+ end
76
+
77
+ it 'defaults the interface description' do
78
+ expect(node).to receive(:config).with(['interface Loopback0',
79
+ 'default description'])
80
+ expect(subject.set_description('Loopback0', default: true)).to be_truthy
81
+ end
82
+
83
+ it 'default is preferred over value' do
84
+ expect(node).to receive(:config).with(['interface Loopback0',
85
+ 'default description'])
86
+ expect(subject.set_description('Loopback0', value: 'test',
87
+ default: true)).to be_truthy
88
+ end
89
+ end
90
+
91
+ describe '#set_shutdown' do
92
+ it 'enables the interface' do
93
+ expect(node).to receive(:config).with(['interface Loopback0',
94
+ 'no shutdown'])
95
+ expect(subject.set_shutdown('Loopback0', value: false)).to be_truthy
96
+ end
97
+
98
+ it 'disables the interface' do
99
+ expect(node).to receive(:config).with(['interface Loopback0',
100
+ 'shutdown'])
101
+ expect(subject.set_shutdown('Loopback0', value: true)).to be_truthy
102
+ end
103
+
104
+ it 'negates the interface description' do
105
+ expect(node).to receive(:config).with(['interface Loopback0',
106
+ 'no shutdown'])
107
+ expect(subject.set_shutdown('Loopback0')).to be_truthy
108
+ end
109
+
110
+ it 'defaults the interface state' do
111
+ expect(node).to receive(:config).with(['interface Loopback0',
112
+ 'default shutdown'])
113
+ expect(subject.set_shutdown('Loopback0', default: true)).to be_truthy
114
+ end
115
+
116
+ it 'default is preferred over value' do
117
+ expect(node).to receive(:config).with(['interface Loopback0',
118
+ 'default shutdown'])
119
+ expect(subject.set_shutdown('Loopback0', value: 'test',
120
+ default: true)).to be_truthy
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/api/interfaces'
4
+
5
+ include FixtureHelpers
6
+
7
+ describe Rbeapi::Api::EthernetInterface do
8
+ subject { described_class.new(node) }
9
+
10
+ let(:node) { double('node') }
11
+
12
+ def interfaces
13
+ interfaces = Fixtures[:interfaces]
14
+ return interfaces if interfaces
15
+ fixture('interfaces', format: :text, dir: File.dirname(__FILE__))
16
+ end
17
+
18
+ before :each do
19
+ allow(subject.node).to receive(:running_config).and_return(interfaces)
20
+ end
21
+
22
+ describe '#get' do
23
+ let(:resource) { subject.get('Ethernet1') }
24
+
25
+ let(:keys) do
26
+ [:type, :speed, :sflow, :flowcontrol_send, :flowcontrol_receive,
27
+ :forced, :shutdown, :description, :name]
28
+ end
29
+
30
+ it 'returns an ethernet resource as a hash' do
31
+ expect(resource).to be_a_kind_of(Hash)
32
+ end
33
+
34
+ it 'returns an interface type of ethernet' do
35
+ expect(resource[:type]).to eq('ethernet')
36
+ end
37
+
38
+ it 'has all keys' do
39
+ expect(resource.keys).to match_array(keys)
40
+ end
41
+ end
42
+
43
+ describe '#create' do
44
+ it 'raises a NotImplementedError on create' do
45
+ expect { subject.create('Ethernet1') }.to raise_error(NotImplementedError)
46
+ end
47
+ end
48
+
49
+ describe '#delete' do
50
+ it 'raises a NotImplementedError on delete' do
51
+ expect { subject.delete('Ethernet1') }.to raise_error(NotImplementedError)
52
+ end
53
+ end
54
+
55
+ describe '#default' do
56
+ it 'defaults the interface config' do
57
+ expect(node).to receive(:config).with('default interface Ethernet1')
58
+ expect(subject.default('Ethernet1')).to be_truthy
59
+ end
60
+ end
61
+
62
+ describe '#set_description' do
63
+ it 'sets the interface description' do
64
+ expect(node).to receive(:config).with(['interface Ethernet1',
65
+ 'description test string'])
66
+ expect(subject.set_description('Ethernet1', value: 'test string'))
67
+ .to be_truthy
68
+ end
69
+
70
+ it 'negates the interface description' do
71
+ expect(node).to receive(:config).with(['interface Ethernet1',
72
+ 'no description'])
73
+ expect(subject.set_description('Ethernet1')).to be_truthy
74
+ end
75
+
76
+ it 'defaults the interface description' do
77
+ expect(node).to receive(:config).with(['interface Ethernet1',
78
+ 'default description'])
79
+ expect(subject.set_description('Ethernet1', default: true)).to be_truthy
80
+ end
81
+
82
+ it 'default is preferred over value' do
83
+ expect(node).to receive(:config).with(['interface Ethernet1',
84
+ 'default description'])
85
+ expect(subject.set_description('Ethernet1', value: 'test',
86
+ default: true)).to be_truthy
87
+ end
88
+ end
89
+ end