foreman_git_templates 1.0.0 → 1.0.1

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: f37d8fd9a09c475e1e544c46d1d17d52b928d1dbdb8f37a77c83e4e45aafb026
4
- data.tar.gz: 4dca8880532ee1fcd6d5b28d45896bd922505841e68af7945e2115f3b51de16a
3
+ metadata.gz: 9c38324b0492c54b19ee28e823d91e8f18b6d1427f477710e6516544115b7b1a
4
+ data.tar.gz: 1317ddbf95b8fb0b3601494828e3a6658bdad95a1b656b567edf7617a17378f7
5
5
  SHA512:
6
- metadata.gz: 403f6ec203c8d2f1a9267249f9107d3323ec24c0e68a23420ec8f89b3a6d75fb091d25931fc2de6785b3b635c91ac97a6d48435a4678ff799f0968dee598e51f
7
- data.tar.gz: e13f00738e2878f7f7f102e9b5d4df745e3b54caa3aba7afe1c82b9ebd297415b4c5f9b634ddb0cb6b9764737acf60d76951d58f77aec261fa1eb76e86466397
6
+ metadata.gz: a47d11977a3bbf7a2b86d409ae75a42045c932a96191aa0c4384890171d071588aa26682ef5e75ba889bd64f119ec9ab039d9940a06c524adb9b8d0735d86566
7
+ data.tar.gz: '054158b459f6a48992f170a3f6f39e54d500a18aef4d4eab1b2c151901cc3ca1e449b2c1cc13cc1ac2d87b09ac464ae08d81817a550cbd0d471931594f69933a'
data/README.md CHANGED
@@ -44,6 +44,14 @@ From now the template content for this host will be fetched from the repository.
44
44
  - `There was an error rendering the provision template: Cannot read <template> from repository`
45
45
  - check if there is requested template in the repository
46
46
 
47
+ ### Gitlab Repository Integration
48
+
49
+ If you want to use a private repository hosted on a Gitlab instance to store your Foreman templates, you can use [Gitlab's repositories API](https://docs.gitlab.com/ee/api/repositories.html#get-file-archive) to construct the `template_url` parameter in Foreman. Create a dedicated Foreman user in Gitlab and set up a Personal Access Token that you can use in the `template_url`.
50
+
51
+ ```
52
+ https://gitlab.example.com/api/v4/projects/${GITLAB_PROJECT_ID}/repository/archive.tar.gz?sha=${GITLAB_BRANCH_NAME}&private_token=${PERSONAL_ACCESS_TOKEN}
53
+ ```
54
+
47
55
  ## Contributing
48
56
 
49
57
  Fork and send a Pull Request. Thanks!
@@ -9,7 +9,7 @@ module ForemanGitTemplates
9
9
  def provisioning_template(opts = {})
10
10
  return super unless repository_path
11
11
 
12
- kind = opts[:kind] || 'provision'
12
+ kind = opts[:kind].to_s || 'provision'
13
13
  available_template_kinds.find { |template| template.name == kind }
14
14
  end
15
15
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanGitTemplates
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -6,6 +6,28 @@ module Hostext
6
6
  class OperatingSystemTest < ActiveSupport::TestCase
7
7
  let(:host) { FactoryBot.create(:host, :managed, :with_template_url) }
8
8
 
9
+ describe '#provisioning_template' do
10
+ it 'finds all PXELinux template kinds' do
11
+ Dir.mktmpdir do |dir|
12
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
13
+ tar.add_file_simple('templates/PXELinux/template.erb', 644, host.name.length) { |io| io.write(host.name) }
14
+ end
15
+
16
+ assert_equal 'PXELinux', host.provisioning_template(kind: 'PXELinux')&.name
17
+ end
18
+ end
19
+
20
+ it 'finds all PXELinux template kinds by symbol' do
21
+ Dir.mktmpdir do |dir|
22
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
23
+ tar.add_file_simple('templates/PXELinux/template.erb', 644, host.name.length) { |io| io.write(host.name) }
24
+ end
25
+
26
+ assert_equal 'PXELinux', host.provisioning_template(kind: :PXELinux)&.name
27
+ end
28
+ end
29
+ end
30
+
9
31
  test 'available_template_kinds finds only templates that are defined in the repository' do
10
32
  Dir.mktmpdir do |dir|
11
33
  expected_kinds = ['PXEGrub', 'PXELinux', 'iPXE', 'PXEGrub2', 'provision']
@@ -62,8 +62,47 @@ class TFTPOrchestrationTest < ActiveSupport::TestCase
62
62
  end
63
63
  end
64
64
 
65
+ describe '#validate_tftp' do
66
+ let(:host) { FactoryBot.create(:host, :with_tftp_orchestration, :with_template_url, pxe_loader: 'PXELinux BIOS') }
67
+ let(:kind) { 'PXELinux' }
68
+ let(:template_content) { 'main template content' }
69
+ let(:default_local_boot_template_content) { 'default local boot template content' }
70
+
71
+ context 'host is in build mode' do
72
+ setup do
73
+ host.update(build: true)
74
+ end
75
+
76
+ it 'validates that the host is ready for tftp' do
77
+ Dir.mktmpdir do |dir|
78
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
79
+ tar.add_file_simple("templates/#{kind}/template.erb", 644, template_content.length) { |io| io.write(template_content) }
80
+ tar.add_file_simple("templates/#{kind}/default_local_boot.erb", 644, default_local_boot_template_content.length) { |io| io.write(default_local_boot_template_content) }
81
+ end
82
+
83
+ host.provision_interface.send(:validate_tftp)
84
+ assert_empty host.errors.messages
85
+ end
86
+ end
87
+ end
88
+
89
+ context 'host is not build mode' do
90
+ it 'validates that the host is ready for tftp' do
91
+ Dir.mktmpdir do |dir|
92
+ stub_repository host.params['template_url'], "#{dir}/repo.tar.gz" do |tar|
93
+ tar.add_file_simple("templates/#{kind}/template.erb", 644, template_content.length) { |io| io.write(template_content) }
94
+ tar.add_file_simple("templates/#{kind}/default_local_boot.erb", 644, default_local_boot_template_content.length) { |io| io.write(default_local_boot_template_content) }
95
+ end
96
+
97
+ host.provision_interface.send(:validate_tftp)
98
+ assert_empty host.errors.messages
99
+ end
100
+ end
101
+ end
102
+ end
103
+
65
104
  describe '#setTFTP' do
66
- let(:host) { FactoryBot.create(:host, :with_tftp_orchestration, :with_template_url) }
105
+ let(:host) { FactoryBot.create(:host, :with_tftp_orchestration, :with_template_url, pxe_loader: 'PXELinux BIOS') }
67
106
 
68
107
  let(:kind) { 'PXELinux' }
69
108
  let(:template_content) { 'main template content' }
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.0
4
+ version: 1.0.1
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-03-04 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down