From: Maros Zatko mzatko@redhat.com
--- lib/aeolus_cli/command/build_command.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/aeolus_cli/command/build_command.rb b/lib/aeolus_cli/command/build_command.rb index a3e5341..c2978e9 100644 --- a/lib/aeolus_cli/command/build_command.rb +++ b/lib/aeolus_cli/command/build_command.rb @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License.
+require 'open-uri' + module Aeolus module CLI class BuildCommand < BaseCommand @@ -73,13 +75,14 @@ module Aeolus end
def read_template - template = read_file(@options[:template]) - if template.nil? - puts "Error: Cannot find specified file" - quit(1) + begin + f = open(@options[:template]) + return f.read + rescue Errno::ENOENT => e + puts "Error: Cannot open '#{e}'" + exit(1) end - template - end + end
def combo_implemented? if @options[:template].empty? || @options[:target].empty? || @options[:environment].nil?
From: Maros Zatko mzatko@redhat.com
--- spec/command/build_command_spec.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/spec/command/build_command_spec.rb b/spec/command/build_command_spec.rb index f969aa4..a2b9be6 100644 --- a/spec/command/build_command_spec.rb +++ b/spec/command/build_command_spec.rb @@ -19,7 +19,7 @@ module Aeolus describe BuildCommand do before(:each) do @options[:target] = ['ec2'] - @options[:template] = "#{File.dirname(__FILE__)}" + "../../fixtures/valid_template.tdl" + @options[:template] = File.join("#{File.dirname(__FILE__)}", "../fixtures/valid_template.tdl") @options[:environment] = ['default'] end
@@ -47,6 +47,30 @@ module Aeolus end end
+ it "should kick off a build with template in URL" do + @options[:template] = 'http://localhost:8000/valid_template.tdl' + VCR.use_cassette('command/build_command/build_url') 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") + $stdout.string.should include("Target") + $stdout.string.should include("Status") + + $stdout.string.should include("6affc8f5-a560-4b7e-88da-2e993cf9ebce") + $stdout.string.should include("e0412885-28a6-4c3f-898a-886680ffadd0") + $stdout.string.should include("0079b860-e601-4705-8729-d7624f160786") + $stdout.string.should include("COMPLETED") + $stdout.string.should include("ec2") + + end + end + it "should build for multiple targets" do VCR.use_cassette('command/build_command/multiple_build') do @options[:target] = ['ec2,mock'] @@ -83,7 +107,7 @@ module Aeolus end
it "should exit with appropriate message when a non compliant template is given" do - @options[:template] = "#{File.dirname(__FILE__)}" + "../../fixtures/invalid_template.tdl" + @options[:template] = File.join("#{File.dirname(__FILE__)}", "../fixtures/invalid_template.tdl") @options[:image] = '825c94d1-1353-48ca-87b9-36f02e069a8d' b = BuildCommand.new(@options, @output) begin
From: Maros Zatko mzatko@redhat.com
--- .../cassettes/command/build_command/build_url.yml | 115 ++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 spec/vcr/cassettes/command/build_command/build_url.yml
diff --git a/spec/vcr/cassettes/command/build_command/build_url.yml b/spec/vcr/cassettes/command/build_command/build_url.yml new file mode 100644 index 0000000..5cf547a --- /dev/null +++ b/spec/vcr/cassettes/command/build_command/build_url.yml @@ -0,0 +1,115 @@ +--- +- !ruby/struct:VCR::HTTPInteraction + request: !ruby/struct:VCR::Request + method: :get + uri: http://localhost:8000/valid_template.tdl + body: + headers: + response: !ruby/struct:VCR::Response + status: !ruby/struct:VCR::ResponseStatus + code: 200 + message: OK + headers: + server: + - SimpleHTTP/0.6 Python/2.7.3 + content-type: + - application/octet-stream + content-length: + - "519" + date: + - Wed, 18 Jul 2012 16:18:16 GMT + last-modified: + - Wed, 18 Jul 2012 16:18:11 GMT + body: |- + <template> + <name>tmpl1</name> + <description>foo</description> + <os> + <rootpw>password</rootpw> + <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...</url> + </install> + </os> + <repositories> + <repository name="custom"> + <url>http://repos.fedorapeople.org/repos/aeolus/demo/webapp/</url> + <signed>false</signed> + </repository> + </repositories> + </template> + http_version: "1.1" +- !ruby/struct:VCR::HTTPInteraction + request: !ruby/struct:VCR::Request + method: :post + uri: https://admin:password@localhost:443/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> + <rootpw>password</rootpw> + <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...; + </install> + </os> + <repositories> + <repository name="custom"> + <url>http://repos.fedorapeople.org/repos/aeolus/demo/webapp/%3C/url%3E; + <signed>false</signed> + </repository> + </repositories> + </template></tdl> + </image> + + headers: + accept-language: + - en + content-type: + - application/xml + response: !ruby/struct:VCR::Response + status: !ruby/struct:VCR::ResponseStatus + code: 200 + message: OK + headers: + x-ua-compatible: + - IE=Edge,chrome=1 + etag: + - ""1cc9b56f5dd748a8cfa4632c4f5b54b3"" + content-type: + - application/xml; charset=utf-8 + server: + - thin 1.2.11 codename Bat-Shit Crazy + date: + - Tue, 13 Dec 2011 15:25:24 GMT + x-runtime: + - "2.639965" + set-cookie: + - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlMWJjMzE4Zjc3MThiN2I4ZDc1OTg4MDE4ZmU3YmZmYzkiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--29e37a191161ffc7c3d145e46e63c9c72179b1e8; path=/; HttpOnly + cache-control: + - max-age=0, private, must-revalidate + transfer-encoding: + - chunked + body: |+ + <image href='https://localhost/conductor/api/images/6affc8f5-a560-4b7e-88da-2e993cf9ebce' id='6affc8f5-a560-4b7e-88da-2e993cf9ebce'> + <build href='https://localhost/conductor/api/builds/e0412885-28a6-4c3f-898a-886680ffadd0' id='e0412885-28a6-4c3f-898a-886680ffadd0'> + <target_images> + <target_image href='https://localhost/conductor/api/target_images/0079b860-e601-4705-8729-d7624f...' id='0079b860-e601-4705-8729-d7624f160786'> + <status>COMPLETED</status> + <target>ec2</target> + <provider_images> + </provider_images> + </target_image> + </target_images> + </build> + </image> + + http_version: "1.1"
On Wednesday, July 18, 2012 06:34:56 PM mzatko@redhat.com wrote:
ACK, works for me.
aeolus-devel@lists.fedorahosted.org