Skip to content

Commit

Permalink
nmstate: fix definition of IPv4 defult route interface
Browse files Browse the repository at this point in the history
- Use interface name rather than interface device, as it is done for IPv6
- Fix test for vlan0 to match this change (previous test incorrect)
- Add a test for vlan1.123 to check correct definition of VLAN paramters when
  the VLAN ID is specified in the interface name and the device parameter is
  ommitted
  • Loading branch information
jouvin committed Oct 28, 2024
1 parent da5ce26 commit 11f935b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
8 changes: 5 additions & 3 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ use constant BOND_MASTER_STARTS_SLAVES => 0;
sub iface_filename
{
my ($self, $iface) = @_;
return $self->IFCFG_DIR . "/$iface.yml";
my $filename = $self->IFCFG_DIR . "/$iface.yml";
$self->verbose("Interface $iface configuration file: $filename");
return $filename;
}

# Determine if this is a valid interface for ncm-network to manage,
Expand Down Expand Up @@ -370,7 +372,7 @@ sub generate_nmstate_config
my ($self, $name, $net, $ipv6, $routing_table, $default_gw) = @_;

my $iface = $net->{interfaces}->{$name};
my $device = $iface->{device} || $name;
my $device = $iface->{device} || $iface->{physdev} || $name;
my $is_eth = $iface->{hwaddr} ? 1 : 0;
my $eth_bootproto = $iface->{bootproto} || 'static';
my $is_ip = exists $iface->{ip} ? 1 : 0;
Expand Down Expand Up @@ -507,7 +509,7 @@ sub generate_nmstate_config
$self->debug(3, "Adding the default IPv4 gateway to interface '$name'");
$default_rt{destination} = '0.0.0.0/0';
$default_rt{'next-hop-address'} = $default_gw;
$default_rt{'next-hop-interface'} = $device;
$default_rt{'next-hop-interface'} = $name;
}
}
}
Expand Down
38 changes: 35 additions & 3 deletions ncm-network/src/test/perl/nmstate_advance.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,41 @@ routes:
state: absent
- destination: 0.0.0.0/0
next-hop-address: 4.3.2.254
next-hop-interface: eth0.123
next-hop-interface: vlan0
- destination: 1.2.3.4/32
next-hop-interface: vlan0
EOF


Readonly my $VLAN1_123_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
interfaces:
- ipv4:
address:
- ip: 4.3.2.1
prefix-length: 24
dhcp: false
enabled: true
name: vlan1.123
profile-name: vlan1.123
state: up
type: vlan
vlan:
base-iface: eth0
id: '123'
routes:
config:
- next-hop-interface: vlan1.123
state: absent
- destination: 0.0.0.0/0
next-hop-address: 4.3.2.254
next-hop-interface: vlan1.123
- destination: 1.2.3.4/32
next-hop-interface: vlan1.123
EOF


Readonly my $DHCP_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
Expand Down Expand Up @@ -304,7 +333,10 @@ my $vlanyml = get_file_contents("/etc/nmstate/eth0.123.yml");
is($vlanyml, $VLAN_YML, "Exact eth0.123 vlan yml config");

my $vlanyml2 = get_file_contents("/etc/nmstate/vlan0.yml");
is($vlanyml2, $VLAN0_YML, "Exact vlan0 yml config");
is($vlanyml2, $VLAN0_YML, "Exact vlan0 yml config");

my $vlanyml3 = get_file_contents("/etc/nmstate/vlan1.123.yml");
is($vlanyml3, $VLAN1_123_YML, "Exact vlan1.123 yml config");

my $ibyml = get_file_contents("/etc/nmstate/ib0.yml");
is($ibyml, $IB_YML, "Exact ib0 yml config");
Expand Down Expand Up @@ -332,8 +364,8 @@ ok(command_history_ok([
'/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/vlan1.123.yml',
'/usr/bin/nmstatectl apply /etc/nmstate/bond0.yml',
], []));


done_testing();
12 changes: 9 additions & 3 deletions ncm-network/src/test/resources/nmstate_advance.pan
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ prefix "/system/network/interfaces/eth0.123";
"physdev" = "eth0";
"route/0" = dict("address", "1.2.3.4");

# test vlan interface route on vlan for backward compatibily with network.pm
"/system/network/interfaces/vlan0" = create("defaultinterface");
# test vlan interface vlan0 (interface ID=0/false, no VLAN ID in interface name)
"/system/network/interfaces/vlan0" = create("vlaninterface");
prefix "/system/network/interfaces/vlan0";
"device" = "eth0.123";
"physdev" = "eth0";
"route/0" = dict("address", "1.2.3.4");

# test vlan interface vlan1.123 (interface ID=1/true, VLAN ID in interface name)
"/system/network/interfaces/vlan1.123" = create("vlaninterface");
prefix "/system/network/interfaces/vlan1.123";
"physdev" = "eth0";
"route/0" = dict("address", "1.2.3.4");

# test ib interface (default and with pkey)
prefix "/system/network/interfaces/ib0";
"ip" = "10.11.12.13";
Expand Down Expand Up @@ -72,4 +78,4 @@ prefix "/system/network/interfaces/eth4";
"aliases/dba/broadcast" = "4.3.2.255";
"aliases/dba/fqdn" = "host-alias1.quattor.com";
"aliases/dba/ip" = "4.3.2.12";
"aliases/dba/netmask" = "255.255.255.0";
"aliases/dba/netmask" = "255.255.255.0";

0 comments on commit 11f935b

Please sign in to comment.