diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml index 42648a0..9b36b3e 100644 --- a/.kitchen.dokken.yml +++ b/.kitchen.dokken.yml @@ -1,7 +1,7 @@ --- driver: name: dokken - chef_version: latest + chef_version: 12.20.3 privileged: true transport: name: dokken @@ -82,6 +82,9 @@ suites: - name: default provisioner: policyfile: test/fixtures/policies/default.rb + - name: sentinel + provisioner: + policyfile: test/fixtures/policies/sentinel.rb - name: archive provisioner: policyfile: test/fixtures/policies/default.rb diff --git a/.kitchen.yml b/.kitchen.yml index 4ea8db2..172d4db 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -3,6 +3,7 @@ driver: name: vagrant provisioner: name: chef_zero + require_chef_omnibus: 12.20.3 verifier: name: inspec platforms: diff --git a/libraries/redis_installation_package.rb b/libraries/redis_installation_package.rb index 24c6133..3e952e5 100644 --- a/libraries/redis_installation_package.rb +++ b/libraries/redis_installation_package.rb @@ -103,7 +103,7 @@ def install_redis if node.platform_family?('debian') dpkg_autostart 'redis-server' do - action :nothing + action :create allow false end end @@ -112,7 +112,6 @@ def install_redis notifies :delete, init_file, :immediately version system_package_version if system_package_version if node.platform_family?('debian') - notifies :create, 'dpkg_autostart[redis-server]', :immediately options '-o Dpkg::Options::=--path-exclude=/etc/redis*' end end diff --git a/libraries/redis_sentinel.rb b/libraries/redis_sentinel.rb index f67ddb3..37dc5a3 100644 --- a/libraries/redis_sentinel.rb +++ b/libraries/redis_sentinel.rb @@ -48,7 +48,7 @@ class RedisSentinel < Chef::Resource attribute(:config_path, kind_of: String, default: '/etc/redis-sentinel.conf') # @!attribute config_mode # @return [String] - attribute(:config_mode, kind_of: String, default: '0440') + attribute(:config_mode, kind_of: String, default: '0740') # @see: https://github.com/antirez/redis/blob/3.2/sentinel.conf attribute(:sentinel_port, kind_of: Integer, default: 26_379) @@ -62,10 +62,10 @@ class RedisSentinel < Chef::Resource attribute(:sentinel_client_reconfig, kind_of: [String, NilClass], default: nil) def default_config_source - if parent.version - "#{parent.version.match(/\d\.\d/).first}/sentinel.conf.erb" + if matches = parent.options.fetch('version', '').match(/\d\.\d/) + "#{matches.first}/sentinel.conf.erb" else - 'sentinel.conf.erb' + '3.2/sentinel.conf.erb' end end end @@ -112,7 +112,7 @@ def action_disable # @api private def service_options(service) - service.command("#{new_resource.program} #{new_resource.config_path}") + service.command("#{new_resource.program} #{new_resource.config_path} --sentinel") service.directory(new_resource.directory) service.user(new_resource.user) end diff --git a/recipes/sentinel.rb b/recipes/sentinel.rb index 2059a1f..0ef16cb 100644 --- a/recipes/sentinel.rb +++ b/recipes/sentinel.rb @@ -11,8 +11,8 @@ redis_installation node['blp-redis']['sentinel']['service_name'] { version '' } -redis_sentinel node['redis']['sentinel']['service_name'] do - owner node['blp-redis']['service_owner'] +redis_sentinel node['blp-redis']['sentinel']['service_name'] do + user node['blp-redis']['service_user'] group node['blp-redis']['service_group'] node['blp-redis']['sentinel']['config'].each_pair { |k, v| send(k, v) } end diff --git a/test/fixtures/policies/_base.rb b/test/fixtures/policies/_base.rb index 4e31df2..cf47dd3 100644 --- a/test/fixtures/policies/_base.rb +++ b/test/fixtures/policies/_base.rb @@ -1,7 +1,6 @@ default_source :community default_source :chef_repo, '..' cookbook 'blp-redis', path: '../../..' -run_list 'blp-redis::default' named_run_list :centos, 'yum::default', 'yum-epel::default', run_list named_run_list :debian, 'apt::default', run_list named_run_list :freebsd, 'freebsd::default', run_list diff --git a/test/fixtures/policies/default.rb b/test/fixtures/policies/default.rb index 5a6ad59..6c139e5 100644 --- a/test/fixtures/policies/default.rb +++ b/test/fixtures/policies/default.rb @@ -1,2 +1,3 @@ name 'default' -instance_eval(IO.read(File.expand_path('../_base.rb', __FILE__))) +run_list 'blp-redis::default' +instance_eval(IO.read(File.expand_path('../_base.rb', __FILE__))) \ No newline at end of file diff --git a/test/fixtures/policies/sentinel.rb b/test/fixtures/policies/sentinel.rb index 407e714..43edeca 100644 --- a/test/fixtures/policies/sentinel.rb +++ b/test/fixtures/policies/sentinel.rb @@ -1,3 +1,3 @@ name 'sentinel' +run_list 'blp-redis::sentinel' instance_eval(IO.read(File.expand_path('../_base.rb', __FILE__))) -run_list << 'blp-redis::sentinel' diff --git a/test/integration/sentinel/default_spec.rb b/test/integration/sentinel/default_spec.rb index 7682cf7..3d69de9 100644 --- a/test/integration/sentinel/default_spec.rb +++ b/test/integration/sentinel/default_spec.rb @@ -4,9 +4,10 @@ it { should be_running } end -describe processes('redis-sentinel') do +describe processes('redis-server') do its('list.length') { should eq 1 } its('users') { should eq %w[redis] } + its('list.first.command') { should include '[sentinel]' } end describe group('redis') do @@ -18,7 +19,7 @@ its('group') { should eq 'redis' } end -describe file('/usr/bin/redis-sentinel') do +describe file('/usr/bin/redis-server') do it { should exist } it { should be_file } it { should be_executable.by_user 'redis' } @@ -29,5 +30,5 @@ it { should be_file } it { should be_owned_by 'redis' } it { should be_grouped_into 'redis' } - it { should be_mode 640 } + it { should be_mode 0740 } end