foreman_dlm 0.1.0 → 1.0.0

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: 6d01a9afd6f4e70cd4d05bc1691faa86144c463cb69a46a20af4ce7365f7df66
4
- data.tar.gz: 6d1a4884600efc752622be4452aa9ac694f57eaa70c3cbb27d6d6dd16d2c03fa
3
+ metadata.gz: a0b972d0b154b81592615546f153d32893af3647364ea66f1e0ab5826884f02e
4
+ data.tar.gz: 38ee0b23847863b293adaed2e15c9dcdb6883eec9b512d3c308ae0f7dee88615
5
5
  SHA512:
6
- metadata.gz: 834f7277d2779b95cef01c64a15a146f3c5c2ead8f2d808914d2b9b248d4f7b6702581a4b460994b9df0c46cc80b5a62d30f62969d3d91a7cb8cf407d963bec0
7
- data.tar.gz: 384039584a5bb43567a14ec986db25a7295df791f5293b2809485063f096ba92bfc894350becfa5c1dc18022e29b3036b455ad295a07f82979b87e98d848403b
6
+ metadata.gz: 15549c3c5366a7217fb5ed65f87528f711527698e2a6ecdcefe7330a9e3a02d34a2f4c04fb5400632ab4a79ffab503d75dfbdc9d364d351b8d68e1e443c6dc81
7
+ data.tar.gz: 5f5036aa09ed8ff7e72313352c1bc83a3e8eba76448524305cb4bfda5a49c05c119a080b0168a16a296bbe9ddc1d49b9397c08b0e124ca397ad3ecf4a79fe9b1
data/README.md CHANGED
@@ -10,7 +10,8 @@ With this plugin servers can acquire a lock in Foreman to ensure only one server
10
10
 
11
11
  | Foreman Version | Plugin Version |
12
12
  | --------------- | -------------- |
13
- | >= 1.15 | any |
13
+ | >= 1.15 | ~> 0.1 |
14
+ | >= 1.17 | ~> 1.0 |
14
15
 
15
16
  ## Installation
16
17
 
@@ -45,7 +45,7 @@ module Api
45
45
  process_response @dlmlock.save
46
46
  end
47
47
 
48
- api :PUT, "/dlmlocks/:id/", N_("Update a DLM lock")
48
+ api :PUT, '/dlmlocks/:id/', N_('Update a DLM lock')
49
49
  param :id, String, :required => true, :desc => N_('Id or name of the DLM lock')
50
50
  param_group :dlmlock
51
51
 
@@ -64,14 +64,14 @@ module Api
64
64
  param :id, String, :required => true, :desc => N_('Id or name of the DLM lock')
65
65
  error 200, 'Lock acquired successfully.'
66
66
  error 412, 'Lock could not be acquired.'
67
- description <<-EOS
67
+ description <<-DOCS
68
68
  == Acquire a lock
69
69
  This action acquires a lock.
70
70
  It fails, if the lock is currently taken by another host.
71
71
 
72
72
  == Authentication & Host Identification
73
73
  The host is authenticated via a client certificate and identified via the CN of that certificate.
74
- EOS
74
+ DOCS
75
75
 
76
76
  def acquire
77
77
  process_lock_response @dlmlock.acquire!(@host)
@@ -82,14 +82,14 @@ module Api
82
82
  error 200, 'Lock released successfully.'
83
83
  error 412, 'Lock could not be released.'
84
84
 
85
- description <<-EOS
85
+ description <<-DOCS
86
86
  == Release a lock
87
87
  This action releases a lock.
88
88
  It fails, if the lock is currently taken by another host.
89
89
 
90
90
  == Authentication & Host Identification
91
91
  The host is authenticated via a client certificate and identified via the CN of that certificate.
92
- EOS
92
+ DOCS
93
93
 
94
94
  def release
95
95
  process_lock_response @dlmlock.release!(@host)
@@ -113,10 +113,10 @@ module Api
113
113
 
114
114
  def action_permission
115
115
  case params[:action]
116
- when 'release', 'acquire'
117
- :edit
118
- else
119
- super
116
+ when 'release', 'acquire'
117
+ :edit
118
+ else
119
+ super
120
120
  end
121
121
  end
122
122
 
@@ -125,9 +125,17 @@ module Api
125
125
  unless @host
126
126
  logger.info 'Denying access because no host could be detected.'
127
127
  if User.current
128
- render_error 'access_denied', :status => :forbidden, :locals => { :details => 'You need to authenticate with a valid client cert. The DN has to match a known host.' }
128
+ render_error 'access_denied',
129
+ :status => :forbidden,
130
+ :locals => {
131
+ :details => 'You need to authenticate with a valid client cert. The DN has to match a known host.'
132
+ }
129
133
  else
130
- render_error 'unauthorized', :status => :unauthorized, :locals => { :user_login => get_client_cert_hostname }
134
+ render_error 'unauthorized',
135
+ :status => :unauthorized,
136
+ :locals => {
137
+ :user_login => get_client_cert_hostname
138
+ }
131
139
  end
132
140
  end
133
141
  true
@@ -148,7 +156,7 @@ module Api
148
156
  deny_access
149
157
  else
150
158
  render_error 'precondition_failed', :status => :precondition_failed, :locals => {
151
- :message => 'Precondition failed. Lock is in invalid state for this operation.',
159
+ :message => 'Precondition failed. Lock is in invalid state for this operation.'
152
160
  }
153
161
  end
154
162
  end
@@ -3,7 +3,7 @@ module ForemanDlm
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def authorize_host_by_client_cert(actions, options = {})
6
+ def authorize_host_by_client_cert(actions, _options = {})
7
7
  skip_before_action :require_login, :only => actions, :raise => false
8
8
  skip_before_action :authorize, :only => actions
9
9
  skip_before_action :verify_authenticity_token, :only => actions
@@ -39,8 +39,8 @@ module ForemanDlm
39
39
 
40
40
  return unless hostname
41
41
 
42
- host ||= Host::Base.find_by_certname(hostname) ||
43
- Host::Base.find_by_name(hostname)
42
+ host ||= Host::Base.find_by(certname: hostname) ||
43
+ Host::Base.find_by(name: hostname)
44
44
  logger.info { "Found Host #{host} by client cert #{hostname}" } if host
45
45
  host
46
46
  end
@@ -53,9 +53,9 @@ module ForemanDlm
53
53
  end
54
54
 
55
55
  dn = request.env[Setting[:ssl_client_dn_env]]
56
- return unless (dn && dn =~ /CN=([^\s\/,]+)/i)
56
+ return unless dn && dn =~ /CN=([^\s\/,]+)/i
57
57
 
58
- hostname = $1.downcase
58
+ hostname = Regexp.last_match(1).downcase
59
59
  logger.debug "Extracted hostname '#{hostname}' from client certificate."
60
60
  hostname
61
61
  end
@@ -3,7 +3,7 @@ module ForemanDlm
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def authorize_host_by_ip(actions, options = {})
6
+ def authorize_host_by_ip(actions, _options = {})
7
7
  skip_before_action :require_login, :only => actions, :raise => false
8
8
  skip_before_action :authorize, :only => actions
9
9
  skip_before_action :verify_authenticity_token, :only => actions
@@ -8,6 +8,5 @@ class DlmlocksController < ::ApplicationController
8
8
  @dlmlocks = resource_base_search_and_page(:host)
9
9
  end
10
10
 
11
- def show
12
- end
11
+ def show; end
13
12
  end
@@ -4,8 +4,9 @@ module ForemanDlm
4
4
 
5
5
  included do
6
6
  has_many :dlmlocks,
7
- foreign_key: 'host_id',
8
- dependent: :nullify
7
+ foreign_key: 'host_id',
8
+ dependent: :nullify,
9
+ inverse_of: :host
9
10
 
10
11
  define_model_callbacks :lock, :only => :after
11
12
  define_model_callbacks :unlock, :only => :after
@@ -1,4 +1,4 @@
1
- class Dlmlock < ActiveRecord::Base
1
+ class Dlmlock < ApplicationRecord
2
2
  include Authorizable
3
3
 
4
4
  def self.humanize_class_name
@@ -28,7 +28,7 @@ class Dlmlock < ActiveRecord::Base
28
28
  def locked_by?(host)
29
29
  self.host == host
30
30
  end
31
- alias_method :acquired_by?, :locked_by?
31
+ alias acquired_by? locked_by?
32
32
 
33
33
  def disabled?
34
34
  !enabled?
@@ -37,7 +37,7 @@ class Dlmlock < ActiveRecord::Base
37
37
  def locked?
38
38
  host.present?
39
39
  end
40
- alias_method :taken?, :locked?
40
+ alias taken? locked?
41
41
 
42
42
  def humanized_type
43
43
  _('Generic Lock')
@@ -54,7 +54,7 @@ class Dlmlock < ActiveRecord::Base
54
54
  id: id,
55
55
  host_id: [new_host.try(:id), old_host.try(:id)],
56
56
  enabled: true
57
- ).update_all(changes.merge(updated_at: DateTime.now))
57
+ ).update_all(changes.merge(updated_at: Time.now.utc))
58
58
  if num_updated > 0
59
59
  reload
60
60
  process_host_change(old_host, new_host, changes)
@@ -1,5 +1,7 @@
1
- class Dlmlock::Update < Dlmlock
2
- def humanized_type
3
- _('Update Lock')
1
+ class Dlmlock
2
+ class Update < Dlmlock
3
+ def humanized_type
4
+ _('Update Lock')
5
+ end
4
6
  end
5
7
  end
@@ -3,6 +3,6 @@ object @dlmlock
3
3
  extends 'api/v2/dlmlocks/main'
4
4
 
5
5
  child :host do
6
- node(:name) { |host| host.name }
6
+ node(:name, &:name)
7
7
  node(:self) { |host| host == @detected_host } if @detected_host
8
8
  end
@@ -1,4 +1,4 @@
1
- object resource = controller.get_resource
1
+ object controller.get_resource
2
2
 
3
3
  attributes :id
4
4
 
data/config/routes.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  Rails.application.routes.draw do
2
2
  namespace :api, :defaults => { :format => 'json' } do
3
3
  scope '(:apiv)', :module => :v2,
4
- :defaults => { :apiv => 'v2' },
5
- :apiv => /v1|v2/,
6
- :constraints => ApiConstraints.new(:version => 2, :default => true) do
7
- constraints(id: /[^\/]+/) do
8
- resources :dlmlocks, only: [:index, :show, :update, :destroy] do
9
- get :lock, on: :member, action: :show, controller: 'dlmlocks'
10
- put :lock, on: :member, action: :acquire, controller: 'dlmlocks'
11
- delete :lock, on: :member, action: :release, controller: 'dlmlocks'
12
- end
4
+ :defaults => { :apiv => 'v2' },
5
+ :apiv => /v1|v2/,
6
+ :constraints => ApiConstraints.new(:version => 2, :default => true) do
7
+ constraints(id: /[^\/]+/) do
8
+ resources :dlmlocks, only: [:index, :show, :update, :destroy] do
9
+ get :lock, on: :member, action: :show, controller: 'dlmlocks'
10
+ put :lock, on: :member, action: :acquire, controller: 'dlmlocks'
11
+ delete :lock, on: :member, action: :release, controller: 'dlmlocks'
13
12
  end
14
- resources :dlmlocks, only: [:create]
15
13
  end
14
+ resources :dlmlocks, only: [:create]
15
+ end
16
16
  end
17
17
 
18
18
  scope '/foreman_dlm' do
@@ -1,4 +1,4 @@
1
- class AddDlmlock < ActiveRecord::Migration
1
+ class AddDlmlock < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :dlmlocks do |t|
4
4
  t.string :name, null: false, unique: true
@@ -14,7 +14,7 @@ module ForemanDlm
14
14
 
15
15
  initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |_app|
16
16
  Foreman::Plugin.register :foreman_dlm do
17
- requires_foreman '>= 1.15'
17
+ requires_foreman '>= 1.17'
18
18
 
19
19
  apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]
20
20
 
@@ -43,7 +43,7 @@ module ForemanDlm
43
43
 
44
44
  # add menu entry
45
45
  menu :top_menu, :distributed_locks,
46
- url_hash: { controller: :'dlmlocks', action: :index },
46
+ url_hash: { controller: :dlmlocks, action: :index },
47
47
  caption: N_('Distributed Locks'),
48
48
  parent: :monitor_menu,
49
49
  after: :audits
@@ -55,10 +55,8 @@ module ForemanDlm
55
55
  begin
56
56
  Host::Managed.send(:include, ForemanDlm::HostExtensions)
57
57
 
58
- if ForemanDlm.with_monitoring?
59
- Host::Managed.send(:include, ForemanDlm::HostMonitoringExtensions)
60
- end
61
- rescue => e
58
+ Host::Managed.send(:include, ForemanDlm::HostMonitoringExtensions) if ForemanDlm.with_monitoring?
59
+ rescue StandardError => e
62
60
  Rails.logger.warn "ForemanDlm: skipping engine hook (#{e})"
63
61
  end
64
62
  end
@@ -71,6 +69,9 @@ module ForemanDlm
71
69
  end
72
70
 
73
71
  def self.with_monitoring?
74
- (ForemanMonitoring rescue false) ? true : false
72
+ ForemanMonitoring # rubocop:disable Lint/Void
73
+ true
74
+ rescue StandardError
75
+ false
75
76
  end
76
77
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanDlm
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -21,7 +21,7 @@ namespace :foreman_dlm do
21
21
  "#{ForemanDlm::Engine.root}/lib/**/*.rb",
22
22
  "#{ForemanDlm::Engine.root}/test/**/*.rb"]
23
23
  end
24
- rescue
24
+ rescue StandardError
25
25
  puts 'Rubocop not loaded.'
26
26
  end
27
27
 
@@ -32,6 +32,4 @@ end
32
32
  Rake::Task[:test].enhance ['test:foreman_dlm']
33
33
 
34
34
  load 'tasks/jenkins.rake'
35
- if Rake::Task.task_defined?(:'jenkins:unit')
36
- Rake::Task['jenkins:unit'].enhance ['test:foreman_dlm', 'foreman_dlm:rubocop']
37
- end
35
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_dlm', 'foreman_dlm:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
@@ -13,7 +13,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
13
13
  body = ActiveSupport::JSON.decode(@response.body)
14
14
  results = body['results']
15
15
  assert results
16
- entry = results.detect { |entry| entry['id'] == dlmlock.id }
16
+ entry = results.detect { |e| e['id'] == dlmlock.id }
17
17
  assert entry
18
18
  assert_equal dlmlock.name, entry['name']
19
19
  assert_equal dlmlock.type, entry['type']
@@ -25,7 +25,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
25
25
  context '#create' do
26
26
  test 'should create dlmlock' do
27
27
  assert_difference('Dlmlock.unscoped.count') do
28
- post :create, valid_attrs_with_root
28
+ post :create, params: valid_attrs_with_root
29
29
  end
30
30
  assert_response :success
31
31
  body = ActiveSupport::JSON.decode(@response.body)
@@ -41,7 +41,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
41
41
  context '#show' do
42
42
  test 'should show individual record with host' do
43
43
  dlmlock = FactoryBot.create(:dlmlock, :host => host1)
44
- get :show, { :id => dlmlock.to_param }
44
+ get :show, params: { :id => dlmlock.to_param }
45
45
  assert_response :success
46
46
  body = ActiveSupport::JSON.decode(@response.body)
47
47
  refute_empty body
@@ -53,7 +53,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
53
53
 
54
54
  test 'should show individual record that is disabled' do
55
55
  dlmlock = FactoryBot.create(:dlmlock, :enabled => false)
56
- get :show, { :id => dlmlock.to_param }
56
+ get :show, params: { :id => dlmlock.to_param }
57
57
  assert_response :success
58
58
  body = ActiveSupport::JSON.decode(@response.body)
59
59
  refute_empty body
@@ -65,7 +65,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
65
65
 
66
66
  test 'should show individual record by name' do
67
67
  dlmlock = FactoryBot.create(:dlmlock, :host => host1)
68
- get :show, { :id => dlmlock.name }
68
+ get :show, params: { :id => dlmlock.name }
69
69
  assert_response :success
70
70
  body = ActiveSupport::JSON.decode(@response.body)
71
71
  refute_empty body
@@ -74,11 +74,11 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
74
74
  host = body['host']
75
75
  assert host
76
76
  assert_equal host1.name, host['name']
77
- refute host.has_key?('self')
77
+ refute host.key?('self')
78
78
  end
79
79
 
80
80
  test 'should not find dlmlock with invalid id' do
81
- get :show, { :id => 9999999 }
81
+ get :show, params: { :id => 9_999_999 }
82
82
  assert_response :not_found
83
83
  end
84
84
  end
@@ -86,7 +86,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
86
86
  context '#update' do
87
87
  test 'should update dlmlock' do
88
88
  dlmlock = FactoryBot.create(:dlmlock)
89
- put :update, { :id => dlmlock.to_param, :dlmlock => valid_attrs.merge(:host_id => host1.id, :enabled => false) }
89
+ put :update, params: { :id => dlmlock.to_param, :dlmlock => valid_attrs.merge(:host_id => host1.id, :enabled => false) }
90
90
  assert_response :success
91
91
  dlmlock.reload
92
92
  assert_equal valid_attrs['name'], dlmlock.name
@@ -100,7 +100,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
100
100
  test 'should destroy dlmlock' do
101
101
  dlmlock = FactoryBot.create(:dlmlock)
102
102
  assert_difference('Dlmlock.unscoped.count', -1) do
103
- delete :destroy, { :id => dlmlock.to_param }
103
+ delete :destroy, params: { :id => dlmlock.to_param }
104
104
  end
105
105
  assert_response :success
106
106
  assert_equal 0, Dlmlock.where(:id => dlmlock.id).count
@@ -110,7 +110,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
110
110
  context '#acquire' do
111
111
  test 'should deny access' do
112
112
  dlmlock = FactoryBot.create(:dlmlock)
113
- put :acquire, { :id => dlmlock.to_param }
113
+ put :acquire, params: { :id => dlmlock.to_param }
114
114
  assert_response :forbidden
115
115
  assert_nil dlmlock.reload.host
116
116
  end
@@ -119,7 +119,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
119
119
  context '#release' do
120
120
  test 'should deny access' do
121
121
  dlmlock = FactoryBot.create(:dlmlock, :host => host2)
122
- delete :release, { :id => dlmlock.to_param }
122
+ delete :release, params: { :id => dlmlock.to_param }
123
123
  assert_response :forbidden
124
124
  assert_equal host2, dlmlock.reload.host
125
125
  end
@@ -142,15 +142,15 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
142
142
  context '#index' do
143
143
  test 'should deny access' do
144
144
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
145
- get :index, { :id => dlmlock.to_param }
145
+ get :index, params: { :id => dlmlock.to_param }
146
146
  assert_response :unauthorized
147
147
  end
148
148
  end
149
149
 
150
150
  context '#create' do
151
151
  test 'should deny access' do
152
- dlmlock = as_admin { FactoryBot.create(:dlmlock) }
153
- post :create, valid_attrs_with_root
152
+ as_admin { FactoryBot.create(:dlmlock) }
153
+ post :create, params: valid_attrs_with_root
154
154
  assert_response :unauthorized
155
155
  end
156
156
  end
@@ -158,7 +158,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
158
158
  context '#update' do
159
159
  test 'should deny access' do
160
160
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
161
- put :update, { :id => dlmlock.to_param, :dlmlock => valid_attrs }
161
+ put :update, params: { :id => dlmlock.to_param, :dlmlock => valid_attrs }
162
162
  assert_response :unauthorized
163
163
  end
164
164
  end
@@ -166,7 +166,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
166
166
  context '#destroy' do
167
167
  test 'should deny access' do
168
168
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
169
- delete :destroy, { :id => dlmlock.to_param }
169
+ delete :destroy, params: { :id => dlmlock.to_param }
170
170
  assert_response :unauthorized
171
171
  assert_equal 1, as_admin { Dlmlock.where(:id => dlmlock.id).count }
172
172
  end
@@ -175,7 +175,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
175
175
  context '#show' do
176
176
  test 'should show individual free lock' do
177
177
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
178
- get :show, { :id => dlmlock.to_param }
178
+ get :show, params: { :id => dlmlock.to_param }
179
179
  assert_response :success
180
180
  body = ActiveSupport::JSON.decode(@response.body)
181
181
  refute_empty body
@@ -188,7 +188,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
188
188
 
189
189
  test 'should show individual acquired lock by me' do
190
190
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host1) }
191
- get :show, { :id => dlmlock.to_param }
191
+ get :show, params: { :id => dlmlock.to_param }
192
192
  assert_response :success
193
193
  body = ActiveSupport::JSON.decode(@response.body)
194
194
  refute_empty body
@@ -204,7 +204,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
204
204
 
205
205
  test 'should show individual acquired lock by other' do
206
206
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host2) }
207
- get :show, { :id => dlmlock.to_param }
207
+ get :show, params: { :id => dlmlock.to_param }
208
208
  assert_response :success
209
209
  body = ActiveSupport::JSON.decode(@response.body)
210
210
  refute_empty body
@@ -222,21 +222,21 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
222
222
  context '#acquire' do
223
223
  test 'should acquire empty dlmlock' do
224
224
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
225
- put :acquire, { :id => dlmlock.to_param }
225
+ put :acquire, params: { :id => dlmlock.to_param }
226
226
  assert_response :success
227
227
  assert_equal host1, as_admin { dlmlock.reload.host }
228
228
  end
229
229
 
230
230
  test 'should acquire own dlmlock' do
231
231
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host1) }
232
- put :acquire, { :id => dlmlock.to_param }
232
+ put :acquire, params: { :id => dlmlock.to_param }
233
233
  assert_response :success
234
234
  assert_equal host1, as_admin { dlmlock.reload.host }
235
235
  end
236
236
 
237
237
  test 'should not acquire foreign dlmlock' do
238
238
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host2) }
239
- put :acquire, { :id => dlmlock.to_param }
239
+ put :acquire, params: { :id => dlmlock.to_param }
240
240
  assert_response :precondition_failed
241
241
  assert_equal host2, as_admin { dlmlock.reload.host }
242
242
  end
@@ -244,7 +244,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
244
244
  test 'should transparently create non-existing dlmlock' do
245
245
  lockname = 'Test Lock'
246
246
  assert_equal 0, as_admin { Dlmlock.where(:name => lockname).count }
247
- put :acquire, { :id => lockname }
247
+ put :acquire, params: { :id => lockname }
248
248
  assert_response :success
249
249
  dlmlock = as_admin { Dlmlock.find_by(:name => lockname) }
250
250
  assert_equal lockname, dlmlock.name
@@ -255,21 +255,21 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
255
255
  context '#release' do
256
256
  test 'should release empty dlmlock' do
257
257
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
258
- delete :release, { :id => dlmlock.to_param }
258
+ delete :release, params: { :id => dlmlock.to_param }
259
259
  assert_response :success
260
260
  assert_nil as_admin { dlmlock.reload.host }
261
261
  end
262
262
 
263
263
  test 'should release own dlmlock' do
264
264
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host1) }
265
- delete :release, { :id => dlmlock.to_param }
265
+ delete :release, params: { :id => dlmlock.to_param }
266
266
  assert_response :success
267
267
  assert_nil as_admin { dlmlock.reload.host }
268
268
  end
269
269
 
270
270
  test 'should not acquire foreign dlmlock' do
271
271
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host2) }
272
- delete :release, { :id => dlmlock.to_param }
272
+ delete :release, params: { :id => dlmlock.to_param }
273
273
  assert_response :precondition_failed
274
274
  assert_equal host2, as_admin { dlmlock.reload.host }
275
275
  end
@@ -277,7 +277,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
277
277
  test 'should transparently create non-existing dlmlock' do
278
278
  lockname = 'Test Lock'
279
279
  assert_equal 0, as_admin { Dlmlock.where(:name => lockname).count }
280
- delete :release, { :id => lockname }
280
+ delete :release, params: { :id => lockname }
281
281
  assert_response :success
282
282
  dlmlock = as_admin { Dlmlock.find_by(:name => lockname) }
283
283
  assert_equal lockname, dlmlock.name
@@ -295,7 +295,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
295
295
  context '#index' do
296
296
  test 'should deny access' do
297
297
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
298
- get :index, { :id => dlmlock.to_param }
298
+ get :index, params: { :id => dlmlock.to_param }
299
299
  assert_response :unauthorized
300
300
  end
301
301
  end
@@ -303,15 +303,15 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
303
303
  context '#show' do
304
304
  test 'should deny access' do
305
305
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
306
- get :show, { :id => dlmlock.to_param }
306
+ get :show, params: { :id => dlmlock.to_param }
307
307
  assert_response :unauthorized
308
308
  end
309
309
  end
310
310
 
311
311
  context '#create' do
312
312
  test 'should deny access' do
313
- dlmlock = as_admin { FactoryBot.create(:dlmlock) }
314
- post :create, valid_attrs_with_root
313
+ as_admin { FactoryBot.create(:dlmlock) }
314
+ post :create, params: valid_attrs_with_root
315
315
  assert_response :unauthorized
316
316
  end
317
317
  end
@@ -319,7 +319,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
319
319
  context '#update' do
320
320
  test 'should deny access' do
321
321
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
322
- put :update, { :id => dlmlock.to_param, :dlmlock => valid_attrs }
322
+ put :update, params: { :id => dlmlock.to_param, :dlmlock => valid_attrs }
323
323
  assert_response :unauthorized
324
324
  end
325
325
  end
@@ -327,7 +327,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
327
327
  context '#destroy' do
328
328
  test 'should deny access' do
329
329
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
330
- delete :destroy, { :id => dlmlock.to_param }
330
+ delete :destroy, params: { :id => dlmlock.to_param }
331
331
  assert_response :unauthorized
332
332
  assert_equal 1, as_admin { Dlmlock.where(:id => dlmlock.id).count }
333
333
  end
@@ -336,7 +336,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
336
336
  context '#acquire' do
337
337
  test 'should deny access' do
338
338
  dlmlock = as_admin { FactoryBot.create(:dlmlock) }
339
- put :acquire, { :id => dlmlock.to_param }
339
+ put :acquire, params: { :id => dlmlock.to_param }
340
340
  assert_response :unauthorized
341
341
  assert_nil as_admin { dlmlock.reload.host }
342
342
  end
@@ -345,7 +345,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
345
345
  context '#release' do
346
346
  test 'should deny access' do
347
347
  dlmlock = as_admin { FactoryBot.create(:dlmlock, :host => host2) }
348
- delete :release, { :id => dlmlock.to_param }
348
+ delete :release, params: { :id => dlmlock.to_param }
349
349
  assert_response :unauthorized
350
350
  assert_equal host2, as_admin { dlmlock.reload.host }
351
351
  end
@@ -3,21 +3,21 @@ require 'test_plugin_helper'
3
3
  class DlmlocksControllerTest < ActionController::TestCase
4
4
  test '#index' do
5
5
  FactoryBot.create(:dlmlock)
6
- get :index, {}, set_session_user
6
+ get :index, session: set_session_user
7
7
  assert_response :success
8
8
  assert_not_nil assigns('dlmlocks')
9
9
  assert_template 'index'
10
10
  end
11
11
 
12
12
  test '#index with no lock shows welcome page' do
13
- get :index, {}, set_session_user
13
+ get :index, session: set_session_user
14
14
  assert_response :success
15
15
  assert_template 'welcome'
16
16
  end
17
17
 
18
18
  test '#show' do
19
19
  dlmlock = FactoryBot.create(:dlmlock)
20
- get :show, { :id => dlmlock.id }, set_session_user
20
+ get :show, params: { :id => dlmlock.id }, session: set_session_user
21
21
  assert_response :success
22
22
  assert_template 'show'
23
23
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class FindHostByClientCertTest < ActionController::TestCase
4
- tests "api/v2/dlmlocks"
4
+ tests 'api/v2/dlmlocks'
5
5
 
6
6
  def described_class
7
7
  Api::V2::DlmlocksController
@@ -57,7 +57,7 @@ class FindHostByClientCertTest < ActionController::TestCase
57
57
 
58
58
  test 'certificate with unknown dn denies access' do
59
59
  @request.env['HTTPS'] = 'on'
60
- @request.env['SSL_CLIENT_S_DN'] = "CN=doesnotexist.example.com,DN=example,DN=com"
60
+ @request.env['SSL_CLIENT_S_DN'] = 'CN=doesnotexist.example.com,DN=example,DN=com'
61
61
  @request.env['SSL_CLIENT_VERIFY'] = 'SUCCESS'
62
62
 
63
63
  get :index
@@ -60,16 +60,16 @@ class DlmlockTest < ActiveSupport::TestCase
60
60
  end
61
61
 
62
62
  test 'records audit change on acquisition by owner' do
63
- assert_difference "Audit.where(auditable_type: 'Dlmlock').count" do
63
+ assert_difference "Audit.where(auditable_type: 'Dlmlock', action: 'update').count" do
64
64
  assert dlmlock.acquire!(host1)
65
65
  end
66
66
  audit_record = dlmlock.audits.last
67
67
  assert_equal 'update', audit_record.action
68
- assert_equal({:host_id => host1.id}, audit_record.audited_changes)
68
+ assert_equal({ :host_id => host1.id }, audit_record.audited_changes)
69
69
  end
70
70
 
71
71
  test 'records no audit change on release' do
72
- assert_no_difference "Audit.where(auditable_type: 'Dlmlock').count" do
72
+ assert_no_difference "Audit.where(auditable_type: 'Dlmlock', action: 'update').count" do
73
73
  assert dlmlock.release!(host1)
74
74
  end
75
75
  end
@@ -115,7 +115,7 @@ class DlmlockTest < ActiveSupport::TestCase
115
115
  end
116
116
 
117
117
  context 'an acquired DLM lock' do
118
- let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host1) }
118
+ let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host1) }
119
119
 
120
120
  test 'should be enabled and locked' do
121
121
  assert_equal true, dlmlock.enabled?
@@ -151,16 +151,16 @@ class DlmlockTest < ActiveSupport::TestCase
151
151
  end
152
152
 
153
153
  test 'records audit change on release by owner' do
154
- assert_difference "Audit.where(auditable_type: 'Dlmlock').count" do
154
+ assert_difference "Audit.where(auditable_type: 'Dlmlock', action: 'update').count" do
155
155
  assert dlmlock.release!(host1)
156
156
  end
157
157
  audit_record = dlmlock.audits.last
158
158
  assert_equal 'update', audit_record.action
159
- assert_equal({:host_id => nil}, audit_record.audited_changes)
159
+ assert_equal({ :host_id => nil }, audit_record.audited_changes)
160
160
  end
161
161
 
162
162
  test 'records no audit change on acquisition by owner' do
163
- assert_no_difference "Audit.where(auditable_type: 'Dlmlock').count" do
163
+ assert_no_difference "Audit.where(auditable_type: 'Dlmlock', action: 'update').count" do
164
164
  assert dlmlock.acquire!(host1)
165
165
  end
166
166
  end
@@ -27,7 +27,7 @@ class HostMonitoringTest < ActiveSupport::TestCase
27
27
  end
28
28
 
29
29
  context 'an acquired DLM lock' do
30
- let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host) }
30
+ let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host) }
31
31
 
32
32
  test 'removes monitoring dowmtine' do
33
33
  monitoring_mock.expects(:del_downtime_host).once
@@ -3,7 +3,5 @@ require 'test_helper'
3
3
 
4
4
  # Add plugin to FactoryBot's paths
5
5
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
- if ForemanDlm.with_monitoring?
7
- FactoryBot.definition_file_paths << "#{ForemanMonitoring::Engine.root}/test/factories"
8
- end
6
+ FactoryBot.definition_file_paths << "#{ForemanMonitoring::Engine.root}/test/factories" if ForemanDlm.with_monitoring?
9
7
  FactoryBot.reload
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_dlm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: rdoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rdoc
28
+ name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.52.1
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'
40
+ version: 0.52.1
41
41
  description: Adds a Distributed Lock Manager to Foreman. This enables painless system
42
42
  updates for clusters.
43
43
  email: