-
Notifications
You must be signed in to change notification settings - Fork 897
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 rake task to import custom buttons #17726
Conversation
6444ffe
to
4f59749
Compare
@miq-bot add_label enhancement, wip |
@tinaafitz @syncrou @eclarizio |
ada603c
to
c1abda5
Compare
Okay, fine. WIP cause 1) tests failing 2) yaml linting 3) need flag to overwrite existing thingies being imported. May handle 3 in subsequent PR. |
1ebe6ff
to
1857a9a
Compare
@d-m-u - I found I needed the file extension e.g. |
dba2f15
to
74a43be
Compare
2d7fff4
to
77ecb17
Compare
Dir.glob(glob) do |filename| | ||
begin | ||
import_custom_buttons(filename) | ||
rescue |
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: rescue StandardError
end | ||
|
||
if obj['userid'].present? | ||
check_user(obj) |
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.
Should check_user
be passed new_obj
?
Since code complexity is high on this method maybe we should break the if-blocks out into separate methods.
klass.create!(obj['attributes'].except('guid')).tap do |new_obj|
add_children(obj, new_obj)
add_associations(obj, new_obj)
check_user(new_obj)
end
b1018d1
to
61658f7
Compare
klass.create!(obj['attributes'].except('guid')).tap do |new_obj| | ||
add_children(obj, new_obj) | ||
add_associations(obj, new_obj) | ||
check_user(new_obj) if new_obj.kind_of?(CustomButton) |
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.
This logic should be called from custom_button_post
. Then you do not need this check for the class type.
61658f7
to
fbc0ecc
Compare
@eclarizio PTAL |
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.
Looks good aside from a question I have with the error handling. 👍
begin | ||
import_custom_buttons(filename) | ||
rescue StandardError | ||
warn("Error importing #{options[:source]} due to #{$ERROR_INFO} at #{$ERROR_POSITION}") |
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.
Two things here (I think?), first is that, if we get here, aren't we getting here because of the raise
from here: https://github.com/ManageIQ/manageiq/pull/17726/files#diff-a0ce4acbb7481b72b585132391c2dd4cR28, which means that this will just say something like "error because of raise at line 28?" and not give us actual good info?
Second is that I think there is the potential for YAML.load_file
to fail if the YAML is messed up, in which case I don't remember if StandardError will catch it, cause it's a Psych error or something I think. Maybe?
In either case, maybe some specs ensuring the errors are doing what you want them to do are a good solution to my worries 😄
a215315
to
1f378b8
Compare
This pull request is not mergeable. Please rebase and repush. |
I think these failures are unrelated. |
8692d8c
to
4d4510d
Compare
4d4510d
to
e2d1697
Compare
Checked commits d-m-u/manageiq@f8ca9bf~...e2d1697 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 lib/task_helpers/imports/custom_buttons.rb
|
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 need to be able to import custom buttons via a rake task.
Related export PR:
#17699Importing
Import cbs:
rake evm:import:custom_buttons -- --source /Users/duhlmann/manageiq/custom_buttons
Note: this works either for a single file or for a directory.
The command for a single file looks like this:
rake evm:import:custom_buttons -- --source /Users/duhlmann/manageiq/custom_buttons.yaml