foreman_git_templates 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/foreman_git_templates/application_helper.rb +23 -0
- data/app/lib/foreman_git_templates/renderer.rb +10 -2
- data/app/services/foreman_git_templates/repository_reader.rb +2 -0
- data/lib/foreman_git_templates/engine.rb +1 -0
- data/lib/foreman_git_templates/version.rb +1 -1
- data/lib/tasks/foreman_git_templates_tasks.rake +3 -30
- data/test/models/concerns/foreman_git_templates/orchestration/tftp_test.rb +2 -0
- data/test/models/foreman_git_templates/host_test.rb +19 -4
- data/test/unit/foreman/renderer_test.rb +40 -0
- metadata +28 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef1542116b039a0e33811e4eaa3c65b3c05da618735f47f9f30fe5dd9b243599
|
4
|
+
data.tar.gz: fbbd7adb1894aac45862a92653cc2e84667a1ea14a19c2a1e17ab44d882e6358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba5ffceb6a9049d268589824b73bcf9c1d135d05db12242e08473abe3a2aa47fe4aa21129baf27e646e42d1ce7cddad8d7272b23d173c8a3bb82a75d64dec43
|
7
|
+
data.tar.gz: 9539d07fd4eee73f05d467a5a5f3e2b83d3ff34337b155a96913c53cc69006b25840010d07df79b90ae2f0d219a986e341d094bc4c06b3b80b89525d28938fab
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanGitTemplates
|
4
|
+
module ApplicationHelper
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module Overrides
|
8
|
+
def display_link_if_authorized(name, options = {}, html_options = {})
|
9
|
+
# rubocop:disable Rails/HelperInstanceVariable
|
10
|
+
|
11
|
+
return if @host&.repository_path && options[:use_route] == 'edit_provisioning_template'
|
12
|
+
|
13
|
+
# rubocop:enable Rails/HelperInstanceVariable
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
included do
|
20
|
+
prepend Overrides
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,14 +2,22 @@
|
|
2
2
|
|
3
3
|
module ForemanGitTemplates
|
4
4
|
module Renderer
|
5
|
-
|
5
|
+
REPOSITORY_SOURCE_CLASS = ForemanGitTemplates::Renderer::Source::Repository
|
6
|
+
|
7
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
8
|
+
def get_source(klass: nil, template:, **args)
|
9
|
+
return super if klass && klass != REPOSITORY_SOURCE_CLASS
|
10
|
+
|
6
11
|
repository_path = repository_path(args[:host])
|
7
12
|
if repository_path
|
8
|
-
|
13
|
+
REPOSITORY_SOURCE_CLASS.new(template, repository_path)
|
14
|
+
elsif !repository_path && Gem::Version.new(SETTINGS[:version].version) < Gem::Version.new('1.23')
|
15
|
+
super(klass: klass || Foreman::Renderer::Source::Database, template: template, **args)
|
9
16
|
else
|
10
17
|
super
|
11
18
|
end
|
12
19
|
end
|
20
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
13
21
|
|
14
22
|
private
|
15
23
|
|
@@ -9,6 +9,7 @@ module ForemanGitTemplates
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
raise MissingFileError, "The #{file} file is missing" if content.nil?
|
12
|
+
|
12
13
|
content
|
13
14
|
end
|
14
15
|
|
@@ -30,6 +31,7 @@ module ForemanGitTemplates
|
|
30
31
|
@content ||= Tar.untar(repository_path) do |tar|
|
31
32
|
return tar.each do |entry|
|
32
33
|
next unless entry.file? && entry.full_name.end_with?(file)
|
34
|
+
|
33
35
|
break entry.read.tap do |entry_content|
|
34
36
|
raise EmptyFileError, "The #{file} file is empty" if entry_content.nil?
|
35
37
|
end
|
@@ -30,6 +30,7 @@ module ForemanGitTemplates
|
|
30
30
|
HostParameter.include(ForemanGitTemplates::HostParameterExtensions)
|
31
31
|
Nic::Managed.include(ForemanGitTemplates::Orchestration::TFTP)
|
32
32
|
UnattendedController.include(ForemanGitTemplates::UnattendedControllerExtensions)
|
33
|
+
::ApplicationHelper.include(ForemanGitTemplates::ApplicationHelper)
|
33
34
|
rescue StandardError => e
|
34
35
|
Rails.logger.warn "ForemanGitTemplates: skipping engine hook (#{e})"
|
35
36
|
end
|
@@ -2,46 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
|
5
|
-
# Tasks
|
6
|
-
namespace :foreman_git_templates 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
5
|
# Tests
|
16
6
|
namespace :test do
|
17
7
|
desc 'Test ForemanGitTemplates'
|
18
8
|
Rake::TestTask.new(:foreman_git_templates) do |t|
|
19
|
-
test_dir = File.join(
|
9
|
+
test_dir = File.join(ForemanGitTemplates::Engine.root, 'test')
|
20
10
|
t.libs << ['test', test_dir]
|
21
|
-
t.pattern =
|
11
|
+
t.pattern = File.join(test_dir, '**', '*_test.rb')
|
22
12
|
t.verbose = true
|
23
13
|
t.warning = false
|
24
14
|
end
|
25
15
|
end
|
26
16
|
|
27
|
-
namespace :foreman_git_templates do
|
28
|
-
task :rubocop do
|
29
|
-
begin
|
30
|
-
require 'rubocop/rake_task'
|
31
|
-
RuboCop::RakeTask.new(:rubocop_foreman_git_templates) do |task|
|
32
|
-
task.patterns = ["#{ForemanGitTemplates::Engine.root}/app/**/*.rb",
|
33
|
-
"#{ForemanGitTemplates::Engine.root}/lib/**/*.rb",
|
34
|
-
"#{ForemanGitTemplates::Engine.root}/test/**/*.rb"]
|
35
|
-
end
|
36
|
-
rescue StandardError
|
37
|
-
puts 'Rubocop not loaded.'
|
38
|
-
end
|
39
|
-
|
40
|
-
Rake::Task['rubocop_foreman_git_templates'].invoke
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
17
|
Rake::Task[:test].enhance ['test:foreman_git_templates']
|
45
18
|
|
46
19
|
load 'tasks/jenkins.rake'
|
47
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_git_templates'
|
20
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_git_templates'] if Rake::Task.task_defined?(:'jenkins:unit')
|
@@ -65,6 +65,7 @@ class TFTPOrchestrationTest < ActiveSupport::TestCase
|
|
65
65
|
|
66
66
|
context 'host is in build mode' do
|
67
67
|
setup do
|
68
|
+
host.primary_interface.expects(:valid?).returns(true) if Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('2.0')
|
68
69
|
host.update(build: true)
|
69
70
|
end
|
70
71
|
|
@@ -105,6 +106,7 @@ class TFTPOrchestrationTest < ActiveSupport::TestCase
|
|
105
106
|
|
106
107
|
context 'host is in build mode' do
|
107
108
|
setup do
|
109
|
+
host.primary_interface.expects(:valid?).returns(true) if Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('2.0')
|
108
110
|
host.update(build: true)
|
109
111
|
end
|
110
112
|
|
@@ -34,12 +34,23 @@ module ForemanGitTemplates
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with valid template_url' do
|
37
|
+
setup do
|
38
|
+
ProxyAPI::TFTP.any_instance.expects(:set).returns(true)
|
39
|
+
|
40
|
+
if Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('2.0')
|
41
|
+
ProxyAPI::TFTP.any_instance.expects(:bootServer).returns('127.0.0.1')
|
42
|
+
ProxyAPI::DHCP.any_instance.expects(:set).returns(true)
|
43
|
+
ProxyAPI::DHCP.any_instance.expects(:record).with(host.subnet.network, host.dhcp_records.first.mac).returns(host.dhcp_records.first)
|
44
|
+
ProxyAPI::DHCP.any_instance.expects(:records_by_ip).with(host.subnet.network, host.provision_interface.ip).returns([host.dhcp_records.first])
|
45
|
+
ProxyAPI::DHCP.any_instance.expects(:delete).returns(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
context 'when host is in build mode' do
|
38
50
|
let(:host) { FactoryBot.create(:host, :with_tftp_orchestration, :with_template_url, operatingsystem: os, build: true) }
|
39
51
|
|
40
52
|
it 'updates the host' do
|
41
|
-
ProxyAPI::
|
42
|
-
ProxyAPI::TFTP.any_instance.stubs(:fetch_boot_file).returns(true)
|
53
|
+
ProxyAPI::TFTP.any_instance.expects(:fetch_boot_file).twice.returns(true)
|
43
54
|
|
44
55
|
Dir.mktmpdir do |dir|
|
45
56
|
stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
|
@@ -56,8 +67,6 @@ module ForemanGitTemplates
|
|
56
67
|
let(:host) { FactoryBot.create(:host, :with_tftp_orchestration, :with_template_url, operatingsystem: os, build: false) }
|
57
68
|
|
58
69
|
it 'updates the host' do
|
59
|
-
ProxyAPI::TFTP.any_instance.stubs(:set).returns(true)
|
60
|
-
|
61
70
|
Dir.mktmpdir do |dir|
|
62
71
|
stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
|
63
72
|
tar.add_file_simple('templates/PXEGrub2/default_local_boot.erb', 644, host.name.length) { |io| io.write(host.name) }
|
@@ -73,6 +82,12 @@ module ForemanGitTemplates
|
|
73
82
|
context 'with invalid template_url' do
|
74
83
|
setup do
|
75
84
|
stub_request(:get, host.params['template_url']).to_return(status: 404)
|
85
|
+
|
86
|
+
if Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('2.0')
|
87
|
+
ProxyAPI::TFTP.any_instance.expects(:bootServer).returns('127.0.0.1')
|
88
|
+
ProxyAPI::DHCP.any_instance.expects(:record).with(host.subnet.network, host.dhcp_records.first.mac).returns(host.dhcp_records.first)
|
89
|
+
ProxyAPI::DHCP.any_instance.expects(:records_by_ip).with(host.subnet.network, host.provision_interface.ip).returns([host.dhcp_records.first])
|
90
|
+
end
|
76
91
|
end
|
77
92
|
|
78
93
|
let(:expected_errors) { ["No PXEGrub2 template was found for host #{host.name}. Repository url: #{host.params['template_url']}"] }
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
class RendererTest < ActiveSupport::TestCase
|
6
|
+
describe '.get_source' do
|
7
|
+
subject { Foreman::Renderer.get_source(template: template, host: host, klass: source_klass) }
|
8
|
+
|
9
|
+
let(:template) { FactoryBot.create(:provisioning_template) }
|
10
|
+
|
11
|
+
context 'when the host has a template_url defined' do
|
12
|
+
let(:host) { FactoryBot.create(:host, :with_template_url) }
|
13
|
+
|
14
|
+
context 'when the source class is not passed' do
|
15
|
+
let(:source_klass) { nil }
|
16
|
+
|
17
|
+
it 'uses ForemanGitTemplates::Renderer::Source::Repository' do
|
18
|
+
Dir.mktmpdir do |dir|
|
19
|
+
stub_repository host.params['template_url'], "#{dir}/repo.tar.gz"
|
20
|
+
|
21
|
+
assert_equal ForemanGitTemplates::Renderer::Source::Repository, subject.class
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the source class is implicitly passed' do
|
27
|
+
let(:source_klass) { Foreman::Renderer::Source::Database }
|
28
|
+
|
29
|
+
it { assert_equal Foreman::Renderer::Source::Database, subject.class }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when the host has no template_url defined' do
|
34
|
+
let(:host) { FactoryBot.create(:host) }
|
35
|
+
let(:source_klass) { nil }
|
36
|
+
|
37
|
+
it { assert_equal Foreman::Renderer::Source::Database, subject.class }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_git_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dmTECH GmbH
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -56,17 +56,31 @@ dependencies:
|
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
67
74
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
69
|
-
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
70
84
|
email:
|
71
85
|
- opensource@dm.de
|
72
86
|
executables: []
|
@@ -77,6 +91,7 @@ files:
|
|
77
91
|
- README.md
|
78
92
|
- Rakefile
|
79
93
|
- app/controllers/concerns/foreman_git_templates/unattended_controller_extensions.rb
|
94
|
+
- app/helpers/foreman_git_templates/application_helper.rb
|
80
95
|
- app/lib/foreman_git_templates/renderer.rb
|
81
96
|
- app/lib/foreman_git_templates/renderer/source/repository.rb
|
82
97
|
- app/lib/foreman_git_templates/tar.rb
|
@@ -106,13 +121,14 @@ files:
|
|
106
121
|
- test/models/foreman_git_templates/snippet_repository_template_test.rb
|
107
122
|
- test/test_plugin_helper.rb
|
108
123
|
- test/unit/foreman/renderer/source/repository_test.rb
|
124
|
+
- test/unit/foreman/renderer_test.rb
|
109
125
|
- test/unit/repository_fetcher_test.rb
|
110
126
|
- test/unit/repository_reader_test.rb
|
111
127
|
homepage: https://github.com/dm-drogeriemarkt/foreman_git_templates
|
112
128
|
licenses:
|
113
129
|
- GPL-3.0
|
114
130
|
metadata: {}
|
115
|
-
post_install_message:
|
131
|
+
post_install_message:
|
116
132
|
rdoc_options: []
|
117
133
|
require_paths:
|
118
134
|
- lib
|
@@ -127,13 +143,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
143
|
- !ruby/object:Gem::Version
|
128
144
|
version: '0'
|
129
145
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
-
signing_key:
|
146
|
+
rubygems_version: 3.1.2
|
147
|
+
signing_key:
|
132
148
|
specification_version: 4
|
133
149
|
summary: Adds support for using templates from Git repositories
|
134
150
|
test_files:
|
135
151
|
- test/unit/repository_fetcher_test.rb
|
136
152
|
- test/unit/foreman/renderer/source/repository_test.rb
|
153
|
+
- test/unit/foreman/renderer_test.rb
|
137
154
|
- test/unit/repository_reader_test.rb
|
138
155
|
- test/models/foreman_git_templates/snippet_repository_template_test.rb
|
139
156
|
- test/models/foreman_git_templates/host_test.rb
|