lib/boot.rb in forj-1.0.10 vs lib/boot.rb in forj-1.0.11
- old
+ new
@@ -51,13 +51,13 @@
name
end
def self.load_options(options, options_map)
options_map.each do |opt_key, ac_key|
- unless options[opt_key].nil?
- value = yield(opt_key, options[opt_key])
- @account.set(ac_key, options[opt_key]) unless value.nil?
+ if options.key?(opt_key.to_s)
+ value = yield(opt_key, options[opt_key.to_s])
+ @account.set(ac_key, value) unless value.nil?
end
end
end
def self.validate_keypath(options)
@@ -97,14 +97,16 @@
@account[:blueprint] = blueprint
PrcLib.info("Starting boot process of '%s' with blueprint '%s'.",
@account[:instance_name], @account[:blueprint])
end
end
+ end
+ # rubocop: disable Metrics/CyclomaticComplexity
+ # rubocop: disable Metrics/MethodLength
- # rubocop: disable Metrics/CyclomaticComplexity
- # rubocop: disable Metrics/MethodLength
-
+ #
+ module Boot
# Boot process
def self.boot(blueprint, on_or_name, deprecated_name, options)
@account = Lorj::Account.new(options[:config])
name = deprecated_name?(blueprint, on_or_name, deprecated_name[0],
@@ -123,37 +125,28 @@
PrcLib.fatal(1, "Account '%s' not loaded. You need to call "\
'`forj setup %s [provider]` to use this account.',
@account[:account_name], @account[:account_name])
end
+ options = options.to_h
+ options['tb_path'] = nil if options.key?('test_box') &&
+ !options.key?('tb_path')
options_map = { :infra => :infra_repo,
:key_name => :keypair_name,
:key_path => :keypair_path,
:security_group => :security_group,
:image_name => :image_name,
:maestro_flavor => :flavor,
:bp_flavor => :bp_flavor,
:maestro_repo => :maestro_repo,
:branch => :branch,
:test_box => :test_box,
+ :tb_path => :test_box_path,
:extra_metadata => :extra_metadata }
- load_options(options, options_map) do |key, value|
- case key
- when :test_box
- path = File.expand_path(value)
- return path if File.directory?(path)
- return nil
- end
- value
- end
+ load_options(options, options_map) { |k, v| complete_boot_options(k, v) }
- PrcLib.warning(
- 'test_box is currently disabled in this version.' \
- 'It will be re-activated in newer version.'
- ) if options[:test_box]
-
validate_keypath(options)
# o_cloud = get_o_cloud(o_forj_account)
o_cloud = Forj::CloudConnection.connect(@account)
@@ -162,8 +155,95 @@
"more output in '%s'\n",
@account[:instance_name],
PrcLib.log_file)
o_cloud.create(:forge)
+ end
+ end
+ # rubocop: enable Metrics/CyclomaticComplexity
+ # rubocop: enable Metrics/MethodLength
+
+ #
+ module Boot
+ # Take care of special options cases for boot.
+ def self.complete_boot_options(key, value)
+ case key
+ when :test_box
+ value = tb_repo_detect(value)
+ when :tb_path
+ value = tb_bin_detect(value)
+ end
+ value
+ end
+
+ # Function to check the repository path passed.
+ def self.tb_repo_detect(paths)
+ res = {}
+ paths.each do |path|
+ cmd = <<-CMD
+cd "#{path}"
+git rev-parse --show-toplevel 2>/dev/null 1>&2
+if [ $? -ne 0 ]
+then
+ exit 1
+fi
+REPO_TO_ADD="$(LANG= git remote show origin -n |
+ awk '$1 ~ /Fetch/ { print $3 }')"
+if [ "$REPO_TO_ADD" = "" ]
+then
+ exit 1
+fi
+echo $REPO_TO_ADD
+pwd
+ CMD
+ cmd_res = `#{cmd}`.split
+ # For any reason, $CHILD_STATUS is empty, while $? is not.
+ # Ruby bug. tested with:
+ # ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
+ # rubocop: disable Style/SpecialGlobalVars
+ next unless $?.exitstatus == 0
+ # rubocop: enable Style/SpecialGlobalVars
+ repo_found = cmd_res[0].match(%r{.*/(.*)(.git)?})
+ next unless repo_found
+ res[repo_found[1]] = cmd_res[1]
+ end
+ res
+ end
+
+ # function to detect if test-box.sh is runnable
+ #
+ # It returns the script to execute.
+ def self.tb_bin_detect(tb_path)
+ tb_path = ENV['TEST_BOX'] if tb_path.nil?
+ tb_path = File.expand_path(tb_path) unless tb_path.nil?
+
+ script = 'test-box.sh'
+ if tb_path && File.directory?(tb_path)
+ script_found = tb_check_bin(tb_path)
+ script = File.expand_path(File.join(tb_path, script))
+ if script_found.nil?
+ PrcLib.error("Test-box: '%s' is not a valid runnable script. "\
+ 'test-box is disabled.', script)
+ return nil
+ end
+ return script_found
+ end
+
+ script_found = nil
+
+ ENV['PATH'].split(':').each do |path|
+ script_found = tb_check_bin(path)
+ break unless script_found.nil?
+ end
+
+ script_found
+ end
+
+ # Script to check the bin and path
+ def self.tb_check_bin(tb_path)
+ script = 'test-box.sh'
+ script = File.expand_path(File.join(tb_path, script))
+ return script if File.executable?(script)
+ nil
end
end
end