Skip to content

Commit

Permalink
Convert invalid containers hawkular Endpoints port=nil to port=443
Browse files Browse the repository at this point in the history
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
cben committed Oct 30, 2017
1 parent 92c0b74 commit dd5ed57
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
25 changes: 25 additions & 0 deletions db/migrate/20171030131403_fix_hawkular_endpoints_with_port_nil.rb
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
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

0 comments on commit dd5ed57

Please sign in to comment.