From 2ff0b63d1b7f2f3275c3a2e2435f8ded688b6f66 Mon Sep 17 00:00:00 2001
From: Sam Lucidi <slucidi@redhat.com>
Date: Wed, 11 Oct 2017 14:15:30 -0400
Subject: [PATCH] Move Openstack refresher settings

---
 ...80000_move_openstack_refresher_settings.rb | 13 ++++++++++++
 ...80000_move_openstack_refresher_settings.rb | 21 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 db/migrate/20171011180000_move_openstack_refresher_settings.rb
 create mode 100644 spec/migrations/20171011180000_move_openstack_refresher_settings.rb

diff --git a/db/migrate/20171011180000_move_openstack_refresher_settings.rb b/db/migrate/20171011180000_move_openstack_refresher_settings.rb
new file mode 100644
index 000000000..4b5acc06d
--- /dev/null
+++ b/db/migrate/20171011180000_move_openstack_refresher_settings.rb
@@ -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')
+      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
diff --git a/spec/migrations/20171011180000_move_openstack_refresher_settings.rb b/spec/migrations/20171011180000_move_openstack_refresher_settings.rb
new file mode 100644
index 000000000..2c5c65708
--- /dev/null
+++ b/spec/migrations/20171011180000_move_openstack_refresher_settings.rb
@@ -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