Skip to content
Snippets Groups Projects
Commit f06a4deb authored by Malte Bauch's avatar Malte Bauch
Browse files

Resolve "Failed network element creation leads to the return of false error messages"

See merge request !618
parent fd6542d5
No related branches found
No related tags found
1 merge request!618Resolve "Failed network element creation leads to the return of false error messages"
Pipeline #169388 passed
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
aGNMI "code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi" aGNMI "code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
"github.com/bufbuild/protovalidate-go" "github.com/bufbuild/protovalidate-go"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/go-multierror"
"github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
...@@ -568,8 +569,18 @@ func (n *NetworkElementServer) AddList(ctx context.Context, request *mnepb.AddLi ...@@ -568,8 +569,18 @@ func (n *NetworkElementServer) AddList(ctx context.Context, request *mnepb.AddLi
}, nil }, nil
} }
func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb.TransportOption, requestPluginFunc func(uuid.UUID) (plugin.Plugin, error), pluginID uuid.UUID, pndID uuid.UUID, optionalNetworkElementID ...uuid.UUID) (uuid.UUID, error) { func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb.TransportOption, requestPluginFunc func(uuid.UUID) (plugin.Plugin, error), pluginID uuid.UUID, pndID uuid.UUID, optionalNetworkElementID ...uuid.UUID) (mneId uuid.UUID, err error) {
var err error var plugin plugin.Plugin
var mne networkelement.NetworkElement
defer func() {
if err != nil && plugin != nil {
// clean up plugin
if pErr := plugin.Remove(); pErr != nil {
err = multierror.Append(err, pErr)
}
}
}()
networkElementID := uuid.Nil networkElementID := uuid.Nil
if len(optionalNetworkElementID) > 0 { if len(optionalNetworkElementID) > 0 {
...@@ -580,38 +591,29 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb ...@@ -580,38 +591,29 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb
requestPluginFunc = n.pluginService.RequestPlugin requestPluginFunc = n.pluginService.RequestPlugin
} }
plugin, err := requestPluginFunc(pluginID) plugin, err = requestPluginFunc(pluginID)
if err != nil { if err != nil {
return uuid.Nil, err return uuid.Nil, err
} }
mne, err := nucleus.NewNetworkElement(name, networkElementID, opt, pndID, plugin, conflict.Metadata{ResourceVersion: 0}) mne, err = nucleus.NewNetworkElement(name, networkElementID, opt, pndID, plugin, conflict.Metadata{ResourceVersion: 0})
if err != nil { if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
return uuid.Nil, err return uuid.Nil, err
} }
if mne.IsTransportValid() { if mne.IsTransportValid() {
err := n.initialNetworkElementRootPathRequest(ctx, mne, plugin) err = n.initialNetworkElementRootPathRequest(ctx, mne, plugin)
if err != nil { if err != nil {
return uuid.Nil, err return uuid.Nil, err
} }
err = n.mneService.Add(mne) err = n.mneService.Add(mne)
if err != nil { if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
return uuid.Nil, err return uuid.Nil, err
} }
err = n.pluginService.Add(plugin) err = n.pluginService.Add(plugin)
if err != nil { if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
if err := n.mneService.Delete(mne); err != nil { if err := n.mneService.Delete(mne); err != nil {
return uuid.Nil, err return uuid.Nil, err
} }
...@@ -620,10 +622,8 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb ...@@ -620,10 +622,8 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb
n.networkElementWatchter.SubscribeToNetworkElement(mne, config.GetGnmiSubscriptionPaths(), nil) n.networkElementWatchter.SubscribeToNetworkElement(mne, config.GetGnmiSubscriptionPaths(), nil)
} else { } else {
if pluginRmErr := plugin.Remove(); err != nil { err = fmt.Errorf("invalid transport data provided")
return uuid.Nil, pluginRmErr return uuid.Nil, err
}
return uuid.Nil, fmt.Errorf("invalid transport data provided")
} }
return mne.ID(), nil return mne.ID(), nil
...@@ -632,17 +632,11 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb ...@@ -632,17 +632,11 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb
func (n *NetworkElementServer) initialNetworkElementRootPathRequest(ctx context.Context, mne networkelement.NetworkElement, plugin plugin.Plugin) error { func (n *NetworkElementServer) initialNetworkElementRootPathRequest(ctx context.Context, mne networkelement.NetworkElement, plugin plugin.Plugin) error {
resp, err := n.getPath(ctx, mne, "/") resp, err := n.getPath(ctx, mne, "/")
if err != nil { if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return pluginRmErr
}
return err return err
} }
err = mne.ProcessResponse(resp) err = mne.ProcessResponse(resp)
if err != nil { if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return pluginRmErr
}
return err return err
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment