foreman_puppet 1.0.5 → 2.0.0.alpha.2

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +14 -16
  3. data/app/controllers/concerns/foreman_puppet/{api/import_puppetclasses_common_controller.rb → extensions/api_smart_proxies_controller.rb} +9 -3
  4. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -1
  5. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +15 -17
  6. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +0 -1
  7. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +32 -41
  8. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +26 -41
  9. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +0 -1
  10. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +1 -1
  11. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +0 -5
  12. data/app/helpers/foreman_puppet/hosts_helper.rb +6 -10
  13. data/app/models/concerns/foreman_puppet/extensions/host.rb +2 -16
  14. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +2 -7
  15. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +7 -12
  16. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +5 -10
  17. data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
  18. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +0 -2
  19. data/app/services/foreman_puppet/puppet_class_importer.rb +0 -6
  20. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_list.json.rabl +3 -0
  21. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +2 -0
  22. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_list.json.rabl +3 -0
  23. data/config/api_routes.rb +1 -9
  24. data/config/initializers/api_reroute.rb +73 -5
  25. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +1 -1
  26. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -0
  27. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +20 -36
  28. data/db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb +5 -0
  29. data/db/migrate_foreman/20090722141107_create_environments.rb +2 -2
  30. data/db/migrate_foreman/20090802062223_create_puppetclasses.rb +28 -0
  31. data/db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.rb +12 -0
  32. data/db/migrate_foreman/20110412103238_remove_unused_fields_from_puppet_classes.rb +9 -0
  33. data/db/migrate_foreman/20110712070522_create_host_class.rb +11 -0
  34. data/db/migrate_foreman/20120824142048_add_some_indexes.rb +14 -0
  35. data/db/migrate_foreman/20121018152459_create_hostgroup_classes.rb +11 -0
  36. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +1 -1
  37. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +1 -31
  38. data/db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.rb +24 -0
  39. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +1 -1
  40. data/lib/foreman_puppet/engine.rb +4 -36
  41. data/lib/foreman_puppet/register.rb +16 -47
  42. data/lib/foreman_puppet/version.rb +1 -1
  43. data/lib/foreman_puppet.rb +1 -6
  44. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  45. data/locale/en/foreman_puppet.edit.po +162 -317
  46. data/locale/en/foreman_puppet.po +62 -8
  47. data/locale/foreman_puppet.pot +215 -133
  48. data/locale/gemspec.rb +1 -1
  49. data/package.json +8 -11
  50. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +0 -231
  51. data/test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb +255 -0
  52. data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
  53. data/test/controllers/foreman_puppet/hosts_controller_test.rb +0 -1
  54. data/test/factories/foreman_puppet_factories.rb +0 -2
  55. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +31 -70
  56. data/test/integration/foreman_puppet/host_js_test.rb +0 -1
  57. data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -1
  58. data/test/models/foreman_puppet/host_puppet_facet_test.rb +1 -7
  59. data/test/models/foreman_puppet/host_test.rb +26 -0
  60. data/test/models/foreman_puppet/user_test.rb +1 -5
  61. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +1 -1
  62. metadata +22 -13
  63. data/db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb +0 -10
  64. data/locale/cs_CZ/foreman_puppet.edit.po +0 -1085
  65. data/locale/cs_CZ/foreman_puppet.po.time_stamp +0 -0
@@ -9,88 +9,49 @@ 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
-
17
12
  setup do
18
- f.stubs(:object).returns(object)
19
- f.stubs(:fields_for).yields(fields)
20
- fields.stubs(:object).returns(puppet_facet)
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)
21
23
  end
22
24
 
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
- end
31
-
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
38
-
39
- host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
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'
40
30
  end
41
31
 
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
32
+ host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
33
+ end
48
34
 
49
- host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
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'
50
40
  end
51
41
 
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
42
+ host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
63
43
  end
64
44
 
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) }
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('')
71
51
 
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
52
+ html = host_puppet_environment_field(@f, { disable_button: false }, { data: { url: '/test/url', test: 'some_test_value' } })
81
53
 
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
54
+ assert_no_match(/btn/, html)
94
55
  end
95
56
  end
96
57
 
@@ -362,7 +362,6 @@ module ForemanPuppet
362
362
  page.find('#puppet_klasses_parameters_table')
363
363
  end
364
364
 
365
- # TODO: unless ForemanPuppet.extracted_from_core?
366
365
  def switch_form_tab_to_interfaces
367
366
  switch_form_tab('Interfaces')
368
367
  disable_interface_modal_animation
@@ -11,7 +11,7 @@ module ForemanPuppet
11
11
  let(:puppetclass) { FactoryBot.create(:puppetclass, environments: [environment]) }
12
12
 
13
13
  test 'edit page' do
14
- FactoryBot.create(:puppetclass, name: 'vim', environments: [environment]) if ForemanPuppet.extracted_from_core?
14
+ FactoryBot.create(:puppetclass, name: 'vim', environments: [environment])
15
15
  visit puppetclasses_path
16
16
  click_link 'vim'
17
17
  assert page.has_no_link? 'Common'
@@ -107,13 +107,7 @@ 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_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
110
+ assert_empty host.puppet.parent_config_groups
117
111
  end
118
112
  end
119
113
 
@@ -150,6 +150,32 @@ module ForemanPuppet
150
150
  end
151
151
  end
152
152
 
153
+ describe '#available_template_kinds' do
154
+ let(:template_kinds) { [stub(name: 'iPXE'), stub(name: 'finish')] }
155
+
156
+ test 'calls find_template with Puppet environment' do
157
+ host = FactoryBot.create(:host, :with_hostgroup, :with_puppet_enc)
158
+ host.expects(:template_kinds).returns(template_kinds)
159
+ template_kinds.each do |kind|
160
+ ::ProvisioningTemplate.expects(:find_template)
161
+ .with(kind: kind.name, operatingsystem_id: host.operatingsystem.id, hostgroup_id: host.hostgroup.id, environment_id: host.puppet.environment.id)
162
+ .returns(stub(name: "default #{kind.name}"))
163
+ end
164
+ assert_equal template_kinds.map { |k| "default #{k.name}" }, host.available_template_kinds.map(&:name)
165
+ end
166
+
167
+ test 'calls find_template without Puppet environment' do
168
+ host = FactoryBot.create(:host, :with_hostgroup)
169
+ host.expects(:template_kinds).returns(template_kinds)
170
+ template_kinds.each do |kind|
171
+ ::ProvisioningTemplate.expects(:find_template)
172
+ .with(kind: kind.name, operatingsystem_id: host.operatingsystem.id, hostgroup_id: host.hostgroup.id, environment_id: nil)
173
+ .returns(stub(name: "default #{kind.name}"))
174
+ end
175
+ assert_equal template_kinds.map { |k| "default #{k.name}" }, host.available_template_kinds.map(&:name)
176
+ end
177
+ end
178
+
153
179
  test 'should import from external nodes output' do
154
180
  # create a dummy node
155
181
  Parameter.destroy_all
@@ -5,11 +5,7 @@ module ForemanPuppet
5
5
  describe '#visible_environments' do
6
6
  let(:environment) { FactoryBot.create(:environment) }
7
7
  let(:untaxed_env) { FactoryBot.create(:environment, organizations: [], locations: []) }
8
- let(:env_names) do
9
- env_names = [environment.name, untaxed_env.name]
10
- env_names += %w[production global_puppetmaster testing] unless ForemanPuppet.extracted_from_core?
11
- env_names
12
- end
8
+ let(:env_names) { [environment.name, untaxed_env.name] }
13
9
 
14
10
  setup do
15
11
  environment
@@ -3,7 +3,7 @@ require 'test_puppet_helper'
3
3
  module ForemanPuppet
4
4
  class PuppetClassImporterTest < ActiveSupport::TestCase
5
5
  def setup
6
- FactoryBot.create(:environment, name: 'production') if ForemanPuppet.extracted_from_core?
6
+ FactoryBot.create(:environment, name: 'production')
7
7
  ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[foreman-testing foreman-testing-1])
8
8
  ProxyAPI::Puppet.any_instance.stubs(:classes).returns(mocked_classes)
9
9
  User.current = users(:admin)
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 2.0.0.alpha.2
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-11-15 00:00:00.000000000 Z
12
+ date: 2021-10-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
14
+ description: Allow assigning Puppet environments and classes to the Foreman Hosts.
15
15
  email:
16
16
  - foreman-dev@googlegroups.com
17
17
  executables: []
@@ -22,10 +22,10 @@ files:
22
22
  - README.md
23
23
  - Rakefile
24
24
  - app/assets/stylesheets/foreman_puppet.scss
25
- - app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb
26
25
  - app/controllers/concerns/foreman_puppet/environments_import.rb
27
26
  - app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb
28
27
  - app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb
28
+ - app/controllers/concerns/foreman_puppet/extensions/api_smart_proxies_controller.rb
29
29
  - app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb
30
30
  - app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb
31
31
  - app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb
@@ -113,9 +113,11 @@ files:
113
113
  - app/views/foreman_puppet/api/v2/environments/show.json.rabl
114
114
  - app/views/foreman_puppet/api/v2/environments/update.json.rabl
115
115
  - app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl
116
+ - app/views/foreman_puppet/api/v2/host_puppet_facets/host_list.json.rabl
116
117
  - app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl
117
118
  - app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl
118
119
  - app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl
120
+ - app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_list.json.rabl
119
121
  - app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl
120
122
  - app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl
121
123
  - app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl
@@ -183,15 +185,22 @@ files:
183
185
  - db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
184
186
  - db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb
185
187
  - db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb
186
- - db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb
188
+ - db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb
187
189
  - db/migrate_foreman/20090722141107_create_environments.rb
190
+ - db/migrate_foreman/20090802062223_create_puppetclasses.rb
191
+ - db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.rb
192
+ - db/migrate_foreman/20110412103238_remove_unused_fields_from_puppet_classes.rb
193
+ - db/migrate_foreman/20110712070522_create_host_class.rb
194
+ - db/migrate_foreman/20120824142048_add_some_indexes.rb
188
195
  - db/migrate_foreman/20120905095532_create_environment_classes.rb
196
+ - db/migrate_foreman/20121018152459_create_hostgroup_classes.rb
189
197
  - db/migrate_foreman/20140407161817_create_config_groups.rb
190
198
  - db/migrate_foreman/20140407162007_create_config_group_classes.rb
191
199
  - db/migrate_foreman/20140407162059_create_host_config_groups.rb
192
200
  - db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb
193
201
  - db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb
194
202
  - db/migrate_foreman/20180816134832_cast_lookup_key_values.rb
203
+ - db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.rb
195
204
  - db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb
196
205
  - db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb
197
206
  - db/seeds.d/111_puppet_proxy_feature.rb
@@ -202,8 +211,6 @@ files:
202
211
  - lib/tasks/foreman_puppet_tasks.rake
203
212
  - locale/Makefile
204
213
  - locale/action_names.rb
205
- - locale/cs_CZ/foreman_puppet.edit.po
206
- - locale/cs_CZ/foreman_puppet.po.time_stamp
207
214
  - locale/en/LC_MESSAGES/foreman_puppet.mo
208
215
  - locale/en/foreman_puppet.edit.po
209
216
  - locale/en/foreman_puppet.po
@@ -224,6 +231,7 @@ files:
224
231
  - test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb
225
232
  - test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb
226
233
  - test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb
234
+ - test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb
227
235
  - test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb
228
236
  - test/controllers/foreman_puppet/config_groups_controller_test.rb
229
237
  - test/controllers/foreman_puppet/environments_controller_test.rb
@@ -301,7 +309,7 @@ homepage: https://github.com/theforeman/foreman_puppet
301
309
  licenses:
302
310
  - GPL-3.0
303
311
  metadata: {}
304
- post_install_message:
312
+ post_install_message:
305
313
  rdoc_options: []
306
314
  require_paths:
307
315
  - lib
@@ -312,14 +320,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
320
  version: '0'
313
321
  required_rubygems_version: !ruby/object:Gem::Requirement
314
322
  requirements:
315
- - - ">="
323
+ - - ">"
316
324
  - !ruby/object:Gem::Version
317
- version: '0'
325
+ version: 1.3.1
318
326
  requirements: []
319
327
  rubygems_version: 3.1.6
320
- signing_key:
328
+ signing_key:
321
329
  specification_version: 4
322
- summary: Adds puppet ENC features
330
+ summary: Add Puppet features to Foreman
323
331
  test_files:
324
332
  - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
325
333
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
@@ -379,6 +387,7 @@ test_files:
379
387
  - test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb
380
388
  - test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb
381
389
  - test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb
390
+ - test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb
382
391
  - test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb
383
392
  - test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb
384
393
  - test/controllers/foreman_puppet/puppetclasses_controller_test.rb
@@ -1,10 +0,0 @@
1
- class CleanupEnvironmentFromCoreTables < ActiveRecord::Migration[6.0]
2
- def up
3
- ::Hostgroup.update_all(environment_id: nil) if column_exists?(:hostgroups, :environment_id)
4
- Host::Managed.update_all(environment_id: nil) if column_exists?(:hosts, :environment_id)
5
- end
6
-
7
- def down
8
- # nothing to do
9
- end
10
- end