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 #20389 - Don't report a non numeric major version on debian sid #91

Merged
merged 1 commit into from Jul 27, 2017
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
24 changes: 21 additions & 3 deletions app/services/foreman_ansible/fact_parser.rb
Expand Up @@ -79,10 +79,28 @@ def os_name
facts[:ansible_lsb] && facts[:ansible_lsb]['id']
end

def debian_os_major_sid
case facts[:ansible_distribution_major_version]
when /wheezy/i
'7'
when /jessie/i
'8'
when /stretch/i
'9'
when /buster/i
'10'
end
end

def os_major
facts[:ansible_distribution_major_version] ||
facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] ||
(facts[:version].split('R')[0] if os_name == 'junos')
if os_name == 'Debian' &&
facts[:ansible_distribution_major_version][%r{\/sid}i]
debian_os_major_sid
else
facts[:ansible_distribution_major_version] ||
facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] ||
(facts[:version].split('R')[0] if os_name == 'junos')
end
end

def os_release
Expand Down
19 changes: 19 additions & 0 deletions test/unit/services/fact_parser_test.rb
Expand Up @@ -50,4 +50,23 @@ def expect_where(model, fact_name)
sample_mock.expects(:first_or_create)
end
end

class DebianFactParserTest < ActiveSupport::TestCase
setup do
@facts_parser = ForemanAnsible::FactParser.new(
{'_type': 'ansible',
'_timestamp': '2015-10-29 20:01:51 +0100',
'ansible_facts': {
'ansible_distribution_major_version': 'buster/sid',
'ansible_distribution': 'Debian'
}
})
end

test 'Parses debian unstable aka sid correctly' do
os = @facts_parser.operatingsystem
assert_equal "10", os.major
assert_equal "Debian", os.name
end
end
end