Skip to content

Commit

Permalink
nmstate: support VLAN interface name without partition number
Browse files Browse the repository at this point in the history
- E.g. vlan.456
- Test added for this use case
  • Loading branch information
jouvin committed Oct 28, 2024
1 parent 4dc5fff commit 7568224
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sub is_valid_interface
(?: \A | / )
# $1 will capture for example:
# eth0 bond1 eth0.101 bond0.102 or dummy_$key
( \w+ \d+ (?: \. \d+ )? | dummy_.* )
( \w+ \d* (?: \. \d+ )? | dummy_.* )
# Suffix (not captured)
\. yml \z
}x
Expand Down
33 changes: 33 additions & 0 deletions ncm-network/src/test/perl/nmstate_advance.t
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ routes:
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 @@ -338,6 +367,9 @@ 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 Down Expand Up @@ -365,6 +397,7 @@ ok(command_history_ok([
'/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/vlan.456.yml',
'/usr/bin/nmstatectl apply /etc/nmstate/bond0.yml',
], []));

Expand Down
6 changes: 6 additions & 0 deletions ncm-network/src/test/resources/nmstate_advance.pan
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ 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

0 comments on commit 7568224

Please sign in to comment.