-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ncm-network: nmstate - add additional route rule parameters
- provide additional route rule parameters for nmstate config as defined in https://nmstate.io/devel/yaml_api.html#routes
- Loading branch information
Abdul Karim
authored and
Abdul Karim
committed
Sep 18, 2024
1 parent
4057c4b
commit b5de236
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use strict; | ||
use warnings; | ||
|
||
BEGIN { | ||
*CORE::GLOBAL::sleep = sub {}; | ||
} | ||
|
||
use Test::More; | ||
use Test::Quattor qw(nmstate_route_rule); | ||
use Test::MockModule; | ||
use Readonly; | ||
|
||
use NCM::Component::nmstate; | ||
my $mock = Test::MockModule->new('NCM::Component::nmstate'); | ||
my %executables; | ||
$mock->mock('_is_executable', sub {diag "executables $_[1] ",explain \%executables;return $executables{$_[1]};}); | ||
|
||
my $cfg = get_config_for_profile('nmstate_route_rule'); | ||
my $cmp = NCM::Component::nmstate->new('network'); | ||
|
||
Readonly my $RULE_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 | ||
mac-address: 6e:a5:1b:55:77:0a | ||
name: eth0 | ||
profile-name: eth0 | ||
state: up | ||
type: ethernet | ||
route-rules: | ||
config: | ||
- action: unreachable | ||
family: ipv4 | ||
fwmark: '111' | ||
fwmask: '000' | ||
iif: eth0 | ||
ip-to: 1.2.3.4/24 | ||
priority: 100 | ||
- action: prohibit | ||
family: ipv4 | ||
ip-to: 1.2.4.4/24 | ||
priority: 100 | ||
state: absent | ||
routes: | ||
config: | ||
- next-hop-interface: eth0 | ||
state: absent | ||
- destination: 0.0.0.0/0 | ||
next-hop-address: 4.3.2.254 | ||
next-hop-interface: eth0 | ||
EOF | ||
|
||
is($cmp->Configure($cfg), 1, "Component runs correctly with a test profile"); | ||
|
||
my $ruleyml = get_file_contents("/etc/nmstate/eth0.yml"); | ||
is($ruleyml, $RULE_YML, "Exact eth0 rule yml config"); | ||
|
||
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
object template nmstate_route_rule; | ||
|
||
include 'simple_base_profile'; | ||
include 'components/network/config-nmstate'; | ||
|
||
# test for nmstate rule parameters on new interface | ||
"/hardware/cards/nic/eth0/hwaddr" = "6e:a5:1b:55:77:0a"; | ||
prefix "/system/network/interfaces/eth0"; | ||
"rule/0" = dict("to", "1.2.3.4/24", "nmstate-action", "unreachable", | ||
"nmstate-iif", "eth0", "nmstate-fwmask", "000", "nmstate-fwmark", "111"); | ||
"rule/1" = dict("to", "1.2.4.4/24", "nmstate-action", "prohibit", "nmstate-state", "absent"); |