Add optional keyfile argument to rake tasks
authorJohn Duarte <john.duarte@puppetlabs.com>
Tue, 27 May 2014 18:04:40 +0000 (11:04 -0700)
committerJohn Duarte <john.duarte@puppetlabs.com>
Tue, 27 May 2014 18:15:55 +0000 (11:15 -0700)
This addition walks over any extra arguments provided to the
rake task. If the file is a key file, it is used to set the
BEAKER_keyfile ENVIRONMENT variable for beaker-rspec and/or
the `--keyfile` command line argument for beaker as needed.

Example:

BEAKER_setfile=../vcenterhost.cfg rake beaker:rspec:test[foo,pe,'/home/myuser/.ssh/id_rsa-secret']

Rakefile

index 36a7998..b1e0e14 100755 (executable)
--- a/Rakefile
+++ b/Rakefile
@@ -43,6 +43,9 @@ task :set_beaker_variables do |t,args|
   if ENV['BEAKER_setfile']
     @hosts_config = ENV['BEAKER_setfile']
   end
   if ENV['BEAKER_setfile']
     @hosts_config = ENV['BEAKER_setfile']
   end
+  if File.exists?(check_args_for_keyfile(args.extras))
+    ENV['BEAKER_keyfile'] = check_args_for_keyfile(args.extras)
+  end
 end
 
 def build_beaker_command(args)
 end
 
 def build_beaker_command(args)
@@ -60,5 +63,16 @@ def build_beaker_command(args)
   if File.exists?("./spec/acceptance/beaker")
     cmd << "--tests ./spec/acceptance/beaker"
   end
   if File.exists?("./spec/acceptance/beaker")
     cmd << "--tests ./spec/acceptance/beaker"
   end
+  if File.exists?(check_args_for_keyfile(args.extras))
+    cmd << "--keyfile #{check_args_for_keyfile(args.extras)}"
+  end
   cmd.join(" ")
 end
   cmd.join(" ")
 end
+
+def check_args_for_keyfile(extra_args)
+  keyfile = ''
+  extra_args.each do |a|
+    keyfile = a if (`file -b #{a}`.gsub(/\n/,"").match(/ key/))
+  end
+  return keyfile
+end