foreman_puppet 6.0.1 → 6.1.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: 9ddb41ece0ec9add7b77e958a35fe39da8ff7588a7cd6bb0900a09bbc5a9853b
4
- data.tar.gz: 5054407779deb586f36b4af5ef98a21031511c3f195d8365a2525fe2a5668de8
3
+ metadata.gz: 68939e16cae1564207cb39add5c7fec7cac4e94c8ebf118dc61621197907a745
4
+ data.tar.gz: 5058a3df645b3c30aa9d0845b47c7a07286fa1c87aa261b582a6153e1533965b
5
5
  SHA512:
6
- metadata.gz: c6c095009c3211f066ac1966190edf4598715c636a176ae824eccf3218f85a606c88f89672dd4cb4e6154b9b9a4fe58255e1799f214a5df8848b9e6a6656266d
7
- data.tar.gz: a3711124b1bfc9659070261f9a8aaa4ba4a6de3dc2c021967f80d481b29b35a582b12153ad27cc7a7d32c887c3733ef1550edcad43ee37054640b351250ee219
6
+ metadata.gz: d03b3cf704fb1c44d598f2cdd07f0eb4a42bcbd5f588083b8c47ae8ac91f3c60ed809104321f4942f2adfa4601126883dc973cb9181bcd469136f94c1ccdc748
7
+ data.tar.gz: 10dceada6b636553d2b29ca4e7e76965e6235ba3227765e0a71ea1144d86d09e332ae2aab22c22d3554f81cef933c50a8d2979d818234ff261588b3cdd8736cd
@@ -13,8 +13,6 @@ module ForemanPuppet
13
13
  include_in_clone puppet: %i[config_groups host_config_groups host_classes]
14
14
 
15
15
  scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
16
- scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '],
17
- ext_method: :search_by_deprecated_class
18
16
  scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ '],
19
17
  ext_method: :search_by_puppetclass
20
18
  scoped_search relation: :config_groups, on: :name, complete_value: true, rename: :config_group, only_explicit: true, operators: ['= ', '~ '],
@@ -22,11 +20,6 @@ module ForemanPuppet
22
20
  end
23
21
 
24
22
  class_methods do
25
- def search_by_deprecated_class(key, operator, value)
26
- Foreman::Deprecation.deprecation_warning('3.2', 'search by `class` has been deprecated, please search by `puppetclass` instead')
27
- search_by_puppetclass(key, operator, value)
28
- end
29
-
30
23
  def search_by_puppetclass(_key, operator, value)
31
24
  conditions = sanitize_sql_for_conditions(["puppetclasses.name #{operator} ?", value_to_sql(operator, value)])
32
25
  config_group_ids = ForemanPuppet::ConfigGroup.joins(:puppetclasses).where(conditions).pluck(:id)
@@ -16,7 +16,12 @@ module ForemanPuppet
16
16
 
17
17
  # will need through relation to work properly
18
18
  scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true
19
- scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']
19
+ scoped_search relation: :puppetclasses, on: :name,
20
+ complete_value: true,
21
+ rename: :puppetclass,
22
+ only_explicit: true,
23
+ operators: ['= ', '~ '],
24
+ ext_method: :search_by_puppetclass
20
25
  scoped_search relation: :config_groups, on: :name,
21
26
  complete_value: true,
22
27
  rename: :config_group,
@@ -29,11 +34,22 @@ module ForemanPuppet
29
34
  module PatchedClassMethods
30
35
  def search_by_config_group(_key, operator, value)
31
36
  conditions = sanitize_sql_for_conditions(["config_groups.name #{operator} ?", value_to_sql(operator, value)])
32
- hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :config_groups).where(conditions).map(&:subtree_ids).flatten.uniq
37
+ hostgroup_ids = ::Hostgroup.joins(puppet: :config_groups).where(conditions).map(&:subtree_ids).flatten.uniq
38
+
39
+ conds = 'hostgroups.id < 0'
40
+ conds = "hostgroups.id IN(#{hostgroup_ids.join(',')})" if hostgroup_ids.present?
41
+
42
+ { conditions: conds }
43
+ end
44
+
45
+ def search_by_puppetclass(_key, operator, value)
46
+ conditions = sanitize_sql_for_conditions(["puppetclasses.name #{operator} ?", value_to_sql(operator, value)])
47
+ hostgroup_ids = ::Hostgroup.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids)
48
+
49
+ conds = []
50
+ conds << "hostgroups.id IN (#{hostgroup_ids.join(',')})" if hostgroup_ids.present?
33
51
 
34
- opts = 'hostgroups.id < 0'
35
- opts = "hostgroups.id IN(#{hostgroup_ids.join(',')})" if hostgroup_ids.present?
36
- { conditions: opts }
52
+ { conditions: conds.join(' OR ').presence || 'hostgroups.id < 0' }
37
53
  end
38
54
  end
39
55
  end
@@ -17,7 +17,7 @@ module ForemanPuppet
17
17
  validates :name, presence: true, uniqueness: true
18
18
 
19
19
  scoped_search on: :name, complete_value: true
20
- scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']
20
+ scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ ']
21
21
 
22
22
  default_scope -> { order('config_groups.name') }
23
23
 
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '6.0.1'.freeze
2
+ VERSION = '6.1.0'.freeze
3
3
  end
@@ -48,23 +48,31 @@ module ForemanPuppet
48
48
  assert_equal results, results2
49
49
  end
50
50
 
51
+ test 'deprecated search by class throws error' do
52
+ exception = assert_raises(Exception) do
53
+ host
54
+ Host.search_for("class = #{host.puppet.puppetclass_names.first}")
55
+ end
56
+ assert_equal("Field 'class' not recognized for searching!", exception.message)
57
+ end
58
+
51
59
  test 'can be found by puppetclass' do
52
60
  host
53
- result = Host.search_for("class = #{host.puppet.puppetclass_names.first}")
61
+ result = Host.search_for("puppetclass = #{host.puppet.puppetclass_names.first}")
54
62
  assert_includes result, host
55
63
  end
56
64
 
57
65
  test 'search by puppetclass returns only host within that puppetclass' do
58
66
  host
59
67
  puppetclass = FactoryBot.create(:puppetclass)
60
- result = Host.search_for("class = #{puppetclass.name}")
68
+ result = Host.search_for("puppetclass = #{puppetclass.name}")
61
69
  assert_not_includes result, host
62
70
  end
63
71
 
64
72
  test 'search hosts by inherited puppetclass from a hostgroup' do
65
73
  hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
66
74
  host_with_hg = FactoryBot.create(:host, hostgroup: hostgroup)
67
- result = Host.search_for("class = #{hostgroup.puppet.puppetclass_names.first}")
75
+ result = Host.search_for("puppetclass = #{hostgroup.puppet.puppetclass_names.first}")
68
76
  assert_includes result, host_with_hg
69
77
  end
70
78
 
@@ -72,7 +80,7 @@ module ForemanPuppet
72
80
  parent_hg = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
73
81
  hg = FactoryBot.create(:hostgroup, parent: parent_hg)
74
82
  host = FactoryBot.create(:host, hostgroup: hg)
75
- result = Host.search_for("class = #{parent_hg.puppet.puppetclass_names.first}")
83
+ result = Host.search_for("puppetclass = #{parent_hg.puppet.puppetclass_names.first}")
76
84
  assert_equal 1, result.count
77
85
  assert_includes result, host
78
86
  end
@@ -82,7 +90,7 @@ module ForemanPuppet
82
90
  host = FactoryBot.create(:host, :with_puppet_enc, hostgroup: hostgroup, environment: hostgroup.puppet.environment)
83
91
  config_group = FactoryBot.create(:config_group, :with_puppetclass)
84
92
  hostgroup.puppet.config_groups << config_group
85
- result = Host.search_for("class = #{config_group.puppetclass_names.first}")
93
+ result = Host.search_for("puppetclass = #{config_group.puppetclass_names.first}")
86
94
  assert_equal 1, result.count
87
95
  assert_includes result, host
88
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-08-10 00:00:00.000000000 Z
12
+ date: 2023-09-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environments and classes to the Foreman Hosts.
15
15
  email: