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 #17115 - validate ip from RHSM #6412

Merged
merged 1 commit into from Oct 28, 2016
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: 8 additions & 1 deletion app/models/katello/rhsm_fact_parser.rb
Expand Up @@ -23,7 +23,7 @@ def get_facts_for_interface(interface)
{
'link' => true,
'macaddress' => facts["net.interface.#{interface}.mac_address"],
'ipaddress' => facts["net.interface.#{interface}.ipv4_address"]
'ipaddress' => get_rhsm_ip(interface)
}
end

Expand Down Expand Up @@ -71,5 +71,12 @@ def environment

def ipmi_interface
end

private

def get_rhsm_ip(interface)
ip = facts["net.interface.#{interface}.ipv4_address"]
Net::Validations.validate_ip(ip) ? ip : nil
end
end
end
15 changes: 15 additions & 0 deletions db/migrate/20161026191118_fix_invalid_interfaces.rb
@@ -0,0 +1,15 @@
class FixInvalidInterfaces < ActiveRecord::Migration
class FakeNic < ActiveRecord::Base
self.table_name = 'nics'

def type
Nic::Base
end
end

def up
FakeNic.where(:ip => "Unknown").each do |nic|
nic.update_attributes(:ip => nil)
end
end
end
9 changes: 8 additions & 1 deletion test/models/rhsm_fact_parser_test.rb
Expand Up @@ -9,7 +9,9 @@ def setup
'net.interface.eth0.1.mac_address' => '00:00:00:00:00:12',
'net.interface.eth0.1.ipv4_address' => '192.168.0.2',
'net.interface.ethnone.mac_address' => 'none',
'net.interface.eth2.mac_address' => '00:00:00:00:00:13'
'net.interface.eth2.mac_address' => '00:00:00:00:00:13',
'net.interface.eth3.ipv4_address' => 'Unknown',
'net.interface.eth3.mac_address' => '00:00:00:00:00:14'
}
@parser = RhsmFactParser.new(@facts)
end
Expand Down Expand Up @@ -44,6 +46,11 @@ def test_get_facts_for_interface_without_ip
assert_equal expected_eth1, @parser.get_facts_for_interface('eth1')
end

def test_get_facts_for_interface_with_invalid_ip
assert_equal @facts['net.interface.eth3.mac_address'], @parser.get_facts_for_interface('eth3')['macaddress']
assert_empty @parser.get_facts_for_interface('eth3')['ipaddress']
end

def test_valid_centos_os
@facts['distribution.name'] = 'CentOS'
@facts['distribution.version'] = '7.2'
Expand Down