From b9ed5b156ecb555194e8c69a7662f71109015eac Mon Sep 17 00:00:00 2001 From: stdweird Date: Tue, 16 Jul 2024 10:15:36 +0200 Subject: [PATCH 1/3] ncm-network: nmstate: simple interfaces reorder on apply/delete --- ncm-network/src/main/perl/nmstate.pm | 9 ++++++++- ncm-network/src/test/perl/nmstate_advance.t | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ncm-network/src/main/perl/nmstate.pm b/ncm-network/src/main/perl/nmstate.pm index 00eb075108..9ab4b4584e 100644 --- a/ncm-network/src/main/perl/nmstate.pm +++ b/ncm-network/src/main/perl/nmstate.pm @@ -610,8 +610,15 @@ sub nmstate_apply { my ($self, $exifiles, $ifup, $ifdown, $nwsrv) = @_; + my @ifaces = sort keys %$ifup; my @ifaces_down = sort keys %$ifdown; + + # primitive re-ordering to make sure eg bond are apply'ed last, and removed first + my $order_pattern = '^bond'; + @ifaces = ((grep {$_ !~ m/$order_pattern/} @ifaces), (grep {$_ =~ m/$order_pattern/} @ifaces)); + @ifaces_down = ((grep {$_ =~ m/$order_pattern/} @ifaces_down), (grep {$_ !~ m/$order_pattern/} @ifaces_down)); + my $action; if (@ifaces) { @@ -622,7 +629,7 @@ sub nmstate_apply my $ymlfile = $self->iface_filename($iface); if ($self->any_exists($ymlfile)){ push(@cmds, [$NMSTATECTL, "apply", $ymlfile]); - push(@cmds, [qw(sleep 10)]) if ($iface =~ m/bond/); + push(@cmds, [qw(/usr/bin/sleep 10)]) if ($iface =~ m/^bond/); } else { # TODO: perhaps try down the interface? it's done later anyway $self->verbose("$ymlfile does not exist for $iface, not applying"); diff --git a/ncm-network/src/test/perl/nmstate_advance.t b/ncm-network/src/test/perl/nmstate_advance.t index 5653ef845c..3a3a6c2287 100644 --- a/ncm-network/src/test/perl/nmstate_advance.t +++ b/ncm-network/src/test/perl/nmstate_advance.t @@ -318,4 +318,20 @@ is($dummy_yml, $DUMMY_YML, "Exact dummy interface yml config"); my $alias_yml = get_file_contents("/etc/nmstate/eth4.yml"); is($alias_yml, $ALIAS_YML, "Exact alias interface yml config"); +diag "all history commands ", explain \@Test::Quattor::command_history; + +# apply commands are sorted alphabetically, bond last +ok(command_history_ok([ + '/usr/bin/nmstatectl apply /etc/nmstate/dummy_myvip.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth0.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth0.123.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth1.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth4.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/ib0.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/ib1.12345.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/vlan0.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/bond0.yml', +], [])); + + done_testing(); From d69d3b2f110cdf859b905eaec1218aa5cc1a958f Mon Sep 17 00:00:00 2001 From: stdweird Date: Tue, 16 Jul 2024 10:34:23 +0200 Subject: [PATCH 2/3] ncm-network: nmstate: bond master does not take care of slaves --- ncm-network/src/main/perl/network.pm | 4 +++- ncm-network/src/main/perl/nmstate.pm | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ncm-network/src/main/perl/network.pm b/ncm-network/src/main/perl/network.pm index 55ada87f0b..3aa5180369 100755 --- a/ncm-network/src/main/perl/network.pm +++ b/ncm-network/src/main/perl/network.pm @@ -204,6 +204,8 @@ our @EXPORT = qw($FAILED_SUFFIX # list of constants to allow inheritance via $self->CONSTANTNAME use constant IFCFG_DIR => "/etc/sysconfig/network-scripts"; +use constant BOND_MASTER_STARTS_SLAVES => 1; + sub backup_dir { @@ -1445,7 +1447,7 @@ sub make_ifup $exifiles->{"$cfg_filename"} == $REMOVE) { $self->verbose("Not starting $iface scheduled for removal"); } else { - if ($ifaces->{$iface}->{master}) { + if ($self->BOND_MASTER_STARTS_SLAVES && $ifaces->{$iface}->{master}) { # bonding devices: don't bring the slaves up, only the master $self->verbose("Found SLAVE interface $iface in ifdown map, ", "not starting it with ifup; is left for master $ifaces->{$iface}->{master}."); diff --git a/ncm-network/src/main/perl/nmstate.pm b/ncm-network/src/main/perl/nmstate.pm index 9ab4b4584e..ce60d0e01f 100644 --- a/ncm-network/src/main/perl/nmstate.pm +++ b/ncm-network/src/main/perl/nmstate.pm @@ -41,6 +41,8 @@ Readonly my $YTRUE => $EDG::WP4::CCM::TextRender::ELEMENT_CONVERT{yaml_boolean}- Readonly my $YFALSE => $EDG::WP4::CCM::TextRender::ELEMENT_CONVERT{yaml_boolean}->(0); use constant IFCFG_DIR => "/etc/nmstate"; +use constant BOND_MASTER_STARTS_SLAVES => 0; + sub iface_filename { From 6cc99a15cfb206848a09ca60cdaf627b89ecef57 Mon Sep 17 00:00:00 2001 From: stdweird Date: Tue, 16 Jul 2024 11:57:55 +0200 Subject: [PATCH 3/3] ncm-network: nmstate: handle the bond slaves explicitly --- ncm-network/src/main/perl/network.pm | 23 +++++++++++++++++++++ ncm-network/src/test/perl/nmstate_advance.t | 2 ++ 2 files changed, 25 insertions(+) diff --git a/ncm-network/src/main/perl/network.pm b/ncm-network/src/main/perl/network.pm index 3aa5180369..6665250b90 100755 --- a/ncm-network/src/main/perl/network.pm +++ b/ncm-network/src/main/perl/network.pm @@ -893,6 +893,19 @@ sub process_network } $iface->{my_inner_ipaddr} .= "/$iface->{my_inner_prefix}"; } + + # insert master->slaves data + if ($iface->{master}) { + my $bond = $iface->{master}; + my $bondiface = $nwtree->{interfaces}->{$bond}; + if ($bondiface) { + $bondiface->{slaves} = [] if !exists($bondiface->{slaves}); + push(@{$bondiface->{slaves}}, $ifname); + } else { + $self->warn("Interface $ifname has master $bond configured, but corresponding iface entry not found"); + } + } + } return $nwtree; @@ -1447,6 +1460,16 @@ sub make_ifup $exifiles->{"$cfg_filename"} == $REMOVE) { $self->verbose("Not starting $iface scheduled for removal"); } else { + if (!$self->BOND_MASTER_STARTS_SLAVES && $ifaces->{$iface}->{slaves}) { + my @slaves = @{$ifaces->{$iface}->{slaves}}; + # master won't bring up slaves, so add them here + $self->verbose("Found MASTER interface $iface in ifdown map, ", + "adding slaves @slaves to ifup."); + foreach my $slname (@slaves) { + $ifup{$slname} = 1; + } + } + if ($self->BOND_MASTER_STARTS_SLAVES && $ifaces->{$iface}->{master}) { # bonding devices: don't bring the slaves up, only the master $self->verbose("Found SLAVE interface $iface in ifdown map, ", diff --git a/ncm-network/src/test/perl/nmstate_advance.t b/ncm-network/src/test/perl/nmstate_advance.t index 3a3a6c2287..6f6c16c14e 100644 --- a/ncm-network/src/test/perl/nmstate_advance.t +++ b/ncm-network/src/test/perl/nmstate_advance.t @@ -326,6 +326,8 @@ ok(command_history_ok([ '/usr/bin/nmstatectl apply /etc/nmstate/eth0.yml', '/usr/bin/nmstatectl apply /etc/nmstate/eth0.123.yml', '/usr/bin/nmstatectl apply /etc/nmstate/eth1.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth2.yml', + '/usr/bin/nmstatectl apply /etc/nmstate/eth3.yml', '/usr/bin/nmstatectl apply /etc/nmstate/eth4.yml', '/usr/bin/nmstatectl apply /etc/nmstate/ib0.yml', '/usr/bin/nmstatectl apply /etc/nmstate/ib1.12345.yml',