-
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 support for exporting and importing provision dialogs #17739
Add support for exporting and importing provision dialogs #17739
Conversation
end | ||
|
||
dialogs.each do |dialog| | ||
$log.send(:info, "Exporting Provision Dialog: #{dialog[:name]} (#{dialog[:description]})") |
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.
No need to call send
. Use $log.info
|
||
glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/*.yaml" | ||
Dir.glob(glob) do |fname| | ||
$log.send(:info, "Importing Provision Dialog from: #{fname}") |
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
def export(options = {}) | ||
export_dir = options[:directory] | ||
|
||
dialogs = if options[:all] |
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 could be a ternary.
MiqDialog.order(:id).where(:default => [false, nil]) | ||
end | ||
|
||
dialogs = dialogs.collect do |dialog| |
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.
Could use collect! and not need the variable.
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.
collect!
isn't defined for an ActiveRecord::Relation []
so the only option is using collect
NoMethodError:
undefined method `collect!' for #<ActiveRecord::Relation []>
Did you mean? collect
|
||
miq_dialog = MiqDialog.where(:name => dialog[:name]).first | ||
|
||
if miq_dialog.nil? then |
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 could be a ternary too.
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.
And the then
shouldn't be necessary.
Other than a couple silly nits, looks great! Thanks! |
|
||
dialog = YAML.load_file(fname) | ||
|
||
miq_dialog = MiqDialog.where(:name => dialog[:name]).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.
Prefer find_by(:name => dialog[:name])
instead of where().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.
These are uniq'd by dialog type, does this need to account for that as well?
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.
Both the export and import need to account for them being uniq'd by dialog type. On the export side, with the way the filename is currently generated, when there are two dialogs of different types that have the same name one will overwrite the other.
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.
I don't currently have anything else to add to what @d-m-u and @gmcculloug have said.
@branic Let me know when you've made the requested changes and I'll take another look.
👍
This pull request is not mergeable. Please rebase and repush. |
@eclarizio, @d-m-u, @gmcculloug I've addressed the comments with the latest commit. I had to rebase so in the process I squashed the commits into a single commit. |
|
||
dialogs = options[:all] ? MiqDialog.order(:id).all : MiqDialog.order(:id).where(:default => [false, nil]) | ||
|
||
dialogs = dialogs.collect do |dialog| |
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.
Minor de-duping. You can move the order(:all)
down to the caller.
dialogs = options[:all] ? MiqDialog.all : MiqDialog.where(:default => [false, nil])
dialogs = dialogs.order(:id).collect do |dialog|
@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.
I originally had some of the same nitpicks I saw you fixed, but now it looks good overall. 👍
The only reservation I have at first is from the exports/provision_dialogs_spec.rb
, there's the tests for what happens when --all
isn't specified and when it is, but it doesn't at first appear that anything is different. It's particularly confusing that you are expecting the file count to be 1 for one of the tests when --all
isn't specified, and then 2 for the second test, and then when --all
is specified, you're expecting the count to be 2 again.
I understand that the specs are different because they're checking different descriptions, but it's just not immediately apparent.
I'm not sure the best way to remedy this, perhaps breaking up the specs into separate it
blocks? Something like:
# bunch of setup here for all commonalities
it "exports all provision dialogs to a given directory" do
expect(<filecount>).to eq(2)
end
it "matches the first dialog content and description to the first dialog" do
dialog1 = YAML.load_file(dialog_filename1)
expect(dialog1[:content]).to eq(content)
expect(dialog1[:description]).to eq(dialog_desc1)
end
it "matches the second dialog content and description to the second dialog" do
dialog2 = YAML.load_file(dialog_filename2)
expect(dialog2[:content]).to eq(content)
expect(dialog2[:description]).to eq(dialog_desc2)
end
# etc.
It's a pretty minor nitpick, so I'm going to approve, but something to think about going forward.
@eclarizio With the 2nd I can rework the test to try and be clearer in what is being tested. I'm thinking that I can break the Thoughts? |
@branic Right, I got that after reading it more closely, I was mainly confused at first glance. What you suggested is probably a good way to go about it 👍 |
Checked commits https://github.com/branic/manageiq/compare/1a97e432cb3f7a1eae53ff0f2be427b27c39d407~...7357e42e2e838f293f17d3887d549e0d6b1987d9 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@eclarizio does this rework of the spec look ok? |
@branic Yeah, that looks fine 👍 |
These rake scripts and classes provide functionality for exporting/importing of the following ManageIQ object types:
This PR uses the framework that was implemented for PRs #14126, #15256, #16717, and #16983 to export/import other ManageIQ object types.
These scripts are based on the CFME RH Consulting Scripts and are used by Red Hat consultants to enable storing customizations in Git and maintaining customizations between environments (e.g. dev/qa/prod) for an SDLC lifecycle.
Links [Optional]
Steps for Testing/QA [Optional]
Exporting
Importing