Skip to content

Commit

Permalink
Fixes #37958 - Add "Sync Dependencies" option to Ansible collection r…
Browse files Browse the repository at this point in the history
…epositories
  • Loading branch information
Thorben-D committed Nov 19, 2024
1 parent ea1b911 commit 34440d9
Show file tree
Hide file tree
Showing 15 changed files with 29,030 additions and 28,068 deletions.
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def repository_params
keys = [:download_policy, :mirroring_policy, :sync_policy, :arch, :verify_ssl_on_sync, :upstream_password,
:upstream_username, :download_concurrency, :metadata_expire,
{:os_versions => []}, :deb_releases, :deb_components, :deb_architectures, :description,
:http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []}
:http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []}, :sync_dependencies
]
keys += [{:include_tags => []}, {:exclude_tags => []}, :docker_upstream_name] if params[:action] == 'create' || @repository&.docker?
keys += [:upstream_authentication_token] if params[:action] == 'create' || @repository&.yum?
Expand Down Expand Up @@ -620,7 +620,7 @@ def construct_repo_from_params(repo_params) # rubocop:disable Metrics/AbcSize
root = @product.add_repo(repo_params.slice(:label, :name, :description, :url, :content_type, :arch, :unprotected,
:gpg_key, :ssl_ca_cert, :ssl_client_cert, :ssl_client_key,
:checksum_type, :download_policy, :http_proxy_policy,
:metadata_expire).to_h.with_indifferent_access)
:metadata_expire, :sync_dependencies).to_h.with_indifferent_access)
root.verify_ssl_on_sync = ::Foreman::Cast.to_bool(repo_params[:verify_ssl_on_sync]) if repo_params.key?(:verify_ssl_on_sync)
root.mirroring_policy = repo_params[:mirroring_policy] || Katello::RootRepository::MIRRORING_POLICY_CONTENT
root.upstream_username = repo_params[:upstream_username] if repo_params.key?(:upstream_username)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/event_daemon/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def start
FileUtils.touch(lock_file)

File.open(lock_file, 'r') do |lockfile|
lockfile.flock(File::LOCK_EX)
#lockfile.flock(File::LOCK_EX)
return nil if started? # ensure it wasn't started while we waited for the lock
start_monitor_thread
write_pid_file
Expand Down
3 changes: 2 additions & 1 deletion app/services/katello/pulp3/repository/ansible_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def remote_options
requirements_file: root.ansible_collection_requirements.blank? ? nil : root.ansible_collection_requirements,
auth_url: root.ansible_collection_auth_url,
token: root.ansible_collection_auth_token,
tls_validation: root.verify_ssl_on_sync)
tls_validation: root.verify_ssl_on_sync,
sync_dependencies: root.sync_dependencies)
end

def distribution_options(path)
Expand Down
1 change: 1 addition & 0 deletions app/views/katello/api/v2/repositories/show.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ glue(@resource.root) do
attributes :ssl_ca_cert_id
attributes :ssl_client_cert_id
attributes :ssl_client_key_id
attributes :sync_dependencies

attributes :product_type
attributes :upstream_username
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSyncDepsToAnsibleCollection < ActiveRecord::Migration[6.1]
def change
add_column :katello_root_repositories, :sync_dependencies, :boolean, :default => true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ <h4 translate>Sync Settings</h4>
edit-trigger="uploadedFile">
</dd>

<dt translate>Sync Dependencies</dt>
<dd bst-edit-checkbox="repository.sync_dependencies"
formatter="booleanToYesNo"
on-save="save(repository)"
readonly="denied('edit_products', product) || !repository.allow_updates || repository.is_container_push">
</dd>

<dt translate>Ansible Collection Authorization</dt>
<dd bst-edit-custom="repository.ansible_collection_auth_exists"
readonly="denied('edit_products', product) || !repository.allow_updates || repository.is_container_push"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ angular.module('Bastion.repositories').controller('NewRepositoryController',
});

$scope.save = function (repository) {
var fields = ['upstream_password', 'upstream_username', 'ansible_collection_auth_token', 'ansible_collection_auth_url', 'ansible_collection_requirements'];
var fields = ['upstream_password', 'upstream_username', 'ansible_collection_auth_token', 'ansible_collection_auth_url', 'ansible_collection_requirements', 'sync_repositories'];
if (repository.content_type === 'yum') {
repository.os_versions = $scope.osVersionsParam();
repository.ignorable_content = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ <h4 translate> Sync Settings </h4>
</a></p>
</div>

<div ng-show="repository.content_type === 'ansible_collection'">
<div class="checkbox">
<label>
<input id="sync_dependencies" name="sync_dependencies" ng-model="repository.sync_dependencies" ng-init="repository.sync_dependencies=true" type="checkbox"/>
<span translate>Sync Dependencies</span>
</label>

<p class="help-block" translate>
Include dependencies of Ansible collections in the repository.
</p>
</div>
</div>

<div ng-show="repository.content_type === 'ansible_collection'" bst-form-group label="{{ 'Auth URL' | translate }}">
<input id="ansible_collection_auth_url"
name="ansible_collection_auth_url"
Expand Down
10 changes: 10 additions & 0 deletions test/actions/pulp3/orchestration/ansible_collection_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def test_sync
assert_equal repository_reference.repository_href + "versions/1/", @repo.version_href
end

def test_sync_wo_dependencies
repo = katello_repositories(:pulp3_ansible_collection_wo_deps_1)
sync_args = {:smart_proxy_id => @primary.id, :repo_id => repo.id}
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::Sync, repo, @primary, sync_args)
repo.reload

pulp_remote = repo.backend_service(@primary).get_remote
assert_equal pulp_remote.sync_dependencies, repo.sync_dependencies
end

def test_sync_mirror_false
sync_args = {:smart_proxy_id => @primary.id, :repo_id => @repo.id}
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::Sync, @repo, @primary, sync_args)
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/models/katello_repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ pulp3_ansible_collection_1:
environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_default_version) %>

pulp3_ansible_collection_wo_deps_1:
root_id: <%= ActiveRecord::FixtureSet.identify(:pulp3_ansible_collection_root_wo_deps_1) %>
pulp_id: "Default_Organization-Cabinet-pulp3_Ansible_collection_wo_deps_1"
relative_path: 'Default_Organization/library/pulp3_Ansible_collection_wo_deps_1'
environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_default_version) %>

pulp3_docker_1:
root_id: <%= ActiveRecord::FixtureSet.identify(:pulp3_docker_root_1) %>
pulp_id: "Default_Organization-Cabinet-pulp3_Docker_1"
Expand Down
20 changes: 19 additions & 1 deletion test/fixtures/models/katello_root_repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,27 @@ pulp3_ansible_collection_root_1:
verify_ssl_on_sync: <%= false %>
mirroring_policy: "mirror_content_only"

pulp3_ansible_collection_root_wo_deps_1:
name: Pulp3 Ansible Collection wo deps 1
content_id: 12
content_type: ansible_collection
label: Pulp3_Ansible_Collection_wo_deps_1
product_id: <%= ActiveRecord::FixtureSet.identify(:fedora) %>
gpg_key_id: <%= ActiveRecord::FixtureSet.identify(:fedora_gpg_key) %>
unprotected: <%= true %>
url: "https://galaxy.ansible.com/"
sync_dependencies: <%= false %>
ansible_collection_requirements: "---\n
collections:\n
- robertdebock.rundeck_collection"
ansible_collection_auth_url: "https://some.authUrl.com"
ansible_collection_auth_token: "random_token"
verify_ssl_on_sync: <%= false %>
mirroring_policy: "mirror_content_only"

pulp3_docker_root_1:
name: Pulp3 Docker 1
content_id: 13
content_id: 14
content_type: docker
label: Pulp3_Docker_1
product_id: <%= ActiveRecord::FixtureSet.identify(:fedora) %>
Expand Down
Loading

0 comments on commit 34440d9

Please sign in to comment.