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

Add support for exporting and importing provision dialogs #17739

Merged
merged 3 commits into from
Aug 1, 2018

Conversation

branic
Copy link
Contributor

@branic branic commented Jul 22, 2018

These rake scripts and classes provide functionality for exporting/importing of the following ManageIQ object types:

  • Provision Dialogs

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

  1. Create a directory for the exports
mkdir /tmp/provision_dialogs
  1. Export provision dialogs
vmdb
bin/rake evm:export:provision_dialogs -- --directory /tmp/provision_dialogs

Importing

  1. Import all provision dialog yaml files in a directory
# vmdb
# bin/rake evm:import:provision_dialogs -- --source /tmp/provision_dialogs
  1. or Import specific provision_dialog yaml file
# vmdb
# bin/rake evm:import:provision_dialogs -- --source /tmp/provision_dialogs/Test_Dialog.yaml

@branic
Copy link
Contributor Author

branic commented Jul 22, 2018

/cc @gtanzillo @gmcculloug

end

dialogs.each do |dialog|
$log.send(:info, "Exporting Provision Dialog: #{dialog[:name]} (#{dialog[:description]})")
Copy link
Member

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}")
Copy link
Member

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]
Copy link
Contributor

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|
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor

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.

@d-m-u
Copy link
Contributor

d-m-u commented Jul 23, 2018

Other than a couple silly nits, looks great! Thanks!


dialog = YAML.load_file(fname)

miq_dialog = MiqDialog.where(:name => dialog[:name]).first
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

@branic branic Jul 28, 2018

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.

Copy link
Member

@eclarizio eclarizio left a 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.

👍

@miq-bot
Copy link
Member

miq-bot commented Jul 25, 2018

This pull request is not mergeable. Please rebase and repush.

@branic branic force-pushed the provision_dialogs_export_import branch from 34a4fdb to 1a97e43 Compare July 28, 2018 02:16
@branic
Copy link
Contributor Author

branic commented Jul 28, 2018

@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.

@ManageIQ ManageIQ deleted a comment from branic Jul 30, 2018

dialogs = options[:all] ? MiqDialog.order(:id).all : MiqDialog.order(:id).where(:default => [false, nil])

dialogs = dialogs.collect do |dialog|
Copy link
Member

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|

@gmcculloug
Copy link
Member

@eclarizio PTAL

Copy link
Member

@eclarizio eclarizio left a 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.

@branic
Copy link
Contributor Author

branic commented Jul 30, 2018

@eclarizio With the 2nd it (starting on line 85) what I'm trying to test is that two different types of provisioning dialogs with the same name are saved to different files.

I can rework the test to try and be clearer in what is being tested. I'm thinking that I can break the it block on line 85 into its own describe block as it really applies regardless of whether the --all option was specified.

Thoughts?

@eclarizio
Copy link
Member

@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 👍

@miq-bot
Copy link
Member

miq-bot commented Jul 30, 2018

Checked commits branic/manageiq@1a97e43~...7357e42 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. 🏆

@branic
Copy link
Contributor Author

branic commented Jul 31, 2018

@eclarizio does this rework of the spec look ok?

@eclarizio
Copy link
Member

@branic Yeah, that looks fine 👍

@gmcculloug gmcculloug merged commit b44e073 into ManageIQ:master Aug 1, 2018
@gmcculloug gmcculloug added this to the Sprint 92 Ending Aug 13, 2018 milestone Aug 1, 2018
@branic branic deleted the provision_dialogs_export_import branch August 1, 2018 17:55
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