foreman_puppet 1.0.4 → 1.0.5

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: 0f4ecdeb14e00d3daed1a47021174874190c39173dbcf50548f8652128cff8c9
4
- data.tar.gz: ee23eb1076fbf0a2d5a6b95e7d066c4eb88a343b99d039903f9350233095bb89
3
+ metadata.gz: 7f8a5c7b68f8d77f54787c4c9de924bc02f27d7a0f957fc6539b5b4aa6c64b49
4
+ data.tar.gz: 6cd563d9cc2f56c22186bbbb0fb9d3c9679c8718e965d7fd952bbed3efacf222
5
5
  SHA512:
6
- metadata.gz: fa9df4333cfdf456010e4a67e5a7d67c7a198424b471c48a22a04f86ee8896e8be69ffcdcdc8b0b7df87d081cc7773dc13a489fd1586a5924329fbe3adc0742e
7
- data.tar.gz: 4fc2f8dfccfb68519faed7519b65a8347e156dc776240d66d235c52c36bbed9736755b79bae5407b6bf67c5f8fd46628f126e075099a781b040d0d00a7a87f32
6
+ metadata.gz: 1a09cf7ff50545983f0e472b3c03f0708087dddf8d2136dc32978f49a1fd76ba7ca4c716db6e6b3add3055279745754b2d2eddf2cd1630a91e75187ba9683c1e
7
+ data.tar.gz: 5c4bb18d77784e2a9c43c7f102adc9df6469b739525fee007d1c89bf635713e1dd051140489101ebeb9d66298100195f56571fa5fb55a1a179c8381cac56a65b
@@ -23,7 +23,9 @@ module ForemanPuppet
23
23
  module Actions
24
24
  def nest
25
25
  super
26
- @hostgroup.puppetclasses = @parent.puppetclasses
26
+ return unless @parent.puppet
27
+ puppet = @hostgroup.puppet || @hostgroup.build_puppet
28
+ puppet.puppetclasses = @parent.puppet.puppetclasses
27
29
  end
28
30
 
29
31
  def environment_selected
@@ -48,7 +48,7 @@ module ForemanPuppet
48
48
 
49
49
  def parent_config_groups
50
50
  return [] unless host.hostgroup
51
- host.hostgroup.puppet&.all_config_groups
51
+ host.hostgroup.puppet&.all_config_groups || []
52
52
  end
53
53
 
54
54
  def ensure_puppet_associations
@@ -48,6 +48,8 @@ module ForemanPuppet
48
48
  Hostgroup.sort_by_ancestry(hostgroup.ancestors.joins(:puppet).where(HostgroupPuppetFacet.arel_table[attr.to_sym].not_eq(nil))).last&.puppet.try(attr)
49
49
  end
50
50
 
51
+ delegate :parent_id, to: :hostgroup
52
+
51
53
  # and helpers
52
54
  def parent_facet_id
53
55
  parent_facet&.id
@@ -13,26 +13,8 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
13
13
  end
14
14
 
15
15
  def up
16
- host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
17
- host_config_group_ids.each do |host_id|
18
- host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(: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
27
- end
28
- hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
29
- hostgroup_config_group_ids.each do |hostgroup_id|
30
- hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(: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)
34
- .update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
35
- end
16
+ migrate_host_data_to_facets
17
+ migrate_hostgroup_data_to_facets
36
18
  end
37
19
 
38
20
  def down
@@ -51,4 +33,38 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
51
33
  .update_all(host_type: 'Hostgroup', host_id: hostgroup_facet_ids[hostgroup_facet_id])
52
34
  end
53
35
  end
36
+
37
+ private
38
+
39
+ def migrate_host_data_to_facets
40
+ host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
41
+ host_config_group_ids.each do |host_id|
42
+ host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
43
+ host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
44
+ if host_facet_id
45
+ host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
46
+ else
47
+ deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
48
+ say "Deleting Config groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because the Host doesn't exist or has no environment"
49
+ host_groups.delete_all
50
+ end
51
+ end
52
+ end
53
+
54
+ def migrate_hostgroup_data_to_facets
55
+ hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
56
+ hostgroup_config_group_ids.each do |hostgroup_id|
57
+ hostgroup = Hostgroup.unscoped.find_by(id: hostgroup_id)
58
+ hostgroup_groups = FakeHostConfigGroup.for_hostgroup.where(host_id: hostgroup_id)
59
+ if hostgroup
60
+ hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
61
+ hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: hostgroup).id
62
+ hostgroup_groups.update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
63
+ else
64
+ deleted_groups = FakeConfigGroup.where(id: hostgroup_groups.pluck(:config_group_id)).pluck(:name)
65
+ say "Deleting Config groups #{deleted_groups.join(', ')} from Hostgroup (id=#{hostgroup_id}) because Hostgroup doesn't exist"
66
+ hostgroup_groups.delete_all
67
+ end
68
+ end
69
+ end
54
70
  end
@@ -0,0 +1,10 @@
1
+ class CleanupEnvironmentFromCoreTables < ActiveRecord::Migration[6.0]
2
+ def up
3
+ ::Hostgroup.update_all(environment_id: nil) if column_exists?(:hostgroups, :environment_id)
4
+ Host::Managed.update_all(environment_id: nil) if column_exists?(:hosts, :environment_id)
5
+ end
6
+
7
+ def down
8
+ # nothing to do
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '1.0.5'.freeze
3
3
  end