-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate EmsRefresh.refresh queue args to data
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
db/migrate/20171025122732_move_ems_refresh_args_to_data.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class MoveEmsRefreshArgsToData < ActiveRecord::Migration[5.0] | ||
class MiqQueue < ActiveRecord::Base | ||
serialize :args, Array | ||
end | ||
|
||
def up | ||
say_with_time('Move MiqQueue refresh args to data') do | ||
MiqQueue.where(:class_name => 'EmsRefresh', :method_name => 'refresh').each do |queue_item| | ||
data = Marshal.dump(queue_item.args.first) | ||
queue_item.update_attributes(:msg_data => data, :args => []) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
say_with_time('Move MiqQueue refresh data to args') do | ||
MiqQueue.where(:class_name => 'EmsRefresh', :method_name => 'refresh').each do |queue_item| | ||
args = queue_item.msg_data && Marshal.load(queue_item.msg_data) | ||
queue_item.update_attributes(:args => args, :msg_data => nil) | ||
end | ||
end | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
spec/migrations/20171025122732_move_ems_refresh_args_to_data_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require_migration | ||
|
||
describe MoveEmsRefreshArgsToData do | ||
let(:miq_queue_stub) { migration_stub(:MiqQueue) } | ||
let(:targets) { [['Vm', 1], ['Host', 2]] } | ||
let(:refresh_queue_options) do | ||
{ | ||
:class_name => 'EmsRefresh', | ||
:method_name => 'refresh', | ||
:role => 'ems_inventory', | ||
:queue_name => 'ems_1', | ||
:zone => 'default', | ||
} | ||
end | ||
let(:refresh_new_target_queue_options) do | ||
{ | ||
:class_name => 'EmsRefresh', | ||
:method_name => 'refresh_new_target', | ||
:role => 'ems_inventory', | ||
:queue_name => 'ems_1', | ||
:zone => 'default', | ||
} | ||
end | ||
|
||
migration_context :up do | ||
it "Moves EmsRefresh.refresh queue args to data" do | ||
q_item = miq_queue_stub.create!(refresh_queue_options.merge(:args => [targets])) | ||
|
||
migrate | ||
|
||
expect(Marshal.load(q_item.reload.msg_data)).to match_array(targets) | ||
end | ||
|
||
it "Leaves EmsRefresh.refresh args empty" do | ||
q_item = miq_queue_stub.create!(refresh_queue_options.merge(:args => [targets])) | ||
|
||
migrate | ||
|
||
expect(q_item.reload.args).to match_array([]) | ||
end | ||
|
||
it "Ignores unrelated queue items" do | ||
args = [{:ems_ref => "vm-123"}] | ||
q_item = miq_queue_stub.create!(refresh_new_target_queue_options.merge(:args => args)) | ||
|
||
migrate | ||
|
||
expect(q_item.reload.args).to match_array(args) | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "Moves EmsRefresh.refresh data to args" do | ||
q_item = miq_queue_stub.create!(refresh_queue_options.merge(:msg_data => Marshal.dump(targets))) | ||
|
||
migrate | ||
|
||
expect(q_item.reload.args).to match_array(targets) | ||
end | ||
|
||
it "If there are no args" do | ||
q_item = miq_queue_stub.create!(refresh_queue_options.merge(:msg_data => nil)) | ||
|
||
migrate | ||
|
||
expect(q_item.reload.args).to match_array([]) | ||
end | ||
end | ||
end |