blockdev.format fails with:
ID: format commitlog partition
Function: blockdev.formatted
Name: /dev/xvdq
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1843, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/blockdev.py", line 162, in formatted
__salt__['disk.format_'](name, fs_type, force=force, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1114, in __getitem__
func = super(LazyLoader, self).__getitem__(item)
File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
raise KeyError(key)
KeyError: 'disk.format_
Started: 18:48:04.824170
Duration: 28.28 ms
(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
I attached a volume in aws via /dev/xvdp. Note this volume is not partitioned.
Here is my data_vol.sls:
create /data1:
file.directory:
- name: /data1
format /data1 partition:
blockdev.formatted:
- name: /dev/xvdp
- fs_type: ext4
(Include debug logs if possible and relevant.)
I run with:
salt minion state.apply data_vol
minion:
----------
ID: create /data1
Function: file.directory
Name: /data1
Result: True
Comment: Directory /data1 is in the correct state
Directory /data1 updated
Started: 18:51:58.940637
Duration: 4.938 ms
Changes:
----------
ID: format /data1 partition
Function: blockdev.formatted
Name: /dev/xvdp
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1843, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/blockdev.py", line 162, in formatted
__salt__['disk.format_'](name, fs_type, force=force, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1114, in __getitem__
func = super(LazyLoader, self).__getitem__(item)
File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
raise KeyError(key)
KeyError: 'disk.format_'
Started: 18:51:58.960917
Duration: 360.413 ms
The minion log reports:
2017-11-15 18:51:58,960 [salt.state ][INFO ][12727] Running state [/dev/xvdp] at time 18:51:58.960916
2017-11-15 18:51:58,961 [salt.state ][INFO ][12727] Executing state blockdev.formatted for [/dev/xvdp]
2017-11-15 18:51:58,962 [salt.loaded.int.module.cmdmod][INFO ][12727] Executing command 'blkid -o value -s TYPE /dev/xvdp' in directory '/root'
2017-11-15 18:51:58,987 [salt.loaded.int.module.cmdmod][ERROR ][12727] Command 'blkid -o value -s TYPE /dev/xvdp' failed with return code: 2
2017-11-15 18:51:58,987 [salt.loaded.int.module.cmdmod][ERROR ][12727] output:
2017-11-15 18:51:59,321 [salt.state ][ERROR ][12727] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1843, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/blockdev.py", line 162, in formatted
__salt__['disk.format_'](name, fs_type, force=force, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1114, in __getitem__
func = super(LazyLoader, self).__getitem__(item)
File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
raise KeyError(key)
KeyError: 'disk.format_
2017-11-15 18:51:59,321 [salt.state ][INFO ][12727] Completed state [/dev/xvdp] at time 18:51:59.321330 duration_in_ms=360.413
(Provided by running salt --versions-report
. Please also mention any differences in master/minion versions.)
Salt Version:
Salt: 2017.7.2
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-31-generic
system: Linux
version: Ubuntu 16.04 xenial
NOTE:
It seems to work if I replace line 163 in file /usr/lib/python2.7/dist-packages/salt/states/blockdev.py
__salt__['disk.format_'](name, fs_type, force=force, **kwargs)
to
__salt__['disk.format'](name, fs_type, force=force, **kwargs)
And run:
salt minion state.apply data_vol
minion:
----------
ID: create /data1
Function: file.directory
Name: /data1
Result: True
Comment: Directory /data1 is in the correct state
Directory /data1 updated
Started: 18:54:03.410667
Duration: 4.496 ms
Changes:
----------
ID: format /data1 partition
Function: blockdev.formatted
Name: /dev/xvdp
Result: True
Comment: /dev/xvdp has been formatted with ext4
Started: 18:54:03.428932
Duration: 1070.711 ms
Changes:
----------
new:
ext4
old:
ext4
@justin-sunayu Thanks for the report. Looks like this was fixed here:
https://github.com/saltstack/salt/pull/44029 and should be available in the next 2017.7 release.
Thanks Gareth!
This bug is annoying me to no end. In particular since it has already been reported, that no fix for it has been forthcoming for months and most of all that the obvious fix for it doesn't work either:
## -- Fix Salt bug --
Workaround for Salt Bug 44559:
cmd.run:
- name: sed -i '/format_/s/format_/format/' /usr/lib/python2.7/site-packages/salt/states/blockdev.py
- unless: ! fgrep -q 'format_' /usr/lib/python2.7/site-packages/salt/states/blockdev.py
Apparently the "!" is totally ignored in the "unless" requisite.
What gives?
@MikeH-Halo Same here..
I used your approach to the problem but used _onlyif_ instead of _unless_:
- onlyif: grep 'format_' <file>
Alternatively blockdev.formatted can be replaced by cmd.run to additionally support format settings like:
/dev/xvdb:
cmd.run:
- name: '/sbin/mkfs.xfs -d su=128k,sw=8 -l version=2,su=128k -isize=512 /dev/xvdb'
- unless: '/usr/bin/file -s /dev/xvdb | grep -q "XFS filesystem data"'
- require:
- pkg: xfsprogs.x86_64
When this fixed in 2016.11 ?
I don't believe this has been patched yet. I still have the issue on 2017.7.2
Looks like this was fixed with 2017.7.3! Thanks guys!
Most helpful comment
@MikeH-Halo Same here..
I used your approach to the problem but used _onlyif_ instead of _unless_:
- onlyif: grep 'format_' <file>