forked from quattor/configuration-modules-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14a5f7d
commit e3245cc
Showing
9 changed files
with
317 additions
and
47 deletions.
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,181 @@ | ||
use strict; | ||
use warnings; | ||
|
||
BEGIN { | ||
*CORE::GLOBAL::sleep = sub {}; | ||
} | ||
|
||
use Test::More; | ||
use Test::Quattor qw(nmstate_advance); | ||
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_advance'); | ||
my $cmp = NCM::Component::nmstate->new('network'); | ||
|
||
Readonly my $ETH0_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: | ||
- family: ipv4 | ||
ip-to: 1.2.3.4/24 | ||
priority: 100 | ||
route-table: '4' | ||
- route-table: '4' | ||
state: absent | ||
routes: | ||
config: | ||
- next-hop-interface: eth0 | ||
state: absent | ||
- destination: 1.2.3.4/32 | ||
next-hop-interface: eth0 | ||
- destination: 1.2.3.5/24 | ||
next-hop-interface: eth0 | ||
- destination: 1.2.3.6/8 | ||
next-hop-address: 4.3.2.1 | ||
next-hop-interface: eth0 | ||
- destination: 1.2.3.7/32 | ||
next-hop-address: 4.3.2.2 | ||
next-hop-interface: eth0 | ||
- destination: 0.0.0.0/0 | ||
next-hop-address: 4.3.2.3 | ||
next-hop-interface: eth0 | ||
table-id: '3' | ||
EOF | ||
|
||
Readonly my $VLAN_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: eth0.123 | ||
profile-name: eth0.123 | ||
state: up | ||
type: vlan | ||
vlan: | ||
base-iface: eth0 | ||
id: '123' | ||
routes: | ||
config: | ||
- next-hop-interface: eth0.123 | ||
state: absent | ||
- destination: 1.2.3.4/32 | ||
next-hop-interface: eth0.123 | ||
EOF | ||
|
||
Readonly my $DHCP_YML => <<EOF; | ||
# File generated by NCM::Component::nmstate. Do not edit | ||
--- | ||
interfaces: | ||
- ipv4: | ||
dhcp: true | ||
enabled: true | ||
mac-address: 6e:a5:1b:55:77:0b | ||
name: eth1 | ||
profile-name: eth1 | ||
state: up | ||
type: ethernet | ||
routes: | ||
config: | ||
- next-hop-interface: eth1 | ||
state: absent | ||
EOF | ||
|
||
Readonly my $BOND_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 | ||
link-aggregation: | ||
port: | ||
- eth2 | ||
- eth3 | ||
name: bond0 | ||
profile-name: bond0 | ||
state: up | ||
type: bond | ||
routes: | ||
config: | ||
- next-hop-interface: bond0 | ||
state: absent | ||
EOF | ||
|
||
|
||
Readonly my $RT => <<EOF; | ||
# | ||
# reserved values | ||
# | ||
255 local | ||
254 main | ||
253 default | ||
0 unspec | ||
# | ||
# local | ||
# | ||
#1 inr.ruhep | ||
EOF | ||
|
||
Readonly my $RT_NEW => <<EOF; | ||
# | ||
# reserved values | ||
# | ||
255 local | ||
254 main | ||
253 default | ||
0 unspec | ||
# | ||
# local | ||
# | ||
#1 inr.ruhep | ||
3 outside # managed by Quattor | ||
4 space # managed by Quattor | ||
EOF | ||
|
||
# File must exist, set with correct content | ||
set_file_contents("/etc/iproute2/rt_tables", $RT); | ||
|
||
is($cmp->Configure($cfg), 1, "Component runs correctly with a test profile"); | ||
|
||
is(get_file_contents("/etc/iproute2/rt_tables"), $RT_NEW, "Exact routing table"); | ||
|
||
my $eth0yml = get_file_contents("/etc/nmstate/eth0.yml"); | ||
is($eth0yml, $ETH0_YML, "Exact eth0 route yml config"); | ||
|
||
my $dhcpyml = get_file_contents("/etc/nmstate/eth1.yml"); | ||
is($dhcpyml, $DHCP_YML, "Exact eth1 dhcp yml config"); | ||
|
||
my $bondyml = get_file_contents("/etc/nmstate/bond0.yml"); | ||
is($bondyml, $BOND_YML, "Exact bond0 yml config"); | ||
|
||
my $vlanyml = get_file_contents("/etc/nmstate/eth0.123.yml"); | ||
is($vlanyml, $VLAN_YML, "Exact eth0.123 vlan 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
Oops, something went wrong.