feat(installation): Add task to remove db migrations#89
Conversation
ee1d81d to
f7e2c60
Compare
| plugin = Foreman::Plugin.find ForemanAnsibleDirector.name.underscore | ||
| ActiveRecord::MigrationContext.new(plugin.migrations_paths, ActiveRecord::SchemaMigration).down | ||
| end | ||
| end |
There was a problem hiding this comment.
I don't think this will cut it.
Quite a bit more needs to happen for proper cleanup, as Pulp objects also have to be removed.
I see two options:
- Query all Pulp Ansible Repositories, CollectionRemotes, GitRemotes, and Distributions where the label
creatorisforeman_ansible_director - Iterate over ContentUnitVersions and destroy the associated Pulp objects.
I intend to add a consistency check in general, which will do a mix of both, so this problem may already be solved in the future.
f7e2c60 to
ad04db3
Compare
| def pulp_proxy_url! | ||
| proxy = | ||
| ::SmartProxy.unscoped.with_features('Ansible_Director')&.find { |smart_proxy| smart_proxy.url.present? } || | ||
| ::SmartProxy.unscoped.find { |smart_proxy| smart_proxy.url.present? } | ||
| return proxy.url if proxy&.url.present? | ||
|
|
||
| raise Foreman::Exception, | ||
| 'No Smart Proxy with a URL is available for Foreman Ansible Director Pulp cleanup.' | ||
| end | ||
|
|
There was a problem hiding this comment.
I don't think that we want this part of the code in the way it is written here. It misses the organization filtering.
| return proxy.url if proxy&.url.present? | ||
|
|
||
| raise Foreman::Exception, | ||
| 'No Smart Proxy with a URL is available for Foreman Ansible Director Pulp cleanup.' |
There was a problem hiding this comment.
the pulp_proxy_url is not only related to the pulp cleanup. adjust error message.
| class << self | ||
| def pulp_proxy_url! | ||
| proxy = | ||
| ::SmartProxy.unscoped.with_features('Ansible_Director')&.find { |smart_proxy| smart_proxy.url.present? } || |
There was a problem hiding this comment.
the second find should not be necessary.
| def pulp3_configuration(config_class) | ||
| config_class.new do |config| | ||
| uri = URI.parse(::SmartProxy.first.url) | ||
| uri = URI.parse(pulp_proxy_url!) |
| ::ForemanAnsibleDirector::ContentUnitVersion.find_each do |content_unit_version| | ||
| ::ForemanAnsibleDirector::TaskHelpers.destroy_content_unit_version_pulp_objects( | ||
| content_unit_version, | ||
| deleted_hrefs |
There was a problem hiding this comment.
what is the purpose of this deleted_hrefs?
| role_remote: Set.new, | ||
| } | ||
|
|
||
| ::ForemanAnsibleDirector::ContentUnitVersion.find_each do |content_unit_version| |
There was a problem hiding this comment.
It need to cleanup the Execution Environments, too.
| module TaskHelpers | ||
| module_function | ||
|
|
||
| def destroy_pulp_object(deleted_hrefs, key, href, action, input_key) |
There was a problem hiding this comment.
Is it posible to re-use the introduced labels 1be49d4#diff-bc0ac4dcf2708e3d510050a532b88b8bde8d3e97af27d3b9bde58b62ea777005R13 to find and remove the pulp content / images?
There was a problem hiding this comment.
You mean we could have a call to Pulp which simply removes everything with one specific label?
There was a problem hiding this comment.
yes. this should be possible - for each remote / distribution / publication / etc.
|
|
||
| require 'pulpcore_client' | ||
| module ForemanAnsibleDirector | ||
| module Pulp3 |
There was a problem hiding this comment.
Why is this file being touched at all?
It is an integral requirement of this plugin that Pulp (via Katello) exists on Foreman server.
For this plugin to function at all, the first smart proxy (provisioned on Foreman server) must provide a pulp_ansible API at it's URL.
Use of the Pulp instances of other smart proxies is not and will not be supported.
There was a problem hiding this comment.
Actually, I'm unsure if this is a requirement in general or just now that there is a Smart Proxy Ansible Director on the Foreman server. Can you explain why?
There was a problem hiding this comment.
Thanks for clarification, I'll remove it. I don't think it is necessary for the issue at hand.
There was a problem hiding this comment.
It won't work in the rake context without adjusting the smart proxy urls. I don't completely understand why this is happening but it seems the code is somehow running in another scope during the rake task execution and the proxy does not resolve correctly.
There was a problem hiding this comment.
As mentioned before, there is no guarrantee that the Pulp instance used to store Ansible content has the Ansible_Director feature.
This config will break for all cases where the Smart Proxy provisioned on Foreman Server (id: 1, used to store content) does not have the smart_proxy_ansible_director plugin installed.
There was a problem hiding this comment.
But we need to change this code in a way that it works in rake scope. I will give it another thought.
d583b0e to
b2ec0e8
Compare
| engine_name 'foreman_ansible_director' | ||
|
|
||
| initializer 'foreman_ansible_director.cleanup_context' do |app| | ||
| app.config.x.foreman_ansible_director.running_in_rake = false |
There was a problem hiding this comment.
About the config.x thing: https://guides.rubyonrails.org/configuring.html#custom-configuration
The idea is that we set a flag here and change it in the Rake task. We can evaluate this in the code and choose a smart proxy accordingly. Turns out this works for the smart proxy base client part but not for the pulp3 base client part.
2fbd6e6 to
7118691
Compare
In case we want to remove the plugin, we need clearly defined names for the settings, so we do not accidently remove some setting from another plugin or core.
7118691 to
4a8f44b
Compare
Preparation for plugin deinstallation Refs similar task in ATIX-AG/foreman_resource_quota@37b7c99 Also adds task to clean up the created Pulp content.
4a8f44b to
efa13db
Compare
| def pulp3_configuration(config_class) | ||
| config_class.new do |config| | ||
| uri = URI.parse(::SmartProxy.first.url) | ||
| uri = URI.parse(::SmartProxy.unscoped.first.url) |
There was a problem hiding this comment.
I don't really like this. But it does not seem to work otherwise, even if I add a Rails flag. Maybe because the task is created in rake env but then scheduled from the Rails application. Not sure what exactly happens here. However, something similar seems to exist in Katello:
https://github.com/Katello/katello/blob/master/app/models/katello/concerns/smart_proxy_extensions.rb#L88
| def ensure_ansible_director_proxy! | ||
| proxies = ansible_director_proxies | ||
| missing_feature_message = | ||
| 'No Smart Proxy with the Ansible_Director feature is available for Foreman Ansible Director Pulp cleanup.' | ||
| raise Foreman::Exception, missing_feature_message unless records_exist?(proxies) | ||
|
|
||
| proxy = proxies.first | ||
| return if proxy&.url.present? | ||
|
|
||
| missing_url_message = | ||
| 'No Smart Proxy with a configured URL is available for Foreman Ansible Director Pulp cleanup.' | ||
| raise Foreman::Exception, missing_url_message | ||
| end |
There was a problem hiding this comment.
I know there is something similar in the proxy base client but I thought it might be a good idea to check on the proxy before even starting a task not when the task is running or whenever this is evaluated.
Preparation for plugin deinstallation
Refs similar task in ATIX-AG/foreman_resource_quota@37b7c99