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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/Rakefile +4 -2
  4. data/app/controllers/api/v2/dlmlock_events_controller.rb +3 -0
  5. data/app/controllers/api/v2/dlmlocks_controller.rb +17 -13
  6. data/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +2 -0
  7. data/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +6 -10
  8. data/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +2 -0
  9. data/app/controllers/concerns/foreman_dlm/update_checkin_time.rb +3 -0
  10. data/app/controllers/foreman_dlm/application_controller.rb +2 -0
  11. data/app/controllers/foreman_dlm/dlmlocks_controller.rb +4 -1
  12. data/app/helpers/foreman_dlm/dlmlock_helper.rb +4 -0
  13. data/app/jobs/foreman_dlm/refresh_dlmlock_status.rb +2 -0
  14. data/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb +2 -0
  15. data/app/models/concerns/foreman_dlm/expirable.rb +3 -0
  16. data/app/models/concerns/foreman_dlm/host_extensions.rb +17 -8
  17. data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +5 -1
  18. data/app/models/concerns/foreman_dlm/user_extensions.rb +6 -4
  19. data/app/models/foreman_dlm/dlm_facet.rb +2 -0
  20. data/app/models/foreman_dlm/dlmlock/update.rb +2 -0
  21. data/app/models/foreman_dlm/dlmlock.rb +14 -11
  22. data/app/models/foreman_dlm/dlmlock_event.rb +2 -0
  23. data/app/models/host_status/dlmlock_status.rb +2 -0
  24. data/app/views/api/v2/dlmlock_events/index.json.rabl +2 -0
  25. data/app/views/api/v2/dlmlocks/acquire.json.rabl +2 -0
  26. data/app/views/api/v2/dlmlocks/base.json.rabl +2 -0
  27. data/app/views/api/v2/dlmlocks/create.json.rabl +2 -0
  28. data/app/views/api/v2/dlmlocks/index.json.rabl +2 -0
  29. data/app/views/api/v2/dlmlocks/main.json.rabl +2 -0
  30. data/app/views/api/v2/dlmlocks/release.json.rabl +2 -0
  31. data/app/views/api/v2/dlmlocks/show.json.rabl +2 -0
  32. data/app/views/api/v2/dlmlocks/update.json.rabl +2 -0
  33. data/app/views/api/v2/errors/precondition_failed.json.rabl +2 -0
  34. data/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl +2 -0
  35. data/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl +2 -0
  36. data/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl +2 -0
  37. data/app/views/foreman_dlm/dlmlocks/index.html.erb +1 -1
  38. data/app/views/foreman_dlm/dlmlocks/show.html.erb +1 -1
  39. data/app/views/foreman_dlm/dlmlocks/welcome.html.erb +2 -2
  40. data/app/views/hosts/_dlmlocks_tab.html.erb +3 -3
  41. data/config/routes.rb +2 -0
  42. data/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +2 -0
  43. data/db/migrate/20180627150003_rename_dlmlock_sti_models.rb +2 -0
  44. data/db/migrate/20180704162345_add_dlmlock_events.rb +2 -0
  45. data/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb +2 -0
  46. data/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb +2 -0
  47. data/db/migrate/20180713113208_update_permissions_for_scoped_models.rb +2 -0
  48. data/lib/foreman_dlm/engine.rb +37 -33
  49. data/lib/foreman_dlm/version.rb +3 -1
  50. data/lib/foreman_dlm.rb +2 -0
  51. data/lib/tasks/dlmlock_events.rake +2 -0
  52. data/lib/tasks/foreman_dlm_tasks.rake +2 -20
  53. data/locale/gemspec.rb +3 -1
  54. data/test/controllers/api/v2/dlmlocks_controller_test.rb +22 -20
  55. data/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb +2 -0
  56. data/test/controllers/api/v2/hosts_controller_test.rb +2 -0
  57. data/test/controllers/find_host_by_client_cert_test.rb +5 -3
  58. data/test/controllers/foreman_dlm/dlmlocks_test.rb +4 -2
  59. data/test/controllers/hosts_controller_test.rb +3 -1
  60. data/test/factories/dlm_facets.rb +2 -0
  61. data/test/factories/dlmlock.rb +3 -1
  62. data/test/factories/dlmlock_events.rb +3 -1
  63. data/test/factories/host.rb +2 -0
  64. data/test/integration/foreman_dlm/dlmlocks_test.rb +29 -0
  65. data/test/jobs/refresh_dlmlock_status_test.rb +2 -0
  66. data/test/models/foreman_dlm/dlm_facet_test.rb +2 -0
  67. data/test/models/foreman_dlm/dlmlock_event_test.rb +2 -0
  68. data/test/models/foreman_dlm/dlmlock_test.rb +41 -31
  69. data/test/models/host_managed_test.rb +20 -0
  70. data/test/models/host_monitoring_test.rb +2 -0
  71. data/test/models/host_status/dlmlock_status_test.rb +4 -8
  72. data/test/models/user_test.rb +2 -0
  73. data/test/test_plugin_helper.rb +6 -0
  74. data/test/unit/foreman_dlm/access_permissions_test.rb +18 -0
  75. metadata +36 -29
  76. data/app/models/settings/dlm.rb +0 -20
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rails.application.routes.draw do
2
4
  namespace :api, :defaults => { :format => 'json' } do
3
5
  scope '(:apiv)', :module => :v2,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDlmlock < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :dlmlocks do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RenameDlmlockStiModels < ActiveRecord::Migration[5.1]
2
4
  def up
3
5
  execute "UPDATE dlmlocks set type='ForemanDlm::Dlmlock::Update' where type='Dlmlock::Update';"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDlmlockEvents < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  create_table :dlmlock_events do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddHostsFkToDlmlocks < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  add_foreign_key :dlmlocks, :hosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateDlmFacets < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  create_table :dlm_facets do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UpdatePermissionsForScopedModels < ActiveRecord::Migration[5.1]
2
4
  class FakePermission < ApplicationRecord
3
5
  self.table_name = 'permissions'
@@ -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 '>= 1.17'
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, :distributed_locks,
65
- url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index },
66
- caption: N_('Distributed Locks'),
67
- parent: :monitor_menu,
68
- after: :audits
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
- :name => N_('Locks'),
81
- :partial => 'hosts/dlmlocks_tab',
82
- :onlyif => proc { |host| host.dlm_facet }
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
- begin
90
- Host::Managed.send(:include, ForemanDlm::HostExtensions)
91
- User.send(:include, ForemanDlm::UserExtensions)
92
- Host::Managed.send(:include, ForemanDlm::DlmFacetHostExtensions)
93
-
94
- Host::Managed.send(:include, ForemanDlm::HostMonitoringExtensions) if ForemanDlm.with_monitoring?
95
- rescue StandardError => e
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('../../..', __FILE__), 'locale')
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanDlm
2
- VERSION = '1.1.0'.freeze
4
+ VERSION = '3.0.0'
3
5
  end
data/lib/foreman_dlm.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_dlm/engine'
2
4
 
3
5
  module ForemanDlm
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  desc <<-TASK_DESCRIPTION
2
4
  Expire lock events automatically
3
5
 
@@ -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,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Matches foreman_dlm.gemspec
2
- _('TODO: Description of ForemanDlm.')
4
+ _('Adds a Distributed Lock Manager to Foreman. This enables painless system updates for clusters.')
@@ -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
- assert_equal true, dlmlock.enabled
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
- refute_empty body
49
+ assert_not_empty body
48
50
  assert_equal dlmlock.name, body['name']
49
51
  assert_equal dlmlock.type, body['type']
50
- assert_equal true, body['enabled']
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
- refute_empty body
61
+ assert_not_empty body
60
62
  assert_equal dlmlock.name, body['name']
61
63
  assert_equal dlmlock.type, body['type']
62
- assert_equal false, body['enabled']
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
- refute_empty body
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
- refute host.key?('self')
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
- assert_equal false, dlmlock.enabled
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
- refute_empty body
183
+ assert_not_empty body
182
184
  assert_equal dlmlock.name, body['name']
183
185
  assert_equal dlmlock.type, body['type']
184
- assert_equal true, body['enabled']
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
- refute_empty body
196
+ assert_not_empty body
195
197
  assert_equal dlmlock.name, body['name']
196
198
  assert_equal dlmlock.type, body['type']
197
- assert_equal true, body['enabled']
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
- assert_equal true, host['self']
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
- refute_empty body
212
+ assert_not_empty body
211
213
  assert_equal dlmlock.name, body['name']
212
214
  assert_equal dlmlock.type, body['type']
213
- assert_equal true, body['enabled']
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
- assert_equal false, host['self']
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
- refute as_admin { host1.dlm_facet }
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
- refute as_admin { host1.dlm_facet }
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
- refute as_admin { host1.dlm_facet }
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 Api::V2::DlmlockEventsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class Api::V2::HostsControllerTest < ActionController::TestCase
@@ -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
- assert_equal false, @controller.send(:require_client_cert_or_login)
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
- assert_equal false, @controller.send(:require_client_cert_or_login)
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
- assert_equal false, @controller.send(:require_client_cert_or_login)
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
- refute Dlmlock.exists?(dlmlock.id)
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
- refute dlmlock.reload.taken?
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
- assert @response.body.match(/id='pagelet-id-locks'/)
12
+ assert_match(/id='pagelet-id-locks'/, @response.body)
11
13
  end
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :dlm_facet, class: 'ForemanDlm::DlmFacet' do
3
5
  sequence(:last_checkin_at) { |n| n.minutes.ago }
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :dlmlock, class: ::ForemanDlm::Dlmlock::Update do
3
5
  sequence(:name) { |n| "Lock #{n}" }
4
- type 'ForemanDlm::Dlmlock::Update'
6
+ type { 'ForemanDlm::Dlmlock::Update' }
5
7
 
6
8
  trait :locked do
7
9
  host
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :dlmlock_event, class: ::ForemanDlm::DlmlockEvent do
3
5
  dlmlock
4
- event_type 'release'
6
+ event_type { 'release' }
5
7
  host
6
8
 
7
9
  trait :old_event do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :host do
3
5
  trait :with_dlm_facet do
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class RefreshDlmlockStatusTest < ActiveJob::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanDlm
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanDlm