Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Revert "Bootstrap and chef tasks are less chatty"
Browse files Browse the repository at this point in the history
This reverts commit 8253021.
  • Loading branch information
Ken Mayer committed Mar 18, 2013
1 parent 8eb4b87 commit a203773
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
4 changes: 2 additions & 2 deletions lib/lobot/cli.rb
Expand Up @@ -76,7 +76,7 @@ def certificate
desc "bootstrap", "Configures Lobot's master node"
def bootstrap
sync_bootstrap_script
master_server.system!("bash -l script/bootstrap_server.sh", logfile: 'bootstrap.log')
master_server.system!("bash -l script/bootstrap_server.sh")
rescue Errno::ECONNRESET
sleep 1
end
Expand All @@ -87,7 +87,7 @@ def chef
upload_soloist
sync_github_ssh_key
master_server.upload(File.expand_path('../../../templates/Gemfile-remote', __FILE__), 'Gemfile')
master_server.system!("bash -l -c 'rvm use 1.9.3; bundle install; soloist'", logfile: 'chef_run.log') rescue Errno::ECONNRESET
master_server.system!("bash -l -c 'rvm use 1.9.3; bundle install; soloist'") rescue Errno::ECONNRESET
sleep 1
end

Expand Down
33 changes: 12 additions & 21 deletions lib/lobot/sobo.rb
Expand Up @@ -17,23 +17,20 @@ def timeout
@timeout || 10000
end

def system(command, options = {})
ssh_popen4!(command, options)[2]
def system(command)
ssh_popen4!(command, true)[2]
end

def system!(command, options = {})
result = ssh_popen4!(command, options)
def system!(command)
result = ssh_popen4!(command, true)
raise(CommandFailed, "Failed: #{command}\n#{result[0]}\n\n#{result[1]}") unless result[2] == 0
end

def backtick(command)
ssh_popen4!(command)[0]
end

def ssh_popen4!(command, options = {})
logfile_path = options.fetch(:logfile, nil)
logfile = File.open(logfile_path, 'w') if logfile_path

def ssh_popen4!(command, streaming_output = false)
ssh = Net::SSH.start(ip, user, :keys => [key], :timeout => timeout, paranoid: false)
stdout_data = ""
stderr_data = ""
Expand All @@ -47,22 +44,22 @@ def ssh_popen4!(command, options = {})
end

channel.on_data do |ch,data|
if logfile
logfile << data
logfile.flush
if streaming_output
STDOUT << data
STDOUT.flush
end
stdout_data += data
end

channel.on_extended_data do |ch,type,data|
if logfile
logfile << data
logfile.flush
if streaming_output
STDERR << data
STDERR.flush
end
stderr_data += data
end

channel.on_request("exit-status") do |ch, data|
channel.on_request("exit-status") do |ch,data|
exit_code = data.read_long
end

Expand All @@ -72,12 +69,6 @@ def ssh_popen4!(command, options = {})
end
end
ssh.loop

if logfile
logfile.close
File.delete(logfile_path) if exit_code == 0
end

[stdout_data, stderr_data, exit_code, exit_signal]
end

Expand Down
17 changes: 1 addition & 16 deletions spec/lib/lobot/cli_spec.rb
Expand Up @@ -233,27 +233,12 @@ def builds
describe "#bootstrap", :slow do
before { cli.create_vagrant }

it "installs all necessary packages, installs rvm, and sets up the user" do
it "installs all necessary packages, installs rvm and sets up the user" do
cli.bootstrap
sobo.backtick("dpkg --get-selections").should include("libncurses5-dev")
sobo.backtick("ls /usr/local/rvm/").should_not be_empty
sobo.backtick("groups ubuntu").should include("rvm")
end

context 'when there are no errors' do
it "writes a log file and cleans it up" do
cli.bootstrap
File.exists?('bootstrap.log').should_not be
end
end

context 'when there are errors' do
it "keeps the log file" do
Net::SSH.stub(:start).and_raise
expect{ cli.bootstrap }.to raise_error
File.exists?('bootstrap.log').should be
end
end
end

describe "#chef", :slow do
Expand Down

0 comments on commit a203773

Please sign in to comment.