forked from ManageIQ/manageiq-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert invalid containers hawkular Endpoints port=nil to port=443
For a time (before ManageIQ/manageiq-ui-classic#1172), it was possible in UI to save containers provider without hawkular port and then it'd be impossible to edit the provider as UI would crash. AFAICT, such providers were effectively using port 443 (builds hawkular url https://<host>/ without port, HTTPS defaults to 443). This migration normalizes such endpoints to port 443. This makes it possible to edit in UI, without adding a nil special case. We'll also be able to simplify hawkular connection code in future. https://bugzilla.redhat.com/show_bug.cgi?id=1432070
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
db/migrate/20171030131403_fix_hawkular_endpoints_with_port_nil.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,25 @@ | ||
class FixHawkularEndpointsWithPortNil < ActiveRecord::Migration[5.0] | ||
class ExtManagementSystem < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class Endpoint < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
def up | ||
container_hawkular_endpoints.where(:port => nil).update_all(:port => 443) | ||
end | ||
|
||
def container_hawkular_endpoints | ||
ems_container_ids = ExtManagementSystem.where( | ||
:type => %w(ManageIQ::Providers::Openshift::ContainerManager ManageIQ::Providers::Kubernetes::ContainerManager) | ||
).pluck(:id) | ||
|
||
Endpoint.where( | ||
:resource_type => 'ExtManagementSystem', | ||
:resource_id => ems_container_ids, | ||
:role => 'hawkular' | ||
) | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/migrations/20171030131403_fix_hawkular_endpoints_with_port_nil_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,65 @@ | ||
require_migration | ||
|
||
describe FixHawkularEndpointsWithPortNil do | ||
let(:ext_management_system_stub) { migration_stub(:ExtManagementSystem) } | ||
let(:endpoint_stub) { migration_stub(:Endpoint) } | ||
|
||
migration_context :up do | ||
it 'Modifies hawkular endpoints with nil port' do | ||
ems = ext_management_system_stub.create!( | ||
:name => 'container', | ||
:type => 'ManageIQ::Providers::Openshift::ContainerManager' | ||
) | ||
hawk = endpoint_stub.create!( | ||
:role => "hawkular", | ||
:hostname => "hawkname", | ||
:port => nil, | ||
:resource_type => "ExtManagementSystem", | ||
:resource_id => ems.id | ||
) | ||
|
||
migrate | ||
|
||
expect(hawk.reload.port).to eq(443) | ||
end | ||
|
||
it 'Does not modify non-nil port, or non-containers-hawkular endpoints' do | ||
ems = ext_management_system_stub.create!( | ||
:name => 'container', | ||
:type => 'ManageIQ::Providers::Openshift::ContainerManager' | ||
) | ||
hawk = endpoint_stub.create!( | ||
:role => "hawkular", | ||
:hostname => "hawkname", | ||
:port => 123, | ||
:resource_type => "ExtManagementSystem", | ||
:resource_id => ems.id | ||
) | ||
main = endpoint_stub.create!( | ||
:role => "default", | ||
:hostname => "hostname", | ||
:port => nil, | ||
:resource_type => "ExtManagementSystem", | ||
:resource_id => ems.id | ||
) | ||
|
||
other_ems = ext_management_system_stub.create!( | ||
:name => 'container', | ||
:type => 'ManageIQ::Providers::Amazon::CloudManager' | ||
) | ||
other = endpoint_stub.create!( | ||
:role => "unrelated", | ||
:hostname => "neverwhere", | ||
:port => nil, | ||
:resource_type => "ExtManagementSystem", | ||
:resource_id => other_ems.id | ||
) | ||
|
||
migrate | ||
|
||
expect(hawk.reload.port).to eq(123) | ||
expect(main.reload.port).to eq(nil) | ||
expect(other.reload.port).to eq(nil) | ||
end | ||
end | ||
end |