Skip to content

Commit

Permalink
[api] have seperate backend ports and directories when running for "t…
Browse files Browse the repository at this point in the history
…est" and "development"

This conflicts errors from the test suite when running a development
environement in parallel
  • Loading branch information
adrianschroeter committed Aug 17, 2015
1 parent c21fb04 commit 4b829e3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
8 changes: 8 additions & 0 deletions src/api/config/environment.rb
Expand Up @@ -18,6 +18,14 @@
CONFIG['proxy_auth_mode'] ||= :off
CONFIG['frontend_ldap_mode'] ||= :off

# use hardcoded source server port for test and development
# used in start_test_backend script
if ENV['RAILS_ENV'] == 'test'
CONFIG['source_port'] = 3200
elsif ENV['RAILS_ENV'] == 'development'
CONFIG['source_port'] = 6200
end

# Initialize the rails application
OBSApi::Application.initialize!

1 change: 1 addition & 0 deletions src/api/config/options.yml.example
Expand Up @@ -20,6 +20,7 @@ response_schema_validation: false

# backend source server
source_host: localhost
# NOTE: the source_port setting is ignored and hardcoded for "test" and "development" env
source_port: 5352
#source_protocol: https

Expand Down
77 changes: 45 additions & 32 deletions src/api/script/start_test_backend
Expand Up @@ -8,12 +8,25 @@ require 'opensuse/backend'

Suse::Backend.do_not_start_test_backend

port_src_server = 3200
port_rep_server = 3201
port_service_server = 3202
backend_dir_suffix = ""
if ENV['RAILS_ENV'] == 'development'
port_src_server = 6200
port_rep_server = 6201
port_service_server = 6202
backend_dir_suffix = "_development"
end
backend_config = "#{Rails.root}/tmp/backend_config#{backend_dir_suffix}"
backend_data = "#{Rails.root}/tmp/backend_data#{backend_dir_suffix}"

perlopts="-I#{Rails.root}/../backend -I#{Rails.root}/../backend/build"

if File.exists?("#{Rails.root}/tmp/backend_config")
if File.exists?(backend_config)
puts 'Old backend data is there. checking if we can stop it'
%w{bs_srcserver bs_repserver bs_service bs_sched bs_publish bs_mergechanges}.each do |srv|
system("cd #{Rails.root}/tmp/backend_config && exec perl #{perlopts} ./#{srv} --stop 2>&1 && sleep 2")
system("cd #{backend_config} && exec perl #{perlopts} ./#{srv} --stop 2>&1 && sleep 2")
end
end

Expand All @@ -39,7 +52,7 @@ else
end

# check for still running daemons from former run
%w(3200 3201 3202).each do |port|
[port_src_server, port_rep_server, port_service_server].each do |port|
begin
Net::HTTP.start(CONFIG['source_host'], port) { |http| http.get('/') }
puts "ERROR Port #{port} is already in use, maybe from former unclean shutdown, aborting ..."
Expand All @@ -58,45 +71,45 @@ reposrv_out = nil
servicesrv_out = nil
dienow = false
logger = Rails.logger
FileUtils.rm_rf("#{Rails.root}/tmp/backend_data")
FileUtils.rm_rf("#{Rails.root}/tmp/backend_config")
FileUtils.rm_rf(backend_data)
FileUtils.rm_rf(backend_config)

# minimal auth
@http_user = User.find_by_login('king')
raise 'NO fixtures' unless @http_user
User.current = @http_user

puts "Creating backend config at #{Rails.root}/tmp/backend_config/BSConfig.pm"
FileUtils.mkdir "#{Rails.root}/tmp/backend_config"
file = File.open("#{Rails.root}/tmp/backend_config/BSConfig.pm", 'w')
puts "Creating backend config at #{backend_config}/BSConfig.pm"
FileUtils.mkdir backend_config
file = File.open("#{backend_config}/BSConfig.pm", 'w')
File.open("#{Rails.root}/../backend/BSConfig.pm.template") do |template|
template.readlines.each do |line|
line.gsub!(/our \$ipaccess/, 'our $ipaccess = undef; our $dummy')
line.gsub!(/(our \$bsuser)/, '#\1')
line.gsub!(/(our \$bsgroup)/, '#\1')
line.gsub!(/^(my \$hostname).*/, '\1 = "localhost";')
line.gsub!(/.*our \$localarch.*/, 'our $localarch = "x86_64";')
line.gsub!(/our \$bsdir = .*/, "our $bsdir = '#{Rails.root}/tmp/backend_data';")
line.gsub!(/our \$bsdir = .*/, "our $bsdir = '#{backend_data}';")
line.gsub!(/our \$servicedir = .*/, "our $servicedir = '#{Rails.root}/test/fixtures/backend/services';")
line.gsub!(/:5352/, ":#{CONFIG['source_port']}")
line.gsub!(/:5252/, ':3201') # repservier, used via source server
line.gsub!(/:5152/, ':3202') # source service, used via source server
line.gsub!(/:5352/, ":#{port_src_server}")
line.gsub!(/:5252/, ":#{port_rep_server}") # repservier, used via source server
line.gsub!(/:5152/, ":#{port_service_server}") # source service, used via source server
file.print line
end
end
file.close

%w{bs_admin bs_srcserver bs_repserver bs_service bs_sched bs_publish bs_dispatch bs_productconvert bs_check_consistency bs_mergechanges}.each do |srv|
FileUtils.symlink("#{Rails.root}/../backend/#{srv}", "#{Rails.root}/tmp/backend_config/#{srv}")
unless system("cd #{Rails.root}/tmp/backend_config && exec perl -c #{perlopts} ./#{srv} 2>&1")
FileUtils.symlink("#{Rails.root}/../backend/#{srv}", "#{backend_config}/#{srv}")
unless system("cd #{backend_config} && exec perl -c #{perlopts} ./#{srv} 2>&1")
puts "ERROR: syntax broken of #{srv}"
exit 1
end
end

puts 'Starting backend srcserver...'
srcsrv = Thread.new do
srcsrv_out = IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_srcserver 2>&1")
srcsrv_out = IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_srcserver 2>&1")
puts "Started backend srcserver with pid: #{srcsrv_out.pid}"
while srcsrv_out && !dienow
begin
Expand All @@ -111,7 +124,7 @@ end

puts 'Starting backend repserver...'
reposrv = Thread.new do
reposrv_out = IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_repserver 2>&1")
reposrv_out = IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_repserver 2>&1")
puts "Started backend repserver with pid #{reposrv_out.pid}"
while reposrv_out && !dienow
begin
Expand All @@ -127,7 +140,7 @@ end
while !dienow
puts 'Connecting to srcserver...'
begin
Net::HTTP.start(CONFIG['source_host'], CONFIG['source_port']) { |http| http.get('/') }
Net::HTTP.start(CONFIG['source_host'], port_src_server) { |http| http.get('/') }
rescue Errno::ECONNREFUSED, Errno::ENETUNREACH
sleep 0.5
next
Expand All @@ -138,7 +151,7 @@ end
while !dienow
puts 'Connecting to repserver...'
begin
Net::HTTP.start(CONFIG['source_host'], 3201) { |http| http.get('/') }
Net::HTTP.start(CONFIG['source_host'], port_src_server) { |http| http.get('/') }
rescue Errno::ECONNREFUSED, Errno::ENETUNREACH
sleep 0.5
next
Expand All @@ -151,7 +164,7 @@ Suse::Backend.put('/configuration', Configuration.first.render_xml)

puts 'Starting backend serviceserver...'
servicesrv = Thread.new do
servicesrv_out = IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_service 2>&1")
servicesrv_out = IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_service 2>&1")
puts "Started backend service server with pid #{servicesrv_out.pid}"
while servicesrv_out && !dienow
begin
Expand All @@ -165,7 +178,7 @@ servicesrv = Thread.new do
end

puts 'Starting backend publisher...'
publishsrv_out = IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_publish --testmode 2>&1")
publishsrv_out = IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_publish --testmode 2>&1")
puts "Started backend publish server with pid #{publishsrv_out.pid}"
while publishsrv_out && !dienow
begin
Expand All @@ -180,7 +193,7 @@ end
while !dienow
puts 'Connecting to serviceserver...'
begin
Net::HTTP.start(CONFIG['source_host'], 3202) { |http| http.get('/') }
Net::HTTP.start(CONFIG['source_host'], port_service_server) { |http| http.get('/') }
rescue Errno::ECONNREFUSED, Errno::ENETUNREACH
sleep 0.5
next
Expand Down Expand Up @@ -258,10 +271,10 @@ Suse::Backend.put('/source/home:dmayr/x11vnc/README?user=king', 'just to delete'
Suse::Backend.put('/source/home:king/_config?user=king', 'Type: spec')

# manual placing of files
FileUtils.cp("#{Rails.root}/test/fixtures/backend/source/_pubkey", "#{Rails.root}/tmp/backend_data/projects/BaseDistro.pkg/_pubkey")
FileUtils.cp("#{Rails.root}/test/fixtures/backend/source/_sslcert", "#{Rails.root}/tmp/backend_data/projects/BaseDistro.pkg/_sslcert")
FileUtils.cp("#{Rails.root}/test/fixtures/backend/source/_pubkey", "#{backend_data}/projects/BaseDistro.pkg/_pubkey")
FileUtils.cp("#{Rails.root}/test/fixtures/backend/source/_sslcert", "#{backend_data}/projects/BaseDistro.pkg/_sslcert")
# put meta again so that the srcserver puts the files into history
FileUtils.rm("#{Rails.root}/tmp/backend_data/projects/BaseDistro.pkg/_project.mrev")
FileUtils.rm("#{backend_data}/projects/BaseDistro.pkg/_project.mrev")
Suse::Backend.put('/source/BaseDistro/_meta?user=king', Project.find_by_name('BaseDistro').to_axml)

# reindex all sources
Expand All @@ -278,8 +291,8 @@ scheduler_thread = nil
at_exit do
scheduler_thread.join if scheduler_thread

system("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_srcserver --stop")
system("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_repserver --stop")
system("cd #{backend_config}; exec perl #{perlopts} ./bs_srcserver --stop")
system("cd #{backend_config}; exec perl #{perlopts} ./bs_repserver --stop")

Process.kill 'TERM', srcsrv_out.pid
Process.kill 'TERM', reposrv_out.pid
Expand All @@ -298,8 +311,8 @@ at_exit do
servicesrv_out.close
servicesrv_out = nil
servicesrv.join
# FileUtils.rm_rf("#{Rails.root}/tmp/backend_data")
# FileUtils.rm_rf("#{Rails.root}/tmp/backend_config")
# FileUtils.rm_rf("#{backend_data}")
# FileUtils.rm_rf("#{backend_config}")
File.delete(schedulerdone_file) if File.exists?(schedulerdone_file)
end

Expand All @@ -309,12 +322,12 @@ scheduler_thread = Thread.new do
#

# run scheduler once
IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
# just for waiting until scheduler finishes
io.each { |line| logger.debug line.strip unless line.blank? }
end
# run scheduler once
IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_sched --testmode x86_64") do |io|
IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_sched --testmode x86_64") do |io|
# just for waiting until scheduler finishes
io.each { |line| logger.debug line.strip unless line.blank? }
end
Expand All @@ -332,7 +345,7 @@ scheduler_thread = Thread.new do
File.open("#{Rails.root}/test/fixtures/backend/binary/delete_me-1.0-1.i586.rpm").read())

# run scheduler again to handle the build result
IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
# just for waiting until scheduler finishes
io.each { |line| logger.debug line.strip unless line.blank? }
end
Expand All @@ -342,7 +355,7 @@ scheduler_thread = Thread.new do
Suse::Backend.post('/build/BaseDistro/BaseDistro_repo/i586/pack2?cmd=copy&oproject=home:Iggy&orepository=10.2&opackage=TestPack', nil)

# run scheduler again to handle the copy build event
IO.popen("cd #{Rails.root}/tmp/backend_config; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
IO.popen("cd #{backend_config}; exec perl #{perlopts} ./bs_sched --testmode i586") do |io|
# just for waiting until scheduler finishes
io.each { |line| logger.debug line.strip unless line.blank? }
end
Expand Down

0 comments on commit 4b829e3

Please sign in to comment.