Skip to content

Commit

Permalink
Merge branch 'main' into otlp-support
Browse files Browse the repository at this point in the history
# Conflicts:
#	gosnappi/go.mod
#	gosnappi/go.sum
#	gosnappi/gosnappi.go
#	gosnappi/otg/otg.pb.go
#	gosnappi/otg/otg.proto
#	requirements.txt
#	snappi/docs/openapi.yaml
#	snappi/otg_pb2.py
#	snappi/snappi.py
#	version.py
  • Loading branch information
vhowdhur committed Oct 16, 2023
2 parents 217e0bb + adde0e2 commit 1b55742
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--prefer-binary
requests
openapiart==0.3.1
openapiart==0.3.4
5 changes: 3 additions & 2 deletions gosnappi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (api *api) FromError(err error) (Error, bool) {
func (api *api) setResponseErr(obj Error, code int32, message string) {
errors := []string{}
errors = append(errors, message)
obj.Msg().Code = code
obj.Msg().Code = &code
obj.Msg().Errors = errors
}

Expand All @@ -250,7 +250,8 @@ func (api *api) fromGrpcError(err error) (Error, bool) {
if ok {
rErr := NewError()
if err := rErr.FromJson(st.Message()); err == nil {
rErr.Msg().Code = int32(st.Code())
var code = int32(st.Code())
rErr.Msg().Code = &code
return rErr, true
}

Expand Down
6 changes: 3 additions & 3 deletions gosnappi/generated_required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func TestTransmitStateRequired(t *testing.T) {
err1 := object.FromYaml(string(data))
protoMarshal, _ := proto.Marshal(object.Msg())
err2 := object.FromPbText(string(protoMarshal))
assert.Nil(t, err)
assert.Nil(t, err1)
assert.Nil(t, err2)
assert.NotNil(t, err)
assert.NotNil(t, err1)
assert.NotNil(t, err2)
}
func TestLinkStateRequired(t *testing.T) {
object := gosnappi.NewControlState().Port().Link()
Expand Down
2 changes: 1 addition & 1 deletion gosnappi/httpapi/controllers/capabilities_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ctrl *capabilitiesController) responseGetVersionError(w http.ResponseWrite
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions gosnappi/httpapi/controllers/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (ctrl *configurationController) responseSetConfigError(w http.ResponseWrite
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -135,7 +135,7 @@ func (ctrl *configurationController) responseGetConfigError(w http.ResponseWrite
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -204,7 +204,7 @@ func (ctrl *configurationController) responseUpdateConfigError(w http.ResponseWr
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions gosnappi/httpapi/controllers/control_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (ctrl *controlController) responseSetControlStateError(w http.ResponseWrite
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -156,7 +156,7 @@ func (ctrl *controlController) responseSetControlActionError(w http.ResponseWrit
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions gosnappi/httpapi/controllers/monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (ctrl *monitorController) responseGetMetricsError(w http.ResponseWriter, er
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -150,7 +150,7 @@ func (ctrl *monitorController) responseGetStatesError(w http.ResponseWriter, err
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -218,7 +218,7 @@ func (ctrl *monitorController) responseGetCaptureError(w http.ResponseWriter, er
result = gosnappi.NewError()
err := result.FromJson(rsp_err.Error())
if err != nil {
result.Msg().Code = statusCode
result.Msg().Code = &statusCode
err = result.SetKind(errorKind)
if err != nil {
log.Print(err.Error())
Expand Down
21 changes: 11 additions & 10 deletions gosnappi/mock_grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func getBgpPeerNames(cfg *otg.Config) []string {
func getFlowNames(cfg *otg.Config) []string {
names := []string{}
for _, flow := range mockConfig.Flows {
names = append(names, flow.Name)
names = append(names, *flow.Name)
}

return names
Expand All @@ -106,7 +106,7 @@ func getFlowNames(cfg *otg.Config) []string {
func getPortNames(cfg *otg.Config) []string {
names := []string{}
for _, port := range mockConfig.Ports {
names = append(names, port.Name)
names = append(names, *port.Name)
}

return names
Expand All @@ -119,7 +119,7 @@ func getRouteNames(cfg *otg.Config) []string {
continue
}
for _, r := range d.Bgp.Ipv4Interfaces[0].Peers[0].GetV4Routes() {
names = append(names, r.Name)
names = append(names, *r.Name)
}
}
return names
Expand All @@ -129,7 +129,7 @@ func isFlowMetricsDisabled(cfg *otg.Config) []string {
names := []string{}
for _, flow := range cfg.Flows {
if flow.Metrics == nil || !*flow.Metrics.Enable {
names = append(names, flow.Name)
names = append(names, *flow.Name)
}
}
return names
Expand All @@ -139,6 +139,7 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
var resp *otg.GetMetricsResponse
var err error
var tx uint64 = 100
var errCode int32 = 13
metricsDisabledFlows := isFlowMetricsDisabled(mockConfig)
if req.MetricsRequest.Flow != nil {
f := &otg.FlowMetric{FramesTx: &tx}
Expand All @@ -148,13 +149,13 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
if !res {
resp = nil
errObj := NewError()
errObj.Msg().Code = 13
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"requested flow is not available in configured flows"}
err = errObj
} else if len(metricsDisabledFlows) > 0 {
resp = nil
errObj := NewError()
errObj.Msg().Code = 13
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"metrics not enabled for all the flows"}
err = errObj
} else {
Expand All @@ -175,7 +176,7 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
resp = nil
resp = nil
errObj := NewError()
errObj.Msg().Code = 13
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"requested port is not available in configured ports"}
err = errObj
} else {
Expand Down Expand Up @@ -225,9 +226,9 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
}

func (s *server) SetControlState(ctx context.Context, req *otg.SetControlStateRequest) (*otg.SetControlStateResponse, error) {
switch choice := req.ControlState.Choice; choice {
switch choice := *req.ControlState.Choice; choice {
case otg.ControlState_Choice_port:
switch portChoice := req.ControlState.Port.Choice; portChoice {
switch portChoice := *req.ControlState.Port.Choice; portChoice {
case otg.StatePort_Choice_link:
return s.SetLinkState(ctx, req)
case otg.StatePort_Choice_capture:
Expand All @@ -236,7 +237,7 @@ func (s *server) SetControlState(ctx context.Context, req *otg.SetControlStateRe
return nil, fmt.Errorf("unspecified choice")
}
case otg.ControlState_Choice_protocol:
switch protocolChoice := req.ControlState.Protocol.Choice; protocolChoice {
switch protocolChoice := *req.ControlState.Protocol.Choice; protocolChoice {
case otg.StateProtocol_Choice_route:
return s.SetRouteState(ctx, req)
case otg.StateProtocol_Choice_unspecified:
Expand Down
6 changes: 3 additions & 3 deletions gosnappi/snappigo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func TestHttpGetMetricsPortResponse(t *testing.T) {
assert.NotNil(t, resp)
assert.Nil(t, err)
assert.Equal(t, resp.PortMetrics().Items()[0].Name(), string("port1"))
assert.Equal(t, resp.PortMetrics().Items()[0].BytesTx(), int64(2000))
assert.Equal(t, resp.PortMetrics().Items()[0].BytesRx(), int64(2000))
assert.Equal(t, resp.PortMetrics().Items()[0].BytesTx(), uint64(2000))
assert.Equal(t, resp.PortMetrics().Items()[0].BytesRx(), uint64(2000))
}

func TestGetMetricsPortResponseError(t *testing.T) {
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestHttpGetMetricsBgpv4Response(t *testing.T) {
assert.NotNil(t, resp)
assert.Nil(t, err)
assert.Equal(t, resp.Bgpv4Metrics().Items()[0].Name(), string("BGP-1"))
assert.Equal(t, resp.Bgpv4Metrics().Items()[0].RoutesAdvertised(), int32(80))
assert.Equal(t, resp.Bgpv4Metrics().Items()[0].RoutesAdvertised(), uint32(80))
}

func TestGetMetricsBgpv4ResponseError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class Version:
models_version = "0.12.3"
version = "0.12.3"
models_version = "0.13.0"
version = "0.13.0"
package_name = "snappi"
protobuf_name = "otg"
go_package_name = "gosnappi"

0 comments on commit 1b55742

Please sign in to comment.