From b3b253f2432e5cda15c04b11b89bb3d47e84dc76 Mon Sep 17 00:00:00 2001 From: John Duarte Date: Tue, 27 May 2014 11:04:40 -0700 Subject: Add optional keyfile argument to rake tasks 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index 36a7998..b1e0e14 100755 --- 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 File.exists?(check_args_for_keyfile(args.extras)) + ENV['BEAKER_keyfile'] = check_args_for_keyfile(args.extras) + end 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?(check_args_for_keyfile(args.extras)) + cmd << "--keyfile #{check_args_for_keyfile(args.extras)}" + 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 -- cgit v1.2.3 From 22397d9b36938f6537bc83293e5bee0aff403756 Mon Sep 17 00:00:00 2001 From: John Duarte Date: Tue, 27 May 2014 17:18:37 -0700 Subject: Fix logic to validate keyfile --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index b1e0e14..cb80def 100755 --- a/Rakefile +++ b/Rakefile @@ -72,7 +72,7 @@ end def check_args_for_keyfile(extra_args) keyfile = '' extra_args.each do |a| - keyfile = a if (`file -b #{a}`.gsub(/\n/,"").match(/ key/)) + keyfile = a unless (`ssh-keygen -l -f #{a}`.gsub(/\n/,"").match(/is not a .*key file/)) end return keyfile end -- cgit v1.2.3