[PATCH aeolus-cli] BZ#767068 Fixed Error handling on delete
mtaylor at redhat.com
mtaylor at redhat.com
Fri Dec 16 15:33:38 UTC 2011
From: Martyn Taylor <mtaylor at redhat.com>
---
lib/aeolus_cli/command/delete_command.rb | 72 ++++-------
spec/command/delete_command_spec.rb | 136 ++++++++++++++------
.../delete_command/delete_build_not_found.yml | 39 ++++++
.../delete_command/delete_image_not_found.yml | 39 ++++++
.../delete_provider_image_not_found.yml | 39 ++++++
.../delete_target_image_not_found.yml | 39 ++++++
6 files changed, 277 insertions(+), 87 deletions(-)
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_build_not_found.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_image_not_found.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_provider_image_not_found.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_target_image_not_found.yml
diff --git a/lib/aeolus_cli/command/delete_command.rb b/lib/aeolus_cli/command/delete_command.rb
index 8f7b3cd..54de83f 100644
--- a/lib/aeolus_cli/command/delete_command.rb
+++ b/lib/aeolus_cli/command/delete_command.rb
@@ -21,18 +21,12 @@ module Aeolus
def provider_image
begin
- if pi = ProviderImage.find(@options[:providerimage])
- if response = pi.destroy
- puts "Provider Image: " + @options[:providerimage] + " Deleted Successfully"
- puts ""
- print_provider_content(response.body)
- exit(0)
- end
- puts "ERROR: Unable to Delete Provider Image: " + @options[:providerimage]
- exit(1)
- else
- puts "ERROR: Provider Image: " + @options[:providerimage] + " does not exist"
- exit(1)
+ pi = ProviderImage.new({:id => @options[:providerimage]})
+ if response = pi.destroy
+ puts "Provider Image: " + @options[:providerimage] + " Deleted Successfully"
+ puts ""
+ print_provider_content(response.body)
+ exit(0)
end
rescue => e
handle_exception(e)
@@ -41,18 +35,12 @@ module Aeolus
def target_image
begin
- if ti = TargetImage.find(@options[:targetimage])
- if response = ti.destroy
- puts "Target Image: " + @options[:targetimage] + " Deleted Successfully"
- puts ""
- print_provider_content(response.body)
- exit(0)
- end
- puts "ERROR: Unable to Delete Target Image: " + @options[:targetimage]
- exit(1)
- else
- puts "ERROR: Target Image: " + @options[:targetimage] + " does not exist"
- exit(1)
+ ti = TargetImage.new({:id => @options[:targetimage]})
+ if response = ti.destroy
+ puts "Target Image: " + @options[:targetimage] + " Deleted Successfully"
+ puts ""
+ print_provider_content(response.body)
+ exit(0)
end
rescue => e
handle_exception(e)
@@ -61,18 +49,12 @@ module Aeolus
def build
begin
- if b = Build.find(@options[:build])
- if response = b.destroy
- puts "Build: " + @options[:build] + " Deleted Successfully"
- puts ""
- print_provider_content(response.body)
- exit(0)
- end
- puts "ERROR: Unable to Delete Build: " + @options[:build]
- exit(1)
- else
- puts "ERROR: Build: " + @options[:build] + " does not exist"
- exit(1)
+ b = Build.new({:id => @options[:build]})
+ if response = b.destroy
+ puts "Build: " + @options[:build] + " Deleted Successfully"
+ puts ""
+ print_provider_content(response.body)
+ exit(0)
end
rescue => e
handle_exception(e)
@@ -81,19 +63,15 @@ module Aeolus
def image
begin
- if i = Image.find(@options[:image])
- if response = i.destroy
- puts "Image: " + @options[:image] + " Deleted Successfully"
- puts ""
- print_provider_content(response.body)
- exit(0)
- end
- puts "ERROR: Unable to Delete Image: " + @options[:image]
- else
- puts "ERROR: Image: " + @options[:image] + " does not exist"
+ i = Image.new({:id => @options[:image]})
+ if response = i.destroy
+ puts "Image: " + @options[:image] + " Deleted Successfully"
+ puts ""
+ print_provider_content(response.body)
+ exit(0)
end
rescue => e
- exit(1)
+ handle_exception(e)
end
end
diff --git a/spec/command/delete_command_spec.rb b/spec/command/delete_command_spec.rb
index 49051a8..7325161 100644
--- a/spec/command/delete_command_spec.rb
+++ b/spec/command/delete_command_spec.rb
@@ -17,57 +17,113 @@ require 'spec_helper'
module Aeolus
module CLI
describe DeleteCommand do
- it "should delete a provider image of a given id" do
- @options = {:providerimage => "20bb51cb-a289-4331-9e56-26196df62ca8"}
- 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
+ context "Sucessful Delete" do
+ it "should delete a provider image of a given id" do
+ @options = {:providerimage => "20bb51cb-a289-4331-9e56-26196df62ca8"}
+ 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: 20bb51cb-a289-4331-9e56-26196df62ca8 Deleted Successfully")
end
- $stdout.string.should include("Provider Image: 20bb51cb-a289-4331-9e56-26196df62ca8 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 => "ef7ee9be-5f3c-4695-969a-7c3fa996c048"}
- dc = DeleteCommand.new(@options)
- begin
- dc.target_image
- rescue SystemExit => e
- e.status.should == 0
+ it "should delete an target image of a given id" do
+ VCR.use_cassette('command/delete_command/delete_target_image') do
+ @options = {:targetimage => "ef7ee9be-5f3c-4695-969a-7c3fa996c048"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.target_image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Target Image: ef7ee9be-5f3c-4695-969a-7c3fa996c048 Deleted Successfully")
end
- $stdout.string.should include("Target Image: ef7ee9be-5f3c-4695-969a-7c3fa996c048 Deleted Successfully")
end
- end
- it "should delete a build of a given id" do
- @options = {:build => "becc269c-8a02-4f6a-9132-2af3cb580b2b"}
- VCR.use_cassette('command/delete_command/delete_build') do
- dc = DeleteCommand.new(@options)
- begin
- dc.build
- rescue SystemExit => e
- e.status.should == 0
+ it "should delete a build of a given id" do
+ @options = {:build => "becc269c-8a02-4f6a-9132-2af3cb580b2b"}
+ 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: becc269c-8a02-4f6a-9132-2af3cb580b2b 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 => "55bc53d9-7310-4cff-8c26-99823d79dfa6"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Image: 55bc53d9-7310-4cff-8c26-99823d79dfa6 Deleted Successfully")
+ $stdout.string.should include("N.B. The following provider content must be manually removed")
+ $stdout.string.should include("mock")
end
- $stdout.string.should include("Build: becc269c-8a02-4f6a-9132-2af3cb580b2b 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 => "55bc53d9-7310-4cff-8c26-99823d79dfa6"}
- dc = DeleteCommand.new(@options)
- begin
- dc.image
- rescue SystemExit => e
- e.status.should == 0
+ context "Delete Failed Not Found" do
+ it "should display an appropriate message when the given image is not found" do
+ VCR.use_cassette('command/delete_command/delete_image_not_found') do
+ @options = {:image => "1234"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.image
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("Could not find Image 1234")
+ end
+ end
+
+ it "should display an appropriate message when the given build is not found" do
+ VCR.use_cassette('command/delete_command/delete_build_not_found') do
+ @options = {:build => "1234"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.build
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("Could not find Build 1234")
+ end
+ end
+
+ it "should display an appropriate message when the given target image is not found" do
+ VCR.use_cassette('command/delete_command/delete_target_image_not_found') do
+ @options = {:targetimage => "1234"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.target_image
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("Could not find TargetImage 1234")
+ end
+ end
+
+ it "should display an appropriate message when the given provider image is not found" do
+ VCR.use_cassette('command/delete_command/delete_provider_image_not_found') do
+ @options = {:providerimage => "1234"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.provider_image
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("Could not find ProviderImage 1234")
end
- $stdout.string.should include("Image: 55bc53d9-7310-4cff-8c26-99823d79dfa6 Deleted Successfully")
- $stdout.string.should include("N.B. The following provider content must be manually removed")
- $stdout.string.should include("mock")
end
end
end
diff --git a/spec/vcr/cassettes/command/delete_command/delete_build_not_found.yml b/spec/vcr/cassettes/command/delete_command/delete_build_not_found.yml
new file mode 100644
index 0000000..a879c96
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_build_not_found.yml
@@ -0,0 +1,39 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/builds/1234.xml
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 404
+ message: Not Found
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Fri, 16 Dec 2011 15:22:02 GMT
+ x-runtime:
+ - "0.030815"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlOGQyZDQ1OGJlNzI5YTQ1YTIzNTlhYzM5NmE2YzlkNmUiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--246122de0cd2d386edb27a7e2eb14e4ac1818975; path=/; HttpOnly
+ cache-control:
+ - no-cache
+ transfer-encoding:
+ - chunked
+ body: |
+ <error>
+ <code>BuildNotFound</code>
+ <message>Could not find Build 1234</message>
+ </error>
+
+ http_version: "1.1"
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_image_not_found.yml b/spec/vcr/cassettes/command/delete_command/delete_image_not_found.yml
new file mode 100644
index 0000000..459ca77
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_image_not_found.yml
@@ -0,0 +1,39 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/images/1234.xml
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 500
+ message: Internal Server Error
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Fri, 16 Dec 2011 15:22:02 GMT
+ x-runtime:
+ - "0.094418"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlMDdmYzYxZjc0NDA5MDRiNTNjNzk0NWJjMzU5MTM5YTMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--38649c32a563c52d870e6f2cbf32045b4c9c757f; path=/; HttpOnly
+ cache-control:
+ - no-cache
+ transfer-encoding:
+ - chunked
+ body: |
+ <error>
+ <code>ImageDeleteFailure</code>
+ <message>Could not find Image 1234</message>
+ </error>
+
+ http_version: "1.1"
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_provider_image_not_found.yml b/spec/vcr/cassettes/command/delete_command/delete_provider_image_not_found.yml
new file mode 100644
index 0000000..2e88d0c
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_provider_image_not_found.yml
@@ -0,0 +1,39 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/provider_images/1234.xml
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 404
+ message: Not Found
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Fri, 16 Dec 2011 15:22:02 GMT
+ x-runtime:
+ - "0.137996"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZTYzMDIzMmRhZGMwYTljOTdkNWNjNjk3MTQ4ZjY0ODkiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--f6048c6a5d31f23e5206f6e9079e199f16e19a90; path=/; HttpOnly
+ cache-control:
+ - no-cache
+ transfer-encoding:
+ - chunked
+ body: |
+ <error>
+ <code>ProviderImageNotFound</code>
+ <message>Could not find ProviderImage 1234</message>
+ </error>
+
+ http_version: "1.1"
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_target_image_not_found.yml b/spec/vcr/cassettes/command/delete_command/delete_target_image_not_found.yml
new file mode 100644
index 0000000..1ec8227
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_target_image_not_found.yml
@@ -0,0 +1,39 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/target_images/1234.xml
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 500
+ message: Internal Server Error
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Fri, 16 Dec 2011 15:22:02 GMT
+ x-runtime:
+ - "0.031049"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZDIyMDEyODA4Y2UxMTE2MzBhZjM3ZDZlNzgwZTEwMmIiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--3ca32f2ee99e9364ab7304616a57b1d20f3c6502; path=/; HttpOnly
+ cache-control:
+ - no-cache
+ transfer-encoding:
+ - chunked
+ body: |
+ <error>
+ <code>TargetImageDeleteFailure</code>
+ <message>Could not find TargetImage 1234</message>
+ </error>
+
+ http_version: "1.1"
\ No newline at end of file
--
1.7.6.4
More information about the aeolus-devel
mailing list