Skip to content

[BUG] Spacewalk runner does not properly parse method namespaces #57442

Closed

Description

@LinuxLeafFan

Description
The spacewalk runner does not properly parse the method namespaces. It assumes that a simple .split('.') will result in a two element list [ namespace, method ]. This works in simple cases such as 'system.listSystems' but fails for namespaces such as 'channel.software.listChildren' which results in three elements and causes the following exception:

Exception occurred in runner spacewalk.api: Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/client/mixins.py", line 377, in low
    data['return'] = func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/runners/spacewalk.py", line 175, in api
    namespace, method = command.split('.')
ValueError: too many values to unpack (expected 2)

Setup
N/A

Steps to Reproduce the behavior
salt-run $spacewalkserver spacewalk.api channel.software.listChildren $basechannel

Expected behavior
Should not cause a stack trace

Screenshots
If applicable, add screenshots to help explain your problem.

Versions Report
Irrelevant. Bug has been present since runner was initially committed.
I'm running a 2019.2 branch and it's still present in Salt 3000.1

Proposed Fix

salt/runners/spacewalk.py
168c168,169
<     namespace, method = command.split(".")
---
>     namespace = ".".join(command.split('.')[:-1])
>     method = command.split('.')[-1]

Activity

  1. added
    bug
    on May 23, 2020
  2. Akm0d commented on May 27, 2020

    @Akm0d
    Contributor

    I wonder if command.split(".", maxsplit=2) could also do the trick.

    @LinuxLeafFan Do you want to try opening a PR to fix this?

  3. added this to the Approved milestone on May 27, 2020
  4. agraul commented on May 28, 2020

    @agraul
    Contributor

    command.split(".", maxsplit=2) does not work, since maxsplit is the number of allowed splits. With 2 splits there would be 3 elements in the list. maxsplit=1 does not work either in this case since it starts on the left side and puts too many things on the right element in the resulting list:

    >>> command = "foo.bar.baz"
    >>> command.split(".", maxsplit=2)
    ['foo', 'bar', 'baz']
    >>> command.split(".", maxsplit=1)
    ['foo', 'bar.baz']
  5. added
    Magnesium
    on May 29, 2020
  6. removed
    P4
    on Jun 3, 2020
  7. added
    severity-medium
    on Jul 6, 2020
  8. added a commit that references this issue on Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Execution-ModuleMagnesiumbugseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions