foreman_leapp 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +50 -0
- data/Rakefile +49 -0
- data/app/controllers/api/v2/preupgrade_reports_controller.rb +19 -0
- data/app/controllers/preupgrade_reports_controller.rb +7 -0
- data/app/helpers/concerns/foreman_leapp/hosts_helper_extensions.rb +17 -0
- data/app/helpers/concerns/foreman_leapp/remote_execution_helper_extension.rb +15 -0
- data/app/helpers/foreman_leapp/template_helper.rb +15 -0
- data/app/lib/actions/preupgrade_job.rb +35 -0
- data/app/lib/helpers/job_helper.rb +14 -0
- data/app/models/concerns/foreman_leapp/job_invocation_extensions.rb +11 -0
- data/app/models/preupgrade_report.rb +32 -0
- data/app/models/preupgrade_report_entry.rb +15 -0
- data/app/views/api/v2/preupgrade_report_entries/base.json.rabl +4 -0
- data/app/views/api/v2/preupgrade_reports/base.json.rabl +3 -0
- data/app/views/api/v2/preupgrade_reports/index.json.rabl +3 -0
- data/app/views/api/v2/preupgrade_reports/show.json.rabl +7 -0
- data/app/views/foreman_leapp/job_templates/preupgrade.erb +14 -0
- data/app/views/foreman_leapp/job_templates/remediation.erb +17 -0
- data/app/views/foreman_leapp/job_templates/upgrade.erb +16 -0
- data/app/views/job_invocations/_leapp_preupgrade_report.html.erb +10 -0
- data/app/views/preupgrade_report_entries/base.json.rabl +4 -0
- data/app/views/preupgrade_reports/index.json.rabl +3 -0
- data/app/views/preupgrade_reports/show.json.rabl +7 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20200320104040_preupgrade_report_entries.rb +25 -0
- data/db/migrate/20200326142259_add_job_id_to_report.rb +6 -0
- data/db/migrate/20200327091009_add_host_to_report.rb +6 -0
- data/db/seeds.d/10_leapp_preupgrade.rb +19 -0
- data/lib/foreman_leapp/engine.rb +95 -0
- data/lib/foreman_leapp/version.rb +5 -0
- data/lib/foreman_leapp.rb +7 -0
- data/lib/tasks/foreman_leapp_tasks.rake +49 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_leapp.po +19 -0
- data/locale/foreman_leapp.pot +19 -0
- data/locale/gemspec.rb +4 -0
- data/test/factories/foreman_leapp_factories.rb +27 -0
- data/test/functional/api/v2/preupgrade_reports_controller_test.rb +30 -0
- data/test/functional/preupgrade_reports_controller_test.rb +16 -0
- data/test/helpers/template_helper_test.rb +31 -0
- data/test/models/preupgrade_report_entry_test.rb +36 -0
- data/test/models/preupgrade_report_test.rb +46 -0
- data/test/test_plugin_helper.rb +11 -0
- data/test/unit/actions/preupgrade_job_test.rb +43 -0
- data/test/unit/helpers/job_helper_test.rb +37 -0
- metadata +141 -0
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
rescue LoadError
|
7
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
8
|
+
end
|
9
|
+
begin
|
10
|
+
require 'rdoc/task'
|
11
|
+
rescue LoadError
|
12
|
+
require 'rdoc/rdoc'
|
13
|
+
require 'rake/rdoctask'
|
14
|
+
RDoc::Task = Rake::RDocTask
|
15
|
+
end
|
16
|
+
|
17
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'ForemanLeapp'
|
20
|
+
rdoc.options << '--line-numbers'
|
21
|
+
rdoc.rdoc_files.include('README.rdoc')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
|
31
|
+
Rake::TestTask.new(:test) do |t|
|
32
|
+
t.libs << 'lib'
|
33
|
+
t.libs << 'test'
|
34
|
+
t.pattern = 'test/**/*_test.rb'
|
35
|
+
t.verbose = false
|
36
|
+
end
|
37
|
+
|
38
|
+
task default: :test
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'rubocop/rake_task'
|
42
|
+
RuboCop::RakeTask.new
|
43
|
+
rescue StandardError => _e
|
44
|
+
puts 'Rubocop not loaded.'
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default do
|
48
|
+
Rake::Task['rubocop'].execute
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Api
|
4
|
+
module V2
|
5
|
+
class PreupgradeReportsController < ::Api::V2::BaseController
|
6
|
+
before_action :find_resource, only: %i[show]
|
7
|
+
|
8
|
+
api :GET, '/preupgrade_reports/', N_('List Preupgrade reports')
|
9
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
10
|
+
def index
|
11
|
+
@preupgrade_reports = resource_scope_for_index
|
12
|
+
end
|
13
|
+
|
14
|
+
api :GET, '/preupgrade_reports/:id', N_('Show Preupgrade report')
|
15
|
+
param :id, :identifier, required: true
|
16
|
+
def show; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanLeapp
|
4
|
+
module HostsHelperExtensions
|
5
|
+
def multiple_actions
|
6
|
+
super + [[_('Preupgrade check with Leapp'), new_job_invocation_path(feature: 'leapp_preupgrade'), false],
|
7
|
+
[_('Upgrade with Leapp'), new_job_invocation_path(feature: 'leapp_upgrade'), false]]
|
8
|
+
end
|
9
|
+
|
10
|
+
def rex_host_features(*args)
|
11
|
+
super + [link_to(_('Preupgrade check with Leapp'),
|
12
|
+
new_job_invocation_path(host_ids: [args.first.id], feature: 'leapp_preupgrade')),
|
13
|
+
link_to(_('Upgrade with Leapp'),
|
14
|
+
new_job_invocation_path(host_ids: [args.first.id], feature: 'leapp_upgrade'))]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanLeapp
|
4
|
+
module RemoteExecutionHelperExtension
|
5
|
+
def job_invocation_task_buttons(task)
|
6
|
+
return super unless ::Helpers::JobHelper.correct_feature?(@job_invocation, 'leapp_remediation_plan')
|
7
|
+
|
8
|
+
super.insert(2, link_to(_('Rerun preupgrade check'),
|
9
|
+
new_job_invocation_path(host_ids: @resource_base.map(&:id), feature: 'leapp_preupgrade'),
|
10
|
+
class: 'btn btn-default',
|
11
|
+
title: _('Run Leapp Preupgrade check again'),
|
12
|
+
method: :get))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanLeapp
|
4
|
+
module TemplateHelper
|
5
|
+
def build_remediation_plan(remediation_ids, host)
|
6
|
+
PreupgradeReportEntry.remediation_details(remediation_ids, host)
|
7
|
+
.map { |e| e['remediations'] }
|
8
|
+
.flatten
|
9
|
+
.compact
|
10
|
+
.select { |r| r['type'] == 'command' }
|
11
|
+
.map { |r| "#{r['context'].join(' ')}\n" }
|
12
|
+
.join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanLeapp
|
5
|
+
class PreupgradeJob < Actions::EntryAction
|
6
|
+
def self.subscribe
|
7
|
+
Actions::RemoteExecution::RunHostJob
|
8
|
+
end
|
9
|
+
|
10
|
+
def plan(job_invocation, host, *_args)
|
11
|
+
return unless ::Helpers::JobHelper.correct_feature?(job_invocation, 'leapp_preupgrade')
|
12
|
+
|
13
|
+
plan_self(host_id: host.id, job_invocation_id: job_invocation.id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def finalize(*_args)
|
17
|
+
host = Host.find(input[:host_id])
|
18
|
+
leapp_report = format_output(task.main_action.continuous_output.humanize)
|
19
|
+
|
20
|
+
PreupgradeReport.create_report(host, leapp_report, input[:job_invocation_id])
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def format_output(job_output)
|
26
|
+
output = job_output.each_line(chomp: true)
|
27
|
+
.drop_while { |l| !l.start_with? '===leap_upgrade_report_start===' }.drop(1)
|
28
|
+
.take_while { |l| !l.start_with? 'Exit status:' }
|
29
|
+
.reject(&:empty?)
|
30
|
+
.join('')
|
31
|
+
JSON.parse(output)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
module JobHelper
|
5
|
+
class << self
|
6
|
+
def correct_feature?(job_invocation, feature)
|
7
|
+
job_invocation.job_category == ::ForemanLeapp::JOB_CATEGORY &&
|
8
|
+
RemoteExecutionFeature.find_by(job_template_id: job_invocation.pattern_template_invocations
|
9
|
+
.pluck(:template_id)
|
10
|
+
.first)&.label == feature
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PreupgradeReport < ::Report
|
4
|
+
belongs_to :job_invocation
|
5
|
+
has_many :preupgrade_report_entries, dependent: :destroy
|
6
|
+
|
7
|
+
scoped_search on: :job_invocation_id, only_explicit: true
|
8
|
+
|
9
|
+
def self.create_report(host, data, job_invocation_id)
|
10
|
+
report = PreupgradeReport.create(host: host, status: 0,
|
11
|
+
job_invocation_id: job_invocation_id,
|
12
|
+
reported_at: DateTime.now.utc)
|
13
|
+
|
14
|
+
data['entries']&.each do |entry|
|
15
|
+
PreupgradeReportEntry.create! entry_params(report, entry, host, data)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.entry_params(report, entry, host, data)
|
20
|
+
{ preupgrade_report: report,
|
21
|
+
host_id: host.id,
|
22
|
+
hostname: host.name,
|
23
|
+
title: entry['title'],
|
24
|
+
actor: entry['actor'],
|
25
|
+
audience: entry['audience'],
|
26
|
+
severity: entry['severity'],
|
27
|
+
leapp_run_id: data['leapp_run_id'],
|
28
|
+
summary: entry['summary'],
|
29
|
+
tags: entry['tags'],
|
30
|
+
detail: entry['detail'] }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PreupgradeReportEntry < ApplicationRecord
|
4
|
+
belongs_to :preupgrade_report
|
5
|
+
belongs_to_host
|
6
|
+
|
7
|
+
serialize :tags, Array
|
8
|
+
serialize :detail, JSON
|
9
|
+
|
10
|
+
validates :preupgrade_report, :host, :hostname, :title, :actor, :audience, :severity, :leapp_run_id, presence: true
|
11
|
+
|
12
|
+
def self.remediation_details(remediation_ids, host)
|
13
|
+
where(id: remediation_ids, host: host).where.not(detail: nil).pluck(:detail)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%#
|
2
|
+
kind: job_template
|
3
|
+
name: Run preupgrade via Leapp
|
4
|
+
job_category: Leapp
|
5
|
+
description_format: 'Upgradeability check for RHEL 7 host'
|
6
|
+
provider_type: SSH
|
7
|
+
feature: leapp_preupgrade
|
8
|
+
%>
|
9
|
+
|
10
|
+
leapp preupgrade
|
11
|
+
[ $? -eq 0 ] || exit 1
|
12
|
+
|
13
|
+
echo "===leap_upgrade_report_start==="
|
14
|
+
cat /var/log/leapp/leapp-report.json
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%#
|
2
|
+
kind: job_template
|
3
|
+
name: Remediation plan
|
4
|
+
job_category: Leapp
|
5
|
+
description_format: 'Run Remediation plan with Leapp'
|
6
|
+
provider_type: SSH
|
7
|
+
feature: leapp_remediation_plan
|
8
|
+
template_inputs:
|
9
|
+
- name: remediation_ids
|
10
|
+
required: true
|
11
|
+
advanced: true
|
12
|
+
input_type: user
|
13
|
+
value_type: plain
|
14
|
+
description: List of remediation ids
|
15
|
+
%>
|
16
|
+
|
17
|
+
<%= build_remediation_plan(input('remediation_ids').split(','), @host) %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%#
|
2
|
+
kind: job_template
|
3
|
+
name: Run upgrade via Leapp
|
4
|
+
job_category: Leapp
|
5
|
+
description_format: 'Upgrade RHEL 7 host'
|
6
|
+
provider_type: SSH
|
7
|
+
feature: leapp_upgrade
|
8
|
+
template_inputs:
|
9
|
+
- name: reboot
|
10
|
+
description: reboot the vm automaticaly to continue with the upgrade
|
11
|
+
input_type: user
|
12
|
+
required: false
|
13
|
+
options: "false\ntrue"
|
14
|
+
%>
|
15
|
+
|
16
|
+
leapp upgrade <%= "--reboot" if input('reboot') == "true" %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% content_for(:javascripts) do %>
|
2
|
+
<%= webpacked_plugins_js_for :foreman_leapp %>
|
3
|
+
<% end %>
|
4
|
+
<% content_for(:stylesheets) do %>
|
5
|
+
<%= webpacked_plugins_css_for :foreman_leapp %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%= react_component('PreupgradeReports', {
|
9
|
+
:url => preupgrade_reports_path(:search => "job_invocation_id = #{@job_invocation.id}")
|
10
|
+
}) %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.routes.draw do
|
4
|
+
resources :preupgrade_reports, :only => %i[index]
|
5
|
+
|
6
|
+
namespace :api, defaults: { format: 'json' } do
|
7
|
+
scope '(:apiv)', module: :v2, defaults: { apiv: 'v2'}, apiv: /v2/, constraints: ApiConstraints.new( version: 2, default: true) do
|
8
|
+
resources :preupgrade_reports, only: %i[index show]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class PreupgradeReportEntries < ActiveRecord::Migration[5.2]
|
2
|
+
def up
|
3
|
+
create_table :preupgrade_report_entries do |t|
|
4
|
+
t.integer :preupgrade_report_id, null: false
|
5
|
+
t.string :hostname, null: false
|
6
|
+
t.string :title, null: false
|
7
|
+
t.string :actor, null: false
|
8
|
+
t.string :audience, null: false
|
9
|
+
t.string :severity, null: false
|
10
|
+
t.string :leapp_run_id, null: false
|
11
|
+
t.text :summary
|
12
|
+
t.text :tags
|
13
|
+
t.text :detail
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index :preupgrade_report_entries, :preupgrade_report_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def down
|
22
|
+
remove_index :preupgrade_report_entries, :preupgrade_report_id
|
23
|
+
drop_table :preupgrade_report_entries
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
organizations = Organization.unscoped.all
|
4
|
+
locations = Location.unscoped.all
|
5
|
+
User.as_anonymous_admin do
|
6
|
+
RemoteExecutionFeature.without_auditing do
|
7
|
+
JobTemplate.without_auditing do
|
8
|
+
Dir[File.join("#{ForemanLeapp::Engine.root}/app/views/foreman_leapp/"\
|
9
|
+
'job_templates/**/*.erb')].each do |template|
|
10
|
+
template = JobTemplate.import_raw!(File.read(template),
|
11
|
+
:default => true,
|
12
|
+
:locked => true,
|
13
|
+
:update => true)
|
14
|
+
template.organizations = organizations if template.present?
|
15
|
+
template.locations = locations if template.present?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanLeapp
|
4
|
+
JOB_CATEGORY = 'Leapp'
|
5
|
+
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
engine_name 'foreman_leapp'
|
8
|
+
|
9
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
10
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/api/v2/concerns"]
|
11
|
+
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
12
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
13
|
+
config.autoload_paths += Dir["#{config.root}/app/overrides"]
|
14
|
+
config.autoload_paths += Dir["#{config.root}/app/lib/helpers"]
|
15
|
+
config.autoload_paths += Dir["#{config.root}/test/"]
|
16
|
+
|
17
|
+
# Add any db migrations
|
18
|
+
initializer 'foreman_leapp.load_app_instance_data' do |app|
|
19
|
+
ForemanLeapp::Engine.paths['db/migrate'].existent.each do |path|
|
20
|
+
app.config.paths['db/migrate'] << path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
initializer 'foreman_leapp.register_plugin', before: :finisher_hook do |_app|
|
25
|
+
Foreman::Plugin.register :foreman_leapp do
|
26
|
+
requires_foreman '>= 1.16'
|
27
|
+
|
28
|
+
extend_template_helpers ForemanLeapp::TemplateHelper
|
29
|
+
|
30
|
+
extend_page 'job_invocations/show' do |cx|
|
31
|
+
cx.add_pagelet :main_tabs,
|
32
|
+
partial: 'job_invocations/leapp_preupgrade_report',
|
33
|
+
name: _('Leapp preupgrade report'),
|
34
|
+
id: 'leapp_preupgrade_report',
|
35
|
+
onlyif: proc { |subject| ::Helpers::JobHelper.correct_feature?(subject, 'leapp_preupgrade') }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Include concerns in this config.to_prepare block
|
41
|
+
config.to_prepare do
|
42
|
+
begin
|
43
|
+
HostsHelper.prepend ForemanLeapp::HostsHelperExtensions
|
44
|
+
Host::JobInvocation.include ForemanLeapp::JobInvocationExtensions
|
45
|
+
rescue StandardError => e
|
46
|
+
Rails.logger.warn "ForemanLeapp: skipping engine hook (#{e})"
|
47
|
+
end
|
48
|
+
|
49
|
+
RemoteExecutionFeature.register(
|
50
|
+
:leapp_preupgrade,
|
51
|
+
N_('Preupgrade check with Leapp'),
|
52
|
+
description: N_('Upgradeability check for RHEL 7 host'),
|
53
|
+
host_action_button: false
|
54
|
+
)
|
55
|
+
|
56
|
+
RemoteExecutionFeature.register(
|
57
|
+
:leapp_upgrade,
|
58
|
+
N_('Upgrade with Leapp'),
|
59
|
+
description: N_('Run Leapp upgrade job for RHEL 7 host'),
|
60
|
+
host_action_button: false
|
61
|
+
)
|
62
|
+
|
63
|
+
RemoteExecutionFeature.register(
|
64
|
+
:leapp_remediation_plan,
|
65
|
+
N_('Remediation plan'),
|
66
|
+
description: N_('Run Remediation plan with Leapp'),
|
67
|
+
host_action_button: false
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
rake_tasks do
|
72
|
+
Rake::Task['db:seed'].enhance do
|
73
|
+
ForemanLeapp::Engine.load_seed
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
initializer 'foreman_leapp.register_gettext', after: :load_config_initializers do |_app|
|
78
|
+
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
|
79
|
+
locale_domain = 'foreman_leapp'
|
80
|
+
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
81
|
+
end
|
82
|
+
|
83
|
+
initializer 'foreman_leapp.require_dynflow',
|
84
|
+
before: 'foreman_tasks.initialize_dynflow',
|
85
|
+
after: 'foreman_remote_execution.require_dynflow' do |_app|
|
86
|
+
ForemanTasks.dynflow.require!
|
87
|
+
ForemanTasks.dynflow.config.eager_load_paths << File.join(ForemanLeapp::Engine.root, 'app/lib/actions')
|
88
|
+
end
|
89
|
+
|
90
|
+
initializer('foreman_leapp.extend_remote_execution',
|
91
|
+
after: 'foreman_leapp.require_foreman_remote_execution') do |_app|
|
92
|
+
RemoteExecutionHelper.prepend ForemanLeapp::RemoteExecutionHelperExtension
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
# Tasks
|
6
|
+
namespace :foreman_leapp do
|
7
|
+
namespace :example do
|
8
|
+
desc 'Example Task'
|
9
|
+
task task: :environment do
|
10
|
+
# Task goes here
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Tests
|
16
|
+
namespace :test do
|
17
|
+
desc 'Test ForemanLeapp'
|
18
|
+
Rake::TestTask.new(:foreman_leapp) do |t|
|
19
|
+
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
20
|
+
t.libs << ['test', test_dir]
|
21
|
+
t.pattern = "#{test_dir}/**/*_test.rb"
|
22
|
+
t.verbose = true
|
23
|
+
t.warning = false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :foreman_leapp do
|
28
|
+
task :rubocop do
|
29
|
+
begin
|
30
|
+
require 'rubocop/rake_task'
|
31
|
+
RuboCop::RakeTask.new(:rubocop_foreman_leapp) do |task|
|
32
|
+
task.patterns = ["#{ForemanLeapp::Engine.root}/app/**/*.rb",
|
33
|
+
"#{ForemanLeapp::Engine.root}/lib/**/*.rb",
|
34
|
+
"#{ForemanLeapp::Engine.root}/test/**/*.rb"]
|
35
|
+
end
|
36
|
+
rescue StandardError
|
37
|
+
puts 'Rubocop not loaded.'
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::Task['rubocop_foreman_leapp'].invoke
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Rake::Task[:test].enhance ['test:foreman_leapp']
|
45
|
+
|
46
|
+
load 'tasks/jenkins.rake'
|
47
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
48
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_leapp', 'foreman_leapp:rubocop']
|
49
|
+
end
|
data/locale/Makefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for PO merging and MO generation. More info in the README.
|
3
|
+
#
|
4
|
+
# make all-mo (default) - generate MO files
|
5
|
+
# make check - check translations using translate-tool
|
6
|
+
# make tx-update - download and merge translations from Transifex
|
7
|
+
# make clean - clean everything
|
8
|
+
#
|
9
|
+
DOMAIN = foreman_leapp
|
10
|
+
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
|
11
|
+
POTFILE = $(DOMAIN).pot
|
12
|
+
MOFILE = $(DOMAIN).mo
|
13
|
+
POFILES = $(shell find . -name '$(DOMAIN).po')
|
14
|
+
MOFILES = $(patsubst %.po,%.mo,$(POFILES))
|
15
|
+
POXFILES = $(patsubst %.po,%.pox,$(POFILES))
|
16
|
+
EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
|
17
|
+
|
18
|
+
%.mo: %.po
|
19
|
+
mkdir -p $(shell dirname $@)/LC_MESSAGES
|
20
|
+
msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
|
21
|
+
|
22
|
+
# Generate MO files from PO files
|
23
|
+
all-mo: $(MOFILES)
|
24
|
+
|
25
|
+
# Check for malformed strings
|
26
|
+
%.pox: %.po
|
27
|
+
msgfmt -c $<
|
28
|
+
pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
|
29
|
+
-t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
|
30
|
+
cat $@
|
31
|
+
! grep -q msgid $@
|
32
|
+
|
33
|
+
%.edit.po:
|
34
|
+
touch $@
|
35
|
+
|
36
|
+
check: $(POXFILES)
|
37
|
+
|
38
|
+
# Unify duplicate translations
|
39
|
+
uniq-po:
|
40
|
+
for f in $(shell find ./ -name "*.po") ; do \
|
41
|
+
msguniq $$f -o $$f ; \
|
42
|
+
done
|
43
|
+
|
44
|
+
tx-pull: $(EDITFILES)
|
45
|
+
tx pull -f
|
46
|
+
for f in $(EDITFILES) ; do \
|
47
|
+
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
|
48
|
+
done
|
49
|
+
|
50
|
+
tx-update: tx-pull
|
51
|
+
@echo
|
52
|
+
@echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
|
53
|
+
@echo
|
54
|
+
|
55
|
+
mo-files: $(MOFILES)
|
56
|
+
git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
|
57
|
+
git commit -m "i18n - pulling from tx"
|
58
|
+
@echo
|
59
|
+
@echo Changes commited!
|
60
|
+
@echo
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# foreman_leapp
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_leapp.
|
4
|
+
#
|
5
|
+
#, fuzzy
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: version 0.0.1\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
|
11
|
+
"PO-Revision-Date: 2014-08-20 08:54+0100\n"
|
12
|
+
"Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
|
13
|
+
"Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
|
14
|
+
"Language: \n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
19
|
+
|