Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,12 @@ func (c *Client) Flush(ctx context.Context, req *spb.FlushRequest) (*spb.FlushRe
return nil, fmt.Errorf("must specify an election behaviour for a SINGLE_PRIMARY client")
}

switch t := req.GetElection().(type) {
switch req.GetElection().(type) {
case *spb.FlushRequest_Id:
if c.state.SessParams == nil || c.state.SessParams.Redundancy != spb.SessionParameters_SINGLE_PRIMARY {
return nil, fmt.Errorf("invalid to specify an election ID when the client is not in SINGLE_PRIMARY mode")
}
case *spb.FlushRequest_Override:
if !t.Override {
return nil, fmt.Errorf("invalid override value set to false")
}
if c.state.SessParams == nil || c.state.SessParams.Redundancy != spb.SessionParameters_SINGLE_PRIMARY {
return nil, fmt.Errorf("cannot override election ID when the client is in ALL_PRIMARY mode")
}
Expand Down
22 changes: 2 additions & 20 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ func TestFlush(t *testing.T) {
}(),
inReq: &spb.FlushRequest{
Election: &spb.FlushRequest_Override{
Override: true,
Override: &spb.Empty{},
},
NetworkInstance: &spb.FlushRequest_All{
All: &spb.Empty{},
Expand Down Expand Up @@ -1277,24 +1277,6 @@ func TestFlush(t *testing.T) {
},
},
wantErr: true,
}, {
desc: "override set to false",
inClient: func() *Client {
c, err := New()
if err != nil {
t.Fatalf("can't initialise client, %v", err)
}
return c
}(),
inReq: &spb.FlushRequest{
NetworkInstance: &spb.FlushRequest_Name{
Name: server.DefaultNetworkInstanceName,
},
Election: &spb.FlushRequest_Override{
Override: false,
},
},
wantErr: true,
}, {
desc: "override with non-SINGLE_PRIMARY client",
inClient: func() *Client {
Expand All @@ -1309,7 +1291,7 @@ func TestFlush(t *testing.T) {
Name: server.DefaultNetworkInstanceName,
},
Election: &spb.FlushRequest_Override{
Override: true,
Override: &spb.Empty{},
},
},
wantErr: true,
Expand Down
2 changes: 1 addition & 1 deletion compliance/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestDifferingElectionParameters(c *fluent.GRIBIClient, t testing.TB, opts .

// TestParamsDifferFromOtherClients checks that when a client A is connected as a SINGLE_PRIMARY
// and client B connects with ALL_PRIMARY, an PARAMS_DIFFER_FROM_OTHER_CLIENTS error is returned to client B.

//
// TODO (deepgajjar): The fake implementation does not support ALL_PRIMARY. Ignore
// the current tests since the return error would be UNSUPPORTED_PARAMS instead of PARAMS_DIFFER_FROM_OTHER_CLIENTS.
// Add tests once the support for ALL_PRIMARY comes in.
Expand Down
1 change: 1 addition & 0 deletions compliance/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package compliance

import (
Expand Down
2 changes: 1 addition & 1 deletion fluent/fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (g *gRIBIFlush) WithElectionID(low, high uint64) *gRIBIFlush {
// status on the gRIBI server when calling the Flush operation.
func (g *gRIBIFlush) WithElectionOverride() *gRIBIFlush {
g.pb.Election = &spb.FlushRequest_Override{
Override: true,
Override: &spb.Empty{},
}
return g
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1
github.com/openconfig/gnmi v0.0.0-20210527163611-d3a3e30199da
github.com/openconfig/goyang v0.2.9
github.com/openconfig/gribi v0.1.1-0.20220124194935-f16e301cc493
github.com/openconfig/gribi v0.1.1-0.20220126144445-1634932f9fd8
github.com/openconfig/grpctunnel v0.0.0-20210610163803-fde4a9dc048d // indirect
github.com/openconfig/ygot v0.13.2
go.uber.org/atomic v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ github.com/openconfig/goyang v0.2.9/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+R
github.com/openconfig/gribi v0.1.1-0.20210423184541-ce37eb4ba92f/go.mod h1:OoH46A2kV42cIXGyviYmAlGmn6cHjGduyC2+I9d/iVs=
github.com/openconfig/gribi v0.1.1-0.20220124194935-f16e301cc493 h1:4lIwB7pMo8kJ3V/S0E8jWXTaoSBgwQoxdUHCYsbH0QA=
github.com/openconfig/gribi v0.1.1-0.20220124194935-f16e301cc493/go.mod h1:VFqGH2ZPFIfnKTimP4/AQB4OK0eySW5muJNFxXAwP6k=
github.com/openconfig/gribi v0.1.1-0.20220126144445-1634932f9fd8 h1:V6QU1cocKPRP1yEfxg0cleaIh95d4yRY572UwKu/W+0=
github.com/openconfig/gribi v0.1.1-0.20220126144445-1634932f9fd8/go.mod h1:VFqGH2ZPFIfnKTimP4/AQB4OK0eySW5muJNFxXAwP6k=
github.com/openconfig/grpctunnel v0.0.0-20210610163803-fde4a9dc048d h1:zrs4U92QEAadFotQyidT4U8iZDJO67pXsS4r64uAHik=
github.com/openconfig/grpctunnel v0.0.0-20210610163803-fde4a9dc048d/go.mod h1:x9tAZ4EwqCQ0jI8D6S8Yhw9Z0ee7/BxWQX0k0Uib5Q8=
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
Expand Down
11 changes: 2 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,15 +1040,8 @@ func (s *Server) checkFlushRequest(req *spb.FlushRequest) error {
}
}

if o, ok := e.(*spb.FlushRequest_Override); ok {
if !o.Override {
// TODO(robjs): see github.com/openconfig/gribi/pull/30, if this change is made
// then we will not need this check here.
return addFlushErrDetailsOrReturn(status.Newf(codes.FailedPrecondition, "election ID was not overridden"), &spb.FlushResponseError{
Status: spb.FlushResponseError_NOT_PRIMARY,
})
}
}
// By default, override must have been specified as Election was non-nil.
// return successfully.
return nil
}

Expand Down
20 changes: 3 additions & 17 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1886,29 +1886,15 @@ func TestCheckFlushRequest(t *testing.T) {
},
},
}, {
desc: "override specified as true",
desc: "override specified",
inServer: &Server{
curElecID: &spb.Uint128{High: 0, Low: 3},
},
inRequest: &spb.FlushRequest{
Election: &spb.FlushRequest_Override{
Override: true,
Override: &spb.Empty{},
},
},
}, {
desc: "override specified as false",
inServer: &Server{
curElecID: &spb.Uint128{High: 0, Low: 3},
},
inRequest: &spb.FlushRequest{
Election: &spb.FlushRequest_Override{
Override: false,
},
},
wantErrCode: codes.FailedPrecondition,
wantErrDetails: &spb.FlushResponseError{
Status: spb.FlushResponseError_NOT_PRIMARY,
},
}}

for _, tt := range tests {
Expand Down Expand Up @@ -2120,7 +2106,7 @@ func TestFlush(t *testing.T) {
All: &spb.Empty{},
},
Election: &spb.FlushRequest_Override{
Override: true,
Override: &spb.Empty{},
},
},
wantEntriesInNI: map[string]int{
Expand Down