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 rake script to export/import policies and policy profiles #15256

Merged
merged 5 commits into from
Dec 19, 2017

Conversation

branic
Copy link
Contributor

@branic branic commented May 31, 2017

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

  • policies (MiqPolicy)
  • policy profiles (MiqPolicySet)

This PR uses the framework that was implemented for PR #14126 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.

@branic
Copy link
Contributor Author

branic commented Jun 8, 2017

@gmcculloug,

This is similar to PR #14126 that @carbonin merged a couple weeks ago.

Brant

@branic
Copy link
Contributor Author

branic commented Jun 23, 2017

@gmcculloug any feedback on this?

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.

The code looks fine, I just have a few changes to the specs to be a bit more like the style we're attempting to adhere to.

Mainly minor changes, although the structure changes for the import specs are a bit more involved.

}
end

before(:each) do
Copy link
Member

Choose a reason for hiding this comment

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

before do is actually the same as before(:each) do, so we can drop the (:each).

@export_dir = Dir.mktmpdir('miq_exp_dir')
end

after(:each) do
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here with the (:each)

before(:each) do
FactoryGirl.create(:miq_policy, policy_create_attrs)
FactoryGirl.create(:miq_policy_read_only, policy2_create_attrs)
@export_dir = Dir.mktmpdir('miq_exp_dir')
Copy link
Member

Choose a reason for hiding this comment

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

Extract this to a let instead of an instance variable.

FileUtils.remove_entry(@export_dir)
end

it 'should export user policies to a given directory' do
Copy link
Member

Choose a reason for hiding this comment

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

Minor change, but I believe we've stopped prefixing the descriptions with "should", so this would be better written as something like:
it 'exports user policies to a given directory'

expect(Dir[File.join(@export_dir, '**', '*')].count { |file| File.file?(file) }).to eq(1)
end

it 'should export all policies to a given directory' do
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 with removing the 'should'

}
end

before(:each) do
Copy link
Member

Choose a reason for hiding this comment

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

Same as the previous file, the (:each) is redundant.

@export_dir = Dir.mktmpdir('miq_exp_dir')
end

after(:each) do
Copy link
Member

Choose a reason for hiding this comment

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

Another (:each)

FileUtils.remove_entry @export_dir
end

it 'should export user policy sets to a given directory' do
Copy link
Member

Choose a reason for hiding this comment

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

Again with the description dropping the 'should' and adjusting the wording accordingly

expect(YAML.safe_load(file_contents)).to eq(policy_set_export_attrs)
end

it 'should export all policy sets to a given directory' do
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

expect do
TaskHelpers::Imports::PolicySets.new.import(options)
end.to output.to_stderr
end
Copy link
Member

Choose a reason for hiding this comment

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

I would say to give this file the same treatment as the other import file.

expect do
TaskHelpers::Imports::Policies.new.import(options)
end.to output.to_stderr
end
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, when I was doing the review I had a comment here but it disappeared... I'll try again.

Copy link
Member

Choose a reason for hiding this comment

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

When there are different options/parameters called to the method under test, we'd like to try to structure the tests somewhat as follows:

describe "#import" do
  let(:options) { {:source => source} }

  describe "when the source is a directory" do
    let(:source) { data_dir }

    it "imports all .yaml files within the specified directory" do
    end
  end

  describe "when the source is a valid policy file" do
    let(:source) { "#{data_dir}/#{policy_file}" }

    it "imports all .yaml files within the specified directory" do
    end
  end

  describe "when the source is an invalid policy file" do
    let(:source) { "#{data_dir}/#{bad_policy_file}" }

    it "outputs a message to stderr" do
    end
  end
end

@eclarizio
Copy link
Member

@branic Hey Brant, just wanted to make sure that you were good with the changes I suggested, please let me know if you need any help or have any questions. Thanks.

@branic
Copy link
Contributor Author

branic commented Aug 9, 2017

@eclarizio I think I'm good with the changes suggested. I haven't had time to look at them in detail yet. I'm hoping to be able to do that and make the updates in the next week or so.

@branic
Copy link
Contributor Author

branic commented Nov 27, 2017

@eclarizio I finally was able to make the changes to the spec files.

@branic
Copy link
Contributor Author

branic commented Dec 18, 2017

@eclarizio Are there any other changes you would like me to make on this PR?

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.

@branic Nope, looks good now 👍

# expect do
# TaskHelpers::Imports::PolicySets.new.import(options)
# end.to output.to_stderr
# end
Copy link
Member

Choose a reason for hiding this comment

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

@branic Any reason to keep these commented out tests? They should probably be removed then this PR should be all set.

@branic
Copy link
Contributor Author

branic commented Dec 19, 2017

@gmcculloug No reason to keep them. I just forgot to delete them before committing. They have now been removed.

@miq-bot
Copy link
Member

miq-bot commented Dec 19, 2017

Some comments on commits https://github.com/branic/manageiq/compare/fe6e0b90cd67acebec7d4fb7297c6ad6dcd3dd61~...59bbd0fd60616584c4c2499cc42651fd0c00e0cb

lib/task_helpers/imports/policies.rb

  • ⚠️ - 13 - Detected puts. Remove all debugging statements.

lib/task_helpers/imports/policy_sets.rb

  • ⚠️ - 13 - Detected puts. Remove all debugging statements.

@miq-bot
Copy link
Member

miq-bot commented Dec 19, 2017

Checked commits https://github.com/branic/manageiq/compare/fe6e0b90cd67acebec7d4fb7297c6ad6dcd3dd61~...59bbd0fd60616584c4c2499cc42651fd0c00e0cb with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
17 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Yaml - missing config files

@gmcculloug gmcculloug merged commit 2fa99b2 into ManageIQ:master Dec 19, 2017
@gmcculloug gmcculloug added this to the Sprint 76 Ending Jan 1, 2018 milestone Dec 19, 2017
@branic branic deleted the policy_export_import branch December 22, 2017 00:02
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