From c14472f9b85fa71640cc1257b3a780ac5e6bb98f Mon Sep 17 00:00:00 2001 From: Leigh B Stoller Date: Wed, 24 Oct 2018 13:03:45 -0600 Subject: [PATCH] Fixes for DeleteNodes(): * When deleting a lan can there is only one interface left, need to go back and delete the interface from the last node. Else its a malformed rpsec (which we have been ignoring), but it was passing through to the manifest, which made it a malformed manifest. * But a later bug was causing that now removed interface to sneak back in via the old copy of the manifest in the database. * Also fix a bug that was causing multiple versions of the site_info element to get inserted during an update. * Remove code that updates the manifest in the DB, use the existing Aggregate->UpdateManifest() method instead. --- protogeni/lib/GeniCM.pm.in | 11 ++++++----- protogeni/lib/GeniCMV2.pm.in | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/protogeni/lib/GeniCM.pm.in b/protogeni/lib/GeniCM.pm.in index dce2f11d8..512c7f779 100755 --- a/protogeni/lib/GeniCM.pm.in +++ b/protogeni/lib/GeniCM.pm.in @@ -5044,6 +5044,8 @@ sub SliverWorkAux($) # $inaggregate = 1; $sliver = $nodemap{$virtual_id}; + # Replace the existing rspec/manifest + $sliver->UpdateRspec($ref); } else { $sliver = GeniSliver::Node->Create($slice, $owner, $node, $ref); @@ -5686,7 +5688,8 @@ sub SliverWorkAux($) goto bad; } - my $siteinfo = GeniXML::FindFirst("n:site_info", $manifest); + my $siteinfo = GeniXML::FindFirstNS("n:site_info", $manifest, + $GeniXML::SITEINFO_NS); if (defined($siteinfo)) { # Clean old location. $manifest->removeChild($siteinfo); @@ -5726,11 +5729,9 @@ sub SliverWorkAux($) print STDERR "GeniUsage->NewAggregate($aggregate) failed\n"; } - # This should move someplace else? + $aggregate->UpdateManifest($manifest); + # Need this below. my $manifest_string = GeniXML::Serialize($manifest); - DBQueryWarn("replace into geni_manifests set ". - " manifest=". DBQuoteSpecial($manifest_string) . ", " . - " idx=NULL, slice_uuid='$slice_uuid', created=now()"); # # Cache the credential for subsequent requests. See GetSliver(). diff --git a/protogeni/lib/GeniCMV2.pm.in b/protogeni/lib/GeniCMV2.pm.in index 6550cf502..e5bf76646 100755 --- a/protogeni/lib/GeniCMV2.pm.in +++ b/protogeni/lib/GeniCMV2.pm.in @@ -2398,9 +2398,10 @@ sub DeleteNodes($) # # Suck out nodes. Also figure out what nodes have to be removed - # from which lans. + # from which lans, and which ifaces from which nodes. # - my %ifacestoremovefromlans = (); + my %ifacestoremovefromlans = (); + my %ifacestoremovefromnodes = (); foreach my $noderef (GeniXML::FindNodes("n:node", $manifest)->get_nodelist()) { @@ -2438,9 +2439,29 @@ sub DeleteNodes($) my @ifaces = GeniXML::FindNodes("n:interface_ref", $linkref)->get_nodelist(); if (@ifaces <= 1) { + # Need to find this last iface in the node and delete it + # since otherwise the rspec would be malformed. + foreach my $iref (@ifaces) { + my $client_id = GeniXML::GetInterfaceId($iref); + $ifacestoremovefromnodes{$client_id} = $client_id; + } $manifest->removeChild($linkref); } } + # Purge the ifaces from nodes for links left with just one iface. + if (keys(%ifacestoremovefromnodes)) { + foreach my $noderef (GeniXML::FindNodes("n:node", + $manifest)->get_nodelist()) { + foreach my $iref (GeniXML::FindNodes("n:interface", + $noderef)->get_nodelist()) { + my $client_id = GeniXML::GetInterfaceId($iref); + if (exists($ifacestoremovefromnodes{$client_id})) { + $noderef->removeChild($iref); + } + } + } + } + my $rspecstr = GeniXML::Serialize($manifest); print STDERR "$rspecstr\n"; -- GitLab