Sha256: f6d164e71f997736aa7a1ce5572f6d98f9d8b5304f901d617c851da05c6eb6b7

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 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 ::JobHelper.correct_feature?(job_invocation, 'leapp_preupgrade') ||
                      ::JobHelper.correct_feature?(job_invocation, 'leapp_remediation_plan')

        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

2 entries across 2 versions & 1 rubygems

Version Path
foreman_leapp-2.0.1 app/lib/actions/foreman_leapp/preupgrade_job.rb
foreman_leapp-2.0.0 app/lib/actions/foreman_leapp/preupgrade_job.rb