diff --git a/lib/puppet/provider/domain_name/eos.rb b/lib/puppet/provider/domain_name/eos.rb index c1065f5..03eb4d5 100644 --- a/lib/puppet/provider/domain_name/eos.rb +++ b/lib/puppet/provider/domain_name/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:domain_name).provide(:eos) do diff --git a/lib/puppet/provider/l2_interface/eos.rb b/lib/puppet/provider/l2_interface/eos.rb index 77df246..8f872e8 100644 --- a/lib/puppet/provider/l2_interface/eos.rb +++ b/lib/puppet/provider/l2_interface/eos.rb @@ -1,7 +1,15 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end + Puppet::Type.type(:l2_interface).provide(:eos) do # Create methods that set the @property_hash for the #flush method diff --git a/lib/puppet/provider/name_server/eos.rb b/lib/puppet/provider/name_server/eos.rb index 34326d3..c9dd1e0 100644 --- a/lib/puppet/provider/name_server/eos.rb +++ b/lib/puppet/provider/name_server/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:name_server).provide(:eos) do diff --git a/lib/puppet/provider/network_dns/eos.rb b/lib/puppet/provider/network_dns/eos.rb index 7500bce..5f5cea9 100644 --- a/lib/puppet/provider/network_dns/eos.rb +++ b/lib/puppet/provider/network_dns/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:network_dns).provide(:eos) do diff --git a/lib/puppet/provider/network_interface/eos.rb b/lib/puppet/provider/network_interface/eos.rb index 12d285f..5515327 100644 --- a/lib/puppet/provider/network_interface/eos.rb +++ b/lib/puppet/provider/network_interface/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:network_interface).provide(:eos) do diff --git a/lib/puppet/provider/network_snmp/eos.rb b/lib/puppet/provider/network_snmp/eos.rb index 4f0975d..14f1682 100644 --- a/lib/puppet/provider/network_snmp/eos.rb +++ b/lib/puppet/provider/network_snmp/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:network_snmp).provide(:eos) do diff --git a/lib/puppet/provider/network_trunk/eos.rb b/lib/puppet/provider/network_trunk/eos.rb index f3dfa01..e15552c 100644 --- a/lib/puppet/provider/network_trunk/eos.rb +++ b/lib/puppet/provider/network_trunk/eos.rb @@ -2,7 +2,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:network_trunk).provide(:eos) do diff --git a/lib/puppet/provider/network_vlan/eos.rb b/lib/puppet/provider/network_vlan/eos.rb index 410bf9b..1488571 100644 --- a/lib/puppet/provider/network_vlan/eos.rb +++ b/lib/puppet/provider/network_vlan/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:network_vlan).provide(:eos) do diff --git a/lib/puppet/provider/ntp_config/eos.rb b/lib/puppet/provider/ntp_config/eos.rb index d119649..1404874 100644 --- a/lib/puppet/provider/ntp_config/eos.rb +++ b/lib/puppet/provider/ntp_config/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:ntp_config).provide(:eos) do diff --git a/lib/puppet/provider/ntp_server/eos.rb b/lib/puppet/provider/ntp_server/eos.rb index c71b11f..0410386 100644 --- a/lib/puppet/provider/ntp_server/eos.rb +++ b/lib/puppet/provider/ntp_server/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:ntp_server).provide(:eos) do diff --git a/lib/puppet/provider/port_channel/eos.rb b/lib/puppet/provider/port_channel/eos.rb index ed744ae..c1d41d2 100644 --- a/lib/puppet/provider/port_channel/eos.rb +++ b/lib/puppet/provider/port_channel/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:port_channel).provide(:eos) do @@ -59,7 +66,7 @@ def force=(val) end def speed=(val) - not_supported 'spped' + not_supported 'speed' end def duplex=(val) diff --git a/lib/puppet/provider/radius/eos.rb b/lib/puppet/provider/radius/eos.rb index 3c60436..fc6ad8b 100644 --- a/lib/puppet/provider/radius/eos.rb +++ b/lib/puppet/provider/radius/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/eos/provider' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:radius).provide(:eos) do @@ -9,10 +16,10 @@ mk_resource_methods # Mix in the api as instance methods - include PuppetX::Eos::EapiProviderMixin + include PuppetX::NetDev::EosApi # Mix in the api as class methods - extend PuppetX::Eos::EapiProviderMixin + extend PuppetX::NetDev::EosApi def self.instances result = node.api('radius').get diff --git a/lib/puppet/provider/radius_global/eos.rb b/lib/puppet/provider/radius_global/eos.rb index 596a5ae..aa54ac9 100644 --- a/lib/puppet/provider/radius_global/eos.rb +++ b/lib/puppet/provider/radius_global/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:radius_global).provide(:eos) do diff --git a/lib/puppet/provider/radius_server/eos.rb b/lib/puppet/provider/radius_server/eos.rb index 6de7bc1..e0c631d 100644 --- a/lib/puppet/provider/radius_server/eos.rb +++ b/lib/puppet/provider/radius_server/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:radius_server).provide(:eos) do diff --git a/lib/puppet/provider/radius_server_group/eos.rb b/lib/puppet/provider/radius_server_group/eos.rb index a987786..917596e 100644 --- a/lib/puppet/provider/radius_server_group/eos.rb +++ b/lib/puppet/provider/radius_server_group/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:radius_server_group).provide(:eos) do diff --git a/lib/puppet/provider/search_domain/eos.rb b/lib/puppet/provider/search_domain/eos.rb index 489db2a..bb72513 100644 --- a/lib/puppet/provider/search_domain/eos.rb +++ b/lib/puppet/provider/search_domain/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:search_domain).provide(:eos) do diff --git a/lib/puppet/provider/snmp_community/eos.rb b/lib/puppet/provider/snmp_community/eos.rb index 7474141..77df842 100644 --- a/lib/puppet/provider/snmp_community/eos.rb +++ b/lib/puppet/provider/snmp_community/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:snmp_community).provide(:eos) do diff --git a/lib/puppet/provider/snmp_notification/eos.rb b/lib/puppet/provider/snmp_notification/eos.rb index fcf8860..eb7e2b3 100644 --- a/lib/puppet/provider/snmp_notification/eos.rb +++ b/lib/puppet/provider/snmp_notification/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:snmp_notification).provide(:eos) do diff --git a/lib/puppet/provider/snmp_notification_receiver/eos.rb b/lib/puppet/provider/snmp_notification_receiver/eos.rb index 464836f..039648d 100644 --- a/lib/puppet/provider/snmp_notification_receiver/eos.rb +++ b/lib/puppet/provider/snmp_notification_receiver/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:snmp_notification_receiver).provide(:eos) do diff --git a/lib/puppet/provider/snmp_user/eos.rb b/lib/puppet/provider/snmp_user/eos.rb index 4073bcd..3243d25 100644 --- a/lib/puppet/provider/snmp_user/eos.rb +++ b/lib/puppet/provider/snmp_user/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:snmp_user).provide(:eos) do diff --git a/lib/puppet/provider/syslog_server/eos.rb b/lib/puppet/provider/syslog_server/eos.rb index cb05c11..d9760b9 100644 --- a/lib/puppet/provider/syslog_server/eos.rb +++ b/lib/puppet/provider/syslog_server/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:syslog_server).provide(:eos) do @@ -40,11 +47,11 @@ def source_interface=(val) def create node.api('logging').add_host(resource[:name]) - @provider_hash = { name: resource[:name], ensure: :present } + @property_hash = { name: resource[:name], ensure: :present } end def destroy node.api('logging').remove_host(resource[:name]) - @provider_hash = { name: resource[:name], ensure: :absent } + @property_hash = { name: resource[:name], ensure: :absent } end end diff --git a/lib/puppet/provider/syslog_settings/eos.rb b/lib/puppet/provider/syslog_settings/eos.rb index 044b37c..87fed64 100644 --- a/lib/puppet/provider/syslog_settings/eos.rb +++ b/lib/puppet/provider/syslog_settings/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:syslog_settings).provide(:eos) do diff --git a/lib/puppet/provider/tacacs/eos.rb b/lib/puppet/provider/tacacs/eos.rb index cc2ba13..67ae549 100644 --- a/lib/puppet/provider/tacacs/eos.rb +++ b/lib/puppet/provider/tacacs/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/eos/provider' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:tacacs).provide(:eos) do @@ -9,10 +16,10 @@ mk_resource_methods # Mix in the api as instance methods - include PuppetX::Eos::EapiProviderMixin + include PuppetX::NetDev::EosApi # Mix in the api as class methods - extend PuppetX::Eos::EapiProviderMixin + extend PuppetX::NetDev::EosApi def self.instances result = node.api('tacacs').get diff --git a/lib/puppet/provider/tacacs_global/eos.rb b/lib/puppet/provider/tacacs_global/eos.rb index e0037e8..a2a0526 100644 --- a/lib/puppet/provider/tacacs_global/eos.rb +++ b/lib/puppet/provider/tacacs_global/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:tacacs_global).provide(:eos) do diff --git a/lib/puppet/provider/tacacs_server/eos.rb b/lib/puppet/provider/tacacs_server/eos.rb index b4b3bb0..2c841b4 100644 --- a/lib/puppet/provider/tacacs_server/eos.rb +++ b/lib/puppet/provider/tacacs_server/eos.rb @@ -1,8 +1,14 @@ - # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:tacacs_server).provide(:eos) do diff --git a/lib/puppet/provider/tacacs_server_group/eos.rb b/lib/puppet/provider/tacacs_server_group/eos.rb index 17fa63c..eb04751 100644 --- a/lib/puppet/provider/tacacs_server_group/eos.rb +++ b/lib/puppet/provider/tacacs_server_group/eos.rb @@ -1,7 +1,14 @@ # encoding: utf-8 require 'puppet/type' -require 'puppet_x/net_dev/eos_api' + +begin + require "puppet_x/net_dev/eos_api" +rescue LoadError => detail + require 'pathname' # JJM WORK_AROUND #14073 + module_base = Pathname.new(__FILE__).dirname + require module_base + "../../../" + "puppet_x/net_dev/eos_api" +end Puppet::Type.type(:tacacs_server_group).provide(:eos) do diff --git a/spec/fixtures/fixture_api_logging.yaml b/spec/fixtures/fixture_api_logging.yaml new file mode 100644 index 0000000..c346431 --- /dev/null +++ b/spec/fixtures/fixture_api_logging.yaml @@ -0,0 +1,5 @@ +--- +:enable: true +:hosts: + - 1.2.3.4 + diff --git a/spec/unit/puppet/provider/name_server/fixture_dns.yaml b/spec/fixtures/fixture_dns.yaml similarity index 100% rename from spec/unit/puppet/provider/name_server/fixture_dns.yaml rename to spec/fixtures/fixture_dns.yaml diff --git a/spec/fixtures/fixture_eapi_radius_server_groups.yaml b/spec/fixtures/fixture_eapi_radius_server_groups.yaml index c074c94..b8cbbac 100644 --- a/spec/fixtures/fixture_eapi_radius_server_groups.yaml +++ b/spec/fixtures/fixture_eapi_radius_server_groups.yaml @@ -1,5 +1,7 @@ --- - - !ruby/sym name: RAD-SV1 +:groups: + :RAD-SV1: + !ruby/sym type: "radius" !ruby/sym servers: - !ruby/sym hostname: "10.11.12.13" !ruby/sym auth_port: "1024" @@ -7,7 +9,8 @@ - !ruby/sym hostname: "10.11.12.13" !ruby/sym auth_port: 1812 !ruby/sym acct_port: "1814" - - !ruby/sym name: RAD-SV2 + :RAD-SV2: + !ruby/sym type: "radius" !ruby/sym servers: - !ruby/sym hostname: "10.11.12.13" !ruby/sym auth_port: "1024" @@ -18,7 +21,8 @@ - !ruby/sym hostname: "10.11.12.14" !ruby/sym auth_port: 1812 !ruby/sym acct_port: 1813 - - !ruby/sym name: RAD-SV3 + :RAD-SV3: + !ruby/sym type: "radius" !ruby/sym servers: - !ruby/sym hostname: "10.11.12.13" !ruby/sym auth_port: "1024" diff --git a/spec/fixtures/fixture_eapi_radius_servers.yaml b/spec/fixtures/fixture_eapi_radius_servers.yaml index a007ab8..1de1c9f 100644 --- a/spec/fixtures/fixture_eapi_radius_servers.yaml +++ b/spec/fixtures/fixture_eapi_radius_servers.yaml @@ -1,18 +1,36 @@ ---- +--- +:global: + :timeout: 10 + :retransmit: 10 + :key_format: 7 + :key: 044B0A151C36435C0D +:servers: - !ruby/sym auth_port: 1812 !ruby/sym acct_port: 1813 !ruby/sym hostname: "10.11.12.13" !ruby/sym key_format: 7 !ruby/sym key: "1513090F557878" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: - !ruby/sym auth_port: 1811 !ruby/sym acct_port: 1813 !ruby/sym hostname: "10.11.12.13" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: - !ruby/sym auth_port: 1811 !ruby/sym acct_port: 1814 !ruby/sym hostname: "10.11.12.13" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: - !ruby/sym auth_port: 1812 !ruby/sym acct_port: 1814 !ruby/sym hostname: "10.11.12.13" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: - !ruby/sym auth_port: 1024 !ruby/sym acct_port: 2048 !ruby/sym hostname: "10.11.12.13" @@ -20,6 +38,12 @@ !ruby/sym retransmit_count: 5 !ruby/sym key_format: 7 !ruby/sym key: "011204070A5955" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: - !ruby/sym auth_port: 1812 !ruby/sym acct_port: 1813 !ruby/sym hostname: "10.11.12.14" + !ruby/sym timeout: 0 + !ruby/sym retransmit: 0 + !ruby/sym vrf: diff --git a/spec/fixtures/fixture_eapi_snmp.yaml b/spec/fixtures/fixture_eapi_snmp.yaml new file mode 100644 index 0000000..95c368c --- /dev/null +++ b/spec/fixtures/fixture_eapi_snmp.yaml @@ -0,0 +1,79 @@ +--- +:location: 'data center' +:contact: 'network operations' +:chassis_id: '1234567890' +:source_interface: 'Loopback0' +:communities: + :public: + :access: ro + :acl: foo +:notifications: +- :name: bgp arista-backward-transition + :state: default +- :name: bgp arista-established + :state: default +- :name: bgp backward-transition + :state: default +- :name: bgp established + :state: default +- :name: entity + :state: default +- :name: entity arista-ent-sensor-alarm + :state: default +- :name: entity ent-config-change + :state: default +- :name: entity ent-state-oper-disabled + :state: default +- :name: entity ent-state-oper-enabled + :state: default +- :name: lldp + :state: default +- :name: lldp rem-tables-change + :state: default +- :name: msdp + :state: default +- :name: msdp backward-transition + :state: default +- :name: msdp established + :state: default +- :name: ospf + :state: default +- :name: ospf if-auth-failure + :state: default +- :name: ospf if-config-error + :state: default +- :name: ospf if-state-change + :state: default +- :name: ospf nbr-state-change + :state: default +- :name: pim + :state: default +- :name: pim neighbor-loss + :state: default +- :name: snmp + :state: default +- :name: snmp authentication + :state: default +- :name: snmp link-down + :state: default +- :name: snmp link-up + :state: default +- :name: snmpConfigManEvent + :state: default +- :name: snmpConfigManEvent arista-config-man-event + :state: default +- :name: switchover + :state: default +- :name: switchover arista-redundancy-switch-over-notif + :state: default +- :name: test + :state: default +- :name: test arista-test-notification + :state: default +- :name: vrrp + :state: default +- :name: vrrp trap-new-master + :state: default +- :name: all + :state: default + diff --git a/spec/fixtures/fixture_eapi_tacacs_getall_configured.yaml b/spec/fixtures/fixture_eapi_tacacs_getall_configured.yaml deleted file mode 100644 index ed35ef5..0000000 --- a/spec/fixtures/fixture_eapi_tacacs_getall_configured.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- - - !ruby/sym name: settings - !ruby/sym enable: true - !ruby/sym timeout: 7 - !ruby/sym key_format: 7 - !ruby/sym key: "070E234F1F5B4A" diff --git a/spec/fixtures/fixture_eapi_tacacs_server_groups.yaml b/spec/fixtures/fixture_eapi_tacacs_server_groups.yaml index e42115f..a4f8a30 100644 --- a/spec/fixtures/fixture_eapi_tacacs_server_groups.yaml +++ b/spec/fixtures/fixture_eapi_tacacs_server_groups.yaml @@ -1,13 +1,17 @@ --- - - !ruby/sym name: TAC-GR +:groups: + :TAC-GR: + !ruby/sym type: "tacacs+" !ruby/sym servers: - !ruby/sym hostname: "1.2.3.4" !ruby/sym port: 4949 - !ruby/sym hostname: "1.2.3.5" !ruby/sym port: 49 - - !ruby/sym name: TAC-GR-EMPTY + :TAC-GR-EMPTY: + !ruby/sym type: "tacacs+" !ruby/sym servers: [] - - !ruby/sym name: TAC-GR2 + :TAC-GR2: + !ruby/sym type: "tacacs+" !ruby/sym servers: - !ruby/sym hostname: "1.2.3.5" !ruby/sym port: 50 diff --git a/spec/fixtures/fixture_eapi_tacacs_servers.yaml b/spec/fixtures/fixture_eapi_tacacs_servers.yaml index 372c6ba..87c52ba 100644 --- a/spec/fixtures/fixture_eapi_tacacs_servers.yaml +++ b/spec/fixtures/fixture_eapi_tacacs_servers.yaml @@ -1,19 +1,28 @@ ---- - - !ruby/sym port: 4949 - !ruby/sym hostname: "1.2.3.4" - !ruby/sym timeout: 6 - !ruby/sym key_format: 7 - !ruby/sym key: "06070D221D1C5A" - !ruby/sym multiplex: true - - !ruby/sym port: 49 - !ruby/sym hostname: "1.2.3.4" - !ruby/sym timeout: 10 - !ruby/sym multiplex: false - - !ruby/sym port: 49 - !ruby/sym hostname: "1.2.3.5" - !ruby/sym timeout: 10 - !ruby/sym multiplex: false - - !ruby/sym port: 50 - !ruby/sym hostname: "1.2.3.5" - !ruby/sym timeout: 10 - !ruby/sym multiplex: false +--- +:global: + :timeout: 7 + :key: 070E234F1F5B4A + :key_format: 7 +:servers: + - :port: 4949 + :vrf: + :hostname: "1.2.3.4" + :timeout: 6 + :key_format: 7 + :key: "06070D221D1C5A" + :multiplex: true + - :port: 49 + :vrf: + :hostname: "1.2.3.4" + :timeout: 10 + :multiplex: false + - :port: 49 + :vrf: + :hostname: "1.2.3.5" + :timeout: 10 + :multiplex: false + - :port: 50 + :vrf: + :hostname: "1.2.3.5" + :timeout: 10 + :multiplex: false diff --git a/spec/unit/puppet/provider/ntp_server/fixture_ntp.yaml b/spec/fixtures/fixture_ntp.yaml similarity index 100% rename from spec/unit/puppet/provider/ntp_server/fixture_ntp.yaml rename to spec/fixtures/fixture_ntp.yaml diff --git a/spec/unit/puppet/provider/domain_name/eos_spec.rb b/spec/unit/puppet/provider/domain_name/eos_spec.rb index 35f70cb..a0f88f1 100644 --- a/spec/unit/puppet/provider/domain_name/eos_spec.rb +++ b/spec/unit/puppet/provider/domain_name/eos_spec.rb @@ -51,7 +51,7 @@ def dns dns = Fixtures[:dns] return dns if dns - fixture('dns', dir: File.dirname(__FILE__)) + fixture('dns') end # Stub the Api method class to obtain all vlans. diff --git a/spec/unit/puppet/provider/domain_name/fixture_dns.yaml b/spec/unit/puppet/provider/domain_name/fixture_dns.yaml deleted file mode 100644 index b5592c3..0000000 --- a/spec/unit/puppet/provider/domain_name/fixture_dns.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -:domain_name: arista.com -:domain_list: [] -:name_servers: [] diff --git a/spec/unit/puppet/provider/name_server/eos_spec.rb b/spec/unit/puppet/provider/name_server/eos_spec.rb index 27f1d79..e30611e 100644 --- a/spec/unit/puppet/provider/name_server/eos_spec.rb +++ b/spec/unit/puppet/provider/name_server/eos_spec.rb @@ -51,7 +51,7 @@ def dns dns = Fixtures[:dns] return dns if dns - fixture('dns', dir: File.dirname(__FILE__)) + fixture('dns') end # Stub the Api method class to obtain all vlans. diff --git a/spec/unit/puppet/provider/network_dns/eos_spec.rb b/spec/unit/puppet/provider/network_dns/eos_spec.rb index fcb2f06..3262ba7 100644 --- a/spec/unit/puppet/provider/network_dns/eos_spec.rb +++ b/spec/unit/puppet/provider/network_dns/eos_spec.rb @@ -54,7 +54,7 @@ def dns dns = Fixtures[:dns] return dns if dns - fixture('dns', dir: File.dirname(__FILE__)) + fixture('dns') end # Stub the Api method class to obtain all vlans. diff --git a/spec/unit/puppet/provider/network_dns/fixture_dns.yaml b/spec/unit/puppet/provider/network_dns/fixture_dns.yaml deleted file mode 100644 index a1bd903..0000000 --- a/spec/unit/puppet/provider/network_dns/fixture_dns.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -:domain_name: arista.com -:domain_list: ['arista.net'] -:name_servers: ['1.2.3.4'] diff --git a/spec/unit/puppet/provider/network_snmp/eos_spec.rb b/spec/unit/puppet/provider/network_snmp/eos_spec.rb index beadce8..af51c7e 100644 --- a/spec/unit/puppet/provider/network_snmp/eos_spec.rb +++ b/spec/unit/puppet/provider/network_snmp/eos_spec.rb @@ -54,7 +54,7 @@ def snmp snmp = Fixtures[:snmp] return snmp if snmp - fixture('snmp', dir: File.dirname(__FILE__)) + fixture('eapi_snmp') end # Stub the Api method class to obtain all vlans. @@ -87,8 +87,7 @@ def snmp include_examples 'provider resource methods', name: 'settings', contact: 'network operations', - location: 'data center', - enable: :true + location: 'data center' end end @@ -118,7 +117,7 @@ def snmp expect(resources['settings'].provider.exists?).to be_truthy expect(resources['settings'].provider.contact).to eq 'network operations' expect(resources['settings'].provider.location).to eq 'data center' - expect(resources['settings'].provider.enable).to eq :true + expect(resources['settings'].provider.enable).to eq :absent end it 'does not set the provider instance of the unmanaged resource' do @@ -167,19 +166,20 @@ def snmp end describe '#enable=(value)' do - let(:vid) { resource[:name] } - - it 'updates enable with value :true' do - expect(api).to receive(:set_enable).with(value: true) - provider.enable = :true - expect(provider.enable).to eq(:true) - end - - it 'updates enable with value :false' do - expect(api).to receive(:set_enable).with(value: false) - provider.enable = :false - expect(provider.enable).to eq(:false) - end + # enable is not_supported on EOS. SNMP is always enabled + #let(:vid) { resource[:name] } + + #it 'updates enable with value :true' do + # expect(api).to receive(:set_enable).with(value: true) + # provider.enable = :true + # expect(provider.enable).to eq(:true) + #end + + #it 'updates enable with value :false' do + # expect(api).to receive(:set_enable).with(value: false) + # provider.enable = :false + # expect(provider.enable).to eq(:false) + #end end end end diff --git a/spec/unit/puppet/provider/network_snmp/fixture_snmp.yaml b/spec/unit/puppet/provider/network_snmp/fixture_snmp.yaml deleted file mode 100644 index db4f68c..0000000 --- a/spec/unit/puppet/provider/network_snmp/fixture_snmp.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -:contact: network operations -:location: data center -:source_interface: Loopback0 -:chassis_id: 1234567890 - diff --git a/spec/unit/puppet/provider/ntp_config/eos_spec.rb b/spec/unit/puppet/provider/ntp_config/eos_spec.rb index 1192bc3..87ffce6 100644 --- a/spec/unit/puppet/provider/ntp_config/eos_spec.rb +++ b/spec/unit/puppet/provider/ntp_config/eos_spec.rb @@ -51,7 +51,7 @@ def ntp ntp = Fixtures[:ntp] return ntp if ntp - fixture('ntp', dir: File.dirname(__FILE__)) + fixture('ntp') end before :each do diff --git a/spec/unit/puppet/provider/ntp_config/fixture_ntp.json b/spec/unit/puppet/provider/ntp_config/fixture_ntp.json deleted file mode 100644 index 3b5e5aa..0000000 --- a/spec/unit/puppet/provider/ntp_config/fixture_ntp.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "source_interface": "Loopback0", - "servers": { - "1.2.3.4": { }, - "5.6.7.8": { } - } -} diff --git a/spec/unit/puppet/provider/ntp_config/fixture_ntp.yaml b/spec/unit/puppet/provider/ntp_config/fixture_ntp.yaml deleted file mode 100644 index 2852abc..0000000 --- a/spec/unit/puppet/provider/ntp_config/fixture_ntp.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -:source_interface: Loopback0 -:servers: ['1.2.3.4', '5.6.7.8'] diff --git a/spec/unit/puppet/provider/ntp_server/eos_spec.rb b/spec/unit/puppet/provider/ntp_server/eos_spec.rb index 0c6d524..a1375e3 100644 --- a/spec/unit/puppet/provider/ntp_server/eos_spec.rb +++ b/spec/unit/puppet/provider/ntp_server/eos_spec.rb @@ -50,7 +50,7 @@ def ntp ntp = Fixtures[:ntp] return ntp if ntp - fixture('ntp', dir: File.dirname(__FILE__)) + fixture('ntp') end before :each do diff --git a/spec/unit/puppet/provider/radius/eos_spec.rb b/spec/unit/puppet/provider/radius/eos_spec.rb index 9d953ec..68cad22 100644 --- a/spec/unit/puppet/provider/radius/eos_spec.rb +++ b/spec/unit/puppet/provider/radius/eos_spec.rb @@ -31,6 +31,8 @@ # require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:radius).provider(:eos) do # Puppet RAL memoized methods @@ -50,10 +52,10 @@ def radius radius = Fixtures[:radius] return radius if radius - file = File.join(File.dirname(__FILE__), 'fixture_api_radius.json') - Fixtures[:radius] = JSON.load(File.read(file)) + fixture('eapi_radius_servers') end + # Stub the Api method class. before :each do allow(described_class.node).to receive(:api).with('radius').and_return(api) allow(provider.node).to receive(:api).with('radius').and_return(api) @@ -82,7 +84,7 @@ def radius include_examples 'provider resource methods', name: 'settings', - enable: :true + enable: true end end @@ -93,6 +95,7 @@ def radius 'alternative' => Puppet::Type.type(:radius).new(name: 'alternative') } end + subject { described_class.prefetch(resources) } it 'resource providers are absent prior to calling .prefetch' do diff --git a/spec/unit/puppet/provider/radius/fixture_api_radius.json b/spec/unit/puppet/provider/radius/fixture_api_radius.json deleted file mode 100644 index 0cff212..0000000 --- a/spec/unit/puppet/provider/radius/fixture_api_radius.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "enable": true, - "servers": {}, - "groups": {} -} diff --git a/spec/unit/puppet/provider/radius_global/eos_spec.rb b/spec/unit/puppet/provider/radius_global/eos_spec.rb index 1938610..6eb34b3 100644 --- a/spec/unit/puppet/provider/radius_global/eos_spec.rb +++ b/spec/unit/puppet/provider/radius_global/eos_spec.rb @@ -55,7 +55,7 @@ def radius radius = Fixtures[:radius] return radius if radius - fixture('radius', dir: File.dirname(__FILE__)) + fixture('eapi_radius_servers') end before :each do @@ -88,8 +88,8 @@ def radius name: 'settings', key: '044B0A151C36435C0D', key_format: 7, - timeout: '10', - retransmit_count: '10' + timeout: 10, + retransmit_count: 10 end end @@ -116,8 +116,8 @@ def radius subject expect(resources['settings'].provider.key).to eq('044B0A151C36435C0D') expect(resources['settings'].provider.key_format).to eq(7) - expect(resources['settings'].provider.timeout).to eq('10') - expect(resources['settings'].provider.retransmit_count).to eq('10') + expect(resources['settings'].provider.timeout).to eq(10) + expect(resources['settings'].provider.retransmit_count).to eq(10) end it 'does not set the provider instance of the unmanaged resource' do diff --git a/spec/unit/puppet/provider/radius_global/fixture_radius.yaml b/spec/unit/puppet/provider/radius_global/fixture_radius.yaml deleted file mode 100644 index b5584af..0000000 --- a/spec/unit/puppet/provider/radius_global/fixture_radius.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -:global: - :timeout: '10' - :retransmit: '10' - :key: 044B0A151C36435C0D - :key_format: 7 - diff --git a/spec/unit/puppet/provider/radius_server/eos_spec.rb b/spec/unit/puppet/provider/radius_server/eos_spec.rb index fa5b573..4c82450 100644 --- a/spec/unit/puppet/provider/radius_server/eos_spec.rb +++ b/spec/unit/puppet/provider/radius_server/eos_spec.rb @@ -1,9 +1,39 @@ -# encoding: utf-8 - +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:radius_server).provider(:eos) do - let(:radius) { PuppetX::Eos::Radius.new(PuppetX::Eos::Eapi.new) } let(:type) { Puppet::Type.type(:radius_server) } @@ -29,18 +59,25 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let(:api) { double('radius') } + + def radius + radius = Fixtures[:radius] + return radius if radius + fixture('eapi_radius_servers') + end + + before :each do + allow(described_class.node).to receive(:api).with('radius').and_return(api) + allow(provider.node).to receive(:api).with('radius').and_return(api) + end + it_behaves_like 'provider exists?' - describe 'class methods' do - before :each do - allow(described_class.eapi).to receive(:Radius).and_return(radius) - end + context 'class methods' do + before { allow(api).to receive(:get).and_return(radius) } describe '.instances' do - before :each do - allow(radius).to receive(:servers) - .and_return(fixture(:eapi_radius_servers)) - end subject { described_class.instances } @@ -52,20 +89,22 @@ end end - describe 'instance methods' do - before :each do - allow(provider.eapi).to receive(:Radius).and_return(radius) - end + context 'instance methods' do describe '#flush' do + before :each do + allow(api).to receive(:update_server).and_return(true) + allow(api).to receive(:remove_server).and_return(true) + end + context 'after create' do subject do provider.create provider.flush end - it 'calls PuppetX::Eos::Radius#update_server' do - expect(radius).to receive(:update_server) + it 'calls #update_server' do + expect(api).to receive(:update_server) .with(include(hostname: '127.0.0.1')) .and_return(true) subject @@ -82,8 +121,8 @@ provider.flush end - it 'calls PuppetX::Eos::Radius#remove_server' do - expect(radius).to receive(:remove_server) + it 'calls #remove_server' do + expect(api).to receive(:remove_server) .with(include(hostname: '127.0.0.1')) .and_return(true) subject diff --git a/spec/unit/puppet/provider/radius_server_group/eos_spec.rb b/spec/unit/puppet/provider/radius_server_group/eos_spec.rb index b4a7e57..a54b810 100644 --- a/spec/unit/puppet/provider/radius_server_group/eos_spec.rb +++ b/spec/unit/puppet/provider/radius_server_group/eos_spec.rb @@ -1,9 +1,41 @@ -# encoding: utf-8 +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:radius_server_group).provider(:eos) do - let(:radius) { PuppetX::Eos::Radius.new(PuppetX::Eos::Eapi.new) } + let(:type) { Puppet::Type.type(:radius_server_group) } # Allow text cases to override resource attributes @@ -22,18 +54,25 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let(:api) { double('aaa') } + + def aaa + aaa = Fixtures[:aaa] + return aaa if aaa + fixture('eapi_radius_server_groups') + end + + before :each do + allow(described_class.node).to receive(:api).with('aaa').and_return(api) + allow(provider.node).to receive(:api).with('aaa').and_return(api) + end + it_behaves_like 'provider exists?' - describe 'class methods' do - before :each do - allow(described_class.eapi).to receive(:Radius).and_return(radius) - end + context 'class methods' do + before { allow(api).to receive(:get).and_return(aaa) } describe '.instances' do - before :each do - allow(radius).to receive(:server_groups) - .and_return(fixture(:eapi_radius_server_groups)) - end subject { described_class.instances } @@ -42,21 +81,23 @@ end end - describe 'instance methods' do - before :each do - allow(provider.eapi).to receive(:Radius).and_return(radius) - end + context 'resource (instance) methods' do describe '#flush' do + before :each do + allow(api).to receive_message_chain(:groups, :create).and_return(true) + allow(api).to receive_message_chain(:groups, :set_servers).and_return(true) + allow(api).to receive_message_chain(:groups, :delete).and_return(true) + end + context 'after create' do subject do provider.create - provider.flush end - it 'calls PuppetX::Eos::Radius#update_server_group' do - expect(radius).to receive(:update_server_group) - .with(include(name: 'RAD-SV9')) + it 'calls #create' do + expect(api).to receive_message_chain(:groups, :create) + .with('RAD-SV9', 'radius') .and_return(true) subject end @@ -69,12 +110,11 @@ subject do provider.destroy - provider.flush end - it 'calls PuppetX::Eos::Radius#remove_server_group' do - expect(radius).to receive(:remove_server_group) - .with(include(name: 'RAD-SV9')) + it 'calls #delete' do + expect(api).to receive_message_chain(:groups, :delete) + .with(include('RAD-SV9')) .and_return(true) subject end @@ -84,12 +124,11 @@ subject do provider.create provider.servers=([]) - provider.flush end - it 'calls PuppetX::Eos::Radius#update_server_group' do - expect(radius).to receive(:update_server_group) - .with(include(name: 'RAD-SV9', servers: [])) + it 'calls #set_servers' do + expect(api).to receive_message_chain(:groups, :set_servers) + .with('RAD-SV9', []) .and_return(true) subject end diff --git a/spec/unit/puppet/provider/search_domain/eos_spec.rb b/spec/unit/puppet/provider/search_domain/eos_spec.rb index 23b31b0..519abe5 100644 --- a/spec/unit/puppet/provider/search_domain/eos_spec.rb +++ b/spec/unit/puppet/provider/search_domain/eos_spec.rb @@ -51,7 +51,7 @@ def dns dns = Fixtures[:dns] return dns if dns - fixture('dns', dir: File.dirname(__FILE__)) + fixture('dns') end # Stub the Api method class to obtain all vlans. diff --git a/spec/unit/puppet/provider/search_domain/fixture_dns.yaml b/spec/unit/puppet/provider/search_domain/fixture_dns.yaml deleted file mode 100644 index ed0f3c3..0000000 --- a/spec/unit/puppet/provider/search_domain/fixture_dns.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -:domain_name: arista.com -:domain_list: ['arista.net'] -:name_servers: ['1.2.3.4'] - diff --git a/spec/unit/puppet/provider/snmp_notification/eos_spec.rb b/spec/unit/puppet/provider/snmp_notification/eos_spec.rb index 81791c1..0dd807f 100644 --- a/spec/unit/puppet/provider/snmp_notification/eos_spec.rb +++ b/spec/unit/puppet/provider/snmp_notification/eos_spec.rb @@ -52,7 +52,7 @@ def snmp snmp = Fixtures[:snmp] return snmp if snmp - fixture('snmp', dir: File.dirname(__FILE__)) + fixture('eapi_snmp') end before :each do @@ -69,8 +69,8 @@ def snmp it { is_expected.to be_an Array } - it 'has only one entry' do - expect(subject.size).to eq 1 + it 'has 34 entries' do + expect(subject.size).to eq(34) end it 'has an instance for all' do diff --git a/spec/unit/puppet/provider/snmp_notification_receiver/eos_spec.rb b/spec/unit/puppet/provider/snmp_notification_receiver/eos_spec.rb index c155b08..5e4bb65 100644 --- a/spec/unit/puppet/provider/snmp_notification_receiver/eos_spec.rb +++ b/spec/unit/puppet/provider/snmp_notification_receiver/eos_spec.rb @@ -1,5 +1,34 @@ -# encoding: utf-8 - +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' describe Puppet::Type.type(:snmp_notification_receiver).provider(:eos) do @@ -24,24 +53,34 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let(:api) { double('snmp') } + + before :each do + allow(described_class.node).to receive(:api).with('snmp', {:path=>"rbeapi/netdev", :namespace=>"Rbeapi::Netdev"}).and_return(api) + allow(provider.node).to receive(:api).with('snmp', {:path=>"rbeapi/netdev", :namespace=>"Rbeapi::Netdev"}).and_return(api) + end + it_behaves_like 'provider exists?' - describe 'class methods' do + context 'class methods' do + describe '.instances' do + subject { described_class.instances } context 'when there are no duplicate hosts' do before :each do - allow(described_class.api).to receive(:snmp_notification_receivers) + allow(api).to receive(:snmp_notification_receivers) .and_return(fixture(:api_snmp_notification_receivers)) end + it_behaves_like 'provider instances', size: 4 end context 'when there are duplicate host entries' do before :each do - allow(described_class.api).to receive(:snmp_notification_receivers) + allow(api).to receive(:snmp_notification_receivers) .and_return(fixture(:api_snmp_notification_receivers_duplicates)) end @@ -55,7 +94,7 @@ context 'when there are more duplicate host entries' do before :each do fixed_data = fixture(:api_snmp_notification_receivers_more_duplicates) - allow(described_class.api).to receive(:snmp_notification_receivers) + allow(api).to receive(:snmp_notification_receivers) .and_return(fixed_data) end @@ -66,7 +105,7 @@ describe '.prefetch' do before :each do fixed_data = fixture(:api_snmp_notification_receivers_more_duplicates) - allow(described_class.api).to receive(:snmp_notification_receivers) + allow(api).to receive(:snmp_notification_receivers) .and_return(fixed_data) end @@ -125,7 +164,7 @@ describe '#flush' do context 'when creating' do before :each do - allow(provider.api).to receive(:snmp_notification_receiver_set) + allow(api).to receive(:snmp_notification_receiver_set) .and_return(true) end subject do @@ -136,12 +175,12 @@ let(:name) { '127.0.0.1:snmpuser:162' } it 'calls snmp_notification_receiver_set' do - expect(provider.api).to receive(:snmp_notification_receiver_set) + expect(api).to receive(:snmp_notification_receiver_set) .and_return(true) subject end it 'adds the default port of 162' do - expect(provider.api).to receive(:snmp_notification_receiver_set) + expect(api).to receive(:snmp_notification_receiver_set) .with(resource_hash.merge(port: 162)).and_return(true) subject end @@ -165,7 +204,7 @@ context 'when destroying' do let(:resource_override) { { ensure: :absent } } before :each do - allow(provider.api).to receive(:snmp_notification_receiver_remove) + allow(api).to receive(:snmp_notification_receiver_remove) .and_return(true) end subject do @@ -176,7 +215,7 @@ let(:name) { '127.0.0.1:snmpuser:162' } it 'calls snmp_notification_receiver_remove' do - expect(provider.api).to receive(:snmp_notification_receiver_remove) + expect(api).to receive(:snmp_notification_receiver_remove) .and_return(true) subject end diff --git a/spec/unit/puppet/provider/snmp_user/eos_spec.rb b/spec/unit/puppet/provider/snmp_user/eos_spec.rb index 7df45c3..b40d1d4 100644 --- a/spec/unit/puppet/provider/snmp_user/eos_spec.rb +++ b/spec/unit/puppet/provider/snmp_user/eos_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:snmp_user).provider(:eos) do let(:type) { Puppet::Type.type(:snmp_user) } @@ -22,12 +24,23 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let (:api) { double('snmp') } + + def snmp + snmp = Fixtures[:snmp] + return snmp if snmp + fixture('api_snmp_users') + end + before :each do - allow(described_class.api).to receive(:snmp_users) - .and_return(fixture(:api_snmp_users)) + allow(described_class.node).to receive(:api).with('snmp', {:path=>"rbeapi/netdev", :namespace=>"Rbeapi::Netdev"}).and_return(api) + allow(provider.node).to receive(:api).with('snmp', {:path=>"rbeapi/netdev", :namespace=>"Rbeapi::Netdev"}).and_return(api) end - describe 'class methods' do + context 'class methods' do + + before { allow(api).to receive(:snmp_users).and_return(snmp) } + describe '.instances' do subject { described_class.instances } @@ -40,6 +53,7 @@ end describe '#flush' do + let(:provider) do provider = described_class.new(resource_hash) provider.resource = resource @@ -47,7 +61,7 @@ end before :each do - allow(provider.api).to receive(:snmp_user_set) + allow(api).to receive(:snmp_user_set) .and_return(password: 'foobar') end @@ -58,7 +72,7 @@ end it 'calls snmp_user_set' do - expect(provider.api).to receive(:snmp_user_set) + expect(api).to receive(:snmp_user_set) .and_return(password: 'foobar') subject end @@ -69,7 +83,7 @@ end it 'splits the name on colon' do - expect(provider.api).to receive(:snmp_user_set) + expect(api).to receive(:snmp_user_set) .with(include(name: 'jeff', version: :v3)) .and_return(password: 'foobar') subject @@ -89,7 +103,7 @@ context 'when the resource name matches the title' do it 'calls snmp_user_destroy' do - expect(provider.api).to receive(:snmp_user_destroy) + expect(api).to receive(:snmp_user_destroy) .with(include(expected)).and_return({}) subject end @@ -101,7 +115,7 @@ end it 'splits the name on colon' do - expect(provider.api).to receive(:snmp_user_destroy) + expect(api).to receive(:snmp_user_destroy) .with(include(expected)) .and_return({}) subject @@ -139,6 +153,9 @@ it_behaves_like 'provider exists?' describe '.prefetch(resources)' do + + before { allow(api).to receive(:snmp_users).and_return(snmp) } + let(:matching_resource) do { name: 'jeff', diff --git a/spec/unit/puppet/provider/syslog_server/eos_spec.rb b/spec/unit/puppet/provider/syslog_server/eos_spec.rb index 21a81c6..bf01570 100644 --- a/spec/unit/puppet/provider/syslog_server/eos_spec.rb +++ b/spec/unit/puppet/provider/syslog_server/eos_spec.rb @@ -49,10 +49,12 @@ def logging logging = Fixtures[:logging] return logging if logging - file = File.join(File.dirname(__FILE__), 'fixture_api_logging.json') - Fixtures[:logging] = JSON.load(File.read(file)) + #file = File.join(File.dirname(__FILE__), 'fixture_api_logging.json') + #Fixtures[:logging] = JSON.load(File.read(file)) + fixture('api_logging') end + # Stub the Api method class. before :each do allow(described_class.node).to receive(:api).with('logging').and_return(api) allow(provider.node).to receive(:api).with('logging').and_return(api) @@ -80,8 +82,7 @@ def logging subject { described_class.instances.find { |p| p.name == '1.2.3.4' } } include_examples 'provider resource methods', - name: '1.2.3.4', - enable: :true + name: '1.2.3.4' end end @@ -92,26 +93,25 @@ def logging '5.6.7.8' => Puppet::Type.type(:syslog_server) .new(name: '5.6.7.8') } end + subject { described_class.prefetch(resources) } - it 'resource providers are absent prior to calling .prefetch' do - resources.values.each do |rsrc| - expect(rsrc.provider.enable).to eq(:absent) - end - end + #it 'resource providers are absent prior to calling .prefetch' do + # resources.values.each do |rsrc| + # expect(rsrc.provider.enable).to eq(:absent) + # end + #end it 'sets the provider instance of the managed resource' do subject expect(resources['1.2.3.4'].provider.name).to eq('1.2.3.4') expect(resources['1.2.3.4'].provider.exists?).to be_truthy - expect(resources['1.2.3.4'].provider.enable).to be_truthy end it 'does not set the provider instance of the unmanaged resource' do subject expect(resources['5.6.7.8'].provider.name).to eq('5.6.7.8') expect(resources['5.6.7.8'].provider.exists?).to be_falsey - expect(resources['5.6.7.8'].provider.enable).to eq(:absent) end end end @@ -144,7 +144,7 @@ def logging describe '#destroy' do it 'sets ensure to :absent' do - expect(api).to receive(:delete).with(resource[:name]) + expect(api).to receive(:remove_host).with(resource[:name]) provider.destroy expect(provider.ensure).to eq(:absent) end diff --git a/spec/unit/puppet/provider/syslog_server/fixture_api_logging.json b/spec/unit/puppet/provider/syslog_server/fixture_api_logging.json deleted file mode 100644 index 5702233..0000000 --- a/spec/unit/puppet/provider/syslog_server/fixture_api_logging.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "enable": true, - "hosts": [ - "1.2.3.4" - ] -} diff --git a/spec/unit/puppet/provider/syslog_settings/eos_spec.rb b/spec/unit/puppet/provider/syslog_settings/eos_spec.rb index 6f7003a..5a9b436 100644 --- a/spec/unit/puppet/provider/syslog_settings/eos_spec.rb +++ b/spec/unit/puppet/provider/syslog_settings/eos_spec.rb @@ -31,6 +31,8 @@ # require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:syslog_settings).provider(:eos) do # Puppet RAL memoized methods @@ -50,8 +52,10 @@ def logging logging = Fixtures[:logging] return logging if logging - file = File.join(File.dirname(__FILE__), 'fixture_api_logging.json') - Fixtures[:logging] = JSON.load(File.read(file)) + #file = File.join(File.dirname(__FILE__), 'fixture_api_logging.json') + #Fixtures[:logging] = JSON.load(File.read(file)) + #fixture('api_logging', dir: File.dirname(__FILE__)) + fixture('api_logging') end before :each do diff --git a/spec/unit/puppet/provider/syslog_settings/fixture_api_logging.json b/spec/unit/puppet/provider/syslog_settings/fixture_api_logging.json deleted file mode 100644 index 5702233..0000000 --- a/spec/unit/puppet/provider/syslog_settings/fixture_api_logging.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "enable": true, - "hosts": [ - "1.2.3.4" - ] -} diff --git a/spec/unit/puppet/provider/tacacs/eos_spec.rb b/spec/unit/puppet/provider/tacacs/eos_spec.rb index d15c39f..3465c67 100644 --- a/spec/unit/puppet/provider/tacacs/eos_spec.rb +++ b/spec/unit/puppet/provider/tacacs/eos_spec.rb @@ -50,8 +50,7 @@ def tacacs tacacs = Fixtures[:tacacs] return tacacs if tacacs - file = File.join(File.dirname(__FILE__), 'fixture_api_tacacs.json') - Fixtures[:tacacs] = JSON.load(File.read(file)) + fixture('eapi_tacacs_servers') end before :each do @@ -81,8 +80,7 @@ def tacacs subject { described_class.instances.find { |p| p.name == 'settings' } } include_examples 'provider resource methods', - name: 'settings', - enable: :true + name: 'settings' end end diff --git a/spec/unit/puppet/provider/tacacs/fixture_api_tacacs.json b/spec/unit/puppet/provider/tacacs/fixture_api_tacacs.json deleted file mode 100644 index 0cff212..0000000 --- a/spec/unit/puppet/provider/tacacs/fixture_api_tacacs.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "enable": true, - "servers": {}, - "groups": {} -} diff --git a/spec/unit/puppet/provider/tacacs_global/eos_spec.rb b/spec/unit/puppet/provider/tacacs_global/eos_spec.rb index d9f21d0..17f419f 100644 --- a/spec/unit/puppet/provider/tacacs_global/eos_spec.rb +++ b/spec/unit/puppet/provider/tacacs_global/eos_spec.rb @@ -1,40 +1,71 @@ -# encoding: utf-8 - +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' -describe Puppet::Type.type(:tacacs_global).provider(:eos) do - let(:api) { PuppetX::Eos::Tacacs.new(PuppetX::Eos::Eapi.new) } - - let(:type) { Puppet::Type.type(:tacacs_global) } +include FixtureHelpers - # Allow text cases to override resource attributes - let :resource_override do - {} - end +describe Puppet::Type.type(:tacacs_global).provider(:eos) do - let :resource_hash do - { + let(:resource) do + resource_hash = { name: 'settings', enable: true, key: '070E234F1F5B4A', key_format: 7, - timeout: 30 - }.merge(resource_override) + timeout: 30, + provider: described_class.name + } + Puppet::Type.type(:tacacs_global).new(resource_hash) end - let(:resource) { type.new(resource_hash) } - let(:provider) { described_class.new(resource) } + let(:provider) { resource.provider } - describe 'class methods' do - before :each do - allow(described_class.eapi).to receive(:Tacacs).and_return(api) - end + let(:api) { double('tacacs') } + + def tacacs + tacacs = Fixtures[:tacacs] + return tacacs if tacacs + fixture('eapi_tacacs_servers') + end + + before :each do + allow(described_class.node).to receive(:api).with('tacacs').and_return(api) + allow(provider.node).to receive(:api).with('tacacs').and_return(api) + end + + context 'class methods' do + before { allow(api).to receive(:get).and_return(tacacs) } describe '.instances' do - before :each do - allow(api).to receive(:getall) - .and_return(fixture(:eapi_tacacs_getall_configured)) - end subject { described_class.instances } @@ -48,9 +79,6 @@ it 'has the name "settings"' do expect(subject.name).to eq 'settings' end - it 'enable is true' do - expect(subject.enable).to eq true - end it 'key is 070E234F1F5B4A' do expect(subject.key).to eq '070E234F1F5B4A' end @@ -64,51 +92,38 @@ end end - describe 'instance methods' do - let(:provider) do - provider = described_class.new(resource_hash) - provider.resource = resource - provider - end + context 'resource (instance) methods' do - before :each do - allow(provider.eapi).to receive(:Tacacs).and_return(api) - end + #describe '#key=(value)' do + # it 'updates the global key' do + # expect(api).to receive(:set_global_key).with(key_format: 0, value: '070E234F1F5B4A') + # provider.key = '070E234F1F5B4A' + # expect(provider.key).to eq('070E234F1F5B4A') + # end + #end - describe '#enable=false' do - it 'raises ArgumentError because EOS cannot disable the resource' do - expect { provider.enable = false } - .to raise_error ArgumentError, /cannot be disabled/ - end - end - - describe '#retransmit_count=5' do - it 'raises NotImplementedError because retransmit cannot be configured' do - expect { provider.retransmit_count = 5 } - .to raise_error NotImplementedError, /cannot be configured/ - end - end describe '#flush' do before :each do allow(api).to receive(:set_global_key).and_return(true) - allow(api).to receive(:set_timeout).and_return(true) + allow(api).to receive(:set_global_timeout).and_return(true) end context 'after updating the key' do + subject do provider.key = 'updatedkey' provider.key_format = 5 provider.flush end - it 'calls Tacacs#set_global_key to configure the key' do + it 'calls #set_global_key to configure the key' do expect(api).to receive(:set_global_key) - .with(include(key: 'updatedkey')) + .with(include(value: 'updatedkey')) subject end it 'does not update the timeout' do - expect(api).not_to receive(:set_timeout) + expect(api).not_to receive(:set_global_timeout) subject end end @@ -123,9 +138,9 @@ expect(api).not_to receive(:set_global_key) subject end - it 'calls Tacacs#set_timeout to configure the timeout' do - expect(api).to receive(:set_timeout) - .with(include(timeout: 120)) + it 'calls #set_timeout to configure the timeout' do + expect(api).to receive(:set_global_timeout) + .with(include(value: 120)) subject end end diff --git a/spec/unit/puppet/provider/tacacs_server/eos_spec.rb b/spec/unit/puppet/provider/tacacs_server/eos_spec.rb index 7ba1abd..cc3abeb 100644 --- a/spec/unit/puppet/provider/tacacs_server/eos_spec.rb +++ b/spec/unit/puppet/provider/tacacs_server/eos_spec.rb @@ -1,9 +1,39 @@ -# encoding: utf-8 - +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:tacacs_server).provider(:eos) do - let(:eapi) { PuppetX::Eos::Tacacs.new(PuppetX::Eos::Eapi.new) } let(:type) { Puppet::Type.type(:tacacs_server) } @@ -27,18 +57,25 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let(:api) { double('tacacs') } + + def tacacs + tacacs = Fixtures[:tacacs] + return tacacs if tacacs + fixture('eapi_tacacs_servers') + end + + before :each do + allow(described_class.node).to receive(:api).with('tacacs').and_return(api) + allow(provider.node).to receive(:api).with('tacacs').and_return(api) + end + it_behaves_like 'provider exists?' - describe 'class methods' do - before :each do - allow(described_class.eapi).to receive(:Tacacs).and_return(eapi) - end + context 'class methods' do + before { allow(api).to receive(:get).and_return(tacacs) } describe '.instances' do - before :each do - allow(eapi).to receive(:servers) - .and_return(fixture(:eapi_tacacs_servers)) - end subject { described_class.instances } @@ -46,7 +83,7 @@ it 'size is 4' do expect(subject.size).to eq(4) end - it 'sets the name parameter as //' do + it 'sets the name parameter as /' do subject.each { |i| expect(i.name).to match /^.*?\/\d+$/ } end it 'one instance, 1.2.3.4/4949 has single_connection == :true' do @@ -58,20 +95,22 @@ end end - describe 'instance methods' do + context 'resource (instance) methods' do + + describe '#flush' do before :each do - allow(provider.eapi).to receive(:Tacacs).and_return(eapi) + allow(api).to receive(:update_server).and_return(true) + allow(api).to receive(:remove_server).and_return(true) end - describe '#flush' do context 'after create' do subject do provider.create provider.flush end - it 'calls PuppetX::Eos::Tacacs#update_server' do - expect(eapi).to receive(:update_server) + it 'calls #update_server' do + expect(api).to receive(:update_server) .with(include(hostname: '127.0.0.1')) .and_return(true) subject @@ -81,8 +120,8 @@ let(:resource_override) do { single_connection: :true } end - it 'calls PuppetX::Eos::Tacacs#update_server with multiplex: true' do - expect(eapi).to receive(:update_server) + it 'calls #update_server with multiplex: true' do + expect(api).to receive(:update_server) .with(include(multiplex: true)) .and_return(true) subject @@ -100,8 +139,8 @@ provider.flush end - it 'calls PuppetX::Eos::Tacacs#remove_server' do - expect(eapi).to receive(:remove_server) + it 'calls remove_server' do + expect(api).to receive(:remove_server) .with(include(hostname: '127.0.0.1')) .and_return(true) subject diff --git a/spec/unit/puppet/provider/tacacs_server_group/eos_spec.rb b/spec/unit/puppet/provider/tacacs_server_group/eos_spec.rb index 7f3e215..1929bc8 100644 --- a/spec/unit/puppet/provider/tacacs_server_group/eos_spec.rb +++ b/spec/unit/puppet/provider/tacacs_server_group/eos_spec.rb @@ -1,9 +1,41 @@ -# encoding: utf-8 +# +# Copyright (c) 2014, Arista Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Arista Networks nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require 'spec_helper' +include FixtureHelpers + describe Puppet::Type.type(:tacacs_server_group).provider(:eos) do - let(:api) { PuppetX::Eos::Tacacs.new(PuppetX::Eos::Eapi.new) } + let(:type) { Puppet::Type.type(:tacacs_server_group) } # Allow text cases to override resource attributes @@ -22,18 +54,25 @@ let(:resource) { type.new(resource_hash) } let(:provider) { described_class.new(resource) } + let(:api) { double('aaa') } + + def aaa + aaa = Fixtures[:aaa] + return aaa if aaa + fixture('eapi_tacacs_server_groups') + end + + before :each do + allow(described_class.node).to receive(:api).with('aaa').and_return(api) + allow(provider.node).to receive(:api).with('aaa').and_return(api) + end + it_behaves_like 'provider exists?' - describe 'class methods' do - before :each do - allow(described_class.eapi).to receive(:Tacacs).and_return(api) - end + context 'class methods' do + before { allow(api).to receive(:get).and_return(aaa) } describe '.instances' do - before :each do - allow(api).to receive(:server_groups) - .and_return(fixture(:eapi_tacacs_server_groups)) - end subject { described_class.instances } @@ -42,21 +81,23 @@ end end - describe 'instance methods' do - before :each do - allow(provider.eapi).to receive(:Tacacs).and_return(api) - end + context 'resource (instance) methods' do describe '#flush' do + before :each do + allow(api).to receive_message_chain(:groups, :create).and_return(true) + allow(api).to receive_message_chain(:groups, :set_servers).and_return(true) + allow(api).to receive_message_chain(:groups, :delete).and_return(true) + end + context 'after create' do subject do provider.create - provider.flush end - it 'calls PuppetX::Eos::Tacacs#update_server_group' do - expect(api).to receive(:update_server_group) - .with(include(name: 'TAC-SV9')) + it 'calls #create' do + expect(api).to receive_message_chain(:groups, :create) + .with('TAC-SV9', 'tacacs+') .and_return(true) subject end @@ -69,12 +110,11 @@ subject do provider.destroy - provider.flush end - it 'calls PuppetX::Eos::Tacacs#remove_server_group' do - expect(api).to receive(:remove_server_group) - .with(include(name: 'TAC-SV9')) + it 'calls #delete' do + expect(api).to receive_message_chain(:groups, :delete) + .with(include('TAC-SV9')) .and_return(true) subject end @@ -84,12 +124,11 @@ subject do provider.create provider.servers=[] - provider.flush end - it 'calls PuppetX::Eos::Tacacs#update_server_group' do - expect(api).to receive(:update_server_group) - .with(include(name: 'TAC-SV9', servers: [])) + it 'calls #set_servers' do + expect(api).to receive_message_chain(:groups, :set_servers) + .with('TAC-SV9', []) .and_return(true) subject end