diff --git a/ncm-network/src/main/perl/nmstate.pm b/ncm-network/src/main/perl/nmstate.pm index dc59bbeba6..f63e08fa0a 100644 --- a/ncm-network/src/main/perl/nmstate.pm +++ b/ncm-network/src/main/perl/nmstate.pm @@ -310,11 +310,11 @@ sub generate_nmstate_config my $iface = $net->{interfaces}->{$name}; my $device = $iface->{device} || $name; - my $is_eth = $iface->{set_hwaddr}; + my $is_eth = $iface->{hwaddr} ? 1 : 0; my $eth_bootproto = $iface->{bootproto}; my $is_ip = exists $iface->{ip} ? 1 : 0; my $is_vlan_eth = exists $iface->{vlan} ? 1 : 0; - my $is_bond_eth = exists $iface->{master} ? 1 : 0; + my $is_partof_bond = exists $iface->{master} ? 1 : 0; my $iface_changed = 0; # create hash of interface entries that will be used by nmstate config. @@ -323,9 +323,13 @@ sub generate_nmstate_config $ifaceconfig->{mtu} = $iface->{mtu} if $iface->{mtu}; $ifaceconfig->{'mac-address'} = $iface->{hwaddr} if $iface->{hwaddr}; $ifaceconfig->{'profile-name'} = $name; + + # this will be empty if the interface isnt a bond interface. + # we can use this to determine if this interface is bond interface. + my $bonded_eth = get_bonded_eth($self, $name, $net->{interfaces}); if ($is_eth) { $ifaceconfig->{type} = "ethernet"; - if ($is_bond_eth) { + if ($is_partof_bond) { # no ipv4 address for bonded eth, plus in nmstate bonded eth is controlled by controller. no config is required. $ifaceconfig->{ipv4}->{enabled} = "false"; $ifaceconfig->{state} = "up"; @@ -338,18 +342,17 @@ sub generate_nmstate_config $ifaceconfig->{type} = "vlan"; $ifaceconfig->{vlan}->{'base-iface'} = $iface->{physdev}; $ifaceconfig->{vlan}->{'id'} = $vlan_id; - } else { + } elsif ($bonded_eth) { # if bond device $ifaceconfig->{type} = "bond"; $ifaceconfig->{'link-aggregation'} = $iface->{link_aggregation}; - my $bonded_eth = get_bonded_eth($self, $name, $net->{interfaces}); if ($bonded_eth){ $ifaceconfig->{'link-aggregation'}->{port} = $bonded_eth; } } - if (defined($eth_bootproto)) { - if ($eth_bootproto eq 'static') { + if (defined($eth_bootproto) or $is_ip) { + if ((defined($eth_bootproto) and $eth_bootproto eq 'static') or $is_ip ) { $ifaceconfig->{state} = "up"; if ($is_ip) { # if device has manual ip assigned @@ -377,8 +380,13 @@ sub generate_nmstate_config $self->verbose("no ipv6 entries"); } } - } elsif (($eth_bootproto eq "none") && (!$is_bond_eth)) { - # no ip on interface and is not a bond eth, assume not managed so disable eth. + } elsif (($eth_bootproto eq "dhcp") && (!$is_partof_bond)) { + # dhcp configuration + $ifaceconfig->{state} = "up"; + $ifaceconfig->{ipv4}->{dhcp} = $YTRUE; + $ifaceconfig->{ipv4}->{enabled} = $YTRUE; + } elsif (($eth_bootproto eq "none") && (!$is_partof_bond)) { + # no ip on interface and is not a part of a bonded interface, assume not managed so disable eth. $ifaceconfig->{ipv4}->{enabled} = "false"; $ifaceconfig->{ipv6}->{enabled} = "false"; $ifaceconfig->{state} = "down"; diff --git a/ncm-network/src/test/perl/nmstate_advance.t b/ncm-network/src/test/perl/nmstate_advance.t new file mode 100644 index 0000000000..5705775d28 --- /dev/null +++ b/ncm-network/src/test/perl/nmstate_advance.t @@ -0,0 +1,181 @@ +use strict; +use warnings; + +BEGIN { + *CORE::GLOBAL::sleep = sub {}; +} + +use Test::More; +use Test::Quattor qw(nmstate_advance); +use Test::MockModule; +use Readonly; + +use NCM::Component::nmstate; +my $mock = Test::MockModule->new('NCM::Component::nmstate'); +my %executables; +$mock->mock('_is_executable', sub {diag "executables $_[1] ",explain \%executables;return $executables{$_[1]};}); + +my $cfg = get_config_for_profile('nmstate_advance'); +my $cmp = NCM::Component::nmstate->new('network'); + +Readonly my $ETH0_YML => < < < < < <Configure($cfg), 1, "Component runs correctly with a test profile"); + +is(get_file_contents("/etc/iproute2/rt_tables"), $RT_NEW, "Exact routing table"); + +my $eth0yml = get_file_contents("/etc/nmstate/eth0.yml"); +is($eth0yml, $ETH0_YML, "Exact eth0 route yml config"); + +my $dhcpyml = get_file_contents("/etc/nmstate/eth1.yml"); +is($dhcpyml, $DHCP_YML, "Exact eth1 dhcp yml config"); + +my $bondyml = get_file_contents("/etc/nmstate/bond0.yml"); +is($bondyml, $BOND_YML, "Exact bond0 yml config"); + +my $vlanyml = get_file_contents("/etc/nmstate/eth0.123.yml"); +is($vlanyml, $VLAN_YML, "Exact eth0.123 vlan yml config"); + +done_testing(); diff --git a/ncm-network/src/test/perl/nmstate_simple.t b/ncm-network/src/test/perl/nmstate_simple.t index 6b62c9a0dc..e313938c4c 100644 --- a/ncm-network/src/test/perl/nmstate_simple.t +++ b/ncm-network/src/test/perl/nmstate_simple.t @@ -46,11 +46,21 @@ Readonly my $ETH0_YML => < <