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 options to ems #23

Merged
merged 1 commit into from
Jul 25, 2017
Merged

Add options to ems #23

merged 1 commit into from
Jul 25, 2017

Conversation

enoodle
Copy link

@enoodle enoodle commented Jun 25, 2017

This is migration of ManageIQ/manageiq#15398

@enoodle enoodle force-pushed the add_options_to_ems branch 2 times, most recently from 4f85b51 to 88db4df Compare June 25, 2017 09:43
@enoodle enoodle closed this Jun 25, 2017
@enoodle enoodle reopened this Jun 25, 2017
@enoodle
Copy link
Author

enoodle commented Jun 25, 2017

@simon3z @moolitayer @Fryguy Please take a look

add_column :ext_management_systems, :options, :text

say_with_time("Migrating Kubernetes provider options") do
ExtManagementSystem.where(:type => ["ManageIQ::Providers::Kubernetes::ContainerManager",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove N+1 and do something like:

ExtManagementSystem.where(...).includes(:custom_attributes).where(:custom_attributes => {:section=> 'cluster_settings',... }.each do |ems|
options = ems.custom_attributes.map { |ca| Hash[*["image_inspector_#{ca.name}", ca.value]] }
ems.update(:options => options)
end

Does it cover your intention?

end

def up
add_column :ext_management_systems, :options, :text
Copy link

@moolitayer moolitayer Jun 26, 2017

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

I get that, I think the code should work the same except for dropping the serialize and some other code in the tests.
That way we get native JSON support (for example query only the http_proxy out of options) in the db layer.

@durandom wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

we have jsonb in our migrations, e.g. showback lately

maybe look at their ActiveRecord model about serializing. I have never looked at how we do it

Copy link
Member

Choose a reason for hiding this comment

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

Downside to JSON is that you don't get time objects. Will you need those?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe we will want to have time based optoins? @simon3z

Choose a reason for hiding this comment

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

OK I understand that gap in data types. Since this one is meant to be small
(configuration) I think clear serialization is more important then efficiency.
So I change my mind 👍 for :text

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we will want to have time based optoins? @simon3z

+1 for the ability to have time objects

@@ -19,7 +19,6 @@ def up
ExtManagementSystem
.where(:type => ["ManageIQ::Providers::Kubernetes::ContainerManager",
"ManageIQ::Providers::Openshift::ContainerManager"])
.includes(:custom_attributes).where(:custom_attributes => {:section => "cluster_settings"})
Copy link
Author

Choose a reason for hiding this comment

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

I wonder why this line causes this error: PG::UndefinedColumn: ERROR: column ext_management_systems.security_protocol does not exist , Can anyone advise? cc @lpichler

serialize :options
end

class CustomAttribute < ActiveRecord::Base

Choose a reason for hiding this comment

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

We now put an inheritance_column in every mock class to make it future proof

cp.custom_attributes.where(:section => 'cluster_settings',
:name => %w(no_proxy http_proxy https_proxy))
.map { |ca| ["image_inspector_#{ca.name}".to_sym, ca.value] }]
cp.update(:options => migrated_options)

Choose a reason for hiding this comment

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

the custom attribute names are cluster_settings/no_proxy cluster_settings/http_proxy etc and the new one is image_inspector_no_proxy ?
I think that would be better expressed with nesting.

Copy link
Author

Choose a reason for hiding this comment

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

👍

end

def down
remove_column :ext_management_systems, :options

Choose a reason for hiding this comment

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

up & down will remove the setting...
I'm not sure how stringent we need to be here

Copy link
Author

Choose a reason for hiding this comment

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

I have added down migration.


migration_context :up do
it "up" do
kcp = ems_stub.create!(:type => "ManageIQ::Providers::Openshift::ContainerManager", :id => 1)

Choose a reason for hiding this comment

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

We should avoid ids in tests - that violates region constraints

@enoodle enoodle force-pushed the add_options_to_ems branch 2 times, most recently from 236d34b to fc194a0 Compare June 28, 2017 11:43
@miq-bot
Copy link
Member

miq-bot commented Jun 28, 2017

Checked commit enoodle@fc194a0 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 2 offenses detected

db/migrate/20170619161514_add_options_to_ext_management_system.rb

spec/migrations/20170619161514_add_options_to_ext_management_system_spec.rb

  • ❗ - Line 27, Col 30 - Style/AlignHash - Align the elements of a hash literal if they span more than one line.

Copy link

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@enoodle
Copy link
Author

enoodle commented Jul 10, 2017

ping @lpichler @Fryguy @durandom PTAL

Copy link
Contributor

@simon3z simon3z left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@simon3z
Copy link
Contributor

simon3z commented Jul 17, 2017

@miq-bot assign Fryguy

@Fryguy Fryguy closed this Jul 17, 2017
@Fryguy Fryguy reopened this Jul 17, 2017
@enoodle
Copy link
Author

enoodle commented Jul 20, 2017

ping @Fryguy

@moolitayer
Copy link

cc @Loicavenel

@Fryguy Fryguy merged commit 7dfd56d into ManageIQ:master Jul 25, 2017
@Fryguy Fryguy added this to the Sprint 66 Ending Aug 7, 2017 milestone Jul 25, 2017
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.

8 participants