maas-cli calls into regiond and rackd code

Bug #1924812 reported by Lee Trager
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Status tracked in 3.6
3.5
Won't Fix
Low
Unassigned
3.6
Triaged
Low
Unassigned

Bug Description

I tried using the maas-cli from the Debian packages and was unable to. This ended up being due to a change I was testing but exposed an issue with the maas-cli, it calls into rackd and regiond. This explains why even a simple --help takes 2 seconds. The maas-cli should be completely independent from MAAS.

$ time maas --help
usage: maas [-h] COMMAND ...

optional arguments:
  -h, --help show this help message and exit

drill down:
  COMMAND
    login Log in to a remote API, and remember its description and credentials.
    logout Log out of a remote API, purging any stored credentials.
    list List remote APIs that have been logged-in to.
    refresh Refresh the API descriptions of all profiles.
    init Initialize controller.
    apikey Used to manage a user's API keys. Shows existing keys unless --generate or --delete
                  is passed.
    configauth Configure external authentication.
    createadmin Create a MAAS administrator account.
    changepassword
                  Change a MAAS user's password.
    maas Interact with http://10.0.0.2:5240/MAAS/api/2.0/

http://maas.io/

real 0m2.024s
user 0m1.880s
sys 0m0.144s

$ maas --help
Traceback (most recent call last):
  File "/usr/bin/maas", line 11, in <module>
    load_entry_point('maas==3.0.0b3', 'console_scripts', 'maas')()
  File "/usr/lib/python3/dist-packages/maascli/__init__.py", line 39, in main
    parser = prepare_parser(argv)
  File "/usr/lib/python3/dist-packages/maascli/parser.py", line 75, in prepare_parser
    register_cli_commands(parser)
  File "/usr/lib/python3/dist-packages/maascli/cli.py", line 274, in register_cli_commands
    django_setup()
  File "/usr/lib/python3/dist-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib/python3/dist-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/lib/python3/dist-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/maasserver/models/__init__.py", line 677, in <module>
    from maasserver.models import signals # noqa:E402 isort:skip
  File "/usr/lib/python3/dist-packages/maasserver/models/signals/__init__.py", line 29, in <module>
    from maasserver.models.signals import (
  File "/usr/lib/python3/dist-packages/maasserver/models/signals/nodes.py", line 21, in <module>
    from metadataserver.models.nodekey import NodeKey
  File "/usr/lib/python3/dist-packages/metadataserver/models/__init__.py", line 12, in <module>
    from metadataserver.models.scriptresult import ScriptResult
  File "/usr/lib/python3/dist-packages/metadataserver/models/scriptresult.py", line 28, in <module>
    from metadataserver.builtin_scripts.hooks import NODE_INFO_SCRIPTS
  File "/usr/lib/python3/dist-packages/metadataserver/builtin_scripts/__init__.py", line 15, in <module>
    from maasserver.forms.script import ScriptForm
  File "/usr/lib/python3/dist-packages/maasserver/forms/__init__.py", line 112, in <module>
    from maasserver.forms.settings import (
  File "/usr/lib/python3/dist-packages/maasserver/forms/settings.py", line 21, in <module>
    from maasserver.bootresources import IMPORT_RESOURCES_SERVICE_PERIOD
  File "/usr/lib/python3/dist-packages/maasserver/bootresources.py", line 98, in <module>
    from provisioningserver.upgrade_cluster import create_gnupg_home
  File "/usr/lib/python3/dist-packages/provisioningserver/upgrade_cluster.py", line 29, in <module>
    from provisioningserver.boot import BootMethodRegistry
  File "/usr/lib/python3/dist-packages/provisioningserver/boot/__init__.py", line 503, in <module>
    load_registry()
  File "/usr/lib/python3/dist-packages/provisioningserver/boot/__init__.py", line 452, in load_registry
    with ClusterConfiguration.open() as config:
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/usr/lib/python3/dist-packages/provisioningserver/config.py", line 693, in open
    with cls.backend.open(filepath) as store:
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/usr/lib/python3/dist-packages/provisioningserver/config.py", line 534, in open
    touch(path)
  File "/usr/lib/python3/dist-packages/provisioningserver/config.py", line 326, in touch
    os.close(os.open(path, os.O_CREAT | os.O_APPEND, mode))
PermissionError: [Errno 13] Permission denied: '/etc/maas/rackd.conf'

Revision history for this message
Alberto Donato (ack) wrote :

maas-cli detects whether the region controller code is available, in which case it adds the "init" command and other django-related commands that we expose from the region.

To do that, it has to call Django setup code.

Ideally we should have entirely separate commands for the CLI and MAAS management.

Changed in maas:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Adam Collard (adam-collard) wrote :

Whilst we don't want to tackle the CLI being separate from rack and region (albeit that we recognise a new CLI is needed) we shouldn't try and create files when importing Python modules.

Changed in maas:
importance: Medium → Low
milestone: none → 3.5.0
Changed in maas:
milestone: 3.5.0 → 3.5.x
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.