foreman_git_templates 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c38324b0492c54b19ee28e823d91e8f18b6d1427f477710e6516544115b7b1a
4
- data.tar.gz: 1317ddbf95b8fb0b3601494828e3a6658bdad95a1b656b567edf7617a17378f7
3
+ metadata.gz: 0477f8453ecbee80aeacc47eca0a8d15e4dfab4c7416a342834682523fe8d620
4
+ data.tar.gz: 812f5d9a1d5aefce8dfd3fce7c89232c406381d5fcdf1220bf3b949f5efb2e25
5
5
  SHA512:
6
- metadata.gz: a47d11977a3bbf7a2b86d409ae75a42045c932a96191aa0c4384890171d071588aa26682ef5e75ba889bd64f119ec9ab039d9940a06c524adb9b8d0735d86566
7
- data.tar.gz: '054158b459f6a48992f170a3f6f39e54d500a18aef4d4eab1b2c151901cc3ca1e449b2c1cc13cc1ac2d87b09ac464ae08d81817a550cbd0d471931594f69933a'
6
+ metadata.gz: 3802a1eb148d653a55052f10c87ac215ae044b1b0d883038a75e7c22834ec91df1c4d9ec1f4835e86fa3b68c9a77f89c2e707fa301a9984ae9eb00ae2d4fc531
7
+ data.tar.gz: 70bd0c85037c17da83cb239a6844d34ccb0fdbb1e4651ab0d6dc8928d7d246bd86dee234c280b97e764221cbde4888890e43047d5137aa9b9ae9f1e58cb1e8b3
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanGitTemplates
4
+ module UnattendedControllerExtensions
5
+ extend ActiveSupport::Concern
6
+
7
+ module Overrides
8
+ def render_local_boot_template
9
+ return super unless @host&.repository_path
10
+
11
+ return unless verify_found_host
12
+
13
+ template = ForemanGitTemplates::DefaultLocalBootRepositoryTemplate.new(name: 'iPXE')
14
+ safe_render(template)
15
+ rescue ForemanGitTemplates::RepositoryReader::MissingFileError
16
+ render_ipxe_message(message: _('iPXE default local boot template not found in repository at templates/iPXE/default_local_boot.erb'))
17
+ end
18
+ end
19
+
20
+ included do
21
+ prepend Overrides
22
+ end
23
+ end
24
+ end
@@ -3,9 +3,21 @@
3
3
  module ForemanGitTemplates
4
4
  module HostExtensions
5
5
  def repository_path
6
- return unless host_params['template_url']
6
+ return unless git_template_url
7
7
 
8
- @repository_path ||= RepositoryFetcher.call(host_params['template_url'])
8
+ git_template_tmpfile.path
9
+ end
10
+
11
+ private
12
+
13
+ def git_template_url
14
+ @git_template_url ||= host_params['template_url']
15
+ end
16
+
17
+ def git_template_tmpfile
18
+ return unless git_template_url
19
+
20
+ @git_template_tmpfile ||= RepositoryFetcher.call(git_template_url)
9
21
  end
10
22
  end
11
23
  end
@@ -9,7 +9,7 @@ module ForemanGitTemplates
9
9
  end
10
10
 
11
11
  def call
12
- Down.download(repository_url).path
12
+ Down.download(repository_url)
13
13
  rescue Down::ResponseError => e
14
14
  raise RepositoryFetcherError, "Cannot fetch repository from #{repository_url}. Response code: #{e.response.code}"
15
15
  rescue Down::Error => e
@@ -6,6 +6,7 @@ module ForemanGitTemplates
6
6
 
7
7
  config.autoload_paths += Dir["#{config.root}/app/lib"]
8
8
  config.autoload_paths += Dir["#{config.root}/app/services"]
9
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
9
10
 
10
11
  initializer 'foreman_git_templates.register_plugin', before: :finisher_hook do |_app|
11
12
  Foreman::Plugin.register :foreman_git_templates do
@@ -19,6 +20,7 @@ module ForemanGitTemplates
19
20
  Host::Managed.include(ForemanGitTemplates::Hostext::OperatingSystem)
20
21
  Host::Managed.include(ForemanGitTemplates::HostExtensions)
21
22
  Nic::Managed.include(ForemanGitTemplates::Orchestration::TFTP)
23
+ UnattendedController.include(ForemanGitTemplates::UnattendedControllerExtensions)
22
24
  rescue StandardError => e
23
25
  Rails.logger.warn "ForemanGitTemplates: skipping engine hook (#{e})"
24
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanGitTemplates
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -3,7 +3,7 @@
3
3
  require 'test_plugin_helper'
4
4
 
5
5
  class UnattendedControllerTest < ActionController::TestCase
6
- let(:os) { FactoryBot.create(:operatingsystem, :with_archs, :with_ptables, type: 'Redhat') }
6
+ let(:os) { FactoryBot.create(:operatingsystem, :with_associations, type: 'Redhat') }
7
7
  let(:host) do
8
8
  FactoryBot.create(:host, :managed, :with_template_url, operatingsystem: os, ptable: os.ptables.first)
9
9
  end
@@ -68,4 +68,49 @@ class UnattendedControllerTest < ActionController::TestCase
68
68
  assert_equal 'foo bar', response.body.strip
69
69
  end
70
70
  end
71
+
72
+ describe 'iPXE templates' do
73
+ context 'host not in build mode' do
74
+ test 'should render iPXE local boot template from repository' do
75
+ assert_not_nil host.params['template_url']
76
+
77
+ Dir.mktmpdir do |dir|
78
+ kind = 'iPXE'
79
+
80
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
81
+ tar.add_file_simple("templates/#{kind}/default_local_boot.erb", 644, 5) { |io| io.write('local') }
82
+ tar.add_file_simple("templates/#{kind}/template.erb", 644, host.name.length) { |io| io.write(host.name) }
83
+ end
84
+
85
+ get :host_template, params: { kind: kind, hostname: host.name }, session: set_session_user
86
+ assert_response :success
87
+ assert_equal 'local', response.body.strip
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'host in build mode' do
93
+ setup do
94
+ host.update!(build: true)
95
+ end
96
+
97
+ test 'should render iPXE template from repository' do
98
+ host.reload
99
+ assert_not_nil host.params['template_url']
100
+
101
+ Dir.mktmpdir do |dir|
102
+ kind = 'iPXE'
103
+
104
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
105
+ tar.add_file_simple("templates/#{kind}/default_local_boot.erb", 644, 5) { |io| io.write('local') }
106
+ tar.add_file_simple("templates/#{kind}/template.erb", 644, host.name.length) { |io| io.write(host.name) }
107
+ end
108
+
109
+ get :host_template, params: { kind: kind, hostname: host.name }, session: set_session_user
110
+ assert_response :success
111
+ assert_equal host.name, response.body.strip
112
+ end
113
+ end
114
+ end
115
+ end
71
116
  end
@@ -6,11 +6,12 @@ module ForemanGitTemplates
6
6
  class HostTest < ActiveSupport::TestCase
7
7
  describe '#repository_path' do
8
8
  context 'with template_url parameter' do
9
- let(:repo_path) { '/tmp/repo.tar.gz' }
9
+ let(:repo_tempfile) { Tempfile.new }
10
+ let(:repo_path) { repo_tempfile.path }
10
11
  let(:host) { FactoryBot.create(:host, :managed, :with_template_url) }
11
12
 
12
13
  it 'returns path to the repository' do
13
- ForemanGitTemplates::RepositoryFetcher.expects(:call).once.with(host.params['template_url']).returns(repo_path)
14
+ ForemanGitTemplates::RepositoryFetcher.expects(:call).once.with(host.params['template_url']).returns(repo_tempfile)
14
15
  assert_equal repo_path, host.repository_path
15
16
  end
16
17
  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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dmTECH GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -62,6 +62,7 @@ files:
62
62
  - LICENSE
63
63
  - README.md
64
64
  - Rakefile
65
+ - app/controllers/concerns/foreman_git_templates/unattended_controller_extensions.rb
65
66
  - app/lib/foreman_git_templates/renderer.rb
66
67
  - app/lib/foreman_git_templates/renderer/source/repository.rb
67
68
  - app/lib/foreman_git_templates/tar.rb
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.7.3
114
+ rubygems_version: 2.7.6.2
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: Adds support for using templates from Git repositories