foreman_wreckingball 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/app/assets/javascripts/foreman_wreckingball/modal.js +0 -1
  4. data/app/assets/javascripts/foreman_wreckingball/status_hosts_table.js +2 -2
  5. data/app/assets/javascripts/foreman_wreckingball/status_row.js +17 -0
  6. data/app/controllers/foreman_wreckingball/hosts_controller.rb +65 -35
  7. data/app/lib/actions/foreman_wreckingball/host/remediate_spectre_v2.rb +58 -0
  8. data/app/models/concerns/foreman_wreckingball/host_extensions.rb +10 -25
  9. data/app/models/concerns/foreman_wreckingball/host_status_extensions.rb +13 -0
  10. data/app/models/concerns/foreman_wreckingball/user_extensions.rb +12 -0
  11. data/app/models/concerns/foreman_wreckingball/usergroup_extensions.rb +18 -0
  12. data/app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb +10 -0
  13. data/app/models/foreman_wreckingball/cpu_hot_add_status.rb +8 -0
  14. data/app/models/foreman_wreckingball/hardware_version_status.rb +8 -0
  15. data/app/models/foreman_wreckingball/operatingsystem_status.rb +8 -0
  16. data/app/models/foreman_wreckingball/spectre_v2_status.rb +17 -1
  17. data/app/models/foreman_wreckingball/tools_status.rb +8 -0
  18. data/app/models/foreman_wreckingball/vmware_facet.rb +1 -5
  19. data/app/services/foreman_wreckingball/vmware_cluster_importer.rb +1 -6
  20. data/app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb +10 -21
  21. data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb +1 -1
  22. data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +1 -0
  23. data/app/views/foreman_wreckingball/hosts/status_managed_hosts_dashboard.html.erb +49 -0
  24. data/config/environments/production.rb +7 -0
  25. data/config/routes.rb +1 -0
  26. data/lib/foreman_wreckingball/engine.rb +21 -6
  27. data/lib/foreman_wreckingball/version.rb +1 -1
  28. data/test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb +62 -0
  29. data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +180 -12
  30. data/test/factories/foreman_wreckingball_factories.rb +32 -0
  31. data/test/factories/host.rb +8 -0
  32. data/test/factories/task.rb +17 -0
  33. data/test/integration/hosts_status_dashboard_test.rb +50 -0
  34. data/test/integration/hosts_status_managed_hosts_test.rb +93 -0
  35. data/test/integration_test_plugin_helper.rb +12 -0
  36. data/test/models/host_status_test.rb +22 -0
  37. data/test/models/host_test.rb +64 -5
  38. data/test/models/usergroup_test.rb +25 -0
  39. data/test/test_plugin_helper.rb +17 -0
  40. data/test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb +17 -2
  41. metadata +23 -2
@@ -6,9 +6,68 @@ class Host::ManagedTest < ActiveSupport::TestCase
6
6
  should have_one(:vmware_facet)
7
7
  should have_one(:vmware_cluster)
8
8
  should have_one(:vmware_hypervisor_facet)
9
- should have_one(:vmware_tools_status_object)
10
- should have_one(:vmware_operatingsystem_status_object)
11
- should have_one(:vmware_cpu_hot_add_status_object)
12
- should have_one(:vmware_spectre_v2_status_object)
13
- should have_one(:vmware_hardware_version_status_object)
9
+
10
+ HostStatus.wreckingball_statuses.each do |status|
11
+ should have_one(status.host_association)
12
+ end
13
+
14
+ describe '#owned_by_current_user_or_group_with_current_user' do
15
+ test 'returns only hosts owned by current user' do
16
+ usergroup_with_user = FactoryBot.create(:usergroup, users: [User.current], usergroups: [FactoryBot.create(:usergroup, users: [])])
17
+
18
+ FactoryBot.create :host, :managed, owner: FactoryBot.create(:user)
19
+ FactoryBot.create :host, :managed, owner: FactoryBot.create(:usergroup, users: [])
20
+ FactoryBot.create :host, :managed, owner: usergroup_with_user.usergroups.first
21
+
22
+ expected = [
23
+ FactoryBot.create(:host, :managed, owner: User.current),
24
+ FactoryBot.create(:host, :managed, owner: usergroup_with_user),
25
+ FactoryBot.create(:host, :managed, owner: FactoryBot.create(:usergroup, usergroups: [usergroup_with_user]))
26
+ ]
27
+ actual = Host::Managed.owned_by_current_user_or_group_with_current_user
28
+
29
+ assert_equal expected, actual
30
+ end
31
+ end
32
+
33
+ context 'scoped search' do
34
+ setup do
35
+ @host = FactoryBot.create(:host, :with_vmware_facet)
36
+ end
37
+
38
+ test 'search by hardware_version' do
39
+ hosts = Host.search_for('vsphere_hardware_version = vmx-10')
40
+ assert_includes hosts, @host
41
+ end
42
+
43
+ test 'search by power_state' do
44
+ hosts = Host.search_for('vsphere_power_state = poweredOn')
45
+ assert_includes hosts, @host
46
+ end
47
+
48
+ test 'search by tools_state' do
49
+ hosts = Host.search_for('vsphere_tools_state = toolsOk')
50
+ assert_includes hosts, @host
51
+ end
52
+
53
+ test 'search by guest_id' do
54
+ hosts = Host.search_for('vsphere_guest_id = rhel6_64Guest')
55
+ assert_includes hosts, @host
56
+ end
57
+
58
+ test 'search by cpus' do
59
+ hosts = Host.search_for('vsphere_cpus = 2')
60
+ assert_includes hosts, @host
61
+ end
62
+
63
+ test 'search by corespersocket' do
64
+ hosts = Host.search_for('vsphere_corespersocket = 1')
65
+ assert_includes hosts, @host
66
+ end
67
+
68
+ test 'search by memory_mb' do
69
+ hosts = Host.search_for('vsphere_memory_mb = 8192')
70
+ assert_includes hosts, @host
71
+ end
72
+ end
14
73
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ class UsergroupTest < ActiveSupport::TestCase
6
+ describe '#parent_usergroup_ids' do
7
+ it 'returns the ids of all parents of a usergroup' do
8
+ child = FactoryBot.create(:usergroup)
9
+
10
+ subject = FactoryBot.create(:usergroup, usergroups: [child])
11
+
12
+ parent1 = FactoryBot.create(:usergroup, usergroups: [subject])
13
+ parent2 = FactoryBot.create(:usergroup, usergroups: [parent1])
14
+ parent3 = FactoryBot.create(:usergroup, usergroups: [parent1])
15
+
16
+ assert_equal subject.parent_usergroup_ids, [parent1, parent2, parent3].map(&:id)
17
+ end
18
+
19
+ it 'returns empty array if usergroup has no parents' do
20
+ subject = FactoryBot.create(:usergroup)
21
+
22
+ assert_equal subject.parent_usergroup_ids, []
23
+ end
24
+ end
25
+ end
@@ -2,8 +2,25 @@
2
2
 
3
3
  # This calls the main test_helper in Foreman-core
4
4
  require 'test_helper'
5
+ require 'database_cleaner'
5
6
  require 'dynflow/testing'
6
7
 
7
8
  # Add plugin to FactoryBot's paths
9
+ FactoryBot.definition_file_paths << File.join(ForemanTasks::Engine.root, 'test', 'factories')
8
10
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
9
11
  FactoryBot.reload
12
+
13
+ # Foreman's setup doesn't handle cleaning in plugin
14
+ DatabaseCleaner.strategy = :transaction
15
+
16
+ module Minitest
17
+ class Spec
18
+ before :each do
19
+ DatabaseCleaner.start
20
+ end
21
+
22
+ after :each do
23
+ DatabaseCleaner.clean
24
+ end
25
+ end
26
+ end
@@ -26,10 +26,25 @@ module ForemanWreckingball
26
26
  assert_includes clusters, 'Nested/Lastcluster'
27
27
  end
28
28
 
29
- test 'removes old clusters' do
30
- old_cluster = FactoryBot.create(:vmware_cluster, compute_resource: compute_resource)
29
+ test 'removes old clusters without associated records' do
30
+ old_cluster = FactoryBot.create(:vmware_cluster,
31
+ :with_hosts,
32
+ :with_vmware_facets,
33
+ :with_vmware_hypervisor_facets,
34
+ compute_resource: compute_resource)
35
+
36
+ compute_resource_id = old_cluster.compute_resource.id
37
+ host_ids = old_cluster.hosts.pluck(:id)
38
+ vmware_facet_ids = old_cluster.vmware_facets.pluck(:id)
39
+ vmware_hypervisor_facet_ids = old_cluster.vmware_hypervisor_facets.pluck(:id)
40
+
31
41
  importer.import!
32
42
  refute ForemanWreckingball::VmwareCluster.find_by(id: old_cluster.id)
43
+
44
+ assert Foreman::Model::Vmware.find_by(id: compute_resource_id)
45
+ assert_equal host_ids.count, Host.where(id: host_ids).count
46
+ assert_equal vmware_facet_ids.count, ForemanWreckingball::VmwareFacet.where(id: vmware_facet_ids).count
47
+ assert_equal vmware_hypervisor_facet_ids.count, ForemanWreckingball::VmwareHypervisorFacet.where(id: vmware_hypervisor_facet_ids).count
33
48
  end
34
49
 
35
50
  test 'can be run twice without a change' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_wreckingball
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.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: 2018-11-15 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks
@@ -64,6 +64,7 @@ files:
64
64
  - Rakefile
65
65
  - app/assets/javascripts/foreman_wreckingball/modal.js
66
66
  - app/assets/javascripts/foreman_wreckingball/status_hosts_table.js
67
+ - app/assets/javascripts/foreman_wreckingball/status_row.js
67
68
  - app/assets/stylesheets/foreman_wreckingball/status_hosts_table.css.scss
68
69
  - app/controllers/foreman_wreckingball/hosts_controller.rb
69
70
  - app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb
@@ -71,6 +72,7 @@ files:
71
72
  - app/jobs/update_hosts_vmware_facets.rb
72
73
  - app/lib/actions/foreman_wreckingball/host/refresh_vmware_facet.rb
73
74
  - app/lib/actions/foreman_wreckingball/host/remediate_hardware_version.rb
75
+ - app/lib/actions/foreman_wreckingball/host/remediate_spectre_v2.rb
74
76
  - app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb
75
77
  - app/lib/actions/foreman_wreckingball/vmware/schedule_vmware_sync.rb
76
78
  - app/lib/actions/foreman_wreckingball/vmware/sync_compute_resource.rb
@@ -83,6 +85,9 @@ files:
83
85
  - app/lib/vsphere_os_identifiers/os.rb
84
86
  - app/models/concerns/foreman_wreckingball/compute_resource_extensions.rb
85
87
  - app/models/concerns/foreman_wreckingball/host_extensions.rb
88
+ - app/models/concerns/foreman_wreckingball/host_status_extensions.rb
89
+ - app/models/concerns/foreman_wreckingball/user_extensions.rb
90
+ - app/models/concerns/foreman_wreckingball/usergroup_extensions.rb
86
91
  - app/models/concerns/foreman_wreckingball/vmware_extensions.rb
87
92
  - app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb
88
93
  - app/models/concerns/foreman_wreckingball/vmware_hypervisor_facet_host_extensions.rb
@@ -106,6 +111,8 @@ files:
106
111
  - app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb
107
112
  - app/views/foreman_wreckingball/hosts/status_dashboard.html.erb
108
113
  - app/views/foreman_wreckingball/hosts/status_hosts.json.rabl
114
+ - app/views/foreman_wreckingball/hosts/status_managed_hosts_dashboard.html.erb
115
+ - config/environments/production.rb
109
116
  - config/routes.rb
110
117
  - db/migrate/20171106155000_create_vmware_facets.rb
111
118
  - db/migrate/20180504135345_add_cpu_features_to_vmware_facets.rb
@@ -124,6 +131,7 @@ files:
124
131
  - locale/gemspec.rb
125
132
  - test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb
126
133
  - test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb
134
+ - test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb
127
135
  - test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb
128
136
  - test/actions/foreman_wreckingball/vmware/schedule_vmware_sync_test.rb
129
137
  - test/actions/foreman_wreckingball/vmware/sync_compute_resource_test.rb
@@ -132,6 +140,10 @@ files:
132
140
  - test/factories/compute_resource.rb
133
141
  - test/factories/foreman_wreckingball_factories.rb
134
142
  - test/factories/host.rb
143
+ - test/factories/task.rb
144
+ - test/integration/hosts_status_dashboard_test.rb
145
+ - test/integration/hosts_status_managed_hosts_test.rb
146
+ - test/integration_test_plugin_helper.rb
135
147
  - test/models/compute_resource_test.rb
136
148
  - test/models/compute_resources/vmware_test.rb
137
149
  - test/models/foreman_wreckingball/cpu_hot_add_status_test.rb
@@ -142,7 +154,9 @@ files:
142
154
  - test/models/foreman_wreckingball/vmware_cluster_test.rb
143
155
  - test/models/foreman_wreckingball/vmware_facet_test.rb
144
156
  - test/models/foreman_wreckingball/vmware_hypervisor_facet_test.rb
157
+ - test/models/host_status_test.rb
145
158
  - test/models/host_test.rb
159
+ - test/models/usergroup_test.rb
146
160
  - test/test_plugin_helper.rb
147
161
  - test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb
148
162
  - test/unit/foreman_wreckingball/vmware_hypervisor_importer_test.rb
@@ -173,8 +187,11 @@ summary: Adds status checks of the VMWare VMs to Foreman.
173
187
  test_files:
174
188
  - test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb
175
189
  - test/unit/foreman_wreckingball/vmware_hypervisor_importer_test.rb
190
+ - test/integration/hosts_status_dashboard_test.rb
191
+ - test/integration/hosts_status_managed_hosts_test.rb
176
192
  - test/models/compute_resource_test.rb
177
193
  - test/models/host_test.rb
194
+ - test/models/usergroup_test.rb
178
195
  - test/models/foreman_wreckingball/operatingsystem_status_test.rb
179
196
  - test/models/foreman_wreckingball/spectre_v2_status_test.rb
180
197
  - test/models/foreman_wreckingball/vmware_hypervisor_facet_test.rb
@@ -183,15 +200,19 @@ test_files:
183
200
  - test/models/foreman_wreckingball/vmware_cluster_test.rb
184
201
  - test/models/foreman_wreckingball/vmware_facet_test.rb
185
202
  - test/models/foreman_wreckingball/tools_status_test.rb
203
+ - test/models/host_status_test.rb
186
204
  - test/models/compute_resources/vmware_test.rb
187
205
  - test/factories/compute_resource.rb
188
206
  - test/factories/host.rb
189
207
  - test/factories/foreman_wreckingball_factories.rb
208
+ - test/factories/task.rb
190
209
  - test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb
191
210
  - test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb
192
211
  - test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb
212
+ - test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb
193
213
  - test/actions/foreman_wreckingball/vmware/sync_compute_resource_test.rb
194
214
  - test/actions/foreman_wreckingball/vmware/schedule_vmware_sync_test.rb
195
215
  - test/test_plugin_helper.rb
196
216
  - test/controllers/compute_resources_controller_test.rb
197
217
  - test/controllers/foreman_wreckingball/hosts_controller_test.rb
218
+ - test/integration_test_plugin_helper.rb