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

Ensure EMS relationships are established on upgrade. #117

Merged
merged 1 commit into from
Oct 30, 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
27 changes: 27 additions & 0 deletions db/migrate/20171023170841_ensure_cloud_managers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class EnsureCloudManagers < ActiveRecord::Migration[5.0]
class ExtManagementSystem < ActiveRecord::Base
self.inheritance_column = :_type_disabled # disable STI

def ensure_managers
ensure_manager("#{name} Network Manager", "ManageIQ::Providers::Amazon::NetworkManager")
ensure_manager("#{name} EBS Storage Manager", "ManageIQ::Providers::Amazon::StorageManager::Ebs")
end

def ensure_manager(manager_name, manager_type)
self.class.create_with(
:name => manager_name,
:zone_id => zone_id,
:provider_region => provider_region
).find_or_create_by!(
:parent_ems_id => id,
:type => manager_type
)
end
end

def up
say_with_time("Ensuring other managers for all Amazon CloudManagers") do
ExtManagementSystem.where(:type => "ManageIQ::Providers::Amazon::CloudManager").each(&:ensure_managers)
end
end
end
76 changes: 76 additions & 0 deletions spec/migrations/20171023170841_ensure_cloud_managers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require_migration

describe EnsureCloudManagers do
let(:ems_stub) { migration_stub(:ExtManagementSystem) }
let(:zone_id) { anonymous_class_with_id_regions.region_to_range(anonymous_class_with_id_regions.my_region_number).begin }

let!(:manager) do
ems_stub.create!(
:name => "My Amazon",
:type => "ManageIQ::Providers::Amazon::CloudManager",
:provider_region => "us-east-1",
:zone_id => zone_id
)
end

def assert_managers
emses = ems_stub.order(:type).collect do |ems|
ems.attributes.slice(*%w[name type provider_region zone_id parent_ems_id])
end

expect(emses).to eq(
[
{
"name" => "My Amazon",
"type" => "ManageIQ::Providers::Amazon::CloudManager",
"provider_region" => "us-east-1",
"zone_id" => zone_id,
"parent_ems_id" => nil
},
{
"name" => "My Amazon Network Manager",
"type" => "ManageIQ::Providers::Amazon::NetworkManager",
"provider_region" => "us-east-1",
"zone_id" => zone_id,
"parent_ems_id" => manager.id
},
{
"name" => "My Amazon EBS Storage Manager",
"type" => "ManageIQ::Providers::Amazon::StorageManager::Ebs",
"provider_region" => "us-east-1",
"zone_id" => zone_id,
"parent_ems_id" => manager.id
},
]
)
end

migration_context :up do
it "creates managers for an Amazon CloudManager without child managers" do
migrate

assert_managers
end

it "handles an Amazon CloudManager already with child managers" do
ems_stub.create!(
:name => "My Amazon Network Manager",
:type => "ManageIQ::Providers::Amazon::NetworkManager",
:provider_region => "us-east-1",
:zone_id => zone_id,
:parent_ems_id => manager.id
)
ems_stub.create!(
:name => "My Amazon EBS Storage Manager",
:type => "ManageIQ::Providers::Amazon::StorageManager::Ebs",
:provider_region => "us-east-1",
:zone_id => zone_id,
:parent_ems_id => manager.id
)

migrate

assert_managers
end
end
end