From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/import_command.rb | 26 ++++------
spec/command/import_command_spec.rb | 50 +++++++++--------
.../import_command/import_image_default.yml | 56 ++++++++++++++++++++
.../import_image_description_file.yml | 56 ++++++++++++++++++++
4 files changed, 149 insertions(+), 39 deletions(-)
create mode 100644 spec/vcr/cassettes/command/import_command/import_image_default.yml
create mode 100644
spec/vcr/cassettes/command/import_command/import_image_description_file.yml
diff --git a/lib/aeolus_cli/command/import_command.rb
b/lib/aeolus_cli/command/import_command.rb
index aea159f..09d12b5 100644
--- a/lib/aeolus_cli/command/import_command.rb
+++ b/lib/aeolus_cli/command/import_command.rb
@@ -26,8 +26,6 @@ module Aeolus
:provider => ''
}
@options = default.merge(@options)
- @console = ImageFactoryConsole.new()
- @console.start
end
def import_image
@@ -36,23 +34,19 @@ module Aeolus
@options[:description] = description
end
# TODO: Validate Description XML
-
- #This is a temporary hack in case the agent doesn't show up on bus
- #immediately
- sleep(5)
- import_map = @console.import_image(@options[:image], @options[:build],
@options[:id], @options[:description], @options[:target].first,
@options[:provider].first)
+ image = Aeolus::CLI::Image.new({:target_identifier => @options[:id],
+ :target_name => @options[:target].first,
+ :image_descriptor => @options[:description],
+ :provider_name => @options[:provider].first})
+ image.save!
puts ""
- puts "Target Image: " + import_map['target_image']
- puts "Image: " + import_map['image']
- puts "Build: " + import_map['build']
- puts "Provider Image: " + import_map['provider_image']
+ puts "Image: " + image.id
+ puts "Build: " + image.build.id
+ puts "Target Image: " + image.build.target_images.target_image.id
+ puts "Provider Image: " +
image.build.target_images.target_image.provider_images.provider_image.id
+ puts "Status: " +
image.build.target_images.target_image.provider_images.provider_image.status
quit(0)
end
-
- def quit(code)
- @console.shutdown
- super
- end
end
end
end
diff --git a/spec/command/import_command_spec.rb b/spec/command/import_command_spec.rb
index 9477f9e..29b9ce8 100644
--- a/spec/command/import_command_spec.rb
+++ b/spec/command/import_command_spec.rb
@@ -18,38 +18,42 @@ module Aeolus
module CLI
describe ImportCommand do
before(:each) do
- @options[:id] = "ami-test"
- @options[:target] = "ec2"
- @options[:provider] = "ec2-us-east-1"
+ @options = { :id => "ami-5592553c",
+ :target => ["ec2"],
+ :provider => ["ec2-us-east-1"],
+ :description =>
"<image><name>MyImage</name></image>"}
end
describe "#import_image" do
it "should import an image with default description values" do
- importc = ImportCommand.new(@options)
- begin
- importc.import_image
- rescue SystemExit => e
- e.status.should == 0
+ VCR.use_cassette('command/import_command/import_image_default') do
+ importc = ImportCommand.new(@options)
+ begin
+ importc.import_image
+ 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("Provider Image:")
end
- $stdout.string.should include("Image:")
- $stdout.string.should include("Target Image:")
- $stdout.string.should include("Build:")
- $stdout.string.should include("Provider Image:")
end
it "should import an image with file description" do
- @options[:description] = 'spec/sample_data/image_description.xml'
- importc = ImportCommand.new(@options)
- begin
- importc.import_image
- rescue SystemExit => e
- e.status.should == 0
+
VCR.use_cassette('command/import_command/import_image_description_file') do
+ @options[:description] = 'spec/sample_data/image_description.xml'
+ importc = ImportCommand.new(@options)
+ begin
+ importc.import_image
+ 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("Provider Image:")
end
- $stdout.string.should include("Image:")
- $stdout.string.should include("Target Image:")
- $stdout.string.should include("Build:")
- $stdout.string.should include("Provider Image:")
- #TODO: Add test to check that file was uploaded properly (when we have
implemented a show/view image command)
end
end
end
diff --git a/spec/vcr/cassettes/command/import_command/import_image_default.yml
b/spec/vcr/cassettes/command/import_command/import_image_default.yml
new file mode 100644
index 0000000..2bf6ca5
--- /dev/null
+++ b/spec/vcr/cassettes/command/import_command/import_image_default.yml
@@ -0,0 +1,56 @@
+---
+- !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>
+ <target_name>ec2</target_name>
+ <target_identifier>ami-5592553c</target_identifier>
+ <provider_name>ec2-us-east-1</provider_name>
+
<image_descriptor><image><name>MyImage</name></image></image_descriptor>
+ </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:
+ - "\"a5b26b0eecf7d74100adf5d79c090dfe\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 22:24:37 GMT
+ x-runtime:
+ - "0.444207"
+ content-length:
+ - "760"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNGYzZDhlZTI5YzE5Nzg1OTBkMzM5NjI2ZjA3OGYyNmMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--995b18565f8b15557a3b3897fa3dbeca9e970a17;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <image
href='http://localhost:3000/api/images/ddc15456-6fe3-4947-abdd-b198e0f3362d'
id='ddc15456-6fe3-4947-abdd-b198e0f3362d'>
+ <build
href='http://localhost:3000/api/builds/c65d1b8a-5484-47ce-915e-fe57897eb1f1'
id='c65d1b8a-5484-47ce-915e-fe57897eb1f1'>
+ <target_images>
+ <target_image
href='http://localhost:3000/api/target_images/07553e18-ad7e-455e-aa18-b6d2c1c810b2'
id='07553e18-ad7e-455e-aa18-b6d2c1c810b2'>
+ <provider_images>
+ <provider_image
href='http://localhost:3000/api/provider_images/19c08854-9b3b-4abd-b19c-3d0f98a7d105'
id='19c08854-9b3b-4abd-b19c-3d0f98a7d105'>
+ <status>COMPLETE</status>
+ </provider_image>
+ </provider_images>
+ </target_image>
+ </target_images>
+ </build>
+ </image>
+
+ http_version: "1.1"
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/import_command/import_image_description_file.yml
b/spec/vcr/cassettes/command/import_command/import_image_description_file.yml
new file mode 100644
index 0000000..053a1cb
--- /dev/null
+++ b/spec/vcr/cassettes/command/import_command/import_image_description_file.yml
@@ -0,0 +1,56 @@
+---
+- !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>
+ <target_name>ec2</target_name>
+ <target_identifier>ami-5592553c</target_identifier>
+ <provider_name>ec2-us-east-1</provider_name>
+
<image_descriptor>spec/sample_data/image_description.xml</image_descriptor>
+ </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:
+ - "\"9bffa6c31d892ed5173064f19d76ab9e\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 22:24:38 GMT
+ x-runtime:
+ - "0.545222"
+ content-length:
+ - "760"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNmMwM2Q3YWYyMmQwN2VmNDg2MTU4YzNhZGI1NzU4ODMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--99d5431c9025c37b729f5f254b52104fad89cc1e;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <image
href='http://localhost:3000/api/images/510bec08-e6fa-4004-aa21-c726b420d97e'
id='510bec08-e6fa-4004-aa21-c726b420d97e'>
+ <build
href='http://localhost:3000/api/builds/24c0f87e-86f6-4bd3-a3a6-a61d89b348f6'
id='24c0f87e-86f6-4bd3-a3a6-a61d89b348f6'>
+ <target_images>
+ <target_image
href='http://localhost:3000/api/target_images/e6841cdc-c632-4dc8-be5e-8da8476b02cc'
id='e6841cdc-c632-4dc8-be5e-8da8476b02cc'>
+ <provider_images>
+ <provider_image
href='http://localhost:3000/api/provider_images/e21fe1a3-4c14-473a-8818-9aeeac09c8ad'
id='e21fe1a3-4c14-473a-8818-9aeeac09c8ad'>
+ <status>COMPLETE</status>
+ </provider_image>
+ </provider_images>
+ </target_image>
+ </target_images>
+ </build>
+ </image>
+
+ http_version: "1.1"
\ No newline at end of file
--
1.7.6.4