From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/build_command.rb | 60 ++++++++----------
spec/command/build_command_spec.rb | 26 +++++---
spec/vcr/cassettes/command/build_command/build.yml | 66 ++++++++++++++++++++
3 files changed, 107 insertions(+), 45 deletions(-)
create mode 100644 spec/vcr/cassettes/command/build_command/build.yml
diff --git a/lib/aeolus_cli/command/build_command.rb
b/lib/aeolus_cli/command/build_command.rb
index 78b361c..8bd5b93 100644
--- a/lib/aeolus_cli/command/build_command.rb
+++ b/lib/aeolus_cli/command/build_command.rb
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require 'imagefactory'
-
module Aeolus
module CLI
class BuildCommand < BaseCommand
@@ -28,42 +26,42 @@ module Aeolus
:build => ''
}
@options = default.merge(@options)
- @console = ImageFactoryConsole.new()
- @console.start
end
def run
if combo_implemented?
- @options[:template_str] = read_file(@options[:template])
- if @options[:template_str].nil?
- puts "Cannot find specified file"
- quit(1)
- end
+ template = read_template
+ validate_xml_schema(template)
- # Validate XML against TDL Schema
- errors = validate_xml_document(File.dirname(__FILE__) +
"/../../../examples/tdl.rng", @options[:template_str])
- if errors.length > 0
- puts "ERROR: The given Template does not conform to the TDL Schema, see
below for specific details:"
- errors.each do |error|
- puts "- " + error.message
- end
- quit(1)
- end
+ image = Aeolus::CLI::Image.new({:targets => @options[:target].to_s, :tdl
=> template})
+ image.save!
+ puts "Image: " + image.id
+ puts "Build: " + image.build.id
+ puts "Target Image: " + image.build.target_images.target_image.id
+ quit(0)
+ end
+ end
- #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],
@options[:build]).each do |adaptor|
- puts ""
- puts "Target Image: #{adaptor.image_id}"
- puts "Image: #{adaptor.image}"
- puts "Build: #{adaptor.build}"
- puts "Status: #{adaptor.status}"
- puts "Percent Complete: #{adaptor.percent_complete}"
+ def validate_xml_schema(xml)
+ errors = validate_xml_document(File.dirname(__FILE__) +
"/../../../examples/tdl.rng", xml)
+ if errors.length > 0
+ puts "ERROR: The given Template does not conform to the TDL Schema, see
below for specific details:"
+ errors.each do |error|
+ puts "- " + error.message
end
- quit(0)
+ quit(1)
end
end
+ def read_template
+ template = read_file(@options[:template])
+ if template.nil?
+ puts "Cannot find specified file"
+ quit(1)
+ end
+ template
+ end
+
def combo_implemented?
if @options[:template].empty? || @options[:target].empty?
puts "This combination of parameters is not currently supported"
@@ -71,12 +69,6 @@ module Aeolus
end
true
end
-
- def quit(code)
- @console.shutdown
- super
- end
-
end
end
end
diff --git a/spec/command/build_command_spec.rb b/spec/command/build_command_spec.rb
index c9887d0..0ab2fbd 100644
--- a/spec/command/build_command_spec.rb
+++ b/spec/command/build_command_spec.rb
@@ -18,22 +18,25 @@ module Aeolus
module CLI
describe BuildCommand do
before(:each) do
- @options[:target] = ['mock','ec2']
- @options[:template] = "#{File.dirname(__FILE__)}" +
"/../examples/custom_repo.tdl"
+ @options[:target] = ['ec2']
+ @options[:template] = "#{File.dirname(__FILE__)}" +
"../../fixtures/valid_template.tdl"
end
describe "#run" do
it "should kick off a build with valid options" do
- b = BuildCommand.new(@options, @output)
- begin
- b.run
- rescue SystemExit => e
- e.status.should == 0
+ VCR.use_cassette('command/build_command/build') do
+ b = BuildCommand.new(@options, @output)
+ begin
+ b.run
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Image:")
+ $stdout.string.should include("Target Image:")
+ $stdout.string.should include("Build:")
end
- $stdout.string.should include("Image:")
- $stdout.string.should include("Target Image:")
- $stdout.string.should include("Build:")
end
+
it "should exit with a message if only image id is provided" do
@options.delete(:template)
@options.delete(:target)
@@ -46,8 +49,9 @@ module Aeolus
end
$stdout.string.should include("This combination of parameters is not
currently supported")
end
+
it "should exit with appropriate message when a non compliant template is
given" do
- @options[:template] = "spec/fixtures/invalid_template.tdl"
+ @options[:template] = "#{File.dirname(__FILE__)}" +
"../../fixtures/invalid_template.tdl"
@options[:image] = '825c94d1-1353-48ca-87b9-36f02e069a8d'
b = BuildCommand.new(@options, @output)
begin
diff --git a/spec/vcr/cassettes/command/build_command/build.yml
b/spec/vcr/cassettes/command/build_command/build.yml
new file mode 100644
index 0000000..c1e6dc1
--- /dev/null
+++ b/spec/vcr/cassettes/command/build_command/build.yml
@@ -0,0 +1,66 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
https://admin:password@localhost/conductor/api/images.xml
+ body: |
+ <?xml version="1.0" encoding="UTF-8"?>
+ <image>
+ <targets>ec2</targets>
+ <tdl><template>
+ <name>tmpl1</name>
+ <description>foo</description>
+ <os>
+ <name>Fedora</name>
+ <arch>x86_64</arch>
+ <version>14</version>
+ <install type="url">
+
<url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>
+ </install>
+ </os>
+ <repositories>
+ <repository name="custom">
+
<url>http://repos.fedorapeople.org/repos/aeolus/demo/webapp/</url>
+ <signed>false</signed>
+ </repository>
+ </repositories>
+ </template></tdl>
+ </image>
+
+ headers:
+ content-type:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"30d8cefae8512ba1ca0339ea65a97a11\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Tue, 18 Oct 2011 20:43:34 GMT
+ x-runtime:
+ - "0.610872"
+ content-length:
+ - "506"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNDM1MDhhNTU5OTUyZGExMjI0ZmMxNTQxODk5ZjAyNmIiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--413b56edceb09120972fbb2569938f03184f2ca8;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <image
href='http://localhost:3000/api/images/a36ad5dd-b050-4dc3-bdc2-848fdcc9d956'
id='a36ad5dd-b050-4dc3-bdc2-848fdcc9d956'>
+ <build
href='http://localhost:3000/api/builds/48fb708a-902e-4767-b7c4-161e43103b95'
id='48fb708a-902e-4767-b7c4-161e43103b95'>
+ <target_images>
+ <target_image
href='http://localhost:3000/api/target_images/f99926c1-86f7-4062-879d-b149b5325afe'
id='f99926c1-86f7-4062-879d-b149b5325afe'></target_image>
+ <status>New</status>
+ </target_images>
+ </build>
+ </image>
+
+ http_version: "1.1"
\ No newline at end of file
--
1.7.6.4