mount.mounted exits on "IndexError: list index out of range" if run a 2nd time on already mounted mountpoints in a for loop
Open
Nobody has claimed this yet.
bug
severity-medium
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description of Issue
mount.mounted runs fine iterating over a loop of mountpoints but when it runs for a 2nd time, it errors out with "IndexError: list index out of range". The mounts stay mounted but salt stops. Without the for loop of course it works..
Setup
[~]# cat mount-from-grains.sls
{% for MOUNT in grains['mountpoints'] %}
/mnt/{{ MOUNT }}/:
mount.mounted:
- name: {{ pillar[ MOUNT ]['name'] }}
- device: {{ pillar[ MOUNT ]['device'] }}
- fstype: {{ pillar[ MOUNT ]['fstype'] }}
- opts: rw,_netdev,user,exec,auto,vers=3.0,cache=none,credentials=/root/.smbcredentials
- mkmnt: True
{% endfor %}
[~]# cd /srv/pillar/MOUNT-01/
[~]# ls
init.sls
[~]# cat init.sls
MOUNT-01:
name:
/mnt/MOUNT-01
device:
//MOUNT-01.domain.com/Share1
fstype:
cifs
opts:
rw,_netdev,user,exec,auto,vers=3.0,cache=none,credentials=/root/.smbcredentials
#########################< the other two are the same
[~]# salt MINION grains.item mountpoints
MINION :
----------
mountpoints:
- MOUNT-01
- MOUNT-02
- MOUNT-03/NESTED
Steps to Reproduce Issue
[~]# salt 'MINION' state.apply mount-from-grains
MINION:
----------
ID: /mnt/MOUNT-01/
Function: mount.mounted
Name: /mnt/MOUNT-01
Result: True
Comment: Target was successfully mounted. Added new entry to the fstab.
Started: 09:20:11.841453
Duration: 138.153 ms
Changes:
----------
mount:
True
persist:
new
----------
ID: /mnt/MOUNT-02/
Function: mount.mounted
Name: /mnt/MOUNT-02
Result: True
Comment: Target was successfully mounted. Added new entry to the fstab.
Started: 09:20:12.010936
Duration: 110.796 ms
Changes:
----------
mount:
True
persist:
new
----------
ID: /mnt/MOUNT-03/NESTED
Function: mount.mounted
Name: /mnt/MOUNT-03/NESTED
Result: True
Comment: Target was successfully mounted. Added new entry to the fstab.
Started: 09:20:12.144262
Duration: 111.894 ms
Changes:
----------
mount:
True
persist:
new
Summary for MINION
------------
Succeeded: 3 (changed=3)
Failed: 0
------------
Total states run: 3
Total run time: 360.843 ms
[~]# salt 'MINION' state.apply mount-from-grains
MINION:
----------
ID: /mnt/MOUNT-01/
Function: mount.mounted
Name: /mnt/MOUNT-01
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/state.py", line 2180, in call
*cdata["args"], **cdata["kwargs"]
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
return callable(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1249, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/states/mount.py", line 430, in mounted
opt = "username={}".format(opt.split("=")[1])
IndexError: list index out of range
Started: 09:20:23.866736
Duration: 90.279 ms
Changes:
----------
ID: /mnt/MOUNT-02/
Function: mount.mounted
Name: /mnt/MOUNT-02
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/state.py", line 2180, in call
*cdata["args"], **cdata["kwargs"]
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
return callable(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1249, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/states/mount.py", line 430, in mounted
opt = "username={}".format(opt.split("=")[1])
IndexError: list index out of range
Started: 09:20:23.982512
Duration: 51.789 ms
Changes:
----------
ID: /mnt/MOUNT-03/NESTED
Function: mount.mounted
Name: /mnt/MOUNT-03/NESTED
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/state.py", line 2180, in call
*cdata["args"], **cdata["kwargs"]
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
return callable(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1249, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/states/mount.py", line 430, in mounted
opt = "username={}".format(opt.split("=")[1])
IndexError: list index out of range
Started: 09:20:24.059216
Duration: 47.912 ms
Changes:
Summary for MINION
------------
Succeeded: 0
Failed: 3
------------
Total states run: 3
Total run time: 189.980 ms
ERROR: Minions returned with non-zero exit code
Versions Report
[~]# salt --versions-report
Salt Version:
Salt: 3004
Dependency Versions:
cffi: 1.15.0
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.11.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 17.0.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.1.4
System Versions:
dist: centos 7 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-1160.45.1.el7.x86_64
system: Linux
version: CentOS Linux 7 Core
[~]# salt MINION --versions-report
Salt Version:
Salt: 3004
Dependency Versions:
cffi: 1.15.0
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.11.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 17.0.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.1.4
System Versions:
dist: centos 7 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-1160.45.1.el7.x86_64
system: Linux
version: CentOS Linux 7 Core
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/states/mount.py around line 430, where the reported IndexError occurs. Reproduce with the provided mount-from-grains state by running state.apply twice on already mounted mountpoints. Done means the second run completes without the exception and reports the mounts correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- infrastructure, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100