foreman_dlm 1.1.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 +8 -4
- data/Rakefile +4 -2
- data/app/controllers/api/v2/dlmlock_events_controller.rb +3 -0
- data/app/controllers/api/v2/dlmlocks_controller.rb +17 -13
- data/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +6 -10
- data/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/update_checkin_time.rb +3 -0
- data/app/controllers/foreman_dlm/application_controller.rb +2 -0
- data/app/controllers/foreman_dlm/dlmlocks_controller.rb +4 -1
- data/app/helpers/foreman_dlm/dlmlock_helper.rb +4 -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 +3 -0
- data/app/models/concerns/foreman_dlm/host_extensions.rb +17 -8
- data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +5 -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 +14 -11
- 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/app/views/foreman_dlm/dlmlocks/index.html.erb +1 -1
- data/app/views/foreman_dlm/dlmlocks/show.html.erb +1 -1
- data/app/views/foreman_dlm/dlmlocks/welcome.html.erb +2 -2
- data/app/views/hosts/_dlmlocks_tab.html.erb +3 -3
- 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 +37 -33
- 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 +22 -20
- 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 +4 -2
- data/test/controllers/hosts_controller_test.rb +3 -1
- data/test/factories/dlm_facets.rb +2 -0
- data/test/factories/dlmlock.rb +3 -1
- data/test/factories/dlmlock_events.rb +3 -1
- data/test/factories/host.rb +2 -0
- data/test/integration/foreman_dlm/dlmlocks_test.rb +29 -0
- 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 +41 -31
- data/test/models/host_managed_test.rb +20 -0
- data/test/models/host_monitoring_test.rb +2 -0
- data/test/models/host_status/dlmlock_status_test.rb +4 -8
- data/test/models/user_test.rb +2 -0
- data/test/test_plugin_helper.rb +6 -0
- data/test/unit/foreman_dlm/access_permissions_test.rb +18 -0
- metadata +36 -29
- data/app/models/settings/dlm.rb +0 -20
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'
|
@@ -6,14 +8,6 @@ module ForemanDlm
|
|
6
8
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
7
9
|
config.autoload_paths += Dir["#{config.root}/app/jobs"]
|
8
10
|
|
9
|
-
initializer 'foreman_dlm.load_default_settings', before: :load_config_initializers do
|
10
|
-
require_dependency File.expand_path('../../app/models/settings/dlm.rb', __dir__) if begin
|
11
|
-
Setting.table_exists?
|
12
|
-
rescue StandardError
|
13
|
-
(false)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
11
|
# Add any db migrations
|
18
12
|
initializer 'foreman_dlm.load_app_instance_data' do |app|
|
19
13
|
ForemanDlm::Engine.paths['db/migrate'].existent.each do |path|
|
@@ -23,33 +17,44 @@ module ForemanDlm
|
|
23
17
|
|
24
18
|
initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |_app|
|
25
19
|
Foreman::Plugin.register :foreman_dlm do
|
26
|
-
requires_foreman '>=
|
20
|
+
requires_foreman '>= 3.0'
|
27
21
|
|
28
22
|
apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]
|
29
23
|
|
24
|
+
settings do
|
25
|
+
category(:general) do
|
26
|
+
setting('dlm_stale_time',
|
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 } })
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
30
35
|
# Add permissions
|
31
36
|
security_block :foreman_dlm do
|
32
37
|
permission :view_dlmlocks, {
|
33
38
|
:'foreman_dlm/dlmlocks' => [:index, :show, :auto_complete_search],
|
34
|
-
:'api/v2/dlmlocks' => [:index, :show]
|
39
|
+
:'api/v2/dlmlocks' => [:index, :show],
|
35
40
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
36
41
|
|
37
42
|
permission :create_dlmlocks, {
|
38
|
-
:'api/v2/dlmlocks' => [:create]
|
43
|
+
:'api/v2/dlmlocks' => [:create],
|
39
44
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
40
45
|
|
41
46
|
permission :edit_dlmlocks, {
|
42
47
|
:'foreman_dlm/dlmlocks' => [:release, :enable, :disable],
|
43
|
-
:'api/v2/dlmlocks' => [:update, :acquire, :release]
|
48
|
+
:'api/v2/dlmlocks' => [:update, :acquire, :release],
|
44
49
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
45
50
|
|
46
51
|
permission :destroy_dlmlocks, {
|
47
52
|
:'foreman_dlm/dlmlocks' => [:destroy],
|
48
|
-
:'api/v2/dlmlocks' => [:destroy]
|
53
|
+
:'api/v2/dlmlocks' => [:destroy],
|
49
54
|
}, :resource_type => 'ForemanDlm::Dlmlock'
|
50
55
|
|
51
56
|
permission :view_dlmlock_events, {
|
52
|
-
:'api/v2/dlmlock_events' => [:index]
|
57
|
+
:'api/v2/dlmlock_events' => [:index],
|
53
58
|
}, :resource_type => 'ForemanDlm::DlmlockEvent'
|
54
59
|
end
|
55
60
|
|
@@ -58,14 +63,15 @@ module ForemanDlm
|
|
58
63
|
:create_dlmlocks,
|
59
64
|
:edit_dlmlocks,
|
60
65
|
:destroy_dlmlocks,
|
61
|
-
:view_dlmlock_events]
|
66
|
+
:view_dlmlock_events],
|
67
|
+
'Role granting full access permissions to distributed locks'
|
62
68
|
|
63
69
|
# add menu entry
|
64
|
-
menu :top_menu, :
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
menu :top_menu, :foreman_dlm_dlmlocks,
|
71
|
+
url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index },
|
72
|
+
caption: N_('Distributed Locks'),
|
73
|
+
parent: :monitor_menu,
|
74
|
+
after: :audits
|
69
75
|
|
70
76
|
# Dlm Facet
|
71
77
|
register_facet(ForemanDlm::DlmFacet, :dlm_facet) do
|
@@ -77,28 +83,26 @@ module ForemanDlm
|
|
77
83
|
# extend host show page
|
78
84
|
extend_page('hosts/show') do |context|
|
79
85
|
context.add_pagelet :main_tabs,
|
80
|
-
|
81
|
-
|
82
|
-
|
86
|
+
:name => N_('Locks'),
|
87
|
+
:partial => 'hosts/dlmlocks_tab',
|
88
|
+
:onlyif => proc { |host| host.dlm_facet }
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
87
93
|
# Include concerns in this config.to_prepare block
|
88
94
|
config.to_prepare do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Rails.logger.warn "ForemanDlm: skipping engine hook (#{e})"
|
97
|
-
end
|
95
|
+
Host::Managed.include ForemanDlm::HostExtensions
|
96
|
+
User.include ForemanDlm::UserExtensions
|
97
|
+
Host::Managed.include ForemanDlm::DlmFacetHostExtensions
|
98
|
+
|
99
|
+
Host::Managed.include ForemanDlm::HostMonitoringExtensions if ForemanDlm.with_monitoring?
|
100
|
+
rescue StandardError => e
|
101
|
+
Rails.logger.warn "ForemanDlm: skipping engine hook (#{e})"
|
98
102
|
end
|
99
103
|
|
100
104
|
initializer 'foreman_dlm.register_gettext', after: :load_config_initializers do |_app|
|
101
|
-
locale_dir = File.join(File.expand_path('
|
105
|
+
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
|
102
106
|
locale_domain = 'foreman_dlm'
|
103
107
|
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
104
108
|
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
|
@@ -44,10 +46,10 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
44
46
|
get :show, params: { :id => dlmlock.to_param }
|
45
47
|
assert_response :success
|
46
48
|
body = ActiveSupport::JSON.decode(@response.body)
|
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
|
|
@@ -56,10 +58,10 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
56
58
|
get :show, params: { :id => dlmlock.to_param }
|
57
59
|
assert_response :success
|
58
60
|
body = ActiveSupport::JSON.decode(@response.body)
|
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
|
|
@@ -68,13 +70,13 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
68
70
|
get :show, params: { :id => dlmlock.name }
|
69
71
|
assert_response :success
|
70
72
|
body = ActiveSupport::JSON.decode(@response.body)
|
71
|
-
|
73
|
+
assert_not_empty body
|
72
74
|
assert_equal dlmlock.id, body['id']
|
73
75
|
assert_equal dlmlock.name, body['name']
|
74
76
|
host = body['host']
|
75
77
|
assert host
|
76
78
|
assert_equal host1.name, host['name']
|
77
|
-
|
79
|
+
assert_not host.key?('self')
|
78
80
|
end
|
79
81
|
|
80
82
|
test 'should not find dlmlock with invalid id' do
|
@@ -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
|
@@ -178,10 +180,10 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
178
180
|
get :show, params: { :id => dlmlock.to_param }
|
179
181
|
assert_response :success
|
180
182
|
body = ActiveSupport::JSON.decode(@response.body)
|
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
|
@@ -191,15 +193,15 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
191
193
|
get :show, params: { :id => dlmlock.to_param }
|
192
194
|
assert_response :success
|
193
195
|
body = ActiveSupport::JSON.decode(@response.body)
|
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
|
@@ -207,20 +209,20 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
207
209
|
get :show, params: { :id => dlmlock.to_param }
|
208
210
|
assert_response :success
|
209
211
|
body = ActiveSupport::JSON.decode(@response.body)
|
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
|
222
224
|
dlmlock = as_admin { FactoryBot.create(:dlmlock) }
|
223
|
-
|
225
|
+
assert_not as_admin { host1.dlm_facet }
|
224
226
|
put :show, params: { :id => dlmlock.to_param }
|
225
227
|
assert as_admin { host1.reload.dlm_facet.last_checkin_at }
|
226
228
|
end
|
@@ -260,7 +262,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
260
262
|
|
261
263
|
test 'should update checkin time' do
|
262
264
|
dlmlock = as_admin { FactoryBot.create(:dlmlock) }
|
263
|
-
|
265
|
+
assert_not as_admin { host1.dlm_facet }
|
264
266
|
put :acquire, params: { :id => dlmlock.to_param }
|
265
267
|
assert as_admin { host1.reload.dlm_facet.last_checkin_at }
|
266
268
|
end
|
@@ -300,7 +302,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase
|
|
300
302
|
|
301
303
|
test 'should update checkin time' do
|
302
304
|
dlmlock = as_admin { FactoryBot.create(:dlmlock) }
|
303
|
-
|
305
|
+
assert_not as_admin { host1.dlm_facet }
|
304
306
|
put :release, params: { :id => dlmlock.to_param }
|
305
307
|
assert as_admin { host1.reload.dlm_facet.last_checkin_at }
|
306
308
|
end
|
@@ -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
|
module ForemanDlm
|
@@ -27,7 +29,7 @@ module ForemanDlm
|
|
27
29
|
dlmlock = FactoryBot.create(:dlmlock)
|
28
30
|
delete :destroy, params: { :id => dlmlock.id }, session: set_session_user
|
29
31
|
assert_redirected_to foreman_dlm_dlmlocks_url
|
30
|
-
|
32
|
+
assert_not Dlmlock.exists?(dlmlock.id)
|
31
33
|
end
|
32
34
|
|
33
35
|
test '#enable' do
|
@@ -49,7 +51,7 @@ module ForemanDlm
|
|
49
51
|
dlmlock = FactoryBot.create(:dlmlock, host: host)
|
50
52
|
put :release, params: { :id => dlmlock.id }, session: set_session_user
|
51
53
|
assert_redirected_to foreman_dlm_dlmlocks_url
|
52
|
-
|
54
|
+
assert_not dlmlock.reload.taken?
|
53
55
|
end
|
54
56
|
end
|
55
57
|
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
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
require 'integration_test_helper'
|
5
|
+
|
6
|
+
class DlmlocksTest < IntegrationTestWithJavascript
|
7
|
+
setup do
|
8
|
+
User.current = users(:admin)
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'the index page works' do
|
12
|
+
FactoryBot.create_list(:dlmlock, 10)
|
13
|
+
assert_index_page(foreman_dlm_dlmlocks_path, 'Distributed Locks')
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'the search bar has autocomplete' do
|
17
|
+
FactoryBot.create_list(:dlmlock, 10)
|
18
|
+
|
19
|
+
visit foreman_dlm_dlmlocks_path
|
20
|
+
|
21
|
+
search_bar = page.first('.foreman-search-bar')
|
22
|
+
search_bar.first('input').set('ho')
|
23
|
+
|
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
|
+
|
27
|
+
assert_includes list, 'host'
|
28
|
+
end
|
29
|
+
end
|