Permalink
Browse files

fork a process to remove vblob directory; fix some minor bugs in unit…

… test

Change-Id: I153253b907c07f05c6ba2802381130ac7678a98c
  • Loading branch information...
1 parent aa8d761 commit 601412d14a99afd2802a6a281784b0a742050990 @SlimYang SlimYang committed Sep 25, 2012
@@ -277,21 +277,24 @@ def unprovision(name, bindings)
def cleanup_service(provisioned_service)
@logger.info("Killing #{provisioned_service.name} started with pid #{provisioned_service.pid}")
+ raise VBlobError.new(VBlobError::VBLOB_CLEANUP_ERROR, provisioned_service.errors.pretty_inspect) unless provisioned_service.new? || provisioned_service.destroy
provisioned_service.kill(:SIGKILL) if provisioned_service.running?
if provisioned_service.wait_killed
- dir = service_dir(provisioned_service.name)
- log_dir = log_dir(provisioned_service.name)
+ instance_name = provisioned_service.name
+ dir = service_dir(instance_name)
+ log_dir = log_dir(instance_name)
@logger.debug("vblob pid:#{provisioned_service.pid} terminated")
- EM.defer do
+ return_port(provisioned_service.port)
+ pid = Process.fork do
+ @logger.debug("started to remove vblob instance #{instance_name} log and data directory")
FileUtils.rm_rf(dir)
FileUtils.rm_rf(log_dir)
+ @logger.debug("vblob instance #{instance_name} log and data directory removed")
end
- return_port(provisioned_service.port)
+ Process.detach(pid) if pid
else
- @logger.error("Timeout to terminate mongod pid:#{provisioned_service.pid}")
+ @logger.error("Timeout to terminate vblob pid:#{provisioned_service.pid}")
end
- raise VBlobError.new(VBlobError::VBLOB_CLEANUP_ERROR, provisioned_service.errors.pretty_inspect) unless provisioned_service.new? || provisioned_service.destroy
- true
end
# provide the key/secret to vblob gw
@@ -75,22 +75,22 @@ def get_node_config()
config = YAML.load_file(config_file)
vblob_conf_template = File.join(PWD, "../resources/vblob.conf.erb")
options = {
- # :logger => Logger.new(parse_property(config, "log_file", String, :optional => true) || STDOUT, "daily"),
+ :logger => Logger.new(parse_property(config, "log_file", String, :optional => true) || STDOUT, "daily"),
:nodejs_path => parse_property(config, "nodejs_path", String),
:plan => parse_property(config, "plan", String),
:capacity => parse_property(config, "capacity", Integer),
:vblobd_path => parse_property(config, "vblobd_path", String),
+ :vblobd_auth => parse_property(config, "vblobd_auth", String),
:vblobd_log_dir => parse_property(config, "vblobd_log_dir", String),
:ip_route => parse_property(config, "ip_route", String, :optional => true),
:node_id => parse_property(config, "node_id", String),
:mbus => parse_property(config, "mbus", String),
:config_template => vblob_conf_template,
:port_range => parse_property(config, "port_range", Range),
:base_dir => '/tmp/vblob/instances',
+ :log_dir => '/tmp/vblob/service-log',
:local_db => 'sqlite3:/tmp/vblob/vblob_node.db'
}
- VCAP::Logging.setup_from_config(config["logging"])
- # Use the node id for logger identity name.
- options[:logger] = VCAP::Logging.logger(options[:node_id])
+ options[:logger].level = Logger::DEBUG
options
end
@@ -1,4 +1,5 @@
# Copyright (c) 2009-2011 VMware, Inc.
+$:.unshift(File.dirname(__FILE__))
require "spec_helper"
describe "vblob_node bind" do
@@ -9,16 +10,17 @@
@opts = get_node_config()
@logger = @opts[:logger]
@node = Node.new(@opts)
- EM.add_timer(2) do #must! wait for a while before provisioning
- @resp = @node.provision("free")
- end
- EM.add_timer(4) do
- @bind_resp = @node.bind(@resp['name'], 'rw')
- EM.stop
- end
+ @resp = @node.provision("free")
+ @bind_resp = @node.bind(@resp['name'], 'rw')
+ EM.add_timer(1){ EM.stop }
end
end
+ after :all do
+ @node.shutdown if @node
+ FileUtils.rm_rf('/tmp/vblob')
+ end
+
it "should have valid response" do
@resp.should_not be_nil
@resp['host'].should_not be_nil
@@ -96,10 +98,4 @@
EM.stop
end
end
-
- after:all do
- FileUtils.rm_rf Dir.glob('/tmp/vblob')
- end
end
-
-
@@ -3,6 +3,7 @@
require "spec_helper"
describe "vblob_node check & purge orphan" do
+
before :all do
EM.run do
@opts = get_node_config
@@ -12,6 +13,11 @@
end
end
+ after :all do
+ @node.shutdown if @node
+ FileUtils.rm_rf('/tmp/vblob')
+ end
+
it "should return proper instances & bindings list" do
EM.run do
before_instances = @node.all_instances_list
@@ -39,4 +45,5 @@
EM.stop
end
end
+
end
@@ -15,9 +15,13 @@
end
end
+ after :all do
+ @node.shutdown if @node
+ FileUtils.rm_rf('/tmp/vblob')
+ end
+
it "should have valid response" do
@resp.should_not be_nil
- puts @resp
inst_name = @resp['name']
inst_name.should_not be_nil
inst_name.should_not == ""
@@ -85,9 +89,4 @@
end
end
- after:all do
- FileUtils.rm_rf Dir.glob('/tmp/vblob')
- end
end
-
-

0 comments on commit 601412d

Please sign in to comment.