katello 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of katello might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71f002d889e1ed307d9a97f9cc97266659b04591
4
- data.tar.gz: 699bcc1ee8187e27816ef953d3b3a471e0820481
3
+ metadata.gz: 80f67a786159867d60c20979f0602bb3863524e0
4
+ data.tar.gz: dd24b2382a538d7153d4ebaa76f237e18fdcd811
5
5
  SHA512:
6
- metadata.gz: 8b2912f0372097ecb9364fbcdf0d4d7a8d62f46458a272b6bd0bc5f2ed849266283ef23b45f270e0ab568e60fe0cb3e159b21eb7cad604b09c9b740fa5f12f1f
7
- data.tar.gz: 403cb22a72f122040550fdf5a309bf4e260545014c19ba8015126813c20e6127ff358866245bd57168a2e2d038ba53f0f4712a6ac1aaa5743962d8662b16d749
6
+ metadata.gz: 30ddccbb6ff1bc0cffa457ee04d0d0284d350893286f88814a87a616a3d3824742f2d45e1aae77c8f07341f9f7827357dd660f456de87a9a4e5d3098578d8eab
7
+ data.tar.gz: f0c4848493c531015c3b321b37aa18b0ea3ce9a0e59900a07bc51324571f36a033e20daf7307b2a81a8fca29e0c715f22fc0424b5bee5454d9fbfb9f1e6c3a92
@@ -49,11 +49,18 @@ module Katello
49
49
  query = query.select(group).group(group) if group
50
50
  sub_total = query.count
51
51
 
52
- sort_attr = params[:sort_by] || default_sort_by
52
+ sort_attr = (params[:sort_by] || default_sort_by).to_s.downcase
53
53
 
54
54
  if sort_attr
55
- sort_attr = "#{query.table_name}.#{sort_attr}" unless sort_attr.to_s.include?('.')
56
- query = query.order("#{sort_attr} #{params[:sort_order] || default_sort_order}")
55
+ table, column = sort_attr.split(".").length == 2 ? sort_attr.split(".") : [query.table_name, sort_attr]
56
+ if ActiveRecord::Base.connection.columns(table).map(&:name).include?(column)
57
+ sort_attr = "#{table}.#{column}"
58
+ else
59
+ sort_attr = default_sort_by
60
+ end
61
+ sort_order = (params[:sort_order] || default_sort_order).to_s.downcase
62
+ sort_order = default_sort_order unless ['desc', 'asc'].include?(sort_order)
63
+ query = query.order("#{sort_attr} #{sort_order}")
57
64
  elsif options[:custom_sort]
58
65
  query = options[:custom_sort].call(query)
59
66
  end
@@ -66,12 +66,6 @@ module Actions
66
66
  end
67
67
 
68
68
  def done?
69
- output[:pulp_tasks].each do |pulp_task|
70
- if pulp_exception = ::Katello::Errors::PulpError.from_task(pulp_task)
71
- fail pulp_exception
72
- end
73
- end
74
-
75
69
  external_task.all? { |task| task[:finish_time] || FINISHED_STATES.include?(task[:state]) }
76
70
  end
77
71
 
@@ -97,6 +91,14 @@ module Actions
97
91
  end
98
92
  end
99
93
 
94
+ def rescue_external_task(error)
95
+ if error.is_a?(PulpError)
96
+ raise error
97
+ else
98
+ super
99
+ end
100
+ end
101
+
100
102
  private
101
103
 
102
104
  def external_task=(external_task_data)
@@ -112,6 +114,11 @@ module Actions
112
114
 
113
115
  #Combine new tasks and remove call reports
114
116
  output[:pulp_tasks] = external_task_data.reject { |task| task['task_id'].nil? } + new_tasks
117
+ output[:pulp_tasks].each do |pulp_task|
118
+ if pulp_exception = ::Katello::Errors::PulpError.from_task(pulp_task)
119
+ fail pulp_exception
120
+ end
121
+ end
115
122
  end
116
123
 
117
124
  def get_new_tasks(current_list, spawned_task_ids)
@@ -200,6 +200,7 @@ module Katello
200
200
  load "#{Katello::Engine.root}/lib/katello/tasks/rubocop.rake"
201
201
  load "#{Katello::Engine.root}/lib/katello/tasks/asset_compile.rake"
202
202
  load "#{Katello::Engine.root}/lib/katello/tasks/clean_backend_objects.rake"
203
+ load "#{Katello::Engine.root}/lib/katello/tasks/preupgrade_content_host_check.rake"
203
204
 
204
205
  load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/2.1/import_errata.rake"
205
206
  load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/2.2/update_gpg_key_urls.rake"
@@ -212,3 +213,4 @@ module Katello
212
213
  end
213
214
  end
214
215
  end
216
+
@@ -0,0 +1,131 @@
1
+ namespace :katello do
2
+ task :preupgrade_content_host_check => ["environment"] do
3
+ desc "Task that can be run before upgrading to Katello 3.0 to show a list of registered Content Hosts that will be deleted."
4
+
5
+ ping = ::Katello::Ping.ping
6
+ if ping[:status] != ::Katello::Ping::OK_RETURN_CODE
7
+ fail _("Some backend services are not running: %s") % ping.inspect
8
+ end
9
+
10
+ puts "This script makes no modifications and can be re-run multiple times for the most up to date results."
11
+ puts "Calculating Host changes on upgrade. This may take a few minutes."
12
+
13
+ User.current = User.anonymous_api_admin
14
+ @systems_to_unregister = {}
15
+
16
+ def ensure_one_system_per_hostname(systems)
17
+ systems = get_systems_with_facts(systems)
18
+ system_hostnames = group_systems_by_hostname(systems)
19
+
20
+ system_hostnames.each do |hostname, duplicate_systems|
21
+ if duplicate_systems.count > 1
22
+ unregister_all_but_last_system(duplicate_systems)
23
+ end
24
+ end
25
+ end
26
+
27
+ def group_systems_by_hostname(systems)
28
+ system_hostnames = {}
29
+
30
+ systems.each do |system|
31
+ hostname = system.facts['network.hostname']
32
+ if system_hostnames[hostname]
33
+ system_hostnames[hostname].push(system)
34
+ else
35
+ system_hostnames[hostname] = [system]
36
+ end
37
+ end
38
+
39
+ system_hostnames
40
+ end
41
+
42
+ def get_systems_with_facts(systems)
43
+ systems_to_remove = []
44
+
45
+ systems.each do |system|
46
+ begin
47
+ facts = system.facts
48
+ unless facts
49
+ systems_to_remove.push(system)
50
+ end
51
+ rescue RestClient::Exception
52
+ systems_to_remove.push(system)
53
+ end
54
+ end
55
+
56
+ systems_to_remove.each do |system|
57
+ systems.delete(system)
58
+ unregister_system(system, "This Content Host seems to be missing from the backend service Candlepin.")
59
+ end
60
+
61
+ systems
62
+ end
63
+
64
+ def unregister_all_but_last_system(systems)
65
+ systems_by_created_date = systems.sort_by(&:created_at)
66
+ system = systems_by_created_date.pop
67
+
68
+ systems_by_created_date.each do |system_to_remove|
69
+ unregister_system(system_to_remove, "More recently registered Content Host with same hostname #{system.hostname} found.")
70
+ end
71
+
72
+ system
73
+ end
74
+
75
+ def unregister_system(system, cause)
76
+ @systems_to_unregister[system] ||= []
77
+ @systems_to_unregister[system] << cause
78
+ end
79
+
80
+ def human_output(systems)
81
+ puts "\n\nSummary:\n"
82
+ puts "Content hosts to be preserved: #{::Katello::System.count - systems.count}"
83
+ puts "Content hosts to be deleted: #{systems.count}"
84
+ end
85
+
86
+ def csv_output(systems)
87
+ header = 'uuid, name, hostname, last_checkin, causes for deletion'
88
+ ouptut_lines = systems.map do |system, causes|
89
+ "#{system.uuid},#{system.name},#{system.hostname},#{system.lastCheckin},#{causes.join(" ")}"
90
+ end
91
+ "#{header}\n#{ouptut_lines.join("\n")}"
92
+ end
93
+
94
+ def write_csv(systems)
95
+ filename = "/tmp/pre-upgrade-#{Time.new.to_i}.csv"
96
+ file = open(filename, 'w')
97
+ file.write(csv_output(systems))
98
+ file.close
99
+ filename
100
+ end
101
+
102
+ ensure_one_system_per_hostname(Katello::System.all)
103
+ systems = get_systems_with_facts(Katello::System.all)
104
+
105
+ systems.each do |system|
106
+ next if @systems_to_unregister.include?(system)
107
+ hostname = system.facts['network.hostname']
108
+
109
+ if hostname.nil?
110
+ unregister_system(system, "Missing hostname information.")
111
+ break
112
+ end
113
+
114
+ hosts = ::Host.where(:name => hostname)
115
+ if hosts.any? && hosts.where(:organization_id => system.environment.organization.id).empty? # host is not in the correct org
116
+ unregister_system(system, "Organization mismatch between Host (#{hosts[0].org.name}) and Content Host #{system.environment.organization.name}.")
117
+ end
118
+ end
119
+
120
+ if @systems_to_unregister.any?
121
+ human_output(@systems_to_unregister)
122
+ puts "Details on Content Hosts planned for deletion saved to #{write_csv(@systems_to_unregister)}"
123
+ puts "You may want to manually resolve some of the conflicts and duplicate Content Hosts."
124
+ puts "Upon upgrade those found for deletion will be removed permanently."
125
+ else
126
+ puts "Upgrading will not affect any of your Content Hosts."
127
+ end
128
+
129
+ FileUtils.touch('/var/lib/foreman/3.0_upgrade_ready')
130
+ end
131
+ end
@@ -1,3 +1,3 @@
1
1
  module Katello
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katello
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - N/A
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -1728,6 +1728,7 @@ files:
1728
1728
  - lib/katello/tasks/jshint.rake
1729
1729
  - lib/katello/tasks/jsroutes.rake
1730
1730
  - lib/katello/tasks/pretty_routes.rake
1731
+ - lib/katello/tasks/preupgrade_content_host_check.rake
1731
1732
  - lib/katello/tasks/regenerate_repo_metadata.rake
1732
1733
  - lib/katello/tasks/reindex.rake
1733
1734
  - lib/katello/tasks/rubocop.rake
@@ -1855,7 +1856,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1855
1856
  version: '0'
1856
1857
  requirements: []
1857
1858
  rubyforge_project:
1858
- rubygems_version: 2.2.3
1859
+ rubygems_version: 2.2.5
1859
1860
  signing_key:
1860
1861
  specification_version: 4
1861
1862
  summary: ''