foreman_wreckingball 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5038fc9d12985cb5fb7ee83a5dc72567d63a04fc11ff5d8d17c09d4cc59ea6b9
4
- data.tar.gz: 1579d2bb8bb7c35188b76861b84611a190103fdef76f3135f2b3776d86a34003
3
+ metadata.gz: 6f9adf6349a9a378c18d5be9f632245d0861f63b53ba5ce89b1d72849e0e8c0a
4
+ data.tar.gz: '09d87212258ae239f338beed765cf7f9685505e446b458c030e49b33cfc11f27'
5
5
  SHA512:
6
- metadata.gz: ca6aefe61f1d908461e3f527b8384046923cbe3ecc20864165394532b4735587d1bab362836d2ae044c1c3b1a4d4e48e433bbeec34c7beaba18d20c62cc9f4bf
7
- data.tar.gz: cfe558ecd67daf5a1b76943396df76626461023f80bae31662aad1cdbc6e4786206ee0307879b5e4d4725b9ecf75fa8a963bbf1f0f98dd7995e3bbe29330a653
6
+ metadata.gz: ad1fd61579be1231af29fd18b660e7b8185923f21cef0fad379bede4464eef6fc3cffb1b36da738bf3323918838a97003221a1a23500328ef2f6db9cdf690dc6
7
+ data.tar.gz: 2a2afce44f557b74509e3b9833f8ca8b3c95564146e2d16f8c733f0ea62ccc15bcc902da4a510f0b18d7fe76e22617c963aacbf4d073a9af66fa9c647c9bace6
@@ -1,8 +1,14 @@
1
1
  $(document).ready(() => {
2
- $('table#missing_vms').add('table#duplicate_vms').add('table#different_vms')
2
+ $('table#missing_vms').add('table#wrong_hosts').add('table#more_than_one_hosts')
3
3
  .DataTable({
4
4
  bLengthChange: true,
5
5
  lengthMenu: [20, 50, 100],
6
- order: [[ 0, 'desc' ]]
6
+ order: [[ 0, 'desc' ]],
7
+ columnDefs: [
8
+ {
9
+ 'targets': 'no-sort',
10
+ 'orderable': false,
11
+ }
12
+ ]
7
13
  });
8
14
  });
@@ -42,35 +42,48 @@ module ForemanWreckingball
42
42
  end
43
43
 
44
44
  def status_managed_hosts_dashboard
45
+ vmware_compute_resources = Foreman::Model::Vmware.unscoped.all
46
+
45
47
  # NOTE The call to ComputeResource#vms may slow things down
46
- vms_by_compute_resource_id = Foreman::Model::Vmware.all.each_with_object({}) do |cr, memo|
47
- memo[cr.id] = cr.vms(eager_loading: true)
48
+ vms_by_compute_resource_id = vmware_compute_resources.each_with_object({}) do |cr, memo|
49
+ memo[cr.id] = cr.vms.all
48
50
  end
49
51
 
50
- # Find all hosts with duplicate VMs
51
- @duplicate_vms = vms_by_compute_resource_id.values
52
- .flatten
53
- .group_by(&:uuid)
54
- .select { |_uuid, vms| vms.size > 1 }
52
+ # Get all VM UUIDs found in any of the compute resources
53
+ all_vm_uuids = vms_by_compute_resource_id.values.flatten.group_by(&:id).keys
54
+
55
+ # Map all VM UUIDs to all compute resources that have access to this VM
56
+ @vm_compute_resource_mapping = all_vm_uuids.each_with_object({}) do |uuid, obj|
57
+ cr_ids = vms_by_compute_resource_id.select { |_cr_id, vms| vms.find { |vm| vm.id == uuid } }.keys
58
+ obj[uuid] = vmware_compute_resources.select { |cr| cr_ids.include?(cr.id) }
59
+ end
55
60
 
56
61
  @missing_hosts = []
57
- @different_hosts = []
62
+ @wrong_hosts = []
63
+ @more_than_one_hosts = []
58
64
 
59
65
  Host::Managed.authorized(:view_hosts, Host)
60
- .where.not(compute_resource_id: nil)
66
+ .includes(:compute_resource)
67
+ .where(compute_resource: vmware_compute_resources)
61
68
  .try { |query| params[:owned_only] ? query.owned_by_current_user_or_group_with_current_user : query }
62
69
  .each do |host|
63
- # find the compute resource id of the host in the vm map
64
- cr_id, _vms = vms_by_compute_resource_id.find { |_cr_id, vms| vms.find { |vm| vm.uuid == host.uuid } }
65
70
 
66
- if cr_id.nil?
67
- # No compute resource id is found, vSphere does not have the vm uuid
71
+ compute_resources = @vm_compute_resource_mapping[host.uuid]
72
+
73
+ if compute_resources.empty?
74
+ # VM is not found on any compute resource, vSphere does not have the vm uuid
68
75
  @missing_hosts << host
69
- elsif cr_id != host.compute_resource_id
70
- # The host uuid is found in a different compute resource
71
- @different_hosts << host
76
+ elsif compute_resources.count > 1
77
+ # The vm uuid is found on more than one compute resource
78
+ @more_than_one_hosts << host
79
+ elsif host.compute_resource_id != compute_resources.first.id
80
+ # The host is associated to a wrong compute resource
81
+ @wrong_hosts << host
72
82
  end
73
83
  end
84
+
85
+ @compute_resource_authorizer = Authorizer.new(User.current, collection: vmware_compute_resources)
86
+ @host_authorizer = Authorizer.new(User.current)
74
87
  end
75
88
 
76
89
  # ajax method
@@ -1,16 +1,16 @@
1
1
  <div class='status-managed-hosts-dashboard-cards container-fluid container-cards-pf'>
2
2
  <div class='row row-cards-pf'>
3
3
  <%= render partial: 'status_managed_hosts_dashboard_cards_card', locals: {
4
- title: _('List of Hosts not found in vSphere'),
4
+ title: _('Hosts not found in vSphere'),
5
5
  count: missing_hosts_count
6
6
  } %>
7
7
  <%= render partial: 'status_managed_hosts_dashboard_cards_card', locals: {
8
- title: _('List of VMs with same uuid'),
9
- count: duplicate_vms_count
8
+ title: _('Hosts associated to wrong Compute Resource'),
9
+ count: wrong_hosts_count
10
10
  } %>
11
11
  <%= render partial: 'status_managed_hosts_dashboard_cards_card', locals: {
12
- title: _('List of VMs associated with different compute resources'),
13
- count: different_hosts_count
12
+ title: _('Hosts found on more than one Compute Resource'),
13
+ count: more_than_one_hosts_count
14
14
  } %>
15
15
  </div>
16
16
  </div>
@@ -14,8 +14,8 @@
14
14
 
15
15
  <%= render partial: 'status_managed_hosts_dashboard_cards', locals: {
16
16
  missing_hosts_count: @missing_hosts.count,
17
- duplicate_vms_count: @duplicate_vms.map(&:second).flatten.count,
18
- different_hosts_count: @different_hosts.count
17
+ wrong_hosts_count: @wrong_hosts.count,
18
+ more_than_one_hosts_count: @more_than_one_hosts.count
19
19
  } %>
20
20
 
21
21
  <ul class='nav nav-tabs' data-tabs='tabs'>
@@ -23,74 +23,101 @@
23
23
  <%= content_tag :a, _('List of Hosts not found in vSphere'), href: '#missing_vms_tab', 'data-toggle': 'tab' %>
24
24
  </li>
25
25
  <li>
26
- <%= content_tag :a, _('List of VMs with same uuid'), href: '#duplicate_vms_tab', 'data-toggle': 'tab' %>
26
+ <%= content_tag :a, _('List of Hosts associated to wrong Compute Resource'), href: '#wrong_hosts_tab', 'data-toggle': 'tab' %>
27
27
  </li>
28
28
  <li>
29
- <%= content_tag :a, _('List of VMs associated with different Compute Resources'), href: '#different_vms_tab', 'data-toggle': 'tab' %>
29
+ <%= content_tag :a, _('List of Hosts found on more than one Compute Resource'), href: '#more_than_one_hosts_tab', 'data-toggle': 'tab' %>
30
30
  </li>
31
31
  </ul>
32
32
 
33
33
  <div class='tab-content'>
34
34
  <div class='tab-pane active' id='missing_vms_tab'>
35
35
  <% if @missing_hosts.empty? %>
36
- <%= content_tag :p, _('No hosts to show'), class: 'ca' %>
36
+ <%= content_tag :p, _('No Hosts to show'), class: 'ca' %>
37
37
  <% else %>
38
38
  <%= content_tag :table, id: 'missing_vms', class: table_css_classes do %>
39
39
  <thead>
40
40
  <tr>
41
41
  <%= content_tag :th, _('Name') %>
42
+ <%= content_tag :th, nil, class: 'no-sort' %>
42
43
  </tr>
43
44
  </thead>
44
45
  <tbody>
45
46
  <% @missing_hosts.each do |host| %>
46
47
  <tr>
47
- <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host)) %>
48
+ <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host).merge(permission: 'view_hosts', auth_object: host, authorizer: @host_authorizer)) %>
49
+ <td>
50
+ <%= action_buttons(display_delete_if_authorized(hash_for_host_path(id: host).merge(permission: 'destroy_hosts', auth_object: host, authorizer: @host_authorizer),
51
+ :data => { :confirm => _('Are you sure you want to delete host %s? This action is irreversible.') % host.name })) %>
52
+ </td>
48
53
  </tr>
49
54
  <% end %>
50
55
  </tbody>
51
56
  <% end %>
52
57
  <% end %>
53
58
  </div>
54
- <div class='tab-pane' id='duplicate_vms_tab'>
55
- <% if @duplicate_vms.empty? %>
56
- <%= content_tag :p, _('No hosts to show'), class: 'ca' %>
59
+ <div class='tab-pane' id='wrong_hosts_tab'>
60
+ <% if @wrong_hosts.empty? %>
61
+ <%= content_tag :p, _('No Hosts to show'), class: 'ca' %>
57
62
  <% else %>
58
- <%= content_tag :table, id: 'duplicate_vms', class: table_css_classes do %>
63
+ <%= content_tag :table, id: 'wrong_hosts', class: table_css_classes do %>
59
64
  <thead>
60
65
  <tr>
61
- <%= content_tag :th, _('UUID') %>
62
66
  <%= content_tag :th, _('Name') %>
67
+ <%= content_tag :th, _('Associated to') %>
68
+ <%= content_tag :th, _('Found on') %>
69
+ <%= content_tag :th, nil, class: 'no-sort' %>
63
70
  </tr>
64
71
  </thead>
65
72
  <tbody>
66
- <% @duplicate_vms.each do |_uuid, hosts| %>
67
- <% hosts.each do |host| %>
68
- <tr>
69
- <%= content_tag :td, host.uuid %>
70
- <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host)) %>
71
- </tr>
72
- <% end %>
73
+ <% @wrong_hosts.each do |host| %>
74
+ <tr>
75
+ <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host).merge(permission: 'view_hosts', auth_object: host, authorizer: @host_authorizer)) %>
76
+ <%= content_tag :td, link_to_if_authorized(host.compute_resource.name, hash_for_compute_resource_path(id: host.compute_resource).merge(permission: 'view_compute_resources', auth_object: host.compute_resource, authorizer: @compute_resource_authorizer)) %>
77
+ <%= content_tag :td, link_to_if_authorized(@vm_compute_resource_mapping[host.uuid].first.name, hash_for_compute_resource_path(id: @vm_compute_resource_mapping[host.uuid].first).merge(permission: 'view_compute_resources', auth_object: @vm_compute_resource_mapping[host.uuid].first, authorizer: @compute_resource_authorizer)) %>
78
+ <td>
79
+ <%= action_buttons(
80
+ display_link_if_authorized(
81
+ _('Fix Association'),
82
+ hash_for_associate_compute_resource_vm_path(
83
+ compute_resource_id: @vm_compute_resource_mapping[host.uuid].first,
84
+ id: host.uuid
85
+ ).merge(
86
+ auth_object: @vm_compute_resource_mapping[host.uuid].first,
87
+ authorizer: @compute_resource_authorizer,
88
+ permission: 'edit_compute_resources'
89
+ ),
90
+ title: _('Associate Host to correct Compute Resouce'),
91
+ method: :put
92
+ )
93
+ ) %>
94
+ </td>
95
+ </tr>
73
96
  <% end %>
74
97
  </tbody>
75
98
  <% end %>
76
99
  <% end %>
77
100
  </div>
78
- <div class='tab-pane' id='different_vms_tab'>
79
- <% if @different_hosts.empty? %>
80
- <%= content_tag :p, _('No hosts to show'), class: 'ca' %>
101
+ <div class='tab-pane' id='more_than_one_hosts_tab'>
102
+ <% if @more_than_one_hosts.empty? %>
103
+ <%= content_tag :p, _('No Hosts to show'), class: 'ca' %>
81
104
  <% else %>
82
- <%= content_tag :table, id: 'different_vms', class: table_css_classes do %>
105
+ <%= content_tag :table, id: 'more_than_one_hosts', class: table_css_classes do %>
83
106
  <thead>
84
107
  <tr>
85
- <%= content_tag :th, _('UUID') %>
86
108
  <%= content_tag :th, _('Name') %>
109
+ <%= content_tag :th, _('Associated to') %>
110
+ <%= content_tag :th, _('Found on') %>
87
111
  </tr>
88
112
  </thead>
89
113
  <tbody>
90
- <% @different_hosts.each do |host| %>
114
+ <% @more_than_one_hosts.each do |host| %>
91
115
  <tr>
92
- <%= content_tag :td, host.uuid %>
93
- <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host)) %>
116
+ <%= content_tag :td, link_to_if_authorized(host.name, hash_for_host_path(id: host).merge(permission: 'view_hosts', auth_object: host, authorizer: authorizer)) %>
117
+ <%= content_tag :td, (link_to_if_authorized(host.compute_resource.name, hash_for_compute_resource_path(id: host.compute_resource).merge(permission: 'view_compute_resources', auth_object: host.compute_resource, authorizer: @compute_resource_authorizer)) if host.compute_resource) %>
118
+ <td>
119
+ <%= safe_join(@vm_compute_resource_mapping[host.uuid].map { |compute_resource| link_to_if_authorized(compute_resource.name, hash_for_compute_resource_path(id: compute_resource).merge(permission: 'view_compute_resources', auth_object: compute_resource, authorizer: @compute_resource_authorizer))}, ', ') %>
120
+ </td>
94
121
  </tr>
95
122
  <% end %>
96
123
  </tbody>
@@ -110,10 +110,10 @@ module ForemanWreckingball
110
110
  ::Usergroup.send(:include, ForemanWreckingball::UsergroupExtensions)
111
111
 
112
112
  if ForemanWreckingball.fog_patches_required?
113
- Fog::Compute::Vsphere::Host.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Host)
114
- Fog::Compute::Vsphere::Server.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Server)
115
- Fog::Compute::Vsphere::Real.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Real)
116
- Fog::Compute::Vsphere::Mock.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Mock)
113
+ ForemanWreckingball.fog_vsphere_namespace::Host.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Host)
114
+ ForemanWreckingball.fog_vsphere_namespace::Server.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Server)
115
+ ForemanWreckingball.fog_vsphere_namespace::Real.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Real)
116
+ ForemanWreckingball.fog_vsphere_namespace::Mock.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Mock)
117
117
  end
118
118
  rescue StandardError => e
119
119
  Rails.logger.warn "ForemanWreckingball: skipping engine hook (#{e})\n#{e.backtrace.join("\n")}"
@@ -138,4 +138,13 @@ module ForemanWreckingball
138
138
  rescue LoadError
139
139
  false
140
140
  end
141
+
142
+ def self.fog_vsphere_namespace
143
+ require 'fog/vsphere/version'
144
+ @fog_vsphere_namespace ||= if Gem::Version.new(Fog::Vsphere::VERSION) >= Gem::Version.new('3.0.0')
145
+ Fog::Vsphere::Compute
146
+ else
147
+ Fog::Compute::Vsphere
148
+ end
149
+ end
141
150
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanWreckingball
4
- VERSION = '3.3.0'
4
+ VERSION = '3.4.0'
5
5
  end
@@ -13,11 +13,11 @@ module Actions
13
13
 
14
14
  setup do
15
15
  ::Fog.mock!
16
- ::Fog::Compute::Vsphere::Mock.any_instance.stubs(:get_vm_ref).returns(vm)
17
- ::Fog::Compute::Vsphere::Server.any_instance.stubs(:ready?).returns(false)
16
+ ::ForemanWreckingball.fog_vsphere_namespace::Mock.any_instance.stubs(:get_vm_ref).returns(vm)
17
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:ready?).returns(false)
18
18
  ::ForemanWreckingball::SpectreV2Status.any_instance.stubs(:recent_hw_version?).returns(true)
19
19
  # this is not stubbed correctly in fog-vsphere
20
- Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
20
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
21
21
  Setting::Wreckingball.load_defaults
22
22
  end
23
23
  teardown { ::Fog.unmock! }
@@ -10,8 +10,8 @@ module Actions
10
10
  setup do
11
11
  ::Fog.mock!
12
12
  # this is not stubbed correctly in fog-vsphere
13
- Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
14
- Fog::Compute::Vsphere::Server.any_instance.stubs(:hardware_version).returns('vmx-13')
13
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
14
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:hardware_version).returns('vmx-13')
15
15
  ::ForemanWreckingball::SpectreV2Status.any_instance.stubs(:recent_hw_version?).returns(true)
16
16
  ::PowerManager::Virt.any_instance.stubs(:ready?).returns(true)
17
17
  Setting::Wreckingball.load_defaults
@@ -10,8 +10,8 @@ module Actions
10
10
  setup do
11
11
  ::Fog.mock!
12
12
  # this is not stubbed correctly in fog-vsphere
13
- Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
14
- Fog::Compute::Vsphere::Server.any_instance.stubs(:hardware_version).returns('vmx-13')
13
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
14
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:hardware_version).returns('vmx-13')
15
15
  ::ForemanWreckingball::SpectreV2Status.any_instance.stubs(:recent_hw_version?).returns(true)
16
16
  ::PowerManager::Virt.any_instance.stubs(:ready?).returns(true)
17
17
  Setting::Wreckingball.load_defaults
@@ -10,7 +10,7 @@ module Actions
10
10
  setup do
11
11
  ::Fog.mock!
12
12
  # this is not stubbed correctly in fog-vsphere
13
- Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
13
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
14
14
  ::ForemanWreckingball::SpectreV2Status.any_instance.stubs(:recent_hw_version?).returns(true)
15
15
  ::PowerManager::Virt.any_instance.stubs(:ready?).returns(true)
16
16
  Setting::Wreckingball.load_defaults
@@ -116,9 +116,9 @@ module ForemanWreckingball
116
116
  @missing_host = FactoryBot.create(:host, :managed, :with_vmware_facet, compute_resource: cr, owner: admin, uuid: 2)
117
117
 
118
118
  mock_vm = mock('vm')
119
- mock_vm.stubs(:uuid).returns(@managed_host.uuid)
119
+ mock_vm.stubs(:id).returns(@managed_host.uuid)
120
120
  mock_vm.stubs(:name).returns(@managed_host.name)
121
- Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
121
+ Foreman::Model::Vmware.any_instance.stubs(:vms).returns(OpenStruct.new(all: Array(mock_vm)))
122
122
  end
123
123
 
124
124
  test 'shows a status page' do
@@ -25,9 +25,9 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
25
25
  missing_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 2)
26
26
 
27
27
  mock_vm = mock('vm')
28
- mock_vm.stubs(:uuid).returns(managed_host.uuid)
28
+ mock_vm.stubs(:id).returns(managed_host.uuid)
29
29
  mock_vm.stubs(:name).returns(managed_host.name)
30
- Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
30
+ Foreman::Model::Vmware.any_instance.stubs(:vms).returns(OpenStruct.new(all: Array(mock_vm)))
31
31
 
32
32
  visit status_managed_hosts_dashboard_hosts_path
33
33
 
@@ -36,25 +36,37 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
36
36
  refute_includes list.text, managed_host.name
37
37
  end
38
38
 
39
- test 'shows duplicate vms with same uuid for a host' do
40
- managed_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
39
+ test 'shows hosts associated to wrong compute resource' do
40
+ other_cr = FactoryBot.create(
41
+ :vmware_cr,
42
+ uuid: 'bla',
43
+ organizations: [organization],
44
+ locations: [tax_location]
45
+ )
46
+
47
+ correct_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
48
+ incorrect_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 2)
41
49
 
42
50
  mock1_vm = mock('vm1')
43
- mock1_vm.stubs(:uuid).returns(managed_host.uuid)
51
+ mock1_vm.stubs(:id).returns(correct_host.uuid)
44
52
  mock1_vm.stubs(:name).returns('foo01.example.com')
45
53
  mock2_vm = mock('vm2')
46
- mock2_vm.stubs(:uuid).returns(managed_host.uuid)
54
+ mock2_vm.stubs(:id).returns(incorrect_host.uuid)
47
55
  mock2_vm.stubs(:name).returns('foo02.example.com')
48
- Foreman::Model::Vmware.any_instance.stubs(:vms).returns([mock1_vm, mock2_vm])
56
+
57
+ cr.stubs(:vms).returns(OpenStruct.new(all: [mock1_vm]))
58
+ other_cr.stubs(:vms).returns(OpenStruct.new(all: [mock2_vm]))
59
+
60
+ Foreman::Model::Vmware.stubs(:unscoped).returns(OpenStruct.new(all: [cr, other_cr]))
49
61
 
50
62
  visit status_managed_hosts_dashboard_hosts_path
51
63
 
52
- list = page.find('#duplicate_vms')
53
- assert_includes list.text, 'foo01.example.com'
54
- assert_includes list.text, 'foo02.example.com'
64
+ list = page.find('#wrong_hosts')
65
+ refute_includes list.text, correct_host.name
66
+ assert_includes list.text, incorrect_host.name
55
67
  end
56
68
 
57
- test 'shows hosts with vm associated with a different compute resource' do
69
+ test 'shows hosts that can be found one more than one compute resource' do
58
70
  other_cr = FactoryBot.create(
59
71
  :vmware_cr,
60
72
  uuid: 'bla',
@@ -69,23 +81,23 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
69
81
  managed3_host = FactoryBot.create(:host, :managed, compute_resource: other_cr, owner: admin, uuid: 3)
70
82
 
71
83
  mock1_vm = mock('vm1')
72
- mock1_vm.stubs(:uuid).returns(managed1_host.uuid)
84
+ mock1_vm.stubs(:id).returns(managed1_host.uuid)
73
85
  mock1_vm.stubs(:name).returns(managed1_host.name)
74
86
  mock2_vm = mock('vm2')
75
- mock2_vm.stubs(:uuid).returns(managed2_host.uuid)
87
+ mock2_vm.stubs(:id).returns(managed2_host.uuid)
76
88
  mock2_vm.stubs(:name).returns(managed2_host.name)
77
89
  mock3_vm = mock('vm3')
78
- mock3_vm.stubs(:uuid).returns(managed3_host.uuid)
90
+ mock3_vm.stubs(:id).returns(managed3_host.uuid)
79
91
  mock3_vm.stubs(:name).returns(managed3_host.name)
80
92
 
81
- cr.stubs(:vms).returns([mock1_vm, mock2_vm])
82
- other_cr.stubs(:vms).returns([mock3_vm])
93
+ cr.stubs(:vms).returns(OpenStruct.new(all: [mock1_vm, mock2_vm]))
94
+ other_cr.stubs(:vms).returns(OpenStruct.new(all: [mock2_vm, mock3_vm]))
83
95
 
84
- Foreman::Model::Vmware.stubs(:all).returns([cr, other_cr])
96
+ Foreman::Model::Vmware.stubs(:unscoped).returns(OpenStruct.new(all: [cr, other_cr]))
85
97
 
86
98
  visit status_managed_hosts_dashboard_hosts_path
87
99
 
88
- list = page.find('#different_vms')
100
+ list = page.find('#more_than_one_hosts')
89
101
  refute_includes list.text, managed1_host.name
90
102
  assert_includes list.text, managed2_host.name
91
103
  refute_includes list.text, managed3_host.name
@@ -6,6 +6,7 @@ require 'webmock/minitest'
6
6
  require 'webmock'
7
7
 
8
8
  # Add plugin to FactoryBot's paths
9
+ FactoryBot.definition_file_paths << File.join(ForemanTasks::Engine.root, 'test', 'factories')
9
10
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
10
11
  FactoryBot.reload
11
12
 
@@ -62,12 +62,12 @@ module ForemanWreckingball
62
62
 
63
63
  setup do
64
64
  ::Fog.mock!
65
- ::Fog::Compute::Vsphere::Mock.any_instance.stubs(:get_vm_ref).returns(vm)
65
+ ::ForemanWreckingball.fog_vsphere_namespace::Mock.any_instance.stubs(:get_vm_ref).returns(vm)
66
66
  # this is not stubbed correctly in fog-vsphere
67
- ::Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
68
- ::Fog::Compute::Vsphere::Server.any_instance.stubs(:hardware_version).returns('vmx-9')
69
- ::Fog::Compute::Vsphere::Server.any_instance.stubs(:corespersocket).returns(1)
70
- ::Fog::Compute::Vsphere::Server.any_instance.stubs(:power_state).returns('poweredOn')
67
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
68
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:hardware_version).returns('vmx-9')
69
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:corespersocket).returns(1)
70
+ ::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:power_state).returns('poweredOn')
71
71
  end
72
72
  teardown { ::Fog.unmock! }
73
73
 
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.3.0
4
+ version: 3.4.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: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks