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

Update return values of some of the methods of PndAdapter

parent d196195c
No related branches found
No related tags found
1 merge request!284Improve usability and better output formatting for gosndc
Pipeline #99456 passed
This commit is part of merge request !284. Comments created here will be created in the context of that merge request.
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors" "code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/openconfig/goyang/pkg/yang" "github.com/openconfig/goyang/pkg/yang"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
...@@ -106,17 +105,16 @@ func (p *PndAdapter) RemovePnd(pid uuid.UUID) (*core.DeletePndResponse, error) { ...@@ -106,17 +105,16 @@ func (p *PndAdapter) RemovePnd(pid uuid.UUID) (*core.DeletePndResponse, error) {
// ChangeOND sends an API call to the controller requesting the creation of // ChangeOND sends an API call to the controller requesting the creation of
// a change from the provided Operation, path and value. The Change is marked // a change from the provided Operation, path and value. The Change is marked
// as Pending and times out after the specified timeout period // as Pending and times out after the specified timeout period
func (p *PndAdapter) ChangeOND(duid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) (uuid.UUID, error) { func (p *PndAdapter) ChangeOND(duid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) (*ppb.SetPathListResponse, error) {
var v string var v string
if len(value) != 0 { if len(value) != 0 {
v = value[0] v = value[0]
} }
resp, err := api.ChangeRequest(p.endpoint, duid.String(), p.id.String(), path, v, operation) resp, err := api.ChangeRequest(p.endpoint, duid.String(), p.id.String(), path, v, operation)
if err != nil { if err != nil {
return uuid.Nil, err return nil, err
} }
log.Info(resp) return resp, err
return uuid.Nil, err
} }
// Request sends an API call to the controller requesting the specified path // Request sends an API call to the controller requesting the specified path
...@@ -221,23 +219,21 @@ func (p *PndAdapter) GetChange(uuid.UUID) (change.Change, error) { ...@@ -221,23 +219,21 @@ func (p *PndAdapter) GetChange(uuid.UUID) (change.Change, error) {
} }
// Commit sends an API call to the controller committing the specified change // Commit sends an API call to the controller committing the specified change
func (p *PndAdapter) Commit(cuid uuid.UUID) error { func (p *PndAdapter) Commit(cuid uuid.UUID) (*ppb.SetChangeListResponse, error) {
resp, err := api.Commit(p.endpoint, p.id.String(), cuid.String()) resp, err := api.Commit(p.endpoint, p.id.String(), cuid.String())
if err != nil { if err != nil {
return err return nil, err
} }
log.Info(resp) return resp, nil
return nil
} }
// Confirm sends an API call to the controller confirming the specified change // Confirm sends an API call to the controller confirming the specified change
func (p *PndAdapter) Confirm(cuid uuid.UUID) error { func (p *PndAdapter) Confirm(cuid uuid.UUID) (*ppb.SetChangeListResponse, error) {
resp, err := api.Confirm(p.endpoint, p.id.String(), cuid.String()) resp, err := api.Confirm(p.endpoint, p.id.String(), cuid.String())
if err != nil { if err != nil {
return err return nil, err
} }
log.Info(resp) return resp, nil
return nil
} }
func filterChanges(state ppb.ChangeState, resp *ppb.GetChangeListResponse) []uuid.UUID { func filterChanges(state ppb.ChangeState, resp *ppb.GetChangeListResponse) []uuid.UUID {
......
...@@ -473,7 +473,7 @@ func TestPndAdapter_Commit(t *testing.T) { ...@@ -473,7 +473,7 @@ func TestPndAdapter_Commit(t *testing.T) {
id: tt.fields.id, id: tt.fields.id,
endpoint: tt.fields.endpoint, endpoint: tt.fields.endpoint,
} }
if err := p.Commit(tt.args.cuid); (err != nil) != tt.wantErr { if _, err := p.Commit(tt.args.cuid); (err != nil) != tt.wantErr {
t.Errorf("PndAdapter.Commit() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("PndAdapter.Commit() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
...@@ -502,7 +502,7 @@ func TestPndAdapter_Confirm(t *testing.T) { ...@@ -502,7 +502,7 @@ func TestPndAdapter_Confirm(t *testing.T) {
id: tt.fields.id, id: tt.fields.id,
endpoint: tt.fields.endpoint, endpoint: tt.fields.endpoint,
} }
if err := p.Confirm(tt.args.cuid); (err != nil) != tt.wantErr { if _, err := p.Confirm(tt.args.cuid); (err != nil) != tt.wantErr {
t.Errorf("PndAdapter.Confirm() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("PndAdapter.Confirm() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
......
...@@ -50,9 +50,13 @@ Change UUID must be specified as positional argument.`, ...@@ -50,9 +50,13 @@ Change UUID must be specified as positional argument.`,
if err != nil { if err != nil {
pterm.Error.Println(err) pterm.Error.Println(err)
} }
if err := pndAdapter.Commit(cuid); err != nil { resp, err := pndAdapter.Commit(cuid)
if err != nil {
pterm.Error.Println(err) pterm.Error.Println(err)
} }
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
}
}, },
} }
......
...@@ -50,9 +50,14 @@ Change UUID must be specified as positional argument`, ...@@ -50,9 +50,14 @@ Change UUID must be specified as positional argument`,
if err != nil { if err != nil {
pterm.Error.Println(err) pterm.Error.Println(err)
} }
if err := pndAdapter.Confirm(cuid); err != nil {
resp, err := pndAdapter.Confirm(cuid)
if err != nil {
pterm.Error.Println(err) pterm.Error.Println(err)
} }
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
}
}, },
} }
......
...@@ -47,7 +47,7 @@ var pndRemoveCmd = &cobra.Command{ ...@@ -47,7 +47,7 @@ var pndRemoveCmd = &cobra.Command{
Long: "Removes the PND with the provided ID", Long: "Removes the PND with the provided ID",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
spinner, _ := pterm.DefaultSpinner.Start("Fetching changes for type: ", cType.String()) spinner, _ := pterm.DefaultSpinner.Start("Removing PND with ID: ", args[0])
pid, err := uuid.Parse(args[0]) pid, err := uuid.Parse(args[0])
if err != nil { if err != nil {
spinner.Fail(err) spinner.Fail(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment