https://bugzilla.redhat.com/show_bug.cgi?id=715103
This started as a patch to tidy up tests and exits, but turned out
to also take care of this BZ. The user should now get appropriate
feedback when calling this not-yet-implemented combination.
This should result in no other functional changes, just removes some
duplication in the tests, and give a non-zero exit code for
error cases, which we should not have had exit with 0 previously.
---
.../aeolus-image/lib/build_command.rb | 2 +-
.../aeolus-image/lib/config_parser.rb | 7 +++++--
.../image_factory/aeolus-image/lib/push_command.rb | 8 +++++++-
.../aeolus-image/spec/base_command_spec.rb | 4 ----
.../aeolus-image/spec/build_command_spec.rb | 13 ++-----------
.../aeolus-image/spec/config_parser_spec.rb | 8 ++++----
.../aeolus-image/spec/import_command_spec.rb | 8 --------
.../aeolus-image/spec/push_command_spec.rb | 13 ++-----------
.../image_factory/aeolus-image/spec/spec_helper.rb | 10 ++++++++++
9 files changed, 31 insertions(+), 42 deletions(-)
diff --git a/services/image_factory/aeolus-image/lib/build_command.rb
b/services/image_factory/aeolus-image/lib/build_command.rb
index 05a2d76..fe7be5a 100644
--- a/services/image_factory/aeolus-image/lib/build_command.rb
+++ b/services/image_factory/aeolus-image/lib/build_command.rb
@@ -28,7 +28,7 @@ module Aeolus
#This is a temporary hack in case the agent doesn't show up on bus
immediately
sleep(5)
- @console.build(@options[:template_str], @options[:target],
@options[:image]).each do |adaptor|
+ @console.build(@options[:template_str], @options[:target], @options[:image],
@options[:build]).each do |adaptor|
puts ""
puts "Target Image: #{adaptor.image_id}"
puts "Image: #{adaptor.image}"
diff --git a/services/image_factory/aeolus-image/lib/config_parser.rb
b/services/image_factory/aeolus-image/lib/config_parser.rb
index 90a7a76..ebfe0e4 100644
--- a/services/image_factory/aeolus-image/lib/config_parser.rb
+++ b/services/image_factory/aeolus-image/lib/config_parser.rb
@@ -163,7 +163,10 @@ module Aeolus
@optparse.parse!(@args)
rescue OptionParser::InvalidOption
puts "Warning: Invalid option"
- exit(0)
+ exit(1)
+ rescue OptionParser::MissingArgument => e
+ puts "Warning, #{e.message}"
+ exit(1)
end
end
@@ -179,7 +182,7 @@ module Aeolus
if @options[:subcommand].nil?
# TODO: Pull out Print Usage into seporate method, and print
puts "Could not find subcommand for list, run `./aeolus-image --help` for
usage instructions"
- exit(0)
+ exit(1)
else
list_command = ListCommand.new(@options)
list_command.send(@options[:subcommand])
diff --git a/services/image_factory/aeolus-image/lib/push_command.rb
b/services/image_factory/aeolus-image/lib/push_command.rb
index 1beeb54..ae79f14 100644
--- a/services/image_factory/aeolus-image/lib/push_command.rb
+++ b/services/image_factory/aeolus-image/lib/push_command.rb
@@ -6,13 +6,19 @@ module Aeolus
attr_accessor :console
def initialize(opts={}, logger=nil)
super(opts, logger)
+ default = {
+ :provider => [],
+ :id => '',
+ :build => ''
+ }
+ @options = default.merge(@options)
@console = ImageFactoryConsole.new()
@console.start
end
def run
if combo_implemented?
sleep(5)
- @console.push(@options[:provider], get_creds, @options[:id]).each do |adaptor|
+ @console.push(@options[:provider], get_creds, @options[:id],
@options[:build]).each do |adaptor|
puts ""
puts "Provider Image: #{adaptor.image_id}"
puts "Image: #{adaptor.image}"
diff --git a/services/image_factory/aeolus-image/spec/base_command_spec.rb
b/services/image_factory/aeolus-image/spec/base_command_spec.rb
index 87f91e7..f56edd5 100644
--- a/services/image_factory/aeolus-image/spec/base_command_spec.rb
+++ b/services/image_factory/aeolus-image/spec/base_command_spec.rb
@@ -3,10 +3,6 @@ require 'spec_helper'
module Aeolus
module Image
describe BaseCommand do
- before(:each) do
- @stdout_orig = $stdout
- $stdout = StringIO.new
- end
it "should determine the correct credentials for HTTP Authentication" do
basec = BaseCommand.new
diff --git a/services/image_factory/aeolus-image/spec/build_command_spec.rb
b/services/image_factory/aeolus-image/spec/build_command_spec.rb
index 32de5ea..f6b97b6 100644
--- a/services/image_factory/aeolus-image/spec/build_command_spec.rb
+++ b/services/image_factory/aeolus-image/spec/build_command_spec.rb
@@ -1,22 +1,13 @@
require 'spec_helper'
-require 'stringio'
module Aeolus
module Image
describe BuildCommand do
before(:each) do
- @output = double('output')
- @stdout_orig = $stdout
- $stdout = StringIO.new
- @options = {}
@options[:target] = ['mock','ec2']
@options[:template] = 'spec/sample_data/custom_repo.tdl'
end
- after(:each) do
- $stdout = @stdout_orig
- end
-
describe "#run" do
it "should kick off a build with valid options" do
b = BuildCommand.new(@options, @output)
@@ -39,7 +30,7 @@ module Aeolus
rescue SystemExit => e
e.status.should == 1
end
- $stdout.string.should include("This combination of parameters is not
currently supported")
+ $stdout.string.should include("This combination of parameters is not
currently supported")
end
end
@@ -53,7 +44,7 @@ module Aeolus
rescue SystemExit => e
e.status.should == 1
end
- $stdout.string.should include("This combination of parameters is not
currently supported")
+ $stdout.string.should include("This combination of parameters is not
currently supported")
end
end
end
diff --git a/services/image_factory/aeolus-image/spec/config_parser_spec.rb
b/services/image_factory/aeolus-image/spec/config_parser_spec.rb
index cf89bdf..724ed4d 100644
--- a/services/image_factory/aeolus-image/spec/config_parser_spec.rb
+++ b/services/image_factory/aeolus-image/spec/config_parser_spec.rb
@@ -14,10 +14,10 @@ module Aeolus
silence_stream(STDOUT) do
config_parser = ConfigParser.new(%w(list))
config_parser.process
- config_parser.should_receive(:exit).with(0)
+ config_parser.should_receive(:exit).with(1)
end
rescue SystemExit => e
- e.status.should == 0
+ e.status.should == 1
end
end
@@ -32,10 +32,10 @@ module Aeolus
it "should exit gracefully with bad params" do
begin
silence_stream(STDOUT) do
- ConfigParser.new(%w(delete --fred)).should_receive(:exit).with(0)
+ ConfigParser.new(%w(delete --fred)).should_receive(:exit).with(1)
end
rescue SystemExit => e
- e.status.should == 0
+ e.status.should == 1
end
end
diff --git a/services/image_factory/aeolus-image/spec/import_command_spec.rb
b/services/image_factory/aeolus-image/spec/import_command_spec.rb
index a2f5c0f..4ce1d6f 100644
--- a/services/image_factory/aeolus-image/spec/import_command_spec.rb
+++ b/services/image_factory/aeolus-image/spec/import_command_spec.rb
@@ -1,22 +1,14 @@
require 'spec_helper'
-require 'stringio'
module Aeolus
module Image
describe ImportCommand do
before(:each) do
- @stdout_orig = $stdout
- $stdout = StringIO.new
- @options = {}
@options[:id] = "ami-test"
@options[:target] = "ec2"
@options[:provider] = "ec2-us-east-1"
end
- after(:each) do
- $stdout = @stdout_orig
- end
-
describe "#import_image" do
it "should import an image with default description values" do
importc = ImportCommand.new(@options)
diff --git a/services/image_factory/aeolus-image/spec/push_command_spec.rb
b/services/image_factory/aeolus-image/spec/push_command_spec.rb
index 4f2b523..75bd1c5 100644
--- a/services/image_factory/aeolus-image/spec/push_command_spec.rb
+++ b/services/image_factory/aeolus-image/spec/push_command_spec.rb
@@ -1,24 +1,15 @@
require 'spec_helper'
-require 'stringio'
module Aeolus
module Image
describe PushCommand do
before(:each) do
- @output = double('output')
- @stdout_orig = $stdout
- $stdout = StringIO.new
- @options = {}
@options[:provider] = ['mock']
@options[:user] = 'admin'
@options[:password] = 'password'
end
- after(:each) do
- $stdout = @stdout_orig
- end
-
describe "#run" do
before(:each) do
options = {}
@@ -49,8 +40,8 @@ module Aeolus
describe "#combo_implemented?" do
it "should give useful feedback if no template or target is specified"
do
- @options[:id] = ''
- @options[:provider] = []
+ @options.delete(:id)
+ @options.delete(:provider)
b = PushCommand.new(@options, @output)
begin
b.combo_implemented?
diff --git a/services/image_factory/aeolus-image/spec/spec_helper.rb
b/services/image_factory/aeolus-image/spec/spec_helper.rb
index ad0b5cc..fb58b43 100644
--- a/services/image_factory/aeolus-image/spec/spec_helper.rb
+++ b/services/image_factory/aeolus-image/spec/spec_helper.rb
@@ -2,6 +2,7 @@ $: << File.expand_path(File.join(File.dirname(__FILE__),
"../lib"))
$: << File.expand_path(File.join(File.dirname(__FILE__), "."))
require 'rubygems'
require 'config_parser'
+require 'stringio'
require 'base_command'
require 'list_command'
require 'build_command'
@@ -39,4 +40,13 @@ Spec::Runner.configure do |config|
end
end
end
+ config.before(:each) do
+ @output = double('output')
+ @stdout_orig = $stdout
+ $stdout = StringIO.new
+ @options = {}
+ end
+ config.after(:each) do
+ $stdout = @stdout_orig
+ end
end
\ No newline at end of file
--
1.7.4.4