Commit 0e8e50eb authored by Nigel Kukard's avatar Nigel Kukard

Merge branch 'nkfixes' into 'master'

Fixes for pool override functionality

See merge request !8
parents ffda0646 28665a2b
Pipeline #2893 failed with stages
...@@ -93,6 +93,7 @@ our (@ISA,@EXPORT,@EXPORT_OK); ...@@ -93,6 +93,7 @@ our (@ISA,@EXPORT,@EXPORT_OK);
setPoolShaperState setPoolShaperState
unsetPoolShaperState unsetPoolShaperState
isPoolIDValid isPoolIDValid
isPoolOverridden
isPoolReady isPoolReady
getEffectivePool getEffectivePool
...@@ -2805,6 +2806,26 @@ sub isPoolReady ...@@ -2805,6 +2806,26 @@ sub isPoolReady
# Function to check if pool is being overridden or not
sub isPoolOverridden
{
my $pid = shift;
if (!isPoolIDValid($pid)) {
return;
}
# Set a property based on if this pool is overridden or not
if (defined($globals->{'Pools'}->{$pid}->{'.applied_overrides'}) &&
(keys %{$globals->{'Pools'}->{$pid}->{'.applied_overrides'}}) > 0) {
return 1;
}
return 0;
}
# Function to return a pool with any items changed as per pool overrides # Function to return a pool with any items changed as per pool overrides
sub getEffectivePool sub getEffectivePool
{ {
...@@ -3353,7 +3374,7 @@ sub createLimit ...@@ -3353,7 +3374,7 @@ sub createLimit
my $poolName = $limitData->{'Username'}; my $poolName = $limitData->{'Username'};
my $poolData = { my $poolData = {
'FriendlyName' => $limitData->{'IPAddress'}, 'FriendlyName' => $limitData->{'FriendlyName'} || $limitData->{'IPAddress'},
'Name' => $poolName, 'Name' => $poolName,
'InterfaceGroupID' => $limitData->{'InterfaceGroupID'}, 'InterfaceGroupID' => $limitData->{'InterfaceGroupID'},
'TrafficClassID' => $limitData->{'TrafficClassID'}, 'TrafficClassID' => $limitData->{'TrafficClassID'},
...@@ -3404,7 +3425,10 @@ sub createPoolOverride ...@@ -3404,7 +3425,10 @@ sub createPoolOverride
# Check that we have at least one match attribute # Check that we have at least one match attribute
my $isValid = 0; my $isValid = 0;
foreach my $item (POOL_OVERRIDE_MATCH_ATTRIBUTES) { foreach my $item (POOL_OVERRIDE_MATCH_ATTRIBUTES) {
$isValid++; # Bump up $isValid if we have a match attribute
if (defined($poolOverrideData->{$item})) {
$isValid++;
}
} }
if (!$isValid) { if (!$isValid) {
$logger->log(LOG_WARN,"[CONFIGMANAGER] Cannot process pool override as there is no selection attribute"); $logger->log(LOG_WARN,"[CONFIGMANAGER] Cannot process pool override as there is no selection attribute");
...@@ -3623,14 +3647,15 @@ sub _resolve_pool_override ...@@ -3623,14 +3647,15 @@ sub _resolve_pool_override
# Loop with the attributes and check for a full match # Loop with the attributes and check for a full match
foreach my $attr (POOL_OVERRIDE_MATCH_ATTRIBUTES) { foreach my $attr (POOL_OVERRIDE_MATCH_ATTRIBUTES) {
# If this attribute in the pool override is set, then lets check it # If this attribute in the pool override is set, then lets check it
if (defined($poolOverride->{$attr}) && $poolOverride->{$attr} ne "") { if (defined($poolOverride->{$attr}) && $poolOverride->{$attr} ne "") {
# Check for match or mismatch # Check for match or mismatch, only if candidate attribute is defined
if (defined($candidate->{$attr}) && $candidate->{$attr} eq $poolOverride->{$attr}) { if (defined($candidate->{$attr})) {
$numMatches++; if ($candidate->{$attr} eq $poolOverride->{$attr}) {
} else { $numMatches++;
$numMismatches++; } else {
$numMismatches++;
}
} }
} }
} }
......
...@@ -315,7 +315,7 @@ sub _session_pool_add ...@@ -315,7 +315,7 @@ sub _session_pool_add
# Grab pool # Grab pool
my $pool; my $pool;
if (!defined($pool = getPool($pid))) { if (!defined($pool = getPool($pid))) {
$logger->log(LOG_ERR,"[TC] Shaper 'remove' event with non existing pool '%s'",$pid); $logger->log(LOG_ERR,"[TC] Shaper 'add' event with non existing pool '%s'",$pid);
return; return;
} }
......
...@@ -59,6 +59,7 @@ use opentrafficshaper::plugins::configmanager qw( ...@@ -59,6 +59,7 @@ use opentrafficshaper::plugins::configmanager qw(
getPool getPool
getPoolByName getPoolByName
getPoolShaperState getPoolShaperState
isPoolOverridden
isPoolReady isPoolReady
getPoolMembers getPoolMembers
...@@ -213,9 +214,9 @@ EOF ...@@ -213,9 +214,9 @@ EOF
# if ($pool->{'Status'} eq 'conflict') { # if ($pool->{'Status'} eq 'conflict') {
# $icons .= '<span class="glyphicon glyphicon-random" />'; # $icons .= '<span class="glyphicon glyphicon-random" />';
# } # }
# if ($pool->{'Status'} eq 'conflict') { if (isPoolOverridden($pool->{'ID'})) {
# $icons .= '<span class="glyphicon glyphicon-edit" />'; $icons .= '<span class="glyphicon glyphicon-edit" />';
# } }
my $urlStatsPool = sprintf('/statistics/by-pool?pool=%s',uri_escape("$pool->{'InterfaceGroupID'}:$pool->{'Name'}")); my $urlStatsPool = sprintf('/statistics/by-pool?pool=%s',uri_escape("$pool->{'InterfaceGroupID'}:$pool->{'Name'}"));
my $urlPoolEdit = sprintf('/limits/pool-edit?pid=%s',uri_escape($pool->{'ID'})); my $urlPoolEdit = sprintf('/limits/pool-edit?pid=%s',uri_escape($pool->{'ID'}));
...@@ -2010,12 +2011,31 @@ sub pool_override_addedit ...@@ -2010,12 +2011,31 @@ sub pool_override_addedit
push(@errors,"Friendly name must be specified"); push(@errors,"Friendly name must be specified");
} }
# Make sure we have at least a pool name, username or IP address # Check the pool name is valid if it was specified
my $poolName = isUsername($formData->{'PoolName'},ISUSERNAME_ALLOW_ATSIGN); my $poolName;
my $username = isUsername($formData->{'Username'},ISUSERNAME_ALLOW_ATSIGN); if (defined($formData->{'PoolName'}) && $formData->{'PoolName'} ne "") {
my $ipAddress = isIPv4($formData->{'IPAddress'}); if (!defined($poolName = isUsername($formData->{'PoolName'},ISUSERNAME_ALLOW_ATSIGN))) {
push(@errors,"Pool name is not valid");
}
}
# Next check the username
my $username;
if (defined($formData->{'Username'}) && $formData->{'Username'} ne "") {
if (!defined($username = isUsername($formData->{'Username'},ISUSERNAME_ALLOW_ATSIGN))) {
push(@errors,"Username is not valid");
}
}
# Then the IP
my $ipAddress;
if (defined($formData->{'IPAddress'}) && $formData->{'IPAddress'} ne "") {
if (!defined($ipAddress = isIPv4($formData->{'IPAddress'}))) {
push(@errors,"IP address is not valid");
}
}
# Then confirm we have at least one of the above
if (!defined($poolName) && !defined($username) && !defined($ipAddress)) { if (!defined($poolName) && !defined($username) && !defined($ipAddress)) {
push(@errors,"A pool name and/or IP address and/or Username must be specified"); push(@errors,"At least a valid pool name, username or IP address must be specified to match");
} }
# If the traffic class is ticked, process it # If the traffic class is ticked, process it
...@@ -2057,7 +2077,7 @@ sub pool_override_addedit ...@@ -2057,7 +2077,7 @@ sub pool_override_addedit
!defined($txCIR) && !defined($txLimit) && !defined($txCIR) && !defined($txLimit) &&
!defined($rxCIR) && !defined($rxLimit) !defined($rxCIR) && !defined($rxLimit)
) { ) {
push(@errors,"Something must be specified to pool override"); push(@errors,"Something must be specified to override");
} }
my $expires = 0; my $expires = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment