-
Notifications
You must be signed in to change notification settings - Fork 50
Evaluate IoP status at runtime, not application start, and register Ping extension always #1138
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
Merged
jeremylenz
merged 2 commits into
theforeman:develop
from
jeremylenz:fix-iop-metadata-runtime-evaluation
Jan 15, 2026
+208
−9
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,200 @@ | ||
| require 'test_plugin_helper' | ||
|
|
||
| class ForemanRhCloudIopMetadataTest < ActiveSupport::TestCase | ||
| setup do | ||
| # Clean up any existing IoP smart proxies | ||
| SmartProxy.unscoped.with_features('iop').destroy_all | ||
| end | ||
|
|
||
| teardown do | ||
| # Clean up | ||
| SmartProxy.unscoped.with_features('iop').destroy_all | ||
| end | ||
|
|
||
| def create_iop_proxy(url: 'https://iop.example.com') | ||
| feature = Feature.find_or_create_by(name: 'iop') | ||
| proxy = FactoryBot.create(:smart_proxy, :url => url) | ||
| # Clear any existing associations for this feature | ||
| feature.reload | ||
| feature.smart_proxies.clear | ||
| proxy.features << feature | ||
| proxy | ||
| end | ||
|
|
||
| describe 'plugin metadata' do | ||
| test 'iop metadata is false when no IoP smart proxy exists' do | ||
| # Ensure no IoP proxy exists | ||
| refute ForemanRhCloud.with_iop_smart_proxy? | ||
|
|
||
| # Plugin metadata should reflect this | ||
| metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud] | ||
|
|
||
| # The value is a lambda, so we need to call it | ||
| assert_kind_of Proc, metadata[:iop] | ||
| refute metadata[:iop].call | ||
| end | ||
|
|
||
| test 'iop metadata is true when IoP smart proxy exists' do | ||
| # Create an IoP smart proxy | ||
| create_iop_proxy | ||
|
|
||
| # Verify proxy exists | ||
| assert ForemanRhCloud.with_iop_smart_proxy? | ||
|
|
||
| # Plugin metadata should reflect this | ||
| metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud] | ||
|
|
||
| # The value is a lambda, so we need to call it | ||
| assert_kind_of Proc, metadata[:iop] | ||
| assert metadata[:iop].call | ||
| end | ||
|
|
||
| test 'iop metadata updates when IoP smart proxy is created' do | ||
| # Initially no IoP proxy | ||
| metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud] | ||
| refute metadata[:iop].call | ||
|
|
||
| # Create an IoP smart proxy | ||
| create_iop_proxy | ||
|
|
||
| # Metadata should now return true | ||
| assert metadata[:iop].call | ||
| end | ||
|
|
||
| test 'iop metadata updates when IoP smart proxy is destroyed' do | ||
| # Create an IoP smart proxy | ||
| proxy = create_iop_proxy | ||
|
|
||
| metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud] | ||
| assert metadata[:iop].call | ||
|
|
||
| # Destroy the proxy | ||
| proxy.destroy | ||
|
|
||
| # Metadata should now return false | ||
| refute metadata[:iop].call | ||
| end | ||
| end | ||
|
|
||
| describe 'URL methods' do | ||
| test 'base_url returns cloud URL when no IoP smart proxy exists' do | ||
| assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url | ||
| end | ||
|
|
||
| test 'cert_base_url returns cloud URL when no IoP smart proxy exists' do | ||
| assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url | ||
| end | ||
|
|
||
| test 'legacy_insights_url returns cloud URL when no IoP smart proxy exists' do | ||
| assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url | ||
| end | ||
|
|
||
| test 'base_url returns IoP URL when IoP smart proxy exists' do | ||
| create_iop_proxy | ||
|
|
||
| assert_equal 'https://iop.example.com', ForemanRhCloud.base_url | ||
| end | ||
|
|
||
| test 'cert_base_url returns IoP URL when IoP smart proxy exists' do | ||
| create_iop_proxy | ||
|
|
||
| assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url | ||
| end | ||
|
|
||
| test 'legacy_insights_url returns IoP URL when IoP smart proxy exists' do | ||
| create_iop_proxy | ||
|
|
||
| assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url | ||
| end | ||
|
|
||
| test 'base_url returns ENV var when set' do | ||
| ENV['SATELLITE_RH_CLOUD_URL'] = 'https://custom.example.com' | ||
|
|
||
| assert_equal 'https://custom.example.com', ForemanRhCloud.base_url | ||
| ensure | ||
| ENV.delete('SATELLITE_RH_CLOUD_URL') | ||
| end | ||
|
|
||
| test 'cert_base_url returns ENV var when set' do | ||
| ENV['SATELLITE_CERT_RH_CLOUD_URL'] = 'https://env-cert.cloud.test' | ||
|
|
||
| assert_equal 'https://env-cert.cloud.test', ForemanRhCloud.cert_base_url | ||
| ensure | ||
| ENV.delete('SATELLITE_CERT_RH_CLOUD_URL') | ||
| end | ||
|
|
||
| test 'legacy_insights_url returns ENV var when set' do | ||
| ENV['SATELLITE_LEGACY_INSIGHTS_URL'] = 'https://env-legacy.insights.test' | ||
|
|
||
| assert_equal 'https://env-legacy.insights.test', ForemanRhCloud.legacy_insights_url | ||
| ensure | ||
| ENV.delete('SATELLITE_LEGACY_INSIGHTS_URL') | ||
| end | ||
|
|
||
| test 'base_url prefers IoP URL over ENV var' do | ||
| ENV['SATELLITE_RH_CLOUD_URL'] = 'https://custom.example.com' | ||
|
|
||
| create_iop_proxy | ||
|
|
||
| # IoP URL should take precedence | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.base_url | ||
| ensure | ||
| ENV.delete('SATELLITE_RH_CLOUD_URL') | ||
| end | ||
|
|
||
| test 'cert_base_url prefers IoP URL over ENV var' do | ||
| ENV['SATELLITE_CERT_RH_CLOUD_URL'] = 'https://env-cert.cloud.test' | ||
|
|
||
| create_iop_proxy | ||
|
|
||
| # IoP URL should take precedence | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url | ||
| ensure | ||
| ENV.delete('SATELLITE_CERT_RH_CLOUD_URL') | ||
| end | ||
|
|
||
| test 'legacy_insights_url prefers IoP URL over ENV var' do | ||
| ENV['SATELLITE_LEGACY_INSIGHTS_URL'] = 'https://env-legacy.insights.test' | ||
|
|
||
| create_iop_proxy | ||
|
|
||
| # IoP URL should take precedence | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url | ||
| ensure | ||
| ENV.delete('SATELLITE_LEGACY_INSIGHTS_URL') | ||
| end | ||
|
|
||
| test 'URL methods update when IoP smart proxy is created' do | ||
| # Initially returns cloud URLs | ||
| assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url | ||
| assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url | ||
| assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url | ||
|
|
||
| # Create an IoP smart proxy | ||
| create_iop_proxy | ||
|
|
||
| # Should now return IoP URL for all helpers | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.base_url | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url | ||
| end | ||
|
|
||
| test 'URL methods update when IoP smart proxy is destroyed' do | ||
| # Create an IoP smart proxy | ||
| proxy = create_iop_proxy | ||
|
|
||
| # Initially returns IoP URL for all helpers | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.base_url | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url | ||
| assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url | ||
|
|
||
| # Destroy the proxy | ||
| proxy.destroy | ||
|
|
||
| # Should now return cloud URLs again | ||
| assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url | ||
| assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url | ||
| assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.