Page MenuHomeVyOS Platform

VMWare resume script syntax errors
Closed, ResolvedPublic

Description

The VMWare resume scripts seem broken since T2467 since a change was made there which explicitly assumes that "command" is a string by splitting it: https://github.com/vyos/vyos-1x/blame/b5c608949719f4fcbf4234a0e8e52e5d7692b362/python/vyos/util.py#L27

However the VMWare resume script (https://github.com/vyos/vyos-1x/blob/current/src/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py#L53) executes commands as a list which gives the following error:

vyos@vyos:~$ sudo python3 /etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py
Traceback (most recent call last):
  File "/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py", line 63, in <module>
    apply(config)
  File "/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py", line 48, in apply
    run(cmd)
  File "/usr/lib/python3/dist-packages/vyos/util.py", line 148, in run
    decode=decode,
  File "/usr/lib/python3/dist-packages/vyos/util.py", line 83, in popen
    command = _add_sudo(command)
  File "/usr/lib/python3/dist-packages/vyos/util.py", line 31, in _add_sudo
    if _need_sudo(command):
  File "/usr/lib/python3/dist-packages/vyos/util.py", line 27, in _need_sudo
    return os.path.basename(command.split()[0]) in ('systemctl', )

It's a bit odd to assume that command is a string since the function is documented as a wrapper around python's Popen which accepts a list. Adding autosudo=False from the resume script might fix this as well but having clear expectations/checks in the utils module would make more sense to me.

Details

Difficulty level
Unknown (require assessment)
Version
1.3-rolling-202104160642
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Behavior change
Issue type
Bug (incorrect behavior)

Event Timeline

Note that adding autosudo=False to the call to cmd does not fix this issue because this parameter is never passed to popen: https://github.com/vyos/vyos-1x/blob/current/python/vyos/util.py#L143

c-po triaged this task as Normal priority.
c-po added a project: VyOS 1.4 Sagitta.
c-po moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.
c-po moved this task from Need Triage to Finished on the VyOS 1.3 Equuleus board.
SrividyaA set Issue type to Bug (incorrect behavior).Aug 31 2021, 3:17 PM