[PATCH conductor] BZ 783378 - log reboot (and other) instance action

Matt Wagner matt.wagner at redhat.com
Wed Feb 8 14:47:23 UTC 2012


On Wed, Feb 08, 2012 at 01:17:01PM +0100, jprovazn at redhat.com wrote:
> From: Jan Provaznik <jprovazn at redhat.com>
> 
> - instance event with message 'action queued' is now created
> on any instance action
> - event time is now displayed in the list of instance events
> ---
>  src/app/controllers/instances_controller.rb |    2 ++
>  src/app/models/instance.rb                  |   14 +++++++++-----
>  src/app/views/instances/_history.html.haml  |    2 +-
>  src/spec/models/instance_spec.rb            |    9 +++++++++
>  4 files changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/src/app/controllers/instances_controller.rb b/src/app/controllers/instances_controller.rb
> index 96bc2fe..08ce4f5 100644
> --- a/src/app/controllers/instances_controller.rb
> +++ b/src/app/controllers/instances_controller.rb
> @@ -188,6 +188,8 @@ class InstancesController < ApplicationController
>          notices << "#{instance.name}: #{t('instances.flash.notice.reboot', :name => instance.name)}"
>        rescue Exception => err
>          errors << "#{instance.name}: " + err
> +        logger.error err.message
> +        logger.error err.backtrace.join("\n ")
>        end
>      end
>      # If nothing is selected, display an error message:
> diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
> index 68ed3bb..5ecfa3f 100644
> --- a/src/app/models/instance.rb
> +++ b/src/app/models/instance.rb
> @@ -217,11 +217,15 @@ class Instance < ActiveRecord::Base
>  
>    def queue_action(user, action, data = nil)
>      return false unless get_action_list.include?(action)
> -    task = InstanceTask.new({ :user        => user,
> -                              :task_target => self,
> -                              :action      => action,
> -                              :args        => data})
> -    task.save!
> +    task = InstanceTask.create!({ :user        => user,
> +                                  :task_target => self,
> +                                  :action      => action,
> +                                  :args        => data})
> +
> +    event = Event.create!(:source => self, :event_time => Time.now,
> +                          :summary => "#{action} action queued",
> +                          :status_code => "#{action}_queued")
> +
>      return task
>    end
>  
> diff --git a/src/app/views/instances/_history.html.haml b/src/app/views/instances/_history.html.haml
> index ee461e6..60f09e5 100644
> --- a/src/app/views/instances/_history.html.haml
> +++ b/src/app/views/instances/_history.html.haml
> @@ -5,6 +5,6 @@
>    %ol
>      - @events.each do |event|
>        %li
> -        = event.summary
> +        = "#{event.event_time.strftime('%d-%b-%Y %H:%M:%S')}: #{event.summary}"
>  
>    = will_paginate @events
> diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
> index d712411..66b1365 100644
> --- a/src/spec/models/instance_spec.rb
> +++ b/src/spec/models/instance_spec.rb
> @@ -92,6 +92,15 @@ describe Instance do
>      valid_task.should_not == false
>    end
>  
> +  it "should create new event when an action is queued" do
> +    @instance.save!
> +    @instance.stub!(:get_action_list).and_return(@actions)
> +    user = User.new
> +    @instance.queue_action(user, 'stop')
> +    @instance.events.should_not be_empty
> +    @instance.events.last.status_code.should == 'stop_queued'
> +  end
> +
>    describe "with time capsule" do
>  
>      it "should properly calculate the total time that the instance has been in a monitored state" do
> -- 
> 1.7.7.5

ACK, looks good and all tests pass.

-- Matt



More information about the aeolus-devel mailing list