[PATCH aeolus-cli] BZ#753917 Updated Push command to list Provider/Account for ProviderImages

Petr Blaho pblaho at redhat.com
Tue Dec 13 16:05:06 UTC 2011


On Thursday, December 08, 2011 06:33:26 PM mtaylor at redhat.com 
wrote:
> From: Martyn Taylor <mtaylor at redhat.com>
> 
> ---
>  lib/aeolus_cli/command/base_command.rb             |   40 
+++++++++++
>  lib/aeolus_cli/command/list_command.rb             |   41 -----------
>  lib/aeolus_cli/command/push_command.rb             |   21 +++---
>  spec/command/push_command_spec.rb                  |   73
> +++++++++++++++----- 
.../push_command/multiple_push_build_id.yml        |  
> 42 +++++++----- .../push_command/multiple_push_image_id.yml        
|   42
> +++++++----- 
.../push_command/multiple_push_target_image_id.yml |   31
> +++++---- 7 files changed, 175 insertions(+), 115 deletions(-)
> 
> diff --git a/lib/aeolus_cli/command/base_command.rb
> b/lib/aeolus_cli/command/base_command.rb index fc25046..d6afc6f 
100644
> --- a/lib/aeolus_cli/command/base_command.rb
> +++ b/lib/aeolus_cli/command/base_command.rb
> @@ -121,6 +121,46 @@ module Aeolus
>          Aeolus::CLI::Base.password = @config[:conductor][:password]
>        end
> 
> +      # Print Collection to STDOUT in a column layout
> +      def print_collection(collection, headers)
> +        widths = column_widths(collection, headers)
> +
> +        # Print Headers
> +        widths.each_pair do |header, width|
> +          printf("%-#{width + 5}s", headers[header])
> +        end
> +        puts ""
> +
> +        # Print Underlines
> +        widths.each_pair do |header, width|
> +          printf("%-#{width + 5}s", "-" * width)
> +        end
> +        puts ""
> +
> +        # Print collection information
> +        collection.each do |resource|
> +          widths.each_pair do |attr, width|
> +            printf("%-#{width + 5}s", resource.attributes.include?
(attr) ?
> resource.attributes[attr].to_s : "") +          end
> +          puts ""
> +        end
> +        puts ""
> +      end
> +
> +      def column_widths(collection, headers)
> +        widths = ActiveSupport::OrderedHash.new
> +        headers.each_pair do |attr, header|
> +          widths[attr] = header.length
> +        end
> +
> +        collection.each do |resource|
> +          headers.keys.each do |attr|
> +            widths[attr] = widths[attr] >
> resource.attributes[attr].to_s.length ? widths[attr] :
> resource.attributes[attr].to_s.length +          end
> +        end
> +        widths
> +      end
> +
>        def load_config
>          begin
>            file_str = read_file(@config_location)
> diff --git a/lib/aeolus_cli/command/list_command.rb
> b/lib/aeolus_cli/command/list_command.rb index f967174..4714985 
100644
> --- a/lib/aeolus_cli/command/list_command.rb
> +++ b/lib/aeolus_cli/command/list_command.rb
> @@ -127,47 +127,6 @@ module Aeolus
>            handle_exception(e)
>          end
>        end
> -
> -      private
> -      # Print Collection to STDOUT in a column layout
> -      def print_collection(collection, headers)
> -        widths = column_widths(collection, headers)
> -
> -        # Print Headers
> -        widths.each_pair do |header, width|
> -          printf("%-#{width + 5}s", headers[header])
> -        end
> -        puts ""
> -
> -        # Print Underlines
> -        widths.each_pair do |header, width|
> -          printf("%-#{width + 5}s", "-" * width)
> -        end
> -        puts ""
> -
> -        # Print collection information
> -        collection.each do |resource|
> -          widths.each_pair do |attr, width|
> -            printf("%-#{width + 5}s", resource.attributes.include?(attr) 
?
> resource.attributes[attr].to_s : "") -          end
> -          puts ""
> -        end
> -        puts ""
> -      end
> -
> -      def column_widths(collection, headers)
> -        widths = ActiveSupport::OrderedHash.new
> -        headers.each_pair do |attr, header|
> -          widths[attr] = header.length
> -        end
> -
> -        collection.each do |resource|
> -          headers.keys.each do |attr|
> -            widths[attr] = widths[attr] >
> resource.attributes[attr].to_s.length ? widths[attr] :
> resource.attributes[attr].to_s.length -          end
> -        end
> -        widths
> -      end
>      end
>    end
>  end
> diff --git a/lib/aeolus_cli/command/push_command.rb
> b/lib/aeolus_cli/command/push_command.rb index 
cde7336..fc55d27 100644
> --- a/lib/aeolus_cli/command/push_command.rb
> +++ b/lib/aeolus_cli/command/push_command.rb
> @@ -27,20 +27,23 @@ module Aeolus
>            pi = Aeolus::CLI::ProviderImage.new(request_parameters)
>            pi.save!
> 
> +          headers = ActiveSupport::OrderedHash.new
> +          headers[:id] = "ID"
> +          headers[:provider] = "Provider"
> +          headers[:account] = "Account"
> +          headers[:status] = "Status"
> +          pi_array = Array(pi.provider_image)
> +
>            {:image_id => "Image", :build_id => "Build", 
:target_image_id =>
> "Target Image"}.each_pair do |method, label| if pi.respond_to?
(method)
> -              puts label + ": " + pi.send(method)
> -            end
> -          end
> -
> -          if pi.respond_to?(:provider_image)
> -            Array(pi.provider_image).each do |p|
> -              puts "Provider Image: " + p.id + "\t Status: " + p.status
> +              headers[method] = label
> +              pi_array.each do |provider_image|
> +                provider_image.attributes[method] = pi.send(method)
> +              end
>              end
> -          else
> -            puts "Provider Image: " + pi.id
>            end
> 
> +          print_collection(pi_array, headers)
>            quit(0)
>          rescue => e
>            handle_exception(e)
> diff --git a/spec/command/push_command_spec.rb
> b/spec/command/push_command_spec.rb index 57a11ec..aeded43 
100644
> --- a/spec/command/push_command_spec.rb
> +++ b/spec/command/push_command_spec.rb
> @@ -27,43 +27,67 @@ module Aeolus
>        describe "#run" do
>          it "should allow multple push for an image with 2 target 
images
> based on image id" do
> 
VCR.use_cassette('command/push_command/multiple_push_image_id') 
do -       
>     @options = ({ :image => "04b509a2-274b-468d-84b0-
e4190e4457cb", -      
>                    :account => "ec2-acc,mock-acc" })
> +            @options = ({ :image => 
"b4b340dc-0efc-4830-8c59-411c9a3e0aba",
> +                          :account => "mock-acc,mock-acc" })
>              p = PushCommand.new(@options, @output)
>              begin
>                p.run
>              rescue SystemExit => e
>                e.status.should == 0
>              end
> -            $stdout.string.should include("Image:
> 04b509a2-274b-468d-84b0-e4190e4457cb") -            
$stdout.string.should
> include("Provider Image: 139f9822-8228-4d25-
a038-21a5d9e6888d") -          
>  $stdout.string.should include("Provider Image:
> b7460080-2156-4d38-9945-f4edd052d87b") -            
$stdout.string.should
> include("Status: New")
> -            $stdout.string.should include("Status: COMPLETE")
> +
> +            # Headers
> +            $stdout.string.should include("ID")
> +            $stdout.string.should include("Provider")
> +            $stdout.string.should include("Account")
> +            $stdout.string.should include("Image")
> +
> +            # Provider Images
> +            $stdout.string.should
> include("daf6f1b3-d4b9-4ab1-81d3-11adf84d3a6a") +           
> $stdout.string.should include("07bf7f85-
cf4f-4d26-862e-8795f0431f07") +
> +            # Image
> +            $stdout.string.should
> include("b4b340dc-0efc-4830-8c59-411c9a3e0aba") +
> +            $stdout.string.should include("mock")
> +            $stdout.string.should include("mock-acc")
> +            $stdout.string.should include("COMPLETED")
>            end
>          end
> 
>          it "should allow multple push for an image with 2 target 
images
> based on build id" do
> 
VCR.use_cassette('command/push_command/multiple_push_build_id') 
do -       
>     @options = ({ :build => "5d81e1a4-911a-4934-bb50-
b46881343f6d", -      
>                    :account => "ec2-acc,mock-acc" })
> +            @options = ({ :build => 
"661ee541-6db3-4d36-9b3c-8972d6e63c94",
> +                          :account => "mock-acc,mock-acc" })
>              p = PushCommand.new(@options, @output)
>              begin
>                p.run
>              rescue SystemExit => e
>                e.status.should == 0
>              end
> -            $stdout.string.should include("Build:
> 5d81e1a4-911a-4934-bb50-b46881343f6d") -            
$stdout.string.should
> include("Provider Image: bd04dc3d-0e88-4175-987f-f448c009ea90") 
-          
>  $stdout.string.should include("Provider Image:
> 3597b77b-0a0e-4d0c-8916-a071a6e8ec30") -            
$stdout.string.should
> include("Status: New")
> -            $stdout.string.should include("Status: COMPLETE")
> +
> +            # Headers
> +            $stdout.string.should include("ID")
> +            $stdout.string.should include("Provider")
> +            $stdout.string.should include("Account")
> +            $stdout.string.should include("Build")
> +
> +            # Provider Images
> +            $stdout.string.should
> include("4f060b14-d627-4d20-a653-12307b6c0ea2") +           
> $stdout.string.should include("421bf284-2f51-4156-
b068-79d86d8b3d27") +
> +            # Build
> +            $stdout.string.should
> include("661ee541-6db3-4d36-9b3c-8972d6e63c94") +
> +            $stdout.string.should include("mock")
> +            $stdout.string.should include("mock-acc")
> +            $stdout.string.should include("COMPLETED")
>            end
>          end
> 
>          it "should allow single push for an image on target image id" 
do
>           
> 
VCR.use_cassette('command/push_command/multiple_push_target_image_id') 
do -
>            @options = ({ :targetimage =>
> "e650a5cc-61e1-466e-83e1-8f8cfe5ac9b8", +            @options = ({
> :targetimage => "e6176811-49e0-4dba-8b76-06b552a4b3a4",
>                            :account =>
>                            :"mock-acc" })
> 
>              p = PushCommand.new(@options, @output)
>              begin
> @@ -71,9 +95,22 @@ module Aeolus
>              rescue SystemExit => e
>                e.status.should == 0
>              end
> -            $stdout.string.should include("Target Image:
> e650a5cc-61e1-466e-83e1-8f8cfe5ac9b8") -            
$stdout.string.should
> include("Provider Image: 2adccda4-
d7eb-48eb-888e-54bd863f4130") -          
>  $stdout.string.should include("Status: COMPLETE")
> +
> +            # Headers
> +            $stdout.string.should include("ID")
> +            $stdout.string.should include("Provider")
> +            $stdout.string.should include("Account")
> +            $stdout.string.should include("Target Image")
> +
> +            # Provider Image
> +            $stdout.string.should
> include("e4b94bf2-7bfc-4633-b6a1-2f888587417e") +
> +            # Build
> +            $stdout.string.should
> include("e6176811-49e0-4dba-8b76-06b552a4b3a4") +
> +            $stdout.string.should include("mock")
> +            $stdout.string.should include("mock-acc")
> +            $stdout.string.should include("PENDING")
>            end
>          end
>        end
> diff --git
> 
a/spec/vcr/cassettes/command/push_command/multiple_push_build_id.yml
> 
b/spec/vcr/cassettes/command/push_command/multiple_push_build_id.yml 
index
> 3fa3002..edb0741 100644
> --- 
a/spec/vcr/cassettes/command/push_command/multiple_push_build_id.yml
> +++ 
b/spec/vcr/cassettes/command/push_command/multiple_push_build_id.yml
> @@ -2,15 +2,17 @@
>  - !ruby/struct:VCR::HTTPInteraction
>    request: !ruby/struct:VCR::Request
>      method: :post
> -    uri: 
https://admin:password@localhost/conductor/api/provider_images.xml
> +    uri:
> 
https://admin:password@localhost:443/conductor/api/provider_images.xml
> body: |
>        <?xml version="1.0" encoding="UTF-8"?>
>        <provider_image>
> -        <build_id>5d81e1a4-911a-4934-bb50-
b46881343f6d</build_id>
> -        <provider_account>ec2-acc,mock-acc</provider_account>
> +        
<build_id>661ee541-6db3-4d36-9b3c-8972d6e63c94</build_id>
> +        <provider_account>mock-acc,mock-
acc</provider_account>
>        </provider_image>
> 
>      headers:
> +      accept-language:
> +      - en
>        content-type:
>        - application/xml
>    response: !ruby/struct:VCR::Response
> @@ -19,31 +21,37 @@
>        message: OK
>      headers:
>        x-ua-compatible:
> -      - IE=Edge
> +      - IE=Edge,chrome=1
>        etag:
> -      - "\"12874d57a167cb0633095f4cf8468004\""
> +      - "\"5b1fe79150b5348b74161e4904fad719\""
>        content-type:
>        - application/xml; charset=utf-8
>        server:
> -      - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
> +      - thin 1.2.11 codename Bat-Shit Crazy
>        date:
> -      - Tue, 08 Nov 2011 19:57:44 GMT
> +      - Thu, 08 Dec 2011 16:19:11 GMT
>        x-runtime:
> -      - "2.909574"
> -      content-length:
> -      - "427"
> +      - "0.648162"
>        set-cookie:
> -      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlOWFhOTkwZWJhMGE0MWVhYmZmNDEyYzQ1ZjQ0OTI
> 
1ZWIiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--3086dfe54356c68
> 8ed742cbe97ad71028ea0d5e6; path=/; HttpOnly +      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNjY4NWYyMjk0MzZlMjY5YzY0NTYyYzc4NTA0NmN
> 
lNmYiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--
a325a9bf1cd0af3
> d716c70a13ed635751f6d2f84; path=/; HttpOnly cache-control:
>        - max-age=0, private, must-revalidate
> +      transfer-encoding:
> +      - chunked
>      body: |
>        <provider_images>
> -        <provider_image
> 
href='http://localhost:3000/api/provider_images/3597b77b-0a0e-4d0c-8916-
a07
> 1a6e8ec30' id='3597b77b-0a0e-4d0c-8916-a071a6e8ec30'> -         
> <status>New</status>
> -        </provider_image>
> -        <provider_image
> 
href='http://localhost:3000/api/provider_images/bd04dc3d-0e88-4175-987f-
f44
> 8c009ea90' id='bd04dc3d-0e88-4175-987f-f448c009ea90'> -         
> <status>COMPLETED</status>
> -        </provider_image>
> +      <provider_image
> href='https://localhost/conductor/api/provider_images/4f060b14-
d627-4d20-a6
> 53-12307b6c0ea2' id='4f060b14-d627-4d20-a653-12307b6c0ea2'> 
+     
> <status>COMPLETED</status>
> +      <provider>mock</provider>
> +      <account>mock-acc</account>
> +      </provider_image>
> +
> +      <provider_image
> 
href='https://localhost/conductor/api/provider_images/421bf284-2f51-4156-
b0
> 68-79d86d8b3d27' id='421bf284-2f51-4156-b068-79d86d8b3d27'> 
+     
> <status>COMPLETED</status>
> +      <provider>mock</provider>
> +      <account>mock-acc</account>
> +      </provider_image>
> +
>        </provider_images>
> 
>      http_version: "1.1"
> \ No newline at end of file
> diff --git
> 
a/spec/vcr/cassettes/command/push_command/multiple_push_image_id.yml
> 
b/spec/vcr/cassettes/command/push_command/multiple_push_image_id.yml 
index
> 39fb516..0cb3459 100644
> --- 
a/spec/vcr/cassettes/command/push_command/multiple_push_image_id.yml
> +++ 
b/spec/vcr/cassettes/command/push_command/multiple_push_image_id.yml
> @@ -2,15 +2,17 @@
>  - !ruby/struct:VCR::HTTPInteraction
>    request: !ruby/struct:VCR::Request
>      method: :post
> -    uri: 
https://admin:password@localhost/conductor/api/provider_images.xml
> +    uri:
> 
https://admin:password@localhost:443/conductor/api/provider_images.xml
> body: |
>        <?xml version="1.0" encoding="UTF-8"?>
>        <provider_image>
> -        <image_id>04b509a2-274b-468d-84b0-
e4190e4457cb</image_id>
> -        <provider_account>ec2-acc,mock-acc</provider_account>
> +        
<image_id>b4b340dc-0efc-4830-8c59-411c9a3e0aba</image_id>
> +        <provider_account>mock-acc,mock-
acc</provider_account>
>        </provider_image>
> 
>      headers:
> +      accept-language:
> +      - en
>        content-type:
>        - application/xml
>    response: !ruby/struct:VCR::Response
> @@ -19,31 +21,37 @@
>        message: OK
>      headers:
>        x-ua-compatible:
> -      - IE=Edge
> +      - IE=Edge,chrome=1
>        etag:
> -      - "\"59b47843dc5a59e65e39d27c68733e84\""
> +      - "\"6ea2cfc15cdaf5a4601a685bc487bf80\""
>        content-type:
>        - application/xml; charset=utf-8
>        server:
> -      - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
> +      - thin 1.2.11 codename Bat-Shit Crazy
>        date:
> -      - Tue, 08 Nov 2011 19:53:02 GMT
> +      - Thu, 08 Dec 2011 16:19:11 GMT
>        x-runtime:
> -      - "2.448873"
> -      content-length:
> -      - "427"
> +      - "0.697198"
>        set-cookie:
> -      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNDk5ZmIxN2IzM2Q0Yjg3NTVjZTMyYTdlYmYwNjQ
> 
yOGUiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--
c46a499e217f9fd
> e92a41ce5ed57822d1afca919; path=/; HttpOnly +      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNWQyMmVmN2E5ODJkYjdmN2I5YzdhNGIzOWUxMzU
> 
1MzkiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--752b4f91e56f168
> 116ebca99984eaeeaf097f8d4; path=/; HttpOnly cache-control:
>        - max-age=0, private, must-revalidate
> +      transfer-encoding:
> +      - chunked
>      body: |
>        <provider_images>
> -        <provider_image
> 
href='http://localhost:3000/api/provider_images/b7460080-2156-4d38-9945-
f4e
> dd052d87b' id='b7460080-2156-4d38-9945-f4edd052d87b'> -         
> <status>New</status>
> -        </provider_image>
> -        <provider_image
> 
href='http://localhost:3000/api/provider_images/139f9822-8228-4d25-
a038-21a
> 5d9e6888d' id='139f9822-8228-4d25-a038-21a5d9e6888d'> -         
> <status>COMPLETED</status>
> -        </provider_image>
> +      <provider_image
> href='https://localhost/conductor/api/provider_images/daf6f1b3-
d4b9-4ab1-81
> d3-11adf84d3a6a' id='daf6f1b3-d4b9-4ab1-81d3-11adf84d3a6a'> 
+     
> <status>COMPLETED</status>
> +      <provider>mock</provider>
> +      <account>mock-acc</account>
> +      </provider_image>
> +
> +      <provider_image
> href='https://localhost/conductor/api/provider_images/07bf7f85-
cf4f-4d26-86
> 2e-8795f0431f07' id='07bf7f85-cf4f-4d26-862e-8795f0431f07'> +     
> <status>COMPLETED</status>
> +      <provider>mock</provider>
> +      <account>mock-acc</account>
> +      </provider_image>
> +
>        </provider_images>
> 
>      http_version: "1.1"
> \ No newline at end of file
> diff --git
> 
a/spec/vcr/cassettes/command/push_command/multiple_push_target_image_id.yml
> 
b/spec/vcr/cassettes/command/push_command/multiple_push_target_image_id.yml
> index f4eabcc..17d5480 100644
> ---
> 
a/spec/vcr/cassettes/command/push_command/multiple_push_target_image_id.yml
> +++
> 
b/spec/vcr/cassettes/command/push_command/multiple_push_target_image_id.yml
> @@ -2,15 +2,17 @@
>  - !ruby/struct:VCR::HTTPInteraction
>    request: !ruby/struct:VCR::Request
>      method: :post
> -    uri: 
https://admin:password@localhost/conductor/api/provider_images.xml
> +    uri:
> 
https://admin:password@localhost:443/conductor/api/provider_images.xml
> body: |
>        <?xml version="1.0" encoding="UTF-8"?>
>        <provider_image>
> -       
> 
<target_image_id>e650a5cc-61e1-466e-83e1-8f8cfe5ac9b8</target_image_id> 
+  
>     
> 
<target_image_id>e6176811-49e0-4dba-8b76-06b552a4b3a4</target_image_id>
> <provider_account>mock-acc</provider_account>
>        </provider_image>
> 
>      headers:
> +      accept-language:
> +      - en
>        content-type:
>        - application/xml
>    response: !ruby/struct:VCR::Response
> @@ -19,28 +21,31 @@
>        message: OK
>      headers:
>        x-ua-compatible:
> -      - IE=Edge
> +      - IE=Edge,chrome=1
>        etag:
> -      - "\"92211c020ac7e82e1ae9156ba86c2d2b\""
> +      - "\"b7988fd1495b2873da10bdd6f97cf75d\""
>        content-type:
>        - application/xml; charset=utf-8
>        server:
> -      - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
> +      - thin 1.2.11 codename Bat-Shit Crazy
>        date:
> -      - Tue, 08 Nov 2011 20:04:11 GMT
> +      - Thu, 08 Dec 2011 16:19:12 GMT
>        x-runtime:
> -      - "1.008474"
> -      content-length:
> -      - "235"
> +      - "0.363515"
>        set-cookie:
> -      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlOTRjYzc2OWI5YzcwYTczNGNkYTJlYTcwYjU4YTY
> 
0NDUiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--967fa92cdd35ac5
> 663904cd6e0e1ea490be0aa4c; path=/; HttpOnly +      -
> 
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZWUwZDNiMDY3ODk2Yjc2YTg4ZjU4M2VjZTJlZDZ
> 
iYWIiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--0de984cc1042441
> 8ac80ee48119ae426f7c4b451; path=/; HttpOnly cache-control:
>        - max-age=0, private, must-revalidate
> +      transfer-encoding:
> +      - chunked
>      body: |
>        <provider_images>
> -        <provider_image
> href='http://localhost:3000/api/provider_images/2adccda4-
d7eb-48eb-888e-54b
> d863f4130' id='2adccda4-d7eb-48eb-888e-54bd863f4130'> -         
> <status>COMPLETED</status>
> -        </provider_image>
> +      <provider_image
> 
href='https://localhost/conductor/api/provider_images/e4b94bf2-7bfc-4633-
b6
> a1-2f888587417e' id='e4b94bf2-7bfc-4633-b6a1-2f888587417e'> 
+     
> <status>PENDING</status>
> +      <provider>mock</provider>
> +      <account>mock-acc</account>
> +      </provider_image>
> +
>        </provider_images>
> 
>      http_version: "1.1"
> \ No newline at end of file

Works for me, ACK.

-- 

With regards
Petr Blaho



More information about the aeolus-devel mailing list