foreman_scc_manager 1.2.0 → 1.3.0

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: 8c9b8504241cd3feed62bc340cf0db3c37bfc10943bf7db7ac9d119d154a1abc
4
- data.tar.gz: 33c6c4286f16de71f6d3af9ad4d35bbaa741ddc5e66cbc164c95730256945778
3
+ metadata.gz: 96e9a75d883e70453b301cfc95ccdcb3906204f9ae87b5c8abec1f1970bef49f
4
+ data.tar.gz: 9b5b2d8a57b2a0da65631603bb77f5b3503353aa0095267ffe7bb4724c93049d
5
5
  SHA512:
6
- metadata.gz: 729e90d1a64ee314ac3772346b19f3869a142431cbc2d932359c19ea8d9615bc10465b747efe8a7003bc8ae532d310e4a13dd077262fea05266f84059554a7f8
7
- data.tar.gz: e0a3d085ea59df19371f774b48f83d229a970bde2fcf5b394b0c65ac0f9b27489b00530d3582fb4248488442894b3ceb72898fa592573ef2f87cd31170725a37
6
+ metadata.gz: ea1ba3bbdfb6215d48a99ef89a241cf1735de4c085df7e0ee16b849e1bbd786a5734e9b1bfbd79c18ea78d42e2d0440ffbf263e94401b44689a8ef7742b04428
7
+ data.tar.gz: 6ef467fe3c5deead9ccc7555a30ac4b96257a8ec269f333d3826b5e28e366def180a5940f1f932be8329719cb488e06d0184ee533c0fb862b915ad135bbf5595
@@ -65,6 +65,7 @@ class SccAccountsController < ApplicationController
65
65
  # PUT /scc_accounts/1/sync
66
66
  def sync
67
67
  sync_task = ForemanTasks.async_task(::Actions::SccManager::Sync, @scc_account)
68
+ @scc_account.update! sync_task: sync_task
68
69
  notice _('Sync task started.')
69
70
  rescue ::Foreman::Exception => e
70
71
  error _('Failed to add task to queue: %s') % e.to_s
@@ -77,10 +78,15 @@ class SccAccountsController < ApplicationController
77
78
  def bulk_subscribe
78
79
  scc_products_to_subscribe =
79
80
  @scc_account.scc_products.where(id: scc_bulk_subscribe_params[:scc_subscribe_product_ids])
80
- ForemanTasks.async_task(::Actions::BulkAction,
81
- ::Actions::SccManager::SubscribeProduct,
82
- scc_products_to_subscribe)
83
- notice _('Task to subscribe products started.')
81
+
82
+ if (scc_products_to_subscribe.count > 0)
83
+ ForemanTasks.async_task(::Actions::BulkAction,
84
+ ::Actions::SccManager::SubscribeProduct,
85
+ scc_products_to_subscribe)
86
+ notice _('Task to subscribe products started.')
87
+ else
88
+ notice _('No products selected.')
89
+ end
84
90
  rescue ::Foreman::Exception => e
85
91
  error _('Failed to add task to queue: %s') % e.to_s
86
92
  rescue ForemanTasks::Lock::LockConflict => e
@@ -10,18 +10,15 @@ module Actions
10
10
  sync_prod_action = plan_action(::Actions::SccManager::SyncProducts, scc_account)
11
11
  plan_self(repo_status: sync_repo_action.output[:status], prod_status: sync_prod_action.output[:status])
12
12
  end
13
- scc_account.update! sync_status: 'running'
14
13
  end
15
14
 
16
15
  def finalize
17
16
  scc_account = SccAccount.find(input[:scc_account][:id])
18
17
  if input[:repo_status] == 'SUCCESS' && input[:prod_status] == 'SUCCESS'
19
- scc_account.sync_status = 'successful'
20
- scc_account.synced = DateTime.current
18
+ scc_account.update! synced: DateTime.current
21
19
  else
22
- scc_account.sync_status = 'failed'
20
+ raise 'Updating failed'
23
21
  end
24
- scc_account.save!
25
22
  end
26
23
 
27
24
  def rescue_strategy
@@ -4,11 +4,10 @@ class SccAccount < ApplicationRecord
4
4
  include ForemanTasks::Concerns::ActionSubject
5
5
  encrypts :password
6
6
 
7
- SYNC_STATI = [nil, 'running', 'successful', 'failed'].freeze
8
-
9
7
  self.include_root_in_json = false
10
8
 
11
9
  belongs_to :organization
10
+ belongs_to :sync_task, class_name: ForemanTasks::Task
12
11
  has_many :scc_products, dependent: :destroy
13
12
  has_many :scc_repositories, dependent: :destroy
14
13
 
@@ -18,7 +17,6 @@ class SccAccount < ApplicationRecord
18
17
  validates :login, presence: true
19
18
  validates :password, presence: true
20
19
  validates :base_url, presence: true
21
- validates :sync_status, inclusion: { in: SYNC_STATI }
22
20
 
23
21
  default_scope -> { order(:login) }
24
22
 
@@ -29,16 +27,17 @@ class SccAccount < ApplicationRecord
29
27
  end
30
28
 
31
29
  def get_sync_status
32
- if sync_status.nil?
30
+ if sync_task.nil?
33
31
  return _('never synced')
34
- elsif sync_status == 'running'
35
- return _('sync in progress')
36
- elsif sync_status == 'successful'
37
- return synced
38
- elsif sync_status == 'failed'
39
- return _('last sync failed')
32
+ elsif sync_task.state == 'stopped'
33
+ if sync_task.result == 'success'
34
+ return synced
35
+ else
36
+ return sync_task.result
37
+ end
38
+ else
39
+ return sync_task.state
40
40
  end
41
- ''
42
41
  end
43
42
 
44
43
  def test_connection
@@ -18,7 +18,7 @@
18
18
  <%= link_to_if_authorized(scc_account.name, hash_for_edit_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer)) %>
19
19
  </td>
20
20
  <td><%= scc_account.scc_products.count.to_s %></td>
21
- <td><%= scc_account.get_sync_status %></td>
21
+ <td><%= link_to_if(scc_account.sync_task, scc_account.get_sync_status, scc_account.sync_task) %></td>
22
22
  <td>
23
23
  <%= action_buttons(
24
24
  display_link_if_authorized(_("Select products"), hash_for_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer)),
@@ -0,0 +1,7 @@
1
+ class ChangeSyncStatusToSyncTask < ActiveRecord::Migration
2
+ def change
3
+ remove_column :scc_accounts, :sync_status, :string
4
+ add_column :scc_accounts, :sync_task_id, :uuid, null: true
5
+ # add_foreign_key "scc_accounts", "foreman_tasks_tasks", name: "scc_accounts_foreman_tasks_tasks_id_fk", column: "sync_task_id", primary_key: "id" , on_delete: :nullify
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-19 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.49.0
33
+ version: '0.49'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.49.0
40
+ version: '0.49'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.0
61
+ version: '0.10'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.0
68
+ version: '0.10'
69
69
  description: Foreman plugin to sync SUSE Customer Center products and repositories
70
70
  into Katello.
71
71
  email:
@@ -109,6 +109,7 @@ files:
109
109
  - db/migrate/20170307092057_add_synced_to_scc_account.rb
110
110
  - db/migrate/20170418132648_add_name_to_scc_account.rb
111
111
  - db/migrate/20170505063726_add_sync_status_to_scc_account.rb
112
+ - db/migrate/20180321000000_change_sync_status_to_sync_task.rb
112
113
  - lib/foreman_scc_manager.rb
113
114
  - lib/foreman_scc_manager/engine.rb
114
115
  - lib/foreman_scc_manager/version.rb