[PATCH aeolus-cli] BZ#767074 Fix print_provider_content method for delete with no provider content
Jason Guiditta
jguiditt at redhat.com
Tue Dec 20 17:29:01 UTC 2011
On 20/12/11 14:48 +0000, mtaylor at redhat.com wrote:
>From: Martyn Taylor <mtaylor at redhat.com>
>
>---
> lib/aeolus_cli/command/delete_command.rb | 42 ++++++++++---------
> spec/command/delete_command_spec.rb | 41 +++++++++++++++++++
> .../delete_build_no_provider_content.yml | 42 ++++++++++++++++++++
> .../delete_image_no_provider_content.yml | 42 ++++++++++++++++++++
> .../delete_target_image_no_provider_content.yml | 42 ++++++++++++++++++++
> 5 files changed, 189 insertions(+), 20 deletions(-)
> create mode 100644 spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
> create mode 100644 spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
> create mode 100644 spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
>
Almost ACK, with one minor fix needed. The error noted in the BZ is gone, but
there is a test failure:
Failures:
1) Aeolus::CLI::DeleteCommand Delete Failed Not Found should display
an appropriate message when the given image is not found
Failure/Error: $stdout.string.should include("Could not find
Image 1234")
expected "" to include "Could not find Image 1234"
# ./spec/command/delete_command_spec.rb:127
# ./spec/command/delete_command_spec.rb:119
Finished in 1.33 seconds
65 examples, 1 failure
Failed examples:
rspec ./spec/command/delete_command_spec.rb:118 #
Aeolus::CLI::DeleteCommand Delete Failed Not Found should display an
appropriate message when the given image is not found
Upon manual testing, I found the same result. If I deleted the image
with -I, it worked fine. If I then tried it a second time (which
should give me feedback of not found), I got nothing back, error or
otherwise.
>diff --git a/lib/aeolus_cli/command/delete_command.rb b/lib/aeolus_cli/command/delete_command.rb
>index 54de83f..7343262 100644
>--- a/lib/aeolus_cli/command/delete_command.rb
>+++ b/lib/aeolus_cli/command/delete_command.rb
>@@ -70,36 +70,38 @@ module Aeolus
> print_provider_content(response.body)
> exit(0)
> end
>+
> rescue => e
>- handle_exception(e)
>+ exit(1)
> end
> end
>
> private
> def print_provider_content(content_xml)
> h = Hash.from_xml(content_xml)
>- provider_content = h[h.keys.first]["content"]["provider_content"]
>- content = provider_content.instance_of?(Array) ? provider_content : [provider_content]
>- if content.size > 0
>- widths = calculate_widths(content)
>- puts "N.B. The following provider content must be manually removed"
>- puts ""
>-
>- # Print Headers
>- printf("%-#{widths[:provider] + 5}s", "Provider")
>- printf("%-#{widths[:id] + 5}s", "ID")
>- puts ""
>+ if provider_content = h[h.keys.first]["content"]["provider_content"]
>+ content = provider_content.instance_of?(Array) ? provider_content : [provider_content]
>+ if content.size > 0
>+ widths = calculate_widths(content)
>+ puts "N.B. The following provider content must be manually removed"
>+ puts ""
>
>- # Print Column Lines
>- printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
>- printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
>- puts ""
>+ # Print Headers
>+ printf("%-#{widths[:provider] + 5}s", "Provider")
>+ printf("%-#{widths[:id] + 5}s", "ID")
>+ puts ""
>
>- # Print Content
>- content.each do |pc|
>- printf("%-#{widths[:provider] + 5}s", pc["provider"])
>- printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
>+ # Print Column Lines
>+ printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
>+ printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
> puts ""
>+
>+ # Print Content
>+ content.each do |pc|
>+ printf("%-#{widths[:provider] + 5}s", pc["provider"])
>+ printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
>+ puts ""
>+ end
> end
> end
> end
>diff --git a/spec/command/delete_command_spec.rb b/spec/command/delete_command_spec.rb
>index 7325161..a15ac39 100644
>--- a/spec/command/delete_command_spec.rb
>+++ b/spec/command/delete_command_spec.rb
>@@ -73,6 +73,47 @@ module Aeolus
> end
> end
>
>+ context "Delete with no Provider Content" do
>+ it "should correctly return when deleting an image with no Provider Images" do
>+ VCR.use_cassette('command/delete_command/delete_image_no_provider_content') do
>+ @options = {:image => "af1b3773-b229-406a-b59c-f5f96ebc2d0b"}
>+ dc = DeleteCommand.new(@options)
>+ begin
>+ dc.image
>+ rescue SystemExit => e
>+ e.status.should == 0
>+ end
>+ $stdout.string.should include("Image: af1b3773-b229-406a-b59c-f5f96ebc2d0b Deleted Successfully")
>+ end
>+ end
>+
>+ it "should correctly return when deleting build with no Provider Images" do
>+ VCR.use_cassette('command/delete_command/delete_build_no_provider_content') do
>+ @options = {:build => "85e1efd5-890a-422f-adfa-d340ddcae187"}
>+ dc = DeleteCommand.new(@options)
>+ begin
>+ dc.build
>+ rescue SystemExit => e
>+ e.status.should == 0
>+ end
>+ $stdout.string.should include("Build: 85e1efd5-890a-422f-adfa-d340ddcae187 Deleted Successfully")
>+ end
>+ end
>+
>+ it "should correctly return when deleting a target image with no Provider Images" do
>+ VCR.use_cassette('command/delete_command/delete_target_image_no_provider_content') do
>+ @options = {:targetimage => "93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b"}
>+ dc = DeleteCommand.new(@options)
>+ begin
>+ dc.target_image
>+ rescue SystemExit => e
>+ e.status.should == 0
>+ end
>+ $stdout.string.should include("Target Image: 93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b Deleted Successfully")
>+ end
>+ end
>+ end
>+
> 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
>diff --git a/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
>new file mode 100644
>index 0000000..854f6ef
>--- /dev/null
>+++ b/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
>@@ -0,0 +1,42 @@
>+---
>+- !ruby/struct:VCR::HTTPInteraction
>+ request: !ruby/struct:VCR::Request
>+ method: :delete
>+ uri: https://admin:password@localhost:443/conductor/api/builds/85e1efd5-890a-422f-adfa-d340ddcae187.xml
>+ body:
>+ headers:
>+ accept-language:
>+ - en
>+ accept:
>+ - 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:
>+ - "\"d27ce6cf60644af5736fff88e6d73dda\""
>+ content-type:
>+ - application/xml; charset=utf-8
>+ server:
>+ - thin 1.2.11 codename Bat-Shit Crazy
>+ date:
>+ - Tue, 20 Dec 2011 14:35:06 GMT
>+ x-runtime:
>+ - "0.258616"
>+ set-cookie:
>+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZDJkYWI3NDcwZGRlNjdiMTM3ODhjYzJhNjMwMmVjMTgiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--cdf1db4ad503e7a2177a113543adc7d62c73cd51; path=/; HttpOnly
>+ cache-control:
>+ - max-age=0, private, must-revalidate
>+ transfer-encoding:
>+ - chunked
>+ body: |
>+ <build href='https://localhost/conductor/api/images/85e1efd5-890a-422f-adfa-d340ddcae187' id='85e1efd5-890a-422f-adfa-d340ddcae187'>
>+ <status>DELETED</status>
>+ <content>
>+ </content>
>+ </build>
>+
>+ http_version: "1.1
>\ No newline at end of file
>diff --git a/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
>new file mode 100644
>index 0000000..c9f7b16
>--- /dev/null
>+++ b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
>@@ -0,0 +1,42 @@
>+---
>+- !ruby/struct:VCR::HTTPInteraction
>+ request: !ruby/struct:VCR::Request
>+ method: :delete
>+ uri: https://admin:password@localhost:443/conductor/api/images/af1b3773-b229-406a-b59c-f5f96ebc2d0b.xml
>+ body:
>+ headers:
>+ accept-language:
>+ - en
>+ accept:
>+ - 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:
>+ - "\"5d1bc3e7c96eba873098df89f4af1ee2\""
>+ content-type:
>+ - application/xml; charset=utf-8
>+ server:
>+ - thin 1.2.11 codename Bat-Shit Crazy
>+ date:
>+ - Tue, 20 Dec 2011 14:30:22 GMT
>+ x-runtime:
>+ - "0.309692"
>+ set-cookie:
>+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZTJjNTVhZDliMTljMzUyOTZiMDFiOWZlYWVlNTU2OTgiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--7db888b26ee555c9d51cad92eec0f20f725fd6f3; path=/; HttpOnly
>+ cache-control:
>+ - max-age=0, private, must-revalidate
>+ transfer-encoding:
>+ - chunked
>+ body: |
>+ <image href='https://localhost/conductor/api/images/af1b3773-b229-406a-b59c-f5f96ebc2d0b' id='af1b3773-b229-406a-b59c-f5f96ebc2d0b'>
>+ <status>DELETED</status>
>+ <content>
>+ </content>
>+ </image>
>+
>+ http_version: "1.1"
>\ No newline at end of file
>diff --git a/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
>new file mode 100644
>index 0000000..717757b
>--- /dev/null
>+++ b/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
>@@ -0,0 +1,42 @@
>+---
>+- !ruby/struct:VCR::HTTPInteraction
>+ request: !ruby/struct:VCR::Request
>+ method: :delete
>+ uri: https://admin:password@localhost:443/conductor/api/target_images/93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b.xml
>+ body:
>+ headers:
>+ accept-language:
>+ - en
>+ accept:
>+ - 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:
>+ - "\"641448cca5a5780b18b324c7308ff65a\""
>+ content-type:
>+ - application/xml; charset=utf-8
>+ server:
>+ - thin 1.2.11 codename Bat-Shit Crazy
>+ date:
>+ - Tue, 20 Dec 2011 14:39:50 GMT
>+ x-runtime:
>+ - "0.204005"
>+ set-cookie:
>+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNTNkZGFmNGNkOGZhNjQxZmI1Nzc5MTM3OTQxN2VjNTYiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--b59985e00d69a7903bc134a51a9f1cd00edc276d; path=/; HttpOnly
>+ cache-control:
>+ - max-age=0, private, must-revalidate
>+ transfer-encoding:
>+ - chunked
>+ body: |
>+ <target_image href='https://localhost/conductor/api/images/93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b' id='93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b'>
>+ <status>DELETED</status>
>+ <content>
>+ </content>
>+ </target_image>
>+
>+ http_version: "1.1"
>\ No newline at end of file
>--
>1.7.6.4
>
More information about the aeolus-devel
mailing list