foreman_dlm 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/Rakefile +4 -2
- data/app/controllers/api/v2/dlmlock_events_controller.rb +2 -0
- data/app/controllers/api/v2/dlmlocks_controller.rb +14 -11
- data/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/update_checkin_time.rb +2 -0
- data/app/controllers/foreman_dlm/application_controller.rb +2 -0
- data/app/controllers/foreman_dlm/dlmlocks_controller.rb +4 -10
- data/app/helpers/foreman_dlm/dlmlock_helper.rb +2 -0
- data/app/jobs/foreman_dlm/refresh_dlmlock_status.rb +2 -0
- data/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb +2 -0
- data/app/models/concerns/foreman_dlm/expirable.rb +2 -0
- data/app/models/concerns/foreman_dlm/host_extensions.rb +10 -8
- data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +3 -1
- data/app/models/concerns/foreman_dlm/user_extensions.rb +6 -4
- data/app/models/foreman_dlm/dlm_facet.rb +2 -0
- data/app/models/foreman_dlm/dlmlock/update.rb +2 -0
- data/app/models/foreman_dlm/dlmlock.rb +11 -9
- data/app/models/foreman_dlm/dlmlock_event.rb +2 -0
- data/app/models/host_status/dlmlock_status.rb +2 -0
- data/app/views/api/v2/dlmlock_events/index.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/acquire.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/base.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/create.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/index.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/main.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/release.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/show.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/update.json.rabl +2 -0
- data/app/views/api/v2/errors/precondition_failed.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl +2 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +2 -0
- data/db/migrate/20180627150003_rename_dlmlock_sti_models.rb +2 -0
- data/db/migrate/20180704162345_add_dlmlock_events.rb +2 -0
- data/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb +2 -0
- data/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb +2 -0
- data/db/migrate/20180713113208_update_permissions_for_scoped_models.rb +2 -0
- data/lib/foreman_dlm/engine.rb +20 -18
- data/lib/foreman_dlm/version.rb +3 -1
- data/lib/foreman_dlm.rb +2 -0
- data/lib/tasks/dlmlock_events.rake +2 -0
- data/lib/tasks/foreman_dlm_tasks.rake +2 -20
- data/locale/gemspec.rb +3 -1
- data/test/controllers/api/v2/dlmlocks_controller_test.rb +12 -10
- data/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb +2 -0
- data/test/controllers/api/v2/hosts_controller_test.rb +2 -0
- data/test/controllers/find_host_by_client_cert_test.rb +5 -3
- data/test/controllers/foreman_dlm/dlmlocks_test.rb +2 -0
- data/test/controllers/hosts_controller_test.rb +3 -1
- data/test/factories/dlm_facets.rb +2 -0
- data/test/factories/dlmlock.rb +2 -0
- data/test/factories/dlmlock_events.rb +2 -0
- data/test/factories/host.rb +2 -0
- data/test/integration/foreman_dlm/dlmlocks_test.rb +4 -3
- data/test/jobs/refresh_dlmlock_status_test.rb +2 -0
- data/test/models/foreman_dlm/dlm_facet_test.rb +2 -0
- data/test/models/foreman_dlm/dlmlock_event_test.rb +2 -0
- data/test/models/foreman_dlm/dlmlock_test.rb +26 -24
- data/test/models/host_managed_test.rb +2 -0
- data/test/models/host_monitoring_test.rb +2 -0
- data/test/models/host_status/dlmlock_status_test.rb +2 -2
- data/test/models/user_test.rb +2 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/foreman_dlm/access_permissions_test.rb +18 -0
- metadata +12 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbea781adcb410612c6d6fde4e13f116f31f50f393ac518c55cdf8ff0bc0ab22
|
4
|
+
data.tar.gz: 201b1a484408da1971ebd7b33285d5738a1a707bd84ec06a04ed05510c85d065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 961720c5a51b86f720e61f1463bc9b413419be9876d93d36070053d14961db07b9f42f0a82c99c0b917f621296b401da1caf49f123882402e943d8994228f734
|
7
|
+
data.tar.gz: c9cab6e1b37b3321ce4d862dc8599f9af2d8b9b5ce911eaa4141f28816364cfed1d29e372cbe5a1583df2876d47681b7c4c66c70c11dc5ef3164611965ccd99b
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
5
|
require 'bundler/setup'
|
4
6
|
rescue LoadError
|
@@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
23
|
end
|
22
24
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
25
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
26
|
|
25
27
|
Bundler::GemHelper.install_tasks
|
26
28
|
|
@@ -38,7 +40,7 @@ task default: :test
|
|
38
40
|
begin
|
39
41
|
require 'rubocop/rake_task'
|
40
42
|
RuboCop::RakeTask.new
|
41
|
-
rescue
|
43
|
+
rescue StandardError
|
42
44
|
puts 'Rubocop not loaded.'
|
43
45
|
end
|
44
46
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V2
|
3
5
|
class DlmlocksController < V2::BaseController
|
@@ -37,7 +39,8 @@ module Api
|
|
37
39
|
error 404, 'Lock could not be found.'
|
38
40
|
param :id, String, :required => true, :desc => N_('Id or name of the DLM lock')
|
39
41
|
|
40
|
-
def show
|
42
|
+
def show
|
43
|
+
end
|
41
44
|
|
42
45
|
api :POST, '/dlmlocks', N_('Create a DLM lock')
|
43
46
|
param_group :dlmlock, :as => :create
|
@@ -52,7 +55,7 @@ module Api
|
|
52
55
|
param_group :dlmlock
|
53
56
|
|
54
57
|
def update
|
55
|
-
process_response @dlmlock.
|
58
|
+
process_response @dlmlock.update(dlmlocks_params)
|
56
59
|
end
|
57
60
|
|
58
61
|
api :DELETE, '/dlmlocks/:id/', N_('Delete a DLM lock')
|
@@ -133,16 +136,16 @@ module Api
|
|
133
136
|
logger.info 'Denying access because no host could be detected.'
|
134
137
|
if User.current
|
135
138
|
render_error 'access_denied',
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
:status => :forbidden,
|
140
|
+
:locals => {
|
141
|
+
:details => 'You need to authenticate with a valid client cert. The DN has to match a known host.',
|
142
|
+
}
|
140
143
|
else
|
141
144
|
render_error 'unauthorized',
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
145
|
+
:status => :unauthorized,
|
146
|
+
:locals => {
|
147
|
+
:user_login => get_client_cert_hostname,
|
148
|
+
}
|
146
149
|
end
|
147
150
|
end
|
148
151
|
true
|
@@ -163,7 +166,7 @@ module Api
|
|
163
166
|
deny_access
|
164
167
|
else
|
165
168
|
render_error 'precondition_failed', :status => :precondition_failed, :locals => {
|
166
|
-
:message => 'Precondition failed. Lock is in invalid state for this operation.'
|
169
|
+
:message => 'Precondition failed. Lock is in invalid state for this operation.',
|
167
170
|
}
|
168
171
|
end
|
169
172
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
class DlmlocksController < ::ForemanDlm::ApplicationController
|
3
5
|
include ::Foreman::Controller::AutoCompleteSearch
|
@@ -9,7 +11,8 @@ module ForemanDlm
|
|
9
11
|
@dlmlocks = resource_base_search_and_page(:host)
|
10
12
|
end
|
11
13
|
|
12
|
-
def show
|
14
|
+
def show
|
15
|
+
end
|
13
16
|
|
14
17
|
def destroy
|
15
18
|
if @dlmlock.destroy
|
@@ -59,15 +62,6 @@ module ForemanDlm
|
|
59
62
|
ForemanDlm::Dlmlock
|
60
63
|
end
|
61
64
|
|
62
|
-
# see https://projects.theforeman.org/issues/25976
|
63
|
-
# can be removed for Foreman 1.22+
|
64
|
-
def auto_complete_controller_name
|
65
|
-
current_version = Gem::Version.new(Foreman::Version.new.notag)
|
66
|
-
return '/foreman_dlm/dlmlocks' if current_version >= Gem::Version.new('1.20') && current_version < Gem::Version.new('1.22')
|
67
|
-
|
68
|
-
controller_name
|
69
|
-
end
|
70
|
-
|
71
65
|
private
|
72
66
|
|
73
67
|
def action_permission
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module HostExtensions
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
included do
|
6
8
|
has_many :dlmlocks,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class_name: 'ForemanDlm::Dlmlock',
|
10
|
+
foreign_key: 'host_id',
|
11
|
+
dependent: :nullify,
|
12
|
+
inverse_of: :host
|
11
13
|
|
12
14
|
has_many :dlmlock_events,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
class_name: 'ForemanDlm::DlmlockEvent',
|
16
|
+
foreign_key: 'host_id',
|
17
|
+
dependent: :destroy,
|
18
|
+
inverse_of: :host
|
17
19
|
|
18
20
|
define_model_callbacks :lock, :only => :after
|
19
21
|
define_model_callbacks :unlock, :only => :after
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module HostMonitoringExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -31,7 +33,7 @@ module ForemanDlm
|
|
31
33
|
{
|
32
34
|
comment: _('Host acquired lock.'),
|
33
35
|
start_time: Time.current.to_i,
|
34
|
-
end_time: Time.current.advance(:minutes => 180).to_i
|
36
|
+
end_time: Time.current.advance(:minutes => 180).to_i,
|
35
37
|
}
|
36
38
|
end
|
37
39
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module UserExtensions
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
included do
|
6
8
|
has_many :dlmlock_events,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class_name: 'ForemanDlm::DlmlockEvent',
|
10
|
+
foreign_key: 'user_id',
|
11
|
+
dependent: :nullify,
|
12
|
+
inverse_of: :user
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
class Dlmlock < ApplicationRecord
|
3
5
|
include Authorizable
|
@@ -13,9 +15,9 @@ module ForemanDlm
|
|
13
15
|
belongs_to_host
|
14
16
|
|
15
17
|
has_many :dlmlock_events,
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
class_name: '::ForemanDlm::DlmlockEvent',
|
19
|
+
dependent: :destroy,
|
20
|
+
inverse_of: :dlmlock
|
19
21
|
|
20
22
|
validates :name, presence: true, uniqueness: true
|
21
23
|
|
@@ -67,7 +69,7 @@ module ForemanDlm
|
|
67
69
|
def locked_by?(host)
|
68
70
|
self.host == host
|
69
71
|
end
|
70
|
-
|
72
|
+
alias_method :acquired_by?, :locked_by?
|
71
73
|
|
72
74
|
def disabled?
|
73
75
|
!enabled?
|
@@ -76,7 +78,7 @@ module ForemanDlm
|
|
76
78
|
def locked?
|
77
79
|
host.present?
|
78
80
|
end
|
79
|
-
|
81
|
+
alias_method :taken?, :locked?
|
80
82
|
|
81
83
|
def humanized_type
|
82
84
|
_('Generic Lock')
|
@@ -91,7 +93,7 @@ module ForemanDlm
|
|
91
93
|
query = {
|
92
94
|
id: id,
|
93
95
|
host_id: [new_host.try(:id), old_host.try(:id)],
|
94
|
-
enabled: true
|
96
|
+
enabled: true,
|
95
97
|
}
|
96
98
|
|
97
99
|
updated = self.class.where(query).update(changes.merge(updated_at: Time.now.utc))
|
@@ -127,9 +129,9 @@ module ForemanDlm
|
|
127
129
|
)
|
128
130
|
end
|
129
131
|
|
130
|
-
def run_callback(
|
131
|
-
|
132
|
-
logger.debug { "custom hook after_#{callback} on #{
|
132
|
+
def run_callback(host, callback)
|
133
|
+
host.run_callbacks callback do
|
134
|
+
logger.debug { "custom hook after_#{callback} on #{host} will be executed if defined." }
|
133
135
|
true
|
134
136
|
end
|
135
137
|
end
|
data/config/routes.rb
CHANGED
data/lib/foreman_dlm/engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
engine_name 'foreman_dlm'
|
@@ -22,11 +24,11 @@ module ForemanDlm
|
|
22
24
|
settings do
|
23
25
|
category(:general) do
|
24
26
|
setting('dlm_stale_time',
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
type: :integer,
|
28
|
+
default: 4,
|
29
|
+
description: N_('Number of hours after which locked Distributed Lock is stale'),
|
30
|
+
full_name: N_('Distributed Lock stale time'),
|
31
|
+
validate: { numericality: { greater_than: 0 } })
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -34,25 +36,25 @@ module ForemanDlm
|
|
34
36
|
security_block :foreman_dlm do
|
35
37
|
permission :view_dlmlocks, {
|
36
38
|
:'foreman_dlm/dlmlocks' => [:index, :show, :auto_complete_search],
|
37
|
-
:'api/v2/dlmlocks' => [:index, :show]
|
39
|
+
:'api/v2/dlmlocks' => [:index, :show],
|
38
40
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
39
41
|
|
40
42
|
permission :create_dlmlocks, {
|
41
|
-
:'api/v2/dlmlocks' => [:create]
|
43
|
+
:'api/v2/dlmlocks' => [:create],
|
42
44
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
43
45
|
|
44
46
|
permission :edit_dlmlocks, {
|
45
47
|
:'foreman_dlm/dlmlocks' => [:release, :enable, :disable],
|
46
|
-
:'api/v2/dlmlocks' => [:update, :acquire, :release]
|
48
|
+
:'api/v2/dlmlocks' => [:update, :acquire, :release],
|
47
49
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
48
50
|
|
49
51
|
permission :destroy_dlmlocks, {
|
50
52
|
:'foreman_dlm/dlmlocks' => [:destroy],
|
51
|
-
:'api/v2/dlmlocks' => [:destroy]
|
53
|
+
:'api/v2/dlmlocks' => [:destroy],
|
52
54
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
53
55
|
|
54
56
|
permission :view_dlmlock_events, {
|
55
|
-
:'api/v2/dlmlock_events' => [:index]
|
57
|
+
:'api/v2/dlmlock_events' => [:index],
|
56
58
|
}, :resource_type => 'ForemanDlm::DlmlockEvent'
|
57
59
|
end
|
58
60
|
|
@@ -62,14 +64,14 @@ module ForemanDlm
|
|
62
64
|
:edit_dlmlocks,
|
63
65
|
:destroy_dlmlocks,
|
64
66
|
:view_dlmlock_events],
|
65
|
-
|
67
|
+
'Role granting full access permissions to distributed locks'
|
66
68
|
|
67
69
|
# add menu entry
|
68
70
|
menu :top_menu, :foreman_dlm_dlmlocks,
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index },
|
72
|
+
caption: N_('Distributed Locks'),
|
73
|
+
parent: :monitor_menu,
|
74
|
+
after: :audits
|
73
75
|
|
74
76
|
# Dlm Facet
|
75
77
|
register_facet(ForemanDlm::DlmFacet, :dlm_facet) do
|
@@ -81,9 +83,9 @@ module ForemanDlm
|
|
81
83
|
# extend host show page
|
82
84
|
extend_page('hosts/show') do |context|
|
83
85
|
context.add_pagelet :main_tabs,
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
:name => N_('Locks'),
|
87
|
+
:partial => 'hosts/dlmlocks_tab',
|
88
|
+
:onlyif => proc { |host| host.dlm_facet }
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
data/lib/foreman_dlm/version.rb
CHANGED
data/lib/foreman_dlm.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake/testtask'
|
2
4
|
|
3
5
|
# Tests
|
@@ -12,24 +14,4 @@ namespace :test do
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
namespace :foreman_dlm do
|
16
|
-
task :rubocop do
|
17
|
-
begin
|
18
|
-
require 'rubocop/rake_task'
|
19
|
-
RuboCop::RakeTask.new(:rubocop_foreman_dlm) do |task|
|
20
|
-
task.patterns = ["#{ForemanDlm::Engine.root}/app/**/*.rb",
|
21
|
-
"#{ForemanDlm::Engine.root}/lib/**/*.rb",
|
22
|
-
"#{ForemanDlm::Engine.root}/test/**/*.rb"]
|
23
|
-
end
|
24
|
-
rescue StandardError
|
25
|
-
puts 'Rubocop not loaded.'
|
26
|
-
end
|
27
|
-
|
28
|
-
Rake::Task['rubocop_foreman_dlm'].invoke
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
17
|
Rake::Task[:test].enhance ['test:foreman_dlm']
|
33
|
-
|
34
|
-
load 'tasks/jenkins.rake'
|
35
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_dlm', 'foreman_dlm:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|
data/locale/gemspec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
@@ -33,7 +35,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
33
35
|
assert dlmlock
|
34
36
|
assert_equal valid_attrs['name'], dlmlock.name
|
35
37
|
assert_equal valid_attrs['type'], dlmlock.type
|
36
|
-
|
38
|
+
assert dlmlock.enabled
|
37
39
|
assert_nil dlmlock.host
|
38
40
|
end
|
39
41
|
end
|
@@ -47,7 +49,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
47
49
|
assert_not_empty body
|
48
50
|
assert_equal dlmlock.name, body['name']
|
49
51
|
assert_equal dlmlock.type, body['type']
|
50
|
-
|
52
|
+
assert body['enabled']
|
51
53
|
assert_equal host1.id, body['host_id']
|
52
54
|
end
|
53
55
|
|
@@ -59,7 +61,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
59
61
|
assert_not_empty body
|
60
62
|
assert_equal dlmlock.name, body['name']
|
61
63
|
assert_equal dlmlock.type, body['type']
|
62
|
-
|
64
|
+
assert_not body['enabled']
|
63
65
|
assert_nil body['host_id']
|
64
66
|
end
|
65
67
|
|
@@ -91,7 +93,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
91
93
|
dlmlock.reload
|
92
94
|
assert_equal valid_attrs['name'], dlmlock.name
|
93
95
|
assert_equal valid_attrs['type'], dlmlock.type
|
94
|
-
|
96
|
+
assert_not dlmlock.enabled
|
95
97
|
assert_equal host1.id, dlmlock.host_id
|
96
98
|
end
|
97
99
|
end
|
@@ -181,7 +183,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
181
183
|
assert_not_empty body
|
182
184
|
assert_equal dlmlock.name, body['name']
|
183
185
|
assert_equal dlmlock.type, body['type']
|
184
|
-
|
186
|
+
assert body['enabled']
|
185
187
|
assert_nil body['host_id']
|
186
188
|
assert_nil body['host']
|
187
189
|
end
|
@@ -194,12 +196,12 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
194
196
|
assert_not_empty body
|
195
197
|
assert_equal dlmlock.name, body['name']
|
196
198
|
assert_equal dlmlock.type, body['type']
|
197
|
-
|
199
|
+
assert body['enabled']
|
198
200
|
assert_equal host1.id, body['host_id']
|
199
201
|
host = body['host']
|
200
202
|
assert host
|
201
203
|
assert_equal host1.name, host['name']
|
202
|
-
|
204
|
+
assert host['self']
|
203
205
|
end
|
204
206
|
|
205
207
|
test 'should show individual acquired lock by other' do
|
@@ -210,12 +212,12 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
210
212
|
assert_not_empty body
|
211
213
|
assert_equal dlmlock.name, body['name']
|
212
214
|
assert_equal dlmlock.type, body['type']
|
213
|
-
|
215
|
+
assert body['enabled']
|
214
216
|
assert_equal host2.id, body['host_id']
|
215
217
|
host = body['host']
|
216
218
|
assert host
|
217
219
|
assert_equal host2.name, host['name']
|
218
|
-
|
220
|
+
assert_not host['self']
|
219
221
|
end
|
220
222
|
|
221
223
|
test 'should update checkin time' do
|
@@ -378,7 +380,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
378
380
|
def valid_attrs
|
379
381
|
{
|
380
382
|
'name' => 'testlock',
|
381
|
-
'type' => 'ForemanDlm::Dlmlock::Update'
|
383
|
+
'type' => 'ForemanDlm::Dlmlock::Update',
|
382
384
|
}
|
383
385
|
end
|
384
386
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class FindHostByClientCertTest < ActionController::TestCase
|
@@ -62,7 +64,7 @@ class FindHostByClientCertTest < ActionController::TestCase
|
|
62
64
|
|
63
65
|
get :index
|
64
66
|
|
65
|
-
|
67
|
+
assert_not @controller.send(:require_client_cert_or_login)
|
66
68
|
assert_nil @controller.detected_host
|
67
69
|
end
|
68
70
|
|
@@ -73,7 +75,7 @@ class FindHostByClientCertTest < ActionController::TestCase
|
|
73
75
|
|
74
76
|
get :index
|
75
77
|
|
76
|
-
|
78
|
+
assert_not @controller.send(:require_client_cert_or_login)
|
77
79
|
assert_nil @controller.detected_host
|
78
80
|
end
|
79
81
|
|
@@ -83,7 +85,7 @@ class FindHostByClientCertTest < ActionController::TestCase
|
|
83
85
|
|
84
86
|
get :index
|
85
87
|
|
86
|
-
|
88
|
+
assert_not @controller.send(:require_client_cert_or_login)
|
87
89
|
assert_nil @controller.detected_host
|
88
90
|
end
|
89
91
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class HostsControllerTest < ActionController::TestCase
|
@@ -7,6 +9,6 @@ class HostsControllerTest < ActionController::TestCase
|
|
7
9
|
FactoryBot.create_list(:dlmlock, 2, host: host)
|
8
10
|
get :show, params: { :id => host.to_param }, session: set_session_user
|
9
11
|
assert_response :success
|
10
|
-
|
12
|
+
assert_match(/id='pagelet-id-locks'/, @response.body)
|
11
13
|
end
|
12
14
|
end
|
data/test/factories/dlmlock.rb
CHANGED
data/test/factories/host.rb
CHANGED
@@ -14,15 +14,16 @@ class DlmlocksTest < IntegrationTestWithJavascript
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'the search bar has autocomplete' do
|
17
|
-
skip if Gem::Version.new(Foreman::Version.new.notag) < Gem::Version.new('1.20')
|
18
17
|
FactoryBot.create_list(:dlmlock, 10)
|
19
18
|
|
20
19
|
visit foreman_dlm_dlmlocks_path
|
21
20
|
|
22
|
-
search_bar = page.first('
|
21
|
+
search_bar = page.first('.foreman-search-bar')
|
23
22
|
search_bar.first('input').set('ho')
|
24
23
|
|
25
|
-
|
24
|
+
autocomplete_list = page.first('div[data-ouia-component-id="search-autocomplete-menu"]')
|
25
|
+
list = autocomplete_list.find_all('span.pf-c-menu__item-text').map(&:text)
|
26
|
+
|
26
27
|
assert_includes list, 'host'
|
27
28
|
end
|
28
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
module ForemanDlm
|
@@ -45,10 +47,10 @@ module ForemanDlm
|
|
45
47
|
let(:dlmlock) { FactoryBot.create(:dlmlock) }
|
46
48
|
|
47
49
|
test 'should be enabled and unlocked' do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
assert dlmlock.enabled?
|
51
|
+
assert_not dlmlock.disabled?
|
52
|
+
assert_not dlmlock.locked?
|
53
|
+
assert_not dlmlock.taken?
|
52
54
|
end
|
53
55
|
|
54
56
|
test 'can be acquired' do
|
@@ -100,21 +102,21 @@ module ForemanDlm
|
|
100
102
|
let(:dlmlock) { FactoryBot.create(:dlmlock, :enabled => false) }
|
101
103
|
|
102
104
|
test 'should be disabled and unlocked' do
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
assert_not dlmlock.enabled?
|
106
|
+
assert dlmlock.disabled?
|
107
|
+
assert_not dlmlock.locked?
|
108
|
+
assert_not dlmlock.taken?
|
107
109
|
end
|
108
110
|
|
109
111
|
test 'can not be acquired' do
|
110
112
|
assert_nil dlmlock.host
|
111
|
-
|
113
|
+
assert_not dlmlock.acquire!(host1)
|
112
114
|
assert_nil dlmlock.reload.host
|
113
115
|
end
|
114
116
|
|
115
117
|
test 'can not be released' do
|
116
118
|
assert_nil dlmlock.host
|
117
|
-
|
119
|
+
assert_not dlmlock.release!(host1)
|
118
120
|
assert_nil dlmlock.reload.host
|
119
121
|
end
|
120
122
|
|
@@ -122,8 +124,8 @@ module ForemanDlm
|
|
122
124
|
host = HostWithCallbacks.new
|
123
125
|
host.name = 'test.example.com'
|
124
126
|
host.save
|
125
|
-
|
126
|
-
|
127
|
+
assert_not dlmlock.release!(host)
|
128
|
+
assert_empty host.callbacks
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
@@ -131,12 +133,12 @@ module ForemanDlm
|
|
131
133
|
let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host1) }
|
132
134
|
|
133
135
|
test 'should be enabled and locked' do
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
assert dlmlock.enabled?
|
137
|
+
assert_not dlmlock.disabled?
|
138
|
+
assert dlmlock.locked?
|
139
|
+
assert dlmlock.taken?
|
140
|
+
assert dlmlock.locked_by?(host1)
|
141
|
+
assert dlmlock.acquired_by?(host1)
|
140
142
|
end
|
141
143
|
|
142
144
|
test 'can be acquired by owner' do
|
@@ -147,7 +149,7 @@ module ForemanDlm
|
|
147
149
|
|
148
150
|
test 'can not be acquired by other host' do
|
149
151
|
assert_equal host1, dlmlock.host
|
150
|
-
|
152
|
+
assert_not dlmlock.acquire!(host2)
|
151
153
|
assert_equal host1, dlmlock.reload.host
|
152
154
|
end
|
153
155
|
|
@@ -159,7 +161,7 @@ module ForemanDlm
|
|
159
161
|
|
160
162
|
test 'can not be released by other host' do
|
161
163
|
assert_equal host1, dlmlock.host
|
162
|
-
|
164
|
+
assert_not dlmlock.release!(host2)
|
163
165
|
assert_equal host1, dlmlock.reload.host
|
164
166
|
end
|
165
167
|
|
@@ -196,16 +198,16 @@ module ForemanDlm
|
|
196
198
|
assert host1_with_callbacks
|
197
199
|
assert host2_with_callbacks
|
198
200
|
dlmlock.update(:host => host1_with_callbacks)
|
199
|
-
|
200
|
-
|
201
|
-
|
201
|
+
assert_not dlmlock.release!(host2_with_callbacks)
|
202
|
+
assert_empty host1_with_callbacks.callbacks
|
203
|
+
assert_empty host2_with_callbacks.callbacks
|
202
204
|
end
|
203
205
|
|
204
206
|
test 'triggers no callbacks on acquiry attempt by owner' do
|
205
207
|
assert host1_with_callbacks
|
206
208
|
dlmlock.update(:host => host1_with_callbacks)
|
207
209
|
assert dlmlock.acquire!(host1_with_callbacks)
|
208
|
-
|
210
|
+
assert_empty host1_with_callbacks.callbacks
|
209
211
|
end
|
210
212
|
end
|
211
213
|
|
@@ -32,14 +32,14 @@ class DlmlockStatusTest < ActiveSupport::TestCase
|
|
32
32
|
status = host.get_status(HostStatus::DlmlockStatus)
|
33
33
|
|
34
34
|
assert_not_empty host.dlmlocks
|
35
|
-
|
35
|
+
assert status.relevant?
|
36
36
|
end
|
37
37
|
|
38
38
|
test 'should return false if host has no dlmlocks' do
|
39
39
|
status = host.get_status(HostStatus::DlmlockStatus)
|
40
40
|
|
41
41
|
assert_empty host.dlmlocks
|
42
|
-
|
42
|
+
assert_not status.relevant?
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/test/models/user_test.rb
CHANGED
data/test/test_plugin_helper.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
require 'unit/shared/access_permissions_test_base'
|
5
|
+
|
6
|
+
# Permissions are added in AccessPermissions with lists of controllers and
|
7
|
+
# actions that they enable access to. For non-admin users, we need to test
|
8
|
+
# that there are permissions available that cover every controller action, else
|
9
|
+
# it can't be delegated and this will lead to parts of the application that
|
10
|
+
# aren't functional for non-admin users.
|
11
|
+
#
|
12
|
+
# In particular, it's important that actions for AJAX requests are added to
|
13
|
+
# an appropriate permission so views using those requests function.
|
14
|
+
class AccessPermissionsTest < ActiveSupport::TestCase
|
15
|
+
include AccessPermissionsTestBase
|
16
|
+
|
17
|
+
check_routes(ForemanDlm::Engine.routes, [])
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_dlm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.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:
|
11
|
+
date: 2024-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -25,47 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rubocop
|
28
|
+
name: theforeman-rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 0.1.2
|
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: 1.
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop-performance
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.13.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.13.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop-rails
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.9.1
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.9.1
|
40
|
+
version: 0.1.2
|
69
41
|
description: Adds a Distributed Lock Manager to Foreman. This enables painless system
|
70
42
|
updates for clusters.
|
71
43
|
email:
|
@@ -154,6 +126,7 @@ files:
|
|
154
126
|
- test/models/host_status/dlmlock_status_test.rb
|
155
127
|
- test/models/user_test.rb
|
156
128
|
- test/test_plugin_helper.rb
|
129
|
+
- test/unit/foreman_dlm/access_permissions_test.rb
|
157
130
|
homepage: https://github.com/dm-drogeriemarkt/foreman_dlm
|
158
131
|
licenses:
|
159
132
|
- GPL-3.0
|
@@ -168,14 +141,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
141
|
requirements:
|
169
142
|
- - ">="
|
170
143
|
- !ruby/object:Gem::Version
|
171
|
-
version: '
|
144
|
+
version: '2.5'
|
145
|
+
- - "<"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '4'
|
172
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
149
|
requirements:
|
174
150
|
- - ">="
|
175
151
|
- !ruby/object:Gem::Version
|
176
152
|
version: '0'
|
177
153
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
154
|
+
rubygems_version: 3.4.1
|
179
155
|
signing_key:
|
180
156
|
specification_version: 4
|
181
157
|
summary: Distributed Lock Manager for Foreman.
|
@@ -200,3 +176,4 @@ test_files:
|
|
200
176
|
- test/models/host_status/dlmlock_status_test.rb
|
201
177
|
- test/models/user_test.rb
|
202
178
|
- test/test_plugin_helper.rb
|
179
|
+
- test/unit/foreman_dlm/access_permissions_test.rb
|