foreman_dlm 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/Rakefile +4 -2
  4. data/app/controllers/api/v2/dlmlock_events_controller.rb +2 -0
  5. data/app/controllers/api/v2/dlmlocks_controller.rb +14 -11
  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 +2 -0
  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 +2 -0
  10. data/app/controllers/foreman_dlm/application_controller.rb +2 -0
  11. data/app/controllers/foreman_dlm/dlmlocks_controller.rb +4 -10
  12. data/app/helpers/foreman_dlm/dlmlock_helper.rb +2 -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 +2 -0
  16. data/app/models/concerns/foreman_dlm/host_extensions.rb +10 -8
  17. data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +3 -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 +11 -9
  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/config/routes.rb +2 -0
  38. data/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +2 -0
  39. data/db/migrate/20180627150003_rename_dlmlock_sti_models.rb +3 -1
  40. data/db/migrate/20180704162345_add_dlmlock_events.rb +2 -0
  41. data/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb +2 -0
  42. data/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb +2 -0
  43. data/db/migrate/20180713113208_update_permissions_for_scoped_models.rb +2 -0
  44. data/lib/foreman_dlm/engine.rb +70 -70
  45. data/lib/foreman_dlm/version.rb +3 -1
  46. data/lib/foreman_dlm.rb +2 -0
  47. data/lib/tasks/dlmlock_events.rake +2 -0
  48. data/lib/tasks/foreman_dlm_tasks.rake +2 -20
  49. data/locale/gemspec.rb +3 -1
  50. data/test/controllers/api/v2/dlmlocks_controller_test.rb +12 -10
  51. data/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb +2 -0
  52. data/test/controllers/api/v2/hosts_controller_test.rb +2 -0
  53. data/test/controllers/find_host_by_client_cert_test.rb +5 -3
  54. data/test/controllers/foreman_dlm/dlmlocks_test.rb +2 -0
  55. data/test/controllers/hosts_controller_test.rb +3 -1
  56. data/test/factories/dlm_facets.rb +2 -0
  57. data/test/factories/dlmlock.rb +2 -0
  58. data/test/factories/dlmlock_events.rb +2 -0
  59. data/test/factories/host.rb +2 -0
  60. data/test/integration/foreman_dlm/dlmlocks_test.rb +9 -3
  61. data/test/jobs/refresh_dlmlock_status_test.rb +2 -0
  62. data/test/models/foreman_dlm/dlm_facet_test.rb +2 -0
  63. data/test/models/foreman_dlm/dlmlock_event_test.rb +2 -0
  64. data/test/models/foreman_dlm/dlmlock_test.rb +26 -24
  65. data/test/models/host_managed_test.rb +2 -0
  66. data/test/models/host_monitoring_test.rb +2 -0
  67. data/test/models/host_status/dlmlock_status_test.rb +2 -2
  68. data/test/models/user_test.rb +2 -0
  69. data/test/test_plugin_helper.rb +2 -0
  70. data/test/unit/foreman_dlm/access_permissions_test.rb +18 -0
  71. metadata +12 -38
@@ -1,11 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanDlm
2
4
  class Engine < ::Rails::Engine
3
5
  engine_name 'foreman_dlm'
4
6
 
5
- config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
6
- config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
7
- config.autoload_paths += Dir["#{config.root}/app/jobs"]
8
-
9
7
  # Add any db migrations
10
8
  initializer 'foreman_dlm.load_app_instance_data' do |app|
11
9
  ForemanDlm::Engine.paths['db/migrate'].existent.each do |path|
@@ -13,77 +11,79 @@ module ForemanDlm
13
11
  end
14
12
  end
15
13
 
16
- initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |_app|
17
- Foreman::Plugin.register :foreman_dlm do
18
- requires_foreman '>= 3.0'
19
-
20
- apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]
21
-
22
- settings do
23
- category(:general) do
24
- setting('dlm_stale_time',
25
- type: :integer,
26
- default: 4,
27
- description: N_('Number of hours after which locked Distributed Lock is stale'),
28
- full_name: N_('Distributed Lock stale time'),
29
- validate: { numericality: { greater_than: 0 } })
14
+ initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |app|
15
+ app.reloader.to_prepare do
16
+ Foreman::Plugin.register :foreman_dlm do
17
+ requires_foreman '>= 3.13'
18
+
19
+ apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]
20
+
21
+ settings do
22
+ category(:general) do
23
+ setting('dlm_stale_time',
24
+ type: :integer,
25
+ default: 4,
26
+ description: N_('Number of hours after which locked Distributed Lock is stale'),
27
+ full_name: N_('Distributed Lock stale time'),
28
+ validate: { numericality: { greater_than: 0 } })
29
+ end
30
30
  end
31
- end
32
31
 
33
- # Add permissions
34
- security_block :foreman_dlm do
35
- permission :view_dlmlocks, {
36
- :'foreman_dlm/dlmlocks' => [:index, :show, :auto_complete_search],
37
- :'api/v2/dlmlocks' => [:index, :show]
38
- }, :resource_type => 'ForemanDlm::Dlmlock'
39
-
40
- permission :create_dlmlocks, {
41
- :'api/v2/dlmlocks' => [:create]
42
- }, :resource_type => 'ForemanDlm::Dlmlock'
43
-
44
- permission :edit_dlmlocks, {
45
- :'foreman_dlm/dlmlocks' => [:release, :enable, :disable],
46
- :'api/v2/dlmlocks' => [:update, :acquire, :release]
47
- }, :resource_type => 'ForemanDlm::Dlmlock'
48
-
49
- permission :destroy_dlmlocks, {
50
- :'foreman_dlm/dlmlocks' => [:destroy],
51
- :'api/v2/dlmlocks' => [:destroy]
52
- }, :resource_type => 'ForemanDlm::Dlmlock'
53
-
54
- permission :view_dlmlock_events, {
55
- :'api/v2/dlmlock_events' => [:index]
56
- }, :resource_type => 'ForemanDlm::DlmlockEvent'
57
- end
32
+ # Add permissions
33
+ security_block :foreman_dlm do
34
+ permission :view_dlmlocks, {
35
+ :'foreman_dlm/dlmlocks' => [:index, :show, :auto_complete_search],
36
+ :'api/v2/dlmlocks' => [:index, :show],
37
+ }, :resource_type => 'ForemanDlm::Dlmlock'
38
+
39
+ permission :create_dlmlocks, {
40
+ :'api/v2/dlmlocks' => [:create],
41
+ }, :resource_type => 'ForemanDlm::Dlmlock'
42
+
43
+ permission :edit_dlmlocks, {
44
+ :'foreman_dlm/dlmlocks' => [:release, :enable, :disable],
45
+ :'api/v2/dlmlocks' => [:update, :acquire, :release],
46
+ }, :resource_type => 'ForemanDlm::Dlmlock'
47
+
48
+ permission :destroy_dlmlocks, {
49
+ :'foreman_dlm/dlmlocks' => [:destroy],
50
+ :'api/v2/dlmlocks' => [:destroy],
51
+ }, :resource_type => 'ForemanDlm::Dlmlock'
52
+
53
+ permission :view_dlmlock_events, {
54
+ :'api/v2/dlmlock_events' => [:index],
55
+ }, :resource_type => 'ForemanDlm::DlmlockEvent'
56
+ end
58
57
 
59
- # Add a new role called 'Distributed Lock Manager' if it doesn't exist
60
- role 'Distributed Lock Manager', [:view_dlmlocks,
61
- :create_dlmlocks,
62
- :edit_dlmlocks,
63
- :destroy_dlmlocks,
64
- :view_dlmlock_events],
65
- 'Role granting full access permissions to distributed locks'
66
-
67
- # add menu entry
68
- menu :top_menu, :foreman_dlm_dlmlocks,
69
- url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index },
70
- caption: N_('Distributed Locks'),
71
- parent: :monitor_menu,
72
- after: :audits
73
-
74
- # Dlm Facet
75
- register_facet(ForemanDlm::DlmFacet, :dlm_facet) do
76
- api_view list: 'foreman_dlm/api/v2/dlm_facets/base_with_root', single: 'foreman_dlm/api/v2/dlm_facets/show'
77
- end
58
+ # Add a new role called 'Distributed Lock Manager' if it doesn't exist
59
+ role 'Distributed Lock Manager', [:view_dlmlocks,
60
+ :create_dlmlocks,
61
+ :edit_dlmlocks,
62
+ :destroy_dlmlocks,
63
+ :view_dlmlock_events],
64
+ 'Role granting full access permissions to distributed locks'
65
+
66
+ # add menu entry
67
+ menu :top_menu, :foreman_dlm_dlmlocks,
68
+ url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index },
69
+ caption: N_('Distributed Locks'),
70
+ parent: :monitor_menu,
71
+ after: :audits
72
+
73
+ # Dlm Facet
74
+ register_facet(ForemanDlm::DlmFacet, :dlm_facet) do
75
+ api_view list: 'foreman_dlm/api/v2/dlm_facets/base_with_root', single: 'foreman_dlm/api/v2/dlm_facets/show'
76
+ end
78
77
 
79
- register_custom_status HostStatus::DlmlockStatus
78
+ register_custom_status HostStatus::DlmlockStatus
80
79
 
81
- # extend host show page
82
- extend_page('hosts/show') do |context|
83
- context.add_pagelet :main_tabs,
84
- :name => N_('Locks'),
85
- :partial => 'hosts/dlmlocks_tab',
86
- :onlyif => proc { |host| host.dlm_facet }
80
+ # extend host show page
81
+ extend_page('hosts/show') do |context|
82
+ context.add_pagelet :main_tabs,
83
+ :name => N_('Locks'),
84
+ :partial => 'hosts/dlmlocks_tab',
85
+ :onlyif => proc { |host| host.dlm_facet }
86
+ end
87
87
  end
88
88
  end
89
89
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanDlm
2
- VERSION = '2.0.0'.freeze
4
+ VERSION = '4.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
@@ -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
- assert_equal true, body['enabled']
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
- assert_equal false, body['enabled']
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
- 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
@@ -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
- 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
@@ -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
- 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
@@ -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
- 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
@@ -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
@@ -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,3 +1,5 @@
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}" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :dlmlock_event, class: ::ForemanDlm::DlmlockEvent do
3
5
  dlmlock
@@ -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
@@ -14,15 +14,21 @@ 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('#search-bar')
21
+ search_bar = page.first('.foreman-search-bar')
23
22
  search_bar.first('input').set('ho')
24
23
 
25
- list = search_bar.find_all('a.dropdown-item').map(&:text)
24
+ autocomplete_list = page.first('div[data-ouia-component-id="search-autocomplete-menu"]')
25
+ version = Foreman::Version.new
26
+ list = if version.major.to_i == 3 && version.minor.to_i <= 14
27
+ autocomplete_list.find_all('span.pf-c-menu__item-text').map(&:text)
28
+ else
29
+ autocomplete_list.find_all('span.pf-v5-c-menu__item-text').map(&:text)
30
+ end
31
+
26
32
  assert_includes list, 'host'
27
33
  end
28
34
  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
@@ -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
- assert_equal true, dlmlock.enabled?
49
- assert_equal false, dlmlock.disabled?
50
- assert_equal false, dlmlock.locked?
51
- assert_equal false, dlmlock.taken?
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
- assert_equal false, dlmlock.enabled?
104
- assert_equal true, dlmlock.disabled?
105
- assert_equal false, dlmlock.locked?
106
- assert_equal false, dlmlock.taken?
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
- assert_equal false, dlmlock.acquire!(host1)
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
- assert_equal false, dlmlock.release!(host1)
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
- assert_equal false, dlmlock.release!(host)
126
- assert_equal [], host.callbacks
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
- assert_equal true, dlmlock.enabled?
135
- assert_equal false, dlmlock.disabled?
136
- assert_equal true, dlmlock.locked?
137
- assert_equal true, dlmlock.taken?
138
- assert_equal true, dlmlock.locked_by?(host1)
139
- assert_equal true, dlmlock.acquired_by?(host1)
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
- assert_equal false, dlmlock.acquire!(host2)
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
- assert_equal false, dlmlock.release!(host2)
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
- assert_equal false, dlmlock.release!(host2_with_callbacks)
200
- assert_equal [], host1_with_callbacks.callbacks
201
- assert_equal [], host2_with_callbacks.callbacks
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
- assert_equal [], host1_with_callbacks.callbacks
210
+ assert_empty host1_with_callbacks.callbacks
209
211
  end
210
212
  end
211
213
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module Host
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostMonitoringTest < ActiveSupport::TestCase
@@ -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
- assert_equal true, status.relevant?
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
- assert_equal false, status.relevant?
42
+ assert_not status.relevant?
43
43
  end
44
44
  end
45
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class UserTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
 
@@ -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