Skip to content

Commit

Permalink
ncm-network: nmstate change the way dummy interfaces are created.
Browse files Browse the repository at this point in the history
use key instead of index to label dummy interface. This will allow
referencing the correct vip elsewhere in pan or external applications.
Add tests.
  • Loading branch information
Abdul Karim authored and Abdul Karim committed May 7, 2024
1 parent dba7d73 commit c6f5502
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,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
( \w+ \d+ (?: \. \d+ )? )
# eth0 bond1 eth0.101 bond0.102 or dummy_$key
( \w+ \d+ (?: \. \d+ )? | dummy_.* )
# Suffix (not captured)
\. yml \z
}x
Expand Down Expand Up @@ -717,13 +717,11 @@ sub Configure
if ($net->{manage_vips} && defined($net->{vips})) {
$self->verbose("Service address vips found, configuring dummy interfaces");
my $vips = $net->{vips};
my $idx = 0;
foreach my $name (sort keys %$vips) {
my $dummy_name = "dummy$idx";
my $dummy_name = "dummy_$name";
my $nmstate_dummy_cfg = $self->generate_vip_config($dummy_name, $vips->{$name});
my $dummy_filename = $self->iface_filename($dummy_name);
$exifiles->{$dummy_filename} = $self->nmstate_file_dump($dummy_filename, $nmstate_dummy_cfg);
$idx++;
}
};

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 @@ -166,6 +166,20 @@ routes:
next-hop-interface: bond0
EOF

Readonly my $DUMMY_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
interfaces:
- ipv4:
address:
- ip: 4.3.2.10
prefix-length: 32
enabled: true
name: dummy_myvip
profile-name: dummy_myvip
state: up
type: dummy
EOF

Readonly my $IB_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
Expand Down Expand Up @@ -272,5 +286,7 @@ is($ibyml, $IB_YML, "Exact ib0 yml config");
my $ibpkyml = get_file_contents("/etc/nmstate/ib1.12345.yml");
is($ibpkyml, $IBPKEY_YML, "Exact ib1 pkey yml config");

my $dummy_yml = get_file_contents("/etc/nmstate/dummy_myvip.yml");
is($dummy_yml, $DUMMY_YML, "Exact dummy interface yml config");

done_testing();
7 changes: 7 additions & 0 deletions ncm-network/src/test/resources/nmstate_advance.pan
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ prefix "/system/network/interfaces/ib1.12345";
"netmask" = "255.255.255.0";
"broadcast" = "10.11.15.255";
"type" = "Infiniband";

# Test creating dummy interface. aka loopback interface needed for vip, such as zebra.
"/system/network/manage_vips" = true;
prefix "/system/network/vips/myvip";
"fqdn" = "myvip.test.com";
"ip" = "4.3.2.10";
"interfaces/0" = "eth0";

0 comments on commit c6f5502

Please sign in to comment.