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

Move Openstack refresher settings #91

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions db/migrate/20171011180000_move_openstack_refresher_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class MoveOpenstackRefresherSettings < ActiveRecord::Migration[5.0]
class SettingsChange < ActiveRecord::Base
end

def up
say_with_time('Move Openstack provider refresher settings') do
SettingsChange.where(:key => '/ems/ems_openstack/refresh/inventory_object_refresh').update(:key => '/ems/ems_refresh/openstack/inventory_object_refresh')
Copy link
Member

@Fryguy Fryguy Oct 20, 2017

Choose a reason for hiding this comment

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

Prefer update_all over update as it will go direct to the DB instead of instantiating one-by-one.

Doesn't matter since you search for a single key. However, if the entirety of "/ems/ems_openstack/refresh" is changing you can also do:

SettingsChange.where("key LIKE ?", "/ems/ems_openstack/refresh/%"').each do |sc|
  sc.update_attributes!(:key => sc.key.sub("/ems/ems_openstack/refresh/", "/ems/ems_refresh/openstack")
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. The changes aren't all exactly 1-1 so I'm going to stick with the explicit calls, if that's alright with you.

SettingsChange.where(:key => '/ems/ems_openstack/refresh/heat/is_global_admin').update(:key => '/ems/ems_refresh/openstack/heat/is_global_admin')
SettingsChange.where(:key => '/ems/ems_openstack/refresh/is_admin').update(:key => '/ems/ems_refresh/openstack/is_admin')
SettingsChange.where(:key => '/ems/ems_openstack/refresh/event_targeted_refresh').update(:key => '/ems/ems_refresh/openstack/allow_targeted_refresh')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_migration

describe MoveOpenstackRefresherSettings do
let(:settings_stub) { migration_stub(:SettingsChange) }

migration_context :up do
it 'Move Openstack provider refresher settings' do
settings_stub.create!(:key => '/ems/ems_openstack/refresh/inventory_object_refresh', :value => true)
settings_stub.create!(:key => '/ems/ems_openstack/refresh/heat/is_global_admin', :value => true)
settings_stub.create!(:key => '/ems/ems_openstack/refresh/is_admin', :value => true)
settings_stub.create!(:key => '/ems/ems_openstack/refresh/event_targeted_refresh', :value => true)

migrate

expect(settings_stub.where(:key => '/ems/ems_refresh/openstack/inventory_object_refresh').count).to eq(1)
expect(settings_stub.where(:key => '/ems/ems_refresh/openstack/heat/is_global_admin').count).to eq(1)
expect(settings_stub.where(:key => '/ems/ems_refresh/openstack/is_admin').count).to eq(1)
expect(settings_stub.where(:key => '/ems/ems_refresh/openstack/allow_targeted_refresh').count).to eq(1)
end
end
end