foreman_puppet 1.0.1 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +4 -2
  3. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  4. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +41 -32
  5. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +42 -33
  6. data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +4 -0
  7. data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
  8. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +2 -0
  9. data/app/services/concerns/foreman_puppet/extensions/host_counter.rb +17 -0
  10. data/app/views/hosts/_form_puppet_enc_tab.html.erb +3 -4
  11. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -2
  12. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +36 -20
  13. data/db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb +10 -0
  14. data/lib/foreman_puppet/engine.rb +2 -0
  15. data/lib/foreman_puppet/version.rb +1 -1
  16. data/locale/cs_CZ/foreman_puppet.edit.po +1085 -0
  17. data/locale/cs_CZ/foreman_puppet.po.time_stamp +0 -0
  18. data/locale/en/foreman_puppet.edit.po +317 -162
  19. data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -52
  20. data/test/factories/host_puppet_enhancements.rb +3 -0
  21. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +70 -31
  22. data/test/models/foreman_puppet/host_puppet_facet_test.rb +7 -1
  23. data/test/services/foreman_puppet/host_counter_test.rb +17 -0
  24. data/webpack/src/Components/Environments/Welcome.js +2 -2
  25. metadata +11 -5
@@ -4,68 +4,88 @@ module ForemanPuppet
4
4
  class HostgroupsControllerTest < ActionController::TestCase
5
5
  tests ::HostgroupsController
6
6
 
7
- setup do
8
- @routes = ForemanPuppet::Engine.routes
7
+ context 'with core routes' do
8
+ describe '#nest' do
9
+ it 'works without puppetclasses' do
10
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
11
+
12
+ post :nest, params: { id: hostgroup.id }, session: set_session_user
13
+ assert_template 'new'
14
+ end
15
+
16
+ it 'works with puppetclasses' do
17
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
18
+
19
+ post :nest, params: { id: hostgroup.id }, session: set_session_user
20
+ assert_template 'new'
21
+ end
22
+ end
9
23
  end
10
24
 
11
- describe '#environment_selected' do
25
+ context 'with plugin routes' do
12
26
  setup do
13
- @environment = FactoryBot.create(:environment)
14
- @puppetclass = FactoryBot.create(:puppetclass)
15
- @hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment)
16
- @params = {
17
- id: @hostgroup.id,
18
- hostgroup: {
19
- name: @hostgroup.name,
20
- environment_id: '',
21
- puppetclass_ids: [@puppetclass.id],
22
- },
23
- }
27
+ @routes = ForemanPuppet::Engine.routes
24
28
  end
25
29
 
26
- test 'should return the selected puppet classes on environment change' do
27
- assert_equal 0, @hostgroup.puppet.puppetclasses.length
28
-
29
- post :environment_selected, params: @params, session: set_session_user, xhr: true
30
- assert_equal(1, assigns(:hostgroup).puppet.puppetclasses.length)
31
- assert_include assigns(:hostgroup).puppet.puppetclasses, @puppetclass
32
- end
30
+ describe '#environment_selected' do
31
+ setup do
32
+ @environment = FactoryBot.create(:environment)
33
+ @puppetclass = FactoryBot.create(:puppetclass)
34
+ @hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment)
35
+ @params = {
36
+ id: @hostgroup.id,
37
+ hostgroup: {
38
+ name: @hostgroup.name,
39
+ environment_id: '',
40
+ puppetclass_ids: [@puppetclass.id],
41
+ },
42
+ }
43
+ end
33
44
 
34
- context 'environment_id param is set' do
35
- test 'it will take the hostgroup params environment_id' do
36
- other_environment = FactoryBot.create(:environment)
37
- @params[:hostgroup][:environment_id] = other_environment.id
45
+ test 'should return the selected puppet classes on environment change' do
46
+ assert_equal 0, @hostgroup.puppet.puppetclasses.length
38
47
 
39
48
  post :environment_selected, params: @params, session: set_session_user, xhr: true
40
- assert_equal assigns(:environment), other_environment
49
+ assert_equal(1, assigns(:hostgroup).puppet.puppetclasses.length)
50
+ assert_include assigns(:hostgroup).puppet.puppetclasses, @puppetclass
41
51
  end
42
- end
43
52
 
44
- test 'should not escape lookup values on environment change' do
45
- hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment, puppetclasses: [@puppetclass])
46
- lookup_key = FactoryBot.create(:puppetclass_lookup_key, :array, default_value: %w[a b],
47
- override: true,
48
- puppetclass: @puppetclass,
49
- overrides: { "hostgroup=#{hostgroup.name}" => %w[c d] })
50
- lookup_value = lookup_key.lookup_values.first
51
- FactoryBot.create(:environment_class, puppetclass: @puppetclass, environment: @environment, puppetclass_lookup_key: lookup_key)
52
-
53
- # sending exactly what the host form would send which is lookup_value.value_before_type_cast
54
- lk = { 'lookup_values_attributes' => { lookup_key.id.to_s => { 'value' => lookup_value.value_before_type_cast,
55
- 'id' => lookup_value.id,
56
- 'lookup_key_id' => lookup_key.id,
57
- '_destroy' => false } } }
58
-
59
- params = {
60
- hostgroup_id: hostgroup.id,
61
- hostgroup: hostgroup.attributes.merge(lk),
62
- }
63
-
64
- # environment change calls puppetclass_parameters which caused the extra escaping
65
- post :puppetclass_parameters, params: params, session: set_session_user, xhr: true
66
-
67
- # if this was escaped during refresh_host the value in response.body after unescapeHTML would include "[\\\"c\\\",\\\"d\\\"]"
68
- assert_includes CGI.unescapeHTML(response.body), '["c","d"]'
53
+ context 'environment_id param is set' do
54
+ test 'it will take the hostgroup params environment_id' do
55
+ other_environment = FactoryBot.create(:environment)
56
+ @params[:hostgroup][:environment_id] = other_environment.id
57
+
58
+ post :environment_selected, params: @params, session: set_session_user, xhr: true
59
+ assert_equal assigns(:environment), other_environment
60
+ end
61
+ end
62
+
63
+ test 'should not escape lookup values on environment change' do
64
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment, puppetclasses: [@puppetclass])
65
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, :array, default_value: %w[a b],
66
+ override: true,
67
+ puppetclass: @puppetclass,
68
+ overrides: { "hostgroup=#{hostgroup.name}" => %w[c d] })
69
+ lookup_value = lookup_key.lookup_values.first
70
+ FactoryBot.create(:environment_class, puppetclass: @puppetclass, environment: @environment, puppetclass_lookup_key: lookup_key)
71
+
72
+ # sending exactly what the host form would send which is lookup_value.value_before_type_cast
73
+ lk = { 'lookup_values_attributes' => { lookup_key.id.to_s => { 'value' => lookup_value.value_before_type_cast,
74
+ 'id' => lookup_value.id,
75
+ 'lookup_key_id' => lookup_key.id,
76
+ '_destroy' => false } } }
77
+
78
+ params = {
79
+ hostgroup_id: hostgroup.id,
80
+ hostgroup: hostgroup.attributes.merge(lk),
81
+ }
82
+
83
+ # environment change calls puppetclass_parameters which caused the extra escaping
84
+ post :puppetclass_parameters, params: params, session: set_session_user, xhr: true
85
+
86
+ # if this was escaped during refresh_host the value in response.body after unescapeHTML would include "[\\\"c\\\",\\\"d\\\"]"
87
+ assert_includes CGI.unescapeHTML(response.body), '["c","d"]'
88
+ end
69
89
  end
70
90
  end
71
91
  end
@@ -45,6 +45,9 @@ FactoryBot.modify do
45
45
  puppet_proxy do
46
46
  FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:feature, :puppet)])
47
47
  end
48
+ puppet_ca_proxy do
49
+ FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:feature, :puppetca)])
50
+ end
48
51
  end
49
52
 
50
53
  trait :with_config_group do
@@ -9,49 +9,88 @@ module ForemanPuppet
9
9
  include HostsAndHostgroupsHelper
10
10
 
11
11
  describe 'puppet environment field' do
12
+ let(:fields) { mock('fields_for') }
13
+ let(:f) { mock('form_for') }
14
+ let(:object) { mock('object') }
15
+ let(:puppet_facet) { mock('puppet') }
16
+
12
17
  setup do
13
- @host = mock('host')
14
- puppet = mock('puppet')
15
- @host.stubs(:hostgroup)
16
- @host.stubs(:puppet).returns(puppet)
17
- @host.stubs(:id).returns(999)
18
- @f = mock('f')
19
- @f.stubs(:object).returns(@host)
20
- @fields = mock('fields')
21
- @fields.stubs(:object).returns(puppet)
22
- @f.stubs(:fields_for).yields(@fields)
18
+ f.stubs(:object).returns(object)
19
+ f.stubs(:fields_for).yields(fields)
20
+ fields.stubs(:object).returns(puppet_facet)
23
21
  end
24
22
 
25
- test 'it adds new first level attributes' do
26
- @fields.expects(:collection_select).with do |*attrs|
27
- select_options, html_options = extract_collection_options(attrs)
28
- select_options[:test_select_option] == 'test_value1' &&
29
- html_options[:test_html_option] == 'test_value2'
23
+ describe '#host_puppet_environment_field' do
24
+ let(:object) do
25
+ host = mock('host')
26
+ host.stubs(:hostgroup)
27
+ host.stubs(:puppet).returns(puppet_facet)
28
+ host.stubs(:id).returns(999)
29
+ host
30
30
  end
31
31
 
32
- host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
33
- end
32
+ test 'it adds new first level attributes' do
33
+ fields.expects(:collection_select).with do |*attrs|
34
+ select_options, html_options = extract_collection_options(attrs)
35
+ select_options[:test_select_option] == 'test_value1' &&
36
+ html_options[:test_html_option] == 'test_value2'
37
+ end
34
38
 
35
- test 'it adds new data attributes' do
36
- @fields.expects(:collection_select).with do |*attrs|
37
- select_options, html_options = extract_collection_options(attrs)
38
- select_options[:test_select_option] == 'test_value1' &&
39
- html_options[:data][:test] == 'test_value2'
39
+ host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
40
40
  end
41
41
 
42
- host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
42
+ test 'it adds new data attributes' do
43
+ fields.expects(:collection_select).with do |*attrs|
44
+ select_options, html_options = extract_collection_options(attrs)
45
+ select_options[:test_select_option] == 'test_value1' &&
46
+ html_options[:data][:test] == 'test_value2'
47
+ end
48
+
49
+ host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
50
+ end
51
+
52
+ test 'it overrides existing attributes' do
53
+ fields.expects(:collection_select).with do |*attrs|
54
+ html_options = attrs.pop
55
+ html_options[:data][:test] == 'some_test_value' &&
56
+ html_options[:data][:url] == '/test/url'
57
+ end.returns('')
58
+
59
+ html = host_puppet_environment_field(f, { disable_button: false }, { data: { url: '/test/url', test: 'some_test_value' } })
60
+
61
+ assert_no_match(/btn/, html)
62
+ end
43
63
  end
44
64
 
45
- test 'it overrides existing attributes' do
46
- @fields.expects(:collection_select).with do |*attrs|
47
- html_options = attrs.pop
48
- html_options[:data][:test] == 'some_test_value' &&
49
- html_options[:data][:url] == '/test/url'
50
- end.returns('')
65
+ describe '#hostgroup_puppet_environment_field' do
66
+ let(:object) { FactoryBot.build_stubbed(:hostgroup, parent: parent_hg) }
67
+ let(:puppet_facet) { object.puppet || object.build_puppet }
68
+
69
+ context 'parent without puppet' do
70
+ let(:parent_hg) { FactoryBot.create(:hostgroup) }
51
71
 
52
- html = host_puppet_environment_field(@f, { disable_button: false }, { data: { url: '/test/url', test: 'some_test_value' } })
72
+ it 'shows Inherit option with no value' do
73
+ fields.expects(:collection_select).with do |*attrs|
74
+ options = attrs.second
75
+ options.first.to_label == 'Inherit parent (no value)'
76
+ end.returns('')
77
+
78
+ hostgroup_puppet_environment_field(f)
79
+ end
80
+ end
53
81
 
54
- assert_no_match(/btn/, html)
82
+ context 'parent with puppet' do
83
+ let(:parent_hg) { FactoryBot.create(:hostgroup, :with_puppet_enc) }
84
+
85
+ it 'shows Inherit option with no value' do
86
+ fields.expects(:collection_select).with do |*attrs|
87
+ options = attrs.second
88
+ options.first.to_label == "Inherit parent (#{parent_hg.puppet.environment.name})"
89
+ end.returns('')
90
+
91
+ hostgroup_puppet_environment_field(f)
92
+ end
93
+ end
55
94
  end
56
95
  end
57
96
 
@@ -107,7 +107,13 @@ module ForemanPuppet
107
107
  test 'should return empty array if host has no hostgroup' do
108
108
  host = FactoryBot.create(:host, :with_puppet_enc)
109
109
  assert_not host.hostgroup
110
- assert_empty host.puppet.parent_config_groups
110
+ assert_equal [], host.puppet.parent_config_groups
111
+ end
112
+
113
+ test 'should return empty array if hostgroup do not have puppet data' do
114
+ hostgroup = FactoryBot.create(:hostgroup)
115
+ host = FactoryBot.create(:host, :with_puppet_enc, hostgroup: hostgroup)
116
+ assert_equal [], host.puppet.parent_config_groups
111
117
  end
112
118
  end
113
119
 
@@ -0,0 +1,17 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class HostCounterTest < ActiveSupport::TestCase
5
+ def hosts_count(association)
6
+ ::HostCounter.new(association)
7
+ end
8
+
9
+ let(:environment) { FactoryBot.create(:environment) }
10
+
11
+ test 'it should get number of hosts associated to environment' do
12
+ FactoryBot.create(:host, :with_puppet_enc, environment: environment)
13
+ count = hosts_count(:environment)
14
+ assert_equal 1, count[environment]
15
+ end
16
+ end
17
+ end
@@ -7,11 +7,11 @@ import { foremanUrl, getManualURL } from 'foremanReact/common/helpers';
7
7
  export const WelcomeEnv = ({ canCreate }) => {
8
8
  const action = canCreate && {
9
9
  title: __('Create Puppet Environment'),
10
- url: foremanUrl('environments/new'),
10
+ url: foremanUrl('/foreman_puppet/environments/new'),
11
11
  };
12
12
 
13
13
  const content = __(`If you are planning to use Foreman as an external node classifier you should provide information about one or more environments.<br/>
14
- This information is commonly imported from a pre-existing Puppet configuration by the use of the <a href=${getManualURL(
14
+ This information is commonly imported from a pre-existing Puppet configuration by the use of the <a target="_blank" href=${getManualURL(
15
15
  '4.2.2Classes'
16
16
  )}>Puppet classes and environment importer.</a>`);
17
17
  return (
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  - Shira Maximov
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-13 00:00:00.000000000 Z
12
+ date: 2021-11-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
15
15
  email:
@@ -94,6 +94,7 @@ files:
94
94
  - app/models/foreman_puppet/puppetclass.rb
95
95
  - app/models/foreman_puppet/puppetclass_lookup_key.rb
96
96
  - app/prepend_views/api/v2/template_combinations/base.json.rabl
97
+ - app/services/concerns/foreman_puppet/extensions/host_counter.rb
97
98
  - app/services/foreman_puppet/host_info_providers/config_groups_info.rb
98
99
  - app/services/foreman_puppet/host_info_providers/puppet_info.rb
99
100
  - app/services/foreman_puppet/input_type/puppet_parameter_input.rb
@@ -182,6 +183,7 @@ files:
182
183
  - db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
183
184
  - db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb
184
185
  - db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb
186
+ - db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb
185
187
  - db/migrate_foreman/20090722141107_create_environments.rb
186
188
  - db/migrate_foreman/20120905095532_create_environment_classes.rb
187
189
  - db/migrate_foreman/20140407161817_create_config_groups.rb
@@ -200,6 +202,8 @@ files:
200
202
  - lib/tasks/foreman_puppet_tasks.rake
201
203
  - locale/Makefile
202
204
  - locale/action_names.rb
205
+ - locale/cs_CZ/foreman_puppet.edit.po
206
+ - locale/cs_CZ/foreman_puppet.po.time_stamp
203
207
  - locale/en/LC_MESSAGES/foreman_puppet.mo
204
208
  - locale/en/foreman_puppet.edit.po
205
209
  - locale/en/foreman_puppet.po
@@ -263,6 +267,7 @@ files:
263
267
  - test/models/foreman_puppet/report_test.rb
264
268
  - test/models/foreman_puppet/smart_proxy_test.rb
265
269
  - test/models/foreman_puppet/user_test.rb
270
+ - test/services/foreman_puppet/host_counter_test.rb
266
271
  - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
267
272
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
268
273
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
@@ -296,7 +301,7 @@ homepage: https://github.com/theforeman/foreman_puppet
296
301
  licenses:
297
302
  - GPL-3.0
298
303
  metadata: {}
299
- post_install_message:
304
+ post_install_message:
300
305
  rdoc_options: []
301
306
  require_paths:
302
307
  - lib
@@ -312,13 +317,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
317
  version: '0'
313
318
  requirements: []
314
319
  rubygems_version: 3.1.6
315
- signing_key:
320
+ signing_key:
316
321
  specification_version: 4
317
322
  summary: Adds puppet ENC features
318
323
  test_files:
319
324
  - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
320
325
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
321
326
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
327
+ - test/services/foreman_puppet/host_counter_test.rb
322
328
  - test/integration/foreman_puppet/smartclass_parameter_js_test.rb
323
329
  - test/integration/foreman_puppet/puppetclass_js_test.rb
324
330
  - test/integration/foreman_puppet/hostgroup_js_test.rb