You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/01/14 11:59:00 UTC
[1/5] git commit: Core: Initial tests for deltacloudd launcher
Core: Initial tests for deltacloudd launcher
- 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
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/e7338751
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/e7338751
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/e7338751
Branch: refs/heads/master
Commit: e7338751b5f1de1ea3ce086f3f420fa6cfa4b49c
Parents: 9096fd1
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu Dec 13 12:42:15 2012 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Mon Jan 14 11:58:01 2013 +0100
----------------------------------------------------------------------
server/tests/deltacloud/launcher_test.rb | 101 +++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e7338751/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