Zpool.present with raid layout fails via salt-ssh, 2018.3.2
Description of Issue
When running zpool.present via salt-ssh with a layout more complex than just a list of disks it will fail with:
ID: newpool
Function: zpool.present
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/var/tmp/.rs-salt_1ec649_salt/py2/salt/state.py", line 1905, in call
**cdata['kwargs'])
File "/var/tmp/.rs-salt_1ec649_salt/py2/salt/loader.py", line 1830, in wrapper
return f(*args, **kwargs)
File "/var/tmp/.rs-salt_1ec649_salt/py2/salt/states/zpool.py", line 279, in present
vdevs = _layout_to_vdev(layout, config['device_dir'])
File "/var/tmp/.rs-salt_1ec649_salt/py2/salt/states/zpool.py", line 134, in _layout_to_vdev
if device_dir and vdev[0] != '/':
KeyError: 0
Started: 13:42:43.957202
Duration: 17.286 ms
Changes:
Running the same state via salt-call --local state.apply ... works fine as does a regular salt call, e.g. salt minion state.apply ....
I did modify the states/zpool.py in the delivered payload and added the following lines between line 130 and 131:
for vdev in layout:
+ print(type(vdev))
+ print(vdev)
if isinstance(vdev, OrderedDict):
Running the payload locally produced the following output:
<type 'dict'>
{u'raidz': [u'/tmp/ztest0', u'/tmp/ztest1', u'/tmp/ztest2']}
Seems like vdev is not an OrderedDict when used via salt-ssh and therefore might actually be caused further up the chain before the pillar data is handled in states/zpool.py. At least as far as I can tell from reading the code.
Setup
I used Vagrant with the libvirt provider (but VirtualBox should work as well with some modifications in the provider settings) to set up a test environment for anyone to reproduce.
Create Vagrantfile
cd $(mktemp -d) && cat >Vagrantfile <<EOF
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# general settings
config.vm.network "private_network", type: "dhcp"
# salt settings
config.vm.provision :salt do |salt|
salt.masterless = true
salt.install_type = "stable"
salt.install_args = "2018.3.1"
end
config.vm.box = "debian/stretch64"
# define salt master
config.vm.define "salt" do |salt|
config.vm.hostname = "salt"
config.vm.provision :salt do |salt|
salt.install_master = true
end
# provide enough memory
config.vm.provider :libvirt do |libvirt|
libvirt.memory = 2048
end
end
# define salt minion
config.vm.define "minion" do |minion|
config.vm.hostname = "minion"
end
end
EOF
Commands
vagrant up
Setup salt master
vagrant ssh salt
sudo -i
mkdir -p /srv/salt
cat >/srv/salt/zfs_test_simple.sls <<EOF
newpool:
zpool.present:
- config:
import: false
force: true
- properties:
comment: salty storage pool
- layout:
- /tmp/ztest1
- /tmp/ztest2
EOF
cat >/srv/salt/zfs_test_failing.sls <<EOF
newpool:
zpool.present:
- config:
import: false
force: true
- properties:
comment: salty storage pool
- layout:
- mirror:
- /tmp/ztest1
- /tmp/ztest2
EOF
# add salt repo to install salt-ssh
wget -O - https://repo.saltstack.com/apt/debian/9/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
cat >/etc/apt/sources.list.d/saltstack.list <<EOF
deb http://repo.saltstack.com/apt/debian/9/amd64/latest stretch main
EOF
apt update && apt full-upgrade -y
apt install salt-ssh
# run salt-ssh to generate ssh keys and trust minion
salt-ssh -i minion test.ping
# get salt ssh public key, needed on minion
cat /etc/salt/pki/master/ssh/salt-ssh.rsa.pub
# leave salt master or better open another shell in the tmp dir
exit
exit
Continue in the minion box and prep it
vagrant ssh minion
sudo -i
# add contrib to repo
cat >/etc/apt/sources.list <<EOF
deb http://httpredir.debian.org/debian stretch main contrib
EOF
apt update && apt full-upgrade -y
apt install zfsutils-linux
modprobe zfs
Prep the minion for salt-ssh:
mkdir -p /root/.ssh -m 700
nano /root/.ssh/authorized_keys
# paste the public ssh key from master
Create sparse files on minion for ZFS pool devices:
dd if=/dev/zero of=/tmp/ztest1 bs=1 count=0 seek=2G
dd if=/dev/zero of=/tmp/ztest2 bs=1 count=0 seek=2G
Steps to Reproduce Issue
On the salt master:
Accept the minion key:
salt-key --accept-all
Now run the states with a zpool destroy newpoool in between.
# this will work
salt-ssh minion state.apply zfs_test_simple
salt-ssh minion cmd.run 'zpool destroy newpool'
# this will fail
salt-ssh minion state.apply zfs_test_failing
Running them normally, e.g. salt minion state.apply zfs_test_failing, will work fine.
Versions Report
salt-master
root@salt:~# salt-call --versions-report
Salt Version:
Salt: 2018.3.2
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.5.3
docker-py: Not Installed
gitdb: 2.0.0
gitpython: 2.1.1
ioflo: Not Installed
Jinja2: 2.9.4
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.13 (default, Nov 24 2017, 17:33:09)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: 2.0.1
timelib: Not Installed
Tornado: 4.4.3
ZMQ: 4.2.1
System Versions:
dist: debian 9.4
locale: ANSI_X3.4-1968
machine: x86_64
release: 4.9.0-6-amd64
system: Linux
version: debian 9.4
salt-minion
root@minion:~# salt-call --versions-report
Salt Version:
Salt: 2018.3.2
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.5.3
docker-py: Not Installed
gitdb: 2.0.0
gitpython: 2.1.1
ioflo: Not Installed
Jinja2: 2.9.4
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.13 (default, Nov 24 2017, 17:33:09)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: 2.0.1
timelib: Not Installed
Tornado: 4.4.3
ZMQ: 4.2.1
System Versions:
dist: debian 9.4
locale: ANSI_X3.4-1968
machine: x86_64
release: 4.9.0-6-amd64
system: Linux
version: debian 9.4
@sjorge Any thoughts on why this would have different results over salt-ssh?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
Oops, didn't see this before! Not sure why it's not working via salt-ssh.
But they should be OrderedDict for a reason, as we need to keep the correct structure/order after parsing the zpool output.
Is salt-ssh perhaps doing something different wrt Dict vs OrderedDict?
Thank you for updating this issue. It is no longer marked as stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
@saltstack/team-ssh or @saltstack/team-core this likely needs to be followed-up
Thank you for updating this issue. It is no longer marked as stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
I cant confirm that salt-ssh on master branch doesn't keep OrderedDicts. Simple case is this (see the comment argument of the state):
$ cat /srv/salt/base/odict_test.sls
do the odict test:
test.configurable_test_state:
- comment:
key1: val1
key2: val2
$ ./scripts/salt-call -l warning --local state.apply odict_test
local:
----------
ID: do the odict test
Function: test.configurable_test_state
Result: True
Comment: OrderedDict([('key1', 'val1'), ('key2', 'val2')])
Started: 20:47:02.996880
Duration: 0.646 ms
Changes:
----------
testing:
----------
new:
Something pretended to change
old:
Unchanged
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 0.646 ms
$ ./scripts/salt-ssh -l warning alpha state.apply odict_test
alpha:
----------
ID: do the odict test
Function: test.configurable_test_state
Result: True
Comment: {'key1': 'val1', 'key2': 'val2'}
Started: 20:47:28.822345
Duration: 0.552 ms
Changes:
----------
testing:
----------
new:
Something pretended to change
old:
Unchanged
Summary for alpha
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 0.552 ms
$ ./scripts/salt --version
salt 3000.1-1-gcdca5aafe0
Closing this issue due to age and lack of activity. Please test this on version 3006.2 and create a new issue if the problem persists. The new issue template has more information and will allow us to track and reproduce the issue more effectively. Thanks!