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
@@ -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
@@ -82,27 +84,39 @@ module ForemanDlm
82
84
  assert dlmlock.acquire!(host)
83
85
  assert_equal ['callback1'], host.callbacks
84
86
  end
87
+
88
+ context 'with a parameter disabeling the locking' do
89
+ setup do
90
+ FactoryBot.create(:host_parameter, host: host1, name: 'can_acquire_update_locks', value: 'false')
91
+ end
92
+
93
+ test 'can not be acquired' do
94
+ assert_nil dlmlock.host
95
+ assert_not dlmlock.acquire!(host1)
96
+ assert_nil dlmlock.reload.host
97
+ end
98
+ end
85
99
  end
86
100
 
87
101
  context 'a free and disabled DLM lock' do
88
102
  let(:dlmlock) { FactoryBot.create(:dlmlock, :enabled => false) }
89
103
 
90
104
  test 'should be disabled and unlocked' do
91
- assert_equal false, dlmlock.enabled?
92
- assert_equal true, dlmlock.disabled?
93
- assert_equal false, dlmlock.locked?
94
- assert_equal false, dlmlock.taken?
105
+ assert_not dlmlock.enabled?
106
+ assert dlmlock.disabled?
107
+ assert_not dlmlock.locked?
108
+ assert_not dlmlock.taken?
95
109
  end
96
110
 
97
111
  test 'can not be acquired' do
98
112
  assert_nil dlmlock.host
99
- assert_equal false, dlmlock.acquire!(host1)
113
+ assert_not dlmlock.acquire!(host1)
100
114
  assert_nil dlmlock.reload.host
101
115
  end
102
116
 
103
117
  test 'can not be released' do
104
118
  assert_nil dlmlock.host
105
- assert_equal false, dlmlock.release!(host1)
119
+ assert_not dlmlock.release!(host1)
106
120
  assert_nil dlmlock.reload.host
107
121
  end
108
122
 
@@ -110,8 +124,8 @@ module ForemanDlm
110
124
  host = HostWithCallbacks.new
111
125
  host.name = 'test.example.com'
112
126
  host.save
113
- assert_equal false, dlmlock.release!(host)
114
- assert_equal [], host.callbacks
127
+ assert_not dlmlock.release!(host)
128
+ assert_empty host.callbacks
115
129
  end
116
130
  end
117
131
 
@@ -119,12 +133,12 @@ module ForemanDlm
119
133
  let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host1) }
120
134
 
121
135
  test 'should be enabled and locked' do
122
- assert_equal true, dlmlock.enabled?
123
- assert_equal false, dlmlock.disabled?
124
- assert_equal true, dlmlock.locked?
125
- assert_equal true, dlmlock.taken?
126
- assert_equal true, dlmlock.locked_by?(host1)
127
- 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)
128
142
  end
129
143
 
130
144
  test 'can be acquired by owner' do
@@ -135,7 +149,7 @@ module ForemanDlm
135
149
 
136
150
  test 'can not be acquired by other host' do
137
151
  assert_equal host1, dlmlock.host
138
- assert_equal false, dlmlock.acquire!(host2)
152
+ assert_not dlmlock.acquire!(host2)
139
153
  assert_equal host1, dlmlock.reload.host
140
154
  end
141
155
 
@@ -147,7 +161,7 @@ module ForemanDlm
147
161
 
148
162
  test 'can not be released by other host' do
149
163
  assert_equal host1, dlmlock.host
150
- assert_equal false, dlmlock.release!(host2)
164
+ assert_not dlmlock.release!(host2)
151
165
  assert_equal host1, dlmlock.reload.host
152
166
  end
153
167
 
@@ -184,16 +198,16 @@ module ForemanDlm
184
198
  assert host1_with_callbacks
185
199
  assert host2_with_callbacks
186
200
  dlmlock.update(:host => host1_with_callbacks)
187
- assert_equal false, dlmlock.release!(host2_with_callbacks)
188
- assert_equal [], host1_with_callbacks.callbacks
189
- 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
190
204
  end
191
205
 
192
206
  test 'triggers no callbacks on acquiry attempt by owner' do
193
207
  assert host1_with_callbacks
194
208
  dlmlock.update(:host => host1_with_callbacks)
195
209
  assert dlmlock.acquire!(host1_with_callbacks)
196
- assert_equal [], host1_with_callbacks.callbacks
210
+ assert_empty host1_with_callbacks.callbacks
197
211
  end
198
212
  end
199
213
 
@@ -212,15 +226,11 @@ module ForemanDlm
212
226
  not_locked = FactoryBot.create(:dlmlock)
213
227
 
214
228
  assert_includes subject, locked
215
- refute_includes subject, not_locked
229
+ assert_not_includes subject, not_locked
216
230
  end
217
231
  end
218
232
 
219
233
  describe '#stale' do
220
- setup do
221
- FactoryBot.create(:setting, category: Setting::General, name: 'dlm_stale_time', value: 4)
222
- end
223
-
224
234
  subject { Dlmlock.stale }
225
235
 
226
236
  it 'includes only Distributed Locks that are stale' do
@@ -232,8 +242,8 @@ module ForemanDlm
232
242
  not_locked = FactoryBot.create(:dlmlock)
233
243
 
234
244
  assert_includes subject, stale
235
- refute_includes subject, not_stale
236
- refute_includes subject, not_locked
245
+ assert_not_includes subject, not_stale
246
+ assert_not_includes subject, not_locked
237
247
  end
238
248
  end
239
249
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module Host
@@ -6,6 +8,24 @@ module Host
6
8
  should have_many(:dlmlock_events)
7
9
  should have_one(:dlm_facet)
8
10
 
11
+ describe '#can_acquire_update_locks?' do
12
+ let(:host) { FactoryBot.create(:host, :managed) }
13
+
14
+ it 'should be true without a host parameter' do
15
+ assert host.can_acquire_update_locks?
16
+ end
17
+
18
+ it 'should be true if parameter is true' do
19
+ FactoryBot.create(:host_parameter, host: host, name: 'can_acquire_update_locks', value: 'true')
20
+ assert host.can_acquire_update_locks?
21
+ end
22
+
23
+ it 'should be false if parameter is false' do
24
+ FactoryBot.create(:host_parameter, host: host, name: 'can_acquire_update_locks', value: 'false')
25
+ assert_not host.can_acquire_update_locks?
26
+ end
27
+ end
28
+
9
29
  context 'scoped search on' do
10
30
  context 'a host' do
11
31
  let(:host) { FactoryBot.create(:host, :with_dlm_facet) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostMonitoringTest < ActiveSupport::TestCase
@@ -3,10 +3,6 @@
3
3
  require 'test_plugin_helper'
4
4
 
5
5
  class DlmlockStatusTest < ActiveSupport::TestCase
6
- setup do
7
- FactoryBot.create(:setting, category: Setting::General, name: 'dlm_stale_time', value: 4)
8
- end
9
-
10
6
  let(:host) { FactoryBot.create(:host, :managed) }
11
7
 
12
8
  describe '#to_status' do
@@ -17,7 +13,7 @@ class DlmlockStatusTest < ActiveSupport::TestCase
17
13
  FactoryBot.create(:dlmlock, :locked, host: host, updated_at: now - 5.hours)
18
14
  status = host.get_status(HostStatus::DlmlockStatus)
19
15
 
20
- refute_empty host.dlmlocks.stale
16
+ assert_not_empty host.dlmlocks.stale
21
17
  assert_equal HostStatus::DlmlockStatus::STALE, status.to_status
22
18
  end
23
19
  end
@@ -35,15 +31,15 @@ class DlmlockStatusTest < ActiveSupport::TestCase
35
31
  FactoryBot.create(:dlmlock, host: host)
36
32
  status = host.get_status(HostStatus::DlmlockStatus)
37
33
 
38
- refute_empty host.dlmlocks
39
- assert_equal true, status.relevant?
34
+ assert_not_empty host.dlmlocks
35
+ assert status.relevant?
40
36
  end
41
37
 
42
38
  test 'should return false if host has no dlmlocks' do
43
39
  status = host.get_status(HostStatus::DlmlockStatus)
44
40
 
45
41
  assert_empty host.dlmlocks
46
- assert_equal false, status.relevant?
42
+ assert_not status.relevant?
47
43
  end
48
44
  end
49
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,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
 
4
6
  # Add plugin to FactoryBot's paths
5
7
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
8
+
9
+ # Add factories of external plugin dependencies
6
10
  FactoryBot.definition_file_paths << "#{ForemanMonitoring::Engine.root}/test/factories" if ForemanDlm.with_monitoring?
11
+
12
+ # Reload factory paths
7
13
  FactoryBot.reload
@@ -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: 1.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -25,19 +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: 0.52.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: 0.52.1
40
+ version: 0.1.2
41
41
  description: Adds a Distributed Lock Manager to Foreman. This enables painless system
42
42
  updates for clusters.
43
43
  email:
@@ -69,7 +69,6 @@ files:
69
69
  - app/models/foreman_dlm/dlmlock/update.rb
70
70
  - app/models/foreman_dlm/dlmlock_event.rb
71
71
  - app/models/host_status/dlmlock_status.rb
72
- - app/models/settings/dlm.rb
73
72
  - app/views/api/v2/dlmlock_events/index.json.rabl
74
73
  - app/views/api/v2/dlmlocks/acquire.json.rabl
75
74
  - app/views/api/v2/dlmlocks/base.json.rabl
@@ -117,6 +116,7 @@ files:
117
116
  - test/factories/dlmlock.rb
118
117
  - test/factories/dlmlock_events.rb
119
118
  - test/factories/host.rb
119
+ - test/integration/foreman_dlm/dlmlocks_test.rb
120
120
  - test/jobs/refresh_dlmlock_status_test.rb
121
121
  - test/models/foreman_dlm/dlm_facet_test.rb
122
122
  - test/models/foreman_dlm/dlmlock_event_test.rb
@@ -126,11 +126,14 @@ files:
126
126
  - test/models/host_status/dlmlock_status_test.rb
127
127
  - test/models/user_test.rb
128
128
  - test/test_plugin_helper.rb
129
+ - test/unit/foreman_dlm/access_permissions_test.rb
129
130
  homepage: https://github.com/dm-drogeriemarkt/foreman_dlm
130
131
  licenses:
131
132
  - GPL-3.0
132
- metadata: {}
133
- post_install_message:
133
+ metadata:
134
+ rubygems_mfa_required: 'true'
135
+ is_foreman_plugin: 'true'
136
+ post_install_message:
134
137
  rdoc_options: []
135
138
  require_paths:
136
139
  - lib
@@ -138,35 +141,39 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
141
  requirements:
139
142
  - - ">="
140
143
  - !ruby/object:Gem::Version
141
- version: '0'
144
+ version: '2.5'
145
+ - - "<"
146
+ - !ruby/object:Gem::Version
147
+ version: '4'
142
148
  required_rubygems_version: !ruby/object:Gem::Requirement
143
149
  requirements:
144
150
  - - ">="
145
151
  - !ruby/object:Gem::Version
146
152
  version: '0'
147
153
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.3
150
- signing_key:
154
+ rubygems_version: 3.4.1
155
+ signing_key:
151
156
  specification_version: 4
152
157
  summary: Distributed Lock Manager for Foreman.
153
158
  test_files:
154
- - test/models/host_managed_test.rb
155
- - test/models/foreman_dlm/dlmlock_event_test.rb
159
+ - test/controllers/api/v2/dlmlocks_controller_test.rb
160
+ - test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb
161
+ - test/controllers/api/v2/hosts_controller_test.rb
162
+ - test/controllers/find_host_by_client_cert_test.rb
163
+ - test/controllers/foreman_dlm/dlmlocks_test.rb
164
+ - test/controllers/hosts_controller_test.rb
165
+ - test/factories/dlm_facets.rb
166
+ - test/factories/dlmlock.rb
167
+ - test/factories/dlmlock_events.rb
168
+ - test/factories/host.rb
169
+ - test/integration/foreman_dlm/dlmlocks_test.rb
170
+ - test/jobs/refresh_dlmlock_status_test.rb
156
171
  - test/models/foreman_dlm/dlm_facet_test.rb
172
+ - test/models/foreman_dlm/dlmlock_event_test.rb
157
173
  - test/models/foreman_dlm/dlmlock_test.rb
158
- - test/models/host_status/dlmlock_status_test.rb
174
+ - test/models/host_managed_test.rb
159
175
  - test/models/host_monitoring_test.rb
176
+ - test/models/host_status/dlmlock_status_test.rb
160
177
  - test/models/user_test.rb
161
- - test/factories/dlm_facets.rb
162
- - test/factories/host.rb
163
- - test/factories/dlmlock_events.rb
164
- - test/factories/dlmlock.rb
165
178
  - test/test_plugin_helper.rb
166
- - test/jobs/refresh_dlmlock_status_test.rb
167
- - test/controllers/foreman_dlm/dlmlocks_test.rb
168
- - test/controllers/api/v2/dlmlocks_controller_test.rb
169
- - test/controllers/api/v2/hosts_controller_test.rb
170
- - test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb
171
- - test/controllers/hosts_controller_test.rb
172
- - test/controllers/find_host_by_client_cert_test.rb
179
+ - test/unit/foreman_dlm/access_permissions_test.rb
@@ -1,20 +0,0 @@
1
- class Setting
2
- class Dlm < ::Setting
3
- def self.load_defaults
4
- return unless ActiveRecord::Base.connection.table_exists?('settings')
5
- return unless super
6
-
7
- Setting.transaction do
8
- [
9
- set('dlm_stale_time', N_('Number of hours after which locked Distributed Lock is stale'), 4, N_('Distributed Lock stale time'))
10
- ].compact.each { |s| Setting::General.create s.update(category: 'Setting::General') }
11
- end
12
-
13
- true
14
- end
15
-
16
- def self.humanized_category
17
- N_('Distributed Locks')
18
- end
19
- end
20
- end