foreman_puppet 1.0.5 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) 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_hostgroup.rb +2 -8
  8. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +0 -1
  9. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +1 -1
  10. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +1 -1
  11. data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
  12. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +0 -5
  13. data/app/helpers/foreman_puppet/hosts_helper.rb +6 -10
  14. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +1 -1
  15. data/app/models/concerns/foreman_puppet/extensions/host.rb +2 -16
  16. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +2 -7
  17. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +7 -12
  18. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +5 -10
  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/app/views/foreman_puppet/config_groups/index.html.erb +1 -1
  24. data/config/api_routes.rb +1 -9
  25. data/config/initializers/api_reroute.rb +73 -5
  26. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +1 -1
  27. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -0
  28. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +0 -8
  29. data/db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb +5 -0
  30. data/db/migrate/20211111125003_drop_puppetclasses_direct_references.foreman_puppet.rb +11 -0
  31. data/db/migrate/20220201205305_migrate_host_class_permission.foreman_puppet.rb +9 -0
  32. data/db/migrate/20220208135305_migrate_environment_ignore_type.foreman_puppet.rb +15 -0
  33. data/db/migrate_foreman/{20090722141107_create_environments.rb → 20090722141107_create_environments.foreman_puppet.rb} +3 -3
  34. data/db/migrate_foreman/20090802062223_create_puppetclasses.foreman_puppet.rb +29 -0
  35. data/db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb +14 -0
  36. data/db/migrate_foreman/20110412103238_remove_unused_fields_from_puppet_classes.foreman_puppet.rb +9 -0
  37. data/db/migrate_foreman/20110712070522_create_host_class.foreman_puppet.rb +11 -0
  38. data/db/migrate_foreman/20120824142048_add_some_indexes.foreman_puppet.rb +21 -0
  39. data/db/migrate_foreman/{20120905095532_create_environment_classes.rb → 20120905095532_create_environment_classes.foreman_puppet.rb} +2 -2
  40. data/db/migrate_foreman/20121018152459_create_hostgroup_classes.foreman_puppet.rb +11 -0
  41. data/db/migrate_foreman/{20140407161817_create_config_groups.rb → 20140407161817_create_config_groups.foreman_puppet.rb} +0 -0
  42. data/db/migrate_foreman/{20140407162007_create_config_group_classes.rb → 20140407162007_create_config_group_classes.foreman_puppet.rb} +0 -0
  43. data/db/migrate_foreman/{20140407162059_create_host_config_groups.rb → 20140407162059_create_host_config_groups.foreman_puppet.rb} +0 -0
  44. data/db/migrate_foreman/{20161205142618_delete_orphaned_smart_class_parameters.rb → 20161205142618_delete_orphaned_smart_class_parameters.foreman_puppet.rb} +1 -1
  45. data/db/migrate_foreman/{20170109115157_fix_lookup_key_auditable_type.rb → 20170109115157_fix_lookup_key_auditable_type.foreman_puppet.rb} +0 -0
  46. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.foreman_puppet.rb +5 -0
  47. data/db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb +24 -0
  48. data/db/migrate_foreman/{20181023112532_add_environment_puppetclass_id.rb → 20181023112532_add_environment_puppetclass_id.foreman_puppet.rb} +1 -1
  49. data/db/migrate_foreman/{20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb → 20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.foreman_puppet.rb} +0 -0
  50. data/lib/foreman_puppet/engine.rb +4 -36
  51. data/lib/foreman_puppet/register.rb +51 -46
  52. data/lib/foreman_puppet/version.rb +1 -1
  53. data/lib/foreman_puppet.rb +1 -6
  54. data/locale/ca/LC_MESSAGES/foreman_puppet.mo +0 -0
  55. data/locale/ca/foreman_puppet.po +760 -0
  56. data/locale/cs_CZ/LC_MESSAGES/foreman_puppet.mo +0 -0
  57. data/locale/cs_CZ/foreman_puppet.po +823 -0
  58. data/locale/de/LC_MESSAGES/foreman_puppet.mo +0 -0
  59. data/locale/de/foreman_puppet.po +844 -0
  60. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  61. data/locale/en/foreman_puppet.po +119 -8
  62. data/locale/en_GB/LC_MESSAGES/foreman_puppet.mo +0 -0
  63. data/locale/en_GB/foreman_puppet.po +820 -0
  64. data/locale/es/LC_MESSAGES/foreman_puppet.mo +0 -0
  65. data/locale/es/foreman_puppet.po +827 -0
  66. data/locale/foreman_puppet.pot +376 -205
  67. data/locale/fr/LC_MESSAGES/foreman_puppet.mo +0 -0
  68. data/locale/fr/foreman_puppet.po +835 -0
  69. data/locale/gemspec.rb +1 -1
  70. data/locale/gl/LC_MESSAGES/foreman_puppet.mo +0 -0
  71. data/locale/gl/foreman_puppet.po +818 -0
  72. data/locale/it/LC_MESSAGES/foreman_puppet.mo +0 -0
  73. data/locale/it/foreman_puppet.po +822 -0
  74. data/locale/ja/LC_MESSAGES/foreman_puppet.mo +0 -0
  75. data/locale/ja/foreman_puppet.po +830 -0
  76. data/locale/ko/LC_MESSAGES/foreman_puppet.mo +0 -0
  77. data/locale/ko/foreman_puppet.po +819 -0
  78. data/locale/nl_NL/LC_MESSAGES/foreman_puppet.mo +0 -0
  79. data/locale/nl_NL/foreman_puppet.po +823 -0
  80. data/locale/pl/LC_MESSAGES/foreman_puppet.mo +0 -0
  81. data/locale/pl/foreman_puppet.po +822 -0
  82. data/locale/pt_BR/LC_MESSAGES/foreman_puppet.mo +0 -0
  83. data/locale/pt_BR/foreman_puppet.po +826 -0
  84. data/locale/ru/LC_MESSAGES/foreman_puppet.mo +0 -0
  85. data/locale/ru/foreman_puppet.po +827 -0
  86. data/locale/sv_SE/LC_MESSAGES/foreman_puppet.mo +0 -0
  87. data/locale/sv_SE/foreman_puppet.po +822 -0
  88. data/locale/zh_CN/LC_MESSAGES/foreman_puppet.mo +0 -0
  89. data/locale/zh_CN/foreman_puppet.po +831 -0
  90. data/locale/zh_TW/LC_MESSAGES/foreman_puppet.mo +0 -0
  91. data/locale/zh_TW/foreman_puppet.po +821 -0
  92. data/package.json +8 -11
  93. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +0 -231
  94. data/test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb +255 -0
  95. data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
  96. data/test/controllers/foreman_puppet/hosts_controller_test.rb +0 -1
  97. data/test/factories/foreman_puppet_factories.rb +0 -2
  98. data/test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb +34 -0
  99. data/test/integration/foreman_puppet/dashboard_js_test.rb +31 -0
  100. data/test/integration/foreman_puppet/host_js_test.rb +0 -1
  101. data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -1
  102. data/test/models/foreman_puppet/host_test.rb +26 -0
  103. data/test/models/foreman_puppet/user_test.rb +1 -5
  104. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +1 -1
  105. metadata +69 -16
  106. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +0 -35
data/package.json CHANGED
@@ -21,25 +21,22 @@
21
21
  "url": "http://projects.theforeman.org/projects/foreman_puppet/issues"
22
22
  },
23
23
  "peerDependencies": {
24
- "@theforeman/vendor": ">= 6.0.0"
24
+ "@theforeman/vendor": "^8.15.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@babel/core": "^7.7.0",
28
28
  "@sheerun/mutationobserver-shim": "^0.3.3",
29
- "@theforeman/builder": "^6.0.0",
30
- "@theforeman/eslint-plugin-foreman": "^6.0.0",
31
- "@theforeman/find-foreman": "^4.8.0",
32
- "@theforeman/stories": "^7.0.0",
33
- "@theforeman/test": "^8.0.0",
34
- "@theforeman/vendor-dev": "^6.0.0",
29
+ "@theforeman/builder": "^8.15.0",
30
+ "@theforeman/eslint-plugin-foreman": "^8.15.0",
31
+ "@theforeman/find-foreman": "^8.15.0",
32
+ "@theforeman/stories": "^8.15.0",
33
+ "@theforeman/test": "^8.15.0",
34
+ "@theforeman/vendor-dev": "^8.15.0",
35
35
  "babel-eslint": "^10.0.3",
36
36
  "eslint": "^6.7.2",
37
+ "jed": "^1.1.1",
37
38
  "prettier": "^1.19.1",
38
39
  "stylelint-config-standard": "^18.0.0",
39
40
  "stylelint": "^9.3.0"
40
- },
41
- "dependencies": {
42
- "jed": "^1.1.1",
43
- "react-intl": "^2.8.0"
44
41
  }
45
42
  }
@@ -111,237 +111,6 @@ module ForemanPuppet
111
111
  end
112
112
  assert_response :success
113
113
  end
114
-
115
- describe 'POST #import_puppetclasses' do
116
- # puppetmaster proxy - import_puppetclasses tests
117
-
118
- let(:proxy) { FactoryBot.create(:puppet_smart_proxy) }
119
-
120
- test 'should import new environments' do
121
- setup_import_classes
122
- as_admin do
123
- Host::Managed.update_all(environment_id: nil)
124
- Hostgroup.update_all(environment_id: nil)
125
- Puppetclass.destroy_all
126
- Environment.destroy_all
127
- end
128
- assert_difference('Environment.unscoped.count', 2) do
129
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
130
- end
131
- assert_response :success
132
- response = ActiveSupport::JSON.decode(@response.body)
133
- assert_equal 2, response['environments_with_new_puppetclasses']
134
- end
135
-
136
- # this is intentional: put test_attributes only for the first generated test eg: dryrun_param = {}
137
- test_attributes pid: '385efd1b-6146-47bf-babf-0127ce5955ed'
138
- [{}, { dryrun: false }, { dryrun: 'false' }].each do |dryrun_param|
139
- test 'should import new puppetclasses' do
140
- setup_import_classes
141
- as_admin do
142
- Host::Managed.update_all(environment_id: nil)
143
- Hostgroup.update_all(environment_id: nil)
144
- Puppetclass.destroy_all
145
- Environment.destroy_all
146
- assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
147
- post :import_puppetclasses,
148
- params: { id: proxy.id }.merge(dryrun_param),
149
- session: set_session_user
150
- end
151
- end
152
- assert_response :success
153
- assert_match 'Successfully updated environment and puppetclasses from the on-disk puppet installation', @response.body
154
- end
155
- end
156
-
157
- test 'should not import new puppetclasses when dryrun' do
158
- setup_import_classes
159
- as_admin do
160
- Host::Managed.update_all(environment_id: nil)
161
- Hostgroup.update_all(environment_id: nil)
162
- Puppetclass.destroy_all
163
- Environment.destroy_all
164
- assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 0) do
165
- post :import_puppetclasses, params: { id: proxy.id, dryrun: true }, session: set_session_user
166
- end
167
- end
168
- assert_response :success
169
- end
170
-
171
- test 'should obsolete environment' do
172
- setup_import_classes
173
- as_admin do
174
- FactoryBot.create(:environment, name: 'xyz')
175
- end
176
-
177
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
178
- assert_response :success
179
- as_admin do
180
- assert_nil ForemanPuppet::Environment.find_by(name: 'xyz')
181
- end
182
- end
183
-
184
- test 'should obsolete puppetclasses' do
185
- setup_import_classes
186
- as_admin do
187
- assert_difference(-> { ForemanPuppet::Environment.unscoped.find_by(name: 'env1').puppetclasses.count }, -2) do
188
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
189
- end
190
- end
191
- assert_response :success
192
- end
193
-
194
- test 'should update puppetclass smart class parameters' do
195
- setup_import_classes
196
- LookupKey.destroy_all
197
- assert_difference(-> { LookupKey.unscoped.count }, 1) do
198
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
199
- end
200
- assert_response :success
201
- end
202
-
203
- test 'no changes on import_puppetclasses' do
204
- setup_import_classes
205
- Puppetclass.find_by(name: 'b').destroy
206
- Puppetclass.find_by(name: 'c').destroy
207
- assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
208
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
209
- end
210
- assert_response :success
211
- response = ActiveSupport::JSON.decode(@response.body)
212
- assert_equal 'Successfully updated environment and puppetclasses from the on-disk puppet installation', response['message']
213
- end
214
-
215
- test 'should import new environment that does not exist in db' do
216
- setup_import_classes
217
- as_admin do
218
- env_name = 'env1'
219
- assert Environment.find_by(name: env_name).destroy
220
- assert_difference('Environment.unscoped.count', 1) do
221
- post :import_puppetclasses, params: { id: proxy.id, environment_id: env_name }, session: set_session_user
222
- end
223
- assert_response :success
224
- response = ActiveSupport::JSON.decode(@response.body)
225
- assert_equal env_name, response['results']['name']
226
- end
227
- end
228
-
229
- test 'should NOT delete environment if pass ?except=obsolete' do
230
- setup_import_classes
231
- as_admin do
232
- Environment.create!(name: 'xyz')
233
- end
234
- assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
235
- post :import_puppetclasses, params: { id: proxy.id, except: 'obsolete' }, session: set_session_user
236
- end
237
- assert_response :success
238
- end
239
-
240
- test 'should NOT add or update puppetclass smart class parameters if pass ?except=new,updated' do
241
- setup_import_classes
242
- LookupKey.destroy_all
243
- assert_difference(-> { LookupKey.unscoped.count }, 0) do
244
- post :import_puppetclasses, params: { id: proxy.id, except: 'new,updated' }, session: set_session_user
245
- end
246
- assert_response :success
247
- end
248
-
249
- context 'import puppetclasses' do
250
- setup do
251
- ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
252
- classes_env1 = { 'a' => Foreman::ImporterPuppetclass.new('name' => 'a') }
253
- classes_env2 = { 'b' => Foreman::ImporterPuppetclass.new('name' => 'b') }
254
- ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes_env1.merge(classes_env2))
255
- ProxyAPI::Puppet.any_instance.stubs(:classes).with('env1').returns(classes_env1)
256
- ProxyAPI::Puppet.any_instance.stubs(:classes).with('env2').returns(classes_env2)
257
- end
258
-
259
- test 'should render templates according to api version 2' do
260
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
261
- assert_template 'foreman_puppet/api/v2/import_puppetclasses/index'
262
- end
263
-
264
- test 'should import puppetclasses for specified environment only' do
265
- assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
266
- post :import_puppetclasses, params: { id: proxy.id, environment_id: 'env1' }, session: set_session_user
267
- assert_includes Puppetclass.pluck(:name), 'a'
268
- assert_not_includes Puppetclass.pluck(:name), 'b'
269
- end
270
- assert_response :success
271
- end
272
-
273
- test 'should import puppetclasses for all environments if none specified' do
274
- assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 2) do
275
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
276
- end
277
- assert_includes Puppetclass.pluck(:name), 'a'
278
- assert_includes Puppetclass.pluck(:name), 'b'
279
- assert_response :success
280
- end
281
-
282
- context 'ignored entvironments or classes are set' do
283
- setup do
284
- setup_import_classes
285
- end
286
-
287
- test 'should contain ignored environments' do
288
- env_name = 'env1'
289
- PuppetClassImporter.any_instance.stubs(:ignored_environments).returns([env_name])
290
-
291
- as_admin do
292
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
293
- assert_response :success
294
- response = ActiveSupport::JSON.decode(@response.body)
295
- assert_equal env_name, response['results'][0]['ignored_environment']
296
- end
297
- end
298
-
299
- test 'should contain ignored puppet_classes' do
300
- PuppetClassImporter.any_instance.stubs(:ignored_classes).returns([/^a$/])
301
-
302
- as_admin do
303
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
304
- assert_response :success
305
- response = ActiveSupport::JSON.decode(@response.body)
306
- assert_includes response['results'][0]['ignored_puppetclasses'], 'a'
307
- assert_not_includes response['results'][0]['ignored_puppetclasses'], 'c'
308
- end
309
- end
310
- end
311
- end
312
- end
313
-
314
- private
315
-
316
- def setup_import_classes
317
- as_admin do
318
- ::Host::Managed.update_all(environment_id: nil)
319
- ::Hostgroup.update_all(environment_id: nil)
320
- ForemanPuppet::HostClass.destroy_all
321
- ForemanPuppet::HostgroupClass.destroy_all
322
- ForemanPuppet::Puppetclass.destroy_all
323
- ForemanPuppet::Environment.destroy_all
324
- end
325
- orgs = [taxonomies(:organization1)]
326
- locs = [taxonomies(:location1)]
327
- # This is the database status
328
- # and should result in a db_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
329
- as_admin do
330
- %w[a b c].each { |name| ForemanPuppet::Puppetclass.create name: name }
331
- %w[env1 env2].each do |name|
332
- e = ForemanPuppet::Environment.create!(name: name, organizations: orgs, locations: locs)
333
- e.puppetclasses = ForemanPuppet::Puppetclass.all
334
- end
335
- end
336
- # This is the on-disk status
337
- # and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
338
- envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
339
- pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => nil, 'params' => { 'key' => 'special' } })]
340
- classes = pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }.to_h
341
- ForemanPuppet::Environment.expects(:puppetEnvs).returns(envs).at_least(0)
342
- ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
343
- ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
344
- end
345
114
  end
346
115
  end
347
116
  end
@@ -0,0 +1,255 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class SmartProxiesControllerTest < ActionController::TestCase
7
+ tests ::Api::V2::SmartProxiesController
8
+
9
+ describe 'POST #import_puppetclasses' do
10
+ # puppetmaster proxy - import_puppetclasses tests
11
+
12
+ let(:proxy) { FactoryBot.create(:puppet_smart_proxy) }
13
+
14
+ test 'should import new environments' do
15
+ setup_import_classes
16
+ as_admin do
17
+ HostPuppetFacet.destroy_all
18
+ HostgroupPuppetFacet.destroy_all
19
+ Puppetclass.destroy_all
20
+ Environment.destroy_all
21
+ end
22
+ assert_difference('Environment.unscoped.count', 2) do
23
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
24
+ end
25
+ assert_response :success
26
+ response = ActiveSupport::JSON.decode(@response.body)
27
+ assert_equal 2, response['environments_with_new_puppetclasses']
28
+ end
29
+
30
+ # this is intentional: put test_attributes only for the first generated test eg: dryrun_param = {}
31
+ test_attributes pid: '385efd1b-6146-47bf-babf-0127ce5955ed'
32
+ [{}, { dryrun: false }, { dryrun: 'false' }].each do |dryrun_param|
33
+ test 'should import new puppetclasses' do
34
+ setup_import_classes
35
+ as_admin do
36
+ HostPuppetFacet.destroy_all
37
+ HostgroupPuppetFacet.destroy_all
38
+ Puppetclass.destroy_all
39
+ Environment.destroy_all
40
+ assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
41
+ post :import_puppetclasses,
42
+ params: { id: proxy.id }.merge(dryrun_param),
43
+ session: set_session_user
44
+ end
45
+ end
46
+ assert_response :success
47
+ assert_match 'Successfully updated environment and puppetclasses from the on-disk puppet installation', @response.body
48
+ end
49
+ end
50
+
51
+ test 'should not import new puppetclasses when dryrun' do
52
+ setup_import_classes
53
+ as_admin do
54
+ HostPuppetFacet.destroy_all
55
+ HostgroupPuppetFacet.destroy_all
56
+ Puppetclass.destroy_all
57
+ Environment.destroy_all
58
+ assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 0) do
59
+ post :import_puppetclasses, params: { id: proxy.id, dryrun: true }, session: set_session_user
60
+ end
61
+ end
62
+ assert_response :success
63
+ end
64
+
65
+ test 'should obsolete environment' do
66
+ setup_import_classes
67
+ as_admin do
68
+ FactoryBot.create(:environment, name: 'xyz')
69
+ end
70
+
71
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
72
+ assert_response :success
73
+ as_admin do
74
+ assert_nil ForemanPuppet::Environment.find_by(name: 'xyz')
75
+ end
76
+ end
77
+
78
+ test 'should obsolete puppetclasses' do
79
+ setup_import_classes
80
+ as_admin do
81
+ assert_difference(-> { ForemanPuppet::Environment.unscoped.find_by(name: 'env1').puppetclasses.count }, -2) do
82
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
83
+ end
84
+ end
85
+ assert_response :success
86
+ end
87
+
88
+ test 'should update puppetclass smart class parameters' do
89
+ setup_import_classes
90
+ LookupKey.destroy_all
91
+ assert_difference(-> { LookupKey.unscoped.count }, 1) do
92
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
93
+ end
94
+ assert_response :success
95
+ end
96
+
97
+ test 'no changes on import_puppetclasses' do
98
+ setup_import_classes
99
+ Puppetclass.find_by(name: 'b').destroy
100
+ Puppetclass.find_by(name: 'c').destroy
101
+ assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
102
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
103
+ end
104
+ assert_response :success
105
+ response = ActiveSupport::JSON.decode(@response.body)
106
+ assert_equal 'Successfully updated environment and puppetclasses from the on-disk puppet installation', response['message']
107
+ end
108
+
109
+ test 'should import new environment that does not exist in db' do
110
+ setup_import_classes
111
+ as_admin do
112
+ env_name = 'env1'
113
+ assert Environment.find_by(name: env_name).destroy
114
+ assert_difference('Environment.unscoped.count', 1) do
115
+ post :import_puppetclasses, params: { id: proxy.id, environment_id: env_name }, session: set_session_user
116
+ end
117
+ assert_response :success
118
+ response = ActiveSupport::JSON.decode(@response.body)
119
+ assert_equal env_name, response['results']['name']
120
+ end
121
+ end
122
+
123
+ test 'should NOT delete environment if pass ?except=obsolete' do
124
+ setup_import_classes
125
+ as_admin do
126
+ Environment.create!(name: 'xyz')
127
+ end
128
+ assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
129
+ post :import_puppetclasses, params: { id: proxy.id, except: 'obsolete' }, session: set_session_user
130
+ end
131
+ assert_response :success
132
+ end
133
+
134
+ test 'should NOT add or update puppetclass smart class parameters if pass ?except=new,updated' do
135
+ setup_import_classes
136
+ LookupKey.destroy_all
137
+ assert_difference(-> { LookupKey.unscoped.count }, 0) do
138
+ post :import_puppetclasses, params: { id: proxy.id, except: 'new,updated' }, session: set_session_user
139
+ end
140
+ assert_response :success
141
+ end
142
+
143
+ context 'import puppetclasses' do
144
+ setup do
145
+ ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
146
+ classes_env1 = { 'a' => Foreman::ImporterPuppetclass.new('name' => 'a') }
147
+ classes_env2 = { 'b' => Foreman::ImporterPuppetclass.new('name' => 'b') }
148
+
149
+ ProxyAPI::Puppet.any_instance.stubs(:classes).with('invalid').returns({})
150
+ ProxyAPI::Puppet.any_instance.stubs(:classes).with('env1').returns(classes_env1)
151
+ ProxyAPI::Puppet.any_instance.stubs(:classes).with('env2').returns(classes_env2)
152
+ end
153
+
154
+ test 'should render templates according to api version 2' do
155
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
156
+ assert_template 'foreman_puppet/api/v2/import_puppetclasses/index'
157
+ end
158
+
159
+ test 'should import puppetclasses for specified environment only' do
160
+ assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
161
+ post :import_puppetclasses, params: { id: proxy.id, environment_id: 'env1' }, session: set_session_user
162
+ assert_includes Puppetclass.pluck(:name), 'a'
163
+ assert_not_includes Puppetclass.pluck(:name), 'b'
164
+ end
165
+ assert_response :success
166
+ end
167
+
168
+ test 'should render error message when invalid environment is set' do
169
+ env = 'invalid'
170
+ assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 0) do
171
+ post :import_puppetclasses, params: { id: proxy.id, environment_id: env }, session: set_session_user
172
+ assert_not_includes Puppetclass.pluck(:name), 'a'
173
+ assert_not_includes Puppetclass.pluck(:name), 'b'
174
+ end
175
+ response = ActiveSupport::JSON.decode(@response.body)
176
+ assert_equal 'The requested environment cannot be found.', response['message']
177
+ assert_response :success
178
+ end
179
+
180
+ test 'should import puppetclasses for all environments if none specified' do
181
+ assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 2) do
182
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
183
+ end
184
+ assert_includes Puppetclass.pluck(:name), 'a'
185
+ assert_includes Puppetclass.pluck(:name), 'b'
186
+ assert_response :success
187
+ end
188
+
189
+ context 'ignored environments or classes are set' do
190
+ setup do
191
+ setup_import_classes
192
+ end
193
+
194
+ test 'should contain ignored environments' do
195
+ env_name = 'env1'
196
+ PuppetClassImporter.any_instance.stubs(:ignored_environments).returns([env_name])
197
+
198
+ as_admin do
199
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
200
+ assert_response :success
201
+ response = ActiveSupport::JSON.decode(@response.body)
202
+ assert_equal env_name, response['results'][0]['ignored_environment']
203
+ end
204
+ end
205
+
206
+ test 'should contain ignored puppet_classes' do
207
+ PuppetClassImporter.any_instance.stubs(:ignored_classes).returns([/^a$/])
208
+
209
+ as_admin do
210
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
211
+ assert_response :success
212
+ response = ActiveSupport::JSON.decode(@response.body)
213
+ assert_includes response['results'][0]['ignored_puppetclasses'], 'a'
214
+ assert_not_includes response['results'][0]['ignored_puppetclasses'], 'c'
215
+ end
216
+ end
217
+ end
218
+ end
219
+ end
220
+
221
+ private
222
+
223
+ def setup_import_classes
224
+ as_admin do
225
+ HostPuppetFacet.destroy_all
226
+ HostgroupPuppetFacet.destroy_all
227
+ ForemanPuppet::HostClass.destroy_all
228
+ ForemanPuppet::HostgroupClass.destroy_all
229
+ ForemanPuppet::Puppetclass.destroy_all
230
+ ForemanPuppet::Environment.destroy_all
231
+ end
232
+ orgs = [taxonomies(:organization1)]
233
+ locs = [taxonomies(:location1)]
234
+ # This is the database status
235
+ # and should result in a db_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
236
+ as_admin do
237
+ %w[a b c].each { |name| ForemanPuppet::Puppetclass.create name: name }
238
+ %w[env1 env2].each do |name|
239
+ e = ForemanPuppet::Environment.create!(name: name, organizations: orgs, locations: locs)
240
+ e.puppetclasses = ForemanPuppet::Puppetclass.all
241
+ end
242
+ end
243
+ # This is the on-disk status
244
+ # and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
245
+ envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
246
+ pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => nil, 'params' => { 'key' => 'special' } })]
247
+ classes = pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }.to_h
248
+ ForemanPuppet::Environment.expects(:puppetEnvs).returns(envs).at_least(0)
249
+ ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
250
+ ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end
@@ -194,8 +194,8 @@ module ForemanPuppet
194
194
 
195
195
  def setup_import_classes
196
196
  as_admin do
197
- Host::Managed.all.each { |h| h.update(environment_id: nil) }
198
- Hostgroup.all.each { |h| h.update(environment_id: nil) }
197
+ HostPuppetFacet.destroy_all
198
+ HostgroupPuppetFacet.destroy_all
199
199
  Puppetclass.destroy_all
200
200
  Environment.destroy_all
201
201
  end
@@ -48,7 +48,6 @@ module ForemanPuppet
48
48
  setup { @routes = Rails.application.routes }
49
49
 
50
50
  test 'lookup value and description should be html escaped' do
51
- skip 'Needs complete migration to be done' unless ForemanPuppet.extracted_from_core?
52
51
  FactoryBot.create(:puppetclass_lookup_key,
53
52
  default_value: "<script>alert('hacked!');</script>",
54
53
  description: "<script>alert('hacked!');</script>",
@@ -105,8 +105,6 @@ FactoryBot.define do
105
105
  evaluator.parameter_count.times do
106
106
  evaluator.environments.each do |env|
107
107
  FactoryBot.create :puppetclass_lookup_key, override: false, puppetclass: pc, environment: env
108
- # for Host#managed validation, once extracted_from_core? we can remove
109
- env.reload
110
108
  end
111
109
  end
112
110
  else
@@ -0,0 +1,34 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetclassLookupKeysHelperTest < ActionView::TestCase
5
+ include PuppetclassLookupKeysHelper
6
+
7
+ describe '#overridable_puppet_lookup_keys' do
8
+ let(:parent_puppet_var) { FactoryBot.create(:puppetclass_lookup_key) }
9
+ let(:parent_hg) { FactoryBot.create(:hostgroup, :with_puppet_enc, environment: parent_puppet_var.environments.first) }
10
+
11
+ context 'with new hostgroup' do
12
+ subject do
13
+ hg = Hostgroup.new(parent: parent_hg)
14
+ hg.build_puppet
15
+ hg
16
+ end
17
+
18
+ it 'returns inherited parameter' do
19
+ keys = overridable_puppet_lookup_keys(parent_puppet_var.param_classes.first, subject)
20
+ _(keys).must_include(parent_puppet_var)
21
+ end
22
+ end
23
+
24
+ context 'with new host' do
25
+ subject { Host.new(hostgroup: parent_hg) }
26
+
27
+ it 'returns inherited parameter' do
28
+ keys = overridable_puppet_lookup_keys(parent_puppet_var.param_classes.first, subject)
29
+ _(keys).must_include(parent_puppet_var)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_puppet_helper'
2
+ require 'integration_test_helper'
3
+ require 'integration/shared/host_finders'
4
+ require 'integration/shared/host_orchestration_stubs'
5
+
6
+ module ForemanPuppet
7
+ class DashboardJSTest < IntegrationTestWithJavascript
8
+ setup do
9
+ Dashboard::Manager.reset_user_to_default(users(:admin))
10
+ Setting[:outofsync_interval] = 35
11
+ end
12
+
13
+ context 'with origin' do
14
+ setup do
15
+ Setting[:puppet_out_of_sync_disabled] = true
16
+ end
17
+
18
+ context 'out of sync disabled' do
19
+ test 'has no out of sync link' do
20
+ visit dashboard_path
21
+ wait_for_ajax
22
+ within "li[data-name='Host Configuration Status for Puppet']" do
23
+ assert page.has_no_link?('Out of sync hosts')
24
+ assert page.has_no_link?('Good host reports in the last')
25
+ assert page.has_link?('Good host with reports')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -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'