saltstack / saltstack/salt

[BUG] calling btrfs.resize from module.run fails

Open
#66,069 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
When calling the module btrfs.resize from a module.runstanza it fails with NameError: name '__salt__' is not defined
Setup
(Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)

Please be as specific as possible and give set-up details.

  • on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • [X ] EC2 instance on ARM
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit
  • jails if it is FreeBSD
  • classic packaging
  • onedir packaging
  • used bootstrap to install

Steps to Reproduce the behavior

Have a sls file with this content:

resize /data filesystem:
  module.run:
    - btrfs.resize:
      - mountpoint: /data
      - size: max

When /data is a mounted btrfs filesystem.

I'm getting

          ID: resize /data filesystem
    Function: module.run
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/state.py", line 2423, in call
                  ret = self.states[cdata["full"]](
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in __call__
                  ret = self.loader.run(run_func, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1293, in wrapper
                  return f(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/module.py", line 396, in run
                  return _run(**kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/module.py", line 451, in _run
                  func_ret = _call_function(
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/module.py", line 497, in _call_function
                  mret = salt.utils.functools.call_function(__salt__[name], *func_args, **func_kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/functools.py", line 174, in call_function
                  return salt_function(*function_args, **function_kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in __call__
                  ret = self.loader.run(run_func, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/btrfs.py", line 394, in resize
                  if not salt.utils.fsutils._is_device(mountpoint):
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/fsutils.py", line 115, in _is_device
                  out = __salt__["cmd.run_all"]("file -i {}".format(path))
              NameError: name '__salt__' is not defined
     Started: 05:56:38.877384
    Duration: 2.188 ms
     Changes:

Expected behavior
it should work, it seems that if I specify a size and not max it's not erroring.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
salt-call  --versions-report
Salt Version:
          Salt: 3006.6

Python Version:
        Python: 3.10.13 (main, Nov 15 2023, 04:37:53) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.3
       libgit2: Not Installed
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.14.2
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: ubuntu 22.04.3 jammy
        locale: utf-8
       machine: aarch64
       release: 6.2.0-1018-aws
        system: Linux
       version: Ubuntu 22.04.3 jammy


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with salt/modules/btrfs.py at resize and salt/utils/fsutils.py at _is_device, then reproduce the provided module.run SLS with a mounted Btrfs filesystem and size: max. The fix is done when this invocation completes without the reported salt NameError and behaves like the non-max resize case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.