lib/jamie.rb in jamie-0.1.0.beta3 vs lib/jamie.rb in jamie-0.1.0.beta4
- old
+ new
@@ -162,11 +162,11 @@
# @return [Symbol] log level verbosity
def log_level
@log_level ||= begin
ENV['JAMIE_LOG'] && ENV['JAMIE_LOG'].downcase.to_sym ||
- Jamie::DEFAULT_LOG_LEVEL
+ Jamie::DEFAULT_LOG_LEVEL
end
end
def supervised
@supervised.nil? ? @supervised = true : @supervised
@@ -284,11 +284,11 @@
end
def platform_driver_hash(platform_name)
h = yaml[:platforms].find { |p| p[:name] == platform_name } || Hash.new
- h.select { |key, value| [ :driver_plugin, :driver_config ].include?(key) }
+ h.select { |key, value| [:driver_plugin, :driver_config].include?(key) }
end
def new_instance_logger(index)
level = Util.to_logger_level(self.log_level)
color = Color::COLORS[index % Color::COLORS.size].to_sym
@@ -353,11 +353,11 @@
{ :driver_plugin => DEFAULT_DRIVER_PLUGIN, :driver_config => {} }
end
def common_driver_hash
yaml.select do |key, value|
- [ :driver_plugin, :driver_config ].include?(key)
+ [:driver_plugin, :driver_config].include?(key)
end
end
end
# Default log level verbosity
@@ -372,11 +372,11 @@
:bright_cyan => 36, :bright_white => 37
}.freeze
COLORS = %w(
cyan yellow green magenta red blue bright_cyan bright_yellow
- bright_green bright_magenta bright_red, bright_blue
+ bright_green bright_magenta bright_red bright_blue
).freeze
def self.escape(name)
return "" if name.nil?
return "" unless ansi = ANSI[name]
@@ -561,11 +561,11 @@
end
private
def validate_options(opts)
- [ :name, :run_list ].each do |k|
+ [:name, :run_list].each do |k|
raise ClientError, "Suite#new requires option :#{k}" if opts[k].nil?
end
end
end
@@ -602,11 +602,11 @@
end
private
def validate_options(opts)
- [ :name ].each do |k|
+ [:name].each do |k|
raise ClientError, "Platform#new requires option :#{k}" if opts[k].nil?
end
end
end
@@ -790,11 +790,11 @@
end
private
def validate_options(opts)
- [ :suite, :platform, :driver, :jr, :logger ].each do |k|
+ [:suite, :platform, :driver, :jr, :logger].each do |k|
raise ClientError, "Instance#new requires option :#{k}" if opts[k].nil?
end
end
def setup_driver_mutex
@@ -836,11 +836,11 @@
def perform_action(verb, output_verb)
banner "#{output_verb} #{to_str}"
elapsed = action(verb) { |state| driver.public_send(verb, state) }
info("Finished #{output_verb.downcase} #{to_str}" +
- " #{Util.duration(elapsed.real)}.")
+ " #{Util.duration(elapsed.real)}.")
yield if block_given?
Actor.current
end
def action(what, &block)
@@ -925,11 +925,11 @@
end
end
private
- TRANSITIONS = [ :destroy, :create, :converge, :setup, :verify ]
+ TRANSITIONS = [:destroy, :create, :converge, :setup, :verify]
def self.index(transition)
if transition.nil?
0
else
@@ -951,11 +951,11 @@
# @param [String] suite_name name of suite on which to operate
# (**Required**)
# @param [Hash] opts optional configuration
# @option opts [TrueClass, FalseClass] :use_sudo whether or not to invoke
# sudo before commands requiring root access (default: `true`)
- def initialize(suite_name, opts = {:use_sudo => true})
+ def initialize(suite_name, opts = { :use_sudo => true })
validate_options(suite_name)
@suite_name = suite_name
@use_sudo = opts[:use_sudo]
end
@@ -970,11 +970,11 @@
# work needs to be performed
def setup_cmd
@setup_cmd ||= if local_suite_files.empty?
nil
else
- <<-INSTALL_CMD.gsub(/ {10}/, '')
+ <<-INSTALL_CMD.gsub(/^ {10}/, '')
#{sudo}#{ruby_bin} -e "$(cat <<"EOF"
#{install_script}
EOF
)"
#{sudo}#{jr_bin} install #{plugins.join(' ')}
@@ -992,11 +992,11 @@
# nil if no work needs to be performed.
def sync_cmd
@sync_cmd ||= if local_suite_files.empty?
nil
else
- <<-INSTALL_CMD.gsub(/ {10}/, '')
+ <<-INSTALL_CMD.gsub(/^ {10}/, '')
#{sudo}#{jr_bin} cleanup-suites
#{local_suite_files.map { |f| stream_file(f, remote_file(f)) }.join}
INSTALL_CMD
end
end
@@ -1051,11 +1051,11 @@
end
def stream_file(local_path, remote_path)
local_file = IO.read(local_path)
md5 = Digest::MD5.hexdigest(local_file)
- perms = sprintf("%o", File.stat(local_path).mode)[3,3]
+ perms = sprintf("%o", File.stat(local_path).mode)[3, 3]
jr_stream_file = "#{jr_bin} stream-file #{remote_path} #{md5} #{perms}"
<<-STREAMFILE.gsub(/^ {8}/, '')
echo "Uploading #{remote_path} (mode=#{perms})"
cat <<"__EOFSTREAM__" | #{sudo}#{jr_stream_file}
@@ -1113,22 +1113,22 @@
end
end
def self.symbolized_hash(obj)
if obj.is_a?(Hash)
- obj.inject({}) { |h, (k,v)| h[k.to_sym] = symbolized_hash(v) ; h }
+ obj.inject({}) { |h, (k, v)| h[k.to_sym] = symbolized_hash(v) ; h }
elsif obj.is_a?(Array)
obj.inject([]) { |a, v| a << symbolized_hash(v) ; a }
else
obj
end
end
def self.duration(total)
minutes = (total / 60).to_i
seconds = (total - (minutes * 60))
- "(%dm%.2fs)" % [ minutes, seconds ]
+ "(%dm%.2fs)" % [minutes, seconds]
end
end
# Mixin that wraps a command shell out invocation, providing a #run_command
# method.
@@ -1314,11 +1314,11 @@
if value.nil? || value.to_s.empty?
raise UserError, "#{klass}#config[:#{attr}] cannot be blank"
end
end
end
- @validations << [ attr, block ]
+ @validations << [attr, block]
end
def self.no_parallel_for(*methods)
Array(methods).each do |meth|
if ! ACTION_METHODS.include?(meth)
@@ -1389,11 +1389,11 @@
opts[:user_known_hosts_file] = "/dev/null"
opts[:paranoid] = false
opts[:password] = config[:password] if config[:password]
opts[:keys] = Array(config[:ssh_key]) if config[:ssh_key]
- [ state[:hostname], config[:username], opts ]
+ [state[:hostname], config[:username], opts]
end
def chef_home
"/tmp/jamie-chef-solo".freeze
end
@@ -1473,11 +1473,11 @@
def test_ssh(hostname)
socket = TCPSocket.new(hostname, config[:port])
IO.select([socket], nil, nil, 5)
rescue SocketError, Errno::ECONNREFUSED,
- Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError
+ Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError
sleep 2
false
rescue Errno::EPERM, Errno::ETIMEDOUT
false
ensure
@@ -1544,12 +1544,13 @@
def upload_roles(scp)
upload_path(scp, instance.suite.roles_path)
end
def upload_path(scp, path, dir = File.basename(path))
- scp.upload!(path, "#{chef_home}/#{dir}", :recursive => true
- ) do |ch, name, sent, total|
+ dest = "#{chef_home}/#{dir}"
+
+ scp.upload!(path, dest, :recursive => true) do |ch, name, sent, total|
if sent == total
info("Uploaded #{name.sub(%r{^#{path}/}, '')} (#{total} bytes)")
end
end
end
@@ -1591,11 +1592,12 @@
run_command "if ! command -v #{bin} >/dev/null; then exit 1; fi"
rescue Jamie::ShellOut::ShellCommandFailed
fatal("#{name} must be installed, add it to your Gemfile.")
raise UserError, "#{bin} command not found"
end
- run_command "#{bin} install --path #{tmpdir}"
+
+ Jamie.mutex.synchronize { run_command "#{bin} install --path #{tmpdir}" }
end
def cp_cookbooks(tmpdir)
FileUtils.cp_r(File.join(jamie_root, "cookbooks", "."), tmpdir)
cp_this_cookbook(tmpdir) if File.exists?(File.expand_path('metadata.rb'))
@@ -1626,10 +1628,10 @@
# @param metadata_file [String] path to a metadata.rb file
# @return [Array<String>] array containing the cookbook name and version
# attributes or nil values if they could not be determined
def self.extract(metadata_file)
mc = new(File.expand_path(metadata_file))
- [ mc[:name], mc[:version] ]
+ [mc[:name], mc[:version]]
end
# Creates a new instances and loads in the contents of the metdata.rb
# file. If you value your life, you may want to avoid reading the
# implementation.