summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-25 22:14:34 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-28 17:34:55 -0700
commitb8cffc2e35c662585acff290b27f072c60105479 (patch)
tree5ad0dec08499bf48c9b29e3122d9b96587c75ec7 /lib
parent68656820438b84d433ae9015b953790f67ddf0ec (diff)
downloadchef-b8cffc2e35c662585acff290b27f072c60105479.tar.gz
Add test for nonzero systemctl exit code
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/chef_class.rb5
-rw-r--r--lib/chef/mixin/which.rb2
-rw-r--r--lib/chef/platform/service_helpers.rb23
3 files changed, 18 insertions, 12 deletions
diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb
index b18c3fbdde..6a0d09ec96 100644
--- a/lib/chef/chef_class.rb
+++ b/lib/chef/chef_class.rb
@@ -226,5 +226,10 @@ class Chef
end
end
+ # @api private Only for test dependency injection; not evenly implemented as yet.
+ def self.path_to(path)
+ path
+ end
+
reset!
end
diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb
index 4179c97b62..4e1c516386 100644
--- a/lib/chef/mixin/which.rb
+++ b/lib/chef/mixin/which.rb
@@ -28,7 +28,7 @@ class Chef
paths = ENV['PATH'].split(File::PATH_SEPARATOR) + extra_path
paths.each do |path|
filename = File.join(path, cmd)
- return filename if File.executable?(filename)
+ return filename if File.executable?(Chef.path_to(filename))
end
false
end
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb
index 6b44478725..8a840b91c3 100644
--- a/lib/chef/platform/service_helpers.rb
+++ b/lib/chef/platform/service_helpers.rb
@@ -19,6 +19,7 @@
# XXX: mixing shellout into a mixin into classes has to be code smell
require 'chef/mixin/shell_out'
require 'chef/mixin/which'
+require 'chef/chef_class'
class Chef
class Platform
@@ -44,24 +45,24 @@ class Chef
def service_resource_providers
@service_resource_providers ||= [].tap do |service_resource_providers|
- if ::File.exist?("/usr/sbin/update-rc.d")
+ if ::File.exist?(Chef.path_to("/usr/sbin/update-rc.d"))
service_resource_providers << :debian
end
- if ::File.exist?("/usr/sbin/invoke-rc.d")
+ if ::File.exist?(Chef.path_to("/usr/sbin/invoke-rc.d"))
service_resource_providers << :invokercd
end
- if ::File.exist?("/sbin/insserv")
+ if ::File.exist?(Chef.path_to("/sbin/insserv"))
service_resource_providers << :insserv
end
# debian >= 6.0 has /etc/init but does not have upstart
- if ::File.exist?("/etc/init") && ::File.exist?("/sbin/start")
+ if ::File.exist?(Chef.path_to("/etc/init")) && ::File.exist?(Chef.path_to("/sbin/start"))
service_resource_providers << :upstart
end
- if ::File.exist?("/sbin/chkconfig")
+ if ::File.exist?(Chef.path_to("/sbin/chkconfig"))
service_resource_providers << :redhat
end
@@ -75,23 +76,23 @@ class Chef
def config_for_service(service_name)
configs = []
- if ::File.exist?("/etc/init.d/#{service_name}")
+ if ::File.exist?(Chef.path_to("/etc/init.d/#{service_name}"))
configs << :initd
end
- if ::File.exist?("/etc/init/#{service_name}.conf")
+ if ::File.exist?(Chef.path_to("/etc/init/#{service_name}.conf"))
configs << :upstart
end
- if ::File.exist?("/etc/xinetd.d/#{service_name}")
+ if ::File.exist?(Chef.path_to("/etc/xinetd.d/#{service_name}"))
configs << :xinetd
end
- if ::File.exist?("/etc/rc.d/#{service_name}")
+ if ::File.exist?(Chef.path_to("/etc/rc.d/#{service_name}"))
configs << :etc_rcd
end
- if ::File.exist?("/usr/local/etc/rc.d/#{service_name}")
+ if ::File.exist?(Chef.path_to("/usr/local/etc/rc.d/#{service_name}"))
configs << :usr_local_etc_rcd
end
@@ -117,7 +118,7 @@ class Chef
end
def systemd_sanity_check?
- systemctl_path && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd"
+ systemctl_path && File.exist?(Chef.path_to("/proc/1/comm")) && File.open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd"
end
def extract_systemd_services(command)