foreman_scc_manager 1.8.19 → 1.8.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94924eef8de5143907ca81d9ea6c41915d51c931d394356497e7168b8ffbe09e
4
- data.tar.gz: 49d822f0d3c70abd53a0d818c3dc7c2102c9e12e8c325a3580f9e966bf50dd61
3
+ metadata.gz: 39d299a2ed13146bd47fda51bfe3b47cccc78a2fe3984f5070b38acfa1d54bb0
4
+ data.tar.gz: eb22cc8040b485c69aa0dffd09b91a5ba926e89c9d124f4d9a32800a8db7546f
5
5
  SHA512:
6
- metadata.gz: c26c8d840bd3a97a3cbc99e84dc53bc17c48a8175dd026cfd618d5597cbf934373ed048c978e5805db1942ef0b3b4ef9283ee60b8e36b26e5d3a886e48f20067
7
- data.tar.gz: 6599cad1358b63afba7824ca2d8f7328d30c8f2d851814b681be2b7ec4de42116e9e3160680cd814f960cb49b65fd09edda863a7383e5fabd93925791bd6600e
6
+ metadata.gz: bf8c718efe53da5e8f8b417e249bfb3826a080f328331bee932af7108b0fea3da7a0f6b2fc5f581dc0c9f1588e056ae19d1dad83a2e3f45e2ba776763f672a1a
7
+ data.tar.gz: 83665d655bb8fa02fa9140115b3d6a604c7e18bde4c1bb4cc5d0bda505c2e1df7cb8c34fc515c62894e0964edc78ca0c773ca5ec34ed1d821ffe87304ecdd0b3
@@ -33,7 +33,7 @@ module Api
33
33
  param :login, String, :required => true, :desc => N_('Login id of scc_account')
34
34
  param :password, String, :required => true, :desc => N_('Password of scc_account')
35
35
  param :base_url, String, :required => false, :desc => N_('URL of SUSE for scc_account')
36
- param :interval, ['never', 'daily', 'weekly', 'monthy'], :desc => N_('Interval for syncing scc_account')
36
+ param :interval, ['never', 'daily', 'weekly', 'monthly'], :desc => N_('Interval for syncing scc_account')
37
37
  param :sync_date, String, :desc => N_('Date and time relative to which the sync interval is run')
38
38
  param :katello_gpg_key_id, :identifier, :required => false, :desc => N_('Associated GPG key of scc_account')
39
39
  end
@@ -19,7 +19,8 @@ module Actions
19
19
  :product_id => product_create_action.output[:product_id],
20
20
  :uniq_name => repo.uniq_name(scc_product),
21
21
  :pretty_repo_name => repo.pretty_name,
22
- :url => repo.full_url,
22
+ :url => repo.url,
23
+ :token => repo.token,
23
24
  :arch => arch)
24
25
  katello_repos[repo.id] = repo_create_action.output[:katello_root_repository_id]
25
26
  end
@@ -37,8 +38,7 @@ module Actions
37
38
  scc_product.update!(product: product)
38
39
  # extract Katello repo ids from input hash and store to database
39
40
  input[:katello_repos].each do |scc_repo_id, katello_root_repository_id|
40
- scc_repo = SccRepository.find(scc_repo_id)
41
- scc_repo.update!(katello_root_repository_id: katello_root_repository_id)
41
+ SccKatelloRepository.find_or_create_by(scc_repository_id: scc_repo_id, katello_root_repository_id: katello_root_repository_id)
42
42
  end
43
43
  end
44
44
 
@@ -79,7 +79,6 @@ module Actions
79
79
  gpg_key = product.gpg_key
80
80
  repo_param = { :label => label,
81
81
  :name => input[:pretty_repo_name],
82
- :url => input[:url],
83
82
  :content_type => 'yum',
84
83
  :unprotected => unprotected,
85
84
  :gpg_key => gpg_key,
@@ -91,6 +90,13 @@ module Actions
91
90
  else
92
91
  repository.mirroring_policy = ::Katello::RootRepository::MIRRORING_POLICY_CONTENT
93
92
  end
93
+ if repository.has_attribute?('upstream_authentication_token')
94
+ repository.url = input[:url]
95
+ repository.upstream_authentication_token = input[:token]
96
+ else
97
+ repository.url = input[:token].blank? ? input[:url] : "#{input[:url]}?#{input[:token]}"
98
+ end
99
+
94
100
  repository.verify_ssl_on_sync = true
95
101
  trigger(::Actions::Katello::Repository::CreateRoot, repository).tap do
96
102
  output[:katello_root_repository_id] = repository.id
@@ -194,12 +194,13 @@ class SccAccount < ApplicationRecord
194
194
 
195
195
  # all scc repos that are kept but not available upstream need to be marked invalid
196
196
  # subscription_valid can be set to nil
197
- to_invalidate = invalidated_repos.select { |ir| ir.katello_root_repository_id.present? && !ir.subscription_valid }
197
+ to_invalidate = invalidated_repos.select { |ir| ir.katello_root_repositories.count > 0 && !ir.subscription_valid }
198
198
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Invalidating #{to_invalidate.count} expired repositories"
199
199
  invalidate_subscription_status(to_invalidate, save_record: true)
200
200
 
201
201
  # delete repositories being removed upstream and that are not subscribed to
202
- to_delete = scc_repositories.where.not(scc_id: upstream_repo_ids)
202
+ to_delete = scc_repositories.where.not(scc_id: upstream_repo_ids).includes(:scc_katello_repositories).where(scc_katello_repositories: { id: nil })
203
+
203
204
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Deleting #{to_delete.count} old repositories"
204
205
  to_delete.destroy_all
205
206
  end
@@ -0,0 +1,4 @@
1
+ class SccKatelloRepository < ApplicationRecord
2
+ belongs_to :scc_repository
3
+ belongs_to :katello_root_repository, class_name: 'Katello::RootRepository'
4
+ end
@@ -56,13 +56,19 @@ class SccProduct < ApplicationRecord
56
56
  label = Katello::Util::Model.labelize(uniq_repo_name)
57
57
  unprotected = true
58
58
  gpg_key = new_product.gpg_key
59
- new_repo = new_product.add_repo(label, uniq_repo_name, repo.full_url, 'yum', unprotected, gpg_key)
59
+ new_repo = new_product.add_repo(label, uniq_repo_name, repo.url, 'yum', unprotected, gpg_key)
60
60
  new_repo.arch = arch || 'noarch'
61
61
  if new_repo.has_attribute?('mirror_on_sync')
62
62
  new_repo.mirror_on_sync = true
63
63
  else
64
64
  new_repo.mirroring_policy = ::Katello::RootRepository::MIRRORING_POLICY_CONTENT
65
65
  end
66
+ if new_repo.has_attribute?('upstream_authentication_token')
67
+ new_repo.upstream_authentication_token = repo.token
68
+ new_repo.url = repo.url
69
+ else
70
+ new_repo.url = repo.full_url
71
+ end
66
72
  new_repo.verify_ssl_on_sync = true
67
73
  ForemanTasks.sync_task(::Actions::Katello::Repository::Create, new_repo, false, false)
68
74
  end
@@ -4,7 +4,8 @@ class SccRepository < ApplicationRecord
4
4
  self.include_root_in_json = false
5
5
 
6
6
  belongs_to :scc_account
7
- belongs_to :katello_root_repository, class_name: 'Katello::RootRepository'
7
+ has_many :scc_katello_repositories
8
+ has_many :katello_root_repositories, through: :scc_katello_repositories
8
9
  has_one :organization, through: :scc_account
9
10
  has_and_belongs_to_many :scc_products
10
11
 
@@ -27,9 +28,16 @@ class SccRepository < ApplicationRecord
27
28
  # as uniq_name was changed, we need to look for repo labels that end with the repo name
28
29
  katello_repos = Katello::RootRepository.where('label like ?', "%#{::Katello::Util::Model.labelize(self.description)}%")
29
30
  katello_repos.each do |repo|
30
- unless repo.url == full_url
31
- ::Foreman::Logging.logger('foreman_scc_manager').info "Update URL-token for repository '#{repo.name}'."
32
- ForemanTasks.async_task(::Actions::Katello::Repository::Update, repo, url: full_url)
31
+ if repo.has_attribute?('upstream_authentication_token')
32
+ unless repo.url == url && repo.upstream_authentication_token == token
33
+ ForemanTasks.async_task(::Actions::Katello::Repository::Update, repo, url: url, upstream_authentication_token: token)
34
+ ::Foreman::Logging.logger('foreman_scc_manager').info "Update URL and authentication token for repository '#{repo.name}'."
35
+ end
36
+ else
37
+ unless repo.url == full_url
38
+ ForemanTasks.async_task(::Actions::Katello::Repository::Update, repo, url: full_url)
39
+ ::Foreman::Logging.logger('foreman_scc_manager').info "Update URL-token for repository '#{repo.name}'."
40
+ end
33
41
  end
34
42
  end
35
43
  end
@@ -0,0 +1,10 @@
1
+ class AddSccKatelloRepositoryRelation < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table(:scc_katello_repositories) do |t|
4
+ t.references :scc_repository, null: false, foreign_key: { on_delete: :cascade }
5
+ t.references :katello_root_repository, null: false, foreign_key: { on_delete: :cascade }
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class RemoveRootRepositoryIdFromSccRepository < ActiveRecord::Migration[6.0]
2
+ def change
3
+ remove_foreign_key :scc_repositories, :katello_root_repositories, column: :katello_root_repository_id, on_delete: :nullify
4
+ remove_column :scc_repositories, :katello_root_repository_id, :integer, index: true, null: true
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ class PopulateSccKatelloRepositories < ActiveRecord::Migration[6.0]
2
+ class SccProduct < ApplicationRecord
3
+ belongs_to :product, class_name: 'Katello::Product'
4
+ has_and_belongs_to_many :scc_repositories
5
+ end
6
+
7
+ def up
8
+ SccProduct.where.not(product_id: nil).each do |scc_p|
9
+ scc_p.scc_repositories.each do |scc_r|
10
+ # find all Katello repositories that were derived from that SCC repository
11
+ katello_repos = Katello::RootRepository.where('label like ?', "%#{::Katello::Util::Model.labelize(scc_r.description)}%")
12
+ scc_r.update!(katello_root_repositories: katello_repos)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ class PopulateUpstreamAuthenticationToken < ActiveRecord::Migration[6.0]
2
+ def up
3
+ return unless ActiveRecord::Base.connection.column_exists?('katello_root_repositories', 'upstream_authentication_token')
4
+
5
+ scc_repositories = SccRepository.includes(:scc_katello_repositories).where.not(scc_katello_repositories: { id: nil })
6
+ scc_repositories.each do |scc_repo|
7
+ scc_repo.katello_root_repositories.each do |katello_repo|
8
+ katello_repo.update!(url: scc_repo.url, upstream_authentication_token: scc_repo.token)
9
+ end
10
+ end
11
+ end
12
+
13
+ def down
14
+ return if ActiveRecord::Base.connection.column_exists?('katello_root_repositories', 'upstream_authentication_token')
15
+
16
+ scc_repositories = SccRepository.includes(:scc_katello_repositories).where.not(scc_katello_repositories: { id: nil })
17
+ scc_repositories.each do |scc_repo|
18
+ scc_repo.katello_root_repositories.each do |katello_repo|
19
+ katello_repo.update!(url: scc_repo.full_url)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '1.8.19'.freeze
2
+ VERSION = '1.8.20'.freeze
3
3
  end
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'rubocop/rake_task'
3
+
4
+ namespace :foreman_scc_manager do
5
+ desc 'Set up authentication tokens for Katello 4.3.'
6
+ task :setup_authentication_tokens => ['environment'] do
7
+ unless ActiveRecord::Base.connection.column_exists?('katello_root_repositories', 'upstream_authentication_token')
8
+ puts 'Your Katello version needs to be at 4.3 and up to run this task.'
9
+ return
10
+ end
11
+ begin
12
+ scc_repositories = SccRepository.includes(:scc_katello_repositories).where.not(scc_katello_repositories: { id: nil })
13
+ scc_repositories.each do |scc_repo|
14
+ scc_repo.katello_root_repositories.each do |katello_repo|
15
+ katello_repo.update!(url: scc_repo.url, upstream_authentication_token: scc_repo.token)
16
+ end
17
+ end
18
+ puts 'Authentication tokens created successfully.'
19
+ rescue StandardError => e
20
+ puts 'There was an error while creating the authentication tokens.'
21
+ puts e.to_s
22
+ end
23
+ end
24
+ end
25
+ rescue LoadError
26
+ puts 'Rubocop not loaded.'
27
+ end
@@ -0,0 +1,44 @@
1
+ sles12_sp4_updates:
2
+ name: SLES12-SP4-Updates for sle-12-x86_64
3
+ content_type: yum
4
+ label: 1759_SLES12-SP4-Updates_for_sle-12-x86_64_description
5
+ product_id: <%= ActiveRecord::FixtureSet.identify(:suse) %>
6
+ url: www.not-valid.com
7
+ download_policy: immediate
8
+ <% if ActiveRecord::Base.connection.column_exists? :katello_root_repositories, :mirroring_policy %>
9
+ mirroring_policy: "mirror_content_only"
10
+ <% else %>
11
+ mirror_on_sync: "true"
12
+ <% end %>
13
+ created_at: <%= Time.now %>
14
+ updated_at: <%= Time.now %>
15
+
16
+ sles12_sp4_installer_updates:
17
+ name: SLES12-SP4-Installer-Updates for sle-12-x86_64
18
+ content_type: yum
19
+ label: 1759_product_name_SLES12-SP4-Installer-Updates_for_sle-12-x86_64_description
20
+ product_id: <%= ActiveRecord::FixtureSet.identify(:suse) %>
21
+ url: www.not-valid.com
22
+ download_policy: on_demand
23
+ <% if ActiveRecord::Base.connection.column_exists? :katello_root_repositories, :mirroring_policy %>
24
+ mirroring_policy: "mirror_content_only"
25
+ <% else %>
26
+ mirror_on_sync: "true"
27
+ <% end %>
28
+ created_at: <%= Time.now %>
29
+ updated_at: <%= Time.now %>
30
+
31
+ sles12_sp4_installer_updates_2:
32
+ name: SLES12-SP4-Installer-Updates for sle-12-x86_64
33
+ content_type: yum
34
+ label: 1760_product_name_SLES12-SP4-Installer-Updates_for_sle-12-x86_64_description
35
+ product_id: <%= ActiveRecord::FixtureSet.identify(:suse) %>
36
+ url: www.not-valid.com
37
+ download_policy: on_demand
38
+ <% if ActiveRecord::Base.connection.column_exists? :katello_root_repositories, :mirroring_policy %>
39
+ mirroring_policy: "mirror_content_only"
40
+ <% else %>
41
+ mirror_on_sync: "true"
42
+ <% end %>
43
+ created_at: <%= Time.now %>
44
+ updated_at: <%= Time.now %>
@@ -25,5 +25,39 @@ repo_9:
25
25
  autorefresh: true
26
26
  installer_updates: false
27
27
 
28
+ sles12_updates:
29
+ id: 10
30
+ scc_account_id: 1
31
+ scc_id: 1
32
+ name: SLES12-SP4-Updates for sle-12-x86_64
33
+ distro_target: sles_12
34
+ description: SLES12-SP4-Updates for sle-12-x86_64
35
+ url: www.not-valid.com
36
+ token: token_10
37
+ autorefresh: true
38
+ installer_updates: false
28
39
 
29
40
 
41
+ sles12_installer_updates:
42
+ id: 11
43
+ scc_account_id: 1
44
+ scc_id: 2
45
+ name: SLES12-SP4-Installer-Updates for sle-12-x86_64
46
+ distro_target: sles_12
47
+ description: SLES12-SP4-Installer-Updates for sle-12-x86_64
48
+ url: www.not-valid.com
49
+ token: token_11
50
+ autorefresh: true
51
+ installer_updates: false
52
+
53
+ sles12_installer_updates_2:
54
+ id: 12
55
+ scc_account_id: 1
56
+ scc_id: 3
57
+ name: SLES12-SP4-Installer-Updates for sle-12-x86_64_2
58
+ distro_target: sles_9
59
+ description: SLES12-SP4-Installer-Updates for sle-12-x86_64_2
60
+ url: www.not-valid.com
61
+ token: token_12
62
+ autorefresh: true
63
+ installer_updates: false
@@ -3,7 +3,9 @@ module ForemanSccManager
3
3
  FIXTURE_CLASSES = {
4
4
  scc_accounts: ::SccAccount,
5
5
  scc_products: ::SccProduct,
6
- scc_repositories: ::SccRepository
6
+ scc_repositories: ::SccRepository,
7
+ katello_root_repositories: ::Katello::RootRepository,
8
+ scc_katello_repositories: SccKatelloRepository
7
9
  }.freeze
8
10
 
9
11
  def self.set_fixture_classes(test_class)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_scc_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.19
4
+ version: 1.8.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -128,6 +128,7 @@ files:
128
128
  - app/models/scc_account.rb
129
129
  - app/models/scc_account_sync_plan_task_group.rb
130
130
  - app/models/scc_extending.rb
131
+ - app/models/scc_katello_repository.rb
131
132
  - app/models/scc_product.rb
132
133
  - app/models/scc_repository.rb
133
134
  - app/views/api/v2/scc_accounts/base.json.rabl
@@ -165,10 +166,15 @@ files:
165
166
  - db/migrate/20210210104407_add_root_repository_id_to_scc_repository.rb
166
167
  - db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
167
168
  - db/migrate/20210713092440_add_permissions.rb
169
+ - db/migrate/20220425132605_add_scc_katello_repository_relation.rb
170
+ - db/migrate/20220429100843_remove_root_repository_id_from_scc_repository.rb
171
+ - db/migrate/20220429102717_populate_scc_katello_repositories.rb
172
+ - db/migrate/20220513132652_populate_upstream_authentication_token.rb
168
173
  - lib/foreman_scc_manager.rb
169
174
  - lib/foreman_scc_manager/engine.rb
170
175
  - lib/foreman_scc_manager/version.rb
171
176
  - lib/tasks/rubocop.rake
177
+ - lib/tasks/setup_authentication_token.rake
172
178
  - lib/tasks/test.rake
173
179
  - locale/Makefile
174
180
  - locale/action_names.rb
@@ -188,6 +194,7 @@ files:
188
194
  - test/fixtures/files/data_products_page2.json
189
195
  - test/fixtures/files/data_repositories.json
190
196
  - test/fixtures/files/data_subscriptions.json
197
+ - test/fixtures/models/katello_root_repositories.yml
191
198
  - test/fixtures/models/scc_accounts.yml
192
199
  - test/fixtures/models/scc_products.yml
193
200
  - test/fixtures/models/scc_repositories.yml
@@ -229,6 +236,7 @@ test_files:
229
236
  - test/models/scc_account_test.rb
230
237
  - test/features/sync_test.rb
231
238
  - test/fixtures/models/scc_repositories.yml
239
+ - test/fixtures/models/katello_root_repositories.yml
232
240
  - test/fixtures/models/scc_accounts.yml
233
241
  - test/fixtures/models/scc_products.yml
234
242
  - test/fixtures/files/data_products_page1.json