TT#168102 ngcp-instances-validator: Reformat tabs to 4 spaces

This is our prevalent coding convention.

Change-Id: Id6056da575fca24709d684c50739944b6c92e0d0
mr11.0
Guillem Jover 4 years ago
parent b54ff7a6ad
commit 9d1093eebd

@ -24,17 +24,17 @@ my $yaml = YAML::XS::LoadFile($network_file)
sub get_instance
{
my ($instances, $name) = @_;
my $instance_found;
foreach my $instance ( @{ $instances } ) {
if ($instance->{name} eq $name) {
$instance_found = $instance;
last;
}
}
my ($instances, $name) = @_;
my $instance_found;
foreach my $instance ( @{ $instances } ) {
if ($instance->{name} eq $name) {
$instance_found = $instance;
last;
}
}
return $instance_found;
return $instance_found;
}
sub dup_check
@ -54,100 +54,99 @@ sub dup_check
# only run these checks, if we have any of instances defined
if (exists $yaml->{instances}) {
my $errors = 0;
my %duplicate_name_with_another_instance;
my %duplicated_connections;
my @instances_names = ();
my @hosts_names = ();
my $i = 0;
# get existing instances names
foreach my $instance ( @{ $yaml->{instances} } )
{
push(@instances_names, $instance->{name});
}
# get existing hosts names
foreach my $hostname (sort keys %{$yaml->{hosts}})
{
push(@hosts_names, $hostname);
}
# cycle through all existing instances definitions to find mistakes in connections
foreach my $instance ( @{ $yaml->{instances} } )
{
my $instance_host = $instance->{host};
my $j = 0;
# just in case, catch name duplicates used for general instances names
push @{$duplicate_name_with_another_instance{"$instance->{name}"}}, "instance number: $i";
# iterate through the list of connections
foreach my $instance_connection ( @{ $instance->{connections} } )
{
# catch connections names duplicates of each given instance
my $instance_connection_id = $instance->{name} . ': ' . $instance_connection->{name};
push @{$duplicated_connections{"$instance_connection_id"}}, "con #$j: $instance_connection->{name} ;";
# iterate through the list of connection links
foreach my $instance_connection_link ( @{ $instance_connection->{links} } )
{
my $instance_connection_link_name = $instance_connection_link->{name};
# check that each connection of type instance/host indeed exists
if ($instance_connection_link->{type} eq 'instance') {
unless ( grep { /^$instance_connection_link_name$/ } @instances_names ) {
warn " - required instance: $instance_connection_link->{name} for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
} elsif ($instance_connection_link->{type} eq 'host') {
unless ( grep { /^$instance_connection_link_name$/ } @hosts_names ) {
warn " - required host: $instance_connection_link->{name} for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
}
# iterate through the list of link interfaces
foreach my $link_iface ( @{ $instance_connection_link->{interfaces} } )
{
my $link_iface_name = $link_iface->{name};
my $found = 0;
my $remote_instance = get_instance($yaml->{instances}, $instance_connection_link_name);
# requested instance must indeed have requested interface, otherwise not possible to interconnect
foreach my $remote_iface ( @{ $remote_instance->{interfaces} } )
{
if ($remote_iface->{name} eq $link_iface_name) { $found = 1; }
}
if ($found != 1) {
warn " - required link iface: $link_iface_name for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
}
}
$j++;
}
# just in case, check also that a host, on which we must run this instance, exists
unless ( grep { /^$instance_host$/ } @hosts_names ) {
warn " - required host: $instance->{host} for instance: $instance->{name} does not exist\n";
$errors ++;
}
$i++;
}
# check duplicates and raise an error if found
$errors += dup_check(\%duplicate_name_with_another_instance, '[/instances/<name>] Duplicate instance name with an existing instance');
$errors += dup_check(\%duplicated_connections, '[/instances/<name>] Duplicate connetion name');
my $errors = 0;
my %duplicate_name_with_another_instance;
my %duplicated_connections;
my @instances_names = ();
my @hosts_names = ();
my $i = 0;
# get existing instances names
foreach my $instance ( @{ $yaml->{instances} } )
{
push(@instances_names, $instance->{name});
}
# get existing hosts names
foreach my $hostname (sort keys %{$yaml->{hosts}})
{
push(@hosts_names, $hostname);
}
# cycle through all existing instances definitions to find mistakes in connections
foreach my $instance ( @{ $yaml->{instances} } )
{
my $instance_host = $instance->{host};
my $j = 0;
# just in case, catch name duplicates used for general instances names
push @{$duplicate_name_with_another_instance{"$instance->{name}"}}, "instance number: $i";
# iterate through the list of connections
foreach my $instance_connection ( @{ $instance->{connections} } )
{
# catch connections names duplicates of each given instance
my $instance_connection_id = $instance->{name} . ': ' . $instance_connection->{name};
push @{$duplicated_connections{"$instance_connection_id"}}, "con #$j: $instance_connection->{name} ;";
# iterate through the list of connection links
foreach my $instance_connection_link ( @{ $instance_connection->{links} } )
{
my $instance_connection_link_name = $instance_connection_link->{name};
# check that each connection of type instance/host indeed exists
if ($instance_connection_link->{type} eq 'instance') {
unless ( grep { /^$instance_connection_link_name$/ } @instances_names ) {
warn " - required instance: $instance_connection_link->{name} for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
} elsif ($instance_connection_link->{type} eq 'host') {
unless ( grep { /^$instance_connection_link_name$/ } @hosts_names ) {
warn " - required host: $instance_connection_link->{name} for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
}
# iterate through the list of link interfaces
foreach my $link_iface ( @{ $instance_connection_link->{interfaces} } )
{
my $link_iface_name = $link_iface->{name};
my $found = 0;
my $remote_instance = get_instance($yaml->{instances}, $instance_connection_link_name);
# requested instance must indeed have requested interface, otherwise not possible to interconnect
foreach my $remote_iface ( @{ $remote_instance->{interfaces} } )
{
if ($remote_iface->{name} eq $link_iface_name) { $found = 1; }
}
if ($found != 1) {
warn " - required link iface: $link_iface_name for instance connection from: $instance->{name} does not exist\n";
$errors ++;
}
}
}
$j++;
}
# just in case, check also that a host, on which we must run this instance, exists
unless ( grep { /^$instance_host$/ } @hosts_names ) {
warn " - required host: $instance->{host} for instance: $instance->{name} does not exist\n";
$errors ++;
}
$i++;
}
# check duplicates and raise an error if found
$errors += dup_check(\%duplicate_name_with_another_instance, '[/instances/<name>] Duplicate instance name with an existing instance');
$errors += dup_check(\%duplicated_connections, '[/instances/<name>] Duplicate connetion name');
exit 1 if $errors;
exit 1 if $errors;
}
1;

Loading…
Cancel
Save