Skip to content

Commit

Permalink
ncm-network: nmstate: simple interfaces reorder on apply/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird authored and jrha committed Sep 5, 2024
1 parent 0283e92 commit b9ed5b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions ncm-network/src/test/perl/nmstate_advance.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit b9ed5b1

Please sign in to comment.