You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/12/13 12:45:28 UTC
Fixed to deltacloudd (rev 2)
Hi,
Couple minor fixes for nits found by David and others:
- Fix Deltacloud to start properly when thin is not available or
broken.
- Force to start with Webrick when using --webrick option.
Rack::Server right now choose thin if it is installed.
- Initial unit tests for deltacloudd (i'm not sure if they will work
in Travis ;-)
-- Michal
[PATCH core 1/5] Core: Remove 'set' in deltacloudd when thin is not installed
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/bin/deltacloudd | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index 08ec5a3..d9ebcfc 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -197,10 +197,7 @@ unless have_thin
app = Rack::Builder.new {
use Rack::CommonLogger # apache-like logging
- use Rack::Reloader if options[:env] == "development"
- unless RUBY_PLATFORM == 'java'
- set :root, $top_srcdir # Set Sinatra root since we can't chdir to ../
- end
+ use Rack::Reloader #if options[:env] == "development"
run inner_app
}.to_app
--
1.8.0.2
[PATCH core 3/5] Core: Change directory to $top_srcdir when using Webrick
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/bin/deltacloudd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index 18f8b94..2f0eaeb 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -206,8 +206,8 @@ unless have_thin
# There's a bug with string ports on JRuby so convert to int
# http://jira.codehaus.org/browse/JRUBY-4868
port = ENV["API_PORT"].to_i
-
puts "=> Ctrl-C to shutdown server"
+ Dir::chdir($top_srcdir)
Rack::Server::start(:app => app,
:Host => ENV["API_HOST"],
:Port => port,
--
1.8.0.2
Re: [PATCH core 4/5] Core: Overide default Rack::Server server to
use :webrick
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-12-13 at 12:45 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/bin/deltacloudd | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
> index 2f0eaeb..e0ac8a4 100755
> --- a/server/bin/deltacloudd
> +++ b/server/bin/deltacloudd
> @@ -85,7 +85,7 @@ BANNER
> opts.on( '-V', '--verbose', 'Set verbose logging on') do |verbose|
> ENV["API_VERBOSE"] ||= 'true'
> end
> - opts.on( nil, '--webrick', 'Force the use of WEBRick as a server') do |opt|
> + opts.on( '-w', '--webrick', 'Force the use of WEBRick as a server') do |opt|
Minor nit: we shouldn't make it easy on people to run webrick (since
they shouldn't). I'd much rather not have a short -w option for this.
David
[PATCH core 4/5] Core: Overide default Rack::Server server to use :webrick
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/bin/deltacloudd | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index 2f0eaeb..e0ac8a4 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -85,7 +85,7 @@ BANNER
opts.on( '-V', '--verbose', 'Set verbose logging on') do |verbose|
ENV["API_VERBOSE"] ||= 'true'
end
- opts.on( nil, '--webrick', 'Force the use of WEBRick as a server') do |opt|
+ opts.on( '-w', '--webrick', 'Force the use of WEBRick as a server') do |opt|
options[:webrick] = true
end
opts.on('--logdir LOGDIR', "Directory for log files, defaults to #{options[:logdir]}") do |opt|
@@ -209,6 +209,7 @@ unless have_thin
puts "=> Ctrl-C to shutdown server"
Dir::chdir($top_srcdir)
Rack::Server::start(:app => app,
+ :server => :webrick,
:Host => ENV["API_HOST"],
:Port => port,
:AccessLog => [])
--
1.8.0.2
Re: [PATCH core 2/5] Core: Print warning when starting as a daemon
without thin
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-12-13 at 12:45 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/bin/deltacloudd | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
We should die loudly if they ask us to daemonize and we are not able to
do that; a warning isn't enough.
David
[PATCH core 2/5] Core: Print warning when starting as a daemon without thin
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/bin/deltacloudd | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index d9ebcfc..18f8b94 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -165,7 +165,10 @@ end
ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
-unless options[:daemon]
+have_thin = options[:webrick].nil? && library_present?('thin')
+have_rerun = library_present?('rerun')
+
+if !options[:daemon] || options[:daemon] && !have_thin
msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
api_uri = ENV['API_FRONTEND'] == 'cimi' ? 'cimi/cloudEntryPoint' : 'api'
@@ -184,12 +187,11 @@ if ENV['API_USER'] && ENV['API_PASSWORD']
puts
end
-have_thin = options[:webrick].nil? && library_present?('thin')
-have_rerun = library_present?('rerun')
-
unless have_thin
require 'rack'
+ puts "To start Deltacloud as a daemon, install 'thin' (gem install thin)\n\n" if options[:daemon]
+
# Read in config.ru and convert it to an instance of Rack::Builder
cfgfile = File.read(File.join($top_srcdir, 'config.ru'))
inner_app = eval("Rack::Builder.new {(" + cfgfile + "\n )}.to_app",
--
1.8.0.2
Re: [PATCH core 5/5] Core: Initial tests for deltacloudd launcher
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-12-13 at 12:45 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> - Starts a Deltacloud APi instance on port 3011
> - Checks if DC is running (respond to HTTP requests)
> - Checks if DC could be started with multiple frontends
Unfortunately, I get 3 failures with this test; seems that killing the
server isn't always successful. Here's what fails:
> diff --git a/server/tests/deltacloud/launcher_test.rb b/server/tests/deltacloud/launcher_test.rb
> new file mode 100644
> index 0000000..3c9c0b1
> --- /dev/null
> +++ b/server/tests/deltacloud/launcher_test.rb
> @@ -0,0 +1,101 @@
> +describe "deltacloudd" do
> +
> + before do
> + @pids ||= []
> + end
> +
> + it 'starts the deltacloud server gracefully' do
> + pid = Process.fork
> + if pid.nil? then
> + Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
> + exec("./bin/deltacloudd -i mock -p 3011")
> + else
> + Process.detach(pid) && @pids << pid
> + wait_for_port_open(3011).must_equal true
> + RestClient.get('http://localhost:3011/api').code.must_equal 200
> + kill_process(pid)
> + is_port_open?('127.0.0.1', 3011).must_equal false
This returns true.
> + end
> + end
> +
> + it 'starts the deltacloud server gracefully with multiple frontends' do
> + pid = Process.fork
> + if pid.nil? then
> + Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
> + exec("./bin/deltacloudd -i mock -f deltacloud,cimi,ec2 -p 3011")
> + else
> + Process.detach(pid) && @pids << pid
> + wait_for_port_open(3011).must_equal true
> + RestClient.get('http://localhost:3011/api').code.must_equal 200
> + RestClient.get('http://localhost:3011/cimi/cloudEntryPoint').code.must_equal 200
> + kill_process(pid)
> + is_port_open?('127.0.0.1', 3011).must_equal false
Returns true
> + end
> + end
> +
> + it 'starts the deltacloud server gracefully when using webrick' do
> + pid = Process.fork
> + if pid.nil? then
> + Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
> + exec("./bin/deltacloudd -w -i mock -p 3011")
> + else
> + Process.detach(pid) && @pids << pid
> + wait_for_port_open(3011).must_equal true
> + RestClient.get('http://localhost:3011/api').code.must_equal 200
> + kill_process(pid)
> + is_port_open?('127.0.0.1', 3011).must_equal false
Returns true
David
[PATCH core 5/5] Core: Initial tests for deltacloudd launcher
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
- Starts a Deltacloud APi instance on port 3011
- Checks if DC is running (respond to HTTP requests)
- Checks if DC could be started with multiple frontends
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/tests/deltacloud/launcher_test.rb | 101 +++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 server/tests/deltacloud/launcher_test.rb
diff --git a/server/tests/deltacloud/launcher_test.rb b/server/tests/deltacloud/launcher_test.rb
new file mode 100644
index 0000000..3c9c0b1
--- /dev/null
+++ b/server/tests/deltacloud/launcher_test.rb
@@ -0,0 +1,101 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+require_relative 'common.rb'
+require 'socket'
+require 'timeout'
+require 'rest-client'
+
+def is_port_open?(ip, port)
+ begin
+ Timeout::timeout(1) do
+ begin
+ s = TCPSocket.new(ip, port)
+ s.close
+ return true
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
+ return false
+ end
+ end
+ rescue Timeout::Error
+ end
+ return false
+end
+
+def wait_for_port_open(port)
+ retries = 5
+ begin
+ raise unless is_port_open?('127.0.0.1', port)
+ true
+ rescue
+ sleep(1) && retry if (retries-=1) != 0
+ false
+ end
+end
+
+def kill_process(pid)
+ Process.kill('TERM', pid) rescue ''
+ # Die!
+ Process.kill('KILL', pid) rescue ''
+end
+
+describe "deltacloudd" do
+
+ before do
+ @pids ||= []
+ end
+
+ it 'starts the deltacloud server gracefully' do
+ pid = Process.fork
+ if pid.nil? then
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
+ exec("./bin/deltacloudd -i mock -p 3011")
+ else
+ Process.detach(pid) && @pids << pid
+ wait_for_port_open(3011).must_equal true
+ RestClient.get('http://localhost:3011/api').code.must_equal 200
+ kill_process(pid)
+ is_port_open?('127.0.0.1', 3011).must_equal false
+ end
+ end
+
+ it 'starts the deltacloud server gracefully with multiple frontends' do
+ pid = Process.fork
+ if pid.nil? then
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
+ exec("./bin/deltacloudd -i mock -f deltacloud,cimi,ec2 -p 3011")
+ else
+ Process.detach(pid) && @pids << pid
+ wait_for_port_open(3011).must_equal true
+ RestClient.get('http://localhost:3011/api').code.must_equal 200
+ RestClient.get('http://localhost:3011/cimi/cloudEntryPoint').code.must_equal 200
+ kill_process(pid)
+ is_port_open?('127.0.0.1', 3011).must_equal false
+ end
+ end
+
+ it 'starts the deltacloud server gracefully when using webrick' do
+ pid = Process.fork
+ if pid.nil? then
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
+ exec("./bin/deltacloudd -w -i mock -p 3011")
+ else
+ Process.detach(pid) && @pids << pid
+ wait_for_port_open(3011).must_equal true
+ RestClient.get('http://localhost:3011/api').code.must_equal 200
+ kill_process(pid)
+ is_port_open?('127.0.0.1', 3011).must_equal false
+ end
+ end
+
+ it 'lists the available drivers' do
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
+ output = `./bin/deltacloudd -l`
+ output.must_include 'Available drivers'
+ output.must_include 'mock'
+ end
+
+ after do
+ @pids.map { |pid| kill_process(pid) }
+ end
+
+end
--
1.8.0.2