Sha256: 6146cc17bfab1c380539344c3bd65bdaa15c3ad1bdfd8d1bcdab6c8997cdcc65

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Katello
  class UpstreamConnectionChecker
    POSSIBLE_EXCEPTIONS = [
      Katello::Errors::DisconnectedMode,
      Katello::Errors::ManifestExpired,
      Katello::Errors::UpstreamConsumerGone,
      Katello::Errors::UpstreamConsumerNotFound,
      Katello::Errors::NoManifestImported
    ].freeze

    def initialize(organization)
      @organization = organization
    end

    def can_connect?
      assert_connection
    rescue StandardError => e
      if POSSIBLE_EXCEPTIONS.include?(e.class)
        false
      else
        raise e
      end
    end

    def assert_connection
      assert_connected
      assert_unexpired_manifest
      assert_can_upstream_ping

      true
    end

    private

    def assert_connected
      fail Katello::Errors::DisconnectedMode if Setting[:content_disconnected]
    end

    def assert_can_upstream_ping
      ::Organization.as_org(@organization) do
        Katello::Resources::Candlepin::UpstreamConsumer.ping
      end
    end

    def assert_unexpired_manifest
      fail Katello::Errors::ManifestExpired if @organization.manifest_expired?
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
katello-4.3.1 app/services/katello/upstream_connection_checker.rb
katello-4.3.0 app/services/katello/upstream_connection_checker.rb
katello-4.3.0.rc4 app/services/katello/upstream_connection_checker.rb
katello-4.3.0.rc3 app/services/katello/upstream_connection_checker.rb
katello-4.3.0.rc2.1 app/services/katello/upstream_connection_checker.rb
katello-4.3.0.rc2 app/services/katello/upstream_connection_checker.rb
katello-4.3.0.rc1 app/services/katello/upstream_connection_checker.rb