Applies on top of last patch set:
[PATCH aeolus-image 1/2] Brings WarehouseModel objects in from Conductor
[PATCH aeolus-image 2/2] Added Template Model and fields to Image
Show replies by date
From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_image/command/build_command.rb | 11 +++++++++++
lib/aeolus_image/command/list_command.rb | 17 +++++++++++++----
spec/build_command_spec.rb | 12 ++++++++++++
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/lib/aeolus_image/command/build_command.rb
b/lib/aeolus_image/command/build_command.rb
index 0a6601c..5dc0cc9 100644
--- a/lib/aeolus_image/command/build_command.rb
+++ b/lib/aeolus_image/command/build_command.rb
@@ -20,6 +20,7 @@ module Aeolus
def run
if combo_implemented?
+ check_targets
@options[:template_str] = read_file(@options[:template])
if @options[:template_str].nil?
puts "Cannot find specified file"
@@ -58,6 +59,16 @@ module Aeolus
true
end
+ def check_targets
+ lc = ListCommand.new
+ @options[:target].each do |target|
+ unless lc.target_references.include?(target)
+ puts "ERROR: The given target: '" + target + "' is not
supported"
+ quit(1)
+ end
+ end
+ end
+
def quit(code)
@console.shutdown
super
diff --git a/lib/aeolus_image/command/list_command.rb
b/lib/aeolus_image/command/list_command.rb
index cccd382..e730390 100644
--- a/lib/aeolus_image/command/list_command.rb
+++ b/lib/aeolus_image/command/list_command.rb
@@ -128,14 +128,23 @@ module Aeolus
providerimages
end
- def targets
- targets = [["NAME", "TARGET CODE"]]
- targets << ["Mock", "mock"]
+ #TODO: Should really get these targets from conductor/imagefactory. At the moment
Imagefactory does not
+ # offer a way to get these through its API and the ones in Conductor are at
the moment not compatible
+ # with image factory, so these are hardcoded for time being
+ def supported_targets
+ targets = [["Mock", "mock"]]
targets << ["Amazon EC2", "ec2"]
targets << ["RHEV-M", "rhevm"]
targets << ["VMware vSphere", "vsphere"]
targets << ["Condor Cloud", "condor_cloud"]
- format_print(targets)
+ end
+
+ def target_references
+ supported_targets.map { |target| target[1] }
+ end
+
+ def targets
+ format_print([["NAME", "TARGET CODE"]] + supported_targets)
quit(0)
end
diff --git a/spec/build_command_spec.rb b/spec/build_command_spec.rb
index adabb19..fcda5dc 100644
--- a/spec/build_command_spec.rb
+++ b/spec/build_command_spec.rb
@@ -43,6 +43,18 @@ module Aeolus
end
$stdout.string.should include("ERROR: The given Template does not conform
to the TDL Schema")
end
+ it "should exit with appropriate message when an invalid target is
provided" do
+ @options[:template] = "#{File.dirname(__FILE__)}" +
"/../examples/custom_repo.tdl"
+ @options[:image] = '825c94d1-1353-48ca-87b9-36f02e069a8d'
+ @options[:target] = ["InvalidTarget"]
+ b = BuildCommand.new(@options, @output)
+ begin
+ b.check_targets
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("ERROR: The given target:
'InvalidTarget' is not supported")
+ end
end
describe "#combo_implemented?" do
--
1.7.6