Skip to content

Commit 90e1006

Browse files
cisco-nxos-provider: pass context to device configuration methods
1 parent 46337a5 commit 90e1006

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+200
-259
lines changed

internal/provider/cisco/nxos/acl/acl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package acl
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"net/netip"
@@ -105,7 +106,7 @@ func ProtocolFrom(s string) Protocol {
105106
}
106107

107108
// ToYGOT returns a single update forcing the replacement of an ACL configuration.
108-
func (a *ACL) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
109+
func (a *ACL) ToYGOT(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
109110
if err := a.Validate(); err != nil {
110111
return nil, err
111112
}
@@ -143,7 +144,7 @@ func (a *ACL) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
143144
}
144145

145146
// Reset returns a single update deleting the YANG entry of the ACL.
146-
func (a *ACL) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
147+
func (a *ACL) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
147148
if err := a.Validate(); err != nil {
148149
return nil, err
149150
}

internal/provider/cisco/nxos/acl/acl_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Test_ACL(t *testing.T) {
2626
},
2727
}
2828

29-
got, err := a.ToYGOT(&gnmiext.ClientMock{})
29+
got, err := a.ToYGOT(t.Context(), &gnmiext.ClientMock{})
3030
if err != nil {
3131
t.Errorf("unexpected error: %v", err)
3232
}
@@ -103,7 +103,7 @@ func Test_ACL_IPv6(t *testing.T) {
103103
},
104104
}
105105

106-
got, err := a.ToYGOT(&gnmiext.ClientMock{})
106+
got, err := a.ToYGOT(t.Context(), &gnmiext.ClientMock{})
107107
if err != nil {
108108
t.Errorf("unexpected error: %v", err)
109109
}
@@ -137,7 +137,7 @@ func Test_ACL_Validation_MixedIPVersions(t *testing.T) {
137137
},
138138
}
139139

140-
_, err := a.ToYGOT(&gnmiext.ClientMock{})
140+
_, err := a.ToYGOT(t.Context(), &gnmiext.ClientMock{})
141141
if err == nil {
142142
t.Errorf("expected validation error for mixed IP versions, got nil")
143143
}
@@ -158,7 +158,7 @@ func Test_ACL_EmptyDescription(t *testing.T) {
158158
},
159159
}
160160

161-
got, err := a.ToYGOT(&gnmiext.ClientMock{})
161+
got, err := a.ToYGOT(t.Context(), &gnmiext.ClientMock{})
162162
if err != nil {
163163
t.Errorf("unexpected error: %v", err)
164164
}

internal/provider/cisco/nxos/api/grpc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package api
55

66
import (
7+
"context"
78
"errors"
89

910
"github.com/openconfig/ygot/ygot"
@@ -43,7 +44,7 @@ type GNMI struct {
4344
}
4445

4546
// ToYGOT converts the GRPC configuration to a slice of gNMI updates.
46-
func (g *GRPC) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
47+
func (g *GRPC) ToYGOT(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
4748
if !g.Enable {
4849
return []gnmiext.Update{
4950
gnmiext.EditingUpdate{
@@ -100,6 +101,6 @@ func (g *GRPC) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
100101
}
101102

102103
// returns an empty update and an error indicating that the reset is not implemented
103-
func (v *GRPC) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
104+
func (v *GRPC) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
104105
return []gnmiext.Update{}, errors.New("grpc: reset not implemented as it effectively disables management over gNMI")
105106
}

internal/provider/cisco/nxos/api/grpc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Test_GRPC(t *testing.T) {
2020
Trustpoint: "mytrustpoint",
2121
}
2222

23-
got, err := grpc.ToYGOT(&gnmiext.ClientMock{})
23+
got, err := grpc.ToYGOT(t.Context(), &gnmiext.ClientMock{})
2424
if err != nil {
2525
t.Fatalf("unexpected error: %v", err)
2626
}
@@ -78,7 +78,7 @@ func Test_GRPC(t *testing.T) {
7878
func Test_GRPC_Disabled(t *testing.T) {
7979
grpc := &GRPC{Enable: false}
8080

81-
got, err := grpc.ToYGOT(&gnmiext.ClientMock{})
81+
got, err := grpc.ToYGOT(t.Context(), &gnmiext.ClientMock{})
8282
if err != nil {
8383
t.Fatalf("unexpected error: %v", err)
8484
}

internal/provider/cisco/nxos/api/nxapi.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package api
55

66
import (
7+
"context"
78
"fmt"
89

910
"github.com/openconfig/ygot/ygot"
@@ -42,7 +43,7 @@ type Trustpoint struct {
4243

4344
func (Trustpoint) isNXAPICert() {}
4445

45-
func (n *NXAPI) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
46+
func (n *NXAPI) ToYGOT(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
4647
if !n.Enable {
4748
return []gnmiext.Update{
4849
gnmiext.EditingUpdate{
@@ -97,7 +98,7 @@ func (n *NXAPI) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
9798
}
9899

99100
// disables nxapi, resets config to defaults
100-
func (v *NXAPI) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
101+
func (v *NXAPI) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
101102
nxapi := &nxos.Cisco_NX_OSDevice_System_NxapiItems{}
102103
nxapi.PopulateDefaults()
103104
return []gnmiext.Update{

internal/provider/cisco/nxos/api/nxapi_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_NXAPI(t *testing.T) {
1818
Enable: true,
1919
}
2020

21-
got, err := nxapi.ToYGOT(&gnmiext.ClientMock{})
21+
got, err := nxapi.ToYGOT(t.Context(), &gnmiext.ClientMock{})
2222
if err != nil {
2323
t.Fatalf("unexpected error: %v", err)
2424
}
@@ -50,7 +50,7 @@ func Test_NXAPI_Trustpoint(t *testing.T) {
5050
Cert: Trustpoint{ID: "mytrustpoint"},
5151
}
5252

53-
got, err := nxapi.ToYGOT(&gnmiext.ClientMock{})
53+
got, err := nxapi.ToYGOT(t.Context(), &gnmiext.ClientMock{})
5454
if err != nil {
5555
t.Fatalf("unexpected error: %v", err)
5656
}
@@ -108,7 +108,7 @@ func Test_NXAPI_Cert(t *testing.T) {
108108
},
109109
}
110110

111-
got, err := nxapi.ToYGOT(&gnmiext.ClientMock{})
111+
got, err := nxapi.ToYGOT(t.Context(), &gnmiext.ClientMock{})
112112
if err != nil {
113113
t.Fatalf("unexpected error: %v", err)
114114
}
@@ -162,7 +162,7 @@ func Test_NXAPI_Cert(t *testing.T) {
162162
func Test_NXAPI_Disabled(t *testing.T) {
163163
nxapi := &NXAPI{Enable: false}
164164

165-
got, err := nxapi.ToYGOT(&gnmiext.ClientMock{})
165+
got, err := nxapi.ToYGOT(t.Context(), &gnmiext.ClientMock{})
166166
if err != nil {
167167
t.Fatalf("unexpected error: %v", err)
168168
}

internal/provider/cisco/nxos/banner/banner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package banner
1111

1212
import (
13+
"context"
1314
"errors"
1415
"fmt"
1516
"strings"
@@ -30,7 +31,7 @@ type Banner struct {
3031
Message string
3132
}
3233

33-
func (b *Banner) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
34+
func (b *Banner) ToYGOT(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
3435
lines := strings.Split(b.Message, "\n")
3536
if len(lines) > 40 {
3637
return nil, errors.New("banner: maximum of 40 lines allowed")
@@ -52,7 +53,7 @@ func (b *Banner) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
5253
}, nil
5354
}
5455

55-
func (v *Banner) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
56+
func (v *Banner) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
5657
banner := &nxos.Cisco_NX_OSDevice_System_UserextItems_PreloginbannerItems{}
5758
banner.PopulateDefaults()
5859
return []gnmiext.Update{

internal/provider/cisco/nxos/banner/banner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Test_Banner(t *testing.T) {
1919
Message: message,
2020
}
2121

22-
got, err := banner.ToYGOT(&gnmiext.ClientMock{})
22+
got, err := banner.ToYGOT(t.Context(), &gnmiext.ClientMock{})
2323
if err != nil {
2424
t.Errorf("unexpected error: %v", err)
2525
}
@@ -51,7 +51,7 @@ func Test_Banner_Limit(t *testing.T) {
5151
for i, test := range tests {
5252
t.Run(strconv.Itoa(i), func(t *testing.T) {
5353
banner := &Banner{Delimiter: "^", Message: test}
54-
if _, err := banner.ToYGOT(&gnmiext.ClientMock{}); err == nil {
54+
if _, err := banner.ToYGOT(t.Context(), &gnmiext.ClientMock{}); err == nil {
5555
t.Errorf("expected error, got nil")
5656
}
5757
})

internal/provider/cisco/nxos/bgp/bgp.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func WithAddressFamily(af AddressFamily) BGPOption {
8787
}
8888
}
8989

90-
func (b *BGP) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
90+
func (b *BGP) ToYGOT(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
9191
inst := &nxos.Cisco_NX_OSDevice_System_BgpItems_InstItems{}
9292
inst.AdminSt = nxos.Cisco_NX_OSDevice_Nw_AdminSt_enabled
9393
inst.Asn = ygot.String(b.AsNumber)
@@ -130,7 +130,7 @@ func (b *BGP) ToYGOT(_ gnmiext.Client) ([]gnmiext.Update, error) {
130130
return updates, nil
131131
}
132132

133-
func (b *BGP) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
133+
func (b *BGP) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
134134
return []gnmiext.Update{
135135
gnmiext.EditingUpdate{
136136
XPath: "System/fm-items/bgp-items",
@@ -277,7 +277,7 @@ func WithPeerAddressFamily(af PeerAddressFamily) BGPPeerOption {
277277

278278
var ErrMissingBGPInstance = errors.New("bgp peer: missing BGP instance")
279279

280-
func (p *BGPPeer) ToYGOT(client gnmiext.Client) ([]gnmiext.Update, error) {
280+
func (p *BGPPeer) ToYGOT(ctx context.Context, client gnmiext.Client) ([]gnmiext.Update, error) {
281281
// Ensure that the BGP instance exists and is configured on the "default" domain
282282
// and return an error if it does not exist.
283283
// Otherwise, by default of the gnmi specification, all missing nodes in the yang
@@ -287,7 +287,7 @@ func (p *BGPPeer) ToYGOT(client gnmiext.Client) ([]gnmiext.Update, error) {
287287
// configured by requeuing the request for the BGP Peer on the k8s controller. This avoids
288288
// a race condition where the BGP instance is created after the BGP Peer is created.
289289
var inst nxos.Cisco_NX_OSDevice_System_BgpItems_InstItems
290-
err := client.Get(context.Background(), "System/bgp-items/inst-items", &inst)
290+
err := client.Get(ctx, "System/bgp-items/inst-items", &inst)
291291
if err != nil {
292292
if errors.Is(err, gnmiext.ErrNil) {
293293
return nil, ErrMissingBGPInstance
@@ -316,7 +316,7 @@ func (p *BGPPeer) ToYGOT(client gnmiext.Client) ([]gnmiext.Update, error) {
316316
}, nil
317317
}
318318

319-
func (p *BGPPeer) Reset(_ gnmiext.Client) ([]gnmiext.Update, error) {
319+
func (p *BGPPeer) Reset(_ context.Context, _ gnmiext.Client) ([]gnmiext.Update, error) {
320320
return []gnmiext.Update{
321321
gnmiext.DeletingUpdate{
322322
XPath: "System/bgp-items/inst-items/dom-items/Dom-list[name=default]/peer-items/Peer-list[addr=" + p.Addr.String() + "]",

internal/provider/cisco/nxos/bgp/bgp_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func TestBGP_ToYGOT(t *testing.T) {
177177
t.Fatalf("NewBGP() unexpected error = %v", err)
178178
}
179179

180-
got, err := bgp.ToYGOT(&gnmiext.ClientMock{})
180+
got, err := bgp.ToYGOT(t.Context(), &gnmiext.ClientMock{})
181181
if err != nil {
182182
t.Errorf("BGP.ToYGOT() unexpected error = %v", err)
183183
return
@@ -249,7 +249,7 @@ func TestBGP_ToYGOT_WithEVPN(t *testing.T) {
249249
t.Fatalf("NewBGP() unexpected error = %v", err)
250250
}
251251

252-
got, err := bgp.ToYGOT(&gnmiext.ClientMock{})
252+
got, err := bgp.ToYGOT(t.Context(), &gnmiext.ClientMock{})
253253
if err != nil {
254254
t.Errorf("BGP.ToYGOT() unexpected error = %v", err)
255255
return
@@ -286,7 +286,7 @@ func TestBGP_Reset(t *testing.T) {
286286
t.Fatalf("NewBGP() unexpected error = %v", err)
287287
}
288288

289-
got, err := bgp.Reset(&gnmiext.ClientMock{})
289+
got, err := bgp.Reset(t.Context(), &gnmiext.ClientMock{})
290290
if err != nil {
291291
t.Errorf("BGP.Reset() unexpected error = %v", err)
292292
return
@@ -610,7 +610,7 @@ func TestBGPPeer_ToYGOT_MissingBGPInstance(t *testing.T) {
610610
},
611611
}
612612

613-
_, err = peer.ToYGOT(client)
613+
_, err = peer.ToYGOT(t.Context(), client)
614614
if err == nil {
615615
t.Errorf("BGPPeer.ToYGOT() expected error for missing BGP instance, got nil")
616616
return
@@ -633,7 +633,7 @@ func TestBGPPeer_ToYGOT_GetError(t *testing.T) {
633633
},
634634
}
635635

636-
_, err = peer.ToYGOT(client)
636+
_, err = peer.ToYGOT(t.Context(), client)
637637
if err == nil {
638638
t.Errorf("BGPPeer.ToYGOT() expected error, got nil")
639639
return
@@ -661,7 +661,7 @@ func TestBGPPeer_ToYGOT_Success(t *testing.T) {
661661
},
662662
}
663663

664-
got, err := peer.ToYGOT(client)
664+
got, err := peer.ToYGOT(t.Context(), client)
665665
if err != nil {
666666
t.Errorf("BGPPeer.ToYGOT() unexpected error = %v", err)
667667
return
@@ -709,7 +709,7 @@ func TestBGPPeer_Reset(t *testing.T) {
709709
t.Fatalf("NewBGPPeer() unexpected error = %v", err)
710710
}
711711

712-
got, err := peer.Reset(&gnmiext.ClientMock{})
712+
got, err := peer.Reset(t.Context(), &gnmiext.ClientMock{})
713713
if err != nil {
714714
t.Errorf("BGPPeer.Reset() unexpected error = %v", err)
715715
return

0 commit comments

Comments
 (0)