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

ncm-network: nmstate - remove config route entry not in profile #1645

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ sub make_nm_ip_route
return \@rt_entry;
}

# create an absent route entry.
# if you prepend the routes with the 'absent', then nmstate will clear the existing matches and apply the routes
# This will allow nmstate to clear all routes for the interface and only apply routes defined in config.
# useful when routes are changed later on in profile once host is built.
# return arrayref
sub make_nm_route_absent {
my ($self, $device) = @_;
return { 'state' => 'absent', 'next-hop-interface' => $device };
}

# group all eth bound to a bond together in a hashref for to be used as
# - port in nmstate config file
sub get_bonded_eth
Expand Down Expand Up @@ -377,13 +387,13 @@ sub generate_nmstate_config
# next-hop-interface:
# and so on.
my $routes = [];
push @$routes, ($self->make_nm_route_absent($name));
push @$routes, \%default_rt if scalar %default_rt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit weird that at line 396 you are pushing on a single entry array containing a hashref but here you are appending a hashref instead. What does @$routes actually expect in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@$routes, it contains array of hashref.
so will contain values such as

- next-hop-interface: bond0
  state: absent
- destination: 0.0.0.0/0
  next-hop-address: x.x.x.x
  next-hop-interface: bond0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read perldoc -f push and it says that it appends each element in the second list to the first. So line 390 is technically correct: the second arg must be a list. But I always recall using push like: push @a, $b; so I guess it works to have a scalar as the second argument. Perl is weird.

if (defined($iface->{route})) {
$self->verbose("policy route found, nmstate will manage it");
my $route = $iface->{route};
$routes = $self->make_nm_ip_route($name, $route, $routing_table);
push @$routes, \%default_rt if scalar %default_rt;
} elsif (scalar %default_rt){
push @$routes, \%default_rt if scalar %default_rt;
my $policyroutes = $self->make_nm_ip_route($name, $route, $routing_table);
push @$routes, @{$policyroutes};
}

my $policy_rule = [];
Expand Down
4 changes: 4 additions & 0 deletions ncm-network/src/test/perl/nmstate_simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ interfaces:
name: eth0
profile-name: eth0
type: bond
routes:
config:
- next-hop-interface: eth0
state: absent
EOF

Readonly my $NOTTOREMOVE => <<EOF;
Expand Down