Page MenuHomeVyOS Platform

Calling 'stty_size' causes show interfaces API to fail
Closed, ResolvedPublicBUG

Description

A show interface via this API fails due to call to stty command:

curl -k -X POST -F data='{"op":"show", "path": ["interfaces", "ethernet"] }' -F key=vyos https://172.16.0.1:8443/show

with this error message:

/usr/libexec/vyos/op_mode/show_interfaces.py line 303[...] PermissionError: [Errno 1] failed to run command: stty size\n

A quick hack is to wrap the call in a try/except, but probably the call must be done only for interactive sessions.

def split_text(text, used=0):
  try:
      returned = cmd('stty size')
      rows, columns = [int(_) for _ in returned]
  except:
      rows, columns = (40, 80)

Details

Difficulty level
Easy (less than an hour)
Version
1.3-rolling-202009300117
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Stricter validation
Issue type
Bug (incorrect behavior)

Event Timeline

This bug is still present in VyOS 1.4-rolling-202104061143.

curl -ks --location --request POST 'https://172.31.255.1:/show' --form data='{"op": "show", "path": ["interfaces"]}' --form key='MY-KEY' | json_pp 
{
 "data" : "Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down\nInterface        IP Address                        S/L  Description\n---------        ----------                        ---  -----------\nTraceback (most recent call last):\n  File \"/usr/libexec/vyos/op_mode/show_interfaces.py\", line 313, in <module>\n    args.vrrp\n  File \"/usr/libexec/vyos/op_mode/show_interfaces.py\", line 48, in handled_function\n    function(*args, **kwargs)\n  File \"/usr/libexec/vyos/op_mode/show_interfaces.py\", line 233, in run_show_intf_brief\n    descs = list(split_text(interface.get_alias(),0))\n  File \"/usr/libexec/vyos/op_mode/show_interfaces.py\", line 98, in split_text\n    returned = cmd('stty size')\n  File \"/usr/lib/python3/dist-packages/vyos/util.py\", line 179, in cmd\n    raise OSError(code, feedback)\nPermissionError: [Errno 1] failed to run command: stty size\nreturned: \nexit code: 1\n",
 "error" : null,
 "success" : true
}

The important part to pull out of the answer is this:

Traceback (most recent call last):
  File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 313, in <module> args.vrrp
  File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 48, in handled_function function(*args, **kwargs)
  File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 233, in run_show_intf_brief descs = list(split_text(interface.get_alias(),0))
  File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 98, in split_text returned = cmd('stty size')
  File "/usr/lib/python3/dist-packages/vyos/util.py", line 179, in cmd raise OSError(code, feedback)
PermissionError: [Errno 1] failed to run command: stty size 
returned: exit code: 1

This happens on any show command using the "interfaces" path tree.

jestabro moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.
jestabro moved this task from Need Triage to Finished on the VyOS 1.3 Equuleus board.
erkin renamed this task from call to commandd 'stty_size' cause show interfaces API to fail. to Calling 'stty_size' causes show interfaces API to fail.Aug 29 2021, 12:47 PM
erkin set Issue type to Bug (incorrect behavior).
erkin removed a subscriber: Active contributors.