foreman_puppet 0.0.1 → 1.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -7
  3. data/app/controllers/concerns/foreman_puppet/environments_import.rb +1 -1
  4. data/app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb +28 -0
  5. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +1 -1
  6. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
  7. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  8. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +3 -10
  9. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +2 -2
  10. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +9 -1
  11. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +5 -2
  12. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +9 -1
  13. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +9 -1
  14. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +1 -2
  15. data/app/controllers/foreman_puppet/api/v2/{base_controller.rb → puppet_base_controller.rb} +2 -3
  16. data/app/controllers/foreman_puppet/api/v2/{lookups_common_controller.rb → puppet_lookups_common_controller.rb} +6 -2
  17. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +5 -1
  18. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +1 -2
  19. data/app/controllers/foreman_puppet/config_groups_controller.rb +4 -0
  20. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +4 -0
  21. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +2 -2
  22. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +12 -4
  23. data/app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb +29 -0
  24. data/app/graphgl/concerns/foreman_puppet/types/host_extensions.rb +13 -0
  25. data/app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb +13 -0
  26. data/app/graphgl/concerns/foreman_puppet/types/interface_attributes_input_extensions.rb +9 -0
  27. data/app/graphgl/concerns/foreman_puppet/types/location_extensions.rb +14 -0
  28. data/app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb +14 -0
  29. data/app/graphgl/foreman_puppet/types/environment.rb +20 -0
  30. data/app/graphgl/foreman_puppet/types/puppetclass.rb +20 -0
  31. data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
  32. data/app/helpers/foreman_puppet/hosts_helper.rb +15 -0
  33. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +2 -2
  34. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +1 -1
  35. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +2 -2
  36. data/app/models/concerns/foreman_puppet/extensions/host.rb +24 -9
  37. data/app/models/concerns/foreman_puppet/extensions/host_common.rb +17 -0
  38. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +13 -7
  39. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +1 -1
  40. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +19 -13
  41. data/app/models/concerns/foreman_puppet/extensions/report.rb +18 -0
  42. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +1 -1
  43. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +1 -1
  44. data/app/models/concerns/foreman_puppet/extensions/user.rb +19 -12
  45. data/app/models/foreman_puppet/environment.rb +2 -0
  46. data/app/models/foreman_puppet/environment_class.rb +1 -1
  47. data/app/models/foreman_puppet/host_class.rb +1 -1
  48. data/app/models/foreman_puppet/host_puppet_facet.rb +5 -4
  49. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +1 -1
  50. data/app/models/{concerns/foreman_puppet/host_common.rb → foreman_puppet/puppet_facet_common.rb} +1 -1
  51. data/app/models/foreman_puppet/puppetclass.rb +15 -1
  52. data/app/{views/api/v2/template_combinations/base.json.erb → prepend_views/api/v2/template_combinations/base.json.rabl} +0 -0
  53. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +2 -0
  54. data/app/services/foreman_puppet/puppet_class_importer.rb +17 -18
  55. data/app/views/foreman_puppet/common/_puppetclasses_or_envs_changed.html.erb +62 -0
  56. data/app/views/foreman_puppet/config_groups/index.html.erb +2 -2
  57. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -11
  58. data/app/views/foreman_puppet/environments/index.html.erb +1 -1
  59. data/app/views/foreman_puppet/environments/welcome.html.erb +3 -15
  60. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +10 -8
  61. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +1 -1
  62. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +1 -1
  63. data/app/views/foreman_puppet/puppetclasses/index.html.erb +1 -1
  64. data/app/views/hosts/_form_puppet_enc_tab.html.erb +1 -1
  65. data/app/views/hosts/select_multiple_environment.html.erb +1 -1
  66. data/app/views/smart_proxies/plugins/_puppet_ca.html.erb +44 -0
  67. data/config/initializers/api_reroute.rb +13 -0
  68. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +37 -12
  69. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +13 -1
  70. data/lib/foreman_puppet.rb +3 -3
  71. data/lib/foreman_puppet/engine.rb +68 -19
  72. data/lib/foreman_puppet/register.rb +7 -2
  73. data/lib/foreman_puppet/version.rb +1 -1
  74. data/locale/Makefile +1 -1
  75. data/locale/action_names.rb +4 -4
  76. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  77. data/locale/en/foreman_puppet.edit.po +19 -3
  78. data/locale/en/foreman_puppet.po +18 -6
  79. data/locale/en/foreman_puppet.pox +0 -0
  80. data/locale/foreman_puppet.pot +19 -3
  81. data/locale/messages.mo +0 -0
  82. data/package.json +45 -0
  83. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +7 -3
  84. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +18 -16
  85. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +3 -2
  86. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +1 -1
  87. data/test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb +32 -0
  88. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +3 -0
  89. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +7 -1
  90. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +2 -2
  91. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +7 -3
  92. data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
  93. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +2 -2
  94. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +5 -6
  95. data/test/factories/foreman_puppet_factories.rb +3 -0
  96. data/test/factories/host_puppet_enhancements.rb +6 -6
  97. data/test/graphql/mutations/hosts/create_mutation_test.rb +87 -0
  98. data/test/graphql/queries/environment_query_test.rb +54 -0
  99. data/test/graphql/queries/environments_query_test.rb +43 -0
  100. data/test/{qraphql → graphql}/queries/host_puppet_query_test.rb +3 -8
  101. data/test/{qraphql → graphql}/queries/hostgroup_puppet_query_test.rb +1 -6
  102. data/test/graphql/queries/location_query_test.rb +52 -0
  103. data/test/graphql/queries/organization_query_test.rb +52 -0
  104. data/test/graphql/queries/puppetclass_query_test.rb +68 -0
  105. data/test/graphql/queries/puppetclasses_query_test.rb +43 -0
  106. data/test/integration/foreman_puppet/environment_js_test.rb +4 -1
  107. data/test/integration/foreman_puppet/host_js_test.rb +1 -1
  108. data/test/integration/foreman_puppet/puppetclass_js_test.rb +4 -0
  109. data/test/models/foreman_puppet/config_group_class_test.rb +3 -1
  110. data/test/models/foreman_puppet/environment_test.rb +2 -0
  111. data/test/models/foreman_puppet/host_puppet_facet_test.rb +34 -1
  112. data/test/models/foreman_puppet/host_test.rb +4 -3
  113. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +2 -3
  114. data/test/models/foreman_puppet/provisioning_template_test.rb +14 -7
  115. data/test/models/foreman_puppet/report_test.rb +21 -0
  116. data/test/models/foreman_puppet/smart_proxy_test.rb +1 -1
  117. data/test/models/foreman_puppet/user_test.rb +37 -0
  118. data/test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb +35 -0
  119. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +159 -197
  120. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +16 -2
  121. data/webpack/index.js +3 -4
  122. data/webpack/src/Components/Environments/Welcome.js +37 -0
  123. metadata +54 -14
File without changes
@@ -8,8 +8,8 @@ msgid ""
8
8
  msgstr ""
9
9
  "Project-Id-Version: foreman_puppet 1.0.0\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2021-02-02 04:11+0100\n"
12
- "PO-Revision-Date: 2021-02-02 04:11+0100\n"
11
+ "POT-Creation-Date: 2021-02-03 18:00+0100\n"
12
+ "PO-Revision-Date: 2021-02-03 18:00+0100\n"
13
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
15
  "Language: \n"
@@ -1071,6 +1071,22 @@ msgstr ""
1071
1071
  msgid "Loading parameters..."
1072
1072
  msgstr ""
1073
1073
 
1074
+ #: action_names.rb:2
1075
+ msgid "Action with sub plans"
1076
+ msgstr ""
1077
+
1078
+ #: action_names.rb:3
1079
+ msgid "Import facts"
1080
+ msgstr ""
1081
+
1082
+ #: action_names.rb:4
1083
+ msgid "Import Puppet classes"
1084
+ msgstr ""
1085
+
1086
+ #: action_names.rb:5
1087
+ msgid "Remote action:"
1088
+ msgstr ""
1089
+
1074
1090
  #: gemspec.rb:2
1075
- msgid "TODO: Description of ForemanPuppetEnc."
1091
+ msgid "Allow assigning Puppet environmets and classes to the Foreman Hosts."
1076
1092
  msgstr ""
Binary file
data/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "foreman_puppet",
3
+ "version": "1.0.0",
4
+ "description": "DESCRIPTION",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "test": "tfm-test --plugin",
9
+ "test:watch": "tfm-test --plugin --watchAll",
10
+ "test:current": "tfm-test --plugin --watch",
11
+ "publish-coverage": "tfm-publish-coverage",
12
+ "stories": "tfm-stories --plugin",
13
+ "stories:build": "tfm-build-stories --plugin",
14
+ "create-react-component": "yo react-domain"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/theforeman/foreman_puppet.git"
19
+ },
20
+ "bugs": {
21
+ "url": "http://projects.theforeman.org/projects/foreman_puppet/issues"
22
+ },
23
+ "peerDependencies": {
24
+ "@theforeman/vendor": ">= 6.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/core": "^7.7.0",
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",
35
+ "babel-eslint": "^10.0.3",
36
+ "eslint": "^6.7.2",
37
+ "prettier": "^1.19.1",
38
+ "stylelint-config-standard": "^18.0.0",
39
+ "stylelint": "^9.3.0"
40
+ },
41
+ "dependencies": {
42
+ "jed": "^1.1.1",
43
+ "react-intl": "^2.8.0"
44
+ }
45
+ }
@@ -6,18 +6,22 @@ module ForemanPuppet
6
6
  setup do
7
7
  @routes = ForemanPuppet::Engine.routes
8
8
  end
9
+
10
+ let(:puppetclasses) { FactoryBot.create_list(:puppetclass, 2) }
11
+ let(:config_group) { FactoryBot.create(:config_group) }
12
+
9
13
  test 'should create config group' do
10
14
  assert_difference('ConfigGroup.count') do
11
- post :create, params: { config_group: { name: 'config-group', puppetclass_ids: [puppetclasses(:one).id, puppetclasses(:four).id] } }
15
+ post :create, params: { config_group: { name: 'config-group', puppetclass_ids: puppetclasses.map(&:id) } }
12
16
  end
13
17
  assert_response :created
14
18
  end
15
19
 
16
20
  test 'should update config group' do
17
21
  name = 'new name'
18
- put :update, params: { id: config_groups(:one).to_param,
22
+ put :update, params: { id: config_group.to_param,
19
23
  config_group: { name: name,
20
- puppetclass_ids: [puppetclasses(:one).id, puppetclasses(:four).id] } }
24
+ puppetclass_ids: puppetclasses.map(&:id) } }
21
25
  assert_response :success
22
26
  response = JSON.parse(@response.body)
23
27
  assert_equal 2, response['puppetclasses'].count
@@ -106,7 +106,7 @@ module ForemanPuppet
106
106
 
107
107
  test 'should destroy environments' do
108
108
  environment
109
- assert_difference('Environment.unscoped.count', -1) do
109
+ assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, -1) do
110
110
  delete :destroy, params: { id: environment.to_param }
111
111
  end
112
112
  assert_response :success
@@ -171,12 +171,14 @@ module ForemanPuppet
171
171
  test 'should obsolete environment' do
172
172
  setup_import_classes
173
173
  as_admin do
174
- Environment.create!(name: 'xyz')
175
- end
176
- assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, -1) do
177
- post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
174
+ FactoryBot.create(:environment, name: 'xyz')
178
175
  end
176
+
177
+ post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
179
178
  assert_response :success
179
+ as_admin do
180
+ assert_nil ForemanPuppet::Environment.find_by(name: 'xyz')
181
+ end
180
182
  end
181
183
 
182
184
  test 'should obsolete puppetclasses' do
@@ -313,30 +315,30 @@ module ForemanPuppet
313
315
 
314
316
  def setup_import_classes
315
317
  as_admin do
316
- Host::Managed.update_all(environment_id: nil)
317
- Hostgroup.update_all(environment_id: nil)
318
- HostClass.destroy_all
319
- HostgroupClass.destroy_all
320
- Puppetclass.destroy_all
321
- Environment.destroy_all
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
322
324
  end
323
325
  orgs = [taxonomies(:organization1)]
324
326
  locs = [taxonomies(:location1)]
325
327
  # This is the database status
326
328
  # and should result in a db_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
327
329
  as_admin do
328
- %w[a b c].each { |name| Puppetclass.create name: name }
330
+ %w[a b c].each { |name| ForemanPuppet::Puppetclass.create name: name }
329
331
  %w[env1 env2].each do |name|
330
- e = Environment.create!(name: name, organizations: orgs, locations: locs)
331
- e.puppetclasses = Puppetclass.all
332
+ e = ForemanPuppet::Environment.create!(name: name, organizations: orgs, locations: locs)
333
+ e.puppetclasses = ForemanPuppet::Puppetclass.all
332
334
  end
333
335
  end
334
336
  # This is the on-disk status
335
337
  # and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
336
338
  envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
337
339
  pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => nil, 'params' => { 'key' => 'special' } })]
338
- classes = Hash[pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }]
339
- Environment.expects(:puppetEnvs).returns(envs).at_least(0)
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)
340
342
  ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
341
343
  ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
342
344
  end
@@ -61,10 +61,11 @@ module ForemanPuppet
61
61
  end
62
62
 
63
63
  describe '#create' do
64
- test 'should create with puppet proxy' do
64
+ test 'should create with puppet proxy and environment' do
65
65
  host_params = FactoryBot.attributes_for(:host, managed: false).merge(environment_id: environment.id, puppet_proxy_id: puppet_proxy.to_param)
66
66
  post :create, params: { host: host_params }
67
67
  assert_response :created
68
+ assert_equal environment.name, JSON.parse(@response.body)['environment_name'], "Can't create host environment #{environment}"
68
69
  assert_equal puppet_proxy.name, JSON.parse(@response.body)['puppet_proxy']['name'], "Can't create host with puppet proxy #{puppet_proxy}"
69
70
  end
70
71
  end
@@ -92,7 +93,7 @@ module ForemanPuppet
92
93
  assert_response :success
93
94
  response = ActiveSupport::JSON.decode(@response.body)
94
95
  puppet_class = response['data']['classes'].keys
95
- assert_equal host.puppetclasses.map(&:name), puppet_class
96
+ assert_equal host.puppet.puppetclasses.map(&:name), puppet_class
96
97
  end
97
98
  end
98
99
  end
@@ -3,7 +3,7 @@ require 'test_puppet_helper'
3
3
  module ForemanPuppet
4
4
  module Api
5
5
  module V2
6
- class DummyLookupController < ForemanPuppet::Api::V2::LookupsCommonController
6
+ class DummyLookupController < ForemanPuppet::Api::V2::PuppetLookupsCommonController
7
7
  attr_accessor :params
8
8
  end
9
9
 
@@ -0,0 +1,32 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class ProvisioningTemplatesControllerTest < ActionController::TestCase
7
+ tests ::Api::V2::ProvisioningTemplatesController
8
+
9
+ let(:environment) { FactoryBot.create(:environment) }
10
+
11
+ test 'should create provisioning template with template_combinations' do
12
+ name = RFauxFactory.gen_alpha
13
+ valid_attrs = {
14
+ name: name, template: RFauxFactory.gen_alpha, template_kind_id: template_kinds(:ipxe).id,
15
+ template_combinations_attributes: [
16
+ { hostgroup_id: hostgroups(:common).id, environment_id: environment.id },
17
+ ]
18
+ }
19
+ post :create, params: { provisioning_template: valid_attrs }
20
+ assert_response :created
21
+ response = ActiveSupport::JSON.decode(@response.body)
22
+ assert response.key?('id')
23
+ assert response.key?('template_combinations')
24
+ template_combinations = response['template_combinations']
25
+ assert_equal 1, template_combinations.length
26
+ template_combination = TemplateCombination.find(template_combinations[0]['id'])
27
+ assert_equal response['id'], template_combination.provisioning_template_id
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -35,18 +35,21 @@ module ForemanPuppet
35
35
 
36
36
  context 'with taxonomy given' do
37
37
  test 'index should return puppetclasses only in Organization' do
38
+ puppetclass
38
39
  get :index, params: { organization_id: default_organization.id }
39
40
  assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
40
41
  assert_response :success
41
42
  end
42
43
 
43
44
  test 'index should return puppetclasses only in Organization' do
45
+ puppetclass
44
46
  get :index, params: { location_id: default_location.id }
45
47
  assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
46
48
  assert_response :success
47
49
  end
48
50
 
49
51
  test 'index should return puppetclasses only in Organization' do
52
+ puppetclass
50
53
  get :index, params: { location_id: default_location.id, organization_id: default_organization.id }
51
54
  assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
52
55
  assert_response :success
@@ -207,11 +207,17 @@ module ForemanPuppet
207
207
 
208
208
  test_attributes pid: 'd7b1c336-bd9f-40a3-a573-939f2a021cdc'
209
209
  test 'should not set merge overrides for non supported types' do
210
+ expected_error = if Gem::Version.new(SETTINGS[:version].notag) < Gem::Version.new('2.6')
211
+ 'Validation failed: Merge overrides can only be set for array or hash'
212
+ else
213
+ 'Validation failed: Merge overrides can only be set for array, hash, json or yaml'
214
+ end
215
+
210
216
  put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
211
217
  default_value: RFauxFactory.gen_alpha,
212
218
  merge_overrides: true } }
213
219
  assert_response :internal_server_error, 'Can set merge overrides for non supported types'
214
- assert_error_message('Validation failed: Merge overrides can only be set for array or hash')
220
+ assert_error_message(expected_error)
215
221
  assert_not(lookup_key.reload.merge_overrides)
216
222
  end
217
223
 
@@ -64,8 +64,8 @@ module ForemanPuppet
64
64
  environment_id: template_combination.environment.id, id: template_combination.id }
65
65
 
66
66
  json_response = ActiveSupport::JSON.decode(@response.body)
67
- assert_equal(json_response['environment_id'], environment.id)
68
- assert_equal(json_response['hostgroup_id'], hostgroups(:common).id)
67
+ assert_equal(environment.id, json_response['environment_id'])
68
+ assert_equal(hostgroups(:common).id, json_response['hostgroup_id'])
69
69
  assert_response :success
70
70
  end
71
71
 
@@ -9,7 +9,10 @@ module ForemanPuppet
9
9
  basic_pagination_per_page_test
10
10
  basic_pagination_rendered_test
11
11
 
12
+ let(:config_group) { FactoryBot.create(:config_group) }
13
+
12
14
  test 'should get index' do
15
+ config_group
13
16
  get :index, session: set_session_user
14
17
  assert_response :success
15
18
  assert_not_empty assigns(:config_groups)
@@ -28,18 +31,19 @@ module ForemanPuppet
28
31
  end
29
32
 
30
33
  test 'should get edit' do
31
- get :edit, params: { id: config_groups(:one) }, session: set_session_user
34
+ get :edit, params: { id: config_group }, session: set_session_user
32
35
  assert_response :success
33
36
  end
34
37
 
35
38
  test 'should update config_group' do
36
- put :update, params: { id: config_groups(:one), config_group: { name: 'new name' } }, session: set_session_user
39
+ put :update, params: { id: config_group, config_group: { name: 'new name' } }, session: set_session_user
37
40
  assert_redirected_to config_groups_path
38
41
  end
39
42
 
40
43
  test 'should destroy config_group' do
44
+ config_group
41
45
  assert_difference('ForemanPuppet::ConfigGroup.count', -1) do
42
- delete :destroy, params: { id: config_groups(:three) }, session: set_session_user
46
+ delete :destroy, params: { id: config_group }, session: set_session_user
43
47
  end
44
48
  assert_redirected_to config_groups_path
45
49
  end
@@ -170,7 +170,7 @@ module ForemanPuppet
170
170
 
171
171
  test 'user with viewer rights should fail to edit an environment' do
172
172
  setup_user
173
- get :edit, params: { id: environments(:production).name }, session: set_session_user.merge(user: users(:one).id)
173
+ get :edit, params: { id: FactoryBot.create(:environment).name }, session: set_session_user.merge(user: users(:one).id)
174
174
  assert_equal(403, @response.status)
175
175
  end
176
176
 
@@ -215,7 +215,7 @@ module ForemanPuppet
215
215
  # and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
216
216
  envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
217
217
  pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => '', 'params' => {} })]
218
- classes = Hash[pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }]
218
+ classes = pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }.to_h
219
219
  Environment.expects(:puppetEnvs).returns(envs).at_least(0)
220
220
  ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
221
221
  ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
@@ -4,10 +4,10 @@ module ForemanPuppet
4
4
  class PuppetclassLookupKeysControllerTest < ActionController::TestCase
5
5
  setup do
6
6
  @routes = ForemanPuppet::Engine.routes
7
- @factory_options = [{ puppetclass: puppetclasses(:one), override: true, default_value: 'test' }]
7
+ @factory_options = [{ puppetclass: FactoryBot.create(:puppetclass), override: true, default_value: 'test' }]
8
8
  end
9
9
 
10
- let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclasses(:one), override: true) }
10
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, override: true) }
11
11
 
12
12
  basic_pagination_rendered_test
13
13
  basic_pagination_per_page_test
@@ -60,23 +60,22 @@ module ForemanPuppet
60
60
 
61
61
  test 'new db rows are not added to HostClass when POST to parameters' do
62
62
  host = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
63
- host_puppetclass_ids = host.host_classes.pluck(:puppetclass_id)
63
+ host_puppetclass_ids = host.puppet.host_classes.pluck(:puppetclass_id)
64
64
  params = { id: puppetclass.id,
65
65
  host_id: host.id,
66
- host: { puppetclass_ids: (host_puppetclass_ids + [puppetclass.id]) } }
67
- assert_difference('HostClass.count', 0) do
66
+ host: { puppet: { puppetclass_ids: (host_puppetclass_ids + [puppetclass.id]) } } }
67
+ assert_difference(-> { ForemanPuppet::HostClass.count }, 0) do
68
68
  post :parameters, params: params, session: set_session_user
69
69
  end
70
70
  end
71
71
 
72
72
  test 'new db rows are not added to HostgroupClass when POST to parameters' do
73
- skip 'dont know how to achieve for now' unless ForemanPuppet.extracted_from_core?
74
73
  hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
75
74
  hostgroup_puppetclass_ids = hostgroup.puppet.hostgroup_classes.pluck(:puppetclass_id)
76
75
  params = { id: puppetclass.id,
77
76
  host_id: hostgroup.id,
78
- hostgroup: { puppetclass_ids: (hostgroup_puppetclass_ids + [puppetclass.id]) } }
79
- assert_difference('ForemanPuppet::HostgroupClass.count', 0) do
77
+ hostgroup: { puppet: { puppetclass_ids: (hostgroup_puppetclass_ids + [puppetclass.id]) } } }
78
+ assert_difference(-> { ForemanPuppet::HostgroupClass.count }, 0) do
80
79
  post :parameters, params: params, session: set_session_user
81
80
  end
82
81
  end
@@ -105,11 +105,14 @@ 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
108
110
  end
109
111
  end
110
112
  else
111
113
  evaluator.environments.each do |env|
112
114
  FactoryBot.create :environment_class, puppetclass: pc, environment: env unless env.nil?
115
+ env.reload
113
116
  end
114
117
  end
115
118
  end
@@ -2,21 +2,21 @@ FactoryBot.modify do
2
2
  factory :host do
3
3
  trait :with_puppetclass do
4
4
  transient do
5
- environment
5
+ environment { FactoryBot.create(:environment) }
6
6
  puppetclasses { [FactoryBot.create(:puppetclass, environments: [environment])] }
7
7
  end
8
8
  end
9
9
 
10
10
  trait :with_config_group do
11
11
  transient do
12
- environment
12
+ environment { FactoryBot.create(:environment) }
13
13
  config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
14
14
  end
15
15
  end
16
16
 
17
17
  trait :with_puppet_enc do
18
18
  transient do
19
- environment
19
+ environment { FactoryBot.create(:environment) }
20
20
  puppetclasses { [] }
21
21
  config_groups { [] }
22
22
  end
@@ -30,14 +30,14 @@ FactoryBot.modify do
30
30
  factory :hostgroup do
31
31
  trait :with_puppetclass do
32
32
  transient do
33
- environment
33
+ environment { FactoryBot.create(:environment) }
34
34
  puppetclasses { [FactoryBot.create(:puppetclass, environments: [environment])] }
35
35
  end
36
36
  end
37
37
 
38
38
  trait :with_puppet_enc do
39
39
  transient do
40
- environment
40
+ environment { FactoryBot.create(:environment) }
41
41
  puppetclasses { [] }
42
42
  config_groups { [] }
43
43
  end
@@ -49,7 +49,7 @@ FactoryBot.modify do
49
49
 
50
50
  trait :with_config_group do
51
51
  transient do
52
- environment
52
+ environment { FactoryBot.create(:environment) }
53
53
  config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
54
54
  end
55
55
  end