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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbf9d232426c55fc207fed30c696a03c1268f02df5d481daf7bbaec627867a8b
4
- data.tar.gz: b4e30338ca588f25c2ef0f74d383aa432357c5f94f9fae2603445107c55ae382
3
+ metadata.gz: 8e1266d987eb1c009c18ccbcb3d3b7c93da09b277465cead1fce9436bb7547d4
4
+ data.tar.gz: 88fe5230bca03cdef1808dd28d8f1778e7942db64b1b8716726f7d744cac9136
5
5
  SHA512:
6
- metadata.gz: 965c2c192b549c92c474af2d6074a837e8f2ef9fe1241394f083ac519730aaab34732e3ccc99897c8521e97195dc81ab6cc5517f96f5aaa5b4dff4b326ce3209
7
- data.tar.gz: 59434c38a0e0a3da2d63160ccebf1d06b08b6b3907df95455ba8229821d1302c7cad7471adae8e44e72c88c98a8265ab4efc88e27f599493b3ae761b40fbdd93
6
+ metadata.gz: 937af6365b281ddd5cfc5131d7d4251c3d377bf13fa87e37329345e9dd69368ffbdf855cc26a1a11b937a81f9b9347d0a51ecf5e260d147855c04a59058fda58
7
+ data.tar.gz: 6d618171ba97d86e839d849dcac811f3ce6d42e92f5338c0f9cacf7010be3168fcc6422ec22ce37d83ce25f786fd649f9a97c6fb42cc64c5fdc02963b2f04cdd
data/README.md CHANGED
@@ -20,6 +20,7 @@ See Foreman's [plugin installation documentation](https://theforeman.org/plugins
20
20
  | >= 1.16 | 4.0.1 |
21
21
  | >= 1.16 | 5.0.0 |
22
22
  | >= 2.2.0 | 6.0.0 |
23
+ | >= 3.0 | 7.0.0 |
23
24
 
24
25
  ## Usage
25
26
 
@@ -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
- initializer "foreman_default_hostgroup.load_default_settings",
10
- before: :load_config_initializers do
11
- require_dependency File.expand_path(
12
- "../../app/models/setting/default_hostgroup.rb", __dir__
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 ">= 2.2"
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
 
@@ -1,3 +1,3 @@
1
1
  module ForemanDefaultHostgroup
2
- VERSION = '6.0.0'.freeze
2
+ VERSION = '7.0.0'.freeze
3
3
  end
@@ -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::DefaultHostgroup')
21
+ category: 'Setting')
22
22
  FactoryBot.create(:setting,
23
23
  name: 'force_hostgroup_match_only_new',
24
- category: 'Setting::DefaultHostgroup')
24
+ category: 'Setting')
25
25
  FactoryBot.create(:setting,
26
26
  name: 'force_host_environment',
27
- category: 'Setting::DefaultHostgroup')
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, :with_environment, name: 'Test Default')
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: 6.0.0
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: 2021-05-26 00:00:00.000000000 Z
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
- - app/models/setting/default_hostgroup.rb
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.0.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