saltstack/salt — pull request #11004 by dumol (2014-03-06 15:08:03+00:00)
Title: Made the salt-ssh shell shim compatible with AIX.

`salt-ssh` fails for AIX targets, as discussed at https://groups.google.com/forum/#!searchin/salt-users/aix/salt-users/G_a53lNYPsA/Vt6-WWjP-uUJ :
```
$ salt-ssh -c ./etc/salt/ '*aix*' test.ping
aix-aix-5.3-ppc64:
----------
retcode:
127
stderr:
/bin/sh[28]: 0652-141: 0403-012 A test command parameter is not valid.
/bin/sh[28]: 0652-141: 0403-012 A test command parameter is not valid.
/bin/sh[28]: 0652-141: 0403-012 A test command parameter is not valid.
/bin/sh[28]: 0652-141: 0403-012 A test command parameter is not valid.
/bin/sh[47]: 0652-141: 0403-012 A test command parameter is not valid.
/bin/sh[47]: 0652-141: 0403-012 A test command parameter is not valid.
The following required Packages are missing: md5 or md5sum

stdout:

```
The list of fixes:
* fixed shell tests
* made variables definitions safer
* replaced `which` with the POSIX built-in `command -v`
* added code for MD5 checking through AIX's `csum`
* added support for `md5` binaries in non-standard locations
* replaced current `tar` invocation with a more portable one
* added one more error code for failed checksumming, this replaces the generic error that sometimes occurs on first call:
```
freebsd-freebsd-10.0-x86:
----------
retcode:
2
stderr:
/usr/local/bin/python2.7: can't open file '/tmp/.salt/salt-call': [Errno 2] No such file or directory

stdout:

```
with a specific new one:
```
freebsd-freebsd-10.0-x86:
----------
retcode:
1
stderr:
Mismatched checksum for /tmp/.salt/salt-thin.tgz

stdout:

```
The test fixes also prevents errors such as:
```
linux-ubuntu-1204-x64:
----------
retcode:
2
stderr:
/bin/sh: 35: [: /usr/bin/python2.7: unexpected operator
/bin/sh: 60: [: /usr/bin/md5sum: unexpected operator
```
End result:
```
$ salt-ssh -c ./etc/salt/ '*aix*' test.ping
aix-aix-5.3-ppc64:
True
```
Tested on a variety of OS's:
```
$ salt-ssh -c ./etc/salt/ '*' grains.item os oscodename osfinger os_family osfullname osarch cpuarch | grep stdout -A1
stdout:
{"osarch": "x86_64", "cpuarch": "x86_64", "osfullname": "Gentoo", "os_family": "Gentoo", "oscodename": "", "os": "Gentoo"}
--
stdout:
{"osarch": "x86_64", "cpuarch": "x86_64", "osfullname": "SUSE", "os_family": "Suse", "oscodename": "n.a", "os": "SUSE"}
--
stdout:
{"osarch": "i386", "cpuarch": "i686", "osfullname": "Ubuntu", "os_family": "Debian", "oscodename": "lucid", "osfinger": "Ubuntu-10.04", "os": "Ubuntu"}
--
stdout:
{"osarch": "x86_64", "cpuarch": "x86_64", "osfullname": "Red Hat Enterprise Linux AS", "os_family": "RedHat", "oscodename": "Nahant Update 8", "osfinger": "Red Hat Enterprise Linux AS-4", "os": "RedHat"}
--
stdout:
{"osarch": "amd64", "cpuarch": "x86_64", "osfullname": "Ubuntu", "os_family": "Debian", "oscodename": "precise", "osfinger": "Ubuntu-12.04", "os": "Ubuntu"}
--
stdout:
{"osarch": "i386", "os_family": "FreeBSD", "os": "FreeBSD", "cpuarch": "i386"}
--
stdout:
{"osarch": "0001963AD300", "os_family": "AIX", "os": "AIX", "cpuarch": "0001963AD300"}
--
stdout:
{"osarch": "sparc", "cpuarch": "sparc64", "osfullname": "Debian GNU/Linux", "os_family": "Debian", "oscodename": "", "os": "Debian"}
```