mdadm state/module doesn't work
While documentation satates that you should create your RAID like this:
/dev/md0:
raid.present:
- level: 10
....
The code if failing if the options are not nested in "opts", so you have to create it like this:
/dev/md0:
raid.present:
- opts:
- level: 10
....
Now, I get this error:
ID: /dev/md0
Function: raid.present
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1379, in call
**cdata['kwargs'])
File "/usr/lib/pymodules/python2.7/salt/states/mdadm.py", line 104, in present
__salt__['raid.create'](*args)
File "/usr/lib/pymodules/python2.7/salt/modules/mdadm.py", line 193, in create
if arg.startswith('test_mode'):
AttributeError: 'dict' object has no attribute 'startswith'
Changes:
salt --versions-report
Salt: 2014.1.7
Python: 2.7.3 (default, Feb 27 2014, 19:58:35)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.1.10
msgpack-pure: Not Installed
pycrypto: 2.4.1
PyYAML: 3.11
PyZMQ: 13.0.0
ZMQ: 3.2.2
Thanks!
Documentation states the following two methods: METHOD 1:
/dev/md0:
raid.present:
- opts: level=1 chunk=256 raid-devices=2 /dev/xvdd /dev/xvde
METHOD 2:
/dev/md0:
raid.present:
- level: 5
- devices:
- /dev/xvdd
- /dev/xvde
- /dev/xvdf
- chunk: 256
- run: True
Have you tried it with what the documentation suggests? Also please format your code and put them between double back ticks `` (two on each side) so that it's easily readable and whitespace is preserved.
EDIT: Method 1 doesn't work with the latest develop. It should be removed from the documentation. @basepi
I'm sorry i forgot to look at your Salt Version. The implementation and usage has been changed in the latest develop version of Salt. Let me test it with your version of salt.
I got the "-opts" thing from the comment block in this file: /usr/lib/pymodules/python2.7/salt/states/mdadm.py
Which doesn't match the docs I've read here: http://docs.saltstack.com/en/latest/ref/states/all/salt.states.mdadm.html
Here's the piece of doc block:
Verify that the raid is present
name
The name of raid device to be created
opts
The mdadm options to use to create the raid. See
:mod:`mdadm <salt.modules.mdadm>` for more information.
Opts can be expressed as a single string of options.
.. code-block:: yaml
/dev/md0:
raid.present:
- opts: level=1 chunk=256 raid-devices=2 /dev/xvdd /dev/xvde
Or as a list of options.
.. code-block:: yaml
/dev/md0:
raid.present:
- opts:
- level=1
- chunk=256
- raid-devices=2
- /dev/xvdd
- /dev/xvde
After adding all the opts inside "opts", it seemed to work, but I got a different error, which is the one mentioned in the OP
Thanks!
Well the docs you read at http://docs.saltstack.com/en/latest/ref/states/all/salt.states.mdadm.html is for the latest develop version of Salt. Could you try again by replacing your /usr/lib/pymodules/python2.7/salt/modules/mdadm.py file with the one at https://raw.githubusercontent.com/saltstack/salt/develop/salt/states/mdadm.py ?
Don't forget to update your state file to use the new syntax.
EDIT:
/usr/lib/pymodules/python2.7/salt/states/mdadm.py needs to be replaced with the one at https://raw.githubusercontent.com/saltstack/salt/develop/salt/states/mdadm.py
and /usr/lib/pymodules/python2.7/salt/modules/mdadm.py needs to be replaced with the one at https://raw.githubusercontent.com/saltstack/salt/develop/salt/modules/mdadm.py
So is it just a documentation issue, or is there an error here?
Also, @hernanc, I edited your original post and subsequent post with the triple backticks that @nmadhok mentioned. You were using quotes, you need to use the backtick (on the tilde key, sometimes called the grave). Edit either of your posts to see what I mean.
Sounds like we need to move that first example from the docs, @nmadhok, but that there's still an issue with the traceback that was posted?
Sorry I just got time to test this now: Judging for these commits, the doc should be OK and the opts shouldn't have to be nested inside the "opts item" right?
So this is the error I'm having now. I haven't tried @nmadhok 's suggestion yet (that's what comes next) so I'm with the 2014.1.7 from apt:
SLS (just like the doc. I mean, no "opts" item containing the options):
/dev/md0:
raid.present:
- level: 10
- raid-devices: 8
- chunk: 256
- devices:
- /dev/xvdg
- /dev/xvdh
- /dev/xvdi
- /dev/xvdj
- /dev/xvdk
- /dev/xvdl
- /dev/xvdm
- /dev/xvdn
- run: True
ERROR:
ID: /dev/md0
Function: raid.present
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1379, in call
**cdata['kwargs'])
File "/usr/lib/pymodules/python2.7/salt/states/mdadm.py", line 87, in present
args.extend(opts)
TypeError: 'NoneType' object is not iterable
Changes:
salt --versions-report
Salt: 2014.1.7
Python: 2.7.3 (default, Feb 27 2014, 19:58:35)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.1.10
msgpack-pure: Not Installed
pycrypto: 2.4.1
PyYAML: 3.11
PyZMQ: 13.0.0
ZMQ: 3.2.2
Now the code piece that broke:
'''
Verify that the raid is present
name
The name of raid device to be created
opts
The mdadm options to use to create the raid. See
:mod:`mdadm <salt.modules.mdadm>` for more information.
Opts can be expressed as a single string of options.
.. code-block:: yaml
/dev/md0:
raid.present:
- opts: level=1 chunk=256 raid-devices=2 /dev/xvdd /dev/xvde
Or as a list of options.
.. code-block:: yaml
/dev/md0:
raid.present:
- opts:
- level=1
- chunk=256
- raid-devices=2
- /dev/xvdd
- /dev/xvde
'''
ret = {'changes': {},
'comment': '',
'name': name,
'result': True}
salt.utils.warn_until(
'Helium',
'The mdadm API will change drastically in the \'Helium\' Salt '
' release. This will break current states and module calls. '
'See http://salt.rtfd.org/en/latest/ref/modules/all/salt.modules.mdadm.html '
'for more information.'
)
args = [name]
if isinstance(opts, str):
opts = opts.split()
args.extend(opts)
^^^ that last line
Now this is the error that I get if I replace the /usr/lib/pymodules/python2.7/salt/modules/mdadm.py file with the one that @nmadhok suggested
----------
ID: /dev/md0
Function: raid.present
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1379, in call
**cdata['kwargs'])
File "/usr/lib/pymodules/python2.7/salt/states/mdadm.py", line 104, in present
__salt__['raid.create'](*args)
File "/usr/lib/pymodules/python2.7/salt/modules/mdadm.py", line 193, in create
if arg.startswith('test_mode'):
AttributeError: 'dict' object has no attribute 'startswith'
Changes:
@hernanc My bad. I told you to replace the wrong file. Can you replace /usr/lib/pymodules/python2.7/salt/states/mdadm.py with the one on https://raw.githubusercontent.com/saltstack/salt/develop/salt/states/mdadm.py
and /usr/lib/pymodules/python2.7/salt/modules/mdadm.py with the one on https://raw.githubusercontent.com/saltstack/salt/develop/salt/modules/mdadm.py and then try again?
@basepi I believe this is just a documentation issue and maybe some other traceback but let me confirm after @hernanc tries it.
@hernanc I saw you using an invalid option raid-devices. The documentation has it listed as raid_devices.
Here's the corrected state:
/dev/md0:
raid.present:
- level: 10
- raid_devices: 8
- chunk: 256
- devices:
- /dev/xvdg
- /dev/xvdh
- /dev/xvdi
- /dev/xvdj
- /dev/xvdk
- /dev/xvdl
- /dev/xvdm
- /dev/xvdn
- run: True
I've tested the latest develop module and state for mdadm to work with the latest develop salt version as well as Salt 2014.1.7. There was a traceback when using raid_devices option but i have fixed that in a pull request above.
EDIT:
You won't need to specify the option raid_devices after my pull request is merged.
The PR above has been merged, but with our new PR workflow, issues don't always get closed automatically anymore. I'm going to close this, but if this issue is still present, leave a comment and we can re-open.
Hi I haven't got the time to test this yet, I'll get back to it next week. Thanks for all your hard work!