Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect other os guest is a mismatch #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,7 @@ def run
current_os_id = host.vmware_facet.guest_id
current_os = VsphereOsIdentifiers.lookup(current_os_id)

selectors = {
:architecture => host.architecture.name,
:osfamily => host.operatingsystem.family,
:name => host.operatingsystem.name,
:major => host.operatingsystem.major.to_i,
:release => host.facts['os::release::full']
}

desired_os = VsphereOsIdentifiers.find_by(selectors)
desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major))
desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:release))
desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :release))
desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name))
desired_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name, :release))
desired_os = host.deduced_vsphere_guest

fail _('Could not auto detect desired operatingsystem.') unless desired_os

Expand Down
24 changes: 24 additions & 0 deletions app/models/concerns/foreman_wreckingball/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,29 @@ module HostExtensions
def action_input_key
'host'
end

def deduced_vsphere_guest
return unless architecture && operatingsystem

selectors = {
architecture: architecture.name,
osfamily: operatingsystem.family,
name: operatingsystem.name,
major: operatingsystem.major.to_i
}

deduced_os = VsphereOsIdentifiers.find_by(selectors)
deduced_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major))
deduced_os ||= VsphereOsIdentifiers.find_by(selectors.except(:release))
deduced_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :release))
deduced_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name))
deduced_os ||= VsphereOsIdentifiers.find_by(selectors.except(:major, :name, :release))
Comment on lines +28 to +40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selector release does not exist anymore if I understand correctly. If it is ok, that it was removed lines 37, 38,40 are to be removed. If not it should be readded after line 32.


deduced_os
end

def deduced_vsphere_guest_id
deduced_vsphere_guest&.id
end
end
end
5 changes: 5 additions & 0 deletions app/models/foreman_wreckingball/operatingsystem_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def os_matches_identifier?
return false if vsphere_os.name && vsphere_os.name != host.operatingsystem.name
return false if vsphere_os.major && ![vsphere_os.major].flatten.include?(host.operatingsystem.major.to_i)
return false if vsphere_os.release && ![vsphere_os.release].flatten.include?(host.facts['os::release::full'])

deduced_guest_id = host.deduced_vsphere_guest_id

return false if deduced_guest_id && deduced_guest_id != guest_id

true
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/factories/compute_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
factory :compute_resource do
trait :with_vmware_clusters do
transient do
vmware_clusters_count 1
vmware_clusters_count { 1 }
end

after(:create) do |compute_resource, evaluator|
Expand Down
236 changes: 120 additions & 116 deletions test/factories/foreman_wreckingball_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,133 @@
FactoryBot.define do
factory :vmware_facet, class: 'ForemanWreckingball::VmwareFacet' do
vmware_cluster
tools_state 2 #:toolsOk
power_state 1 #:poweredOn
cpus 2
corespersocket 1
memory_mb 8192
guest_id 'rhel6_64Guest'
cpu_hot_add false
hardware_version 'vmx-10'
cpu_features [
'cpuid.SSE3',
'cpuid.PCLMULQDQ',
'cpuid.SSSE3',
'cpuid.CMPXCHG16B',
'cpuid.PCID',
'cpuid.SSE41',
'cpuid.SSE42',
'cpuid.POPCNT',
'cpuid.AES',
'cpuid.XSAVE',
'cpuid.AVX',
'cpuid.DS',
'cpuid.SS',
'cpuid.XCR0_MASTER_SSE',
'cpuid.XCR0_MASTER_YMM_H',
'cpuid.LAHF64',
'cpuid.NX',
'cpuid.RDTSCP',
'cpuid.LM',
'cpuid.Intel'
]
tools_state { 2 } #:toolsOk
power_state { 1 } #:poweredOn
cpus { 2 }
corespersocket { 1 }
memory_mb { 8192 }
guest_id { 'rhel6_64Guest' }
cpu_hot_add { false }
hardware_version { 'vmx-10' }
cpu_features do
[
'cpuid.SSE3',
'cpuid.PCLMULQDQ',
'cpuid.SSSE3',
'cpuid.CMPXCHG16B',
'cpuid.PCID',
'cpuid.SSE41',
'cpuid.SSE42',
'cpuid.POPCNT',
'cpuid.AES',
'cpuid.XSAVE',
'cpuid.AVX',
'cpuid.DS',
'cpuid.SS',
'cpuid.XCR0_MASTER_SSE',
'cpuid.XCR0_MASTER_YMM_H',
'cpuid.LAHF64',
'cpuid.NX',
'cpuid.RDTSCP',
'cpuid.LM',
'cpuid.Intel'
]
end
host
end

factory :vmware_hypervisor_facet, class: 'ForemanWreckingball::VmwareHypervisorFacet' do
host
vmware_cluster
cpu_cores 18
cpu_sockets 1
cpu_threads 36
memory 412_046_372_864
cpu_cores { 18 }
cpu_sockets { 1 }
cpu_threads { 36 }
memory { 412_046_372_864 }
uuid { SecureRandom.uuid }
feature_capabilities [
'cpuid.3DNOW',
'cpuid.3DNOWPLUS',
'cpuid.3DNPREFETCH',
'cpuid.ABM',
'cpuid.ADX',
'cpuid.AES',
'cpuid.AMD',
'cpuid.AVX',
'cpuid.AVX2',
'cpuid.BMI1',
'cpuid.BMI2',
'cpuid.CMPXCHG16B',
'cpuid.CR8AVAIL',
'cpuid.Cyrix',
'cpuid.DS',
'cpuid.ENFSTRG',
'cpuid.EXTAPICSPC',
'cpuid.F16C',
'cpuid.FFXSR',
'cpuid.FMA',
'cpuid.FMA4',
'cpuid.FSGSBASE',
'cpuid.HLE',
'cpuid.IBPB',
'cpuid.IBRS',
'cpuid.INVPCID',
'cpuid.Intel',
'cpuid.LAHF64',
'cpuid.LM',
'cpuid.MISALIGNED_SSE',
'cpuid.MMXEXT',
'cpuid.MOVBE',
'cpuid.MWAIT',
'cpuid.NX',
'cpuid.PCID',
'cpuid.PCLMULQDQ',
'cpuid.PDPE1GB',
'cpuid.POPCNT',
'cpuid.PSN',
'cpuid.RDRAND',
'cpuid.RDSEED',
'cpuid.RDTSCP',
'cpuid.RTM',
'cpuid.SMAP',
'cpuid.SMEP',
'cpuid.SS',
'cpuid.SSE3',
'cpuid.SSE41',
'cpuid.SSE42',
'cpuid.SSE4A',
'cpuid.SSSE3',
'cpuid.STIBP',
'cpuid.SVM',
'cpuid.SVM_DECODE_ASSISTS',
'cpuid.SVM_FLUSH_BY_ASID',
'cpuid.SVM_NPT',
'cpuid.SVM_NRIP',
'cpuid.SVM_VMCB_CLEAN',
'cpuid.TBM',
'cpuid.VIA',
'cpuid.VMX',
'cpuid.XCR0_MASTER_SSE',
'cpuid.XCR0_MASTER_YMM_H',
'cpuid.XOP',
'cpuid.XSAVE',
'cpuid.XSAVEOPT',
'hv.capable',
'misc.cpuidFaulting',
'vpmc.fixctr.0',
'vpmc.fixedWidth',
'vpmc.genWidth',
'vpmc.genctr.0',
'vpmc.genctr.1',
'vpmc.genctr.2',
'vpmc.genctr.3',
'vpmc.microarchitecture.ivybridge',
'vpmc.numFixedCtrs',
'vpmc.numGenCtrs',
'vpmc.version',
'vt.realmode'
]
feature_capabilities do
[
'cpuid.3DNOW',
'cpuid.3DNOWPLUS',
'cpuid.3DNPREFETCH',
'cpuid.ABM',
'cpuid.ADX',
'cpuid.AES',
'cpuid.AMD',
'cpuid.AVX',
'cpuid.AVX2',
'cpuid.BMI1',
'cpuid.BMI2',
'cpuid.CMPXCHG16B',
'cpuid.CR8AVAIL',
'cpuid.Cyrix',
'cpuid.DS',
'cpuid.ENFSTRG',
'cpuid.EXTAPICSPC',
'cpuid.F16C',
'cpuid.FFXSR',
'cpuid.FMA',
'cpuid.FMA4',
'cpuid.FSGSBASE',
'cpuid.HLE',
'cpuid.IBPB',
'cpuid.IBRS',
'cpuid.INVPCID',
'cpuid.Intel',
'cpuid.LAHF64',
'cpuid.LM',
'cpuid.MISALIGNED_SSE',
'cpuid.MMXEXT',
'cpuid.MOVBE',
'cpuid.MWAIT',
'cpuid.NX',
'cpuid.PCID',
'cpuid.PCLMULQDQ',
'cpuid.PDPE1GB',
'cpuid.POPCNT',
'cpuid.PSN',
'cpuid.RDRAND',
'cpuid.RDSEED',
'cpuid.RDTSCP',
'cpuid.RTM',
'cpuid.SMAP',
'cpuid.SMEP',
'cpuid.SS',
'cpuid.SSE3',
'cpuid.SSE41',
'cpuid.SSE42',
'cpuid.SSE4A',
'cpuid.SSSE3',
'cpuid.STIBP',
'cpuid.SVM',
'cpuid.SVM_DECODE_ASSISTS',
'cpuid.SVM_FLUSH_BY_ASID',
'cpuid.SVM_NPT',
'cpuid.SVM_NRIP',
'cpuid.SVM_VMCB_CLEAN',
'cpuid.TBM',
'cpuid.VIA',
'cpuid.VMX',
'cpuid.XCR0_MASTER_SSE',
'cpuid.XCR0_MASTER_YMM_H',
'cpuid.XOP',
'cpuid.XSAVE',
'cpuid.XSAVEOPT',
'hv.capable',
'misc.cpuidFaulting',
'vpmc.fixctr.0',
'vpmc.fixedWidth',
'vpmc.genWidth',
'vpmc.genctr.0',
'vpmc.genctr.1',
'vpmc.genctr.2',
'vpmc.genctr.3',
'vpmc.microarchitecture.ivybridge',
'vpmc.numFixedCtrs',
'vpmc.numGenCtrs',
'vpmc.version',
'vt.realmode'
]
end
end

factory :vmware_cluster, class: 'ForemanWreckingball::VmwareCluster' do
Expand Down
6 changes: 3 additions & 3 deletions test/factories/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
FactoryBot.modify do
factory :some_task do
trait :running do
state 'running'
state { 'running' }
end

trait :stopped do
state 'stopped'
state { 'stopped' }
end

trait :vmware_sync do
label ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync.to_s
label { ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync.to_s }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class OperatingsystemStatusTest < ActiveSupport::TestCase
test 'when architecture, osfamily, name and major match' do
assert status.os_matches_identifier?
end

test 'when os identifier is other os but a proper os is set' do
host.vmware_facet.update(guest_id: 'otherGuest64')
refute status.os_matches_identifier?
end
end
end
end
28 changes: 28 additions & 0 deletions test/models/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@ class Host::ManagedTest < ActiveSupport::TestCase
assert_includes hosts, @host
end
end

describe '#deduced_vsphere_guest' do
context 'host with RHEL 6.1' do
let(:operatingsystem) do
FactoryBot.create(
:operatingsystem,
architectures: [architectures(:x86_64)],
major: 6,
minor: 1,
type: 'Redhat',
name: 'RedHat'
)
end
let(:host) do
FactoryBot.create(
:host,
:managed,
:with_vmware_facet,
architecture: architectures(:x86_64),
operatingsystem: operatingsystem
)
end

it 'deduced the vsphere guest from the host architecture and os' do
assert_equal 'rhel6_64Guest', host.deduced_vsphere_guest&.id
end
end
end
end