From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/delete_command.rb | 33 ++-------
spec/command/delete_command_spec.rb | 73 +++++++++++++++++++
.../command/delete_command/delete_build.yml | 71 ++++++++++++++++++
.../command/delete_command/delete_image.yml | 77 ++++++++++++++++++++
.../delete_command/delete_provider_image.yml | 75 +++++++++++++++++++
.../command/delete_command/delete_target_image.yml | 77 ++++++++++++++++++++
6 files changed, 379 insertions(+), 27 deletions(-)
create mode 100644 spec/command/delete_command_spec.rb
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_build.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_image.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_provider_image.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_target_image.yml
diff --git a/lib/aeolus_cli/command/delete_command.rb
b/lib/aeolus_cli/command/delete_command.rb
index 96cebcc..71dc2e3 100644
--- a/lib/aeolus_cli/command/delete_command.rb
+++ b/lib/aeolus_cli/command/delete_command.rb
@@ -21,8 +21,8 @@ module Aeolus
def provider_image
if pi = ProviderImage.find(@options[:providerimage])
- if pi.delete!
- puts "b: " + @options[:providerimage] + " Deleted
Successfully"
+ if pi.destroy
+ puts "Provider Image: " + @options[:providerimage] + " Deleted
Successfully"
exit(0)
end
puts "ERROR: Unable to Delete Provider Image: " +
@options[:providerimage]
@@ -34,7 +34,7 @@ module Aeolus
def target_image
if ti = TargetImage.find(@options[:targetimage])
- if ti.delete!
+ if ti.destroy
puts "Target Image: " + @options[:targetimage] + " Deleted
Successfully"
exit(0)
end
@@ -46,8 +46,8 @@ module Aeolus
end
def build
- if b = ImageBuild.find(@options[:build])
- if b.delete!
+ if b = Build.find(@options[:build])
+ if b.destroy
puts "Build: " + @options[:build] + " Deleted
Successfully"
exit(0)
end
@@ -60,7 +60,7 @@ module Aeolus
def image
if i = Image.find(@options[:image])
- if i.delete!
+ if i.destroy
puts "Image: " + @options[:image] + " Deleted
Successfully"
exit(0)
end
@@ -70,27 +70,6 @@ module Aeolus
end
exit(1)
end
-
- # Deletes all Images,Builds,TargetImages,ProviderImages
- def iwhd
- Image.all.each do |image|
- Image.delete(image.uuid)
- end
-
- ImageBuild.all.each do |build|
- ImageBuild.delete(build.uuid)
- end
-
- TargetImage.all.each do |target_image|
- TargetImage.delete(target_image.uuid)
- end
-
- ProviderImage.all.each do |provider_image|
- ProviderImage.delete(provider_image.uuid)
- end
- puts "Deleted all objects in IWHD"
- exit(0)
- end
end
end
end
diff --git a/spec/command/delete_command_spec.rb b/spec/command/delete_command_spec.rb
new file mode 100644
index 0000000..b4880a9
--- /dev/null
+++ b/spec/command/delete_command_spec.rb
@@ -0,0 +1,73 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe DeleteCommand do
+ it "should delete a provider image of a given id" do
+ @options = {:providerimage =>
"8f8bc89c-f86b-4366-8b28-f632ad7ce711"}
+ VCR.use_cassette('command/delete_command/delete_provider_image') do
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.provider_image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Provider Image:
8f8bc89c-f86b-4366-8b28-f632ad7ce711 Deleted Successfully")
+ end
+ end
+
+ it "should delete an target image of a given id" do
+ VCR.use_cassette('command/delete_command/delete_target_image') do
+ @options = {:targetimage =>
"e626cadf-5901-4db4-95c5-d53a696e00dd"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.target_image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Target Image:
e626cadf-5901-4db4-95c5-d53a696e00dd Deleted Successfully")
+ end
+ end
+
+ it "should delete a build of a given id" do
+ @options = {:build => "a5b23c06-8d63-4173-be49-fb15975065da"}
+ VCR.use_cassette('command/delete_command/delete_build') do
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.build
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Build: a5b23c06-8d63-4173-be49-fb15975065da
Deleted Successfully")
+ end
+ end
+
+ it "should delete an image of a given id" do
+ VCR.use_cassette('command/delete_command/delete_image') do
+ @options = {:image => "3d0ee4e4-901f-415d-be3a-f8da80e74d03"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Image: 3d0ee4e4-901f-415d-be3a-f8da80e74d03
Deleted Successfully")
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_build.yml
b/spec/vcr/cassettes/command/delete_command/delete_build.yml
new file mode 100644
index 0000000..91f7f24
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_build.yml
@@ -0,0 +1,71 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost/conductor/api/builds/a5b23c06-8d63-4173-...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"9690c7b091734e0fdb3cdd9bd0ef06d3\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:42 GMT
+ x-runtime:
+ - "0.647424"
+ content-length:
+ - "284"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlOTYyM2IxMzFjOWEzNTNiM2EzN2Y0NmQzNWZkNjYxY2EiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--e792880eac59e96477f2d88698a82c60398cf713;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <build
href='http://localhost:3000/api/builds/a5b23c06-8d63-4173-be49-fb15975065da'
id='a5b23c06-8d63-4173-be49-fb15975065da'>
+ <image
href='http://localhost:3000/api/images/3d0ee4e4-901f-415d-be3a-f8da80e74d03'
type='xs:string'>3d0ee4e4-901f-415d-be3a-f8da80e74d03</image>
+ </build>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri:
https://admin:password@localhost/conductor/api/builds/a5b23c06-8d63-4173-...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"a505c6ebbc5d403928e1ef4e4068274c\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:43 GMT
+ x-runtime:
+ - "0.665006"
+ content-length:
+ - "13"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNjgyYjY4MGQyOTM2YjVmZWFkMzIzNDIzMTA2OWI0NDgiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--f1be1b50c8200f8402d2a07004ce31b25c68876d;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: Build Deleted
+ http_version: "1.1"
diff --git a/spec/vcr/cassettes/command/delete_command/delete_image.yml
b/spec/vcr/cassettes/command/delete_command/delete_image.yml
new file mode 100644
index 0000000..5be8625
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_image.yml
@@ -0,0 +1,77 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost/conductor/api/images/3d0ee4e4-901f-415d-...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"cc43f6a95f5152f860ce275abf8053db\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:44 GMT
+ x-runtime:
+ - "0.659938"
+ content-length:
+ - "281"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlYWYwOTg2NzY1ZTJkMWZlNzMwMzg1MTRmMDAxNDk1YmEiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--3fb9e618235c265be515dcdad78d1eb45b6f228f;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <image
href='http://localhost:3000/api/images/3d0ee4e4-901f-415d-be3a-f8da80e74d03'
id='3d0ee4e4-901f-415d-be3a-f8da80e74d03'>
+ <name>tmpl1</name>
+ <description></description>
+ <os></os>
+ <os_version></os_version>
+ <arch></arch>
+ <builds type='xs:list'>
+ </builds>
+ </image>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri:
https://admin:password@localhost/conductor/api/images/3d0ee4e4-901f-415d-...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"5902e96950f4ffc9e380d555f8894f44\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:44 GMT
+ x-runtime:
+ - "0.519205"
+ content-length:
+ - "13"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZThmZGUwNGJiZDhlY2E5ODJjN2E2YzMzNWU5Mzg3ODQiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--f9ed5f598c4bd2451a26aac38bb71db82e0d2264;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: Image Deleted
+ http_version: "1.1"
diff --git a/spec/vcr/cassettes/command/delete_command/delete_provider_image.yml
b/spec/vcr/cassettes/command/delete_command/delete_provider_image.yml
new file mode 100644
index 0000000..dbbfa83
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_provider_image.yml
@@ -0,0 +1,75 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost/conductor/api/provider_images/8f8bc89c-f...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"940d3812694969c5a5e84a1d132f967d\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 20:05:22 GMT
+ x-runtime:
+ - "0.594585"
+ content-length:
+ - "484"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlYjM4Mjg2MTJhNDA1ZmYzNDBmOTc5YWFlNzA1Nzk2N2UiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--b3033b6a4e4c00a3f27d087dfe38df1b6c599a52;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <provider_image
href='http://localhost:3000/api/provider_images/8f8bc89c-f86b-4366-8b28-f632ad7ce711'
id='8f8bc89c-f86b-4366-8b28-f632ad7ce711'>
+ <object_type>provider_image</object_type>
+ <target_identifier>ami-a3ce01ca</target_identifier>
+ <status>COMPLETE</status>
+ <provider>ec2-us-east-1</provider>
+ <target_image
href='http://localhost:3000/api/target_images/2433f569-ff6e-4f8c-8c1b-6667508e4c1b'
id='2433f569-ff6e-4f8c-8c1b-6667508e4c1b'></target_image>
+ </provider_image>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri:
https://admin:password@localhost/conductor/api/provider_images/8f8bc89c-f...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"f4b3876a1a002fc8a2ebc09c1cbbab14\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 20:05:23 GMT
+ x-runtime:
+ - "0.477794"
+ content-length:
+ - "22"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlYjMwZmU1NjU0NDc1ODhlYjEzNTUyOWQxMjBiODMyOGIiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--188f8bf79153f4b7bf62877bb94bdd94f54b6788;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: Provider Image Deleted
+ http_version: "1.1"
diff --git a/spec/vcr/cassettes/command/delete_command/delete_target_image.yml
b/spec/vcr/cassettes/command/delete_command/delete_target_image.yml
new file mode 100644
index 0000000..e50b7dc
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_target_image.yml
@@ -0,0 +1,77 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost/conductor/api/target_images/e626cadf-590...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"750a6fd6f256f02577362005d205b9a0\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:41 GMT
+ x-runtime:
+ - "1.064720"
+ content-length:
+ - "629"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNGYxYWEwNTc4ZDEzZjhmMzA5OTczNDE1MWRjYTE5ZTMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--6bd775a222316d51f8fbca9c9f64a960b3cfd7d0;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <target_image
href='http://localhost:3000/api/target_images/e626cadf-5901-4db4-95c5-d53a696e00dd'
id='e626cadf-5901-4db4-95c5-d53a696e00dd'>
+ <object_type>target_image</object_type>
+ <template>b97b62c8-a55b-4fb6-8ca9-f67e4e869f0b</template>
+ <build
href='http://localhost:3000/api/builds/a5b23c06-8d63-4173-be49-fb15975065da'
id='a5b23c06-8d63-4173-be49-fb15975065da'></build>
+ <status>COMPLETE</status>
+ <provider_image>
+ <provider_image
href='http://localhost:3000/api/provider_images/c36c478c-58af-446b-80bf-1720724a68bd'
id='c36c478c-58af-446b-80bf-1720724a68bd'></provider_image>
+ </provider_image>
+ </target_image>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri:
https://admin:password@localhost/conductor/api/target_images/e626cadf-590...
+ body:
+ headers:
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"c2f80b58455fb6d578895fc59bf244e2\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 19:52:42 GMT
+ x-runtime:
+ - "0.616347"
+ content-length:
+ - "20"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlYTc5NGUyMzY0NTk1MzNmNWMyNjA3OGJmYmJlYTE4YjQiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--2530799f06e70fa34ea5562eb195c1304c530774;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: Target Image Deleted
+ http_version: "1.1"
--
1.7.6.4