installer/utils/nix_install_test.rb in rhoconnect-4.0.4 vs installer/utils/nix_install_test.rb in rhoconnect-5.1.1
- old
+ new
@@ -14,11 +14,11 @@
def run_on_server(server, cmds)
result = server.ssh(cmds)
result.each do |r|
raise "Command #{r.command} failed.\nStdout: #{r.stdout}\nStderr: #{r.stderr}" if r.status != 0
- puts "$ #{r.command}"
+ puts "$ #{r.command}"
puts r.stdout
end
end
def build_type
@@ -49,11 +49,11 @@
dist = { :flavor => "ubuntu",
:package => "rhoconnect_#{Constants::RC_VERSION}_all.deb",
:local_file => "#{local_file}rhoconnect_#{Constants::RC_VERSION}_all.deb",
:pkg_mgr => 'dpkg',
:pkg_type => 'DEB',
- :pkg_cmd => 'apt-get',
+ :pkg_cmd => 'apt-get --force-yes -y',
:deps => Constants::DEB_DEPS,
:repo_src_file => '/etc/apt/sources.list',
:repo_str => '\n' +
'# This is the repository for rhoconnect packages\n' +
"deb http://#{BUCKET}.s3.amazonaws.com/#{channel}/deb rhoconnect main" }
@@ -79,26 +79,26 @@
def connect_to_amazon
lines = IO.readlines Constants::ACCESS_KEY_FILE
access_key = lines.first.strip.split("=")[1]
secret_access_key = lines.last.strip.split("=")[1]
-
+
Fog::Compute.new(:provider => 'AWS', :region => Constants::REGION,
- :aws_access_key_id => access_key,
- :aws_secret_access_key => secret_access_key)
+ :aws_access_key_id => access_key,
+ :aws_secret_access_key => secret_access_key)
end
# Creates a new ec2 instance as per the given stack.
def start_new_instance(connection, params)
puts "Creating new instance..."
- server = connection.servers.create(params)
+ server = connection.servers.create(params)
# Wait for machine to be booted
server.wait_for { ready? }
# Wait for machine to get an ip-address
- server.wait_for { !public_ip_address.nil? }
-
+ server.wait_for { !public_ip_address.nil? }
+
if server.ready?
# wait for all services to start on remote VM
puts "Waiting #{Constants::SLEEP} seconds for services to start on remote VM..."
Constants::SLEEP.times do
sleep 1
@@ -120,22 +120,22 @@
# Create file for yum rhoconnect sources
# Get current permissions of file
perms = server.ssh("stat --format=%a #{filename}")[0].stdout.strip
# Change permissions so that it can be edited by "others"
- cmds = ["sudo chmod 0666 #{filename}",
- "echo -e \"#{src_str}\" >> #{filename}",
+ cmds = ["sudo chmod 0666 #{filename}",
+ "echo -e \"#{src_str}\" >> #{filename}",
"sudo chmod 0#{perms} #{filename}"]
- cmds << "sudo #{distro_params[:pkg_cmd]} update" unless distro_params[:flavor] == "centos"
- run_on_server(server, cmds)
+ cmds << "sudo #{distro_params[:pkg_cmd]} update" unless distro_params[:flavor] == "centos"
+ run_on_server(server, cmds)
puts "Installing rhoconnect package.\nThis may take a while...\n\n"
- run_on_server(server, "yes | sudo #{distro_params[:pkg_cmd]} install rhoconnect")
+ run_on_server(server, "sudo #{distro_params[:pkg_cmd]} install rhoconnect")
end
def start_services(server)
- puts
+ puts
['redis', 'thin', 'nginx'].each do |program|
status = -1
3.times do
res = server.ssh("sudo /etc/init.d/#{program} start")
puts "$ #{res[0].command}"
@@ -181,58 +181,58 @@
status = -1
10.times do
begin
res = server.ssh(['uptime'])
status = res[0].status
- break if status == 0
+ break if status == 0
rescue Exception => e
sleep 6
end
end
status
end
def test_package(connection, stack)
start_time = Time.now
- user, distro_params = compile_stack_info(stack)
- server = start_new_instance(connection, stack)
+ user, distro_params = compile_stack_info(stack)
+ server = start_new_instance(connection, stack)
host = server.dns_name
puts "Remote host #{host} is up and running ..."
-
+
server.username = user
- server.private_key_path = Constants::SSH_KEY
+ server.private_key_path = Constants::SSH_KEY
puts "Establish ssh connection for \"#{user}@#{host}\" ..."
- # For a minute trying to reach remote host
- raise "Cannot establish ssh connection with #{stack[:tags]['Name']} instance." if ping_remote_host(server) != 0
+ # For a minute trying to reach remote host
+ raise "Cannot establish ssh connection with #{stack[:tags]['Name']} instance." if ping_remote_host(server) != 0
puts "SSH connection establised!"
install_package(server, distro_params)
# Start the redis and nginx servers on the remote machine
start_services(server)
# Check the status of the rhoconnect service
- check_rhoconnect_status(server)
+ check_rhoconnect_status(server)
elapsed_time = (Time.now - start_time).to_i
puts "Test for #{stack[:tags]['Name']} completed in #{elapsed_time/60} min. #{elapsed_time - ((elapsed_time/60)*60)} sec."
0
rescue => e
puts e.inspect
puts e.backtrace
-1
ensure
- if server
+ if server
puts "Terminating #{stack[:tags]['Name']} instance ..."
server.destroy
end
end
module ThreadOut
# Writes to Thread.current[:stdout] instead of STDOUT if the thread local is set.
def self.write(stuff)
if Thread.current[:stdout] then
- Thread.current[:stdout].write stuff
+ Thread.current[:stdout].write stuff
else
STDOUT.write stuff
end
end
end
@@ -250,26 +250,26 @@
STACK_SIZE.times do |i|
logs << StringIO.new
threads << Thread.new(i) do |idx|
puts "Starting test for #{STACKS[idx][:tags]['Name']} ... "
Thread.current[:stdout] = logs[idx]
- test_package(connection, STACKS[idx])
+ test_package(connection, STACKS[idx])
end
end
# Wait till threads re finished
threads.each { |thread| thread.join }
# Output logs and check resluts
threads.each_with_index do |thread, i|
- puts "\n#{STACKS[i][:tags]['Name']} installation log:"
- puts logs[i].string
+ puts "\n#{STACKS[i][:tags]['Name']} installation log:"
+ puts logs[i].string
end
exit_code = 0
threads.each_with_index do |thread, i|
if thread.value != 0
- puts "Package for #{STACKS[i][:tags]['Name']} failed to pass test!"
+ puts "Package for #{STACKS[i][:tags]['Name']} failed to pass test!"
exit_code = -1
- end
+ end
end
elapsed_time = (Time.now - start_at).to_i
puts "Elapsed time: #{elapsed_time/60} min. #{elapsed_time - ((elapsed_time/60)*60)} sec."