-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add event state machine for refresh. #243
Conversation
4daa344
to
b58ef1e
Compare
162b676
to
ddda53e
Compare
ddda53e
to
a44a5b3
Compare
target = @handle.object["refresh_target"] | ||
@handle.log(:info, "Refresh target: [#{target}]") | ||
raise "Refresh target not found" if target.nil? | ||
target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do this but since you used tap
above this feels like another example.
@handle.object["refresh_target"].tap do |target|
@handle.log(:info, "Refresh target: [#{target}]")
raise "Refresh target not found" if target.nil?
end
@handle.log(:error, "Refresh task with id : #{task_id} not found") | ||
exit(MIQ_ERROR) | ||
end | ||
task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with tap
.
end | ||
|
||
def refresh_task | ||
task_id = @handle.get_state_var(:task_id).try(:first) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using a more descriptive key name in place of :task_id
, like :refresh_task_id
.
|
||
def check_status(task) | ||
case task.state | ||
when 'Finished' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this string into a constant: STATE_FINISHED = 'Finished'.freeze
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu For master all the methods would have to be builtin methods and can't be inline methods. These changes are appropriate for G and F release but not for master. For master they need to be builtin methods.
@lfu |
a44a5b3
to
0817147
Compare
@mkanoor |
@lfu can you add this BZ to the PR? Thanks! https://bugzilla.redhat.com/show_bug.cgi?id=1534631 It seems to go together with my change for the authentications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future release we might want to use builtin methods.
end | ||
|
||
def fetch_task(task_id) | ||
@handle.object.attributes.sort.each { |k, v| @handle.log(:info, "#{k}: #{v}") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu
Is this just for logging purpose? Do we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor This is for information purpose. It would be useful if anything goes wrong. I would prefer to print it out for our good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get this information from the automation URL in the log already (in a less user-friendly format). This adds more clutter to an already verbose log. I would advise dropping it.
|
||
def check_status(task) | ||
case task.state | ||
when STATE_FINISHED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu What about the error scenario when the task is finished but has an error? will that get flagged as a retry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor A MiqTask's
state may be one of Initialized, Queued, Active and Finished
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor There is a separate status
column for capturing that. app/models/miq_task.rb#L8-L12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu Looks good.
335d1d0
to
a40dc43
Compare
def check_status(task) | ||
case task.state | ||
when STATE_FINISHED | ||
@handle.root['ae_result'] = 'ok' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu If the State == "Finished" but Status != "Ok" we should set the ae_result as error and fail the state machine. Otherwise if there is a password failure during refresh we will continue processing the next state which is going to run the policy action.
fafe199
to
51c2755
Compare
|
||
def fetch_task(task_id) | ||
@handle.vmdb(:miq_task).find(task_id) | ||
rescue MiqAeException::ServiceNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor @tinaafitz @gmcculloug Please review this change.
@handle.vmdb(:miq_task).find(task_id)
would throw an exception instead of returning nil when task is not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @handle.vmdb(:miq_task).find_by(:id => task_id)
51c2755
to
b69ebd1
Compare
47d7bb9
to
97da41d
Compare
End-to-end testing worked well. |
97da41d
to
56ad2bd
Compare
Checked commits lfu/manageiq-content@1535271~...56ad2bd with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 **
|
@tinaafitz Can you look this over again as some things have changed since you approved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu Looks good
Change in ManageIQ/manageiq#16868 caused the Travis failure. |
What is the best way to test this change? Where does the state machine get called so I can see how does it work? |
@mfalesni The state machine is called by reconfigvm_task_complete event. |
Add event state machine for refresh. (cherry picked from commit e0ec800) https://bugzilla.redhat.com/show_bug.cgi?id=1550725
Fine backport details:
|
Add event state machine for refresh. (cherry picked from commit e0ec800) https://bugzilla.redhat.com/show_bug.cgi?id=1550724
Gaprindashvili backport details:
|
This event state machine replaces the builtin method event_action_refresh_sync that waits for the completion of refresh and hence blocks the worker.
Part of ManageIQ/manageiq#16868.
https://bugzilla.redhat.com/show_bug.cgi?id=1534631
@miq-bot add_label bug, fine/yes, gaprindashvili/yes
cc @mkanoor @gmcculloug @tinaafitz