Skip to content

Commit

Permalink
Merge pull request sous-chefs#196 from sethrosenblum/helpers_namespace
Browse files Browse the repository at this point in the history
[sous-chefsGH-195] Helpers module conflict.
  • Loading branch information
bflad committed Jul 23, 2014
2 parents a5f8ed8 + bc46ae7 commit e6707e8
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 68 deletions.
2 changes: 1 addition & 1 deletion files/default/tests/minitest/sysv_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include Helpers::Docker

it 'starts docker' do
if Helpers::Docker.using_docker_io_package?(node)
if Docker::Helpers.using_docker_io_package?(node)
service('docker.io').must_be_running
else
service('docker').must_be_running
Expand Down
2 changes: 1 addition & 1 deletion files/default/tests/minitest/upstart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include Helpers::Docker

it 'starts docker' do
if Helpers::Docker.using_docker_io_package?(node)
if Docker::Helpers.using_docker_io_package?(node)
service('docker.io').must_be_running
else
service('docker').must_be_running
Expand Down
66 changes: 33 additions & 33 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
require 'chef/mixin/shell_out'
include Chef::Mixin::ShellOut

# Helpers module
module Helpers
def binary_installed?(bin)
!shell_out("which #{bin}").error?
end

#
# Pairs with the dep_check recipe.
#
# Parameters:
# @execption - DockerCookbook exception to throw
# @action - symbol representing which action to take
# @msg - string of message to print
#
def alert_on_error(exception, action, msg)
case action
when :warn
Chef::Log.warn <<-MSG
WARNING: #{exception}
#{msg}
MSG
when :fatal
fail exception, msg
end
end

# Helpers::Docker module
module Docker
# Docker module
module Docker
# Docker::Helpers module
module Helpers
# Exception to signify that the Docker daemon is not yet ready to handle
# docker commands.
class DockerNotReady < StandardError
Expand All @@ -51,7 +27,7 @@ class CommandTimeout < RuntimeError; end

# Daemon service name
def self.docker_service(node)
return 'docker.io' if Helpers::Docker.using_docker_io_package?(node)
return 'docker.io' if Docker::Helpers.using_docker_io_package?(node)
'docker'
end

Expand All @@ -61,7 +37,7 @@ def self.docker_settings_file(node)
when 'debian'
'/etc/default/docker'
when 'ubuntu'
if Helpers::Docker.using_docker_io_package?(node)
if Docker::Helpers.using_docker_io_package?(node)
'/etc/default/docker.io'
else
'/etc/default/docker'
Expand All @@ -75,7 +51,7 @@ def self.docker_settings_file(node)
def self.docker_upstart_conf_file(node)
case node['platform']
when 'ubuntu'
if Helpers::Docker.using_docker_io_package?(node)
if Docker::Helpers.using_docker_io_package?(node)
'/etc/init/docker.io.conf'
else
'/etc/init/docker.conf'
Expand All @@ -87,7 +63,7 @@ def self.docker_upstart_conf_file(node)

# Path to docker executable
def self.executable(node)
return '/usr/bin/docker.io' if Helpers::Docker.using_docker_io_package?(node)
return '/usr/bin/docker.io' if Docker::Helpers.using_docker_io_package?(node)
"#{node['docker']['install_dir']}/docker"
end

Expand All @@ -98,7 +74,7 @@ def self.using_docker_io_package?(node)
end

def self.daemon_cli_args(node)
daemon_options = Helpers::Docker.cli_args(
daemon_options = Docker::Helpers.cli_args(
'api-enable-cors' => node['docker']['api_enable_cors'],
'bip' => node['docker']['bip'],
'bridge' => node['docker']['bridge'],
Expand Down Expand Up @@ -272,6 +248,30 @@ def execute_cmd!(cmd, timeout = new_resource.cmd_timeout)
cmd.error!
cmd
end

def binary_installed?(bin)
!shell_out("which #{bin}").error?
end

#
# Pairs with the dep_check recipe.
#
# Parameters:
# @execption - DockerCookbook exception to throw
# @action - symbol representing which action to take
# @msg - string of message to print
#
def alert_on_error(exception, action, msg)
case action
when :warn
Chef::Log.warn <<-MSG
WARNING: #{exception}
#{msg}
MSG
when :fatal
fail exception, msg
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion providers/container.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Helpers::Docker
include Docker::Helpers

def load_current_resource
@current_resource = Chef::Resource::DockerContainer.new(new_resource)
Expand Down
2 changes: 1 addition & 1 deletion providers/image.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Helpers::Docker
include Docker::Helpers

def load_current_resource
wait_until_ready!
Expand Down
2 changes: 1 addition & 1 deletion providers/registry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Helpers::Docker
include Docker::Helpers

def load_current_resource
@current_resource = Chef::Resource::DockerRegistry.new(new_resource)
Expand Down
2 changes: 1 addition & 1 deletion recipes/binary.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
remote_file Helpers::Docker.executable(node) do
remote_file Docker::Helpers.executable(node) do
source node['docker']['binary']['url']
checksum node['docker']['binary']['checksum']
owner 'root'
Expand Down
2 changes: 1 addition & 1 deletion recipes/dep_check.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
::Chef::Recipe.send(:include, Helpers)
::Chef::Recipe.send(:include, Docker::Helpers)

action = node['docker']['alert_on_error_action']

Expand Down
2 changes: 1 addition & 1 deletion recipes/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
action node['docker']['package']['action'].intern
end
when 'debian', 'ubuntu'
if Helpers::Docker.using_docker_io_package? node
if Docker::Helpers.using_docker_io_package? node
link '/usr/local/bin/docker' do
to '/usr/bin/docker.io'
end
Expand Down
6 changes: 3 additions & 3 deletions recipes/runit.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Package installation automatically starts docker service
# So let's stop and disable it.
service 'lxc-docker' do
pattern Helpers::Docker.executable(node)
pattern Docker::Helpers.executable(node)
provider Chef::Provider::Service::Upstart if node['platform'] == 'ubuntu'
service_name Helpers::Docker.docker_service(node)
service_name Docker::Helpers.docker_service(node)
action [:stop, :disable]
end

Expand All @@ -12,6 +12,6 @@
runit_service 'docker' do
default_logger true
options(
'daemon_options' => Helpers::Docker.daemon_cli_args(node)
'daemon_options' => Docker::Helpers.daemon_cli_args(node)
)
end
2 changes: 1 addition & 1 deletion recipes/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
owner 'root'
group 'root'
variables(
'daemon_options' => Helpers::Docker.daemon_cli_args(node)
'daemon_options' => Docker::Helpers.daemon_cli_args(node)
)
notifies :run, 'execute[systemctl-daemon-reload]', :immediately
notifies :restart, 'service[docker]', :immediately
Expand Down
4 changes: 2 additions & 2 deletions recipes/sysv.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker_settings_file = Helpers::Docker.docker_settings_file(node)
docker_settings_file = Docker::Helpers.docker_settings_file(node)

template '/etc/init.d/docker' do
source 'docker.sysv.erb'
Expand All @@ -13,7 +13,7 @@
owner 'root'
group 'root'
variables(
'daemon_options' => Helpers::Docker.daemon_cli_args(node)
'daemon_options' => Docker::Helpers.daemon_cli_args(node)
)
notifies :restart, 'service[docker]', :immediately
end
Expand Down
8 changes: 4 additions & 4 deletions recipes/upstart.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker_settings_file = Helpers::Docker.docker_settings_file(node)
docker_upstart_conf_file = Helpers::Docker.docker_upstart_conf_file(node)
docker_service = Helpers::Docker.docker_service(node)
docker_settings_file = Docker::Helpers.docker_settings_file(node)
docker_upstart_conf_file = Docker::Helpers.docker_upstart_conf_file(node)
docker_service = Docker::Helpers.docker_service(node)

template docker_upstart_conf_file do
source 'docker.conf.erb'
Expand All @@ -15,7 +15,7 @@
owner 'root'
group 'root'
variables(
'daemon_options' => Helpers::Docker.daemon_cli_args(node)
'daemon_options' => Docker::Helpers.daemon_cli_args(node)
)
# DEPRECATED: stop and start only necessary for 0.x cookbook upgrades
# Default docker Upstart job now sources default file for DOCKER_OPTS
Expand Down
4 changes: 2 additions & 2 deletions templates/debian/docker-container.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### BEGIN INIT INFO
# Provides: <%= @service_name %>
# Required-Start: $network
# Required-Stop:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop <%= @service_name %>
Expand All @@ -13,7 +13,7 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="<%= @service_name %>"
NAME="<%= @service_name %>"
DAEMON="<%= Helpers::Docker.executable node %>"
DAEMON="<%= Docker::Helpers.executable node %>"
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
Expand Down
10 changes: 5 additions & 5 deletions templates/default/docker-container.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ author "Docker Chef Cookbook"
start on filesystem and started docker
stop on runlevel [!2345]

# We don't want to TERM the `docker wait` process so we fake the signal
# We don't want to TERM the `docker wait` process so we fake the signal
# we send to it. The pre-stop script issues the `docker stop` command
# which causes the `docker wait` process to exit
kill signal CONT

# Due to a bug in upstart we need to set the modes we consider
# successful exists https://bugs.launchpad.net/upstart/+bug/568288
normal exit 0 CONT

respawn

exec <%= Helpers::Docker.executable(node) %> wait <%= @service_name %>
exec <%= Docker::Helpers.executable(node) %> wait <%= @service_name %>

pre-start script
# Wait for docker to finish starting up first.
Expand All @@ -31,9 +31,9 @@ pre-start script
inotifywait -t 2 -e create $(dirname $FILE)
done
<% end -%>
<%= Helpers::Docker.executable(node) %> start <%= @service_name %> || true
<%= Docker::Helpers.executable(node) %> start <%= @service_name %> || true
end script

pre-stop script
<%= Helpers::Docker.executable(node) %> stop -t <%= @cmd_timeout %> <%= @service_name %>
<%= Docker::Helpers.executable(node) %> stop -t <%= @cmd_timeout %> <%= @service_name %>
end script
6 changes: 3 additions & 3 deletions templates/default/docker-container.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ After=docker.service

[Service]
Restart=always
ExecStartPre=-<%= Helpers::Docker.executable(node) %> start <%= @service_name %>
ExecStart=<%= Helpers::Docker.executable(node) %> wait <%= @service_name %>
ExecStop=<%= Helpers::Docker.executable(node) %> stop -t <%= @cmd_timeout %> <%= @service_name %>
ExecStartPre=-<%= Docker::Helpers.executable(node) %> start <%= @service_name %>
ExecStart=<%= Docker::Helpers.executable(node) %> wait <%= @service_name %>
ExecStop=<%= Docker::Helpers.executable(node) %> stop -t <%= @cmd_timeout %> <%= @service_name %>

[Install]
WantedBy=local.target
2 changes: 1 addition & 1 deletion templates/default/docker-container.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Source function library.
. /etc/rc.d/init.d/functions

exec="<%= Helpers::Docker.executable(node) %>"
exec="<%= Docker::Helpers.executable(node) %>"
prog="<%= @service_name %>"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
Expand Down
2 changes: 1 addition & 1 deletion templates/default/docker.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ExecStartPre=/usr/sbin/sysctl -w net.ipv4.ip_forward=1
<% if node['docker']['ipv6_forward'] -%>
ExecStartPre=/usr/sbin/sysctl -w net.ipv6.conf.all.forwarding=1
<% end -%>
ExecStart=<%= Helpers::Docker.executable(node) %> -d<%= @daemon_options %>
ExecStart=<%= Docker::Helpers.executable(node) %> -d<%= @daemon_options %>
Restart=on-failure

[Install]
Expand Down
2 changes: 1 addition & 1 deletion templates/default/docker.sysconfig.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Docker Upstart and SysVinit configuration file

# Customize location of Docker binary (especially for development testing).
DOCKER="<%= Helpers::Docker.executable(node) %>"
DOCKER="<%= Docker::Helpers.executable(node) %>"

<% if node['docker']['logfile'] -%>
DOCKER_LOGFILE=<%= node['docker']['logfile'] %>
Expand Down
2 changes: 1 addition & 1 deletion templates/default/docker.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Source function library.
. /etc/rc.d/init.d/functions

exec="<%= Helpers::Docker.executable(node) %>"
exec="<%= Docker::Helpers.executable(node) %>"
prog="docker"
<% if node['docker']['pidfile'] -%>
pidfile="<%= node['docker']['pidfile'] %>"
Expand Down
4 changes: 2 additions & 2 deletions templates/default/sv-docker-container-run.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
exec 2>&1
exec <%= Helpers::Docker.executable(node) %> start <%= @options['service_name'] %> || true
exec <%= Helpers::Docker.executable(node) %> attach <%= @options['service_name'] %>
exec <%= Docker::Helpers.executable(node) %> start <%= @options['service_name'] %> || true
exec <%= Docker::Helpers.executable(node) %> attach <%= @options['service_name'] %>
2 changes: 1 addition & 1 deletion templates/default/sv-docker-run.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export HTTP_PROXY=<%= node['docker']['http_proxy'] %>
<% if node['docker']['tmpdir'] -%>
export TMPDIR=<%= node['docker']['tmpdir'] %>
<% end -%>
exec <%= Helpers::Docker.executable(node) %> -d<%= @options['daemon_options'] %>
exec <%= Docker::Helpers.executable(node) %> -d<%= @options['daemon_options'] %>

0 comments on commit e6707e8

Please sign in to comment.