Skip to content

[CLI] runner-all command is bugged #593

Closed

Description

@weakcamel

Description of the problem, including code/CLI snippet

There are 2 problems with runner all command in CLI; I'm not sure if they're related to each other or completely independent.

The --id argument is required - while it shouldn't be - and its value seems to be ignored.

With a workaround (added a dummy --id foobar I get the output in the "legacy" format - which is slightly better - but when trying to retrieve it in JSON, it fails again with an exception. Attaching examples below.

Expected Behavior

$ gitlab  runner all --scope active

Expected: successful list of all runners in "legacy" format (whatever it might be)

$ gitlab -o json runner all --scope active

Expected: successful list of all runners in JSON.

Actual Behavior

a) CLI usage failure:

$ gitlab  runner all --scope active
usage: gitlab runner all [-h] --id ID [--scope SCOPE]
gitlab runner all: error: the following arguments are required: --id

b) with a workaround but in JSON or YAML output format:

$ gitlab  -o yaml runner all --scope active --id foobar
Traceback (most recent call last):
  File "/Users/weakcamel/git/gitlab/scripts/venv/bin/gitlab", line 12, in <module>
    sys.exit(main())
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/cli.py", line 179, in main
    cli_module.run(gl, what, action, args, verbose, output, fields)
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 386, in run
    printer.display_list(data, fields, verbose=verbose)
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 311, in display_list
    [get_dict(obj, fields) for obj in data],
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 311, in <listcomp>
    [get_dict(obj, fields) for obj in data],
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 290, in get_dict
    return obj.attributes
AttributeError: 'dict' object has no attribute 'attributes'

$ gitlab  -o json runner all --scope active --id foobar
Traceback (most recent call last):
  File "/Users/weakcamel/git/gitlab/scripts/venv/bin/gitlab", line 12, in <module>
    sys.exit(main())
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/cli.py", line 179, in main
    cli_module.run(gl, what, action, args, verbose, output, fields)
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 386, in run
    printer.display_list(data, fields, verbose=verbose)
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 300, in display_list
    print(json.dumps([get_dict(obj, fields) for obj in data]))
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 300, in <listcomp>
    print(json.dumps([get_dict(obj, fields) for obj in data]))
  File "/Users/weakcamel/git/gitlab/scripts/venv/lib/python3.7/site-packages/gitlab/v4/cli.py", line 290, in get_dict
    return obj.attributes
AttributeError: 'dict' object has no attribute 'attributes'

Specifications

  • python-gitlab version: 1.6.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 10.8.5

Activity

  1. weakcamel commented on Sep 21, 2018

    @weakcamel
    ContributorAuthor

    A bit similar to #191

  2. pvdissel commented on Aug 27, 2019

    @pvdissel

    Issue still exists :(

    • python-gitlab version: 1.6.0
    • API version you are using (v3/v4): v4
    • Gitlab server version (or gitlab.com): 11.9.6
  3. chrisoldwood commented on Jan 29, 2020

    @chrisoldwood

    I was trying to work out why I couldn't see shared runners and assumed it was a permissions thing but now I've had that sorted I've discovered another issue: gitlab runner list --all is not the same as gitlab runner all 🙂 . The spurious --id argument made no sense so I never really gave it a chance.

    The clue for me that I'd misunderstood was in #850 (Runner List does not support pagination options) but I think it would be nice if this could made clearer somewhere in the documentation or command line help.

    FWIW this is still broken with python-gitlab version 1.15.0.

  4. chrisoldwood commented on Jan 29, 2020

    @chrisoldwood

    I'm no Python expert but I've managed to fix the crash and get JSON output working by looking at the code for the all custom action on the GroupMemberManager class.

    Hence in v4/objects.py inside the RunnerManager class all method (around line 4881 in 1.15.0), replace:

    return self.gitlab.http_list(path, query_data, **kwargs)
    

    with

    obj = self.gitlab.http_list(path, query_data, **kwargs)
    return [self._obj_cls(self, item) for item in obj]
    

    It still asks for the --id argument but you can just pass --id 0 on the command line as it's ignored.

  5. chrisoldwood commented on Jan 29, 2020

    @chrisoldwood

    An alternative workaround, if you're looking for the paging behaviour (which is also broken) and want to avoid the spurious --id argument is to add a new type, called say all-runners, that behaves like runner list, e.g.

    $ gitlab -o json all-runners list --page 2 | jq
    

    This is the snippet of code I added to support that:

    class AllRunners(RESTObject):
        pass
    
    class AllRunnersManager(ListMixin, RESTManager):
        _path = "/runners/all"
        _obj_cls = AllRunners
        _list_filters = ("scope",)
    

    I looked in v4/cli.py and I think the code for handling custom_actions assumes that if the object type has an id then that must be a mandatory argument. But that's clearly all just conjecture though.

                # We need to get the object somehow
                if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(cls):
                    if cls._id_attr is not None:
                        id_attr = cls._id_attr.replace("_", "-")
                        sub_parser_action.add_argument("--%s" % id_attr, required=True)
    
  6. locked as resolved and limited conversation to collaborators on Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions