foreman_default_hostgroup 6.0.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/db/migrate/20221103122801_fix_default_hostgroup_settings_category_to_dsl.rb +9 -0
- data/lib/default_hostgroup_base_host_patch.rb +1 -1
- data/lib/foreman_default_hostgroup/engine.rb +23 -6
- data/lib/foreman_default_hostgroup/version.rb +1 -1
- data/test/unit/default_hostgroup_test.rb +4 -19
- metadata +5 -5
- data/app/models/setting/default_hostgroup.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1266d987eb1c009c18ccbcb3d3b7c93da09b277465cead1fce9436bb7547d4
|
4
|
+
data.tar.gz: 88fe5230bca03cdef1808dd28d8f1778e7942db64b1b8716726f7d744cac9136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937af6365b281ddd5cfc5131d7d4251c3d377bf13fa87e37329345e9dd69368ffbdf855cc26a1a11b937a81f9b9347d0a51ecf5e260d147855c04a59058fda58
|
7
|
+
data.tar.gz: 6d618171ba97d86e839d849dcac811f3ce6d42e92f5338c0f9cacf7010be3168fcc6422ec22ce37d83ce25f786fd649f9a97c6fb42cc64c5fdc02963b2f04cdd
|
data/README.md
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FixDefaultHostgroupSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
|
4
|
+
def up
|
5
|
+
# rubocop:disable Rails/SkipsModelValidations
|
6
|
+
Setting.where(category: 'Setting::DefaultHostgroup').update_all(category: 'Setting')
|
7
|
+
# rubocop:enable Rails/SkipsModelValidations
|
8
|
+
end
|
9
|
+
end
|
@@ -35,7 +35,7 @@ module DefaultHostgroupBaseHostPatch
|
|
35
35
|
return result unless new_hostgroup
|
36
36
|
|
37
37
|
self.host.hostgroup = new_hostgroup
|
38
|
-
self.host.environment = new_hostgroup.environment if Setting[:force_host_environment] == true
|
38
|
+
self.host.environment = new_hostgroup.environment if Setting[:force_host_environment] == true and facts[:_type] == :puppet
|
39
39
|
self.host.save(validate: false)
|
40
40
|
Rails.logger.info "DefaultHostgroupMatch: #{facts["hostname"]} added to #{new_hostgroup}"
|
41
41
|
|
@@ -6,17 +6,34 @@ module ForemanDefaultHostgroup
|
|
6
6
|
|
7
7
|
config.autoload_paths += Dir["#{config.root}/app/models"]
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
# Add any db migrations
|
10
|
+
initializer 'foreman_default_hostgroup.load_app_instance_data' do |app|
|
11
|
+
ForemanDefaultHostgroup::Engine.paths['db/migrate'].existent.each do |path|
|
12
|
+
app.config.paths['db/migrate'] << path
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
initializer "foreman_default_hostgroup.register_plugin",
|
17
17
|
before: :finisher_hook do
|
18
18
|
Foreman::Plugin.register :foreman_default_hostgroup do
|
19
|
-
requires_foreman ">=
|
19
|
+
requires_foreman ">= 3.0"
|
20
|
+
|
21
|
+
settings do
|
22
|
+
category(:default_hostgroup, N_('Default Hostgroup')) do
|
23
|
+
setting('force_hostgroup_match',
|
24
|
+
type: :boolean,
|
25
|
+
description: 'Apply hostgroup matching even if a host already has one.',
|
26
|
+
default: false)
|
27
|
+
setting('force_hostgroup_match_only_new',
|
28
|
+
type: :boolean,
|
29
|
+
description: 'Apply hostgroup matching only on new hosts',
|
30
|
+
default: true)
|
31
|
+
setting('force_host_environment',
|
32
|
+
type: :boolean,
|
33
|
+
description: "Apply hostgroup's environment to host even if a host already has a different one",
|
34
|
+
default: true)
|
35
|
+
end
|
36
|
+
end
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
@@ -18,20 +18,20 @@ class DefaultHostgroupTest < ActiveSupport::TestCase
|
|
18
18
|
# so we use FactoryBot to re-create it
|
19
19
|
FactoryBot.create(:setting,
|
20
20
|
name: 'force_hostgroup_match',
|
21
|
-
category: 'Setting
|
21
|
+
category: 'Setting')
|
22
22
|
FactoryBot.create(:setting,
|
23
23
|
name: 'force_hostgroup_match_only_new',
|
24
|
-
category: 'Setting
|
24
|
+
category: 'Setting')
|
25
25
|
FactoryBot.create(:setting,
|
26
26
|
name: 'force_host_environment',
|
27
|
-
category: 'Setting
|
27
|
+
category: 'Setting')
|
28
28
|
# Set the defaults
|
29
29
|
Setting[:force_hostgroup_match] = false
|
30
30
|
Setting[:force_hostgroup_match_only_new] = true
|
31
31
|
Setting[:force_host_environment] = true
|
32
32
|
|
33
33
|
# Mimic plugin config fron config file
|
34
|
-
FactoryBot.create(:hostgroup,
|
34
|
+
FactoryBot.create(:hostgroup, name: 'Test Default')
|
35
35
|
SETTINGS[:default_hostgroup] = {}
|
36
36
|
SETTINGS[:default_hostgroup][:facts_map] = {
|
37
37
|
'Test Default' => { 'hostname' => '.*' }
|
@@ -69,21 +69,6 @@ class DefaultHostgroupTest < ActiveSupport::TestCase
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context 'force host environment setting' do
|
73
|
-
test 'environment is updated if enabled' do
|
74
|
-
h = FactoryBot.create(:host, :with_environment, created_at: Time.current)
|
75
|
-
h.import_facts(@facts)
|
76
|
-
assert_equal Hostgroup.find_by(name: 'Test Default').environment, h.environment
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'environment not updated if disabled' do
|
80
|
-
Setting[:force_host_environment] = false
|
81
|
-
h = FactoryBot.create(:host, :with_environment, created_at: Time.current)
|
82
|
-
h.import_facts(@facts)
|
83
|
-
assert_not_equal Hostgroup.find_by(name: 'Test Default').environment, h.environment
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
72
|
context 'find_match' do
|
88
73
|
# takes a config map, returns a group or false
|
89
74
|
test 'match a single hostgroup' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_default_hostgroup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sutcliffe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Adds the option to specify a default hostgroup for new hosts created
|
14
14
|
from facts/reports
|
@@ -21,7 +21,7 @@ extra_rdoc_files:
|
|
21
21
|
files:
|
22
22
|
- LICENSE
|
23
23
|
- README.md
|
24
|
-
-
|
24
|
+
- db/migrate/20221103122801_fix_default_hostgroup_settings_category_to_dsl.rb
|
25
25
|
- default_hostgroup.yaml.example
|
26
26
|
- lib/default_hostgroup_base_host_patch.rb
|
27
27
|
- lib/foreman_default_hostgroup.rb
|
@@ -50,11 +50,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.3.26
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: Default Hostgroup Plugin for Foreman
|
57
57
|
test_files:
|
58
58
|
- test/test_plugin_helper.rb
|
59
|
-
- test/unit/facts.json
|
60
59
|
- test/unit/default_hostgroup_test.rb
|
60
|
+
- test/unit/facts.json
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
2
|
-
class Setting::DefaultHostgroup < ::Setting
|
3
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
4
|
-
BLANK_ATTRS << 'default_hostgroup'
|
5
|
-
|
6
|
-
def self.load_defaults
|
7
|
-
# Check the table exists
|
8
|
-
return unless ActiveRecord::Base.connection.table_exists?('settings')
|
9
|
-
return unless super
|
10
|
-
|
11
|
-
Setting.transaction do
|
12
|
-
[
|
13
|
-
set('force_hostgroup_match', 'Apply hostgroup matching even if a host already has one.', false),
|
14
|
-
set('force_hostgroup_match_only_new', 'Apply hostgroup matching only on new hosts', true),
|
15
|
-
set('force_host_environment', "Apply hostgroup's environment to host even if a host already has a different one", true)
|
16
|
-
].compact.each { |s| create s.update(category: 'Setting::DefaultHostgroup') }
|
17
|
-
end
|
18
|
-
|
19
|
-
true
|
20
|
-
end
|
21
|
-
end
|