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-nmstate: relax syntax of VLAN interface names #1679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 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 All @@ -64,8 +66,8 @@ sub is_valid_interface
# Filename is either right at the beginning or following a slash
(?: \A | / )
# $1 will capture for example:
# eth0 bond1 eth0.101 bond0.102 or dummy_$key
( \w+ \d+ (?: \. \d+ )? | dummy_.* )
# eth0 bond1 eth0.101 bond0.102 vlan.456 or dummy_$key
( \w+ \d+ (?: \. \d+ )? | \w+ \. \d+ | dummy_.* )
jrha marked this conversation as resolved.
Show resolved Hide resolved
# Suffix (not captured)
\. yml \z
}x
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
71 changes: 68 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,70 @@ 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 $VLAN_456_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: vlan.456
profile-name: vlan.456
state: up
type: vlan
vlan:
base-iface: eth0
id: '456'
routes:
config:
- next-hop-interface: vlan.456
state: absent
- destination: 0.0.0.0/0
next-hop-address: 4.3.2.254
next-hop-interface: vlan.456
- destination: 1.2.3.4/32
next-hop-interface: vlan.456
EOF


Readonly my $DHCP_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
Expand Down Expand Up @@ -304,7 +362,13 @@ 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 $vlanyml4 = get_file_contents("/etc/nmstate/vlan.456.yml");
is($vlanyml4, $VLAN_456_YML, "Exact vlan.456 yml config");

my $ibyml = get_file_contents("/etc/nmstate/ib0.yml");
is($ibyml, $IB_YML, "Exact ib0 yml config");
Expand All @@ -331,9 +395,10 @@ ok(command_history_ok([
'/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/vlan.456.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();
18 changes: 15 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,25 @@ 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 vlan interface vlan.456 (no partition number, VLAN ID in interface name)
"/system/network/interfaces/vlan.456" = create("vlaninterface");
prefix "/system/network/interfaces/vlan.456";
"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 +84,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";