open-traffic-generator / snappi

Open Traffic Generator SDK in Python and Go
MIT License
69 stars 7 forks source link

GoSnappi: SetStatusCode200 on GetMetricsResponse is not working as expected #143

Closed rudranil-das closed 2 years ago

rudranil-das commented 2 years ago

Snappi version: This issue is observed with dev version of snappi [https://github.com/open-traffic-generator/snappi/tree/gosnappi_server_tmp/gosnappi]. But could be a pre-existing issue.

In ixia-c controller GetMetrics implementation on top of Gosnappi http server, (http://gitlab.it.keysight.com/athena/controller/blob/dev-gosnappi-http/internal/service/results.go), we tried to do following,

result.SetStatusCode200(response) \\ where response= MetricsResponse; result = GetMetricsResponse

And the expectation is the get_metrics call (as mentioned below) would succeed for all choices (port/flow/...)

POST https://localhost/results/metrics HTTP/1.1
Content-Type: application/json

{
    "choice": "port"
}

For choice = "port" it does, but for choice="flow" it shows following weird response,

HTTP/1.1 200 OK
Date: Wed, 01 Dec 2021 14:54:22 GMT
Content-Length: 31
Content-Type: text/plain; charset=utf-8
Connection: close

{
  "choice": "port_metrics"
}

When the scenario is checked with debug-prints in GetMetrics hook of metrics_controller.go (of gosnappi server),

       if result.HasStatusCode200() {
        fmt.Println("MC 200 MSG: ", result.StatusCode200().Msg())
        fmt.Println("MC 200 JSON: ", result.StatusCode200().ToJson())
        httpapi.WriteJSONResponse(w, 200, result.StatusCode200())
        return
    }

it reflected the following output,

MC 200 MSG:  choice:flow_metrics  flow_metrics:{name:"flw"  transmit:started  frames_tx:0  frames_rx:430  bytes_tx:0  bytes_rx:55040  frames_tx_rate:0  frames_rx_rate:0}
MC 200 JSON:  {
  "choice":  "port_metrics"
}

i.e. the Msg() reflects the correct parameters, but ToJson() does not.

I think this reflects the SetStatusCode200 did not work on GetMetricsResponse where MetricsResponse is not of default choice-type (i.e. "port")

rudranil-das commented 2 years ago

Workaround used in ixia-c controller for time-being is, Instead of

result.SetStatusCode200(response)

used the following,

result.StatusCode200().FromJson(response.ToJson())
rudranil-das commented 2 years ago

FYI, Same observation is seen with GetStatesResponse as well.

alakendu commented 2 years ago

This should address in https://github.com/open-traffic-generator/snappi/releases/tag/v0.7.1