Revision aa0f58ea
Added by Stephen Benjamin over 5 years ago
app/registries/foreman/plugin/medium_providers_registry.rb | ||
---|---|---|
provider
|
||
end
|
||
|
||
def unregister(provider)
|
||
@providers.delete(provider.to_s)
|
||
end
|
||
|
||
# Find a provider that can provide a URI for a given entity.
|
||
def find_provider(entity)
|
||
raise Foreman::Exception.new('Must supply an entity to find a medium provider') unless entity
|
||
... | ... | |
valid_providers = provider_instances.select { |provider| provider.valid? }
|
||
if valid_providers.count > 1
|
||
logger.error(
|
||
_('Found more than one provider for %{entity}. Valid providers: %{providers}') %
|
||
'Found more than one provider for %{entity}. Valid providers: %{providers}' %
|
||
{
|
||
entity: entity,
|
||
providers: providers.map { |provider| provider.class.friendly_name }
|
||
... | ... | |
|
||
unless valid_providers.present?
|
||
logger.error(
|
||
_('Could not find a provider for %{entity}. Providers returned %{errors}') %
|
||
'Could not find a provider for %{entity}. Providers returned %{errors}' %
|
||
{
|
||
entity: entity,
|
||
errors: provider_instances.map { |provider| [provider.class.friendly_name, provider.errors] }.to_h
|
test/unit/medium_providers/default_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
class DefaultMediumProviderTest < ActiveSupport::TestCase
|
||
test 'returns default provider for managed host' do
|
||
host = FactoryBot.create(:host, :managed)
|
||
medium_provider = Foreman::Plugin.medium_providers.find_provider(host)
|
||
assert_instance_of MediumProviders::Default, medium_provider
|
||
end
|
||
|
||
test 'interpolated $version does not include dots if only major is specified' do
|
||
operatingsystem = FactoryBot.build_stubbed(:operatingsystem, :name => 'foo', :major => '4')
|
||
architecture = FactoryBot.build_stubbed(:architecture, :name => 'x64')
|
test/unit/medium_providers/plugin_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
class PluginMediumProviderTest < ActiveSupport::TestCase
|
||
class PluginMediumProvider < MediumProviders::Provider
|
||
def medium_uri(path = "", &block)
|
||
'/medium'
|
||
end
|
||
|
||
def valid?
|
||
true
|
||
end
|
||
end
|
||
|
||
setup do
|
||
Foreman::Plugin.medium_providers.register(PluginMediumProvider)
|
||
end
|
||
|
||
teardown do
|
||
Foreman::Plugin.medium_providers.unregister(PluginMediumProvider)
|
||
end
|
||
|
||
test 'plugin can provide media without medium set' do
|
||
host = FactoryBot.create(:host, :with_operatingsystem, medium: nil)
|
||
medium_provider = Foreman::Plugin.medium_providers.find_provider(host)
|
||
assert_nil host.medium
|
||
assert_instance_of PluginMediumProvider, medium_provider
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #25007 - fix medium providers for plugins
Katello doesn't have medium set, since the medium is being provided
through the medium provider. This change allows a medium provider
to function in this case.