Project

General

Profile

« Previous | Next » 

Revision 43c4bd72

Added by Marek Hulán over 9 years ago

Fixes #7456 - Extract primary interface from host

Contributions from:

All host must have at least one primary interface and one provision (can
be the same interface). Primary interface gives host a name so even
unamanaged host have primary interface (we skip validations of other
attributes for unamanged hosts though).

Host still have name attribute which is a cache of primary interface name.
Therefore we can use the host name in SQL queries, as a friendly_id etc.

- realm moved to the primary tab
- fqdn in nics table
- flags in nics table
- checkboxes for provision and primary flags
- modal resize fix
- original fields for primary NIC removed
- skipping validation for new resources
- warnings before switching flags and table update
- host name and primary interface name connected
- host domain name in the page title
- nics on host show page
- clearing modal window on cancel
- fixed domain validation in NIC::Base
- ip suggestion for all interfaces
- flags switchable from the overview table
- use icons instead of text for primary/provision on NICs overview tab
- attempt to fix sending NIC template
- fix fqdn algorithm
- ip addres in the overview table
- fix for class name collision
- better behavior of host name <-> primary name sync
- fix for subnet combobox values
- fix for modal poping up on form submission
- network partial for CRs moved from VM tab to modal
- fix ip suggestion race for ipam=db

View differences:

test/unit/fact_parser_test.rb
require "test_helper"
class FactParserTest < ActiveSupport::TestCase
attr_reader :parser, :host
setup do
@parser = get_parser
end
test "default parsers" do
assert_includes FactParser.parsers.keys, 'puppet'
assert_equal PuppetFactParser, FactParser.parser_for(:puppet)
......
end
test "#parse_interfaces? should answer based on current setttings" do
parser = get_parser
parser.stub(:support_interfaces_parsing?, true) do
Setting.expects(:[]).with('ignore_puppet_facts_for_provisioning').returns(false)
assert parser.parse_interfaces?
......
end
test "#remove_ignored uses ignored_interfaces regular to remove ignored interfaces" do
parser = get_parser
parser.stub(:ignored_interfaces, /^b|^d/) do
assert_equal ['a', 'c'], parser.send(:remove_ignored, ['a', 'b', 'c', 'd'])
end
end
test "#normalize_interfaces converts custom-case interface names to be downcase" do
parser = get_parser
assert_equal ['eth0', 'eth0.0', 'em1'], parser.send(:normalize_interfaces, ['ETH0', 'Eth0.0', 'eM1'])
end
test "#interfaces gets facts hash for desired interfaces, keeping same values it gets from parser" do
parser = get_parser
parser.stub(:get_interfaces, ['eth1', 'lo', 'eth0', 'eth0.0', 'local', 'usb0', 'vnet0', 'br0', 'virbr0']) do
parser.expects(:get_facts_for_interface).with('eth1').returns({'link' => 'false', 'macaddress' => '00:00:00:00:00:AB'}.with_indifferent_access)
parser.expects(:get_facts_for_interface).with('eth0').returns({'link' => 'true', 'macaddress' => '00:00:00:00:00:cd', 'custom' => 'value'}.with_indifferent_access)
......
end
test "#set_additional_attributes detects physical interface" do
parser = get_parser
result = parser.send(:set_additional_attributes, {}, 'eth0')
refute result[:virtual]
......
end
test "#set_additional_attributes detects bridged" do
parser = get_parser
result = parser.send(:set_additional_attributes, {}, 'br0')
assert result[:virtual]
assert_empty result[:attached_to]
......
assert result[:bridge]
end
context "parser tests involving hosts" do
setup do
@host = FactoryGirl.build(:host)
end
test "#suggested_primary_interface detects primary interface using DNS" do
parser.stubs(:interfaces).returns({
'br0' => {'ipaddress' => '30.0.0.30', 'macaddress' => '00:00:00:00:00:30'},
'em1' => {'ipaddress' => '10.0.0.10', 'macaddress' => '00:00:00:00:00:10'},
'em2' => {'ipaddress' => '12.0.0.12', 'macaddress' => '00:00:00:00:00:12'},
'bond0' => {'ipaddress' => '15.0.0.15', 'macaddress' => '00:00:00:00:00:15'},
}.with_indifferent_access)
Resolv::DNS.any_instance.stubs(:getnames).returns([])
Resolv::DNS.any_instance.expects(:getnames).with('12.0.0.12').returns([host.name])
found = parser.suggested_primary_interface(host)
assert_equal 'em2', found.first
assert_equal '12.0.0.12', found.last[:ipaddress]
assert_equal '00:00:00:00:00:12', found.last[:macaddress]
end
test "#suggested_primary_interface primary interface detection falls back to physical with ip and mac" do
parser.stubs(:interfaces).returns({
'br0' => {'ipaddress' => '30.0.0.30', 'macaddress' => '00:00:00:00:00:30'},
'em0' => {'ipaddress' => '', 'macaddress' => ''},
'em1' => {'ipaddress' => '10.0.0.10', 'macaddress' => '00:00:00:00:00:10'},
'em2' => {'ipaddress' => '12.0.0.12', 'macaddress' => '00:00:00:00:00:12'},
'bond0' => {'ipaddress' => '15.0.0.15', 'macaddress' => '00:00:00:00:00:15'},
}.with_indifferent_access)
Resolv::DNS.any_instance.stubs(:getnames).returns([])
found = parser.suggested_primary_interface(host)
assert_equal 'em1', found.first
assert_equal '10.0.0.10', found.last[:ipaddress]
assert_equal '00:00:00:00:00:10', found.last[:macaddress]
end
test "#suggested_primary_interface primary interface detection falls back to bond with ip and mac if no physical" do
parser.stubs(:interfaces).returns({
'br0' => {'ipaddress' => '30.0.0.30', 'macaddress' => '00:00:00:00:00:30'},
'bond1' => {'ipaddress' => '', 'macaddress' => ''},
'bond0' => {'ipaddress' => '15.0.0.15', 'macaddress' => '00:00:00:00:00:15'},
}.with_indifferent_access)
Resolv::DNS.any_instance.stubs(:getnames).returns([])
found = parser.suggested_primary_interface(host)
assert_equal 'bond0', found.first
assert_equal '15.0.0.15', found.last[:ipaddress]
assert_equal '00:00:00:00:00:15', found.last[:macaddress]
end
test "#suggested_primary_interface primary interface detection falls back to first with ip and mac" do
parser.stubs(:interfaces).returns({
'br1' => { 'ipaddress' => '', 'macaddress' => ''},
'br0' => { 'ipaddress' => '30.0.0.30', 'macaddress' => '00:00:00:00:00:30'},
}.with_indifferent_access)
Resolv::DNS.any_instance.stubs(:getnames).returns([])
found = parser.suggested_primary_interface(host)
assert_equal 'br0', found.first
assert_equal '30.0.0.30', found.last[:ipaddress]
assert_equal '00:00:00:00:00:30', found.last[:macaddress]
end
test "#suggested_primary_interface primary interface detection falls back to first if no other option" do
parser.stubs(:interfaces).returns({
'br1' => {'ipaddress' => '', 'macaddress' => ''},
'br0' => {'ipaddress' => '', 'macaddress' => ''},
}.with_indifferent_access)
Resolv::DNS.any_instance.stubs(:getnames).returns([])
found = parser.suggested_primary_interface(host)
assert_equal 'br1', found.first
assert_equal '', found.last[:ipaddress]
assert_equal '', found.last[:macaddress]
end
end
def get_parser(facts = {})
FactParser.new(facts)
end

Also available in: Unified diff