Skip to content

Commit

Permalink
fix case where nodes incorrectly loaded in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jonstout committed Nov 12, 2021
1 parent 31f5ea0 commit b94b909
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions perl-lib/OESS/lib/OESS/DB/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ sub fetch{

my $node_id = $params{'node_id'};
my $node_name = $params{'name'};
my $short_name = $params{'short_name'};
my $details;

my $node;

if (defined $node_id) {
$node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.node_id=? and node_instantiation.end_epoch=-1", [ $node_id ]);
}
elsif (defined $short_name) {
$node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.short_name=? and node_instantiation.end_epoch=-1", [ $short_name ]);
} else {
$node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.name=? and node_instantiation.end_epoch=-1", [ $node_name ]);
}
Expand Down
38 changes: 19 additions & 19 deletions perl-lib/OESS/lib/OESS/NSO/FWDCTL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ sub diff {
# Needed to ensure diff state may be set to PENDING_DIFF_NONE after approval
my $all_nodes = OESS::DB::Node::fetch_all(db => $self->{db}, controller => 'nso');
foreach my $node (@$all_nodes) {
$network_diff->{$node->{name}} = "";
$network_diff->{$node->{short_name}} = "";
}

foreach my $node_hash (@$all_nodes) {
Expand Down Expand Up @@ -346,30 +346,30 @@ sub diff {
# If the database asserts there is no diff pending but memory
# disagrees, then the pending state was modified by an admin. The
# pending diff may now proceed.
foreach my $node_name (keys %$network_diff) {
my $node = new OESS::Node(db => $self->{db}, name => $node_name);
my $diff_len = length $network_diff->{$node_name};
foreach my $short_node_name (keys %$network_diff) {
my $node = new OESS::Node(db => $self->{db}, short_name => $short_node_name);
my $diff_len = length $network_diff->{$short_node_name};

if ($diff_len < 30) {
$self->{pending_diff}->{$node_name} = PENDING_DIFF_NONE;
$self->{pending_diff}->{$short_node_name} = PENDING_DIFF_NONE;
$node->pending_diff(PENDING_DIFF_NONE);
$node->update;
$self->{logger}->info("Applying network diff. No approval required for $node_name.") if $diff_len > 0;
$self->{logger}->info("Applying network diff. No approval required for $short_node_name.") if $diff_len > 0;
} else {
if ($self->{pending_diff}->{$node_name} == PENDING_DIFF_NONE) {
$self->{pending_diff}->{$node_name} = PENDING_DIFF;
if ($self->{pending_diff}->{$short_node_name} == PENDING_DIFF_NONE) {
$self->{pending_diff}->{$short_node_name} = PENDING_DIFF;
$node->pending_diff(PENDING_DIFF);
$node->update;
$self->{logger}->info("Not applying network diff. Manual approval required for $node_name.");
$self->{logger}->info("Not applying network diff. Manual approval required for $short_node_name.");
}

if ($self->{pending_diff}->{$node_name} == PENDING_DIFF && $node->pending_diff == PENDING_DIFF_NONE) {
$self->{pending_diff}->{$node_name} = PENDING_DIFF_APPROVED;
$self->{logger}->info("Applying network diff. Manual approval granted for $node_name.");
if ($self->{pending_diff}->{$short_node_name} == PENDING_DIFF && $node->pending_diff == PENDING_DIFF_NONE) {
$self->{pending_diff}->{$short_node_name} = PENDING_DIFF_APPROVED;
$self->{logger}->info("Applying network diff. Manual approval granted for $short_node_name.");
}
}

$self->{logger}->debug("Diff for $node_name has length of $diff_len:\n$network_diff->{$node_name}");
$self->{logger}->debug("Diff for $short_node_name has length of $diff_len:\n$network_diff->{$short_node_name}");
}
$self->{logger}->debug('Changes: ' . Dumper($changes));

Expand All @@ -380,7 +380,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->endpoints}) {
if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand All @@ -402,7 +402,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->endpoints}) {
if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand All @@ -424,7 +424,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->{endpoint}}) {
if ($self->{pending_diff}->{$ep->{device}} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->{short_node_name}} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand All @@ -445,7 +445,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->endpoints}) {
if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand All @@ -467,7 +467,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->endpoints}) {
if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand All @@ -489,7 +489,7 @@ sub diff {
# If conn endpoint on node with a blocked diff skip
my $diff_approval_required = 0;
foreach my $ep (@{$conn->{endpoint}}) {
if ($self->{pending_diff}->{$ep->{device}} == PENDING_DIFF) {
if ($self->{pending_diff}->{$ep->{short_node_name}} == PENDING_DIFF) {
$diff_approval_required = 1;
last;
}
Expand Down
14 changes: 8 additions & 6 deletions perl-lib/OESS/lib/OESS/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ sub new{
my $class = ref($that) || $that;

my %args = (
db => undef,
logger => Log::Log4perl->get_logger("OESS.Node"),
name => undef,
node_id => undef,
db => undef,
logger => Log::Log4perl->get_logger("OESS.Node"),
name => undef,
node_id => undef,
short_name => undef,
@_
);
my $self = \%args;

bless $self, $class;


if (defined $self->{db} && (defined $self->{name} || defined $self->{node_id})) {
if (defined $self->{db} && (defined $self->{name} || defined $self->{short_name} || defined $self->{node_id})) {
$self->_fetch_from_db();
return $self;
} else {
Expand Down Expand Up @@ -97,7 +98,8 @@ sub _fetch_from_db{
my $hash = OESS::DB::Node::fetch(
db => $db,
name => $self->{name},
node_id => $self->{node_id}
node_id => $self->{node_id},
short_name => $self->{short_name}
);
$self->from_hash($hash);
}
Expand Down

0 comments on commit b94b909

Please sign in to comment.