From 49e35a99f6cfec120405efb387f7313dbd432c02 Mon Sep 17 00:00:00 2001 From: Sean OMeara Date: Wed, 18 Dec 2013 12:33:59 -0500 Subject: [PATCH] [COOK-3267] - Improving tests, updating kitchen scaffolding, improving style --- .kitchen.yml | 73 ++++++---- .rubocop.yml | 8 ++ Gemfile | 16 ++- attributes/default.rb | 90 ++++++------ libraries/provider_runit_service.rb | 85 +++++------ libraries/resource_runit_service.rb | 81 +++++------ metadata.rb | 20 +-- recipes/default.rb | 98 ++++++------- test/cookbooks/runit-other_test/metadata.rb | 12 +- .../default/tests/minitest/default_test.rb | 27 +++- .../default/tests/minitest/service_test.rb | 21 ++- .../default/tests/minitest/support/helpers.rb | 1 + test/cookbooks/runit_test/metadata.rb | 12 +- test/cookbooks/runit_test/recipes/default.rb | 2 +- test/cookbooks/runit_test/recipes/service.rb | 104 +++++++------- .../libraries/provider_runit_service_spec.rb | 136 +++++++++--------- .../libraries/resource_runit_service_spec.rb | 78 +++++----- test/spec/spec_helper.rb | 2 +- 18 files changed, 448 insertions(+), 418 deletions(-) create mode 100644 .rubocop.yml diff --git a/.kitchen.yml b/.kitchen.yml index 0d79fe8..c6b7bdd 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,42 +1,67 @@ --- driver_plugin: vagrant +driver_plugin: digitalocean driver_config: - require_chef_omnibus: 11.4.4 + digitalocean_client_id: <%= ENV['DIGITAL_OCEAN_CLIENT_ID'] %> + digitalocean_api_key: <%= ENV['DIGITAL_OCEAN_API_KEY'] %> + aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> + aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> + aws_ssh_key_id: <%= ENV['AWS_KEYPAIR_NAME'] %> + ssh_key: <%= ENV['AWS_PRIVATE_KEY_PATH'] %> + rackspace_username: <%= ENV['RACKSPACE_USERNAME'] %> + rackspace_api_key: <%= ENV['RACKSPACE_API_KEY'] %> + require_chef_omnibus: latest platforms: -- name: ubuntu-12.10 +- name: centos-5.8 + driver_plugin: digitalocean driver_config: - box: opscode-ubuntu-12.10 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.10_provisionerless.box - run_list: ["recipe[apt]"] + image_id: 1601 + flavor_id: 63 + region_id: 1 + ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> -- name: ubuntu-12.04 +- name: centos-6.4 + driver_plugin: digitalocean driver_config: - box: opscode-ubuntu-12.04 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box - run_list: ["recipe[apt]"] + image_id: 562354 + flavor_id: 63 + region_id: 1 + ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> -- name: ubuntu-10.04 +- name: amazon-2013.09 + driver_plugin: ec2 driver_config: - box: opscode-ubuntu-10.04 - box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box - run_list: ["recipe[apt]"] + image_id: ami-3be4bc52 + username: ec2-user -- name: debian-6 - driver_config: - box: opscode-debian-6 - box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_debian-6.0.7_provisionerless.box - run_list: ["recipe[apt]"] +# - name: fedora-19 +# driver_plugin: digitalocean +# driver_config: +# image_id: 696598 +# flavor_id: 63 +# region_id: 1 +# ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> -- name: centos-5.9 +- name: ubuntu-1004 + driver_plugin: digitalocean driver_config: - box: opscode-centos-5.9 - box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box + image_id: 14097 + flavor_id: 63 + region_id: 1 + ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> + run_list: + - recipe[apt] -- name: centos-6.4 +- name: ubuntu-1204 + driver_plugin: digitalocean driver_config: - box: opscode-centos-6.4 - box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box + image_id: 284203 + flavor_id: 63 + region_id: 1 + ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> + run_list: + - recipe[apt] suites: - name: default diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f18e2d2 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +Encoding: + Enabled: false + +LineLength: + Max: 200 + +HashSyntax: + EnforcedStyle: hash_rockets diff --git a/Gemfile b/Gemfile index 6509746..10aa735 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,14 @@ source 'https://rubygems.org' -group :test do - gem 'chef' - gem 'rake' - gem 'rspec' - gem 'foodcritic' +gem 'berkshelf', '~> 2.0' +gem 'chefspec', '~> 3.0' +gem 'foodcritic', '~> 3.0' +gem 'rubocop' + +group :integration do + gem 'test-kitchen', '~> 1.0' + gem 'kitchen-vagrant', '~> 0.11' + gem 'kitchen-digitalocean' + gem 'kitchen-ec2' end + diff --git a/attributes/default.rb b/attributes/default.rb index eed6325..d29ce70 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -4,67 +4,59 @@ # # Copyright 2008-2009, Opscode, Inc. # -# Licensed under the Apache License, Version 2.0 (the "License"); +# Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -case node["platform_family"] -when "debian" - - default["runit"]["sv_bin"] = "/usr/bin/sv" - default["runit"]["chpst_bin"] = "/usr/bin/chpst" - default["runit"]["service_dir"] = "/etc/service" - default["runit"]["sv_dir"] = "/etc/sv" - default["runit"]["lsb_init_dir"] = "/etc/init.d" - default["runit"]["executable"] = "/sbin/runit" - - if node["platform"] == "debian" - - default["runit"]["start"] = "runsvdir-start" - default["runit"]["stop"] = "" - default["runit"]["reload"] = "" - - elsif node["platform"] == "ubuntu" - - default["runit"]["start"] = "start runsvdir" - default["runit"]["stop"] = "stop runsvdir" - default["runit"]["reload"] = "reload runsvdir" - +case node['platform_family'] +when 'debian' + default['runit']['sv_bin'] = '/usr/bin/sv' + default['runit']['chpst_bin'] = '/usr/bin/chpst' + default['runit']['service_dir'] = '/etc/service' + default['runit']['sv_dir'] = '/etc/sv' + default['runit']['lsb_init_dir'] = '/etc/init.d' + default['runit']['executable'] = '/sbin/runit' + + if node['platform'] == 'debian' + default['runit']['start'] = 'runsvdir-start' + default['runit']['stop'] = '' + default['runit']['reload'] = '' + elsif node['platform'] == 'ubuntu' + default['runit']['start'] = 'start runsvdir' + default['runit']['stop'] = 'stop runsvdir' + default['runit']['reload'] = 'reload runsvdir' end -when "rhel" - - default["runit"]["sv_bin"] = "/sbin/sv" - default["runit"]["chpst_bin"] = "/sbin/chpst" - default["runit"]["service_dir"] = "/etc/service" - default["runit"]["sv_dir"] = "/etc/sv" - default["runit"]["lsb_init_dir"] = "/etc/init.d" - default["runit"]["executable"] = "/sbin/runit" - default["runit"]["use_package_from_yum"] = false - - default["runit"]["start"] = "/etc/init.d/runit-start start" - default["runit"]["stop"] = "/etc/init.d/runit-start stop" - default["runit"]["reload"] = "/etc/init.d/runit-start reload" - -when "gentoo" - - default["runit"]["sv_bin"] = "/usr/bin/sv" - default["runit"]["chpst_bin"] = "/usr/bin/chpst" - default["runit"]["service_dir"] = "/var/service" - default["runit"]["sv_dir"] = "/etc/sv" - default["runit"]["lsb_init_dir"] = "/etc/init.d" - default["runit"]["executable"] = "/sbin/runit" - default["runit"]["start"] = "/etc/init.d/runit-start start" - default["runit"]["stop"] = "/etc/init.d/runit-start stop" - default["runit"]["reload"] = "/etc/init.d/runit-start reload" +when 'rhel' + default['runit']['sv_bin'] = '/sbin/sv' + default['runit']['chpst_bin'] = '/sbin/chpst' + default['runit']['service_dir'] = '/etc/service' + default['runit']['sv_dir'] = '/etc/sv' + default['runit']['lsb_init_dir'] = '/etc/init.d' + default['runit']['executable'] = '/sbin/runit' + default['runit']['use_package_from_yum'] = false + default['runit']['start'] = '/etc/init.d/runit-start start' + default['runit']['stop'] = '/etc/init.d/runit-start stop' + default['runit']['reload'] = '/etc/init.d/runit-start reload' + +when 'gentoo' + default['runit']['sv_bin'] = '/usr/bin/sv' + default['runit']['chpst_bin'] = '/usr/bin/chpst' + default['runit']['service_dir'] = '/var/service' + default['runit']['sv_dir'] = '/etc/sv' + default['runit']['lsb_init_dir'] = '/etc/init.d' + default['runit']['executable'] = '/sbin/runit' + default['runit']['start'] = '/etc/init.d/runit-start start' + default['runit']['stop'] = '/etc/init.d/runit-start stop' + default['runit']['reload'] = '/etc/init.d/runit-start reload' end diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index c14b6f8..23c1658 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -34,6 +34,7 @@ class Chef class Provider class Service class Runit < Chef::Provider::Service + # refactor this whole thing into a Chef11 LWRP include Chef::Mixin::ShellOut def initialize(*args) @@ -67,7 +68,7 @@ def load_current_resource no_runit_message = "Could not locate main runit sv_bin at \"#{new_resource.sv_bin}\". " no_runit_message << "Did you remember to install runit before declaring a \"runit_service\" resource? " no_runit_message << "\n\nTry adding the following to the top of your recipe:\n\ninclude_recipe \"runit\"" - raise no_runit_message + fail no_runit_message end @current_resource.running(running?) @@ -94,9 +95,9 @@ def action_enable end load_new_resource_state @new_resource.enabled(true) - restart_service if @new_resource.restart_on_update and run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update and log_run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update and log_config_file.updated_by_last_action? + restart_service if @new_resource.restart_on_update && run_script.updated_by_last_action? + restart_log_service if @new_resource.restart_on_update && log_run_script.updated_by_last_action? + restart_log_service if @new_resource.restart_on_update && log_config_file.updated_by_last_action? end def configure_service @@ -120,7 +121,7 @@ def configure_service unless new_resource.env.empty? Chef::Log.debug("Setting up environment files for #{new_resource.service_name}") env_dir.run_action(:create) - env_files.each {|file| file.run_action(:create)} + env_files.each { |file| file.run_action(:create) } else Chef::Log.debug("Environment not specified for #{new_resource.service_name}, continuing") end @@ -142,7 +143,7 @@ def configure_service unless new_resource.control.empty? Chef::Log.debug("Creating control signal scripts for #{new_resource.service_name}") control_dir.run_action(:create) - control_signal_files.each {|file| file.run_action(:create)} + control_signal_files.each { |file| file.run_action(:create) } else Chef::Log.debug("Control signals not specified for #{new_resource.service_name}, continuing") end @@ -157,16 +158,16 @@ def enable_service service_link.run_action(:create) Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") - until ::FileTest.pipe?("#{service_dir_name}/supervise/ok") do + until ::FileTest.pipe?("#{service_dir_name}/supervise/ok") sleep 1 - Chef::Log.debug(".") + Chef::Log.debug('.') end if new_resource.log Chef::Log.debug("waiting until named pipe #{service_dir_name}/log/supervise/ok exists.") - until ::FileTest.pipe?("#{service_dir_name}/log/supervise/ok") do + until ::FileTest.pipe?("#{service_dir_name}/log/supervise/ok") sleep 1 - Chef::Log.debug(".") + Chef::Log.debug('.') end end end @@ -238,7 +239,7 @@ def action_usr2 private - def runit_send_signal(signal, friendly_name=nil) + def runit_send_signal(signal, friendly_name = nil) friendly_name ||= signal converge_by("send #{friendly_name} to #{new_resource}") do shell_out!("#{new_resource.sv_bin} #{sv_args}#{signal} #{service_dir_name}") @@ -258,11 +259,11 @@ def log_running? end def enabled? - ::File.exists?(::File.join(service_dir_name, "run")) + ::File.exists?(::File.join(service_dir_name, 'run')) end def log_service_name - ::File.join(new_resource.service_name, "log") + ::File.join(new_resource.service_name, 'log') end def sv_dir_name @@ -289,10 +290,8 @@ def template_cookbook end def default_logger_content - return <<-EOF -#!/bin/sh -exec svlogd -tt /var/log/#{new_resource.service_name} -EOF + '#!/bin/sh +exec svlogd -tt /var/log/#{new_resource.service_name}' end # @@ -316,9 +315,7 @@ def run_script @run_script.source("sv-#{new_resource.run_template_name}-run.erb") @run_script.cookbook(template_cookbook) @run_script.mode(00755) - if new_resource.options.respond_to?(:has_key?) - @run_script.variables(:options => new_resource.options) - end + @run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) @run_script end @@ -355,27 +352,25 @@ def default_log_dir def log_run_script return @log_run_script unless @log_run_script.nil? if new_resource.default_logger - @log_run_script = Chef::Resource::File.new(::File.join( sv_dir_name, - 'log', - 'run' ), - run_context) + @log_run_script = Chef::Resource::File.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) @log_run_script.content(default_logger_content) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @log_run_script.mode(00755) else - @log_run_script = Chef::Resource::Template.new(::File.join( sv_dir_name, - 'log', - 'run' ), - run_context) + @log_run_script = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @log_run_script.mode(00755) @log_run_script.source("sv-#{new_resource.log_template_name}-log-run.erb") @log_run_script.cookbook(template_cookbook) - if new_resource.options.respond_to?(:has_key?) - @log_run_script.variables(:options => new_resource.options) - end + @log_run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) end @log_run_script end @@ -386,9 +381,9 @@ def log_config_file @log_config_file.owner(new_resource.owner) @log_config_file.group(new_resource.group) @log_config_file.mode(00644) - @log_config_file.cookbook("runit") - @log_config_file.source("log-config.erb") - @log_config_file.variables({ + @log_config_file.cookbook('runit') + @log_config_file.source('log-config.erb') + @log_config_file.variables( :size => new_resource.log_size, :num => new_resource.log_num, :min => new_resource.log_min, @@ -397,7 +392,7 @@ def log_config_file :socket => new_resource.log_socket, :prefix => new_resource.log_prefix, :append => new_resource.log_config_append - }) + ) @log_config_file end @@ -430,9 +425,7 @@ def check_script @check_script.source("sv-#{new_resource.check_script_template_name}-check.erb") @check_script.cookbook(template_cookbook) @check_script.mode(00755) - if new_resource.options.respond_to?(:has_key?) - @check_script.variables(:options => new_resource.options) - end + @check_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) @check_script end @@ -444,9 +437,7 @@ def finish_script @finish_script.mode(00755) @finish_script.source("sv-#{new_resource.finish_script_template_name}-finish.erb") @finish_script.cookbook(template_cookbook) - if new_resource.options.respond_to?(:has_key?) - @finish_script.variables(:options => new_resource.options) - end + @finish_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) @finish_script end @@ -462,18 +453,16 @@ def control_dir def control_signal_files return @control_signal_files unless @control_signal_files.nil? @control_signal_files = new_resource.control.map do |signal| - control_signal_file = Chef::Resource::Template.new(::File.join( sv_dir_name, - 'control', - signal), - run_context) + control_signal_file = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'control', signal), + run_context + ) control_signal_file.owner(new_resource.owner) control_signal_file.group(new_resource.group) control_signal_file.mode(00755) control_signal_file.source("sv-#{new_resource.control_template_names[signal]}-#{signal}.erb") control_signal_file.cookbook(template_cookbook) - if new_resource.options.respond_to?(:has_key?) - control_signal_file.variables(:options => new_resource.options) - end + control_signal_file.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) control_signal_file end @control_signal_files diff --git a/libraries/resource_runit_service.rb b/libraries/resource_runit_service.rb index 9ca4374..82ba049 100644 --- a/libraries/resource_runit_service.rb +++ b/libraries/resource_runit_service.rb @@ -23,9 +23,9 @@ class Chef class Resource + # Missing top-level class documentation comment class RunitService < Chef::Resource::Service - - def initialize(name, run_context=nil) + def initialize(name, run_context = nil) super runit_node = runit_attributes_from_node(run_context) @resource_name = :runit_service @@ -93,40 +93,36 @@ def initialize(name, run_context=nil) end end - def sv_bin(arg=nil) + def sv_bin(arg = nil) set_or_return(:sv_bin, arg, :kind_of => [String]) end - def sv_dir(arg=nil) + def sv_dir(arg = nil) set_or_return(:sv_dir, arg, :kind_of => [String, FalseClass]) end - def sv_timeout(arg=nil) + def sv_timeout(arg = nil) set_or_return(:sv_timeout, arg, :kind_of => [Fixnum]) end - def sv_verbose(arg=nil) + def sv_verbose(arg = nil) set_or_return(:sv_verbose, arg, :kind_of => [TrueClass, FalseClass]) end - def service_dir(arg=nil) + def service_dir(arg = nil) set_or_return(:service_dir, arg, :kind_of => [String]) end - def lsb_init_dir(arg=nil) + def lsb_init_dir(arg = nil) set_or_return(:lsb_init_dir, arg, :kind_of => [String]) end - def control(arg=nil) + def control(arg = nil) set_or_return(:control, arg, :kind_of => [Array]) end - def options(arg=nil) - if @env.empty? - opts = @options - else - opts = @options.merge!(:env_dir => ::File.join(@sv_dir, @service_name, 'env')) - end + def options(arg = nil) + @env.empty? ? opts = @options : opts = @options.merge!(:env_dir => ::File.join(@sv_dir, @service_name, 'env')) set_or_return( :options, arg, @@ -135,60 +131,60 @@ def options(arg=nil) ) end - def env(arg=nil) + def env(arg = nil) set_or_return(:env, arg, :kind_of => [Hash]) end - def log(arg=nil) + def log(arg = nil) set_or_return(:log, arg, :kind_of => [TrueClass, FalseClass]) end - def cookbook(arg=nil) + def cookbook(arg = nil) set_or_return(:cookbook, arg, :kind_of => [String]) end - def finish(arg=nil) + def finish(arg = nil) set_or_return(:finish, arg, :kind_of => [TrueClass, FalseClass]) end - def check(arg=nil) + def check(arg = nil) set_or_return(:check, arg, :kind_of => [TrueClass, FalseClass]) end - def owner(arg=nil) + def owner(arg = nil) set_or_return(:owner, arg, :regex => [Chef::Config[:user_valid_regex]]) end - def group(arg=nil) + def group(arg = nil) set_or_return(:group, arg, :regex => [Chef::Config[:group_valid_regex]]) end - def default_logger(arg=nil) + def default_logger(arg = nil) set_or_return(:default_logger, arg, :kind_of => [TrueClass, FalseClass]) end - def restart_on_update(arg=nil) + def restart_on_update(arg = nil) set_or_return(:restart_on_update, arg, :kind_of => [TrueClass, FalseClass]) end - def run_template_name(arg=nil) + def run_template_name(arg = nil) set_or_return(:run_template_name, arg, :kind_of => [String]) end - alias :template_name :run_template_name + alias_method :template_name, :run_template_name - def log_template_name(arg=nil) + def log_template_name(arg = nil) set_or_return(:log_template_name, arg, :kind_of => [String]) end - def check_script_template_name(arg=nil) + def check_script_template_name(arg = nil) set_or_return(:check_script_template_name, arg, :kind_of => [String]) end - def finish_script_template_name(arg=nil) + def finish_script_template_name(arg = nil) set_or_return(:finish_script_template_name, arg, :kind_of => [String]) end - def control_template_names(arg=nil) + def control_template_names(arg = nil) set_or_return( :control_template_names, arg, @@ -204,47 +200,48 @@ def set_control_template_names @control_template_names end - def sv_templates(arg=nil) + def sv_templates(arg = nil) set_or_return(:sv_templates, arg, :kind_of => [TrueClass, FalseClass]) end - def log_size(arg=nil) + def log_size(arg = nil) set_or_return(:log_size, arg, :kind_of => [Integer]) end - def log_num(arg=nil) + def log_num(arg = nil) set_or_return(:log_num, arg, :kind_of => [Integer]) end - def log_min(arg=nil) + def log_min(arg = nil) set_or_return(:log_min, arg, :kind_of => [Integer]) end - def log_timeout(arg=nil) + def log_timeout(arg = nil) set_or_return(:log_timeout, arg, :kind_of => [Integer]) end - def log_processor(arg=nil) + def log_processor(arg = nil) set_or_return(:log_processor, arg, :kind_of => [String]) end - def log_socket(arg=nil) + def log_socket(arg = nil) set_or_return(:log_socket, arg, :kind_of => [String, Hash]) end - def log_prefix(arg=nil) + def log_prefix(arg = nil) set_or_return(:log_prefix, arg, :kind_of => [String]) end - def log_config_append(arg=nil) + def log_config_append(arg = nil) set_or_return(:log_config_append, arg, :kind_of => [String]) end def runit_attributes_from_node(run_context) - runit_attr = if run_context && run_context.node - run_context.node[:runit] + if run_context && run_context.node + runit_attr = run_context.node[:runit] + else + runit_attr == {} end - runit_attr || {} end end end diff --git a/metadata.rb b/metadata.rb index 3be88d1..b618d8f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,16 +1,18 @@ -name "runit" -maintainer "Opscode, Inc." -maintainer_email "cookbooks@opscode.com" -license "Apache 2.0" -description "Installs runit and provides runit_service definition" +name 'runit' +maintainer 'Opscode, Inc.' +maintainer_email 'cookbooks@opscode.com' +license 'Apache 2.0' +description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.4.7" +version '1.4.7' -recipe "runit", "Installs and configures runit" +recipe 'runit', 'Installs and configures runit' %w{ ubuntu debian gentoo centos redhat amazon scientific oracle enterpriseenterprise }.each do |os| supports os end -depends "build-essential" -depends "yum", '< 3.0' +depends 'build-essential' +depends 'yum', '~> 3.0' +depends 'yum-epel' + diff --git a/recipes/default.rb b/recipes/default.rb index 54431a1..020dd4b 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -4,123 +4,119 @@ # # Copyright 2008-2010, Opscode, Inc. # -# Licensed under the Apache License, Version 2.0 (the "License"); +# Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -service "runit" do +service 'runit' do action :nothing end -execute "start-runsvdir" do +execute 'start-runsvdir' do command value_for_platform( - "debian" => { "default" => "runsvdir-start" }, - "ubuntu" => { "default" => "start runsvdir" }, - "gentoo" => { "default" => "/etc/init.d/runit-start start" } + 'debian' => { 'default' => 'runsvdir-start' }, + 'ubuntu' => { 'default' => 'start runsvdir' }, + 'gentoo' => { 'default' => '/etc/init.d/runit-start start' } ) action :nothing end -execute "runit-hup-init" do - command "telinit q" - only_if "grep ^SV /etc/inittab" +execute 'runit-hup-init' do + command 'telinit q' + only_if 'grep ^SV /etc/inittab' action :nothing end -case node["platform_family"] -when "rhel" +case node['platform_family'] +when 'rhel' if node['runit']['use_package_from_yum'] package 'runit' else - include_recipe "build-essential" + include_recipe 'build-essential' # `rpmdevtools` is in EPEL repo in EL <= 5 - include_recipe "yum::epel" if node["platform_version"].to_i <= 5 + include_recipe 'yum-epel' if node['platform_version'].to_i == 5 packages = %w{rpm-build rpmdevtools tar gzip} packages.each do |p| package p end - if node["platform_version"].to_i >= 6 - package "glibc-static" + if node['platform_version'].to_i >= 6 + package 'glibc-static' else - package "buildsys-macros" + package 'buildsys-macros' end rpm_installed = "rpm -qa | grep -q '^runit'" cookbook_file "#{Chef::Config[:file_cache_path]}/runit-2.1.1.tar.gz" do - source "runit-2.1.1.tar.gz" + source 'runit-2.1.1.tar.gz' not_if rpm_installed - notifies :run, "bash[rhel_build_install]", :immediately + notifies :run, 'bash[rhel_build_install]', :immediately end - bash "rhel_build_install" do - user "root" + bash 'rhel_build_install' do + user 'root' cwd Chef::Config[:file_cache_path] code <<-EOH tar xzf runit-2.1.1.tar.gz cd runit-2.1.1 ./build.sh - rpm_root_dir=`rpm --eval "%{_rpmdir}"` - rpm -ivh "$rpm_root_dir/runit-2.1.1.rpm" + rpm_root_dir=`rpm --eval '%{_rpmdir}'` + rpm -ivh '/root/rpmbuild/RPMS/runit-2.1.1.rpm' EOH action :run not_if rpm_installed end end -when "debian","gentoo" +when 'debian', 'gentoo' - if platform?("gentoo") - template "/etc/init.d/runit-start" do - source "runit-start.sh.erb" + if platform?('gentoo') + template '/etc/init.d/runit-start' do + source 'runit-start.sh.erb' mode 0755 end - service "runit-start" do + service 'runit-start' do action :nothing end end - package "runit" do + package 'runit' do action :install - if platform?("ubuntu", "debian") - response_file "runit.seed" - end + response_file 'runit.seed' if platform?('ubuntu', 'debian') notifies value_for_platform( - "debian" => { "4.0" => :run, "default" => :nothing }, - "ubuntu" => { - "default" => :nothing, - "9.04" => :run, - "8.10" => :run, - "8.04" => :run }, - "gentoo" => { "default" => :run } - ), "execute[start-runsvdir]", :immediately + 'debian' => { '4.0' => :run, 'default' => :nothing }, + 'ubuntu' => { + 'default' => :nothing, + '9.04' => :run, + '8.10' => :run, + '8.04' => :run }, + 'gentoo' => { 'default' => :run } + ), 'execute[start-runsvdir]', :immediately notifies value_for_platform( - "debian" => { "squeeze/sid" => :run, "default" => :nothing }, - "default" => :nothing - ), "execute[runit-hup-init]", :immediately - if platform?("gentoo") - notifies :enable, "service[runit-start]" - end + 'debian' => { 'squeeze/sid' => :run, 'default' => :nothing }, + 'default' => :nothing + ), 'execute[runit-hup-init]', :immediately + notifies :enable, 'service[runit-start]' if platform?('gentoo') end - if node["platform"] =~ /ubuntu/i && node["platform_version"].to_f <= 8.04 - cookbook_file "/etc/event.d/runsvdir" do - source "runsvdir" + if node['platform'] =~ /ubuntu/i && node['platform_version'].to_f <= 8.04 + cookbook_file '/etc/event.d/runsvdir' do + source 'runsvdir' mode 0644 - notifies :run, "execute[start-runsvdir]", :immediately - only_if do ::File.directory?("/etc/event.d") end + notifies :run, 'execute[start-runsvdir]', :immediately + only_if { ::File.directory?('/etc/event.d') } end end end diff --git a/test/cookbooks/runit-other_test/metadata.rb b/test/cookbooks/runit-other_test/metadata.rb index 08bb2da..ddcf83c 100644 --- a/test/cookbooks/runit-other_test/metadata.rb +++ b/test/cookbooks/runit-other_test/metadata.rb @@ -1,6 +1,6 @@ -name "runit-other_test" -maintainer "Opscode, Inc." -maintainer_email "cookbooks@opscode.com" -license "Apache 2.0" -description "This cookbook is used with test-kitchen to test the parent, runit cookbok" -version "1.0.0" +name 'runit-other_test' +maintainer 'Opscode, Inc.' +maintainer_email 'cookbooks@opscode.com' +license 'Apache 2.0' +description 'This cookbook is used with test-kitchen to test the parent, runit cookbok' +version '1.0.0' diff --git a/test/cookbooks/runit_test/files/default/tests/minitest/default_test.rb b/test/cookbooks/runit_test/files/default/tests/minitest/default_test.rb index 30f079b..eff2539 100644 --- a/test/cookbooks/runit_test/files/default/tests/minitest/default_test.rb +++ b/test/cookbooks/runit_test/files/default/tests/minitest/default_test.rb @@ -4,14 +4,14 @@ # # Copyright 2012, Opscode, Inc. # -# Licensed under the Apache License, Version 2.0 (the "License"); +# Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. @@ -19,12 +19,29 @@ require File.expand_path('../support/helpers', __FILE__) -describe "runit_test::default" do +describe 'runit_test::default' do include Helpers::RunitTest - describe "packages" do + describe 'packages' do it 'has been installed' do - package("runit").must_be_installed + package('runit').must_be_installed end end + + it 'The service runitsvdir should be running' do + service('runsvdir').must_be_running if node['platform_family'] == 'ubuntu' + end + + it 'The directory /etc/service should exist' do + directory('/etc/service').must_exist + end + + it 'It should have a file called runsvdir in /etc/event.d' do + file('/etc/event.d/runsvdir').must_exist if node['platform'] == 'ubuntu' + end + + it 'It should have a file called run in /etc/sv/getty-5' do + file('/etc/sv/getty-5/run').must_exist if node['platform_family'] == 'debian' + end + end diff --git a/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb b/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb index 081571f..8a20d43 100644 --- a/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb +++ b/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb @@ -4,14 +4,14 @@ # # Copyright 2012, Opscode, Inc. # -# Licensed under the Apache License, Version 2.0 (the "License"); +# Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. @@ -19,7 +19,7 @@ require File.expand_path('../support/helpers', __FILE__) -describe "runit_test::service" do +describe 'runit_test::service' do include Helpers::RunitTest it 'creates a service with the defaults' do @@ -70,7 +70,7 @@ it 'creates a service that sets options for the templates' do service('template-options').must_be_running - file('/etc/service/template-options/run').must_match("# Options are delicious") + file('/etc/service/template-options/run').must_match('# Options are delicious') end it 'creates a service that uses control signal files' do @@ -87,8 +87,8 @@ it 'creates a service running by a normal user in its runsvdir' do floyds_app = shell_out( "#{node['runit']['sv_bin']} status /home/floyd/service/floyds-app", - :user => "floyd", - :cwd => "/home/floyd" + :user => 'floyd', + :cwd => '/home/floyd' ) assert floyds_app.stdout.include?('run:') file('/home/floyd/service/floyds-app/run').must_exist.with(:owner, 'floyd') @@ -110,9 +110,7 @@ it 'creates a service that should exist but be disabled' do file('/etc/sv/exist-disabled/run').must_exist - unless node['platform'] == 'gentoo' - link('/etc/service/exist-disabled').wont_exist - end + link('/etc/service/exist-disabled').wont_exist unless node['platform'] == 'gentoo' end it 'can use templates from another cookbook' do @@ -120,9 +118,8 @@ end it 'creates a service that has its own run scripts' do - if node['platform_family'] == 'rhel' - skip "RHEL platforms don't have a generally available package w/ runit scripts" - end + skip 'RHEL platforms dont ship runit scripts' if node['platform_family'] == 'rhel' + git_daemon = shell_out("#{node['runit']['sv_bin']} status /etc/service/git-daemon") assert git_daemon.stdout.include?('run:') link('/etc/service/git-daemon').must_exist.with( diff --git a/test/cookbooks/runit_test/files/default/tests/minitest/support/helpers.rb b/test/cookbooks/runit_test/files/default/tests/minitest/support/helpers.rb index 148315e..7d711c1 100644 --- a/test/cookbooks/runit_test/files/default/tests/minitest/support/helpers.rb +++ b/test/cookbooks/runit_test/files/default/tests/minitest/support/helpers.rb @@ -20,6 +20,7 @@ require 'chef/mixin/shell_out' module Helpers + # Missing top-level module documentation comment. module RunitTest include MiniTest::Chef::Assertions include MiniTest::Chef::Context diff --git a/test/cookbooks/runit_test/metadata.rb b/test/cookbooks/runit_test/metadata.rb index 07bc0b3..432e14b 100644 --- a/test/cookbooks/runit_test/metadata.rb +++ b/test/cookbooks/runit_test/metadata.rb @@ -1,6 +1,6 @@ -name "runit_test" -maintainer "Opscode, Inc." -maintainer_email "cookbooks@opscode.com" -license "Apache 2.0" -description "This cookbook is used with test-kitchen to test the parent, runit cookbok" -version "1.0.0" +name 'runit_test' +maintainer 'Opscode, Inc.' +maintainer_email 'cookbooks@opscode.com' +license 'Apache 2.0' +description 'This cookbook is used with test-kitchen to test the parent, runit cookbok' +version '1.0.0' diff --git a/test/cookbooks/runit_test/recipes/default.rb b/test/cookbooks/runit_test/recipes/default.rb index 2e01c15..21cf147 100644 --- a/test/cookbooks/runit_test/recipes/default.rb +++ b/test/cookbooks/runit_test/recipes/default.rb @@ -17,4 +17,4 @@ # limitations under the License. # -include_recipe "runit::default" +include_recipe 'runit::default' diff --git a/test/cookbooks/runit_test/recipes/service.rb b/test/cookbooks/runit_test/recipes/service.rb index 195859a..5b403e4 100644 --- a/test/cookbooks/runit_test/recipes/service.rb +++ b/test/cookbooks/runit_test/recipes/service.rb @@ -17,154 +17,154 @@ # limitations under the License. # -include_recipe "runit::default" +include_recipe 'runit::default' -package "netcat" do - package_name "nc" if platform_family?('rhel', 'fedora') +package 'netcat' do + package_name 'nc' if platform_family?('rhel', 'fedora') end # Create a normal user to run services later -group "floyd" +group 'floyd' -user "floyd" do - comment "Floyd the App Runner" - gid "floyd" - shell "/bin/bash" - home "/home/floyd" +user 'floyd' do + comment 'Floyd the App Runner' + gid 'floyd' + shell '/bin/bash' + home '/home/floyd' manage_home true supports :manage_home => true end -["sv", "service"].each do |dir| +%w{ sv service }.each do |dir| directory "/home/floyd/#{dir}" do - owner "floyd" - group "floyd" + owner 'floyd' + group 'floyd' recursive true end end # Create a service with all the fixin's -runit_service "plain-defaults" +runit_service 'plain-defaults' # Create a service that doesn't use the svlog -runit_service "no-svlog" do +runit_service 'no-svlog' do log false end # Create a service that uses the default svlog -runit_service "default-svlog" do +runit_service 'default-svlog' do default_logger true end # Create a service that has a check script -runit_service "checker" do +runit_service 'checker' do check true end # Create a service that has a finish script -runit_service "finisher" do +runit_service 'finisher' do finish true end # Create a service that uses env files -runit_service "env-files" do - env({"PATH" => "$PATH:/opt/chef/embedded/bin"}) +runit_service 'env-files' do + env('PATH' => '$PATH:/opt/chef/embedded/bin') end # Create a service that sets options for the templates -runit_service "template-options" do - options({:raspberry => "delicious"}) +runit_service 'template-options' do + options(:raspberry => 'delicious') end # Create a service that uses control signal files -runit_service "control-signals" do - control ["u"] +runit_service 'control-signals' do + control ['u'] end # Create a runsvdir service for a normal user -runit_service "runsvdir-floyd" +runit_service 'runsvdir-floyd' # Create a service with different timeout -runit_service "timer" do +runit_service 'timer' do sv_timeout 4 check true end # Create a service with verbose enabled -runit_service "chatterbox" do +runit_service 'chatterbox' do sv_verbose true end # # Create a service running by a normal user in its runsvdir -runit_service "floyds-app" do - sv_dir "/home/floyd/sv" - service_dir "/home/floyd/service" - owner "floyd" - group "floyd" +runit_service 'floyds-app' do + sv_dir '/home/floyd/sv' + service_dir '/home/floyd/service' + owner 'floyd' + group 'floyd' end # Create a service with differently named template files -runit_service "yerba" do - log_template_name "yerba-matte" - check_script_template_name "yerba-matte" - finish_script_template_name "yerba-matte" +runit_service 'yerba' do + log_template_name 'yerba-matte' + check_script_template_name 'yerba-matte' + finish_script_template_name 'yerba-matte' end -runit_service "yerba-alt" do - run_template_name "calabash" +runit_service 'yerba-alt' do + run_template_name 'calabash' default_logger true end # Note: this won't update the run script for the above due to # http://tickets.opscode.com/browse/COOK-2353 -# runit_service "the other name for yerba-alt" do -# service_name "yerba-alt" +# runit_service 'the other name for yerba-alt' do +# service_name 'yerba-alt' # default_logger true # end # Create a service that should exist but be disabled -runit_service "exist-disabled" +runit_service 'exist-disabled' -log "Created the exist-disabled service, now disable it" +log 'Created the exist-disabled service, now disable it' -runit_service "exist-disabled" do +runit_service 'exist-disabled' do action :disable end -runit_service "other-cookbook-templates" do - cookbook "runit-other_test" +runit_service 'other-cookbook-templates' do + cookbook 'runit-other_test' end -unless platform_family?("rhel") +unless platform_family?('rhel') # Create a service that has a package with its own service directory - package "git-daemon-run" + package 'git-daemon-run' - runit_service "git-daemon" do + runit_service 'git-daemon' do sv_templates false end end # Despite waiting for runit to create supervise/ok, sometimes services # are supervised, but not actually fully started -ruby_block "sleep 5s to allow services to be fully started" do +ruby_block 'sleep 5s to allow services to be fully started' do block do sleep 5 end end # Notify the plain defaults service as a normal service resource -file "/tmp/notifier" do +file '/tmp/notifier' do content Time.now.to_s notifies :restart, 'service[plain-defaults]', :immediately end # Test for COOK-2867 -link "/etc/init.d/cook-2867" do - to "/usr/bin/sv" +link '/etc/init.d/cook-2867' do + to '/usr/bin/sv' end -runit_service "cook-2867" do +runit_service 'cook-2867' do default_logger true end diff --git a/test/spec/libraries/provider_runit_service_spec.rb b/test/spec/libraries/provider_runit_service_spec.rb index 3f3f39b..4a897da 100644 --- a/test/spec/libraries/provider_runit_service_spec.rb +++ b/test/spec/libraries/provider_runit_service_spec.rb @@ -17,21 +17,21 @@ # limitations under the License. # -$:.unshift(File.join(File.dirname(__FILE__), '..')) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..')) require 'spec_helper' describe Chef::Provider::Service::Runit do subject(:provider) { Chef::Provider::Service::Runit.new(new_resource, run_context) } - let(:sv_bin) { "/usr/bin/sv" } - let(:service_name) { "getty.service" } - let(:service_dir) { "/etc/service" } + let(:sv_bin) { '/usr/bin/sv' } + let(:service_name) { 'getty.service' } + let(:service_dir) { '/etc/service' } let(:service_dir_name) { "#{service_dir}/#{service_name}" } let(:service_status_command) { "#{sv_bin} status #{service_name}" } - let(:run_script) { File.join(service_dir, service_name, "run") } - let(:log_run_script) { File.join(service_dir, service_name, "log", "run") } - let(:log_config_file) { File.join(service_dir, service_name, "log", "config") } + let(:run_script) { File.join(service_dir, service_name, 'run') } + let(:log_run_script) { File.join(service_dir, service_name, 'log', 'run') } + let(:log_config_file) { File.join(service_dir, service_name, 'log', 'config') } let(:node) do node = Chef::Node.new node.automatic['platform'] = 'ubuntu' @@ -51,69 +51,69 @@ provider.current_resource = current_resource end - describe "#load_current_resource" do + describe '#load_current_resource' do before do provider.unstub(:load_current_resource) end - describe "runit is not installed" do - it "raises an exception" do - lambda { provider.load_current_resource }.should raise_error + describe 'runit is not installed' do + it 'raises an exception' do + ->{ provider.load_current_resource }.should raise_error end end - context "runit is installed" do + context 'runit is installed' do let(:status_output) { "run: #{service_name}: (pid 29018) 3s; run: log: (pid 24470) 46882s" } before do File.stub(:exist?).with(sv_bin).and_return(true) File.stub(:executable?).with(sv_bin).and_return(true) - provider.stub(:shell_out). - with(service_status_command). - and_return(mock("ouput", :stdout => status_output, :exitstatus => 0)) + provider.stub(:shell_out) + .with(service_status_command) + .and_return(mock('ouput', :stdout => status_output, :exitstatus => 0)) provider.load_current_resource end - describe "parsing sv status output" do + describe 'parsing sv status output' do - context "returns a pid" do + context 'returns a pid' do let(:status_output) { "run: #{service_name}: (pid 29018) 3s; run: log: (pid 24470) 46882s" } - it "sets resource running state to true" do + it 'sets resource running state to true' do provider.current_resource.running.should be_true end end - context "returns an empty pid" do + context 'returns an empty pid' do let(:status_output) { "down: #{service_name}: 2s, normally up; run: log: (pid 24470) 46250s" } - it "sets resource running state to false" do + it 'sets resource running state to false' do provider.current_resource.running.should be_false end end end - describe "checking for service run script" do - context "service run script is present in service_dir" do + describe 'checking for service run script' do + context 'service run script is present in service_dir' do before do - File.stub(:exists?).with(run_script).and_return(true) + ::File.stub(:exists?).with(run_script).and_return(true) provider.load_current_resource end - it "sets resource enabled state to true" do + it 'sets resource enabled state to true' do provider.current_resource.enabled.should be_true end end - context "service run script is missing" do + context 'service run script is missing' do before do - File.stub(:exists?).with(run_script).and_return(false) + ::File.stub(:exists?).with(run_script).and_return(false) provider.load_current_resource end - it "sets resource enabled state to false" do + it 'sets resource enabled state to false' do provider.current_resource.enabled.should be_false end end @@ -121,8 +121,8 @@ end end - describe "actions" do - describe "start" do + describe 'actions' do + describe 'start' do before do provider.current_resource.running(false) @@ -182,7 +182,7 @@ end end - describe "action_enable" do + describe 'action_enable' do let(:sv_dir_name) { ::File.join(new_resource.sv_dir, new_resource.service_name) } before(:each) do @@ -253,7 +253,7 @@ provider.send(:env_dir).owner.should eq(new_resource.owner) provider.send(:env_dir).group.should eq(new_resource.group) provider.send(:env_dir).mode.should eq(00755) - new_resource.env({'PATH' => '$PATH:/usr/local/bin'}) + new_resource.env('PATH' => '$PATH:/usr/local/bin') provider.send(:env_files)[0].path.should eq(::File.join(sv_dir_name, 'env', 'PATH')) provider.send(:env_files)[0].owner.should eq(new_resource.owner) provider.send(:env_files)[0].group.should eq(new_resource.group) @@ -363,7 +363,7 @@ new_resource.sv_verbose(true) end - %w{start up once cont}.each do |action| + %w{start up once cont}.each do |action| it "pass a verbose argument on #{action} action to the sv binary" do provider.current_resource.running(false) provider.should_receive(:shell_out!).with("#{sv_bin} -v #{action} #{service_dir_name}") @@ -399,7 +399,7 @@ new_resource.sv_verbose(true) end - %w{start up once cont}.each do |action| + %w{ start up once cont }.each do |action| it "pass both timeout and verbose arguments on #{action} action to the sv binary" do provider.current_resource.running(false) provider.should_receive(:shell_out!).with("#{sv_bin} -w '60' -v #{action} #{service_dir_name}") @@ -447,50 +447,50 @@ provider.run_action(:enable) end - describe "run_script template changes" do + describe 'run_script template changes' do before do provider.stub(:configure_service) provider.stub(:enable_service) end - context "run_script is updated" do + context 'run_script is updated' do before { provider.send(:run_script).stub(:updated_by_last_action?).and_return(true) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "restarts the service" do + it 'restarts the service' do provider.should_receive(:restart_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_service) provider.run_action(:enable) end end end - context "run script is unchanged" do + context 'run script is unchanged' do before { provider.send(:run_script).stub(:updated_by_last_action?).and_return(false) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_service) provider.run_action(:enable) end @@ -498,50 +498,50 @@ end end - describe "log_run_script template changes" do + describe 'log_run_script template changes' do before do provider.stub(:configure_service) provider.stub(:enable_service) end - context "log_run_script is updated" do + context 'log_run_script is updated' do before { provider.send(:log_run_script).stub(:updated_by_last_action?).and_return(true) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "restarts the service" do + it 'restarts the service' do provider.should_receive(:restart_log_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end end end - context "log_run_script is unchanged" do + context 'log_run_script is unchanged' do before { provider.send(:log_run_script).stub(:updated_by_last_action?).and_return(false) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end @@ -549,50 +549,50 @@ end end - describe "log_config_file template changes" do + describe 'log_config_file template changes' do before do provider.stub(:configure_service) provider.stub(:enable_service) end - context "log_config_file is updated" do + context 'log_config_file is updated' do before { provider.send(:log_config_file).stub(:updated_by_last_action?).and_return(true) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "restarts the service" do + it 'restarts the service' do provider.should_receive(:restart_log_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end end end - context "log_config_file is unchanged" do + context 'log_config_file is unchanged' do before { provider.send(:log_config_file).stub(:updated_by_last_action?).and_return(false) } - context "restart_on_update attribute is true" do + context 'restart_on_update attribute is true' do before { new_resource.restart_on_update(true) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end end - context "restart_on_update attribute is false" do + context 'restart_on_update attribute is false' do before { new_resource.restart_on_update(false) } - it "does not restart the service" do + it 'does not restart the service' do provider.should_not_receive(:restart_log_service) provider.run_action(:enable) end @@ -620,14 +620,14 @@ end it 'creates the env dir and config files if env is set' do - new_resource.stub(:env).and_return({'PATH' => '/bin'}) + new_resource.stub(:env).and_return('PATH' => '/bin') provider.send(:env_dir).should_receive(:run_action).with(:create) provider.send(:env_files).should_receive(:each).once provider.run_action(:enable) end it 'creates the control dir and signal files if control is set' do - new_resource.stub(:control).and_return(['s', 'u']) + new_resource.stub(:control).and_return %w{ s u } provider.send(:control_dir).should_receive(:run_action).with(:create) provider.send(:control_signal_files).should_receive(:each).once provider.run_action(:enable) diff --git a/test/spec/libraries/resource_runit_service_spec.rb b/test/spec/libraries/resource_runit_service_spec.rb index 16b5c3a..8222c94 100644 --- a/test/spec/libraries/resource_runit_service_spec.rb +++ b/test/spec/libraries/resource_runit_service_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -$:.unshift(File.join(File.dirname(__FILE__), '..')) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..')) require 'spec_helper' describe Chef::Resource::RunitService do @@ -30,20 +30,20 @@ let(:run_context) { Chef::RunContext.new(node, {}, events) } its(:class) { should be Chef::Resource::RunitService } - its(:resource_name) { should eq(:runit_service)} + its(:resource_name) { should eq(:runit_service) } its(:provider) { should eq(Chef::Provider::Service::Runit) } its(:service_name) { should eq('getty.service') } its(:sv_dir) { should eq('/etc/sv') } - its(:sv_bin) { should eq("/usr/bin/sv") } - its(:lsb_init_dir) { should eq("/etc/init.d") } + its(:sv_bin) { should eq('/usr/bin/sv') } + its(:lsb_init_dir) { should eq('/etc/init.d') } its(:sv_timeout) { should eq(nil) } its(:sv_verbose) { should eq(false) } - describe "setting supported default values from node attributes" do - let(:sv_bin) { "/fake/bin/sv_bin" } - let(:sv_dir) { "/fake/sv_dir/path" } - let(:service_dir) { "/fake/service_dir" } - let(:lsb_init_dir) { "/fake/lsb_init_dir" } + describe 'setting supported default values from node attributes' do + let(:sv_bin) { '/fake/bin/sv_bin' } + let(:sv_dir) { '/fake/sv_dir/path' } + let(:service_dir) { '/fake/service_dir' } + let(:lsb_init_dir) { '/fake/lsb_init_dir' } let(:node) do node = Chef::Node.new node.set['runit']['sv_bin'] = sv_bin @@ -59,11 +59,11 @@ its(:lsb_init_dir) { should eq lsb_init_dir } end - describe "backward compatiblility hack" do + describe 'backward compatiblility hack' do let(:simple_service_name) { "service[#{service_name}]" } - it "creates a simple service with the same name" do + it 'creates a simple service with the same name' do resource_collection = resource.run_context.resource_collection simple_service = resource_collection.find(simple_service_name) simple_service.to_s.should eq(simple_service_name) @@ -102,24 +102,24 @@ end it 'has a control parameter that can be set as an array of service control characters' do - resource.control(['s', 'u']) - resource.control.should eq(['s', 'u']) + resource.control %w{ s u } + resource.control.should eq %w{ s u } end it 'has an options parameter that can be set as a hash of arbitrary options' do - resource.options({:binary => '/usr/bin/noodles'}) + resource.options(:binary => '/usr/bin/noodles') resource.options.should have_key(:binary) resource.options[:binary].should eq('/usr/bin/noodles') end it 'has an env parameter that can be set as a hash of environment variables' do - resource.env({'PATH' => '$PATH:/usr/local/bin'}) + resource.env('PATH' => '$PATH:/usr/local/bin') resource.env.should have_key('PATH') resource.env['PATH'].should include('/usr/local/bin') end it 'adds :env_dir to options if env is set' do - resource.env({'PATH' => '/bin'}) + resource.env('PATH' => '/bin') resource.options.should have_key(:env_dir) resource.options[:env_dir].should eq(::File.join(resource.sv_dir, resource.service_name, 'env')) end @@ -221,7 +221,7 @@ end it 'sets the control_template_names for each control character to the service_name by default' do - resource.control(['s', 'u']) + resource.control %w{ s u } resource.control_template_names.should have_key('s') resource.control_template_names.should have_key('u') resource.control_template_names['s'].should eq(resource.service_name) @@ -229,10 +229,10 @@ end it 'has a control_template_names parameter to allow custom template names for the control scripts' do - resource.control_template_names({ - 's' => 'banana_start', - 'u' => 'noodle_up' - }) + resource.control_template_names( + 's' => 'banana_start', + 'u' => 'noodle_up' + ) resource.control_template_names.should have_key('s') resource.control_template_names.should have_key('u') resource.control_template_names['s'].should eq('banana_start') @@ -272,43 +272,43 @@ resource.sv_verbose.should eq(true) end - it "has a log_size parameter to control the maximum log size" do - resource.log_size(1000000) - resource.log_size.should eq(1000000) + it 'has a log_size parameter to control the maximum log size' do + resource.log_size(1_000_000) + resource.log_size.should eq(1_000_000) end - it "has a log_num parameter to control the maximum number of logs" do + it 'has a log_num parameter to control the maximum number of logs' do resource.log_num(10) resource.log_num.should eq(10) end - it "has a log_min parameter to control the minimum number of logs" do + it 'has a log_min parameter to control the minimum number of logs' do resource.log_min(5) resource.log_min.should eq(5) end - it "has a log_timeout parameter to control the maximum age of a log file" do + it 'has a log_timeout parameter to control the maximum age of a log file' do resource.log_timeout(60 * 60) resource.log_timeout.should eq(60 * 60) end - it "has a log_processor parameter to allow logs to be fed through it after rotation" do - resource.log_processor("/usr/local/bin/process") - resource.log_processor.should eq("/usr/local/bin/process") + it 'has a log_processor parameter to allow logs to be fed through it after rotation' do + resource.log_processor('/usr/local/bin/process') + resource.log_processor.should eq('/usr/local/bin/process') end - it "has a log_socket parameter to allow log lines to be sent to a UDP socket" do - resource.log_socket("127.0.0.1:1514") - resource.log_socket.should eq("127.0.0.1:1514") + it 'has a log_socket parameter to allow log lines to be sent to a UDP socket' do + resource.log_socket('127.0.0.1:1514') + resource.log_socket.should eq('127.0.0.1:1514') end - it "has a log_prefix parameter to allow log lines to be prefixed with a fixed string" do - resource.log_prefix("myservice:") - resource.log_prefix.should eq("myservice:") + it 'has a log_prefix parameter to allow log lines to be prefixed with a fixed string' do + resource.log_prefix('myservice:') + resource.log_prefix.should eq('myservice:') end - it "has a log_config_append parameter to allow arbitrary configuration entries to be added to the configuration" do - resource.log_config_append("-bogus") - resource.log_config_append.should eq("-bogus") + it 'has a log_config_append parameter to allow arbitrary configuration entries to be added to the configuration' do + resource.log_config_append('-bogus') + resource.log_config_append.should eq('-bogus') end end diff --git a/test/spec/spec_helper.rb b/test/spec/spec_helper.rb index 4efe8f9..100360b 100644 --- a/test/spec/spec_helper.rb +++ b/test/spec/spec_helper.rb @@ -7,7 +7,7 @@ require 'chef/event_dispatch/base' require 'chef/event_dispatch/dispatcher' -$:.unshift(File.join(File.dirname(__FILE__), "..", "..", "libraries")) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'libraries')) require 'provider_runit_service' require 'resource_runit_service'