Sha256: 7cabcbc7e4095b8142da869a68ef0a20cc3d4e5a9846a95a6ed498f301319869

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Actions
  module ForemanLeapp
    class PreupgradeJob < Actions::EntryAction
      def self.subscribe
        Actions::RemoteExecution::RunHostJob
      end

      def plan(job_invocation, host, *_args)
        return unless ::Helpers::JobHelper.correct_feature?(job_invocation, 'leapp_preupgrade')

        plan_self(host_id: host.id, job_invocation_id: job_invocation.id)
      end

      def finalize(*_args)
        host = Host.find(input[:host_id])
        leapp_report = format_output(task.main_action.continuous_output.humanize)

        PreupgradeReport.create_report(host, leapp_report, input[:job_invocation_id])
      end

      private

      def format_output(job_output)
        output = job_output.each_line(chomp: true)
                           .drop_while { |l| !l.start_with? '===leap_upgrade_report_start===' }.drop(1)
                           .take_while { |l| !l.start_with? 'Exit status:' }
                           .reject(&:empty?)
                           .join('')
        JSON.parse(output)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_leapp-0.0.6 app/lib/actions/preupgrade_job.rb
foreman_leapp-0.0.5 app/lib/actions/preupgrade_job.rb
foreman_leapp-0.0.4 app/lib/actions/preupgrade_job.rb
foreman_leapp-0.0.3 app/lib/actions/preupgrade_job.rb
foreman_leapp-0.0.2 app/lib/actions/preupgrade_job.rb