Skip to content
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

[EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error #19061

Merged
merged 5 commits into from
Jul 29, 2019

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Jul 26, 2019

Currently, we don't set the status when doing a repo (ConfigurationScriptSource) sync. With this change, we now:

  • Create a new record with a 'new' status
  • Set the status to 'running' at the beginning of #sync
  • When the sync is completed last_update_on is updated to Time.now
  • On error we update the status to 'error' and last_update_error to provide the ruby error and stacktrace
  • On error we update the status to 'successful' and clear last_update_error

Worth noting: A "create" action is now done in two transactions and .notify (from CrudCommon). One for creating the record in the DB record and one for starting the sync. This is mostly because they really are two atomic actions. If a .create! passes, but the .sync fails, we shouldn't delete the record and just provide a notification in the UI and update the status.

Also, if there was an error, a simple refresh of the provider will re-attempt the sync, or if there is something like a credential error, the user can update and the .sync will be fired again.

TODO:

  • Handle translations (seperate PR?)
    • Talked with Nick C. on this one, and we think this is probably already done on the front end
  • Do updates also in two transactions with notifications?

@NickLaMuro
Copy link
Member Author

@miq-bot add_label changelog/yes, core, embedded ansible, enhancement, ivanchuk/yes

@Fryguy please review, since I think you will have the most to say with this one

Note: This is also addressing this 'bug'/oversight that was brought up by @sbulage here:

https://gitter.im/ManageIQ/manageiq-providers-embedded_ansible?at=5d354941437a3a134832eb4c
https://gitter.im/ManageIQ/manageiq-providers-embedded_ansible?at=5d3710c009580b7bbb91182f

cc @carbonin

@carbonin
Copy link
Member

Do updates also in two transactions with notifications?

I would say yes.

Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would merge but travis is red.

When a `EmbeddedAnsible::AutomationManager::ConfigurationScriptSource`
is created and has been sync'd, have it update the `.status` field to be
"successful", matching the `awx` results.
To simulate ansible/awx, set `.status` for ConfigurationScriptSource to
'new' when a new EmbeddedAnsible repo is first created.

To do this, `CrudCommon.create_in_provider` was overwritten to append
the `sync` action to the `super` call (instead of in
`raw_create_in_provider`.  Since these are two atomic actions, and a
`Rugged::NetworkError` shouldn't cause the whole process to fail,
splitting the code up like this allows a creation to happen, but it to
fail on the sync without the record being lost and deleted in the
process.

As a result, there are a minor amount of extra DB calls in a successful
use case, but it means that a user isn't required to resubmit the form
fields to try again and can just do a provider refresh when there is a
failure to re-attempt a sync.
Provides "error" status when a `ConfigurationScriptSource#sync` fails.
@NickLaMuro NickLaMuro force-pushed the ansible_runner_fix_status_column branch from 2875ce9 to e7ad3a5 Compare July 27, 2019 01:23
@NickLaMuro NickLaMuro changed the title [EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error [WIP][EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error Jul 27, 2019
@miq-bot miq-bot added the wip label Jul 27, 2019
@NickLaMuro NickLaMuro changed the title [WIP][EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error [EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error Jul 27, 2019
@miq-bot miq-bot removed the wip label Jul 27, 2019
@carbonin
Copy link
Member

Looks good to me, but could you fix the Rails/ActiveRecordAliases and Style/SymbolProc cops?

@NickLaMuro
Copy link
Member Author

Sure, though the Rails/ActiveRecordAliases cops have been left in place throughout this process (Jason just did the same on one of his PRs). We should probably going in and change those at some point to be valid with RuboCop, but I don't think now is the time.

Unlike the ansible_tower provider, we haven't been implementing the
`last_update_error` and `last_updated_on` values when syncing.  This
does the following:

- Always updates `#last_updated_on` when completing a `#sync`
- On error:    Formats and sets `#last_update_error`
- On success:  Removes any previous errors from `#last_update_error`

The ERROR_MAX_SIZE value is pulled from the `AnsibleTower` provider.
Splits up the actions for updating the database and refreshing the git
repository into two atomic actions, similar to repo#create_in_provider.

Also, to slightly DRY things up a bit, #sync_and_notify was added as
well and was used in both the create and update methods.
@NickLaMuro NickLaMuro force-pushed the ansible_runner_fix_status_column branch from 1acb803 to 1738d60 Compare July 29, 2019 16:27
@miq-bot
Copy link
Member

miq-bot commented Jul 29, 2019

Checked commits NickLaMuro/manageiq@9c86b54~...1738d60 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 4 offenses detected

app/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source.rb

@carbonin carbonin merged commit 4e0783d into ManageIQ:master Jul 29, 2019
@carbonin carbonin added this to the Sprint 117 Ending Aug 5, 2019 milestone Jul 29, 2019
@carbonin carbonin self-assigned this Jul 29, 2019
simaishi pushed a commit that referenced this pull request Jul 30, 2019
…olumn

[EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error

(cherry picked from commit 4e0783d)
@simaishi
Copy link
Contributor

Ivanchuk backport details:

$ git log -1
commit 93b1c30025de9c6bbd35e0cdf7608b30b121447b
Author: Nick Carboni <ncarboni@redhat.com>
Date:   Mon Jul 29 13:33:13 2019 -0400

    Merge pull request #19061 from NickLaMuro/ansible_runner_fix_status_column
    
    [EmbeddedAnsible] Better handle ConfigurationScriptSource status/last_updated_on/last_update_error
    
    (cherry picked from commit 4e0783d98d95ce384e75b98add8d3046fada7d76)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants