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

Catch missing errors thrown by plugin.Remove

The initialNetworkElementRootPathRequest() method has been added to reduce
complexity within the addMne() method.
parent df3efdc9
No related branches found
No related tags found
No related merge requests found
Pipeline #164129 passed
......@@ -723,49 +723,67 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb
mne, err := nucleus.NewNetworkElement(name, networkElementID, opt, pndID, plugin, conflict.Metadata{ResourceVersion: 0})
if err != nil {
plugin.Remove()
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
return uuid.Nil, err
}
if mne.IsTransportValid() {
resp, err := n.getPath(ctx, mne, "/")
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
err = mne.ProcessResponse(resp)
err := n.initialNetworkElementRootPathRequest(ctx, mne, plugin)
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
err = n.mneService.Add(mne)
if err != nil {
plugin.Remove()
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
return uuid.Nil, err
}
err = n.pluginService.Add(plugin)
if err != nil {
if err := plugin.Remove(); err != nil {
return uuid.Nil, status.Errorf(codes.Internal, "failed to clean up plugin: ", err)
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
if err := n.mneService.Delete(mne); err != nil {
return uuid.Nil, status.Errorf(codes.Internal, "failed to clean up device: ", err)
return uuid.Nil, err
}
return uuid.Nil, err
}
n.networkElementWatchter.SubscribeToNetworkElement(mne, config.GetGnmiSubscriptionPaths(), nil)
} else {
plugin.Remove()
return uuid.Nil, status.Errorf(codes.InvalidArgument, "invalid transport data provided")
if pluginRmErr := plugin.Remove(); err != nil {
return uuid.Nil, pluginRmErr
}
return uuid.Nil, fmt.Errorf("invalid transport data provided")
}
return mne.ID(), nil
}
func (n *NetworkElementServer) initialNetworkElementRootPathRequest(ctx context.Context, mne networkelement.NetworkElement, plugin plugin.Plugin) error {
resp, err := n.getPath(ctx, mne, "/")
if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return pluginRmErr
}
return err
}
err = mne.ProcessResponse(resp)
if err != nil {
if pluginRmErr := plugin.Remove(); err != nil {
return pluginRmErr
}
return err
}
return nil
}
// SetChangeList sets a list of changes.
func (n *NetworkElementServer) SetChangeList(ctx context.Context, request *mnepb.SetChangeListRequest) (*mnepb.SetChangeListResponse, error) {
labels := prometheus.Labels{"service": "mne", "rpc": "set"}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment