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

Fixes #35658 - don't fail parsing Windows facts without os_name #9476

Merged
merged 1 commit into from Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/services/foreman_ansible/operating_system_parser.rb
Expand Up @@ -79,8 +79,7 @@ def os_minor

def os_name
if facts[:ansible_os_family] == 'Windows'
facts[:ansible_os_name].tr(" \n\t", '') ||
facts[:ansible_distribution].tr(" \n\t", '')
windows_os_name.tr(" \n\t", '')
else
# RHEL 7 is marked as either RedHatEnterpriseServer or RedHatEnterpriseWorkstation, RHEL 8 is lsb id is RedHatEnterprise
# but we always consider it just RHEL on this level, workstation is differentiated below
Expand All @@ -99,10 +98,14 @@ def os_name

def os_description
if facts[:ansible_os_family] == 'Windows'
facts[:ansible_os_name].strip || facts[:ansible_distribution].strip
windows_os_name
else
facts[:ansible_lsb] && facts[:ansible_lsb]['description']
end
end

def windows_os_name
(facts[:ansible_os_name] || facts[:ansible_distribution] || 'Microsoft Windows').strip
end
end
end
31 changes: 31 additions & 0 deletions test/unit/foreman_ansible/fact_parser_test.rb
Expand Up @@ -337,6 +337,37 @@ class WindowsOSFactParserTest < ActiveSupport::TestCase
assert os.valid?
end
end

context 'Windows Server 2016 without admin privileges' do
setup do
@facts_parser = AnsibleFactParser.new(
HashWithIndifferentAccess.new(
'_type' => 'ansible',
'_timestamp' => '2015-10-29 20:01:51 +0100',
'ansible_facts' => {
'ansible_architecture' => '64-Bit',
'ansible_distribution_major_version' => '10',
'ansible_distribution_version' => '10.0.14393.0',
'ansible_os_family' => 'Windows',
'ansible_system' => 'Win32NT',
'ansible_win_rm_certificate_expires' => '2021-01-23 15:08:48',
'ansible_windows_domain' => 'example.com',
}
)
)
end

test 'parses Windows Server correctly' do
os = @facts_parser.operatingsystem
assert_equal '10', os.major
assert_equal '10.0.143930', os.release
assert_equal '0.143930', os.minor
assert_equal 'Windows', os.family
assert_equal 'Microsoft Windows', os.description
assert_equal 'MicrosoftWindows', os.name
assert os.valid?
end
end
end

class CentOSStreamFactParserTest < ActiveSupport::TestCase
Expand Down