foreman_puppet 1.0.0.rc.2 → 1.0.3
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/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
- data/app/controllers/foreman_puppet/api/v2/puppet_base_controller.rb +1 -1
- data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +4 -0
- data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +3 -4
- data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -2
- data/lib/foreman_puppet/engine.rb +0 -1
- data/lib/foreman_puppet/version.rb +1 -1
- data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -52
- data/test/factories/host_puppet_enhancements.rb +3 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c268d86cd3905acdfcd56bc9898df23218553a632bb167c08de6c708351ee8
|
4
|
+
data.tar.gz: fc9d44ecfdd418571796ccc39a302a5ac086bae221bc155ba5e827edfd45a9f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4169751ebd02e01e6628a8583490d7257e27c7f0852e7539fc42b4b989258d3efef9324c684db31776a0d8f48e9360d0e3d40bdb12c03e8dd66d923f7d521e2
|
7
|
+
data.tar.gz: a0384e376fa23ed7dd0ada27f525d04cbeaebd19a1933e91ce97628dc3a4abe74ba79d6857040e4c920071e3afeef7858d121329ecbd3f6db2aa0486de9dba5f
|
@@ -36,7 +36,7 @@ module ForemanPuppet
|
|
36
36
|
|
37
37
|
puppet.puppetclasses = ForemanPuppet::Puppetclass.where(id: params[:hostgroup][:puppetclass_ids])
|
38
38
|
puppet.config_groups = ForemanPuppet::ConfigGroup.where(id: params[:hostgroup][:config_group_ids])
|
39
|
-
render partial: 'hosts/form_puppet_enc_tab', locals: {
|
39
|
+
render partial: 'hosts/form_puppet_enc_tab', locals: { subject: @hostgroup, resource_type: :hostgroup }
|
40
40
|
end
|
41
41
|
|
42
42
|
def puppetclass_parameters
|
@@ -41,7 +41,7 @@ module ForemanPuppet
|
|
41
41
|
set_class_variables(@host)
|
42
42
|
::Taxonomy.as_taxonomy @organization, @location do
|
43
43
|
if @environment || @hostgroup
|
44
|
-
render partial: 'hosts/form_puppet_enc_tab', locals: {
|
44
|
+
render partial: 'hosts/form_puppet_enc_tab', locals: { subject: @host, resource_type: :host }
|
45
45
|
else
|
46
46
|
logger.info 'environment_id or hostgroup_id is required to render puppetclasses'
|
47
47
|
end
|
@@ -11,7 +11,7 @@ module ForemanPuppet
|
|
11
11
|
protected
|
12
12
|
|
13
13
|
def show_deprecation_for_core_routes
|
14
|
-
return if request.path.starts_with?('/foreman_puppet')
|
14
|
+
return if request.path.starts_with?('/foreman_puppet') || request.path.starts_with?('/api/smart_proxies')
|
15
15
|
Foreman::Deprecation.api_deprecation_warning(
|
16
16
|
format(
|
17
17
|
'/api/v2/%{controller} API endpoints are deprecated, please use /foreman_puppet/api/v2/%{controller} instead',
|
@@ -43,7 +43,7 @@ module ForemanPuppet
|
|
43
43
|
# the environment used by #clases nees to be self.environment and not self.parent.environment
|
44
44
|
def parent_classes
|
45
45
|
return [] unless host.hostgroup
|
46
|
-
host.hostgroup.puppet&.classes(environment)
|
46
|
+
host.hostgroup.puppet&.classes(environment) || []
|
47
47
|
end
|
48
48
|
|
49
49
|
def parent_config_groups
|
@@ -1,6 +1,5 @@
|
|
1
1
|
<% resource_type ||= pagelet.opts[:resource_type] %>
|
2
|
-
<%
|
3
|
-
<% obj = (host_or_hostgroup.puppet || host_or_hostgroup.build_puppet) if %i[host hostgroup].include?(resource_type) %>
|
2
|
+
<% obj = (subject.puppet || subject.build_puppet) if %i[host hostgroup].include?(resource_type) %>
|
4
3
|
<% if resource_type == :host %>
|
5
4
|
<span id="puppet_klasses_reload_url" data-url="<%= foreman_puppet.hostgroup_or_environment_selected_hosts_path %>"></span>
|
6
5
|
<% elsif resource_type == :hostgroup %>
|
@@ -18,7 +17,7 @@
|
|
18
17
|
text: _('Please select an environment first')) %>
|
19
18
|
<% end %>
|
20
19
|
|
21
|
-
<fieldset id="puppet_klasses_parameters" data-url="<%= foreman_puppet.url_for(action: :puppetclass_parameters, only_path: true) %>">
|
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) %>">
|
22
21
|
<h2><%= _('Puppet Class Parameters') %></h2>
|
23
|
-
<%= render 'foreman_puppet/puppetclasses/classes_parameters', obj:
|
22
|
+
<%= render 'foreman_puppet/puppetclasses/classes_parameters', obj: subject %>
|
24
23
|
</fieldset>
|
@@ -2,11 +2,11 @@ class MigrateEnvironmentToPuppetFacet < ActiveRecord::Migration[6.0]
|
|
2
2
|
def up
|
3
3
|
puppet_hostgroups = ::Hostgroup.unscoped.where.not(environment_id: nil).pluck(:id, :environment_id)
|
4
4
|
puppet_hostgroups.map! { |hg_id, env_id| { hostgroup_id: hg_id, environment_id: env_id } }
|
5
|
-
ForemanPuppet::HostgroupPuppetFacet.insert_all(puppet_hostgroups) if puppet_hostgroups.any?
|
5
|
+
ForemanPuppet::HostgroupPuppetFacet.insert_all!(puppet_hostgroups) if puppet_hostgroups.any?
|
6
6
|
|
7
7
|
puppet_hosts = Host::Managed.unscoped.where.not(environment_id: nil).pluck(:id, :environment_id)
|
8
8
|
puppet_hosts.map! { |host_id, env_id| { host_id: host_id, environment_id: env_id } }
|
9
|
-
ForemanPuppet::HostPuppetFacet.insert_all(puppet_hosts) if puppet_hosts.any?
|
9
|
+
ForemanPuppet::HostPuppetFacet.insert_all!(puppet_hosts) if puppet_hosts.any?
|
10
10
|
end
|
11
11
|
|
12
12
|
def down
|
@@ -33,7 +33,6 @@ module ForemanPuppet
|
|
33
33
|
engine_name 'foreman_puppet'
|
34
34
|
isolate_namespace ForemanPuppet
|
35
35
|
|
36
|
-
config.paths['db/migrate'] << 'db/migrate_foreman' if Gem::Dependency.new('', ">= #{ForemanPuppet::FOREMAN_EXTRACTION_VERSION}").match?('', SETTINGS[:version])
|
37
36
|
config.paths['config/routes.rb'].unshift('config/api_routes.rb')
|
38
37
|
|
39
38
|
initializer 'foreman_puppet.register_plugin', before: :finisher_hook do |_app|
|
@@ -4,68 +4,88 @@ module ForemanPuppet
|
|
4
4
|
class HostgroupsControllerTest < ActionController::TestCase
|
5
5
|
tests ::HostgroupsController
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
context 'with core routes' do
|
8
|
+
describe '#nest' do
|
9
|
+
it 'works without puppetclasses' do
|
10
|
+
hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
|
11
|
+
|
12
|
+
post :nest, params: { id: hostgroup.id }, session: set_session_user
|
13
|
+
assert_template 'new'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'works with puppetclasses' do
|
17
|
+
hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
|
18
|
+
|
19
|
+
post :nest, params: { id: hostgroup.id }, session: set_session_user
|
20
|
+
assert_template 'new'
|
21
|
+
end
|
22
|
+
end
|
9
23
|
end
|
10
24
|
|
11
|
-
|
25
|
+
context 'with plugin routes' do
|
12
26
|
setup do
|
13
|
-
@
|
14
|
-
@puppetclass = FactoryBot.create(:puppetclass)
|
15
|
-
@hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment)
|
16
|
-
@params = {
|
17
|
-
id: @hostgroup.id,
|
18
|
-
hostgroup: {
|
19
|
-
name: @hostgroup.name,
|
20
|
-
environment_id: '',
|
21
|
-
puppetclass_ids: [@puppetclass.id],
|
22
|
-
},
|
23
|
-
}
|
27
|
+
@routes = ForemanPuppet::Engine.routes
|
24
28
|
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
describe '#environment_selected' do
|
31
|
+
setup do
|
32
|
+
@environment = FactoryBot.create(:environment)
|
33
|
+
@puppetclass = FactoryBot.create(:puppetclass)
|
34
|
+
@hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment)
|
35
|
+
@params = {
|
36
|
+
id: @hostgroup.id,
|
37
|
+
hostgroup: {
|
38
|
+
name: @hostgroup.name,
|
39
|
+
environment_id: '',
|
40
|
+
puppetclass_ids: [@puppetclass.id],
|
41
|
+
},
|
42
|
+
}
|
43
|
+
end
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
other_environment = FactoryBot.create(:environment)
|
37
|
-
@params[:hostgroup][:environment_id] = other_environment.id
|
45
|
+
test 'should return the selected puppet classes on environment change' do
|
46
|
+
assert_equal 0, @hostgroup.puppet.puppetclasses.length
|
38
47
|
|
39
48
|
post :environment_selected, params: @params, session: set_session_user, xhr: true
|
40
|
-
assert_equal assigns(:
|
49
|
+
assert_equal(1, assigns(:hostgroup).puppet.puppetclasses.length)
|
50
|
+
assert_include assigns(:hostgroup).puppet.puppetclasses, @puppetclass
|
41
51
|
end
|
42
|
-
end
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
53
|
+
context 'environment_id param is set' do
|
54
|
+
test 'it will take the hostgroup params environment_id' do
|
55
|
+
other_environment = FactoryBot.create(:environment)
|
56
|
+
@params[:hostgroup][:environment_id] = other_environment.id
|
57
|
+
|
58
|
+
post :environment_selected, params: @params, session: set_session_user, xhr: true
|
59
|
+
assert_equal assigns(:environment), other_environment
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'should not escape lookup values on environment change' do
|
64
|
+
hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment, puppetclasses: [@puppetclass])
|
65
|
+
lookup_key = FactoryBot.create(:puppetclass_lookup_key, :array, default_value: %w[a b],
|
66
|
+
override: true,
|
67
|
+
puppetclass: @puppetclass,
|
68
|
+
overrides: { "hostgroup=#{hostgroup.name}" => %w[c d] })
|
69
|
+
lookup_value = lookup_key.lookup_values.first
|
70
|
+
FactoryBot.create(:environment_class, puppetclass: @puppetclass, environment: @environment, puppetclass_lookup_key: lookup_key)
|
71
|
+
|
72
|
+
# sending exactly what the host form would send which is lookup_value.value_before_type_cast
|
73
|
+
lk = { 'lookup_values_attributes' => { lookup_key.id.to_s => { 'value' => lookup_value.value_before_type_cast,
|
74
|
+
'id' => lookup_value.id,
|
75
|
+
'lookup_key_id' => lookup_key.id,
|
76
|
+
'_destroy' => false } } }
|
77
|
+
|
78
|
+
params = {
|
79
|
+
hostgroup_id: hostgroup.id,
|
80
|
+
hostgroup: hostgroup.attributes.merge(lk),
|
81
|
+
}
|
82
|
+
|
83
|
+
# environment change calls puppetclass_parameters which caused the extra escaping
|
84
|
+
post :puppetclass_parameters, params: params, session: set_session_user, xhr: true
|
85
|
+
|
86
|
+
# if this was escaped during refresh_host the value in response.body after unescapeHTML would include "[\\\"c\\\",\\\"d\\\"]"
|
87
|
+
assert_includes CGI.unescapeHTML(response.body), '["c","d"]'
|
88
|
+
end
|
69
89
|
end
|
70
90
|
end
|
71
91
|
end
|
@@ -45,6 +45,9 @@ FactoryBot.modify do
|
|
45
45
|
puppet_proxy do
|
46
46
|
FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:feature, :puppet)])
|
47
47
|
end
|
48
|
+
puppet_ca_proxy do
|
49
|
+
FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:feature, :puppetca)])
|
50
|
+
end
|
48
51
|
end
|
49
52
|
|
50
53
|
trait :with_config_group 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: 1.0.
|
4
|
+
version: 1.0.3
|
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: 2021-
|
12
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
|
15
15
|
email:
|
@@ -307,9 +307,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
307
307
|
version: '0'
|
308
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
309
309
|
requirements:
|
310
|
-
- - "
|
310
|
+
- - ">="
|
311
311
|
- !ruby/object:Gem::Version
|
312
|
-
version:
|
312
|
+
version: '0'
|
313
313
|
requirements: []
|
314
314
|
rubygems_version: 3.1.6
|
315
315
|
signing_key:
|