foreman_scc_manager 1.8.12 → 1.8.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f09d1fba685e2d82d20dcc19d519dfce35a1b6bd04b6c64353e2e40519b30fc9
4
- data.tar.gz: afdb4e0f4c17546b8984c7b29d3bebfce35fa9043fb308a60423c8f113df2b84
3
+ metadata.gz: 18d3ef9cc3c2af2f26b0da68c6abbb88491361ff689ddeb66061dc574f9604b6
4
+ data.tar.gz: f4a1152c05a14eab317d058f551a738c2e2f676d570e1810b747e05192382c3a
5
5
  SHA512:
6
- metadata.gz: 93779edde27305d62942cdcce50ba8dd548af379f0ff9b88fd7fe800b79bb3de41c58f6e873b116451ba20fbd65c89f6ab0428fbe7f8c7f25f07bc26982054f1
7
- data.tar.gz: 0c58463cfd08bf269ae9c3a6ba2b0c833f1327d5985038cf32b38ff60a3a307377498759ca6cb11734de7a31122b2743bd9a8cb84a454cc8b6167682925c14a4
6
+ metadata.gz: a5f96e7074f6372e072b99c6a49ec300d151e9f0c9b013b254f70ed1f92011849adbe3c5fa9b2c84658f9919030784ced02116682d5f77ca38b316c17bcb8665
7
+ data.tar.gz: 39d1e30b2ac55968f70fe1653e2f0e32127e5cec6cb3f5072e8c5936980f0df4c53b7fde847c00f0d5f5961d72b8207e43fe2df0d56f77137a38881d47ce2bc4
data/README.md CHANGED
@@ -8,7 +8,13 @@ Foreman plugin to sync SUSE Customer Center products and repositories into Katel
8
8
 
9
9
  ## Installation
10
10
 
11
- See [Foreman Manual](https://theforeman.org/plugins/#2.Installation) on how to install Foreman plugins.
11
+ This plugin installation is not supported by foreman-installer and has to be installed manually:
12
+
13
+ ```sh
14
+ yum install tfm-rubygem-foreman_scc_manager
15
+
16
+ foreman-installer
17
+ ```
12
18
 
13
19
  ## Compatibility
14
20
 
@@ -29,7 +35,7 @@ See [Foreman Manual](https://theforeman.org/plugins/#2.Installation) on how to i
29
35
 
30
36
  ## Documentation
31
37
 
32
- [Plugin documentation](https://docs.orcharhino.com/sources/management_ui/the_content_menu/suse_subscriptions.html)
38
+ [Plugin documentation](https://docs.orcharhino.com/or/docs/sources/usage_guides/managing_sles_systems_guide.html#mssg_installing_the_scc_manager_plugin)
33
39
 
34
40
  ## Hammer CLI Extension
35
41
 
data/Rakefile CHANGED
@@ -35,13 +35,9 @@ end
35
35
 
36
36
  task default: :test
37
37
 
38
- begin
39
- require 'rubocop/rake_task'
40
- RuboCop::RakeTask.new
41
- rescue StandardError => _e
42
- puts 'Rubocop not loaded.'
43
- end
44
-
45
- task :default do
46
- Rake::Task['rubocop'].execute
38
+ class ForemanSccManager::Engine
39
+ def self.root
40
+ File.expand_path('__dir__')
41
+ end
47
42
  end
43
+ import 'lib/tasks/rubocop.rake'
@@ -12,11 +12,22 @@ module Api
12
12
 
13
13
  before_action :find_resource, :only => [:show, :subscribe]
14
14
 
15
- api :GET, '/scc_accounts/:scc_account_id/scc_products/', N_('List all products for scc_account')
15
+ def metadata_subtotal
16
+ if @scc_products.present?
17
+ @scc_products.count
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ api :GET, '/scc_accounts/:scc_account_id/scc_products/', N_('List products for an scc_account')
16
24
  param :scc_account_id, :identifier_dottable, :required => true
25
+ param :subscribed_only, :bool, :required => false, :desc => N_('Show subscribed products only')
17
26
  param_group :search_and_pagination, ::Api::V2::BaseController
27
+
18
28
  def index
19
29
  scope = resource_scope
30
+ scope = scope.where.not(:product_id => nil) if ::Foreman::Cast.to_bool(params[:subscribed_only])
20
31
  scope = scope.where(:organization => params[:organization_id]) if params[:organization_id].present?
21
32
  @scc_products = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
22
33
  end
@@ -47,8 +58,8 @@ module Api
47
58
  private
48
59
 
49
60
  def find_resource
50
- @scc_account = ::SccAccount.find_by!(id: params[:scc_account_id])
51
- @scc_product = @scc_account.scc_products.find_by!(id: params[:id])
61
+ @scc_account = ::SccAccount.find(params[:scc_account_id])
62
+ @scc_product = @scc_account.scc_products.find(params[:id])
52
63
  end
53
64
 
54
65
  def action_permission
@@ -37,7 +37,7 @@ class SccAccountsController < ApplicationController
37
37
  # POST /scc_accounts/test_connection
38
38
  def test_connection
39
39
  @scc_account = SccAccount.new(scc_account_params)
40
- @scc_account.password = SccAccount.find_by!(id: params[:scc_account_id]).password if params[:scc_account_id].present? && scc_account_params[:password].empty?
40
+ @scc_account.password = SccAccount.find(params[:scc_account_id]).password if params[:scc_account_id].present? && scc_account_params[:password].empty?
41
41
  respond_to do |format|
42
42
  if @scc_account.test_connection
43
43
  format.json { render json: nil, status: :ok }
@@ -106,7 +106,7 @@ class SccAccountsController < ApplicationController
106
106
 
107
107
  def find_organization
108
108
  @organization = Organization.current
109
- redirect_to '/select_organization?toState=' + request.path unless @organization
109
+ redirect_to "/select_organization?toState=#{request.path}" unless @organization
110
110
  end
111
111
 
112
112
  # Use callbacks to share common setup or constraints between actions.
@@ -10,7 +10,8 @@ module SccManager
10
10
  end
11
11
 
12
12
  url = base_url + rest_url
13
- auth_header = { Authorization: 'Basic ' + Base64.encode64("#{login}:#{password}").chomp,
13
+ credentials = Base64.encode64("#{login}:#{password}").chomp
14
+ auth_header = { Authorization: "Basic #{credentials}",
14
15
  Accept: 'application/vnd.scc.suse.com.v4+json' }
15
16
  results = []
16
17
  loop do
@@ -172,7 +172,7 @@ class SccAccount < ApplicationRecord
172
172
  def update_scc_repositories(upstream_repositories)
173
173
  upstream_repo_ids = []
174
174
  # initially invalidate all repositories and validate them during update
175
- invalidated_repos = invalidate_subscription_status(scc_repositories)
175
+ invalidated_repos = invalidate_subscription_status(scc_repositories, save_record: false)
176
176
  # import repositories
177
177
  upstream_repositories.each do |ur|
178
178
  cached_repository = scc_repositories.find_or_initialize_by(scc_id: ur['id'])
@@ -196,7 +196,7 @@ class SccAccount < ApplicationRecord
196
196
  # subscription_valid can be set to nil
197
197
  to_invalidate = invalidated_repos.select { |ir| ir.katello_root_repository_id.present? && !ir.subscription_valid }
198
198
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Invalidating #{to_invalidate.count} expired repositories"
199
- invalidate_subscription_status(to_invalidate, true)
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
202
  to_delete = scc_repositories.where.not(scc_id: upstream_repo_ids)
@@ -207,7 +207,7 @@ class SccAccount < ApplicationRecord
207
207
  def update_scc_products(upstream_products)
208
208
  upstream_product_ids = []
209
209
  # initially invalidate all products and validate them during update
210
- invalidated_products = invalidate_subscription_status(scc_products)
210
+ invalidated_products = invalidate_subscription_status(scc_products, save_record: false)
211
211
  # import products
212
212
  upstream_products.each do |up|
213
213
  cached_product = scc_products.find_or_initialize_by(scc_id: up['id'])
@@ -233,7 +233,7 @@ class SccAccount < ApplicationRecord
233
233
  # subscription_valid can be set to nil
234
234
  to_invalidate = invalidated_products.select { |ip| ip.product_id.present? && !ip.subscription_valid }
235
235
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Invalidating #{to_invalidate.count} expired products"
236
- invalidate_subscription_status(to_invalidate, true)
236
+ invalidate_subscription_status(to_invalidate, save_record: true)
237
237
 
238
238
  # delete products being removed upstream and that are not subscribed to
239
239
  to_delete = scc_products.where.not(scc_id: upstream_product_ids).where(product_id: nil)
@@ -266,9 +266,9 @@ class SccAccount < ApplicationRecord
266
266
 
267
267
  # set all products/repos invalid
268
268
  # params: items_to_invalidate: ActiveRecord_(*)
269
- # save_record: store in database or not (default)
269
+ # save_record: store in database or not
270
270
  # return: ActiveRecord elements with invalidated subscription status
271
- def invalidate_subscription_status(items_to_invalidate, save_record = false)
271
+ def invalidate_subscription_status(items_to_invalidate, save_record:)
272
272
  if items_to_invalidate.present?
273
273
  items_to_invalidate.each do |inv|
274
274
  inv.subscription_valid = false
@@ -9,11 +9,11 @@ class SccRepository < ApplicationRecord
9
9
  has_and_belongs_to_many :scc_products
10
10
 
11
11
  def full_url
12
- token.blank? ? url : url + '?' + token
12
+ token.blank? ? url : "#{url}?#{token}"
13
13
  end
14
14
 
15
15
  def uniq_name(scc_product)
16
- scc_product.scc_id.to_s + ' ' + description
16
+ "#{scc_product.scc_id} #{description}"
17
17
  end
18
18
 
19
19
  def pretty_name
@@ -0,0 +1,5 @@
1
+ class AddProductClassToSccProduct < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :scc_products, :product_class, :string
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '1.8.12'.freeze
2
+ VERSION = '1.8.13'.freeze
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class SccManagerActions < ActiveSupport::TestCase
4
+ include Dynflow::Testing
5
+
6
+ let(:action_class) { ::Actions::SccManager::Sync }
7
+
8
+ def setup
9
+ @scc_account = scc_accounts(:one)
10
+ # ensure we have an org label
11
+ get_organization
12
+ end
13
+
14
+ test 'plan sync action' do
15
+ action = create_action(action_class)
16
+ action.stubs(:action_subject).with(@scc_account)
17
+
18
+ assert_respond_to(action, :phase)
19
+ plan_action(action, @scc_account)
20
+
21
+ assert_action_planned_with(action, ::Actions::SccManager::SyncProducts, @scc_account)
22
+ assert_action_planned_with(action, ::Actions::SccManager::SyncRepositories, @scc_account)
23
+ end
24
+ end
@@ -5,7 +5,9 @@ class Api::V2::SccProductsControllerTest < ActionController::TestCase
5
5
  @scc_account = scc_accounts(:one)
6
6
  @scc_product1 = scc_products(:one)
7
7
  @scc_product2 = scc_products(:two)
8
- @scc_account.scc_products = [@scc_product1, @scc_product2]
8
+ @scc_product3 = scc_products(:three)
9
+ @scc_product4 = scc_products(:four)
10
+ @scc_account.scc_products = [@scc_product1, @scc_product2, @scc_product3, @scc_product4]
9
11
  end
10
12
 
11
13
  test 'should get index' do
@@ -37,4 +39,22 @@ class Api::V2::SccProductsControllerTest < ActionController::TestCase
37
39
  put :subscribe, params: { :id => 'doest-not-exit', :scc_account_id => @scc_account.id }
38
40
  assert_response :not_found
39
41
  end
42
+
43
+ test 'show subscribed products only' do
44
+ get :index, params: { :scc_account_id => @scc_account.id, :subscribed_only => true }
45
+ assert_response :success
46
+ body = ActiveSupport::JSON.decode(@response.body)
47
+ assert_not_empty body
48
+ assert_equal 2, body['results'].count
49
+ assert_equal 2, body['subtotal']
50
+ end
51
+
52
+ test 'show all products if subscribed_only flag is set to false' do
53
+ get :index, params: { :scc_account_id => @scc_account.id, :subscribed_only => false }
54
+ assert_response :success
55
+ body = ActiveSupport::JSON.decode(@response.body)
56
+ assert_not_empty body
57
+ assert_equal 4, body['results'].count
58
+ assert_equal 4, body['subtotal']
59
+ end
40
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class SccAccountsControllerTest2 < ActionDispatch::IntegrationTest
@@ -0,0 +1,10 @@
1
+ p1:
2
+ id: 1
3
+ name: 'katello product 1'
4
+ provider_id: 1
5
+ created_at: Time.now
6
+ p2:
7
+ id: 2
8
+ name: 'katello product 2'
9
+ provider_id: 1
10
+ created_at: Time.now
@@ -10,6 +10,7 @@ one:
10
10
  description: "<p> lorem ipsum dolor sit amet </p>"
11
11
  product_type: base
12
12
  subscription_valid: nil
13
+ product_id: nil
13
14
 
14
15
  two:
15
16
  scc_account_id: test_account1
@@ -21,6 +22,7 @@ two:
21
22
  description: "<p> lorem ipsum dolor sit amet </p><p> lorem lorem lorem </p>"
22
23
  product_type: extras
23
24
  subscription_valid: true
25
+ product_id: nil
24
26
 
25
27
  three:
26
28
  scc_account_id: test_account1
@@ -32,18 +34,31 @@ three:
32
34
  description: lorem ipsum dolor sit amet
33
35
  product_type: base
34
36
  subscription_valid: nil
37
+ product_id: 1
38
+
39
+ four:
40
+ scc_account_id: test_account1
41
+ scc_id: 444
42
+ name: four
43
+ version: 4
44
+ arch: x86_128
45
+ friendly_name: number four
46
+ description: lorem ipsum dolor sit amet
47
+ product_type: base
48
+ subscription_valid: nil
49
+ product_id: 2
35
50
 
36
51
  # create a couple of products as scc_extensions
37
52
  <% 1.upto(10) do |i| %>
38
53
  p_extension_<%= i %>:
39
54
  scc_account_id: test_account1
40
55
  scc_id: <%= i %>
41
- name: p_ext_<%= i%>
56
+ name: p_ext_<%= i%>
42
57
  version: 3
43
58
  arch: x86_128
44
- friendly_name: number <%= i%>
59
+ friendly_name: number <%= i%>
45
60
  description: lorem ipsum dolor sit amet
46
61
  product_type: extension
47
62
  subscription_valid: nil
63
+ product_id: nil
48
64
  <% end %>
49
-
@@ -0,0 +1,10 @@
1
+ p1:
2
+ id: 1
3
+ name: 'katello product 1'
4
+ provider_id: 1
5
+
6
+ p2:
7
+ id: 2
8
+ name: 'katello product 2'
9
+ provider_id: 1
10
+
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  class SccProductSearchTest < ActiveSupport::TestCase
32
32
  test 'default ordered by name' do
33
- product_names = ['one', 'two', 'three',
33
+ product_names = ['one', 'two', 'three', 'four',
34
34
  'p_ext_1', 'p_ext_10', 'p_ext_2', 'p_ext_3',
35
35
  'p_ext_4', 'p_ext_5', 'p_ext_6', 'p_ext_7',
36
36
  'p_ext_8', 'p_ext_9']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
  # require "#{Katello::Engine.root}/test/katello_test_helper"
@@ -10,6 +12,8 @@ module SignInHelper
10
12
  end
11
13
  end
12
14
 
13
- class ActionDispatch::IntegrationTest
14
- include SignInHelper
15
+ module ActionDispatch
16
+ class IntegrationTest
17
+ include SignInHelper
18
+ end
15
19
  end
@@ -1,6 +1,8 @@
1
1
  # This calls the main test_helper in Foreman-core
2
2
  require 'test_helper'
3
3
 
4
+ require 'dynflow/testing'
5
+ Dynflow::Testing.logger_adapter.level = 1
4
6
  require 'foreman_tasks/test_helpers'
5
7
  require "#{ForemanSccManager::Engine.root}/test/support/fixtures_support"
6
8
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  require 'unit/shared/access_permissions_test_base'
3
5
 
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.12
4
+ version: 1.8.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-21 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -36,28 +36,28 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.75.0
39
+ version: 0.89.0
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.75.0
46
+ version: 0.89.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rubocop-rails
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 2.0.1
53
+ version: 2.8.1
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 2.0.1
60
+ version: 2.8.1
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: webmock
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +165,7 @@ files:
165
165
  - db/migrate/20210210104407_add_root_repository_id_to_scc_repository.rb
166
166
  - db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
167
167
  - db/migrate/20210713092440_add_permissions.rb
168
+ - db/migrate/20211022100718_add_product_class_to_scc_product.rb
168
169
  - lib/foreman_scc_manager.rb
169
170
  - lib/foreman_scc_manager/engine.rb
170
171
  - lib/foreman_scc_manager/version.rb
@@ -182,6 +183,7 @@ files:
182
183
  - locale/en/foreman_scc_manager.po.time_stamp
183
184
  - locale/foreman_scc_manager.pot
184
185
  - locale/gemspec.rb
186
+ - test/actions/sync_test.rb
185
187
  - test/controllers/api/v2/scc_accounts_test.rb
186
188
  - test/controllers/api/v2/scc_products_test.rb
187
189
  - test/controllers/scc_accounts_controller_test.rb
@@ -192,10 +194,12 @@ files:
192
194
  - test/fixtures/files/data_products_page2.json
193
195
  - test/fixtures/files/data_repositories.json
194
196
  - test/fixtures/files/data_subscriptions.json
197
+ - test/fixtures/models/katello_products.yml.bak
195
198
  - test/fixtures/models/scc_accounts.yml
196
199
  - test/fixtures/models/scc_extendings.yml
197
200
  - test/fixtures/models/scc_products.yml
198
201
  - test/fixtures/models/scc_repositories.yml
202
+ - test/models/katello_products.rb
199
203
  - test/models/scc_account_test.rb
200
204
  - test/models/scc_product_test.rb
201
205
  - test/support/fixtures_support.rb
@@ -232,14 +236,17 @@ test_files:
232
236
  - test/test_controller_helper.rb
233
237
  - test/features/sync_test.rb
234
238
  - test/models/scc_product_test.rb
239
+ - test/models/katello_products.rb
235
240
  - test/models/scc_account_test.rb
236
241
  - test/factories/foreman_scc_manager_factories.rb
237
242
  - test/controllers/api/v2/scc_accounts_test.rb
238
243
  - test/controllers/api/v2/scc_products_test.rb
239
244
  - test/controllers/scc_accounts_controller_test2.rb
240
245
  - test/controllers/scc_accounts_controller_test.rb
246
+ - test/actions/sync_test.rb
241
247
  - test/support/fixtures_support.rb
242
248
  - test/fixtures/models/scc_accounts.yml
249
+ - test/fixtures/models/katello_products.yml.bak
243
250
  - test/fixtures/models/scc_repositories.yml
244
251
  - test/fixtures/models/scc_products.yml
245
252
  - test/fixtures/models/scc_extendings.yml