foreman_puppet 2.0.2 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/app/controllers/concerns/foreman_puppet/extensions/api_smart_proxies_controller.rb +7 -2
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +1 -1
- data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +1 -1
- data/app/views/foreman_puppet/config_groups/_config_group.html.erb +5 -1
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +5 -4
- data/db/migrate/20220201205305_migrate_host_class_permission.foreman_puppet.rb +9 -0
- data/db/migrate/20220208135305_migrate_environment_ignore_type.foreman_puppet.rb +15 -0
- data/db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb +3 -1
- data/lib/foreman_puppet/register.rb +2 -1
- data/lib/foreman_puppet/version.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +24 -18
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +10 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/environments_controller_test.rb +1 -1
- data/test/controllers/foreman_puppet/hosts_controller_test.rb +4 -27
- data/test/graphql/queries/environment_query_test.rb +4 -4
- data/test/graphql/queries/puppetclass_query_test.rb +4 -4
- data/test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb +34 -0
- data/test/integration/foreman_puppet/dashboard_js_test.rb +1 -2
- data/test/integration/foreman_puppet/environment_js_test.rb +1 -2
- data/test/integration/foreman_puppet/host_js_test.rb +31 -27
- data/test/integration/foreman_puppet/hostgroup_js_test.rb +1 -2
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -2
- data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +1 -2
- data/test/integration_puppet_helper.rb +3 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +13 -2
- data/test/models/foreman_puppet/host_test.rb +22 -22
- data/test/models/foreman_puppet/provisioning_template_test.rb +3 -3
- data/test/models/foreman_puppet/puppetclass_test.rb +1 -1
- data/test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb +1 -1
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +3 -3
- data/test/unit/foreman_puppet/template_rendering_test.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ff3828222cc632f3ede70b60d3789bc68cd9565a501293ff037d16f089e875
|
4
|
+
data.tar.gz: 4446e0632671fe04ac826ae0c6ca1315ffe2dc4555acf252ee93c7a322b9f0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8176437ecad24bbcbd707459114bedbadd20905ba031142cf9634aec2efe77adf6c790412b65162358c016df2999739c8b4b2f4d4c322d56673325ccf3aa65b
|
7
|
+
data.tar.gz: 723ab74a3fc1b20954e446018508bd61fd35ea04fce200049cb306f04ee6240289ec136d34b00a4873ec51e211781fdb93722baabf04bcf19b777a4f211a85af
|
data/README.md
CHANGED
@@ -37,7 +37,9 @@ You can install it on Foreman 2.5 to prepare for the Foreman update.
|
|
37
37
|
|
38
38
|
|Foreman version|Plugin version|Notes |
|
39
39
|
|---------------|--------------|------------------------------------------|
|
40
|
-
| >= 3.
|
40
|
+
| >= 3.2 | ~> 3.0 | Required |
|
41
|
+
| ~> 3.1 | ~> 2.0 | Required |
|
42
|
+
| ~> 3.0 | ~> 1.0 | Required |
|
41
43
|
| >= 2.5 | ~> 0.1 | Optional; replaces Core features |
|
42
44
|
| < 2.5 | - | Not supported (functionality is in Core) |
|
43
45
|
|
@@ -3,6 +3,8 @@ module ForemanPuppet
|
|
3
3
|
module ApiSmartProxiesController
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
NewEnvironment = Struct.new('Environment', :name)
|
7
|
+
|
6
8
|
included do
|
7
9
|
before_action :find_required_puppet_proxy, only: [:import_puppetclasses]
|
8
10
|
before_action :find_environment_id, only: [:import_puppetclasses]
|
@@ -70,7 +72,7 @@ module ForemanPuppet
|
|
70
72
|
@changed['updated'].keys + @changed['ignored'].keys).uniq.sort
|
71
73
|
|
72
74
|
@environments = environment_names.map do |name|
|
73
|
-
|
75
|
+
NewEnvironment.new(name)
|
74
76
|
end
|
75
77
|
|
76
78
|
unless @environments.any?
|
@@ -87,6 +89,7 @@ module ForemanPuppet
|
|
87
89
|
@environments.any?
|
88
90
|
end
|
89
91
|
|
92
|
+
# rubocop:disable Metrics/MethodLength
|
90
93
|
def import_changed_proxy_environments
|
91
94
|
opts = { url: @smart_proxy.url }
|
92
95
|
opts[:env] = if @environment.present?
|
@@ -98,7 +101,8 @@ module ForemanPuppet
|
|
98
101
|
changed = @importer.changes
|
99
102
|
|
100
103
|
# check if environemnt id passed in URL is name of NEW environment in puppetmaster that doesn't exist in db
|
101
|
-
|
104
|
+
@environment ||= NewEnvironment.new(@env_id) if changed['new'].key?(@env_id)
|
105
|
+
if @environment
|
102
106
|
# only return :keys equal to @environment in @changed hash
|
103
107
|
%w[new obsolete updated ignored].each do |kind|
|
104
108
|
changed[kind].slice!(@environment.name) unless changed[kind].empty?
|
@@ -115,6 +119,7 @@ module ForemanPuppet
|
|
115
119
|
render_message(msg, status: :internal_server_error)
|
116
120
|
nil
|
117
121
|
end
|
122
|
+
# rubocop:enable Metrics/MethodLength
|
118
123
|
|
119
124
|
def find_required_puppet_proxy
|
120
125
|
id = params.key?('smart_proxy_id') ? params['smart_proxy_id'] : params['id']
|
@@ -3,7 +3,7 @@ module ForemanPuppet
|
|
3
3
|
module HostsControllerExtensions
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
PUPPETMASTER_ACTIONS = %i[externalNodes
|
6
|
+
PUPPETMASTER_ACTIONS = %i[externalNodes].freeze
|
7
7
|
PUPPET_AJAX_REQUESTS = %w[hostgroup_or_environment_selected puppetclass_parameters].freeze
|
8
8
|
|
9
9
|
MULTIPLE_EDIT_ACTIONS = %w[select_multiple_environment update_multiple_environment
|
@@ -9,7 +9,7 @@ module ForemanPuppet
|
|
9
9
|
# ------ Host(group) Form Helpers -----
|
10
10
|
|
11
11
|
def overridable_puppet_lookup_keys(klass, obj)
|
12
|
-
klass.class_params.override.where(environment_classes: { environment_id: obj.
|
12
|
+
klass.class_params.override.where(environment_classes: { environment_id: obj.environment })
|
13
13
|
end
|
14
14
|
|
15
15
|
def hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled)
|
@@ -5,7 +5,7 @@ module ForemanPuppet
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
has_many :environments, through: :template_combinations
|
8
|
-
before_destroy
|
8
|
+
before_destroy EnsureNotUsedBy.new(:environments)
|
9
9
|
|
10
10
|
scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
|
11
11
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
<%
|
2
|
+
li_id = "#{added ? 'selected_' : '' }config_group_#{config_group.id}"
|
3
|
+
li_class = "#{added ? 'selected_config_group' : 'config_group'} #{css_class}"
|
4
|
+
%>
|
5
|
+
<%= content_tag :li, id: li_id, class: li_class do %>
|
2
6
|
<%= hidden_field_tag("#{type}[config_group_ids][]", config_group.id) if added == 'manually' %>
|
3
7
|
<span>
|
4
8
|
<%= link_to(icon_text('plus', config_group.name), '#', :rel=>'twipsy', :class => 'config_group_name',
|
@@ -11,13 +11,14 @@
|
|
11
11
|
<% end %>
|
12
12
|
|
13
13
|
<%= render 'foreman_puppet/puppetclasses/class_selection', obj: obj, resource_type: resource_type %>
|
14
|
+
|
15
|
+
<fieldset id="puppet_klasses_parameters" data-url="<%= foreman_puppet.url_for(controller: resource_type.to_s.pluralize.to_sym, action: :puppetclass_parameters, only_path: true) %>">
|
16
|
+
<h2><%= _('Puppet Class Parameters') %></h2>
|
17
|
+
<%= render 'foreman_puppet/puppetclasses/classes_parameters', obj: subject %>
|
18
|
+
</fieldset>
|
14
19
|
<% else %>
|
15
20
|
<%= alert(class: alert_class(:info),
|
16
21
|
header: _('Notice'),
|
17
22
|
text: _('Please select an environment first')) %>
|
18
23
|
<% end %>
|
19
24
|
|
20
|
-
<fieldset id="puppet_klasses_parameters" data-url="<%= foreman_puppet.url_for(controller: resource_type.to_s.pluralize.to_sym, action: :puppetclass_parameters, only_path: true) %>">
|
21
|
-
<h2><%= _('Puppet Class Parameters') %></h2>
|
22
|
-
<%= render 'foreman_puppet/puppetclasses/classes_parameters', obj: subject %>
|
23
|
-
</fieldset>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MigrateEnvironmentIgnoreType < ActiveRecord::Migration[6.0]
|
2
|
+
def up
|
3
|
+
taxonomies = Taxonomy.unscoped.where("ignore_types LIKE '%Environment%'")
|
4
|
+
environment_ids = ForemanPuppet::Environment.unscoped.pluck(:id)
|
5
|
+
|
6
|
+
taxonomies.each do |tax|
|
7
|
+
new_types = tax.ignore_types.reject { |type| type == 'Environment' }
|
8
|
+
tax.update_columns(ignore_types: new_types)
|
9
|
+
taxable_rows = environment_ids.map do |env_id|
|
10
|
+
{ taxable_id: env_id, taxable_type: 'ForemanPuppet::Environment', taxonomy_id: tax.id }
|
11
|
+
end
|
12
|
+
TaxableTaxonomy.insert_all(taxable_rows) if taxable_rows.any?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class CreateHostgroupsPuppetclasses < ActiveRecord::Migration[6.0]
|
2
2
|
def up
|
3
|
-
|
3
|
+
# this table is later renamed into hostgroup_classes and thus we don't want to create it if it exists under the later name
|
4
|
+
return if table_exists?(:hostgroups_puppetclasses) || table_exists?(:hostgroup_classes)
|
5
|
+
create_table :hostgroups_puppetclasses, id: false do |t|
|
4
6
|
t.references :hostgroup, foreign_key: true, null: false
|
5
7
|
t.references :puppetclass, foreign_key: true, null: false
|
6
8
|
end
|
@@ -147,7 +147,8 @@ Foreman::Plugin.register :foreman_puppet do
|
|
147
147
|
permission :import_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[import_environments obsolete_and_new],
|
148
148
|
'foreman_puppet/api/v2/environments' => [:import_puppetclasses] },
|
149
149
|
resource_type: 'ForemanPuppet::Puppetclass'
|
150
|
-
permission :edit_classes, {
|
150
|
+
permission :edit_classes, { :host_editing => [:edit_classes],
|
151
|
+
'foreman_puppet/api/v2/host_classes' => %i[index create destroy] },
|
151
152
|
resource_type: 'ForemanPuppet::HostClass'
|
152
153
|
end
|
153
154
|
|
@@ -11,27 +11,33 @@ module ForemanPuppet
|
|
11
11
|
let(:environment_attrs) { { name: 'Development' } }
|
12
12
|
let(:environment) { FactoryBot.create(:environment) }
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
describe 'GET #index' do
|
15
|
+
it 'gets index' do
|
16
|
+
environment
|
17
|
+
get :index
|
18
|
+
assert_response :success
|
19
|
+
assert_not_nil assigns(:environments)
|
20
|
+
envs = ActiveSupport::JSON.decode(@response.body)
|
21
|
+
assert_not envs.empty?
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
it 'shows environment by id' do
|
25
|
+
get :show, params: { id: environment.id }
|
26
|
+
assert_response :success
|
27
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
it 'shows environment by to_param' do
|
31
|
+
get :show, params: { id: environment.to_param }
|
32
|
+
assert_response :success
|
33
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
it 'shows environment by name' do
|
37
|
+
get :show, params: { id: environment.name }
|
38
|
+
assert_response :success
|
39
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
test 'should create environment' do
|
@@ -79,12 +79,22 @@ module ForemanPuppet
|
|
79
79
|
|
80
80
|
test 'should update with puppet class' do
|
81
81
|
puppetclass = environment.puppetclasses.first
|
82
|
+
# uses the deprecated version of params passing without namespace, to test it works :)
|
82
83
|
put :update, params: { id: host.id, host: { environment_id: environment.id, puppetclass_ids: [puppetclass.id] } }
|
83
84
|
assert_response :success
|
84
85
|
response = JSON.parse(@response.body)
|
85
86
|
assert_equal environment.id, response['environment_id'], "Can't update host with environment #{environment}"
|
86
87
|
assert_equal puppetclass.id, response['puppetclasses'][0]['id'], "Can't update host with puppetclass #{puppetclass}"
|
87
88
|
end
|
89
|
+
|
90
|
+
test 'should remove puppetclass by passing empty array' do
|
91
|
+
host2 = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
|
92
|
+
|
93
|
+
put :update, params: { id: host2.id, host: { puppet_attributes: { puppetclass_ids: [] } } }
|
94
|
+
assert_response :success
|
95
|
+
response = JSON.parse(@response.body)
|
96
|
+
assert_empty(response['puppetclasses'], 'Can not remove puppetclasses')
|
97
|
+
end
|
88
98
|
end
|
89
99
|
|
90
100
|
describe '#enc' do
|
@@ -421,7 +421,7 @@ module ForemanPuppet
|
|
421
421
|
|
422
422
|
test_attributes pid: 'd5d5f084-fa62-4ec3-90ea-9fcabd7bda4f'
|
423
423
|
test 'validate default value with list' do
|
424
|
-
values_list = [RFauxFactory.gen_alpha, RFauxFactory.gen_alphanumeric, rand(100..1 << 64), [true, false].sample]
|
424
|
+
values_list = [RFauxFactory.gen_alpha, RFauxFactory.gen_alphanumeric, rand(100..(1 << 64)), [true, false].sample]
|
425
425
|
values_list_str = values_list.join(', ')
|
426
426
|
value = values_list.sample
|
427
427
|
put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
|
@@ -437,7 +437,7 @@ module ForemanPuppet
|
|
437
437
|
|
438
438
|
test_attributes pid: 'd5df7804-9633-4ef8-a065-10807351d230'
|
439
439
|
test 'validate default value with regexp' do
|
440
|
-
value = rand(1..1 << 64)
|
440
|
+
value = rand(1..(1 << 64))
|
441
441
|
put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
|
442
442
|
default_value: value,
|
443
443
|
validator_type: 'regexp',
|
@@ -107,7 +107,7 @@ module ForemanPuppet
|
|
107
107
|
{ 'env3' => '[]' } } }, session: set_session_user
|
108
108
|
assert_redirected_to environments_url
|
109
109
|
assert_equal 'Successfully updated environments and Puppet classes from the on-disk Puppet installation', flash[:success]
|
110
|
-
|
110
|
+
assert_empty Environment.unscoped.find_by(name: 'env3').puppetclasses.map(&:name).sort
|
111
111
|
end
|
112
112
|
|
113
113
|
test 'should fail to remove active environments' do
|
@@ -201,7 +201,6 @@ module ForemanPuppet
|
|
201
201
|
test 'hosts with a registered smart proxy on should get externalNodes successfully' do
|
202
202
|
User.current = nil
|
203
203
|
Setting[:restrict_registered_smart_proxies] = true
|
204
|
-
Setting[:require_ssl_smart_proxies] = false
|
205
204
|
|
206
205
|
Resolv.any_instance.stubs(:getnames).returns(['else.where'])
|
207
206
|
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
@@ -211,7 +210,6 @@ module ForemanPuppet
|
|
211
210
|
test 'hosts without a registered smart proxy on should not be able to get externalNodes' do
|
212
211
|
User.current = nil
|
213
212
|
Setting[:restrict_registered_smart_proxies] = true
|
214
|
-
Setting[:require_ssl_smart_proxies] = false
|
215
213
|
|
216
214
|
Resolv.any_instance.stubs(:getnames).returns(['another.host'])
|
217
215
|
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
@@ -221,7 +219,6 @@ module ForemanPuppet
|
|
221
219
|
test 'hosts with a registered smart proxy and SSL cert should get externalNodes successfully' do
|
222
220
|
User.current = nil
|
223
221
|
Setting[:restrict_registered_smart_proxies] = true
|
224
|
-
Setting[:require_ssl_smart_proxies] = true
|
225
222
|
|
226
223
|
@request.env['HTTPS'] = 'on'
|
227
224
|
@request.env['SSL_CLIENT_S_DN'] = 'CN=else.where'
|
@@ -234,7 +231,6 @@ module ForemanPuppet
|
|
234
231
|
test 'hosts in trusted hosts list and SSL cert should get externalNodes successfully' do
|
235
232
|
User.current = nil
|
236
233
|
Setting[:restrict_registered_smart_proxies] = true
|
237
|
-
Setting[:require_ssl_smart_proxies] = true
|
238
234
|
Setting[:trusted_hosts] = ['else.where']
|
239
235
|
|
240
236
|
@request.env['HTTPS'] = 'on'
|
@@ -248,7 +244,6 @@ module ForemanPuppet
|
|
248
244
|
test 'hosts with comma-separated SSL DN should get externalNodes successfully' do
|
249
245
|
User.current = nil
|
250
246
|
Setting[:restrict_registered_smart_proxies] = true
|
251
|
-
Setting[:require_ssl_smart_proxies] = true
|
252
247
|
Setting[:trusted_hosts] = ['foreman.example']
|
253
248
|
|
254
249
|
@request.env['HTTPS'] = 'on'
|
@@ -262,7 +257,6 @@ module ForemanPuppet
|
|
262
257
|
test 'hosts with slash-separated SSL DN should get externalNodes successfully' do
|
263
258
|
User.current = nil
|
264
259
|
Setting[:restrict_registered_smart_proxies] = true
|
265
|
-
Setting[:require_ssl_smart_proxies] = true
|
266
260
|
Setting[:trusted_hosts] = ['foreman.linux.lab.local']
|
267
261
|
|
268
262
|
@request.env['HTTPS'] = 'on'
|
@@ -276,53 +270,37 @@ module ForemanPuppet
|
|
276
270
|
test 'hosts without a registered smart proxy but with an SSL cert should not be able to get externalNodes' do
|
277
271
|
User.current = nil
|
278
272
|
Setting[:restrict_registered_smart_proxies] = true
|
279
|
-
Setting[:require_ssl_smart_proxies] = true
|
280
273
|
|
281
274
|
@request.env['HTTPS'] = 'on'
|
282
275
|
@request.env['SSL_CLIENT_S_DN'] = 'CN=another.host'
|
283
276
|
@request.env['SSL_CLIENT_VERIFY'] = 'SUCCESS'
|
284
277
|
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
285
|
-
|
278
|
+
assert_response :forbidden
|
286
279
|
end
|
287
280
|
|
288
281
|
test 'hosts with an unverified SSL cert should not be able to get externalNodes' do
|
289
282
|
User.current = nil
|
290
283
|
Setting[:restrict_registered_smart_proxies] = true
|
291
|
-
Setting[:require_ssl_smart_proxies] = true
|
292
284
|
|
293
285
|
@request.env['HTTPS'] = 'on'
|
294
286
|
@request.env['SSL_CLIENT_S_DN'] = 'CN=else.where'
|
295
287
|
@request.env['SSL_CLIENT_VERIFY'] = 'FAILURE'
|
296
288
|
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
297
|
-
|
289
|
+
assert_response :forbidden
|
298
290
|
end
|
299
291
|
|
300
|
-
test 'when "
|
292
|
+
test 'when "require_ssl" is true, HTTP requests should not be able to get externalNodes' do
|
301
293
|
User.current = nil
|
302
294
|
Setting[:restrict_registered_smart_proxies] = true
|
303
|
-
Setting[:require_ssl_smart_proxies] = true
|
304
295
|
SETTINGS[:require_ssl] = true
|
305
296
|
|
306
297
|
Resolv.any_instance.stubs(:getnames).returns(['else.where'])
|
307
298
|
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
308
|
-
|
309
|
-
end
|
310
|
-
|
311
|
-
test 'when "require_ssl_smart_proxies" is true and "require_ssl" is false, HTTP requests should be able to get externalNodes' do
|
312
|
-
User.current = nil
|
313
|
-
# since require_ssl_smart_proxies is only applicable to HTTPS connections, both should be set
|
314
|
-
Setting[:restrict_registered_smart_proxies] = true
|
315
|
-
Setting[:require_ssl_smart_proxies] = true
|
316
|
-
SETTINGS[:require_ssl] = false
|
317
|
-
|
318
|
-
Resolv.any_instance.stubs(:getnames).returns(['else.where'])
|
319
|
-
get :externalNodes, params: { name: host1.name, format: 'yml' }
|
320
|
-
assert_response :success
|
299
|
+
assert_response :redirect
|
321
300
|
end
|
322
301
|
|
323
302
|
test 'authenticated users over HTTP should be able to get externalNodes' do
|
324
303
|
Setting[:restrict_registered_smart_proxies] = true
|
325
|
-
Setting[:require_ssl_smart_proxies] = true
|
326
304
|
SETTINGS[:require_ssl] = false
|
327
305
|
|
328
306
|
Resolv.any_instance.stubs(:getnames).returns(['users.host'])
|
@@ -332,7 +310,6 @@ module ForemanPuppet
|
|
332
310
|
|
333
311
|
test 'authenticated users over HTTPS should be able to get externalNodes' do
|
334
312
|
Setting[:restrict_registered_smart_proxies] = true
|
335
|
-
Setting[:require_ssl_smart_proxies] = true
|
336
313
|
SETTINGS[:require_ssl] = false
|
337
314
|
|
338
315
|
Resolv.any_instance.stubs(:getnames).returns(['users.host'])
|
@@ -42,10 +42,10 @@ module Queries
|
|
42
42
|
test 'fetching environment attributes' do
|
43
43
|
assert_empty result['errors']
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
expect(data['name']).must_equal(environment.name)
|
46
|
+
expect(data['id']).must_equal(global_id)
|
47
|
+
expect(data['createdAt']).must_equal(environment.created_at.utc.iso8601)
|
48
|
+
expect(data['updatedAt']).must_equal(environment.updated_at.utc.iso8601)
|
49
49
|
|
50
50
|
assert_collection environment.locations, data['locations']
|
51
51
|
assert_collection environment.organizations, data['organizations']
|
@@ -55,10 +55,10 @@ module Queries
|
|
55
55
|
test 'fetching puppetclass attributes' do
|
56
56
|
assert_empty result['errors']
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
expect(data['id']).must_equal global_id
|
59
|
+
expect(data['createdAt']).must_equal puppetclass.created_at.utc.iso8601
|
60
|
+
expect(data['updatedAt']).must_equal puppetclass.updated_at.utc.iso8601
|
61
|
+
expect(data['name']).must_equal puppetclass.name
|
62
62
|
|
63
63
|
assert_collection puppetclass.environments, data['environments']
|
64
64
|
assert_collection puppetclass.locations, data['locations']
|
@@ -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
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'integration_test_helper'
|
1
|
+
require 'integration_puppet_helper'
|
3
2
|
require 'integration/shared/host_finders'
|
4
3
|
require 'integration/shared/host_orchestration_stubs'
|
5
4
|
|
@@ -61,7 +60,8 @@ module ForemanPuppet
|
|
61
60
|
|
62
61
|
close_interfaces_modal
|
63
62
|
|
64
|
-
|
63
|
+
click_button('Submit')
|
64
|
+
find('h5', text: /myhost1*/)
|
65
65
|
|
66
66
|
host = Host::Managed.search_for('name ~ "myhost1"').first
|
67
67
|
assert_equal env2.name, host.puppet.environment.name
|
@@ -95,8 +95,8 @@ module ForemanPuppet
|
|
95
95
|
fill_in 'host_interfaces_attributes_0_mac', with: '00:11:11:11:11:11'
|
96
96
|
fill_in 'host_interfaces_attributes_0_ip', with: '1.1.1.1'
|
97
97
|
close_interfaces_modal
|
98
|
-
|
99
|
-
find('
|
98
|
+
click_button('Submit')
|
99
|
+
find('h5', text: /myhost1*/) # wait for host details page
|
100
100
|
|
101
101
|
host = Host::Managed.search_for('name ~ "myhost1"').first
|
102
102
|
assert_equal env.name, host.puppet.environment.name
|
@@ -112,8 +112,9 @@ module ForemanPuppet
|
|
112
112
|
visit edit_host_path(host)
|
113
113
|
|
114
114
|
select2 env1.name, from: 'host_puppet_attributes_environment_id'
|
115
|
-
|
116
|
-
|
115
|
+
click_button('Submit')
|
116
|
+
find('h5', text: /#{host.name}/)
|
117
|
+
assert_current_path(host_details_page_path(host), ignore_query: true)
|
117
118
|
|
118
119
|
host.reload
|
119
120
|
assert_equal env1.name, host.puppet.environment.name
|
@@ -202,7 +203,8 @@ module ForemanPuppet
|
|
202
203
|
assert puppetclass_params.has_selector?("a[data-tag='override']", visible: :hidden)
|
203
204
|
assert_equal('false', find("#s2id_host_lookup_values_attributes_#{lookup_key.id}_value .select2-chosen").text)
|
204
205
|
select2 'true', from: "host_lookup_values_attributes_#{lookup_key.id}_value"
|
205
|
-
|
206
|
+
click_button('Submit')
|
207
|
+
find('h5', text: /#{host.name}/)
|
206
208
|
|
207
209
|
visit edit_host_path(host)
|
208
210
|
switch_form_tab('Puppet ENC')
|
@@ -214,25 +216,27 @@ module ForemanPuppet
|
|
214
216
|
puppetclass: host.puppet.puppetclasses.first, overrides: { host.lookup_value_matcher => 'hostOverride' })
|
215
217
|
visit edit_host_path(host)
|
216
218
|
switch_form_tab('Puppet ENC')
|
217
|
-
|
219
|
+
expect(puppetclass_params.find('textarea').value).must_equal('hostOverride')
|
218
220
|
assert puppetclass_params.find('textarea:enabled')
|
219
221
|
puppetclass_params.find("a[data-tag='remove']").click
|
220
222
|
assert puppetclass_params.find('textarea:disabled')
|
221
|
-
|
223
|
+
click_button('Submit')
|
224
|
+
find('h5', text: /#{host.name}/)
|
222
225
|
|
223
226
|
visit edit_host_path(host)
|
224
227
|
switch_form_tab('Puppet ENC')
|
225
|
-
|
226
|
-
|
228
|
+
expect(puppetclass_params.find('textarea').value).must_equal('default')
|
229
|
+
expect(puppetclass_params).must_have_selector('textarea:disabled')
|
227
230
|
puppetclass_params.find("a[data-tag='override']").click
|
228
|
-
|
231
|
+
expect(puppetclass_params).must_have_selector('textarea:enabled')
|
229
232
|
puppetclass_params.find('textarea').set('userCustom')
|
230
|
-
|
233
|
+
click_button('Submit')
|
234
|
+
find('h5', text: /#{host.name}/)
|
231
235
|
|
232
236
|
visit edit_host_path(host)
|
233
237
|
switch_form_tab('Puppet ENC')
|
234
|
-
|
235
|
-
|
238
|
+
expect(puppetclass_params.find('textarea').value).must_equal('userCustom')
|
239
|
+
expect(puppetclass_params).must_have_selector('textarea:enabled')
|
236
240
|
end
|
237
241
|
|
238
242
|
test 'can override puppetclass lookup values' do
|
@@ -241,22 +245,22 @@ module ForemanPuppet
|
|
241
245
|
|
242
246
|
visit edit_host_path(host)
|
243
247
|
switch_form_tab('Puppet ENC')
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='remove']", visible: :visible)
|
249
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='override']", visible: :hidden)
|
250
|
+
expect(puppetclass_params.find('textarea').value).must_equal('hostOverride')
|
251
|
+
expect(puppetclass_params).must_have_selector('textarea:enabled')
|
248
252
|
|
249
253
|
puppetclass_params.find("a[data-tag='remove']").click
|
250
|
-
|
251
|
-
|
254
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='remove']", visible: :hidden)
|
255
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='override']", visible: :visible)
|
252
256
|
assert_equal('default', puppetclass_params.find('textarea').value)
|
253
257
|
assert puppetclass_params.find('textarea:disabled')
|
254
258
|
|
255
259
|
puppetclass_params.find("a[data-tag='override']").click
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='remove']", visible: :visible)
|
261
|
+
expect(puppetclass_params).must_have_selector("a[data-tag='override']", visible: :hidden)
|
262
|
+
expect(puppetclass_params.find('textarea').value).must_equal('default')
|
263
|
+
expect(puppetclass_params).must_have_selector('textarea:enabled')
|
260
264
|
end
|
261
265
|
|
262
266
|
context 'with non-admin user' do
|
@@ -272,7 +276,7 @@ module ForemanPuppet
|
|
272
276
|
switch_form_tab('Puppet ENC')
|
273
277
|
assert puppetclass_params.find('textarea').disabled?
|
274
278
|
click_button('Submit')
|
275
|
-
|
279
|
+
find('h5', text: /#{host.name}/)
|
276
280
|
end
|
277
281
|
end
|
278
282
|
|
@@ -53,6 +53,17 @@ module ForemanPuppet
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
describe '#puppetclass_ids=' do
|
57
|
+
test 'allows empting classes' do
|
58
|
+
host = FactoryBot.create(:host, :with_puppet_enc,
|
59
|
+
environment: environment,
|
60
|
+
puppetclasses: [puppetclass_both])
|
61
|
+
host.attributes = { puppet_attributes: { puppetclass_ids: [] } }
|
62
|
+
assert host.save, 'Host could not be saved after updating puppetclasses'
|
63
|
+
assert_empty host.reload.all_puppetclasses, 'Puppetclasses were not removed successfuly'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
56
67
|
describe '#all_puppetclasses' do
|
57
68
|
test 'should return all classes for environment only' do
|
58
69
|
host = FactoryBot.create(:host, :with_puppet_enc,
|
@@ -107,13 +118,13 @@ module ForemanPuppet
|
|
107
118
|
test 'should return empty array if host has no hostgroup' do
|
108
119
|
host = FactoryBot.create(:host, :with_puppet_enc)
|
109
120
|
assert_not host.hostgroup
|
110
|
-
|
121
|
+
assert_empty host.puppet.parent_config_groups
|
111
122
|
end
|
112
123
|
|
113
124
|
test 'should return empty array if hostgroup do not have puppet data' do
|
114
125
|
hostgroup = FactoryBot.create(:hostgroup)
|
115
126
|
host = FactoryBot.create(:host, :with_puppet_enc, hostgroup: hostgroup)
|
116
|
-
|
127
|
+
assert_empty host.puppet.parent_config_groups
|
117
128
|
end
|
118
129
|
end
|
119
130
|
|
@@ -4,13 +4,13 @@ module ForemanPuppet
|
|
4
4
|
class HostTest < ActiveSupport::TestCase
|
5
5
|
test 'should read the Puppetserver URL from its proxy settings' do
|
6
6
|
host = FactoryBot.build_stubbed(:host)
|
7
|
-
|
8
|
-
|
7
|
+
expect(host.puppet_server_uri).must_be_nil
|
8
|
+
expect(host.puppetmaster).must_be_empty
|
9
9
|
|
10
10
|
proxy = FactoryBot.create(:puppet_smart_proxy, url: 'https://smartproxy.example.com:8443')
|
11
11
|
host.puppet_proxy = proxy
|
12
|
-
|
13
|
-
|
12
|
+
expect(host.puppet_server_uri.to_s).must_equal 'https://smartproxy.example.com:8140'
|
13
|
+
expect(host.puppetmaster).must_equal 'smartproxy.example.com'
|
14
14
|
|
15
15
|
features = {
|
16
16
|
'puppet' => {
|
@@ -18,8 +18,8 @@ module ForemanPuppet
|
|
18
18
|
},
|
19
19
|
}
|
20
20
|
SmartProxyFeature.import_features(proxy, features)
|
21
|
-
|
22
|
-
|
21
|
+
expect(host.puppet_server_uri.to_s).must_equal 'https://puppet.example.com:8140'
|
22
|
+
expect(host.puppetmaster).must_equal 'puppet.example.com'
|
23
23
|
end
|
24
24
|
|
25
25
|
test 'should find smart proxy ids' do
|
@@ -141,12 +141,12 @@ module ForemanPuppet
|
|
141
141
|
host = FactoryBot.create(:host, :with_puppet_enc, :with_config_group, :with_puppetclass, :with_parameter,
|
142
142
|
hostgroup: hostgroup, environment: hostgroup.puppet.environment)
|
143
143
|
copy = host.clone
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
144
|
+
expect(copy.puppet.individual_puppetclasses.map(&:id)).must_equal(host.puppet.individual_puppetclasses.map(&:id))
|
145
|
+
expect(copy.puppet.classes_in_groups.map(&:id)).must_equal(host.puppet.classes_in_groups.map(&:id))
|
146
|
+
expect(copy.puppet.classes.map(&:id)).must_equal(host.puppet.classes.map(&:id))
|
147
|
+
expect(copy.puppet.available_puppetclasses.map(&:id)).must_equal(host.puppet.available_puppetclasses.map(&:id))
|
148
|
+
expect(copy.puppet.host_classes.map(&:puppetclass_id)).must_equal(host.puppet.host_classes.map(&:puppetclass_id))
|
149
|
+
expect(copy.puppet.host_config_groups.map(&:config_group_id)).must_equal(host.puppet.host_config_groups.map(&:config_group_id))
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -232,20 +232,20 @@ module ForemanPuppet
|
|
232
232
|
nodeinfo['parameters']['special_info'] = 'secret' # smart variable on apache
|
233
233
|
|
234
234
|
info = host.info
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
235
|
+
expect(host.puppet.environment.name).must_equal(env.name)
|
236
|
+
expect(info.keys).must_include 'environment'
|
237
|
+
expect(info.keys).must_include 'parameters'
|
238
|
+
expect(info.keys).must_include 'classes'
|
239
239
|
# This worked in core, but it's beyond me how could have :shrug:
|
240
240
|
# assert_equal(classes_params, info['classes'])
|
241
241
|
# We are only importing classes in the method
|
242
|
-
|
242
|
+
expect(info['classes'].keys.sort).must_equal(classes_params.keys.sort)
|
243
243
|
parameters = info['parameters']
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
244
|
+
expect(parameters['puppetmaster']).must_equal 'puppet'
|
245
|
+
expect(parameters['root_pw']).must_equal 'xybxa6JUkz63w'
|
246
|
+
expect(parameters['foreman_interfaces'].first['ip']).must_equal '3.3.4.12'
|
247
|
+
expect(parameters.keys).must_include 'foreman_subnets'
|
248
|
+
expect(parameters.keys).must_include 'foreman_interfaces'
|
249
249
|
end
|
250
250
|
|
251
251
|
test 'should import from non-parameterized external nodes output' do
|
@@ -32,9 +32,9 @@ module ForemanPuppet
|
|
32
32
|
assert tmplt.save
|
33
33
|
end
|
34
34
|
assert_nil tmplt.template_kind
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
assert_empty tmplt.hostgroups
|
36
|
+
assert_empty tmplt.environments
|
37
|
+
assert_empty tmplt.template_combinations
|
38
38
|
end
|
39
39
|
|
40
40
|
test '#template_includes adds environment include' do
|
@@ -17,7 +17,7 @@ module ForemanPuppet
|
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'looking for a nonexistent host returns no puppetclasses' do
|
20
|
-
|
20
|
+
assert_empty Puppetclass.search_for('host = imaginaryhost.nodomain.what')
|
21
21
|
end
|
22
22
|
|
23
23
|
test 'Puppetclass singularize from custom inflection' do
|
@@ -98,7 +98,7 @@ module ForemanPuppet
|
|
98
98
|
puppetclass: puppetclass)
|
99
99
|
|
100
100
|
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
101
|
-
|
101
|
+
assert_nil enc[puppetclass.name][lkey.key]
|
102
102
|
end
|
103
103
|
|
104
104
|
test '#enc should not return class parameters when lookup_value should use puppet default' do
|
@@ -113,7 +113,7 @@ module ForemanPuppet
|
|
113
113
|
|
114
114
|
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
115
115
|
|
116
|
-
|
116
|
+
assert_nil enc[puppetclass.name][lkey.key]
|
117
117
|
end
|
118
118
|
|
119
119
|
test '#enc should return class parameters when default value and lookup_values should not use puppet default' do
|
@@ -160,7 +160,7 @@ module ForemanPuppet
|
|
160
160
|
|
161
161
|
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
162
162
|
|
163
|
-
|
163
|
+
assert_nil enc[puppetclass.name][key.key]
|
164
164
|
end
|
165
165
|
|
166
166
|
test '#enc should return correct merged override to host when multiple overrides for inherited hostgroups exist' do
|
@@ -3,7 +3,7 @@ require 'test_puppet_helper'
|
|
3
3
|
module ForemanPuppet
|
4
4
|
class TemplateRenderingTest < ActiveSupport::TestCase
|
5
5
|
let(:host) { FactoryBot.build_stubbed(:host, :with_puppet_enc) }
|
6
|
-
let(:template) {
|
6
|
+
let(:template) { stub(name: 'Test', template: 'Test') }
|
7
7
|
let(:source) { Foreman::Renderer::Source::Database.new(template) }
|
8
8
|
let(:scope) do
|
9
9
|
Class.new(Foreman::Renderer::Scope::Base) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allow assigning Puppet environments and classes to the Foreman Hosts.
|
15
15
|
email:
|
@@ -188,6 +188,8 @@ files:
|
|
188
188
|
- db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb
|
189
189
|
- db/migrate/20211111125003_drop_puppetclasses_direct_references.foreman_puppet.rb
|
190
190
|
- db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb
|
191
|
+
- db/migrate/20220201205305_migrate_host_class_permission.foreman_puppet.rb
|
192
|
+
- db/migrate/20220208135305_migrate_environment_ignore_type.foreman_puppet.rb
|
191
193
|
- db/migrate_foreman/20090722141107_create_environments.foreman_puppet.rb
|
192
194
|
- db/migrate_foreman/20090802062223_create_puppetclasses.foreman_puppet.rb
|
193
195
|
- db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb
|
@@ -292,6 +294,7 @@ files:
|
|
292
294
|
- test/graphql/queries/puppetclass_query_test.rb
|
293
295
|
- test/graphql/queries/puppetclasses_query_test.rb
|
294
296
|
- test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb
|
297
|
+
- test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb
|
295
298
|
- test/helpers/foreman_puppet/puppetclasses_helper_test.rb
|
296
299
|
- test/integration/foreman_puppet/dashboard_js_test.rb
|
297
300
|
- test/integration/foreman_puppet/environment_js_test.rb
|
@@ -299,6 +302,7 @@ files:
|
|
299
302
|
- test/integration/foreman_puppet/hostgroup_js_test.rb
|
300
303
|
- test/integration/foreman_puppet/puppetclass_js_test.rb
|
301
304
|
- test/integration/foreman_puppet/smartclass_parameter_js_test.rb
|
305
|
+
- test/integration_puppet_helper.rb
|
302
306
|
- test/models/foreman_puppet/config_group_class_test.rb
|
303
307
|
- test/models/foreman_puppet/config_group_test.rb
|
304
308
|
- test/models/foreman_puppet/environment_test.rb
|
@@ -363,7 +367,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
363
367
|
- !ruby/object:Gem::Version
|
364
368
|
version: '0'
|
365
369
|
requirements: []
|
366
|
-
rubygems_version: 3.
|
370
|
+
rubygems_version: 3.3.4
|
367
371
|
signing_key:
|
368
372
|
specification_version: 4
|
369
373
|
summary: Add Puppet features to Foreman
|
@@ -387,6 +391,8 @@ test_files:
|
|
387
391
|
- test/graphql/queries/environment_query_test.rb
|
388
392
|
- test/graphql/queries/hostgroup_puppet_query_test.rb
|
389
393
|
- test/graphql/queries/environments_query_test.rb
|
394
|
+
- test/integration_puppet_helper.rb
|
395
|
+
- test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb
|
390
396
|
- test/helpers/foreman_puppet/puppetclasses_helper_test.rb
|
391
397
|
- test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb
|
392
398
|
- test/models/foreman_puppet/config_group_class_test.rb
|