pf-tools/pf-tools: fix du test des clefs obligatoires
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Apr 3 09:39:54 UTC 2014
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/941865e07473
changeset: 1247:941865e07473
user: shad
date: Thu Apr 03 11:39:31 2014 +0200
description:
fix du test des clefs obligatoires
accord doc<=>code pour link et interface
ajout des site et type de link dans le traducteur
le mode des bonding est une option comme une autre
message plus clair lorsqu'un site non défini est utilisé dans un vlan
diffstat:
doc/hostfile-sample | 37 ----------
doc/hostfile-syntax | 2 +-
lib/PFTools/Compat/Translation.pm | 31 ++-----
lib/PFTools/Conf/Syntax.pm | 20 +----
lib/PFTools/Structqueries.pm | 5 +-
t/13.conf.cfg1/config-export/MODEL/model-rdeploy | 1 +
t/13.conf.cfg1/config-export/SITE/cbv4-pfds/CONFIG/hostfile-cbv4-spawn | 7 +-
t/13.conf.cfg1/config-export/SITE/cbv4-pfds/MODEL/model-cbv4-pfds | 4 +
t/13.conf.t | 9 ++
t/20.files.t | 7 +
10 files changed, 45 insertions(+), 78 deletions(-)
diffs (398 lines):
diff -r db767ed9f51f -r 941865e07473 doc/hostfile-sample
--- a/doc/hostfile-sample Tue Apr 01 17:50:29 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-[interface::eth0]
- mac.0 = 00:00:00:00:00:00
- vlan.default = vlan-systeme
- ipv4.default = 3.0
- ipv4.1 = 3.12
-
-[interface::eth0.TAG1]
- vlan.default = vlan-admindsi
- ipv4.default = 12
-
-[interface::bond0]
- slaves.default = eth2,eth3
- mode.default = active-backup
- mode.1 = 802.3ad
- options.1 = xmit_hash_policy=layer3+4,miimon=100
- vlan.default = vlan-pfds-ext
- ipv4.default = 92
- @route = 224.0.0.0/4
- @route = default via gw-pfds.vlan-pfds-ext.private
-
-[deployment]
- mode.default = debian
- arch.default = amd64
- distrib.default = lenny
-
-[hostgroup]
- number = 2
- order = 1
-
-[boot]
- pxefilename.default = pxelinux.0
- kernel.default = vmlinuz-2.6.26.5-universal-grm2.1.12
- console.default = default
-
-[dns]
- resolver.default = vip-spawn.private,nscache.private
- shortname.default = vlan-systeme
diff -r db767ed9f51f -r 941865e07473 doc/hostfile-syntax
--- a/doc/hostfile-syntax Tue Apr 01 17:50:29 2014 +0200
+++ b/doc/hostfile-syntax Thu Apr 03 11:39:31 2014 +0200
@@ -1,5 +1,5 @@
[link::<NETWORK_NAME>]
- ! type[.%HOSTNUM%] ::= ether|bond|bridge
+ ! type[.%HOSTNUM%] ::= ether|bond|bridge|tun|tap
! dev[.%HOSTNUM%] ::= <IFACE_NAME> || NONE if link doesn't exist for the specified %HOSTNUM%
! mac.%HOSTNUM% ::= <MAC_ADDR> WARNING this directive MUST BE defined for interface which is used for deployment
? slaves[.%HOSTNUM%] ::= comma separated list of <IFACE>, WARNING this directive is mandatory if type[.%HOSTNUM%] is defined
diff -r db767ed9f51f -r 941865e07473 lib/PFTools/Compat/Translation.pm
--- a/lib/PFTools/Compat/Translation.pm Tue Apr 01 17:50:29 2014 +0200
+++ b/lib/PFTools/Compat/Translation.pm Thu Apr 03 11:39:31 2014 +0200
@@ -147,8 +147,9 @@
#use Data::Dumper;
#print Dumper $host_parsed;
+ $new_host->{'hostgroup'}->{'site'} = q{UNDEFINED};
$new_host->{'hostgroup'}->{'hostname'} = $hostname;
- $new_host->{'hostgroup'}->{'comment'} = $host_parsed->{'comment'} || q{};
+ $new_host->{'hostgroup'}->{'comment'} = $host_parsed->{'comment'} || q{};
foreach my $key ( keys %{$host_parsed} ) {
if ( $key eq 'shortname' ) {
$new_host->{'dns'}->{'shortname'} = $host_parsed->{'shortname'};
@@ -240,8 +241,6 @@
}
}
}
- if ( defined $host_parsed->{$iface} ) {
- }
}
}
elsif ( $key eq 'alias' ) {
@@ -308,8 +307,8 @@
#use Data::Dumper;
#print Dumper $host_parsed;
- $new_host->{'type'} = q{server};
- $new_host->{'site'} = q{UNDEFINED};
+ $new_host->{'type'} = q{server};
+ $new_host->{'site'} = q{UNDEFINED};
$new_host->{'comment'} = $host_parsed->{'comment'} || q{};
foreach my $key ( keys %{$host_parsed} ) {
if ( $key eq 'shortname' ) {
@@ -324,7 +323,6 @@
my $vlan;
if ( ref $host_parsed->{$key}->{$iface} eq q{} ) {
$vlan = $host_parsed->{$key}->{$iface};
- #$new_host->{ 'link::' . $vlan }->{'dev'} = $iface;
__addvlinksection( $host_parsed, $new_host, $vlan,
$iface );
if ( !$ifacedone->{$iface} ) {
@@ -340,8 +338,6 @@
keys %{ $host_parsed->{$key}->{$iface} } )
{
$vlan = $host_parsed->{$key}->{$iface}->{$hostnum};
- #$new_host->{ 'link::' . $vlan }
- # ->{ 'dev' . qq{.$hostnum} } = $iface;
__addvlinksection( $host_parsed, $new_host, $vlan,
$iface );
if ( !$ifacedone->{$iface} ) {
@@ -366,12 +362,12 @@
}
return $new_host;
}
+
sub __addvlinksection {
my ( $host_parsed, $new_host, $vlan, $iface ) = @_;
if ( defined $host_parsed->{'ipstart'}->{$vlan} ) {
- $new_host->{ 'ipv4.' . $vlan }
- = $host_parsed->{'ipstart'}->{$vlan};
+ $new_host->{ 'ipv4.' . $vlan } = $host_parsed->{'ipstart'}->{$vlan};
}
elsif ( defined $host_parsed->{'ip'}->{$vlan} ) {
foreach my $subkey ( keys %{ $host_parsed->{'ip'}->{$vlan} } ) {
@@ -382,7 +378,7 @@
= $host_parsed->{'ip'}->{$vlan}->{$subkey};
}
else {
- $new_host->{ 'ipv4.' . $vlan . q{.} . $subkey}
+ $new_host->{ 'ipv4.' . $vlan . q{.} . $subkey }
= $host_parsed->{'ip'}->{$vlan}->{$subkey};
}
}
@@ -394,10 +390,10 @@
return;
}
-
sub __addlinksection {
my ( $host_parsed, $new_host, $vlan, $iface ) = @_;
+ $new_host->{ 'link::' . $vlan }->{'type'} = q{ether};
if ( defined $host_parsed->{'ipstart'}->{$vlan} ) {
$new_host->{ 'link::' . $vlan }->{'ipv4'}
= $host_parsed->{'ipstart'}->{$vlan};
@@ -453,6 +449,7 @@
sub __addbondtolink {
my ( $host_parsed, $new_host, $vlan, $iface ) = @_;
if ( $iface =~ /\A bond/xms ) {
+ $new_host->{ 'link::' . $vlan }->{'type'} = q{bond};
if ( ref $host_parsed->{'bonding'}->{$iface} eq 'HASH' ) {
foreach
my $subkey ( keys %{ $host_parsed->{'bonding'}->{$iface} } )
@@ -494,14 +491,8 @@
foreach my $cmd ( split /[ ]/xms, $ref_cmdline->{$cmdline} ) {
if ( $cmd =~ /\A bonding[.](.+) \z/xms ) {
my ( $opt, $val ) = split /=/xms, $1;
- if ( $opt eq 'mode' ) {
- $new_host->{ 'link::' . $vlan }->{$newmode_key}
- = $val;
- }
- else {
- $new_host->{ 'link::' . $vlan }->{$newopt_key}
- = $opt . q{=} . $val . q{ };
- }
+ $new_host->{ 'link::' . $vlan }->{$newopt_key}
+ .= $opt . q{=} . $val . q{ };
}
else {
$new_host->{'boot'}->{$newcmd_key} .= $cmd . q{ };
diff -r db767ed9f51f -r 941865e07473 lib/PFTools/Conf/Syntax.pm
--- a/lib/PFTools/Conf/Syntax.pm Tue Apr 01 17:50:29 2014 +0200
+++ b/lib/PFTools/Conf/Syntax.pm Thu Apr 03 11:39:31 2014 +0200
@@ -155,19 +155,6 @@
'@route' => 'undefined',
'@route6' => 'undefined',
},
- 'interface' => {
- 'MANDATORY_KEYS' => [ 'vlan', 'ipv4', 'slaves' ],
- 'mac' => '([0-9a-f]{2}:){5}[0-9a-f]{2}',
- 'options' => 'undefined',
- 'mode' => '(active-backup|802.3ad|\d+)',
- 'vlan' => '[a-z][a-z0-9\-]+[a-z0-9]',
- 'ipv4' => '(\d{1,3})((\.\d{1,3}){1,3})?',
- 'slaves' => 'e(th)?\d+(\s*,\s*e(th)?\d+)+',
- 'ipv6' => 'undefined',
- 'iface_opt' => 'undefined',
- '@route' => 'undefined',
- '@route6' => 'undefined',
- },
'deployment' => {
'MANDATORY_KEYS' => [ 'arch', 'mode', 'distrib' ],
'arch' => 'i386|amd64',
@@ -424,7 +411,8 @@
# Next if useless checks
next
if $key eq $master_key
- or $definition->{$def_key} eq 'undefined';
+ or defined $definition->{$def_key}
+ and $definition->{$def_key} eq 'undefined';
# Check if key exists
if ( not defined $definition->{$def_key} ) {
@@ -444,9 +432,9 @@
if ($check_mandatory_keys) {
foreach my $key ( @{ $definition->{'MANDATORY_KEYS'} } ) {
- if ( not defined $parsed_keys_list ) {
+ if ( not defined $parsed_keys_list->{$key} ) {
croak
- qq{Mandatory key $key must be defined in section $section_name context $context file $file};
+ qq{ERROR: Mandatory key '$key' must be defined in section '$section_name' context '$context' file '$file'};
}
}
}
diff -r db767ed9f51f -r 941865e07473 lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Tue Apr 01 17:50:29 2014 +0200
+++ b/lib/PFTools/Structqueries.pm Thu Apr 03 11:39:31 2014 +0200
@@ -304,7 +304,6 @@
}
croak qq{ERROR: Host have no interface in vlan '$vlan'};
- return;
}
=head2 get_mode_from_host_ref($host_ref)
@@ -370,7 +369,7 @@
my $site_ref = $global_config->{'SITE'}->{'BY_NAME'}->{$site_name};
- if ( not $site_ref ) {
+ if ( !$site_ref || !%{$site_ref} ) {
croak qq{ERROR: Unknown site '$site_name'};
}
@@ -399,7 +398,7 @@
my $site_ref = $global_config->{'DHCP'}->{'BY_SITE'}->{$site_name};
- if ( not $site_ref ) {
+ if ( !$site_ref || !%{$site_ref} ) {
croak qq{ERROR: Unknown site '$site_name'};
}
diff -r db767ed9f51f -r 941865e07473 t/13.conf.cfg1/config-export/MODEL/model-rdeploy
--- a/t/13.conf.cfg1/config-export/MODEL/model-rdeploy Tue Apr 01 17:50:29 2014 +0200
+++ b/t/13.conf.cfg1/config-export/MODEL/model-rdeploy Thu Apr 03 11:39:31 2014 +0200
@@ -16,6 +16,7 @@
alias.spawn = vlan-systeme
[link::vlan-systeme]
+ type = ether
dev = eth0
#[interface::eth0.TAG1]
diff -r db767ed9f51f -r 941865e07473 t/13.conf.cfg1/config-export/SITE/cbv4-pfds/CONFIG/hostfile-cbv4-spawn
--- a/t/13.conf.cfg1/config-export/SITE/cbv4-pfds/CONFIG/hostfile-cbv4-spawn Tue Apr 01 17:50:29 2014 +0200
+++ b/t/13.conf.cfg1/config-export/SITE/cbv4-pfds/CONFIG/hostfile-cbv4-spawn Thu Apr 03 11:39:31 2014 +0200
@@ -12,6 +12,7 @@
alias.spawn = vlan-systeme
[link::vlan-middledsi]
+ type = ether
dev = eth5
ipv4 = 41
# vlan = vlan-middledsi
@@ -22,13 +23,15 @@
# distrib = lenny
[link::vlan-systeme]
- dev = eth0
+ type = ether
+ dev = eth0
ipv4 = 167.0
mac.1 = 00:1e:c9:ff:42:0a
mac.0 = 00:1e:c9:ff:08:e3
# vlan = vlan-systeme
[link::vlan-pfds-int]
+ type = ether
dev = eth0.TAG1
# vlan = vlan-pfds-int
ipv4 = 167.0
@@ -42,11 +45,13 @@
# site = cbv4-pfds
[link::vlan-admindsi]
+ type = ether
dev = eth4
ipv4 = 41
# vlan = vlan-admindsi
[link::vlan-pfds-ext]
+ type = bond
dev = bond0
# options = miimon=100
ipv4 = 97
diff -r db767ed9f51f -r 941865e07473 t/13.conf.cfg1/config-export/SITE/cbv4-pfds/MODEL/model-cbv4-pfds
--- a/t/13.conf.cfg1/config-export/SITE/cbv4-pfds/MODEL/model-cbv4-pfds Tue Apr 01 17:50:29 2014 +0200
+++ b/t/13.conf.cfg1/config-export/SITE/cbv4-pfds/MODEL/model-cbv4-pfds Thu Apr 03 11:39:31 2014 +0200
@@ -10,6 +10,7 @@
resolver = nsprivate.private,spawn.private
[link::vlan-middledsi]
+ type = ether
dev = eth5
[deployment]
@@ -18,6 +19,7 @@
distrib = lenny
[link::vlan-systeme]
+ type = ether
dev = eth0
[hostgroup]
@@ -25,9 +27,11 @@
site = cbv4-pfds
[link::vlan-admindsi]
+ type = ether
dev = eth4
[link::vlan-pfds-ext]
+ type = bond
dev = bond0
options = miimon=100,mode=active-backup
slaves = eth2,eth3
diff -r db767ed9f51f -r 941865e07473 t/13.conf.t
--- a/t/13.conf.t Tue Apr 01 17:50:29 2014 +0200
+++ b/t/13.conf.t Thu Apr 03 11:39:31 2014 +0200
@@ -654,6 +654,7 @@
'site' => 'cbv4-pfds',
},
'link::vlan-pfds-ext' => {
+ 'type' => 'bond',
'@route' => [
'default via GATEWAY',
],
@@ -663,20 +664,24 @@
'slaves' => 'eth2,eth3',
},
'link::vlan-systeme' => {
+ 'type' => 'ether',
'dev' => 'eth0',
'ipv4' => '167.0',
'mac.0' => '00:1e:c9:ff:08:e3',
'mac.1' => '00:1e:c9:ff:42:0a',
},
'link::vlan-pfds-int' => {
+ 'type' => 'ether',
'dev' => 'eth0.TAG1',
'ipv4' => '167.0',
},
'link::vlan-admindsi' => {
+ 'type' => 'ether',
'dev' => 'eth4',
'ipv4' => '41',
},
'link::vlan-middledsi' => {
+ 'type' => 'ether',
'dev' => 'eth5',
'ipv4' => '41',
},
@@ -722,6 +727,7 @@
'site' => 'cbv4-pfds',
},
'link::vlan-pfds-ext' => {
+ 'type' => 'bond',
'@route' => [
'default via GATEWAY',
],
@@ -730,12 +736,15 @@
'slaves' => 'eth2,eth3',
},
'link::vlan-systeme' => {
+ 'type' => 'ether',
'dev' => 'eth0',
},
'link::vlan-admindsi' => {
+ 'type' => 'ether',
'dev' => 'eth4',
},
'link::vlan-middledsi' => {
+ 'type' => 'ether',
'dev' => 'eth5',
},
};
diff -r db767ed9f51f -r 941865e07473 t/20.files.t
--- a/t/20.files.t Tue Apr 01 17:50:29 2014 +0200
+++ b/t/20.files.t Thu Apr 03 11:39:31 2014 +0200
@@ -427,6 +427,13 @@
qr{ \A ERROR: [ ] Unknown [ ] site [ ] 'foo' [ ] }xms
=> q{Dies if unknown $site_name};
+$args_ref->{'hostname'} = q{cbv4-spawn01};
+$args_ref->{'site_name'} = q{foo};
+$args_ref->{'global_config'}->{'SITE'}->{'BY_NAME'}->{'foo'} = {};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] site [ ] 'foo' [ ] }xms
+ => q{Dies if unknown $site_name but already used in vlan section};
+
$args_ref->{'site_name'} = q{cbv4};
throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
qr{ \A ERROR: [ ] hostname [ ] cbv4-spawn01: [ ] no [ ] configuration [ ] found }xms
More information about the pf-tools-commits
mailing list