polycube icon indicating copy to clipboard operation
polycube copied to clipboard

CLI parameter parsing problem

Open acloudiator opened this issue 7 years ago • 4 comments

The CLI has some issues when a string that can be converted to a number is used as name of a port. Probably this is a more generic problem.

$ polycubectl simplebridge add br0
$ polycubectl br0 ports add 10e30
$ polycubectl show br0
name: br0
uuid: 104fc8c1-fdf4-405b-8ae9-db7d2a92aa43
type: type_tc
loglevel: info
fdb:
 aging-time: 300
ports:
- [0]
    name: 9999999999999999635896294965248.000000
    uuid: 9efbe0c7-f990-4544-b72f-4f445672fb40
    status: down
    peer: 
    mac: 4e:cc:d4:0c:ec:e7
$ polycubectl br0 fdb entry add 02:42:a7:24:d4:2d port=10e30
type must be string, but is number

-Mauricio

acloudiator avatar Dec 18 '18 19:12 acloudiator

Confirmed by @michelsciortino.

palexster avatar Jan 14 '20 21:01 palexster

@goldenrye I think https://github.com/polycube-network/polycube/pull/261 doesn't solve this issue completely.

Please consider the following case:

$ nc -l 9000 # in another terminal
$ polycubectl br0 fdb entry add 02:42:a7:24:d4:2d port=10e30

The request that polycubectl will perform is something like:

POST /polycube/v1/br0/fdb/entry/02:42:a7:24:d4:2d/ HTTP/1.1
Host: localhost:9000
User-Agent: Go-http-client/1.1
Content-Length: 14
Content-Type: application/json
Accept-Encoding: gzip

{"port":1e+31} 
#       ^^^^^^

The problem is probably in the logic to build the body of the request, that tries to convert integers, floats, bools into that representation:

https://github.com/polycube-network/polycube/blob/7c684ee371803b176c4ad4bfc5eba6b93ff8f28f/src/polycubectl/cliargs/cliargs.go#L330-L346

Btw, I don't know if there is an easy way to solve that or if this is one of the issues that will be never solved.

mauriciovasquezbernal avatar Jan 23 '20 22:01 mauriciovasquezbernal

Mauricio,

You are right, this is a different issue. The original issue mentioned in 261 is purely a display issue caused by polycubectl interpretting the json response incorrectly. While this issue is reverse direction where polycubectl builds the json request incorrectly to the server.

thanks, -Jianwen

On Thu, Jan 23, 2020 at 2:05 PM Mauricio Vásquez [email protected] wrote:

@goldenrye https://github.com/goldenrye I think #261 https://github.com/polycube-network/polycube/pull/261 doesn't solve this issue completely.

Please consider the following case:

$ nc -l 9000 # in another terminal $ polycubectl br0 fdb entry add 02:42:a7:24:d4:2d port=10e30

The request that polycubectl will perform is something like:

POST /polycube/v1/br0/fdb/entry/02:42:a7:24:d4:2d/ HTTP/1.1 Host: localhost:9000 User-Agent: Go-http-client/1.1 Content-Length: 14 Content-Type: application/json Accept-Encoding: gzip

{"port":1e+31}

^^^^^^

The problem is probably in the logic to build the body of the request, that tries to convert integers, floats, bools into that representation:

https://github.com/polycube-network/polycube/blob/7c684ee371803b176c4ad4bfc5eba6b93ff8f28f/src/polycubectl/cliargs/cliargs.go#L330-L346

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/polycube-network/polycube/issues/16?email_source=notifications&email_token=AD5DPPCTEMXPRKJ5XLBCSCLQ7IIBDA5CNFSM4GLD34W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJZAWGI#issuecomment-577899289, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5DPPCBEQDYF2LGFZ2SSMTQ7IIBDANCNFSM4GLD34WQ .

goldenrye avatar Jan 24 '20 21:01 goldenrye

Good catch, Mauricio!

frisso avatar Jan 25 '20 10:01 frisso