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
......@@ -11,7 +11,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors"
"github.com/google/uuid"
"github.com/openconfig/goyang/pkg/yang"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/proto"
)
......@@ -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
// a change from the provided Operation, path and value. The Change is marked
// 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
if len(value) != 0 {
v = value[0]
}
resp, err := api.ChangeRequest(p.endpoint, duid.String(), p.id.String(), path, v, operation)
if err != nil {
return uuid.Nil, err
return nil, err
}
log.Info(resp)
return uuid.Nil, err
return resp, err
}
// 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) {
}
// 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())
if err != nil {
return err
return nil, err
}
log.Info(resp)
return nil
return resp, nil
}
// 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())
if err != nil {
return err
return nil, err
}
log.Info(resp)
return nil
return resp, nil
}
func filterChanges(state ppb.ChangeState, resp *ppb.GetChangeListResponse) []uuid.UUID {
......
......@@ -473,7 +473,7 @@ func TestPndAdapter_Commit(t *testing.T) {
id: tt.fields.id,
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)
}
})
......@@ -502,7 +502,7 @@ func TestPndAdapter_Confirm(t *testing.T) {
id: tt.fields.id,
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)
}
})
......
......@@ -50,9 +50,13 @@ Change UUID must be specified as positional argument.`,
if err != nil {
pterm.Error.Println(err)
}
if err := pndAdapter.Commit(cuid); err != nil {
resp, err := pndAdapter.Commit(cuid)
if err != nil {
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`,
if err != nil {
pterm.Error.Println(err)
}
if err := pndAdapter.Confirm(cuid); err != nil {
resp, err := pndAdapter.Confirm(cuid)
if err != nil {
pterm.Error.Println(err)
}
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
}
},
}
......
......@@ -47,7 +47,7 @@ var pndRemoveCmd = &cobra.Command{
Long: "Removes the PND with the provided ID",
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])
if err != nil {
spinner.Fail(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment