diff --git a/definitions/features/foreman_proxy.rb b/definitions/features/foreman_proxy.rb index 8e017511c..6e14a8742 100644 --- a/definitions/features/foreman_proxy.rb +++ b/definitions/features/foreman_proxy.rb @@ -28,11 +28,7 @@ def dhcpd_conf_exist? end def services - services = [system_service('foreman-proxy', 40)] - if check_max_version('foreman-proxy', '2.4') - services << system_service('smart_proxy_dynflow_core', 20) - end - services + [system_service('foreman-proxy', 40)] end def features diff --git a/definitions/features/foreman_tasks.rb b/definitions/features/foreman_tasks.rb index 90fa4de0d..ce2387bf6 100644 --- a/definitions/features/foreman_tasks.rb +++ b/definitions/features/foreman_tasks.rb @@ -91,11 +91,9 @@ def delete(state) DELETE FROM foreman_tasks_tasks WHERE #{tasks_condition}; -- Delete locks and links which may now be orphaned DELETE FROM foreman_tasks_locks as ftl where ftl.task_id NOT IN (SELECT id FROM foreman_tasks_tasks); + DELETE FROM foreman_tasks_links as ftl where ftl.task_id NOT IN (SELECT id FROM foreman_tasks_tasks); SQL - sql += 'DELETE FROM foreman_tasks_links as ftl ' \ - 'where ftl.task_id NOT IN (SELECT id FROM foreman_tasks_tasks);' - feature(:foreman_database).psql("BEGIN; #{sql}; COMMIT;") count(state) diff --git a/definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb b/definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb deleted file mode 100644 index fa0e796e1..000000000 --- a/definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb +++ /dev/null @@ -1,64 +0,0 @@ -module Procedures::Foreman - class RemoveDuplicateObsoleteRoles < ForemanMaintain::Procedure - metadata do - for_feature :foreman_database - description 'Remove duplicate obsolete roles from DB' - confine do - check_max_version('foreman', '1.20') - end - end - - def run - duplicate_roles = feature(:foreman_database).query( - Checks::Foreman::CheckDuplicateRoles.query_to_get_duplicate_roles - ) - roles_hash = duplicate_roles.each_with_object({}) do |role_rec, new_obj| - r_name = role_rec['name'] - new_obj[r_name] = [] unless new_obj.key?(r_name) - new_obj[r_name] << role_rec['id'].to_i - end - duplicate_role_ids = filter_consumed_roles(roles_hash) - remove_obsolete_role_records(duplicate_role_ids) unless duplicate_role_ids.empty? - end - - private - - def filter_consumed_roles(roles_hash) - consumed_role_ids = find_consumed_role_ids - roles_hash.values.map do |ids| - consumed_ids = ids & consumed_role_ids - if consumed_ids.count == 1 - ids -= consumed_ids - elsif consumed_ids.count > 1 - ids -= consumed_ids - update_duplicate_consumed_roles(consumed_ids) - elsif ids.length > 1 - ids.delete(ids.min) - end - ids - end.flatten - end - - def find_consumed_role_ids - feature(:foreman_database).query(<<-SQL).map { |r| r['role_id'].to_i } - select DISTINCT(role_id) role_id from user_roles - SQL - end - - def update_duplicate_consumed_roles(role_ids) - logger.info("Updating name of duplicate consumed roles using id(s): #{role_ids.join(', ')}") - - feature(:foreman_database).psql(<<-SQL) - UPDATE roles set name = concat(name, ' - ', id) where id in (#{role_ids.join(', ')}) - SQL - end - - def remove_obsolete_role_records(role_ids) - feature(:foreman_database).psql(<<-SQL) - BEGIN; - DELETE from roles r where r.id IN (#{role_ids.join(', ')}); - COMMIT; - SQL - end - end -end