foreman_puppet 1.0.0.rc.1 → 1.0.2

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: f41d4919f84bff60f30a23f1e05ceae83e468bb4d005ed781f635ee39a33246c
4
- data.tar.gz: 208fbb6587882e138874b60cf19d1c76d5470f3ffd1cf5c7487f5a48983a5e51
3
+ metadata.gz: ccf0e28e1eb6fd2a88980db29a6c6f30d1bb972bd58800d444c4507bad61b771
4
+ data.tar.gz: a4828f6dd4e0df4e6210c2bbcfe624c247758a3566dcb5f514dcc2de6246ed45
5
5
  SHA512:
6
- metadata.gz: 3d4c7c3a02a500d554a0c11fd35f3f47f37e3accb2503270f82d920c47b1bd6aa751a76b698105d508ef24c04757fc7cc5f08a412a0221cfc2e51a553523a567
7
- data.tar.gz: bae382d27974df26cfebed71b5b89963229f97b962e75fecd53bf19a9b35edbff829b9d823fde79c05f8859341982cc24b4e3f3a3b35c58d1c81f5802cd49c01
6
+ metadata.gz: 9df9c3ae3fb503fd9c3f21bd692af6a194eab2ec021846ab4089d8b21d55dcb7d68ee6b33467d98f308401abf4aad2a22dd89ca8ae78bb0555760b3ed29ca787
7
+ data.tar.gz: 2a17492b79af4c0c53523b678f05b632d61e436421f19c1af37f8baa6e2259ca719416b08fe3555aab4f1533b09641feba575e60b2498747a040c41aa78c4dde
@@ -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',
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanPuppet
4
+ module Types
5
+ module InterfaceAttributesInputExtensions
6
+ delegate :with_indifferent_access, to: :to_h
7
+ end
8
+ end
9
+ end
@@ -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
@@ -3,6 +3,8 @@ module ForemanPuppet
3
3
  module Host
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
7
+
6
8
  included do
7
9
  prepend PrependedMethods
8
10
 
@@ -82,10 +84,10 @@ module ForemanPuppet
82
84
  def available_template_kinds(provisioning = nil)
83
85
  kinds = template_kinds(provisioning)
84
86
  kinds.map do |kind|
85
- ProvisioningTemplate.find_template({ kind: kind.name,
86
- operatingsystem_id: operatingsystem_id,
87
- hostgroup_id: hostgroup_id,
88
- environment_id: puppet&.environment_id })
87
+ ::ProvisioningTemplate.find_template({ kind: kind.name,
88
+ operatingsystem_id: operatingsystem_id,
89
+ hostgroup_id: hostgroup_id,
90
+ environment_id: puppet&.environment_id })
89
91
  end.compact
90
92
  end
91
93
 
@@ -0,0 +1,17 @@
1
+ module ForemanPuppet
2
+ module Extensions
3
+ module HostCommon
4
+ extend ActiveSupport::Concern
5
+
6
+ def all_puppetclasses(env = environment)
7
+ return ForemanPuppet::Puppetclass.none unless puppet
8
+ puppet.all_puppetclasses(env)
9
+ end
10
+
11
+ def puppetclasses
12
+ return ForemanPuppet::Puppetclass.none unless puppet
13
+ puppet.puppetclasses
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,6 +3,8 @@ module ForemanPuppet
3
3
  module Hostgroup
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
7
+
6
8
  included do
7
9
  class << self
8
10
  prepend PatchedClassMethods
@@ -46,7 +46,7 @@ module ForemanPuppet
46
46
 
47
47
  def template_includes
48
48
  includes = super
49
- tc_include = includes.detect { |i| i.key?(:template_combinations) }
49
+ tc_include = includes.detect { |i| i.is_a?(Hash) && i.key?(:template_combinations) }
50
50
  tc_include ||= includes << {}
51
51
  tc_include[:template_combinations] = %i[hostgroup environment]
52
52
  includes
@@ -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
@@ -2,6 +2,8 @@ module ForemanPuppet
2
2
  module HostInfoProviders
3
3
  class ConfigGroupsInfo < HostInfo::Provider
4
4
  def host_info
5
+ return {} unless host.puppet
6
+
5
7
  config_groups = (host.puppet.config_groups + host.puppet.parent_config_groups).uniq.map(&:name)
6
8
  { 'parameters' => { 'foreman_config_groups' => config_groups } }
7
9
  end
@@ -0,0 +1,44 @@
1
+ <ul id="proxy-puppetca-tab" class="nav nav-tabs nav-tabs-pf">
2
+ <li class="active"><a href="#ca_general" data-toggle="tab"><%= _("General") %></a></li>
3
+ <% if authorized_for(:permission => :view_smart_proxies_puppetca, :auth_object => @smart_proxy, :authorizer => authorizer) %>
4
+ <li><a href="#certificates" data-toggle="tab"><%= _("Certificates") %></a></li>
5
+ <% end %>
6
+ <% if authorized_for(:permission => :view_smart_proxies_autosign, :auth_object => @smart_proxy, :authorizer => authorizer) %>
7
+ <li><a href="#autosign" data-toggle="tab"><%= _("Autosign entries") %></a></li>
8
+ <% end %>
9
+ </ul>
10
+ <div id="proxy-puppetca-tab-content" class="tab-content">
11
+ <div class="tab-pane active in" id="ca_general">
12
+ <div class="row">
13
+ <div class="col-md-6">
14
+ <%= show_feature_version('puppetca') %>
15
+ <div class="row">
16
+ <div class="col-md-4"><strong><%= _('Hosts managed:') %></strong></div>
17
+ <div class="col-md-8">
18
+ <%= link_to Host::Managed.where(:puppet_ca_proxy_id => @smart_proxy.id).count, hosts_path(:search => "puppet_ca = \"#{@smart_proxy.name}\"") %>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ <div class="container-fluid container-cards-pf">
24
+ <div class="row row-cards-pf">
25
+ <% if authorized_for(:permission => :view_smart_proxies_puppetca, :auth_object => @smart_proxy) %>
26
+ <span data-ajax-url="<%= counts_smart_proxy_puppetca_path(:smart_proxy_id => @smart_proxy) %>"><%= spinner%></span>
27
+ <span data-ajax-url="<%= expiry_smart_proxy_puppetca_path(:smart_proxy_id => @smart_proxy) %>"><%= spinner%></span>
28
+ <% end %>
29
+ <% if authorized_for(:permission => :view_smart_proxies_autosign, :auth_object => @smart_proxy, :authorizer => authorizer) %>
30
+ <span data-ajax-url="<%= counts_smart_proxy_autosign_path(:smart_proxy_id => @smart_proxy) %>"><%= spinner%></span>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ <% if authorized_for(:permission => :view_smart_proxies_puppetca, :auth_object => @smart_proxy, :authorizer => authorizer) %>
36
+ <div class="tab-pane" id="certificates" data-ajax-url="<%= smart_proxy_puppetca_index_path(:smart_proxy_id => @smart_proxy) %>" data-on-complete="certTable"><%= spinner %></div>
37
+ <% end %>
38
+ <% if authorized_for(:permission => :view_smart_proxies_autosign, :auth_object => @smart_proxy, :authorizer => authorizer) %>
39
+ <div class="tab-pane" id="autosign" data-ajax-url="<%= smart_proxy_autosign_index_path(:smart_proxy_id => @smart_proxy) %>" data-on-complete="tfm.tools.activateDatatables"><%= spinner %></div>
40
+ <% if authorized_for(:permission => :create_smart_proxies_autosign, :auth_object => @smart_proxy, :authorizer => authorizer) %>
41
+ <div data-ajax-url=<%= new_smart_proxy_autosign_path(:smart_proxy_id => @smart_proxy) %>></div>
42
+ <% end %>
43
+ <% end %>
44
+ </div>
@@ -1,34 +1,53 @@
1
1
  class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
2
2
  class FakeHostConfigGroup < ::ApplicationRecord
3
3
  self.table_name = 'host_config_groups'
4
+
5
+ scope :for_host, -> { where(host_type: %w[Host::Base Host::Managed]) }
6
+ scope :for_hostgroup, -> { where(host_type: 'Hostgroup') }
7
+ scope :for_host_facet, -> { where(host_type: 'ForemanPuppet::HostPuppetFacet') }
8
+ scope :for_hostgroup_facet, -> { where(host_type: 'ForemanPuppet::HostgroupPuppetFacet') }
9
+ end
10
+
11
+ class FakeConfigGroup < ::ApplicationRecord
12
+ self.table_name = 'config_groups'
4
13
  end
5
14
 
6
15
  def up
7
- host_config_group_ids = FakeHostConfigGroup.where(host_type: %w[Host::Base Host::Managed]).pluck(:host_id).uniq
16
+ host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
8
17
  host_config_group_ids.each do |host_id|
9
18
  host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
10
- FakeHostConfigGroup.where(host_type: %w[Host::Base Host::Managed], host_id: host_id)
11
- .update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
19
+ host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
20
+ if host_facet_id
21
+ host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
22
+ else
23
+ deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
24
+ say "deleting groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because it has no environment"
25
+ host_groups.delete_all
26
+ end
12
27
  end
13
- hostgroup_config_group_ids = FakeHostConfigGroup.where(host_type: 'Hostgroup').pluck(:host_id).uniq
28
+ hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
14
29
  hostgroup_config_group_ids.each do |hostgroup_id|
15
30
  hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
16
- FakeHostConfigGroup.where(host_type: 'Hostgroup', host_id: hostgroup_id)
31
+ hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: Hostgroup.unscoped.find(hostgroup_id)).id
32
+ FakeHostConfigGroup.for_hostgroup
33
+ .where(host_id: hostgroup_id)
17
34
  .update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
18
35
  end
19
36
  end
20
37
 
21
38
  def down
22
- host_config_group_ids = FakeHostConfigGroup.where(host_type: 'ForemanPuppet::HostPuppetFacet').pluck(:host_id).uniq
39
+ host_config_group_ids = FakeHostConfigGroup.for_host_facet.pluck(:host_id).uniq
23
40
  host_facet_ids = ForemanPuppet::HostPuppetFacet.where(id: host_config_group_ids).pluck(:id, :host_id).to_h
24
41
  host_config_group_ids.each do |host_puppet_facet_id|
25
- FakeHostConfigGroup.where(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_puppet_facet_id)
42
+ FakeHostConfigGroup.for_host_facet
43
+ .where(host_id: host_puppet_facet_id)
26
44
  .update_all(host_type: 'Host::Managed', host_id: host_facet_ids[host_puppet_facet_id])
27
45
  end
28
- hostgroup_config_group_ids = FakeHostConfigGroup.where(host_type: 'ForemanPuppet::HostgroupPuppetFacet').pluck(:host_id).uniq
46
+ hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup_facet.pluck(:host_id).uniq
29
47
  hostgroup_facet_ids = ForemanPuppet::HostgroupPuppetFacet.where(id: hostgroup_config_group_ids).pluck(:id, :hostgroup_id).to_h
30
48
  hostgroup_config_group_ids.each do |hostgroup_facet_id|
31
- FakeHostConfigGroup.where(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
49
+ FakeHostConfigGroup.for_hostgroup_facet
50
+ .where(host_id: hostgroup_facet_id)
32
51
  .update_all(host_type: 'Hostgroup', host_id: hostgroup_facet_ids[hostgroup_facet_id])
33
52
  end
34
53
  end
@@ -7,6 +7,10 @@ class MigratePuppetclassesToFacets < ActiveRecord::Migration[6.0]
7
7
  self.table_name = 'hostgroup_classes'
8
8
  end
9
9
 
10
+ class FakePuppetclass < ApplicationRecord
11
+ self.table_name = 'puppetclasses'
12
+ end
13
+
10
14
  def up
11
15
  add_reference :host_classes, :host_puppet_facet, foreign_key: true, index: true
12
16
  add_reference :hostgroup_classes, :hostgroup_puppet_facet, foreign_key: true, index: true
@@ -14,11 +18,19 @@ class MigratePuppetclassesToFacets < ActiveRecord::Migration[6.0]
14
18
  host_ids = FakeHostClass.all.pluck(:host_id).uniq
15
19
  host_ids.each do |host_id|
16
20
  host_facet = ForemanPuppet::HostPuppetFacet.find_by(host_id: host_id)
17
- ForemanPuppet::HostClass.where(host_id: host_id).update_all(host_puppet_facet_id: host_facet.id)
21
+ host_classes = ForemanPuppet::HostClass.where(host_id: host_id)
22
+ if host_facet
23
+ host_classes.update_all(host_puppet_facet_id: host_facet.id)
24
+ else
25
+ deleted_classes = FakePuppetclass.where(id: host_classes.pluck(:puppetclass_id)).pluck(:name)
26
+ say "deleting classes #{deleted_classes.join(', ')} from Host (id=#{host_id}) because it has no environment"
27
+ host_classes.delete_all
28
+ end
18
29
  end
19
30
  hostgroup_ids = FakeHostgroupClass.all.pluck(:hostgroup_id).uniq
20
31
  hostgroup_ids.each do |hostgroup_id|
21
32
  hostgroup_facet = ForemanPuppet::HostgroupPuppetFacet.find_by(hostgroup_id: hostgroup_id)
33
+ hostgroup_facet ||= ForemanPuppet::HostgroupPuppetFacet.create(hostgroup: Hostgroup.unscoped.find(hostgroup_id))
22
34
  ForemanPuppet::HostgroupClass.where(hostgroup_id: hostgroup_id).update_all(hostgroup_puppet_facet_id: hostgroup_facet.id)
23
35
  end
24
36
 
@@ -15,14 +15,24 @@ module ForemanPuppet
15
15
  end
16
16
  end
17
17
 
18
+ module RelayClassicMutationClassMethodPath
19
+ # rubocop:disable Metrics/ParameterLists
20
+ def argument(name, type, *rest, loads: nil, **kwargs, &block)
21
+ # rubocop:enable Metrics/ParameterLists
22
+ return if [::Types::Environment, ::Types::Puppetclass].include?(loads)
23
+
24
+ super
25
+ end
26
+ end
27
+
18
28
  GraphQL::Types::Relay::BaseObject.extend(BaseObjectClassMethodPath)
29
+ GraphQL::Schema::RelayClassicMutation.extend(RelayClassicMutationClassMethodPath)
19
30
  end
20
31
  end
21
32
 
22
33
  engine_name 'foreman_puppet'
23
34
  isolate_namespace ForemanPuppet
24
35
 
25
- config.paths['db/migrate'] << 'db/migrate_foreman' if Gem::Dependency.new('', ">= #{ForemanPuppet::FOREMAN_EXTRACTION_VERSION}").match?('', SETTINGS[:version])
26
36
  config.paths['config/routes.rb'].unshift('config/api_routes.rb')
27
37
 
28
38
  initializer 'foreman_puppet.register_plugin', before: :finisher_hook do |_app|
@@ -97,6 +107,8 @@ module ForemanPuppet
97
107
  ::Types::Hostgroup.include(ForemanPuppet::Types::HostgroupExtensions)
98
108
  ::Types::Location.include(ForemanPuppet::Types::LocationExtensions)
99
109
  ::Types::Organization.include(ForemanPuppet::Types::OrganizationExtensions)
110
+ ::Types::InterfaceAttributesInput.include(ForemanPuppet::Types::InterfaceAttributesInputExtensions)
111
+
100
112
  ::Mutations::Hosts::Create.include(ForemanPuppet::Mutations::Hosts::CreateExtensions)
101
113
  rescue StandardError => e
102
114
  Rails.logger.warn "ForemanPuppet: skipping engine hook (#{e})\n#{e.backtrace.join("\n")}"
@@ -170,8 +170,7 @@ Foreman::Plugin.register :foreman_puppet do
170
170
  # extend_model ForemanPuppet::Extensions::Host
171
171
  api_view list: 'foreman_puppet/api/v2/host_puppet_facets/base',
172
172
  single: 'foreman_puppet/api/v2/host_puppet_facets/host_single'
173
- template_compatibility_properties :environment, :environment_id, :environment_name,
174
- :puppetclasses, :all_puppetclasses
173
+ template_compatibility_properties :environment, :environment_id, :environment_name
175
174
  set_dependent_action :destroy
176
175
  end
177
176
  configure_hostgroup(ForemanPuppet::HostgroupPuppetFacet) do
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '1.0.0.rc.1'.freeze
2
+ VERSION = '1.0.2'.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
@@ -17,6 +17,16 @@ module ForemanPuppet
17
17
  name: hostname,
18
18
  environmentId: environment_id,
19
19
  puppetclassIds: [puppetclass_id],
20
+ interfacesAttributes: [
21
+ {
22
+ type: 'bond',
23
+ attachedTo: %w[eth0 eth1],
24
+ identifier: 'bond0',
25
+ primary: true,
26
+ provision: true,
27
+ managed: true,
28
+ },
29
+ ],
20
30
  }
21
31
  end
22
32
  let(:context_user) { FactoryBot.create(:user, :admin, locations: [tax_location], organizations: [organization]) }
@@ -28,11 +38,13 @@ module ForemanPuppet
28
38
  $name: String!,
29
39
  $environmentId: ID,
30
40
  $puppetclassIds: [ID!],
41
+ $interfacesAttributes: [InterfaceAttributesInput!]
31
42
  ) {
32
43
  createHost(input: {
33
44
  name: $name,
34
45
  environmentId: $environmentId,
35
46
  puppetclassIds: $puppetclassIds,
47
+ interfacesAttributes: $interfacesAttributes,
36
48
  }) {
37
49
  host {
38
50
  id
@@ -57,6 +69,15 @@ module ForemanPuppet
57
69
  assert_equal environment.id, host.puppet.environment_id
58
70
  assert_equal [puppetclass.id], host.puppet.puppetclasses.pluck(:id)
59
71
 
72
+ assert_equal 1, host.interfaces.count
73
+ interface = host.interfaces.first
74
+ assert_equal 'Nic::Bond', interface.type
75
+ assert_equal 'eth0, eth1', interface.attached_to
76
+ assert_equal 'bond0', interface.identifier
77
+ assert interface.primary
78
+ assert interface.provision
79
+ assert interface.managed
80
+
60
81
  assert_not_nil data
61
82
  end
62
83
  end
@@ -37,6 +37,13 @@ module ForemanPuppet
37
37
  assert_equal [], tmplt.template_combinations
38
38
  end
39
39
 
40
+ test '#template_includes adds environment include' do
41
+ includes = ProvisioningTemplate.template_includes
42
+ tc_include = includes.detect { |i| i.is_a?(Hash) && i.key?(:template_combinations) }
43
+ assert tc_include
44
+ assert_includes tc_include[:template_combinations], :environment
45
+ end
46
+
40
47
  describe '#find_template by template_combinations' do
41
48
  setup do
42
49
  @arch = FactoryBot.create(:architecture)
@@ -0,0 +1,35 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class ConfigGroupInfoTest < ActiveSupport::TestCase
5
+ let(:cg_info) { HostInfoProviders::ConfigGroupsInfo.new(host) }
6
+
7
+ context 'with Puppet Host' do
8
+ let(:config_group) { FactoryBot.create(:config_group) }
9
+ let(:host) do
10
+ FactoryBot.build(:host, :with_puppet_enc,
11
+ location: taxonomies(:location1),
12
+ organization: taxonomies(:organization1),
13
+ operatingsystem: operatingsystems(:redhat),
14
+ config_groups: [config_group])
15
+ end
16
+
17
+ it 'adds config_groups to host parameters' do
18
+ assert_equal([config_group.name], cg_info.host_info['parameters']['foreman_config_groups'])
19
+ end
20
+ end
21
+
22
+ context 'without Puppet' do
23
+ let(:host) do
24
+ FactoryBot.build(:host,
25
+ location: taxonomies(:location1),
26
+ organization: taxonomies(:organization1),
27
+ operatingsystem: operatingsystems(:redhat))
28
+ end
29
+
30
+ it 'does not fail without puppet facet' do
31
+ assert_equal({}, cg_info.host_info)
32
+ end
33
+ end
34
+ end
35
+ end
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.1
4
+ version: 1.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: 2021-07-15 00:00:00.000000000 Z
12
+ date: 2021-09-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
15
15
  email:
@@ -56,6 +56,7 @@ files:
56
56
  - app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb
57
57
  - app/graphgl/concerns/foreman_puppet/types/host_extensions.rb
58
58
  - app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb
59
+ - app/graphgl/concerns/foreman_puppet/types/interface_attributes_input_extensions.rb
59
60
  - app/graphgl/concerns/foreman_puppet/types/location_extensions.rb
60
61
  - app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb
61
62
  - app/graphgl/foreman_puppet/types/environment.rb
@@ -70,6 +71,7 @@ files:
70
71
  - app/helpers/foreman_puppet/puppetclasses_helper.rb
71
72
  - app/helpers/foreman_puppet/template_combinations_helper.rb
72
73
  - app/models/concerns/foreman_puppet/extensions/host.rb
74
+ - app/models/concerns/foreman_puppet/extensions/host_common.rb
73
75
  - app/models/concerns/foreman_puppet/extensions/hostgroup.rb
74
76
  - app/models/concerns/foreman_puppet/extensions/nic_managed.rb
75
77
  - app/models/concerns/foreman_puppet/extensions/operatingsystem.rb
@@ -169,6 +171,7 @@ files:
169
171
  - app/views/provisioning_templates/_combination.html.erb
170
172
  - app/views/provisioning_templates/_combinations.html.erb
171
173
  - app/views/smart_proxies/plugins/_puppet.html.erb
174
+ - app/views/smart_proxies/plugins/_puppet_ca.html.erb
172
175
  - config/api_routes.rb
173
176
  - config/initializers/api_reroute.rb
174
177
  - config/routes.rb
@@ -260,6 +263,7 @@ files:
260
263
  - test/models/foreman_puppet/report_test.rb
261
264
  - test/models/foreman_puppet/smart_proxy_test.rb
262
265
  - test/models/foreman_puppet/user_test.rb
266
+ - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
263
267
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
264
268
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
265
269
  - test/test_puppet_helper.rb
@@ -303,15 +307,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
307
  version: '0'
304
308
  required_rubygems_version: !ruby/object:Gem::Requirement
305
309
  requirements:
306
- - - ">"
310
+ - - ">="
307
311
  - !ruby/object:Gem::Version
308
- version: 1.3.1
312
+ version: '0'
309
313
  requirements: []
310
314
  rubygems_version: 3.1.6
311
315
  signing_key:
312
316
  specification_version: 4
313
317
  summary: Adds puppet ENC features
314
318
  test_files:
319
+ - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
315
320
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
316
321
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
317
322
  - test/integration/foreman_puppet/smartclass_parameter_js_test.rb