rbeapi 0.2.0 → 0.3.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/.gitignore +1 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +4 -0
  4. data/README.md +9 -9
  5. data/Rakefile +20 -0
  6. data/lib/rbeapi/api/bgp.rb +770 -0
  7. data/lib/rbeapi/api/dns.rb +32 -31
  8. data/lib/rbeapi/api/interfaces.rb +106 -87
  9. data/lib/rbeapi/api/ipinterfaces.rb +27 -42
  10. data/lib/rbeapi/api/logging.rb +9 -19
  11. data/lib/rbeapi/api/mlag.rb +60 -90
  12. data/lib/rbeapi/api/ntp.rb +12 -17
  13. data/lib/rbeapi/api/ospf.rb +9 -26
  14. data/lib/rbeapi/api/radius.rb +29 -43
  15. data/lib/rbeapi/api/snmp.rb +54 -83
  16. data/lib/rbeapi/api/staticroutes.rb +68 -21
  17. data/lib/rbeapi/api/stp.rb +41 -49
  18. data/lib/rbeapi/api/switchports.rb +41 -68
  19. data/lib/rbeapi/api/system.rb +6 -12
  20. data/lib/rbeapi/api/tacacs.rb +12 -21
  21. data/lib/rbeapi/api/varp.rb +25 -26
  22. data/lib/rbeapi/api/vlans.rb +19 -28
  23. data/lib/rbeapi/api.rb +30 -21
  24. data/lib/rbeapi/client.rb +3 -1
  25. data/lib/rbeapi/version.rb +1 -1
  26. data/rbeapi.spec.tmpl +4 -0
  27. data/spec/spec_helper.rb +8 -0
  28. data/spec/system/api_ospf_interfaces_spec.rb +16 -0
  29. data/spec/system/api_ospf_spec.rb +14 -0
  30. data/spec/system/api_varp_interfaces_spec.rb +16 -0
  31. data/spec/system/rbeapi/api/dns_spec.rb +66 -0
  32. data/spec/system/rbeapi/api/interfaces_base_spec.rb +4 -4
  33. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +6 -6
  34. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +6 -6
  35. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +4 -4
  36. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +44 -0
  37. data/spec/system/rbeapi/api/logging_spec.rb +18 -2
  38. data/spec/system/rbeapi/api/mlag_spec.rb +94 -2
  39. data/spec/system/rbeapi/api/ntp_spec.rb +14 -0
  40. data/spec/system/rbeapi/api/snmp_spec.rb +105 -0
  41. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +43 -6
  42. data/spec/system/rbeapi/api/stp_spec.rb +18 -6
  43. data/spec/system/rbeapi/api/switchports_spec.rb +75 -3
  44. data/spec/system/rbeapi/api/system_spec.rb +16 -0
  45. data/spec/system/rbeapi/api/vlans_spec.rb +28 -0
  46. data/spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb +289 -0
  47. data/spec/unit/rbeapi/api/bgp/bgp_spec.rb +192 -0
  48. data/spec/unit/rbeapi/api/bgp/fixture_bgp.text +101 -0
  49. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +7 -13
  50. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +3 -3
  51. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +11 -16
  52. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +15 -21
  53. data/spec/unit/rbeapi/api/mlag/default_spec.rb +13 -19
  54. data/spec/unit/rbeapi/api/staticroutes/default_spec.rb +138 -0
  55. data/spec/unit/rbeapi/api/staticroutes/fixture_staticroutes.text +5 -0
  56. data/spec/unit/rbeapi/api/vlans/default_spec.rb +4 -4
  57. metadata +15 -4
@@ -34,6 +34,20 @@ describe Rbeapi::Api::Mlag do
34
34
  expect(subject.set_domain_id(value: 'foo')).to be_truthy
35
35
  expect(subject.get[:global][:domain_id]).to eq('foo')
36
36
  end
37
+
38
+ it 'negates the mlag domain_id' do
39
+ expect(subject.set_domain_id(value: 'foo')).to be_truthy
40
+ expect(subject.get[:global][:domain_id]).to eq('foo')
41
+ expect(subject.set_domain_id(enable: false)).to be_truthy
42
+ expect(subject.get[:global][:domain_id]).to be_empty
43
+ end
44
+
45
+ it 'defaults the mlag domain_id' do
46
+ expect(subject.set_domain_id(value: 'foo')).to be_truthy
47
+ expect(subject.get[:global][:domain_id]).to eq('foo')
48
+ expect(subject.set_domain_id(default: true)).to be_truthy
49
+ expect(subject.get[:global][:domain_id]).to be_empty
50
+ end
37
51
  end
38
52
 
39
53
  describe '#set_local_interface' do
@@ -44,6 +58,20 @@ describe Rbeapi::Api::Mlag do
44
58
  expect(subject.set_local_interface(value: 'Vlan4094')).to be_truthy
45
59
  expect(subject.get[:global][:local_interface]).to eq('Vlan4094')
46
60
  end
61
+
62
+ it 'negates the local interface' do
63
+ expect(subject.set_local_interface(value: 'Vlan4094')).to be_truthy
64
+ expect(subject.get[:global][:local_interface]).to eq('Vlan4094')
65
+ expect(subject.set_local_interface(enable: false)).to be_truthy
66
+ expect(subject.get[:global][:local_interface]).to be_empty
67
+ end
68
+
69
+ it 'defaults the local interface' do
70
+ expect(subject.set_local_interface(value: 'Vlan4094')).to be_truthy
71
+ expect(subject.get[:global][:local_interface]).to eq('Vlan4094')
72
+ expect(subject.set_local_interface(default: true)).to be_truthy
73
+ expect(subject.get[:global][:local_interface]).to be_empty
74
+ end
47
75
  end
48
76
 
49
77
  describe '#set_peer_link' do
@@ -57,6 +85,20 @@ describe Rbeapi::Api::Mlag do
57
85
  expect(subject.set_peer_link(value: 'Ethernet1')).to be_truthy
58
86
  expect(subject.get[:global][:peer_link]).to eq('Ethernet1')
59
87
  end
88
+
89
+ it 'negates the mlag peer link' do
90
+ expect(subject.set_peer_link(value: 'Ethernet1')).to be_truthy
91
+ expect(subject.get[:global][:peer_link]).to eq('Ethernet1')
92
+ expect(subject.set_peer_link(enable: false)).to be_truthy
93
+ expect(subject.get[:global][:peer_link]).to be_empty
94
+ end
95
+
96
+ it 'defaults the mlag peer link' do
97
+ expect(subject.set_peer_link(value: 'Ethernet1')).to be_truthy
98
+ expect(subject.get[:global][:peer_link]).to eq('Ethernet1')
99
+ expect(subject.set_peer_link(default: true)).to be_truthy
100
+ expect(subject.get[:global][:peer_link]).to be_empty
101
+ end
60
102
  end
61
103
 
62
104
  describe '#set_peer_address' do
@@ -70,21 +112,71 @@ describe Rbeapi::Api::Mlag do
70
112
  expect(subject.set_peer_address(value: '1.1.1.1')).to be_truthy
71
113
  expect(subject.get[:global][:peer_address]).to eq('1.1.1.1')
72
114
  end
115
+
116
+ it 'negates the mlag peer address' do
117
+ expect(subject.set_peer_address(value: '1.1.1.1')).to be_truthy
118
+ expect(subject.get[:global][:peer_address]).to eq('1.1.1.1')
119
+ expect(subject.set_peer_address(enable: false)).to be_truthy
120
+ expect(subject.get[:global][:peer_address]).to be_empty
121
+ end
122
+
123
+ it 'defaults the mlag peer address' do
124
+ expect(subject.set_peer_address(value: '1.1.1.1')).to be_truthy
125
+ expect(subject.get[:global][:peer_address]).to eq('1.1.1.1')
126
+ expect(subject.set_peer_address(default: true)).to be_truthy
127
+ expect(subject.get[:global][:peer_address]).to be_empty
128
+ end
73
129
  end
74
130
 
75
131
  describe '#set_shutdown' do
76
132
  it 'configures mlag to be enabled' do
77
133
  node.config(['mlag configuration', 'shutdown'])
78
134
  expect(subject.get[:global][:shutdown]).to be_truthy
79
- expect(subject.set_shutdown(value: false)).to be_truthy
135
+ expect(subject.set_shutdown(enable: true)).to be_truthy
80
136
  expect(subject.get[:global][:shutdown]).to be_falsy
81
137
  end
82
138
 
83
139
  it 'configures mlag to be disabled' do
84
140
  node.config(['mlag configuration', 'no shutdown'])
85
141
  expect(subject.get[:global][:shutdown]).to be_falsy
86
- expect(subject.set_shutdown(value: true)).to be_truthy
142
+ expect(subject.set_shutdown(enable: false)).to be_truthy
87
143
  expect(subject.get[:global][:shutdown]).to be_truthy
88
144
  end
145
+
146
+ it 'defaults the shutdown value' do
147
+ expect(node).to receive(:config).with(['mlag configuration',
148
+ 'default shutdown'])
149
+ expect(subject.set_shutdown(default: true)).to be_truthy
150
+ end
151
+ end
152
+
153
+ describe '#set_mlag_id' do
154
+ before do
155
+ node.config(['default mlag configuration',
156
+ 'default interface Ethernet1',
157
+ 'default interface Port-Channel20',
158
+ 'interface Ethernet1',
159
+ 'channel-group 20 mode active',
160
+ 'interface port-channel 20',
161
+ 'mlag 20'])
162
+ end
163
+
164
+ it 'configure the mlag id' do
165
+ expect(subject.get[:interfaces]['Port-Channel20'][:mlag_id]).to eq(20)
166
+ expect(subject.set_mlag_id('Port-Channel20', value: '1000')).to be_truthy
167
+ expect(subject.get[:interfaces]['Port-Channel20'][:mlag_id]).to eq(1000)
168
+ end
169
+
170
+ it 'negate the mlag id' do
171
+ expect(subject.get[:interfaces]['Port-Channel20'][:mlag_id]).to eq(20)
172
+ expect(subject.set_mlag_id('Port-Channel20', enable: false)).to be_truthy
173
+ expect(subject.get[:interfaces]['Port-Channel20']).to eq(nil)
174
+ end
175
+
176
+ it 'default the mlag id' do
177
+ expect(subject.get[:interfaces]['Port-Channel20'][:mlag_id]).to eq(20)
178
+ expect(subject.set_mlag_id('Port-Channel20', default: true)).to be_truthy
179
+ expect(subject.get[:interfaces]['Port-Channel20']).to eq(nil)
180
+ end
89
181
  end
90
182
  end
@@ -35,6 +35,20 @@ describe Rbeapi::Api::Ntp do
35
35
  expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
36
36
  expect(subject.get[:source_interface]).to eq('Loopback0')
37
37
  end
38
+
39
+ it 'negates the ntp source interface' do
40
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
41
+ expect(subject.get[:source_interface]).to eq('Loopback0')
42
+ expect(subject.set_source_interface(enable: false)).to be_truthy
43
+ expect(subject.get[:source_interface]).to be_empty
44
+ end
45
+
46
+ it 'defaults the ntp source interface' do
47
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
48
+ expect(subject.get[:source_interface]).to eq('Loopback0')
49
+ expect(subject.set_source_interface(default: true)).to be_truthy
50
+ expect(subject.get[:source_interface]).to be_empty
51
+ end
38
52
  end
39
53
 
40
54
  describe '#add_server' do
@@ -31,6 +31,20 @@ describe Rbeapi::Api::Snmp do
31
31
  expect(subject.set_location(value: 'foo')).to be_truthy
32
32
  expect(subject.get[:location]).to eq('foo')
33
33
  end
34
+
35
+ it 'negates the snmp location' do
36
+ expect(subject.set_location(value: 'foo')).to be_truthy
37
+ expect(subject.get[:location]).to eq('foo')
38
+ expect(subject.set_location(enable: false)).to be_truthy
39
+ expect(subject.get[:location]).to be_empty
40
+ end
41
+
42
+ it 'defaults the snmp location' do
43
+ expect(subject.set_location(value: 'foo')).to be_truthy
44
+ expect(subject.get[:location]).to eq('foo')
45
+ expect(subject.set_location(default: true)).to be_truthy
46
+ expect(subject.get[:location]).to be_empty
47
+ end
34
48
  end
35
49
 
36
50
  describe '#set_contact' do
@@ -41,6 +55,20 @@ describe Rbeapi::Api::Snmp do
41
55
  expect(subject.set_contact(value: 'foo')).to be_truthy
42
56
  expect(subject.get[:contact]).to eq('foo')
43
57
  end
58
+
59
+ it 'negates the snmp contact' do
60
+ expect(subject.set_contact(value: 'foo')).to be_truthy
61
+ expect(subject.get[:contact]).to eq('foo')
62
+ expect(subject.set_contact(enable: false)).to be_truthy
63
+ expect(subject.get[:contact]).to be_empty
64
+ end
65
+
66
+ it 'defaults the snmp contact' do
67
+ expect(subject.set_contact(value: 'foo')).to be_truthy
68
+ expect(subject.get[:contact]).to eq('foo')
69
+ expect(subject.set_contact(default: true)).to be_truthy
70
+ expect(subject.get[:contact]).to be_empty
71
+ end
44
72
  end
45
73
 
46
74
  describe '#set_chassis_id' do
@@ -51,6 +79,20 @@ describe Rbeapi::Api::Snmp do
51
79
  expect(subject.set_chassis_id(value: 'foo')).to be_truthy
52
80
  expect(subject.get[:chassis_id]).to eq('foo')
53
81
  end
82
+
83
+ it 'negates the chassis id' do
84
+ expect(subject.set_chassis_id(value: 'foo')).to be_truthy
85
+ expect(subject.get[:chassis_id]).to eq('foo')
86
+ expect(subject.set_chassis_id(enable: false)).to be_truthy
87
+ expect(subject.get[:chassis_id]).to be_empty
88
+ end
89
+
90
+ it 'defaults the chassis id' do
91
+ expect(subject.set_chassis_id(value: 'foo')).to be_truthy
92
+ expect(subject.get[:chassis_id]).to eq('foo')
93
+ expect(subject.set_chassis_id(default: true)).to be_truthy
94
+ expect(subject.get[:chassis_id]).to be_empty
95
+ end
54
96
  end
55
97
 
56
98
  describe '#set_source_interface' do
@@ -61,5 +103,68 @@ describe Rbeapi::Api::Snmp do
61
103
  expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
62
104
  expect(subject.get[:source_interface]).to eq('Loopback0')
63
105
  end
106
+
107
+ it 'negates the snmp source-interface' do
108
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
109
+ expect(subject.get[:source_interface]).to eq('Loopback0')
110
+ expect(subject.set_source_interface(enable: false)).to be_truthy
111
+ expect(subject.get[:source_interface]).to be_empty
112
+ end
113
+
114
+ it 'defaults the snmp source-interface' do
115
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
116
+ expect(subject.get[:source_interface]).to eq('Loopback0')
117
+ expect(subject.set_source_interface(default: true)).to be_truthy
118
+ expect(subject.get[:source_interface]).to be_empty
119
+ end
120
+ end
121
+
122
+ describe '#set_community_acl' do
123
+ before do
124
+ node.config(['no snmp-server community foo',
125
+ 'no snmp-server community bar'])
126
+ end
127
+
128
+ it 'configures nil acl for snmp community foo and bar' do
129
+ expect(subject.get[:communities]).to be_empty
130
+ expect(subject.set_community_acl('foo')).to be_truthy
131
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: nil)
132
+ expect(subject.set_community_acl('bar')).to be_truthy
133
+ expect(subject.get[:communities]['bar']).to eq(access: 'ro', acl: nil)
134
+ end
135
+
136
+ it 'configures IPv4 acl for snmp community foo and bar' do
137
+ expect(subject.get[:communities]).to be_empty
138
+ expect(subject.set_community_acl('foo', value: 'eng')).to be_truthy
139
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: 'eng')
140
+ expect(subject.set_community_acl('bar', value: 'eng')).to be_truthy
141
+ expect(subject.get[:communities]['bar']).to eq(access: 'ro', acl: 'eng')
142
+ end
143
+
144
+ it 'negates the snmp community ACL for bar' do
145
+ expect(subject.get[:communities]).to be_empty
146
+ expect(subject.set_community_acl('foo', value: 'eng')).to be_truthy
147
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: 'eng')
148
+ expect(subject.set_community_acl('bar', value: 'eng')).to be_truthy
149
+ expect(subject.get[:communities]['bar']).to eq(access: 'ro', acl: 'eng')
150
+ # Remove bar
151
+ expect(subject.set_community_acl('bar', enable: false)).to be_truthy
152
+ expect(subject.get[:communities]['bar']).to be_falsy
153
+ # Make sure foo is still there
154
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: 'eng')
155
+ end
156
+
157
+ it 'defaults the snmp community ACL for bar' do
158
+ expect(subject.get[:communities]).to be_empty
159
+ expect(subject.set_community_acl('foo', value: 'eng')).to be_truthy
160
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: 'eng')
161
+ expect(subject.set_community_acl('bar', value: 'eng')).to be_truthy
162
+ expect(subject.get[:communities]['bar']).to eq(access: 'ro', acl: 'eng')
163
+ # Default bar
164
+ expect(subject.set_community_acl('bar', default: true)).to be_truthy
165
+ expect(subject.get[:communities]['bar']).to be_falsy
166
+ # Make sure foo is still there
167
+ expect(subject.get[:communities]['foo']).to eq(access: 'ro', acl: 'eng')
168
+ end
64
169
  end
65
170
  end
@@ -36,33 +36,70 @@ describe Rbeapi::Api::StpInterfaces do
36
36
  end
37
37
 
38
38
  describe '#set_portfast' do
39
- it 'sets the portfast value to true' do
39
+ it 'enables portfast' do
40
40
  node.config(['interface Ethernet1', 'no spanning-tree portfast'])
41
41
  expect(subject.get('Ethernet1')[:portfast]).to be_falsy
42
- expect(subject.set_portfast('Ethernet1', value: true)).to be_truthy
42
+ expect(subject.set_portfast('Ethernet1', enable: true)).to be_truthy
43
43
  expect(subject.get('Ethernet1')[:portfast]).to be_truthy
44
44
  end
45
45
 
46
- it 'sets the portfast value to false' do
46
+ it 'disable portfast' do
47
47
  node.config(['interface Ethernet1', 'spanning-tree portfast'])
48
48
  expect(subject.get('Ethernet1')[:portfast]).to be_truthy
49
- expect(subject.set_portfast('Ethernet1', value: false)).to be_truthy
49
+ expect(subject.set_portfast('Ethernet1', enable: false)).to be_truthy
50
50
  expect(subject.get('Ethernet1')[:portfast]).to be_falsy
51
51
  end
52
+
53
+ it 'sets portfast to default value' do
54
+ node.config(['interface Ethernet1', 'spanning-tree portfast'])
55
+ expect(subject.get('Ethernet1')[:portfast]).to be_truthy
56
+ expect(subject.set_portfast('Ethernet1', default: true)).to be_truthy
57
+ expect(subject.get('Ethernet1')[:portfast]).to be_falsy
58
+ end
59
+ end
60
+
61
+ describe '#set_portfast_type' do
62
+ it 'raises an ArgumentError if value is not set' do
63
+ expect { subject.set_portfast_type('Ethernet1') }
64
+ .to raise_error(ArgumentError)
65
+ end
66
+
67
+ it 'enables portfast type' do
68
+ node.config(['interface Ethernet1', 'no spanning-tree portfast'])
69
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('normal')
70
+ expect(subject.set_portfast_type('Ethernet1', value: 'edge')).to be_truthy
71
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('edge')
72
+ end
73
+
74
+ it 'disable portfast' do
75
+ node.config(['interface Ethernet1', 'spanning-tree portfast edge'])
76
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('edge')
77
+ expect(subject.set_portfast_type('Ethernet1', value: 'edge',
78
+ enable: false)).to be_truthy
79
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('normal')
80
+ end
81
+
82
+ it 'sets portfast to default value' do
83
+ node.config(['interface Ethernet1', 'spanning-tree portfast network'])
84
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('network')
85
+ expect(subject.set_portfast_type('Ethernet1', value: 'network',
86
+ default: true)).to be_truthy
87
+ expect(subject.get('Ethernet1')[:portfast_type]).to eq('normal')
88
+ end
52
89
  end
53
90
 
54
91
  describe '#set_bpduguard' do
55
92
  it 'sets the bpduguard value to true' do
56
93
  node.config(['interface Ethernet1', 'no spanning-tree bpduguard'])
57
94
  expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
58
- expect(subject.set_bpduguard('Ethernet1', value: true)).to be_truthy
95
+ expect(subject.set_bpduguard('Ethernet1', enable: true)).to be_truthy
59
96
  expect(subject.get('Ethernet1')[:bpduguard]).to be_truthy
60
97
  end
61
98
 
62
99
  it 'sets the bpduguard value to false' do
63
100
  node.config(['interface Ethernet1', 'spanning-tree bpduguard enable'])
64
101
  expect(subject.get('Ethernet1')[:bpduguard]).to be_truthy
65
- expect(subject.set_bpduguard('Ethernet1', value: false)).to be_truthy
102
+ expect(subject.set_bpduguard('Ethernet1', enable: false)).to be_truthy
66
103
  expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
67
104
  end
68
105
  end
@@ -46,12 +46,24 @@ describe Rbeapi::Api::Stp do
46
46
  end
47
47
 
48
48
  it 'sets the stp mode to none' do
49
- node.config('spanning-tree mode mstp') do
50
- node.config('spanning-tree mode mstp')
51
- expect(subject.get[:mode]).to eq('mstp')
52
- expect(subject.set_mode(value: 'none')).to be_truthy
53
- expect(subject.get[:mode]).to eq('none')
54
- end
49
+ node.config('spanning-tree mode mstp')
50
+ expect(subject.get[:mode]).to eq('mstp')
51
+ expect(subject.set_mode(value: 'none')).to be_truthy
52
+ expect(subject.get[:mode]).to eq('none')
53
+ end
54
+
55
+ it 'negates the stp mode' do
56
+ node.config('spanning-tree mode none')
57
+ expect(subject.get[:mode]).to eq('none')
58
+ expect(subject.set_mode(enable: false)).to be_truthy
59
+ expect(subject.get[:mode]).to eq('mstp')
60
+ end
61
+
62
+ it 'defaults the stp mode' do
63
+ node.config('spanning-tree mode none')
64
+ expect(subject.get[:mode]).to eq('none')
65
+ expect(subject.set_mode(default: true)).to be_truthy
66
+ expect(subject.get[:mode]).to eq('mstp')
55
67
  end
56
68
  end
57
69
  end
@@ -95,6 +95,20 @@ describe Rbeapi::Api::Switchports do
95
95
  expect(subject.set_mode('Ethernet1', value: 'trunk')).to be_truthy
96
96
  expect(subject.get('Ethernet1')[:mode]).to eq('trunk')
97
97
  end
98
+
99
+ it 'negate the mode value' do
100
+ node.config(['interface Ethernet1', 'switchport mode trunk'])
101
+ expect(subject.get('Ethernet1')[:mode]).to eq('trunk')
102
+ expect(subject.set_mode('Ethernet1', enable: false)).to be_truthy
103
+ expect(subject.get('Ethernet1')[:mode]).to eq('access')
104
+ end
105
+
106
+ it 'default the mode value' do
107
+ node.config(['interface Ethernet1', 'switchport mode trunk'])
108
+ expect(subject.get('Ethernet1')[:mode]).to eq('trunk')
109
+ expect(subject.set_mode('Ethernet1', default: true)).to be_truthy
110
+ expect(subject.get('Ethernet1')[:mode]).to eq('access')
111
+ end
98
112
  end
99
113
 
100
114
  describe '#set_access_vlan' do
@@ -105,6 +119,22 @@ describe Rbeapi::Api::Switchports do
105
119
  expect(subject.set_access_vlan('Ethernet1', value: '100')).to be_truthy
106
120
  expect(subject.get('Ethernet1')[:access_vlan]).to eq('100')
107
121
  end
122
+
123
+ it 'negates the access vlan value' do
124
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('1')
125
+ expect(subject.set_access_vlan('Ethernet1', value: '100')).to be_truthy
126
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('100')
127
+ expect(subject.set_access_vlan('Ethernet1', enable: false)).to be_truthy
128
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('1')
129
+ end
130
+
131
+ it 'defaults the access vlan value' do
132
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('1')
133
+ expect(subject.set_access_vlan('Ethernet1', value: '100')).to be_truthy
134
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('100')
135
+ expect(subject.set_access_vlan('Ethernet1', default: true)).to be_truthy
136
+ expect(subject.get('Ethernet1')[:access_vlan]).to eq('1')
137
+ end
108
138
  end
109
139
 
110
140
  describe '#set_trunk_native_vlan' do
@@ -116,6 +146,26 @@ describe Rbeapi::Api::Switchports do
116
146
  .to be_truthy
117
147
  expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('100')
118
148
  end
149
+
150
+ it 'negates the trunk native vlan' do
151
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('1')
152
+ expect(subject.set_trunk_native_vlan('Ethernet1', value: '100'))
153
+ .to be_truthy
154
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('100')
155
+ expect(subject.set_trunk_native_vlan('Ethernet1', enable: false))
156
+ .to be_truthy
157
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('1')
158
+ end
159
+
160
+ it 'defaults the trunk native vlan' do
161
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('1')
162
+ expect(subject.set_trunk_native_vlan('Ethernet1', value: '100'))
163
+ .to be_truthy
164
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('100')
165
+ expect(subject.set_trunk_native_vlan('Ethernet1', default: true))
166
+ .to be_truthy
167
+ expect(subject.get('Ethernet1')[:trunk_native_vlan]).to eq('1')
168
+ end
119
169
  end
120
170
 
121
171
  describe '#set_trunk_allowed_vlans' do
@@ -126,12 +176,34 @@ describe Rbeapi::Api::Switchports do
126
176
  .to raise_error(ArgumentError)
127
177
  end
128
178
 
129
- it 'sets vlan 100 to the trunk allowed vlans' do
179
+ it 'sets vlan 8 and 9 to the trunk allowed vlans' do
130
180
  node.config(['interface Ethernet1', 'switchport trunk allowed vlan none'])
131
181
  expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to be_empty
132
- expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [100]))
182
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [8, 9]))
183
+ .to be_truthy
184
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to eq([8, 9])
185
+ end
186
+
187
+ it 'negate switchport trunk allowed vlan' do
188
+ node.config(['interface Ethernet1', 'switchport trunk allowed vlan none'])
189
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to be_empty
190
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [8, 9]))
191
+ .to be_truthy
192
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to eq([8, 9])
193
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', enable: false))
194
+ .to be_truthy
195
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans].length).to eq(4094)
196
+ end
197
+
198
+ it 'default switchport trunk allowed vlan' do
199
+ node.config(['interface Ethernet1', 'switchport trunk allowed vlan none'])
200
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to be_empty
201
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', value: [8, 9]))
202
+ .to be_truthy
203
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to eq([8, 9])
204
+ expect(subject.set_trunk_allowed_vlans('Ethernet1', default: true))
133
205
  .to be_truthy
134
- expect(subject.get('Ethernet1')[:trunk_allowed_vlans]).to include(100)
206
+ expect(subject.get('Ethernet1')[:trunk_allowed_vlans].length).to eq(4094)
135
207
  end
136
208
  end
137
209
  end
@@ -31,5 +31,21 @@ describe Rbeapi::Api::System do
31
31
  expect(subject.set_hostname(value: 'foo')).to be_truthy
32
32
  expect(subject.get[:hostname]).to eq('foo')
33
33
  end
34
+
35
+ it 'configures the system hostname with a dot value' do
36
+ expect(subject.get[:hostname]).to eq('localhost')
37
+ expect(subject.set_hostname(value: 'foo.bar')).to be_truthy
38
+ expect(subject.get[:hostname]).to eq('foo.bar')
39
+ end
40
+
41
+ it 'negates the hostname' do
42
+ expect(subject.set_hostname(enable: false)).to be_truthy
43
+ expect(subject.get[:hostname]).to be_empty
44
+ end
45
+
46
+ it 'defaults the hostname' do
47
+ expect(subject.set_hostname(default: true)).to be_truthy
48
+ expect(subject.get[:hostname]).to be_empty
49
+ end
34
50
  end
35
51
  end
@@ -91,6 +91,20 @@ describe Rbeapi::Api::Vlans do
91
91
  expect(subject.set_name('1', value: 'foo')).to be_truthy
92
92
  expect(subject.get('1')[:name]).to eq('foo')
93
93
  end
94
+
95
+ it 'negates the vlan name' do
96
+ expect(subject.set_name('1', value: 'foo')).to be_truthy
97
+ expect(subject.get('1')[:name]).to eq('foo')
98
+ expect(subject.set_name('1', enable: false)).to be_truthy
99
+ expect(subject.get('1')[:name]).to eq('default')
100
+ end
101
+
102
+ it 'defaults the vlan name' do
103
+ expect(subject.set_name('1', value: 'foo')).to be_truthy
104
+ expect(subject.get('1')[:name]).to eq('foo')
105
+ expect(subject.set_name('1', default: true)).to be_truthy
106
+ expect(subject.get('1')[:name]).to eq('default')
107
+ end
94
108
  end
95
109
 
96
110
  describe '#set_state' do
@@ -107,6 +121,20 @@ describe Rbeapi::Api::Vlans do
107
121
  expect(subject.set_state('1', value: 'active')).to be_truthy
108
122
  expect(subject.get('1')[:state]).to eq('active')
109
123
  end
124
+
125
+ it 'negate vlan 1 state' do
126
+ node.config(['vlan 1', 'state suspend'])
127
+ expect(subject.get('1')[:state]).to eq('suspend')
128
+ expect(subject.set_state('1', enable: false)).to be_truthy
129
+ expect(subject.get('1')[:state]).to eq('active')
130
+ end
131
+
132
+ it 'set vlan 1 state to default' do
133
+ node.config(['vlan 1', 'state suspend'])
134
+ expect(subject.get('1')[:state]).to eq('suspend')
135
+ expect(subject.set_state('1', default: true)).to be_truthy
136
+ expect(subject.get('1')[:state]).to eq('active')
137
+ end
110
138
  end
111
139
 
112
140
  describe '#add_trunk_group' do