foreman_puppet 1.0.0.rc.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37d0dfe755f795957a77e9889c1c958343a3b2b54d38e451e7a119bb8b4db98b
4
- data.tar.gz: 2e4e4bad454345c115ec10fa6968409a56dbf2403891bf0711fdaf858225291c
3
+ metadata.gz: 06c268d86cd3905acdfcd56bc9898df23218553a632bb167c08de6c708351ee8
4
+ data.tar.gz: fc9d44ecfdd418571796ccc39a302a5ac086bae221bc155ba5e827edfd45a9f0
5
5
  SHA512:
6
- metadata.gz: c7558294ebc8a1eaca149102ed9d5dcefe10a7ae1fa643bd7836c143de807bec77e3af8fa31df43dcd6b3ec52775ba7b36a6a5a15028413e4f889f479d3295fe
7
- data.tar.gz: b40b1472b66dc27f61c634c11cd500d23d61de31d1eb984c7b68184cb626e9fbfa2b2dbd0bba74009cdd2800c7576fae427cef346a4f48b4e4fb59b8b88eeaf0
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: { host_or_hostgroup: @hostgroup, resource_type: :hostgroup }
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: { host_or_hostgroup: @host, resource_type: :host }
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',
@@ -4,5 +4,9 @@ module ForemanPuppet
4
4
  def hosts_path(*attrs)
5
5
  main_app.hosts_path(*attrs)
6
6
  end
7
+
8
+ def host_config_reports_path(*attrs)
9
+ main_app.host_config_reports_path(*attrs)
10
+ end
7
11
  end
8
12
  end
@@ -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
- <% host_or_hostgroup ||= local_assigns[resource_type] %>
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: host_or_hostgroup %>
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|
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '1.0.0.rc.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -4,68 +4,88 @@ module ForemanPuppet
4
4
  class HostgroupsControllerTest < ActionController::TestCase
5
5
  tests ::HostgroupsController
6
6
 
7
- setup do
8
- @routes = ForemanPuppet::Engine.routes
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
- describe '#environment_selected' do
25
+ context 'with plugin routes' do
12
26
  setup do
13
- @environment = FactoryBot.create(:environment)
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
- test 'should return the selected puppet classes on environment change' do
27
- assert_equal 0, @hostgroup.puppet.puppetclasses.length
28
-
29
- post :environment_selected, params: @params, session: set_session_user, xhr: true
30
- assert_equal(1, assigns(:hostgroup).puppet.puppetclasses.length)
31
- assert_include assigns(:hostgroup).puppet.puppetclasses, @puppetclass
32
- end
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
- context 'environment_id param is set' do
35
- test 'it will take the hostgroup params environment_id' do
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(:environment), other_environment
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
- test 'should not escape lookup values on environment change' do
45
- hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: @environment, puppetclasses: [@puppetclass])
46
- lookup_key = FactoryBot.create(:puppetclass_lookup_key, :array, default_value: %w[a b],
47
- override: true,
48
- puppetclass: @puppetclass,
49
- overrides: { "hostgroup=#{hostgroup.name}" => %w[c d] })
50
- lookup_value = lookup_key.lookup_values.first
51
- FactoryBot.create(:environment_class, puppetclass: @puppetclass, environment: @environment, puppetclass_lookup_key: lookup_key)
52
-
53
- # sending exactly what the host form would send which is lookup_value.value_before_type_cast
54
- lk = { 'lookup_values_attributes' => { lookup_key.id.to_s => { 'value' => lookup_value.value_before_type_cast,
55
- 'id' => lookup_value.id,
56
- 'lookup_key_id' => lookup_key.id,
57
- '_destroy' => false } } }
58
-
59
- params = {
60
- hostgroup_id: hostgroup.id,
61
- hostgroup: hostgroup.attributes.merge(lk),
62
- }
63
-
64
- # environment change calls puppetclass_parameters which caused the extra escaping
65
- post :puppetclass_parameters, params: params, session: set_session_user, xhr: true
66
-
67
- # if this was escaped during refresh_host the value in response.body after unescapeHTML would include "[\\\"c\\\",\\\"d\\\"]"
68
- assert_includes CGI.unescapeHTML(response.body), '["c","d"]'
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.0.rc.2
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-08-16 00:00:00.000000000 Z
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: 1.3.1
312
+ version: '0'
313
313
  requirements: []
314
314
  rubygems_version: 3.1.6
315
315
  signing_key: