Skip to content

Commit

Permalink
Merge pull request #298 from shortdudey123/fix_test_failures
Browse files Browse the repository at this point in the history
Fix test failures (FoodCritic and Rubocop)
  • Loading branch information
brianbianco authored Oct 25, 2016
2 parents 60b0be9 + 15efcdc commit a80931f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 73 deletions.
10 changes: 5 additions & 5 deletions attributes/redis_sentinel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# limitations under the License.
#

config_dir = '/etc/redis'

if node['platform_family'] == 'freebsd'
config_dir = '/usr/local/etc/redis'
end
config_dir = if node['platform_family'] == 'freebsd'
'/usr/local/etc/redis'
else
'/etc/redis'
end

default['redisio']['sentinel_defaults'] = {
'user' => 'redis',
Expand Down
66 changes: 28 additions & 38 deletions providers/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def configure
# Merge the configuration defaults with the provided array of configurations provided
current = current_defaults_hash.merge(current_instance_hash)

#Merge in the default maxmemory
node_memory_kb = node["memory"]["total"]
#On BSD platforms Ohai reports total memory as a Fixnum
# Merge in the default maxmemory
node_memory_kb = node['memory']['total']
# On BSD platforms Ohai reports total memory as a Fixnum
if node_memory_kb.is_a? String
node_memory_kb.slice! "kB"
node_memory_kb.slice! 'kB'
node_memory_kb = node_memory_kb.to_i
end

Expand Down Expand Up @@ -86,13 +86,13 @@ def configure
maxmemory = (node_memory_kb * 1024 * percent_factor / new_resource.servers.length).round.to_s
end

if current['ulimit'] == 0
descriptors = current['maxclients'] + 32
elsif current['ulimit'] > current['maxclients']
descriptors = current['ulimit']
else
descriptors = current['maxclients']
end
descriptors = if current['ulimit'] == 0
current['maxclients'] + 32
elsif current['ulimit'] > current['maxclients']
current['ulimit']
else
current['maxclients']
end

recipe_eval do
server_name = current['name'] || current['port']
Expand Down Expand Up @@ -175,10 +175,10 @@ def configure

# Setup the redis users descriptor limits
# Pending response on https://github.com/brianbianco/redisio/commit/4ee9aad3b53029cc3b6c6cf741f5126755e712cd#diff-8ae42a59a6f4e8dc5b4e6dd2d6a34eab
#TODO: ulimit cookbook v0.1.2 doesn't work with freeBSD
# TODO: ulimit cookbook v0.1.2 doesn't work with freeBSD
if current['ulimit'] && node['platform_family'] != 'freebsd' # ~FC023
user_ulimit current['user'] do
filehandle_limit descriptors
filehandle_limit descriptors
end
end

Expand Down Expand Up @@ -325,31 +325,21 @@ def configure
)
only_if { node['redisio']['job_control'] == 'upstart' }
end
template "/usr/local/etc/rc.d/redis#{server_name}" do
source 'redis.rcinit.erb'
cookbook 'redisio'
owner current['user']
group current['group']
mode '0755'
variables({
:name => server_name,
:bin_path => bin_path,
:job_control => node['redisio']['job_control'],
:port => current['port'],
:address => current['address'],
:user => current['user'],
:group => current['group'],
:maxclients => current['maxclients'],
:requirepass => current['requirepass'],
:shutdown_save => current['shutdown_save'],
:save => current['save'],
:configdir => current['configdir'],
:piddir => piddir,
:platform => node['platform'],
:unixsocket => current['unixsocket']
})
only_if { node['redisio']['job_control'] == 'rcinit' }
end
template "/usr/local/etc/rc.d/redis#{server_name}" do
source 'redis.rcinit.erb'
cookbook 'redisio'
owner current['user']
group current['group']
mode '0755'
variables(
name: server_name,
bin_path: bin_path,
user: current['user'],
configdir: current['configdir'],
piddir: piddir
)
only_if { node['redisio']['job_control'] == 'rcinit' }
end
end
end # servers each loop
end
Expand Down
6 changes: 3 additions & 3 deletions providers/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
package_resource.run_action(:install)
new_resource.updated_by_last_action(true) if package_resource.updated_by_last_action?

# freeBSD does not support from source since ports does not support versioning (without a lot of hassle)
elsif node.platform_family == 'freebsd'
fail 'Source install not supported for freebsd'
# freeBSD does not support from source since ports does not support versioning (without a lot of hassle)
elsif node['platform_family'] == 'freebsd'
raise 'Source install not supported for freebsd'
# Tarball install
else
@tarball = "#{new_resource.base_name}#{new_resource.version}.#{new_resource.artifact_type}"
Expand Down
35 changes: 16 additions & 19 deletions providers/sentinel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,22 @@ def configure
)
only_if { node['redisio']['job_control'] == 'upstart' }
end
#TODO: fix for freebsd
template "/usr/local/etc/rc.d/redis_#{sentinel_name}" do
source 'sentinel.rcinit.erb'
cookbook 'redisio'
owner current['user']
group current['group']
mode '0755'
variables({
:name => sentinel_name,
:bin_path => bin_path,
:job_control => node['redisio']['job_control'],
:user => current['user'],
:group => current['group'],
:configdir => current['configdir'],
:piddir => piddir,
:platform => node['platform'],
})
only_if { node['redisio']['job_control'] == 'rcinit' }
end
# TODO: fix for freebsd
template "/usr/local/etc/rc.d/redis_#{sentinel_name}" do
source 'sentinel.rcinit.erb'
cookbook 'redisio'
owner current['user']
group current['group']
mode '0755'
variables(
name: sentinel_name,
bin_path: bin_path,
user: current['user'],
configdir: current['configdir'],
piddir: piddir
)
only_if { node['redisio']['job_control'] == 'rcinit' }
end
end
end # servers each loop
end
Expand Down
2 changes: 1 addition & 1 deletion recipes/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
when 'rcinit'
service "redis#{server_name}" do
provider Chef::Provider::Service::Freebsd
supports :start => true, :stop => true, :restart => true, :status => true
supports start: true, stop: true, restart: true, status: true
end
else
Chef::Log.error('Unknown job control type, no service resource created!')
Expand Down
2 changes: 0 additions & 2 deletions test/integration/default/serverspec/redisio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
['save a', 'save b', 'save c'].each do |m|
its(:content) { should match(m) }
end

end
else
describe file('/etc/redis/savetest.conf') do
Expand All @@ -20,6 +19,5 @@
['save a', 'save b', 'save c'].each do |m|
its(:content) { should match(m) }
end

end
end
4 changes: 2 additions & 2 deletions test/integration/helpers/serverspec/redisio_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"redis#{redis_port}"
end
expect(service service_name).to be_enabled
expect(service service_name).to be_running, :if => os[:family] != 'fedora'
expect(service service_name).to be_running, if: os[:family] != 'fedora'
end

# We use grep and commands here, since serverspec only checks systemd on fedora 20
# instead of also being able to check sysv style init systems.
describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), :if => os[:family] == 'fedora' do
describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), if: os[:family] == 'fedora' do
its(:exit_status) { should eq(0) }
end

Expand Down
5 changes: 2 additions & 3 deletions test/integration/helpers/serverspec/sentinel_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
"redis_sentinel_#{redis_cluster_name}"
end
expect(service name).to be_enabled
expect(service name).to be_running, :if => os[:family] != 'fedora'
expect(service name).to be_running, if: os[:family] != 'fedora'
end

describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), :if => os[:family] == 'fedora' do
describe command("ps aux | grep -v grep | grep 'redis-server' | grep '*:#{redis_port}'"), if: os[:family] == 'fedora' do
its(:exit_status) { should eq(0) }
end


it "is listening on port #{redis_port}" do
expect(port redis_port).to be_listening
end
Expand Down

0 comments on commit a80931f

Please sign in to comment.