foreman_puppet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +38 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/stylesheets/foreman_puppet.scss +117 -0
  6. data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
  7. data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
  8. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
  9. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
  10. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
  11. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
  12. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
  13. data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
  14. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
  15. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
  16. data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
  17. data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
  18. data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
  19. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
  20. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
  21. data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
  22. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
  23. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
  24. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
  25. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
  26. data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
  27. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
  28. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
  29. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
  30. data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
  31. data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
  32. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
  33. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
  34. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
  35. data/app/controllers/foreman_puppet/react_controller.rb +19 -0
  36. data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
  37. data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
  38. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
  39. data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
  40. data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
  41. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
  42. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
  43. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
  44. data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
  45. data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
  46. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
  47. data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
  48. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
  49. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
  50. data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
  51. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
  52. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
  53. data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
  54. data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
  55. data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
  56. data/app/models/foreman_puppet/config_group.rb +45 -0
  57. data/app/models/foreman_puppet/config_group_class.rb +19 -0
  58. data/app/models/foreman_puppet/environment.rb +63 -0
  59. data/app/models/foreman_puppet/environment_class.rb +40 -0
  60. data/app/models/foreman_puppet/host_class.rb +23 -0
  61. data/app/models/foreman_puppet/host_config_group.rb +15 -0
  62. data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
  63. data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
  64. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
  65. data/app/models/foreman_puppet/puppetclass.rb +132 -0
  66. data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
  67. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
  68. data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
  69. data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
  70. data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
  71. data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
  72. data/app/views/api/v2/template_combinations/base.json.erb +9 -0
  73. data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
  74. data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
  75. data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
  76. data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
  77. data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
  78. data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
  79. data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
  80. data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
  81. data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
  82. data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
  83. data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
  84. data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
  85. data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
  86. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
  87. data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
  88. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
  89. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
  90. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
  91. data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
  92. data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
  93. data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
  94. data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
  95. data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
  96. data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
  97. data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
  98. data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
  99. data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
  100. data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
  101. data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
  102. data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
  103. data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
  104. data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
  105. data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
  106. data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
  107. data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
  108. data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
  109. data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
  110. data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
  111. data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
  112. data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
  113. data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
  114. data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
  115. data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
  116. data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
  117. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
  118. data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
  119. data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
  120. data/app/views/foreman_puppet/environments/index.html.erb +32 -0
  121. data/app/views/foreman_puppet/environments/new.html.erb +7 -0
  122. data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
  123. data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
  124. data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
  125. data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
  126. data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
  127. data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
  128. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
  129. data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
  130. data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
  131. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
  132. data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
  133. data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
  134. data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
  135. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
  136. data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
  137. data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
  138. data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
  139. data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
  140. data/app/views/hosts/select_multiple_environment.html.erb +8 -0
  141. data/app/views/provisioning_templates/_combination.html.erb +5 -0
  142. data/app/views/provisioning_templates/_combinations.html.erb +6 -0
  143. data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
  144. data/config/api_routes.rb +81 -0
  145. data/config/routes.rb +89 -0
  146. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
  147. data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
  148. data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
  149. data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
  150. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
  151. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
  152. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
  153. data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
  154. data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
  155. data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
  156. data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
  157. data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
  158. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
  159. data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
  160. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
  161. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
  162. data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
  163. data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
  164. data/lib/foreman_puppet.rb +10 -0
  165. data/lib/foreman_puppet/engine.rb +82 -0
  166. data/lib/foreman_puppet/register.rb +218 -0
  167. data/lib/foreman_puppet/version.rb +3 -0
  168. data/lib/tasks/foreman_puppet_tasks.rake +31 -0
  169. data/locale/Makefile +60 -0
  170. data/locale/action_names.rb +5 -0
  171. data/locale/en/foreman_puppet.edit.po +911 -0
  172. data/locale/en/foreman_puppet.po +690 -0
  173. data/locale/en/foreman_puppet.po.time_stamp +0 -0
  174. data/locale/foreman_puppet.pot +1076 -0
  175. data/locale/gemspec.rb +2 -0
  176. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
  177. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
  178. data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
  179. data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
  180. data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
  181. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
  182. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
  183. data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
  184. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
  185. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
  186. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
  187. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
  188. data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
  189. data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
  190. data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
  191. data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
  192. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
  193. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
  194. data/test/controllers/provisioning_templates_controller_test.rb +70 -0
  195. data/test/factories/foreman_puppet_factories.rb +134 -0
  196. data/test/factories/host_puppet_enhancements.rb +61 -0
  197. data/test/factories/proxy_puppet_enhancements.rb +33 -0
  198. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
  199. data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
  200. data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
  201. data/test/integration/foreman_puppet/host_js_test.rb +371 -0
  202. data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
  203. data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
  204. data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
  205. data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
  206. data/test/models/foreman_puppet/config_group_test.rb +8 -0
  207. data/test/models/foreman_puppet/environment_test.rb +92 -0
  208. data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
  209. data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
  210. data/test/models/foreman_puppet/host_test.rb +288 -0
  211. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
  212. data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
  213. data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
  214. data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
  215. data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
  216. data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
  217. data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
  218. data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
  219. data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
  220. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
  221. data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
  222. data/test/test_puppet_helper.rb +30 -0
  223. data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
  224. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
  225. data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
  226. data/test/unit/foreman_puppet_test.rb +11 -0
  227. data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
  228. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
  229. data/webpack/__mocks__/foremanReact/readme.md +11 -0
  230. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  231. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  232. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  233. data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
  234. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  235. data/webpack/fills_index.js +30 -0
  236. data/webpack/index.js +18 -0
  237. data/webpack/src/ForemanPuppet.js +11 -0
  238. data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
  239. data/webpack/src/Router/index.js +14 -0
  240. data/webpack/src/Router/routes.js +3 -0
  241. data/webpack/src/Router/routes.test.js +16 -0
  242. data/webpack/src/foreman_class_edit.js +224 -0
  243. data/webpack/src/foreman_puppet_host_form.js +140 -0
  244. data/webpack/src/foreman_puppet_host_form.test.js +65 -0
  245. data/webpack/src/index.js +1 -0
  246. data/webpack/src/reducers.js +7 -0
  247. metadata +340 -0
@@ -0,0 +1,79 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class HostgroupsControllerTest < ActionController::TestCase
7
+ tests ::Api::V2::HostgroupsController
8
+
9
+ let(:hostgroup) { FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass, :with_config_group) }
10
+ let(:non_puppet) { FactoryBot.create(:hostgroup, ptable: templates(:autopart)) }
11
+ let(:inherited) { FactoryBot.create(:hostgroup, :with_puppet_enc, parent: non_puppet) }
12
+
13
+ describe '#show' do
14
+ test 'includes puppetclasses under puppet node' do
15
+ get :show, params: { id: hostgroup.to_param }
16
+ assert_response :success
17
+ json_response = ActiveSupport::JSON.decode(response.body)
18
+ assert json_response['puppet']['puppetclasses'].is_a? Array
19
+ response_pg_ids = json_response['puppet']['puppetclasses'].map { |pg| pg['id'] }
20
+ assert_equal hostgroup.puppet.puppetclasses.pluck(:id), response_pg_ids
21
+ end
22
+
23
+ test 'include config_groups under puppet node' do
24
+ get :show, params: { id: hostgroup.to_param }
25
+ assert_response :success
26
+ json_response = ActiveSupport::JSON.decode(response.body)
27
+ assert json_response['puppet']['config_groups'].is_a? Array
28
+ response_cg_ids = json_response['puppet']['config_groups'].map { |cg| cg['id'] }
29
+ assert_equal hostgroup.puppet.config_groups.pluck(:id), response_cg_ids
30
+ end
31
+
32
+ test 'include all_puppet clases for individual record under puppet node' do
33
+ get :show, params: { id: hostgroup.id }
34
+ assert_response :success
35
+ show_response = ActiveSupport::JSON.decode(response.body)
36
+ assert_not show_response.empty?
37
+ assert_not_equal 0, show_response['puppet']['all_puppetclasses'].length
38
+ end
39
+
40
+ test 'includes puppetclasses for backward compatibility' do
41
+ get :show, params: { id: hostgroup.to_param }
42
+ assert_response :success
43
+ json_response = ActiveSupport::JSON.decode(response.body)
44
+ assert json_response['puppetclasses'].is_a? Array
45
+ response_pg_ids = json_response['puppetclasses'].map { |pg| pg['id'] }
46
+ assert_equal hostgroup.puppet.puppetclasses.pluck(:id), response_pg_ids
47
+ end
48
+
49
+ test 'include config_groups for backward compatibility' do
50
+ get :show, params: { id: hostgroup.to_param }
51
+ assert_response :success
52
+ json_response = ActiveSupport::JSON.decode(response.body)
53
+ assert json_response['config_groups'].is_a? Array
54
+ response_cg_ids = json_response['config_groups'].map { |cg| cg['id'] }
55
+ assert_equal hostgroup.puppet.config_groups.pluck(:id), response_cg_ids
56
+ end
57
+
58
+ test 'include all_puppet clases for individual record' do
59
+ get :show, params: { id: hostgroup.id }
60
+ assert_response :success
61
+ show_response = ActiveSupport::JSON.decode(response.body)
62
+ assert_not show_response.empty?
63
+ assert_not_equal 0, show_response['all_puppetclasses'].length
64
+ end
65
+
66
+ test 'should show inherited parameters' do
67
+ get :show, params: { id: inherited.to_param }
68
+ assert_response :success
69
+ show_response = ActiveSupport::JSON.decode(@response.body)
70
+ assert_equal inherited.puppet.environment_id, show_response['environment_id']
71
+ assert_nil show_response['inherited_environment_id']
72
+ assert_nil show_response['ptable_id']
73
+ assert_equal templates(:autopart).id, show_response['inherited_ptable_id']
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,101 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class HostsControllerTest < ActionController::TestCase
7
+ tests ::Api::V2::HostsController
8
+
9
+ let(:host) { FactoryBot.create(:host, :with_puppet_enc) }
10
+ let(:environment) do
11
+ FactoryBot.create(:environment, :with_puppetclass, organizations: [host.organization], locations: [host.location])
12
+ end
13
+ let(:puppet_proxy) { FactoryBot.create(:puppet_smart_proxy) }
14
+
15
+ describe '#show' do
16
+ test 'includes config_groups under puppet node' do
17
+ get :show, params: { id: host.to_param }
18
+ assert_response :success
19
+ json_response = ActiveSupport::JSON.decode(response.body)
20
+ assert json_response['puppet']['config_groups'].is_a? Array
21
+ response_cg_ids = json_response['puppet']['config_groups'].map { |cg| cg['id'] }
22
+ assert_equal host.puppet.config_groups.pluck(:id), response_cg_ids
23
+ end
24
+
25
+ test 'includes puppetclasses under puppet node' do
26
+ get :show, params: { id: host.to_param }
27
+ assert_response :success
28
+ json_response = ActiveSupport::JSON.decode(response.body)
29
+ assert json_response['puppet']['puppetclasses'].is_a? Array
30
+ response_pg_ids = json_response['puppet']['puppetclasses'].map { |pg| pg['id'] }
31
+ assert_equal host.puppet.puppetclasses.pluck(:id), response_pg_ids
32
+ end
33
+
34
+ test 'includes config_groups for backward compatibility' do
35
+ get :show, params: { id: host.to_param }
36
+ assert_response :success
37
+ json_response = ActiveSupport::JSON.decode(response.body)
38
+ assert json_response['config_groups'].is_a? Array
39
+ response_cg_ids = json_response['config_groups'].map { |cg| cg['id'] }
40
+ assert_equal host.puppet.config_groups.pluck(:id), response_cg_ids
41
+ end
42
+
43
+ test 'includes puppetclasses for backward compatibility' do
44
+ get :show, params: { id: host.to_param }
45
+ assert_response :success
46
+ json_response = ActiveSupport::JSON.decode(response.body)
47
+ assert json_response['puppetclasses'].is_a? Array
48
+ response_pg_ids = json_response['puppetclasses'].map { |pg| pg['id'] }
49
+ assert_equal host.puppet.puppetclasses.pluck(:id), response_pg_ids
50
+ end
51
+
52
+ test 'should show host puppet_proxy_name' do
53
+ # cover issue #16525
54
+ host.update(puppet_proxy: puppet_proxy)
55
+ get :show, params: { id: host.to_param }
56
+ assert_response :success
57
+ json = ActiveSupport::JSON.decode(response.body)
58
+ assert json.key?('puppet_proxy_name')
59
+ assert_equal puppet_proxy.name, json['puppet_proxy_name']
60
+ end
61
+ end
62
+
63
+ describe '#create' do
64
+ test 'should create with puppet proxy' do
65
+ host_params = FactoryBot.attributes_for(:host, managed: false).merge(environment_id: environment.id, puppet_proxy_id: puppet_proxy.to_param)
66
+ post :create, params: { host: host_params }
67
+ assert_response :created
68
+ assert_equal puppet_proxy.name, JSON.parse(@response.body)['puppet_proxy']['name'], "Can't create host with puppet proxy #{puppet_proxy}"
69
+ end
70
+ end
71
+
72
+ describe '#update' do
73
+ test 'should update with puppet proxy' do
74
+ put :update, params: { id: host.id, host: host.attributes.merge(puppet_proxy_id: puppet_proxy.id) }
75
+ assert_response :success
76
+ assert_equal puppet_proxy['name'], JSON.parse(@response.body)['puppet_proxy']['name'], "Can't update host with puppet proxy #{puppet_proxy}"
77
+ end
78
+
79
+ test 'should update with puppet class' do
80
+ puppetclass = environment.puppetclasses.first
81
+ put :update, params: { id: host.id, host: { environment_id: environment.id, puppetclass_ids: [puppetclass.id] } }
82
+ assert_response :success
83
+ response = JSON.parse(@response.body)
84
+ assert_equal environment.id, response['environment_id'], "Can't update host with environment #{environment}"
85
+ assert_equal puppetclass.id, response['puppetclasses'][0]['id'], "Can't update host with puppetclass #{puppetclass}"
86
+ end
87
+ end
88
+
89
+ describe '#enc' do
90
+ test 'should get ENC values of host' do
91
+ get :enc, params: { id: host.to_param }
92
+ assert_response :success
93
+ response = ActiveSupport::JSON.decode(@response.body)
94
+ puppet_class = response['data']['classes'].keys
95
+ assert_equal host.puppetclasses.map(&:name), puppet_class
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class DummyLookupController < ForemanPuppet::Api::V2::LookupsCommonController
7
+ attr_accessor :params
8
+ end
9
+
10
+ class LookupsCommonControllerTest < ActiveSupport::TestCase
11
+ setup do
12
+ @dummy = DummyLookupController.new
13
+ end
14
+
15
+ test 'should cast default_value from smart class parameter' do
16
+ @dummy.params = { smart_class_parameter: { default_value: %w[a b] } }
17
+ @dummy.cast_value(:smart_class_parameter, :default_value)
18
+ assert_equal %w[a b].to_s, @dummy.params[:smart_class_parameter][:default_value]
19
+ end
20
+
21
+ test 'should cast value from override value' do
22
+ @dummy.params = { override_value: { value: 123 } }
23
+ @dummy.cast_value
24
+ assert_equal '123', @dummy.params[:override_value][:value]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,169 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class OverrideValuesControllerTest < ActionController::TestCase
7
+ setup do
8
+ @routes = ForemanPuppet::Engine.routes
9
+ lookup_key
10
+ end
11
+
12
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, path: %w[hostgroup comment os].join("\n")) }
13
+ let(:lookup_value) { FactoryBot.create(:lookup_value, lookup_key: lookup_key, match: 'os=default') }
14
+
15
+ test 'should get override values for specific smart class parameter' do
16
+ lookup_value
17
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, match: 'comment=override')
18
+ get :index, params: { smart_class_parameter_id: lookup_key.to_param }
19
+ assert_response :success
20
+ override_values = ActiveSupport::JSON.decode(@response.body)
21
+ assert_not_empty override_values
22
+ assert_equal 2, override_values['results'].length
23
+ end
24
+
25
+ test 'should create override values for specific smart class parameter' do
26
+ assert_difference('LookupValue.count') do
27
+ post :create, params: { smart_class_parameter_id: lookup_key.to_param, override_value: { match: 'os=abc', value: 'liftoff' } }
28
+ end
29
+ assert_response :created
30
+ end
31
+
32
+ test 'should show specific override values for specific smart class parameter' do
33
+ get :show, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.id }
34
+ results = ActiveSupport::JSON.decode(@response.body)
35
+ assert_not_empty results
36
+ assert_equal 'os=default', results['match']
37
+ assert_response :success
38
+ end
39
+
40
+ test 'should show specific override values using match' do
41
+ get :show, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.match }
42
+ results = ActiveSupport::JSON.decode(@response.body)
43
+ assert_not_empty results
44
+ assert_equal 'os=default', results['match']
45
+ assert_response :success
46
+ end
47
+
48
+ test 'should update specific override value' do
49
+ put :update, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.id, override_value: { match: 'os=abc' } }
50
+ assert_response :success
51
+ end
52
+ test 'should update specific override value using match' do
53
+ put :update, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.match, override_value: { match: 'os=abc' } }
54
+ assert_response :success
55
+ end
56
+
57
+ test 'should destroy specific override value' do
58
+ lookup_value
59
+ assert_difference('LookupValue.count', -1) do
60
+ delete :destroy, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.id }
61
+ end
62
+ assert_response :success
63
+ end
64
+ test 'should destroy specific override value using match' do
65
+ lookup_value
66
+ assert_difference('LookupValue.count', -1) do
67
+ delete :destroy, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.match }
68
+ end
69
+ assert_response :success
70
+ end
71
+
72
+ [{ value: 'xyz=10' }, { match: 'os=string' }].each do |override_value|
73
+ test "should not create override value without #{override_value.keys.first}" do
74
+ assert_difference('LookupValue.count', 0) do
75
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: override_value }
76
+ end
77
+ response = ActiveSupport::JSON.decode(@response.body)
78
+ param_not_posted = (override_value.keys.first.to_s == 'match') ? 'Value' : 'Match' # The opposite of override_value is missing
79
+ assert_match(/Validation failed: #{param_not_posted} can't be blank/, response['error']['message'])
80
+ assert_response :error
81
+ end
82
+ end
83
+
84
+ test_attributes pid: '2b205e9c-e50c-48cd-8ebb-3b6bea09be77'
85
+ test 'should create override value without when omit is true' do
86
+ value = RFauxFactory.gen_alpha
87
+ assert_difference('LookupValue.count', 1) do
88
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'os=string', value: value, omit: true } }
89
+ end
90
+ assert_response :success
91
+ lookup_key.reload
92
+ assert_equal('os=string', lookup_key.override_values.first.match)
93
+ assert_equal lookup_key.override_values.first.value, value
94
+ assert(lookup_key.override_values.first.omit)
95
+ end
96
+
97
+ test 'should not create override value without when omit is false' do
98
+ assert_difference('LookupValue.count', 0) do
99
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'os=string', omit: false } }
100
+ end
101
+ assert_response :error
102
+ end
103
+
104
+ test_attributes pid: 'bef0e457-16be-4ca6-bc56-fa32dff55a01'
105
+ test 'should not create invalid matcher for non existing attribute' do
106
+ assert_difference('LookupValue.count', 0) do
107
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'hostgroup=nonexistingHG', value: RFauxFactory.gen_alpha } }
108
+ end
109
+ assert_includes JSON.parse(response.body)['error']['message'], 'Validation failed: Match hostgroup=nonexistingHG does not match an existing host group'
110
+ end
111
+
112
+ test_attributes pid: '49de2c9b-40f1-4837-8ebb-dfa40d8fcb89'
113
+ test 'should not create matcher with blank matcher value' do
114
+ lookup_key.update(required: true)
115
+ assert_difference('LookupValue.count', 0) do
116
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'os=string', value: '' } }
117
+ end
118
+ assert_includes JSON.parse(response.body)['error']['message'], "Validation failed: Value can't be blank"
119
+ end
120
+
121
+ test_attributes pid: '21668ef4-1a7a-41cb-98e3-dc4c664db351'
122
+ test 'should not create matcher with value that does not matches default type' do
123
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, :boolean)
124
+ assert_difference('LookupValue.count', 0) do
125
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'os=string', value: RFauxFactory.gen_alpha } }
126
+ end
127
+ assert_includes JSON.parse(response.body)['error']['message'], 'Validation failed: Value is invalid'
128
+ end
129
+
130
+ test_attributes pid: '19d319e6-9b12-485e-a680-c84d18742c40'
131
+ test 'should create matcher for attribute in parameter' do
132
+ value = RFauxFactory.gen_alpha
133
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, override_value_order: 'is_virtual')
134
+ assert_difference('LookupValue.count') do
135
+ post :create, params: { smart_class_parameter_id: lookup_key.id, override_value: { match: 'is_virtual=true', value: value } }
136
+ end
137
+ lookup_key.reload
138
+ assert_equal('is_virtual=true', lookup_key.override_values.first.match)
139
+ assert_equal lookup_key.override_values.first.value, value
140
+ end
141
+
142
+ context 'hidden' do
143
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, hidden_value: true, default_value: 'hidden') }
144
+
145
+ test 'should show a override value as hidden unless show_hidden is true' do
146
+ get :show, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.to_param }
147
+ show_response = ActiveSupport::JSON.decode(@response.body)
148
+ assert_equal lookup_value.hidden_value, show_response['value']
149
+ end
150
+
151
+ test 'should show override value unhidden when show_hidden is true' do
152
+ get :show, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.to_param, show_hidden: 'true' }
153
+ show_response = ActiveSupport::JSON.decode(@response.body)
154
+ assert_equal lookup_value.value, show_response['value']
155
+ end
156
+
157
+ test 'should show a override value parameter as hidden when user in unauthorized for smart class variable' do
158
+ setup_user 'view', 'puppetclasses'
159
+ setup_user 'view', 'external_parameters'
160
+ setup_user 'edit', 'external_variables'
161
+ get :show, params: { smart_class_parameter_id: lookup_key.to_param, id: lookup_value.to_param, show_hidden: 'true' }
162
+ show_response = ActiveSupport::JSON.decode(@response.body)
163
+ assert_equal lookup_value.hidden_value, show_response['value']
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,144 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class PuppetclassesControllerTest < ActionController::TestCase
7
+ let(:valid_attrs) { { name: 'PuppetClassValidName' } }
8
+
9
+ let(:default_organization) { Organization.first }
10
+ let(:default_location) { Location.first }
11
+ let(:environment) do
12
+ FactoryBot.create(:environment, locations: [default_location], organizations: [default_organization])
13
+ end
14
+ let(:puppetclass) { FactoryBot.create(:puppetclass, environments: [environment]) }
15
+ let(:eager_load) { puppetclass }
16
+
17
+ setup do
18
+ @routes = ForemanPuppet::Engine.routes
19
+ eager_load
20
+ end
21
+
22
+ test 'should get index' do
23
+ get :index
24
+ assert_response :success
25
+ assert_not json_response.empty?
26
+ assert json_response['results'].is_a?(Hash)
27
+ end
28
+
29
+ test 'should get index with style=list' do
30
+ get :index, params: { style: 'list' }
31
+ assert_response :success
32
+ assert_not json_response.empty?
33
+ assert json_response['results'].is_a?(Array)
34
+ end
35
+
36
+ context 'with taxonomy given' do
37
+ test 'index should return puppetclasses only in Organization' do
38
+ get :index, params: { organization_id: default_organization.id }
39
+ assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
40
+ assert_response :success
41
+ end
42
+
43
+ test 'index should return puppetclasses only in Organization' do
44
+ get :index, params: { location_id: default_location.id }
45
+ assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
46
+ assert_response :success
47
+ end
48
+
49
+ test 'index should return puppetclasses only in Organization' do
50
+ get :index, params: { location_id: default_location.id, organization_id: default_organization.id }
51
+ assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
52
+ assert_response :success
53
+ end
54
+ end
55
+
56
+ test 'should create puppetclass' do
57
+ assert_difference(-> { ForemanPuppet::Puppetclass.count }) do
58
+ post :create, params: { puppetclass: valid_attrs }
59
+ end
60
+ assert_response :created
61
+ assert Puppetclass.exists?(name: valid_attrs[:name])
62
+ end
63
+
64
+ test 'should update puppetclass' do
65
+ put :update, params: { id: puppetclass.to_param, puppetclass: valid_attrs }
66
+ assert_response :success
67
+ assert_equal valid_attrs[:name], puppetclass.reload.name
68
+ end
69
+
70
+ test 'should destroy puppetclasss' do
71
+ assert_difference(-> { ForemanPuppet::Puppetclass.count }, -1) do
72
+ delete :destroy, params: { id: puppetclass.to_param }
73
+ end
74
+ assert_response :success
75
+ end
76
+
77
+ test 'should get puppetclasses for given host only' do
78
+ host1 = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
79
+ FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
80
+ get :index, params: { host_id: host1.to_param }
81
+ assert_response :success
82
+ assert_equal host1.puppet.puppetclasses.map(&:name).sort, json_response['results'].keys.sort
83
+ end
84
+
85
+ test 'should not get puppetclasses for nonexistent host' do
86
+ get :index, params: { 'search' => 'host = imaginaryhost.nodomain.what' }
87
+ assert_response :success
88
+ assert_empty json_response['results']
89
+ end
90
+
91
+ test 'should get puppetclasses for hostgroup' do
92
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
93
+ get :index, params: { hostgroup_id: hostgroup.to_param }
94
+ assert_response :success
95
+ assert_not json_response['results'].empty?
96
+ assert_equal hostgroup.puppet.puppetclasses.map(&:name).sort, json_response['results'].keys.sort
97
+ end
98
+
99
+ test 'should get puppetclasses for environment' do
100
+ environment = FactoryBot.create(:environment, :with_puppetclass)
101
+ get :index, params: { environment_id: environment.to_param }
102
+ assert_response :success
103
+ assert_not json_response['results'].empty?
104
+ assert_equal environment.puppetclasses.map(&:name).sort, json_response['results'].keys.sort
105
+ end
106
+
107
+ test 'should show error if optional nested environment does not exist' do
108
+ get :index, params: { environment_id: 'nonexistent' }
109
+ assert_response 404
110
+ assert_equal "Environment not found by id 'nonexistent'", json_response['message']
111
+ end
112
+
113
+ test 'should show puppetclass for host' do
114
+ host = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
115
+ get :show, params: { host_id: host.to_param, id: host.puppet.puppetclasses.first.id }
116
+ assert_response :success
117
+ assert_not_empty json_response
118
+ end
119
+
120
+ test 'should show puppetclass for hostgroup' do
121
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
122
+ get :show, params: { hostgroup_id: hostgroup.to_param, id: hostgroup.puppet.puppetclasses.first.id }
123
+ assert_response :success
124
+ assert_not_empty json_response
125
+ end
126
+
127
+ test 'should show puppetclass for environment' do
128
+ environment = FactoryBot.create(:environment, :with_puppetclass)
129
+ get :show, params: { environment_id: environment, id: environment.puppetclasses.first.id }
130
+ assert_response :success
131
+ assert_not_empty json_response
132
+ end
133
+
134
+ test 'should not remove puppetclass params' do
135
+ FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclass)
136
+ assert_equal 1, puppetclass.class_params.length
137
+ put :update, params: { id: puppetclass.id, smart_class_parameter_ids: [] }
138
+ puppetclass.reload
139
+ assert_equal 1, puppetclass.class_params.length
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end