From f1be5be743bba9a014d90d1cc6b9c377ea0f2a47 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Thu, 21 Nov 2019 14:27:36 +0100 Subject: [PATCH 1/6] Fixes #28329 - Add support for dynflow_sidekiq --- definitions/features/dynflow_sidekiq.rb | 40 +++++++++++++++++++++++++ definitions/features/foreman_tasks.rb | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 definitions/features/dynflow_sidekiq.rb diff --git a/definitions/features/dynflow_sidekiq.rb b/definitions/features/dynflow_sidekiq.rb new file mode 100644 index 000000000..cc9a53bea --- /dev/null +++ b/definitions/features/dynflow_sidekiq.rb @@ -0,0 +1,40 @@ +class Features::DynflowSidekiq < ForemanMaintain::Feature + metadata do + label :dynflow_sidekiq + + confine do + server? && find_package('foreman-dynflow-sidekiq') + end + + def services + [ + # TODO: Move redis to a separate feature when we're sure how it will be configured + system_service('redis', 10), + service_names.map { |service| system_service service, instance_priority(service) } + ].flatten + end + + def config_files + [ + '/etc/foreman/dynflow', + # Workaround until foreman-installer can deploy scaled workers + configured_services.map { |service| "/etc/systemd/system/multi-user.target.wants/#{service}.service" } + ].flatten + end + + private + + def instance_priority(instance) + # Orchestrator should be started before the workers are + instance.end_with?('@orchestrator') ? 30 : 31 + end + + def service_names + configured_instances.map { |instance| "dynflow-sidekiq@#{instance}" } + end + + def configured_instances + Dir["/etc/foreman/dynflow/*"].map { |config| File.basename(config).gsub(/\.yml$/, '') } + end + end +end diff --git a/definitions/features/foreman_tasks.rb b/definitions/features/foreman_tasks.rb index 0f12f780f..e7d0e005d 100644 --- a/definitions/features/foreman_tasks.rb +++ b/definitions/features/foreman_tasks.rb @@ -108,7 +108,7 @@ def fetch_tasks_status(state, spinner) end def services - [system_service(service_name, 30)] + feature(:dynflow_sidekiq) ? [] : [system_service(service_name, 30)] end def service_name From 0753000e8df5a5eb732a7b7ee4cf3d3528dfc6f2 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Fri, 22 Nov 2019 11:42:38 +0100 Subject: [PATCH 2/6] Fixes #28329 - Move redis to its own feature --- definitions/features/dynflow_sidekiq.rb | 6 +----- definitions/features/redis.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 definitions/features/redis.rb diff --git a/definitions/features/dynflow_sidekiq.rb b/definitions/features/dynflow_sidekiq.rb index cc9a53bea..432f7faef 100644 --- a/definitions/features/dynflow_sidekiq.rb +++ b/definitions/features/dynflow_sidekiq.rb @@ -7,11 +7,7 @@ class Features::DynflowSidekiq < ForemanMaintain::Feature end def services - [ - # TODO: Move redis to a separate feature when we're sure how it will be configured - system_service('redis', 10), - service_names.map { |service| system_service service, instance_priority(service) } - ].flatten + service_names.map { |service| system_service service, instance_priority(service) } end def config_files diff --git a/definitions/features/redis.rb b/definitions/features/redis.rb new file mode 100644 index 000000000..e0a3d6456 --- /dev/null +++ b/definitions/features/redis.rb @@ -0,0 +1,22 @@ +class Features::Redis < ForemanMaintain::Feature + SCL_PREFIX = 'rh-redis5'.freeze + SERVICE_NAME = "#{SCL_PREFIX}-redis".freeze + + metadata do + label :redis + + confine do + # Luckily, the service name is the same as the package providing it + server? && find_package(SERVICE_NAME) + end + + def services + [system_service(SERVICE_NAME, 10)] + end + + def config_files + ["/etc/opt/rh/#{SCL_PREFIX}/redis", + "/etc/opt/rh/#{SCL_PREFIX}/redis.conf"] + end + end +end From 64146d77d1f2ea3921c40906f6dee29f7222c631 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Mon, 20 Jan 2020 15:21:18 +0100 Subject: [PATCH 3/6] Fixes #28329 - Make rubocop happy --- definitions/features/dynflow_sidekiq.rb | 43 +++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/definitions/features/dynflow_sidekiq.rb b/definitions/features/dynflow_sidekiq.rb index 432f7faef..8be840427 100644 --- a/definitions/features/dynflow_sidekiq.rb +++ b/definitions/features/dynflow_sidekiq.rb @@ -5,32 +5,35 @@ class Features::DynflowSidekiq < ForemanMaintain::Feature confine do server? && find_package('foreman-dynflow-sidekiq') end + end - def services - service_names.map { |service| system_service service, instance_priority(service) } - end + def services + service_names.map { |service| system_service service, instance_priority(service) } + end - def config_files - [ - '/etc/foreman/dynflow', - # Workaround until foreman-installer can deploy scaled workers - configured_services.map { |service| "/etc/systemd/system/multi-user.target.wants/#{service}.service" } - ].flatten + def config_files + # Workaround until foreman-installer can deploy scaled workers + service_symlinks = configured_services.map do |service| + "/etc/systemd/system/multi-user.target.wants/#{service}.service" end + [ + '/etc/foreman/dynflow', + service_symlinks + ].flatten + end - private + private - def instance_priority(instance) - # Orchestrator should be started before the workers are - instance.end_with?('@orchestrator') ? 30 : 31 - end + def instance_priority(instance) + # Orchestrator should be started before the workers are + instance.end_with?('@orchestrator') ? 30 : 31 + end - def service_names - configured_instances.map { |instance| "dynflow-sidekiq@#{instance}" } - end + def service_names + configured_instances.map { |instance| "dynflow-sidekiq@#{instance}" } + end - def configured_instances - Dir["/etc/foreman/dynflow/*"].map { |config| File.basename(config).gsub(/\.yml$/, '') } - end + def configured_instances + Dir['/etc/foreman/dynflow/*'].map { |config| File.basename(config).gsub(/\.yml$/, '') } end end From 1f24eb632fdc8620f7fc81129ae618a5ed1b48a9 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Tue, 21 Jan 2020 09:25:54 +0100 Subject: [PATCH 4/6] Fixes #28329 - Turn constants into methods This should allow us to modify them more easily when running on different platforms. --- definitions/features/redis.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/definitions/features/redis.rb b/definitions/features/redis.rb index e0a3d6456..186dad87c 100644 --- a/definitions/features/redis.rb +++ b/definitions/features/redis.rb @@ -1,22 +1,31 @@ class Features::Redis < ForemanMaintain::Feature - SCL_PREFIX = 'rh-redis5'.freeze - SERVICE_NAME = "#{SCL_PREFIX}-redis".freeze + SCL_NAME = 'rh-redis5'.freeze metadata do label :redis confine do # Luckily, the service name is the same as the package providing it - server? && find_package(SERVICE_NAME) + server? && find_package(service_name) end + end - def services - [system_service(SERVICE_NAME, 10)] - end + def services + [system_service(service_name, 10)] + end - def config_files - ["/etc/opt/rh/#{SCL_PREFIX}/redis", - "/etc/opt/rh/#{SCL_PREFIX}/redis.conf"] - end + def config_files + ["/etc/opt/rh/#{SCL_NAME}/redis", + "/etc/opt/rh/#{SCL_NAME}/redis.conf"] + end + + private + + def scl_prefix + "#{SCL_NAME}-" + end + + def service_name + "#{scl_prefix}redis" end end From 194351c05eaf1df9486601ed6e674ab898e896ab Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Tue, 21 Jan 2020 13:15:50 +0100 Subject: [PATCH 5/6] Fixes #28329 - Handle redis config files paths better This should allow us to modify them more easily when running on different platforms. --- definitions/features/dynflow_sidekiq.rb | 2 +- definitions/features/redis.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/definitions/features/dynflow_sidekiq.rb b/definitions/features/dynflow_sidekiq.rb index 8be840427..961e8ce62 100644 --- a/definitions/features/dynflow_sidekiq.rb +++ b/definitions/features/dynflow_sidekiq.rb @@ -34,6 +34,6 @@ def service_names end def configured_instances - Dir['/etc/foreman/dynflow/*'].map { |config| File.basename(config).gsub(/\.yml$/, '') } + Dir['/etc/foreman/dynflow/*'].map { |config| File.basename(config, '.yml') } end end diff --git a/definitions/features/redis.rb b/definitions/features/redis.rb index 186dad87c..9dcf3fb4a 100644 --- a/definitions/features/redis.rb +++ b/definitions/features/redis.rb @@ -15,12 +15,15 @@ def services end def config_files - ["/etc/opt/rh/#{SCL_NAME}/redis", - "/etc/opt/rh/#{SCL_NAME}/redis.conf"] + %w[redis redis.conf].map { |config| File.join(etc_prefix, config) } end private + def etc_prefix + "/etc/opt/rh/#{SCL_NAME}" + end + def scl_prefix "#{SCL_NAME}-" end From bb9c27ce7033405a85267439535ddb43e2f5b3d8 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Tue, 21 Jan 2020 14:57:29 +0100 Subject: [PATCH 6/6] Fixes #28329 - Handle confine block running in the context of the class --- definitions/features/redis.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/definitions/features/redis.rb b/definitions/features/redis.rb index 9dcf3fb4a..17e923bbc 100644 --- a/definitions/features/redis.rb +++ b/definitions/features/redis.rb @@ -1,6 +1,4 @@ class Features::Redis < ForemanMaintain::Feature - SCL_NAME = 'rh-redis5'.freeze - metadata do label :redis @@ -11,24 +9,26 @@ class Features::Redis < ForemanMaintain::Feature end def services - [system_service(service_name, 10)] + [system_service(self.class.service_name, 10)] end def config_files - %w[redis redis.conf].map { |config| File.join(etc_prefix, config) } + %w[redis redis.conf].map { |config| File.join(self.class.etc_prefix, config) } end - private + class << self + SCL_NAME = 'rh-redis5'.freeze - def etc_prefix - "/etc/opt/rh/#{SCL_NAME}" - end + def etc_prefix + "/etc/opt/rh/#{SCL_NAME}" + end - def scl_prefix - "#{SCL_NAME}-" - end + def scl_prefix + "#{SCL_NAME}-" + end - def service_name - "#{scl_prefix}redis" + def service_name + "#{scl_prefix}redis" + end end end