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,2 @@
1
+ ---
2
+ - output: "\nUser name : jeff\nSecurity model : v3\nEngine ID : f5717f00420008177800\nAuthentication : SHA\nPrivacy : AES-128\nGroup : developers\n\nUser name : nigel\nSecurity model : v2c\nGroup : sysops (not configured)\n\nUser name : nigel\nSecurity model : v3\nEngine ID : f5717f00420008177800\nAuthentication : SHA\nPrivacy : AES-128\nGroup : sysops\n"
@@ -0,0 +1 @@
1
+ --- "\nUser name : jeff\nSecurity model : v3\nEngine ID : f5717f00420008177800\nAuthentication : SHA\nPrivacy : AES-128\nGroup : developers\n\nUser name : nigel\nSecurity model : v2c\nGroup : sysops (not configured)\n\nUser name : nigel\nSecurity model : v3\nEngine ID : f5717f00420008177800\nAuthentication : SHA\nPrivacy : AES-128\nGroup : sysops\n"
@@ -0,0 +1,37 @@
1
+ {
2
+ "jsonrpc": "2.0",
3
+ "result": [
4
+ {
5
+ "sourceDetail": "",
6
+ "vlans": {
7
+ "1": {
8
+ "status": "active",
9
+ "name": "default",
10
+ "interfaces": {
11
+ "Ethernet2": {
12
+ "privatePromoted": false
13
+ },
14
+ "Ethernet3": {
15
+ "privatePromoted": false
16
+ },
17
+ "Ethernet1": {
18
+ "privatePromoted": false
19
+ },
20
+ "Ethernet4": {
21
+ "privatePromoted": false
22
+ }
23
+ },
24
+ "dynamic": false
25
+ },
26
+ "3110": {
27
+ "status": "active",
28
+ "name": "VLAN3110",
29
+ "interfaces": {
30
+ },
31
+ "dynamic": false
32
+ }
33
+ }
34
+ }
35
+ ],
36
+ "id": "db8d1ea6-9f28-43e1-a71f-cac3df16d985"
37
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "jsonrpc": "2.0",
3
+ "result": [
4
+ {
5
+ "sourceDetail": "",
6
+ "vlans": {
7
+ "3110": {
8
+ "status": "active",
9
+ "name": "VLAN3110",
10
+ "interfaces": {
11
+ },
12
+ "dynamic": false
13
+ }
14
+ }
15
+ }
16
+ ],
17
+ "id": "ddccdc56-5def-4eb7-81dd-0bce075e7954"
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "jsonrpc": "2.0",
3
+ "id": "27f0a14d-c3bc-4bdd-b4cc-cd00e6127f07",
4
+ "error": {
5
+ "data": [
6
+ {
7
+ "sourceDetail": "",
8
+ "errors": [
9
+ "VLAN 4000 not found in current VLAN database"
10
+ ],
11
+ "vlans": {
12
+ }
13
+ }
14
+ ],
15
+ "message": "CLI command 1 of 1 'show vlan 4000' failed: could not run command",
16
+ "code": 1000
17
+ }
18
+ }
@@ -0,0 +1,11 @@
1
+ ---
2
+ !ruby/sym name: "127.0.0.4:private:10162:v2:informs"
3
+ !ruby/sym ensure: !ruby/sym absent
4
+ !ruby/sym port: 10162
5
+ !ruby/sym version: !ruby/sym v2
6
+ !ruby/sym type: !ruby/sym informs
7
+ !ruby/sym community: private
8
+ !ruby/sym username:
9
+ !ruby/sym security:
10
+ !ruby/sym vrf:
11
+ !ruby/sym source_interface:
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ add_filter '/.bundle/'
7
+ end
8
+
9
+ require 'puppet_x_eos_eapi'
10
+
11
+ dir = File.expand_path(File.dirname(__FILE__))
12
+ Dir["#{dir}/support/**/*.rb"].sort.each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ config.include FixtureHelpers
16
+
17
+ # rspec configuration
18
+ config.mock_with :rspec do |rspec_config|
19
+ rspec_config.syntax = :expect
20
+ end
21
+ end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pathname'
4
+ require 'yaml'
5
+ require 'json'
6
+
7
+ ##
8
+ # Fixtures implements a global container to store fixture data loaded from the
9
+ # filesystem.
10
+ class Fixtures
11
+ def self.[](name)
12
+ @fixtures[name]
13
+ end
14
+
15
+ def self.[]=(name, value)
16
+ @fixtures[name] = value
17
+ end
18
+
19
+ def self.clear
20
+ @fixtures = {}
21
+ end
22
+
23
+ clear
24
+
25
+ ##
26
+ # save an object and saves it as a fixture in the filesystem.
27
+ #
28
+ # @param [Symbol] key The fixture name without the `fixture_` prefix or
29
+ # `.json` suffix.
30
+ #
31
+ # @param [Object] obj The object to serialize to JSON and write to the
32
+ # fixture file.
33
+ #
34
+ # @option opts [String] :dir ('/path/to/fixtures') The fixtures directory,
35
+ # defaults to the full path of spec/fixtures/ relative to the root of the
36
+ # module.
37
+ def self.save(key, obj, opts = {})
38
+ dir = opts[:dir] || File.expand_path('../../fixtures', __FILE__)
39
+ file = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
40
+ fail ArgumentError, "Error, file #{file} exists" if file.exist?
41
+ File.open(file, 'w+') { |f| f.puts YAML.dump(obj) }
42
+ end
43
+ end
44
+
45
+ ##
46
+ # FixtureHelpers provides instance methods for RSpec test cases that aid in the
47
+ # loading and caching of fixture data.
48
+ module FixtureHelpers
49
+ ##
50
+ # fixture loads a JSON fixture from the spec/fixtures/ directory, prefixed
51
+ # with fixture_. Given the name 'foo' the file
52
+ # `spec/fixtures/fixture_foo.json` will be loaded and returned. This method
53
+ # is memoized across the life of the process.
54
+ #
55
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength,
56
+ # rubocop:disable Metrics/PerceivedComplexity
57
+ #
58
+ # @param [Symbol] key The fixture name without the `fixture_` prefix or
59
+ # `.json` suffix.
60
+ #
61
+ # @option opts [String] :dir ('/path/to/fixtures') The fixtures directory,
62
+ # defaults to the full path of spec/fixtures/ relative to the root of the
63
+ # module.
64
+ #
65
+ # @option opts [String] :format (:ruby) The format to return the fixture in,
66
+ # defaults to native Ruby objects. :json will return a JSON string.
67
+ def fixture(key, opts = { format: :ruby })
68
+ if opts[:format] == :ruby
69
+ memo = Fixtures[key]
70
+ return memo if memo
71
+ end
72
+ dir = opts[:dir] || fixture_dir
73
+
74
+ yaml = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
75
+ json = Pathname.new(File.join(dir, "fixture_#{key}.json"))
76
+
77
+ data = if yaml.exist?; then YAML.load(File.read(yaml))
78
+ elsif json.exist?; then JSON.load(File.read(json))
79
+ else fail "could not load YAML or JSON fixture #{key} "\
80
+ "tried:\n #{yaml}\n #{json}"
81
+ end
82
+
83
+ Fixtures[key] = data
84
+
85
+ case opts[:format]
86
+ when :ruby then data
87
+ when :json then JSON.pretty_generate(data)
88
+ when :yaml then YAML.dump(data)
89
+ else fail ArgumentError, "unknown format #{opts[:format].inspect}"
90
+ end
91
+ end
92
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
93
+ # rubocop:enable Metrics/PerceivedComplexity
94
+
95
+ ##
96
+ # fixture_dir returns the full path to the fixture directory
97
+ #
98
+ # @api public
99
+ #
100
+ # @return [String] the full path to the fixture directory
101
+ def fixture_dir
102
+ File.expand_path('../../fixtures', __FILE__)
103
+ end
104
+ end
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+
3
+ describe PuppetX::Eos::Eapi do
4
+ let(:hostname) { 'localhost' }
5
+ let(:port) { 80 }
6
+ let(:username) { 'admin' }
7
+ let(:password) { 'puppet' }
8
+ let(:enable_pwd) { 'puppet' }
9
+ let(:config) do
10
+ {
11
+ hostname: hostname,
12
+ port: 80,
13
+ username: 'admin',
14
+ password: 'puppet'
15
+ }
16
+ end
17
+ let(:api) { PuppetX::Eos::Eapi.new(config) }
18
+
19
+ context 'when initializing a new EAPI instance' do
20
+ [:hostname, :port, :username, :password, :enable_pwd].each do |option|
21
+ it "initializes with #{option}" do
22
+ api = described_class.new(option => send(option))
23
+ expect(api.send(option)).to eq(send(option))
24
+ end
25
+ end
26
+
27
+ it 'defaults hostname to localhost' do
28
+ expect(subject.hostname).to eq('localhost')
29
+ end
30
+
31
+ it 'uses a non-ssl connnection' do
32
+ api = described_class.new(use_ssl: false)
33
+ expect(api.uri.to_s).to eq('http://localhost')
34
+ end
35
+
36
+ context 'when the command API unix domain socket exists' do
37
+ before :each do
38
+ fakepath = double(Pathname)
39
+ [:socket?, :readable?, :writable?].each do |method|
40
+ allow(fakepath).to receive(method).and_return(true)
41
+ end
42
+ expect(Pathname).to receive(:new).with('/var/run/command-api.sock')
43
+ .and_return(fakepath)
44
+ end
45
+
46
+ let(:default_instance_state) { described_class.new }
47
+
48
+ describe '#http' do
49
+ subject { default_instance_state.http }
50
+
51
+ it { is_expected.to be_a NetX::HTTPUnix }
52
+ it 'address is /var/run/command-api.sock' do
53
+ expect(subject.address).to eq '/var/run/command-api.sock'
54
+ end
55
+ it 'port is nil' do
56
+ expect(subject.port).to be_nil
57
+ end
58
+ end
59
+
60
+ describe '#socket' do
61
+ subject { default_instance_state.socket }
62
+ it { is_expected.to eq '/var/run/command-api.sock' }
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#uri' do
68
+ it 'returns a default uri string' do
69
+ expect(subject.uri.to_s).to eq('http://localhost')
70
+ end
71
+ end
72
+
73
+ describe '#http' do
74
+ it 'returns an instance of Net::HTTP' do
75
+ expect(subject.http).to be_a Net::HTTP
76
+ end
77
+ end
78
+
79
+ context '#request' do
80
+ subject { api.request(commands, format: format) }
81
+ let(:format) { 'json' }
82
+
83
+ describe 'request a single command' do
84
+ let(:commands) { 'foo' }
85
+
86
+ it 'returns a request object of len 1' do
87
+ expect(subject['params']['cmds']).to be_a Array
88
+ expect(subject['params']['cmds'].length).to eq 1
89
+ expect(subject).to be_a Hash
90
+ end
91
+ end
92
+
93
+ describe 'request a commands array' do
94
+ let(:commands) { %w(foo bar) }
95
+
96
+ it 'returns a request object hash of len 2' do
97
+ expect(subject['params']['cmds']).to be_a Array
98
+ expect(subject['params']['cmds'].length).to eq 2
99
+ expect(subject).to be_a Hash
100
+ end
101
+ end
102
+
103
+ describe 'request a commands array with text' do
104
+ let(:commands) { 'foo' }
105
+ let(:format) { 'text' }
106
+ it 'requets a reqest objct of format text' do
107
+ expect(subject['params']['format']).to eq 'text'
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#enable' do
113
+ context 'when sending a single command' do
114
+ subject { api.enable('foo') }
115
+
116
+ before do
117
+ allow(api).to receive(:execute)
118
+ .with(['foo'], {})
119
+ .and_return([{}])
120
+ end
121
+
122
+ it { is_expected.to be_a_kind_of Array }
123
+ end
124
+
125
+ context 'when sending a commands with format = "text"' do
126
+ subject { api.enable('foo', format: 'text') }
127
+
128
+ before do
129
+ allow(api).to receive(:execute)
130
+ .with(['foo'], format: 'text')
131
+ .and_return([{}])
132
+ end
133
+
134
+ it { is_expected.to be_a_kind_of Array }
135
+ end
136
+
137
+ context 'when sending an array of commands' do
138
+ subject { api.enable(%w(foo bar)) }
139
+
140
+ before do
141
+ allow(api).to receive(:execute)
142
+ .with(%w(foo bar), {})
143
+ .and_return([{}, {}])
144
+ end
145
+
146
+ it { is_expected.to be_a_kind_of Array }
147
+ end
148
+ end
149
+
150
+ describe '#config' do
151
+
152
+ context 'when sending a command' do
153
+ subject { api.config('foo') }
154
+
155
+ before do
156
+ allow(api).to receive(:enable)
157
+ .with(%w(configure foo))
158
+ .and_return([{}, {}])
159
+ end
160
+
161
+ it { is_expected.to be_a_kind_of Array }
162
+ end
163
+
164
+ context 'when sending an array of commands' do
165
+ subject { api.config(%w(foo bar)) }
166
+
167
+ before do
168
+ allow(api).to receive(:enable)
169
+ .with(%w(configure foo bar))
170
+ .and_return([{}, {}, {}])
171
+ end
172
+
173
+ it { is_expected.to be_a_kind_of Array }
174
+ end
175
+ end
176
+
177
+ describe '#execute' do
178
+ end
179
+
180
+ describe '#invoke' do
181
+ end
182
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe PuppetX::Eos::ModuleBase do
4
+ let(:api) { PuppetX::Eos::Eapi.new }
5
+
6
+ describe '#running_configuration' do
7
+ let :result do
8
+ [
9
+ {
10
+ 'output' => "! Fake running-config",
11
+ 'warnings' => ['Command: show running-config']
12
+ }
13
+ ]
14
+ end
15
+
16
+ before :each do
17
+ allow(api).to receive(:enable).with('show running-config', format: 'text')
18
+ .and_return(result)
19
+ end
20
+
21
+ subject { described_class.new(api).running_configuration }
22
+
23
+ it { is_expected.to be_a String }
24
+ it { is_expected.to eq(result.last['output']) }
25
+ end
26
+ end
@@ -0,0 +1,110 @@
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/daemon'
34
+
35
+ describe PuppetX::Eos::Daemon do
36
+ let(:eapi) { double }
37
+ let(:instance) { PuppetX::Eos::Daemon.new eapi }
38
+
39
+ context 'when initializing a new Daemon instance' do
40
+ subject { instance }
41
+ it { is_expected.to be_a_kind_of PuppetX::Eos::Daemon }
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 '#getall' do
52
+ subject { instance.getall }
53
+
54
+ let(:commands) { 'show running-config section daemon' }
55
+
56
+ let :api_response do
57
+ dir = File.dirname(__FILE__)
58
+ file = File.join(dir, 'fixtures/daemon_getall.json')
59
+ JSON.load(File.read(file))
60
+ end
61
+
62
+ describe 'retreiving daemons from running-config' do
63
+ it { is_expected.to be_a_kind_of Hash }
64
+
65
+ it 'has two entries' do
66
+ expect(subject.size).to eq 2
67
+ end
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 '#create' do
80
+ subject { instance.create(name, command) }
81
+
82
+ let(:commands) { ["daemon #{name}", "command #{command}"] }
83
+ let(:api_response) { [{}, {}] }
84
+
85
+ describe 'configure agent=foo with command=/path/to/foo' do
86
+ before :each do
87
+ allow(File).to receive(:executable?)
88
+ .and_return(true)
89
+ end
90
+
91
+ let(:name) { 'foo' }
92
+ let(:command) { '/path/to/foo' }
93
+
94
+ it { is_expected.to be_truthy }
95
+ end
96
+ end
97
+
98
+ context '#delete' do
99
+ subject { instance.delete(name) }
100
+
101
+ let(:commands) { "no daemon #{name}" }
102
+ let(:api_response) { [{}] }
103
+
104
+ describe 'delete agent foo from the running-config' do
105
+ let(:name) { 'foo' }
106
+ it { is_expected.to be_truthy }
107
+ end
108
+ end
109
+ end
110
+ end