[PATCH aeolus-cli 2/2] BZ#749376: Handle conductor being down/configuration errors

Martyn Taylor mtaylor at redhat.com
Mon Dec 19 16:29:29 UTC 2011


Hey Maros,

Can you use Active Resource to check for an Execption and handle that 
exception in the "handle_exception" method in the BaseCommand class.  I 
really don't like the idea of adding in  new dependency just for this case.

Also, can you please make sure to submit tests together with code so we 
make sure it makes it in, also the review probably need the tests to 
figure out if its working properly.

Regards

Martyn

On 12/16/2011 06:06 PM, mzatko at redhat.com wrote:
> From: Maros Zatko<mzatko at redhat.com>
>
> ---
>   lib/aeolus_cli/command/config_parser.rb |   41 +++++++++++++++++++++++++++++++
>   1 files changed, 41 insertions(+), 0 deletions(-)
>
> diff --git a/lib/aeolus_cli/command/config_parser.rb b/lib/aeolus_cli/command/config_parser.rb
> index 2be3e61..1968238 100644
> --- a/lib/aeolus_cli/command/config_parser.rb
> +++ b/lib/aeolus_cli/command/config_parser.rb
> @@ -14,6 +14,7 @@
>
>   require 'optparse'
>   require 'logger'
> +require 'rest_client'
>
>   module Aeolus
>     module CLI
> @@ -35,6 +36,13 @@ module Aeolus
>           # File.expand_path("~")
>           if COMMANDS.include?(@command)
>             parse(@command)
> +
> +          if not ping_conductor
> +            puts "ERROR: Can't connect to Conductor instance. \
> +Either Conductor is not running or there is incorrect URL/credentials in configuration file (~/.aeolus-cli)."
> +            exit(1)
> +          end
> +
>             self.send(@command.to_sym)
>           else
>             @args<<  "-h"
> @@ -231,6 +239,39 @@ module Aeolus
>           end
>         end
>
> +      def ping_conductor
> +        bc = BaseCommand.new
> +        config = bc.instance_variable_get(:@config)
> +
> +        url = config[:conductor][:url]
> +        usr = config[:conductor][:username]
> +        pwd = config[:conductor][:password]
> +
> +        begin
> +          resp = RestClient::Request.new(
> +            :method =>  :get,
> +            :url =>  url,
> +            :user =>  usr,
> +            :password =>  pwd
> +          ).execute
> +
> +        rescue SocketError,
> +               RestClient::ResourceNotFound,
> +               OpenSSL::SSL::SSLError,
> +               RestClient::Request::Unauthorized,
> +               RestClient::ServiceUnavailable,
> +               Errno::ECONNREFUSED =>  e
> +          puts "ERROR: " + e.message
> +          return false
> +
> +        rescue =>  e
> +          puts "ERROR: " + e.message
> +          raise e
> +        end
> +
> +        return true
> +      end
> +
>         # TODO: Remove all this boilerplate and replace with some metaprogramming,
>         # perhaps method_missing
>         def list




More information about the aeolus-devel mailing list