From dfd82ad0bd33d892e0025d76a70997e2f1ebb1f2 Mon Sep 17 00:00:00 2001 From: Corey Quinn Date: Mon, 16 Jan 2012 15:36:59 -0800 Subject: [PATCH] Debian/Ubuntu package for upstream acceptance Applying latest changes for packaging Fixed typos in man pages Latest round of changes More packaging fixups Fixed salt-common typo Fixed wildcarding in install files Removed extra man pages Removed trailing slash Fixed links Moved binaries to proper packages Fixed man pages Pathing Perms tweak Missing files Fixed spacing Fixed another lintian error build the msgpack stuff Updating rules and install files Fixed shebang Control updates Fixed copyright file Fixed lintian Fixed overrides cmd.retcode no longer uses subprocess.call since it is broken fix issue with source_hash and trailing whitespace Bye-bye pickle, hello msgpack Add docs for new source powers Add support for source_hash to be a source hash string add pure python template type add return clarifying that no states were found if no states are found change some strings to use format add code to cache jobs on the minion if option is set serialize cache data was caching the wrong line data Add cache_jobs to the minion config template add docs for new config param cache_jobs make the minions return to the master in addition to returning to returners Add capability to designate multiple returns only run the apache module if apachectl is installed only load solr module if solr is installed Debug statement used the wrong variable. Only load nginx on machines that have nginx installed Make it more like the apache module --- conf/minion.template | 10 ++- debian/changelog | 2 +- debian/control | 50 +++++++------ debian/copyright | 6 +- debian/lintian-overrides | 3 + debian/rules | 5 +- debian/salt-common.install | 34 ++++++--- debian/salt-common.manpages | 1 + debian/salt-master.install | 7 +- debian/{links => salt-master.links} | 3 - debian/salt-master.manpages | 5 +- debian/salt-minion.install | 8 +-- debian/salt-minion.links | 2 + debian/salt-syndic.install | 1 + debian/salt-syndic.links | 1 + debian/salt.manpages | 9 --- doc/man/salt-cp.1 | 6 +- doc/man/salt.7 | 13 ++-- doc/ref/cli/salt-cp.rst | 6 +- doc/ref/configuration/minion.rst | 19 +++++ doc/topics/index.rst | 3 +- salt/__init__.py | 0 salt/config.py | 1 + salt/log.py | 0 salt/minion.py | 63 ++++++++++++----- salt/modules/apache.py | 11 +++ salt/modules/cmd.py | 2 +- salt/modules/mysql.py | 0 salt/modules/nginx.py | 18 ++++- salt/modules/solr.py | 17 +++-- salt/returners/cassandra_return.py | 2 +- salt/state.py | 8 +++ salt/states/file.py | 106 ++++++++++++++++++++++------ salt/states/mysql_database.py | 0 salt/states/mysql_user.py | 0 salt/utils/find.py | 0 scripts/salt | 2 +- scripts/salt-call | 2 +- scripts/salt-cp | 2 +- scripts/salt-key | 2 +- scripts/salt-master | 2 +- scripts/salt-minion | 2 +- scripts/salt-run | 2 +- scripts/salt-syndic | 2 +- 44 files changed, 305 insertions(+), 133 deletions(-) create mode 100644 debian/lintian-overrides create mode 100644 debian/salt-common.manpages rename debian/{links => salt-master.links} (59%) create mode 100644 debian/salt-minion.links create mode 100644 debian/salt-syndic.links delete mode 100644 debian/salt.manpages mode change 100755 => 100644 salt/__init__.py mode change 100755 => 100644 salt/log.py mode change 100755 => 100644 salt/modules/apache.py mode change 100755 => 100644 salt/modules/mysql.py mode change 100755 => 100644 salt/modules/nginx.py mode change 100755 => 100644 salt/states/mysql_database.py mode change 100755 => 100644 salt/states/mysql_user.py mode change 100755 => 100644 salt/utils/find.py diff --git a/conf/minion.template b/conf/minion.template index 669ff76f6c1..3d739a4998e 100644 --- a/conf/minion.template +++ b/conf/minion.template @@ -29,10 +29,16 @@ # Where cache data goes #cachedir: /var/cache/salt +# The minion can locally cache the return data from jobs sent to it, this +# can be a good way to keep track minion side of the jobs the minion has +# executed. By default this feature is disabled, to enable set cache_jobs +# to True +#cache_jobs: False + # When waiting for a master to accept the minion's public key, salt will -# contiuously attempt to reconnect until successful. This is the time, in +# continuously attempt to reconnect until successful. This is the time, in # seconds, between those reconnection attempts. -# acceptance_wait_time = 10 +#acceptance_wait_time = 10 diff --git a/debian/changelog b/debian/changelog index 52368b3f170..719d4de5c14 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -salt (0.9.5+git20111227.g8182e48-1) unstable; urgency=low +salt (0.9.5-1) unstable; urgency=low * First package release. (Closes: #643789) diff --git a/debian/control b/debian/control index b353685884b..6ba30ed2e24 100644 --- a/debian/control +++ b/debian/control @@ -7,14 +7,11 @@ Build-Depends: debhelper (>= 7.0.50~), cython, python-yaml, python-setuptools, - python-yaml, python-crypto, python-m2crypto, python-zmq (>= 2.1.9), - libzmq1 (>= 2.1.9), libzmq-dev (>= 2.1.9), - python (>= 2.6), - python-dev (>= 2.6), + python-all-dev, python-jinja2 Standards-Version: 3.9.2 Homepage: http://saltstack.org @@ -24,8 +21,20 @@ Homepage: http://saltstack.org Package: salt-common Architecture: any -Depends: ${python:Depends}, - ${misc:Depends} +Depends: ${python:Depends}, + ${misc:Depends}, + ${shlibs:Depends}, + python-support, + cython, + python-setuptools, + python-yaml, + python-crypto, + python-m2crypto, + python-zmq (>= 2.1.9), + libzmq-dev (>= 2.1.9), + python, + python-dev, + python-jinja2 Description: Shared libraries that salt requires for all packages This package is a powerful remote execution manager that can be used to administer servers in a fast and efficient way. @@ -41,15 +50,14 @@ Description: Shared libraries that salt requires for all packages Between the remote execution system, and state management Salt addresses the backbone of cloud and data center management. . - This particular package provides shared libraries that salt-master, salt-minion, - and salt-syndic require to function. - + This particular package provides shared libraries that salt-master, + salt-minion, and salt-syndic require to function. Package: salt-master Architecture: all -Depends: ${python:Depends}, - ${misc:Depends}, - salt-common +Depends: ${misc:Depends}, + python, + salt-common (>= ${source:Version}) Description: This package provides a remote manager to administer servers via salt This package is a powerful remote execution manager that can be used to administer servers in a fast and efficient way. @@ -70,9 +78,9 @@ Description: This package provides a remote manager to administer servers via sa Package: salt-minion Architecture: all -Depends: ${python:Depends}, - ${misc:Depends}, - salt-common +Depends: ${misc:Depends}, + python, + salt-common (>= ${source:Version}) Description: This package represents the client package for salt This package is a powerful remote execution manager that can be used to administer servers in a fast and efficient way. @@ -93,10 +101,10 @@ Description: This package represents the client package for salt Package: salt-syndic Architecture: all -Depends: ${python:Depends}, - ${misc:Depends}, - salt-master -Description: salt-syndic represents the master-of-masters for salt +Depends: ${misc:Depends}, + python, + salt-master (>= ${source:Version}) +Description: This package represents the master-of-masters for salt This package is a powerful remote execution manager that can be used to administer servers in a fast and efficient way. . @@ -111,5 +119,5 @@ Description: salt-syndic represents the master-of-masters for salt Between the remote execution system, and state management Salt addresses the backbone of cloud and data center management. . - This particular package provides the master of masters for salt-- it enables the management - of multiple masters at a time. + This particular package provides the master of masters for salt-- it enables + the management of multiple masters at a time. diff --git a/debian/copyright b/debian/copyright index 9fc9484c313..b548adad163 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,10 +1,10 @@ Format: http://dep.debian.net/deps/dep5 Upstream-Name: salt -Upstream-Contact: Aaron Toponce -Source: http://github.com/thatch45/salt/ +Upstream-Contact: salt-users@googlegroups.com +Source: https://github.com/downloads/saltstack/salt/salt-0.9.5.tar.gz Files: * -Copyright: 2011 Thomas S Hatch +Copyright: 2012 Thomas S Hatch License: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/debian/lintian-overrides b/debian/lintian-overrides new file mode 100644 index 00000000000..caf9e9d7950 --- /dev/null +++ b/debian/lintian-overrides @@ -0,0 +1,3 @@ +salt-common: manpage-has-errors-from-man usr/share/man/man7/salt.7.gz +# The man page renders correctly, no need for lintian to get upset about +# it. diff --git a/debian/rules b/debian/rules index a140040585e..04dfdf8f288 100755 --- a/debian/rules +++ b/debian/rules @@ -1,8 +1,7 @@ #!/usr/bin/make -f - +#export DH_VERBOSE=1 %: - dh $@ - + dh $@ --buildsystem=python_distutils #override_dh_installinit: # dh_installinit --no-start --name="salt-master" # dh_installinit --no-start --name="salt-minion" diff --git a/debian/salt-common.install b/debian/salt-common.install index 8ef4a2454ea..3b0e763edc6 100644 --- a/debian/salt-common.install +++ b/debian/salt-common.install @@ -1,9 +1,25 @@ -usr/share/man/man1/salt-minion.1 -usr/share/man/man1/salt-call.1 -usr/share/man/man1/salt-key.1 -usr/share/man/man1/salt-master.1 -usr/share/man/man1/salt-syndic.1 -usr/share/man/man1/salt-cp.1 -usr/share/man/man1/salt.1 -conf/minion /etc/salt/minion -salt/* /usr/share/salt/ +salt/exceptions.py /usr/share/salt +salt/loader.py /usr/share/salt +salt/master.py /usr/share/salt +salt/client.py /usr/share/salt +salt/runner.py /usr/share/salt +salt/output.py /usr/share/salt +salt/minion.py /usr/share/salt +salt/version.py /usr/share/salt +salt/config.py /usr/share/salt +salt/state.py /usr/share/salt +salt/log.py /usr/share/salt +salt/__init__.py /usr/share/salt +salt/payload.py /usr/share/salt +salt/crypt.py /usr/share/salt +salt/runners /usr/share/salt/ +salt/renderers /usr/share/salt/ +salt/returners /usr/share/salt/ +salt/ext /usr/share/salt/ +salt/msgpack /usr/share/salt/ +salt/grains /usr/share/salt/ +salt/cli /usr/share/salt/ +salt/states /usr/share/salt/ +salt/utils /usr/share/salt/ +usr/lib/python2*/dist-packages/salt/msgpack +debian/lintian-overrides /usr/share/lintian/overrides/salt-common diff --git a/debian/salt-common.manpages b/debian/salt-common.manpages new file mode 100644 index 00000000000..ce2ea1742d6 --- /dev/null +++ b/debian/salt-common.manpages @@ -0,0 +1 @@ +doc/man/salt.7 diff --git a/debian/salt-master.install b/debian/salt-master.install index 53d4c1340db..80e93e1cacb 100644 --- a/debian/salt-master.install +++ b/debian/salt-master.install @@ -1 +1,6 @@ -conf/master /etc/salt/master +conf/master.template /etc/salt/master +scripts/salt-key /usr/share/salt +scripts/salt /usr/share/salt +scripts/salt-run /usr/share/salt +scripts/salt-cp /usr/share/salt +scripts/salt-master /usr/share/salt diff --git a/debian/links b/debian/salt-master.links similarity index 59% rename from debian/links rename to debian/salt-master.links index e325b02fa1d..0b3afffea41 100644 --- a/debian/links +++ b/debian/salt-master.links @@ -1,8 +1,5 @@ usr/share/salt/salt /usr/bin/salt usr/share/salt/salt-master /usr/bin/salt-master -usr/share/salt/salt-syndic /usr/bin/salt-syndic usr/share/salt/salt-cp /usr/bin/salt-cp usr/share/salt/salt-key /usr/bin/salt-key usr/share/salt/salt-run /usr/bin/salt-run -usr/share/salt/salt-minion /usr/bin/salt-minion -usr/share/salt/salt-call /usr/bin/salt-call diff --git a/debian/salt-master.manpages b/debian/salt-master.manpages index 074f304fb2c..52beb2836be 100644 --- a/debian/salt-master.manpages +++ b/debian/salt-master.manpages @@ -1,6 +1,5 @@ -doc/man/salt.7 doc/man/salt.1 -doc/man/salt-master.1 -doc/man/salt-key.1 doc/man/salt-cp.1 +doc/man/salt-key.1 +doc/man/salt-master.1 doc/man/salt-run.1 diff --git a/debian/salt-minion.install b/debian/salt-minion.install index 7ed61cee7ef..03f11693026 100644 --- a/debian/salt-minion.install +++ b/debian/salt-minion.install @@ -1,4 +1,4 @@ -scripts/salt-minion /usr/share/salt/salt-minion -scripts/salt-call /usr/share/salt/salt-call -modules/* /usr/share/salt/modules/ -conf/minion /etc/salt/minion +scripts/salt-minion /usr/share/salt +scripts/salt-call /usr/share/salt +salt/modules /usr/share/salt/modules +conf/minion.template /etc/salt/minion diff --git a/debian/salt-minion.links b/debian/salt-minion.links new file mode 100644 index 00000000000..599cef31fd4 --- /dev/null +++ b/debian/salt-minion.links @@ -0,0 +1,2 @@ +usr/share/salt/salt-minion /usr/bin/salt-minion +usr/share/salt/salt-call /usr/bin/salt-call diff --git a/debian/salt-syndic.install b/debian/salt-syndic.install index e69de29bb2d..e4bc3242811 100644 --- a/debian/salt-syndic.install +++ b/debian/salt-syndic.install @@ -0,0 +1 @@ +scripts/salt-syndic /usr/share/salt diff --git a/debian/salt-syndic.links b/debian/salt-syndic.links new file mode 100644 index 00000000000..3edb1ec97d7 --- /dev/null +++ b/debian/salt-syndic.links @@ -0,0 +1 @@ +usr/share/salt/salt-syndic /usr/bin/salt-syndic diff --git a/debian/salt.manpages b/debian/salt.manpages deleted file mode 100644 index 43d8412c8da..00000000000 --- a/debian/salt.manpages +++ /dev/null @@ -1,9 +0,0 @@ -doc/man/salt.1 -doc/man/salt.7 -doc/man/salt-call.1 -doc/man/salt-cp.1 -doc/man/salt-key.1 -doc/man/salt-master.1 -doc/man/salt-minion.1 -doc/man/salt-run.1 -doc/man/salt-syndic.1 diff --git a/doc/man/salt-cp.1 b/doc/man/salt-cp.1 index e0196f6f49d..71d01834d2c 100644 --- a/doc/man/salt-cp.1 +++ b/doc/man/salt-cp.1 @@ -61,7 +61,7 @@ The timeout in seconds to wait for replies from the salt minions. .INDENT 0.0 .TP .B \-E, \-\-pcre -The target expresion will be interpereted as a pcre regular expression +The target expression will be interpereted as a pcre regular expression rather than a shell glob. .UNINDENT .INDENT 0.0 @@ -74,8 +74,8 @@ example: server1.foo.bar,server2.foo.bar,example7.quo.qux .TP .B \-G, \-\-grain The target expression matches values returned by the salt grains system on -the minions. The target expresion is in the format of \(aq:\(aq; example: \(aqos:Arch.*\(aq +the minions. The target expression is in the format of \(aq:\(aq; example: \(aqos:Arch.*\(aq .UNINDENT .INDENT 0.0 .TP diff --git a/doc/man/salt.7 b/doc/man/salt.7 index 7545aabab45..0f9d1c7253e 100644 --- a/doc/man/salt.7 +++ b/doc/man/salt.7 @@ -7827,7 +7827,7 @@ extra information needs to be sent with the publications, the order_masters option makes sure that the extra data is sent out. .SS Running the Syndic .sp -The Syndic is a seperate daemon that needs to be started on the master that is +The Syndic is a separate daemon that needs to be started on the master that is controlled by a higher master. Starting the Syndic daemon is the same as starting the other Salt daemons. .sp @@ -8149,7 +8149,7 @@ def get_file(path, dest, env=\(aqbase\(aq): # syndic servers(s) below it set the "order_masters" setting to True, if this # is a master that will be running a syndic daemon for passthrough the # "syndic_master" setting needs to be set to the location of the master server -# to recieve commands from +# to receive commands from # # Set the order_masters setting to True if this master will command lower # masters\(aq syndic interfaces @@ -8608,7 +8608,7 @@ master. Using the syndic is simple, if this is a master that will have syndic servers(s) below it set the "order_masters" setting to True, if this is a master that will be running a syndic daemon for passthrough the "syndic_master" setting needs to be set to the location of the master server -to recieve commands from +to receive commands from .SS \fBorder_masters\fP .sp Default: \fBFalse\fP @@ -9443,7 +9443,7 @@ The timeout in seconds to wait for replies from the salt minions. .INDENT 0.0 .TP .B \-E, \-\-pcre -The target expresion will be interpereted as a pcre regular expression +The target expression will be interpereted as a pcre regular expression rather than a shell glob. .UNINDENT .INDENT 0.0 @@ -9456,8 +9456,8 @@ example: server1.foo.bar,server2.foo.bar,example7.quo.qux .TP .B \-G, \-\-grain The target expression matches values returned by the salt grains system on -the minions. The target expresion is in the format of \(aq:\(aq; example: \(aqos:Arch.*\(aq +the minions. The target expression is in the format of \(aq:\(aq; example: \(aqos:Arch.*\(aq .UNINDENT .INDENT 0.0 .TP @@ -11192,5 +11192,4 @@ Thomas S. Hatch and many others, please see the Authors file .SH COPYRIGHT 2011, Thomas S. Hatch .\" Generated by docutils manpage writer. -.\" . diff --git a/doc/ref/cli/salt-cp.rst b/doc/ref/cli/salt-cp.rst index 977aec2dd48..de338d9a35e 100644 --- a/doc/ref/cli/salt-cp.rst +++ b/doc/ref/cli/salt-cp.rst @@ -36,7 +36,7 @@ Options .. option:: -E, --pcre - The target expresion will be interpereted as a pcre regular expression + The target expression will be interpereted as a pcre regular expression rather than a shell glob. .. option:: -L, --list @@ -47,8 +47,8 @@ Options .. option:: -G, --grain The target expression matches values returned by the salt grains system on - the minions. The target expresion is in the format of ':'; example: 'os:Arch.*' + the minions. The target expression is in the format of ':'; example: 'os:Arch.*' .. option:: -Q, --query diff --git a/doc/ref/configuration/minion.rst b/doc/ref/configuration/minion.rst index cfb79de8475..8fd86a1160c 100644 --- a/doc/ref/configuration/minion.rst +++ b/doc/ref/configuration/minion.rst @@ -99,8 +99,27 @@ The location for minion cache data. cachedir: /var/cache/salt +.. conf_minion:: cache_jobs + +``cache_jobs`` +-------------- + +Default: ``False`` + +The minion can locally cache the return data from jobs sent to it, this +can be a good way to keep track minion side of the jobs the minion has +executed. By default this feature is disabled, to enable set cache_jobs +to True + +.. code-block:: yaml + + cache_jobs: False + .. conf_minion:: acceptance_wait_time +``acceptance_wait_time`` +------------------------ + Default: ``10`` The number of seconds to wait until attempting to re-authenticate with the diff --git a/doc/topics/index.rst b/doc/topics/index.rst index 756b16c7cea..7340c3fb890 100644 --- a/doc/topics/index.rst +++ b/doc/topics/index.rst @@ -45,9 +45,10 @@ contains a viable, and transparent, AMQ broker inside the daemon. Salt uses public keys for authentication with the master daemon, then uses faster AES encryption for payload communication, this means that authentication and encryption are also built into Salt. Salt takes advantage of communication via -Python pickles, enabling fast and light network traffic. +`msgpack`_, enabling fast and light network traffic. .. _`ZeroMQ`: http://www.zeromq.org/ +.. _`msgpack`: http://msgpack.org/ Python client interface ======================= diff --git a/salt/__init__.py b/salt/__init__.py old mode 100755 new mode 100644 diff --git a/salt/config.py b/salt/config.py index 5863c444ca9..641605980fa 100644 --- a/salt/config.py +++ b/salt/config.py @@ -80,6 +80,7 @@ def minion_config(path): 'pki_dir': '/etc/salt/pki', 'id': socket.getfqdn(), 'cachedir': '/var/cache/salt', + 'cache_jobs': False, 'conf_file': path, 'renderer': 'yaml_jinja', 'failhard': False, diff --git a/salt/log.py b/salt/log.py old mode 100755 new mode 100644 diff --git a/salt/minion.py b/salt/minion.py index 8f6d3583b26..dfe45193214 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -226,14 +226,19 @@ class Minion(object): ret['jid'] = data['jid'] ret['fun'] = data['fun'] + self._return_pub(ret) if data['ret']: - ret['id'] = self.opts['id'] - try: - self.returners[data['ret']](ret) - except Exception as exc: - log.error('The return failed for job %s %s', data['jid'], exc) - else: - self._return_pub(ret) + for returner in set(data['ret'].split(',')): + ret['id'] = self.opts['id'] + try: + self.returners[returner](ret) + except Exception as exc: + log.error( + 'The return failed for job {0} {1}'.format( + data['jid'], + exc + ) + ) def _thread_multi_return(self, data): ''' @@ -259,23 +264,32 @@ class Minion(object): = self.functions[data['fun'][ind]](*data['arg'][ind]) except Exception as exc: trb = traceback.format_exc() - log.warning('The minion function caused an exception: %s', exc) + log.warning( + 'The minion function caused an exception: {0}'.format( + exc + ) + ) ret['return'][data['fun'][ind]] = trb ret['jid'] = data['jid'] + self._return_pub(ret) if data['ret']: - ret['id'] = self.opts['id'] - try: - self.returners[data['ret']](ret) - except Exception as exc: - log.error('The return failed for job %s %s', data['jid'], exc) - else: - self._return_pub(ret) + for returner in set(data['ret'].split(',')): + ret['id'] = self.opts['id'] + try: + self.returners[returner](ret) + except Exception as exc: + log.error( + 'The return failed for job {0} {1}'.format( + data['jid'], + exc + ) + ) def _return_pub(self, ret, ret_cmd='_return'): ''' Return the data from the executed command to the master server ''' - log.info('Returning information for job: %(jid)s', ret) + log.info('Returning information for job: {0}'.format(ret['jid'])) context = zmq.Context() socket = context.socket(zmq.REQ) socket.connect(self.opts['master_uri']) @@ -301,8 +315,21 @@ class Minion(object): except KeyError: pass payload['load'] = self.crypticle.dumps(load) - socket.send(self.serial.dumps(payload)) - return socket.recv() + data = self.serial.dumps(payload) + socket.send(data) + ret_val = socket.recv() + if self.opts['cache_jobs']: + # Local job cache has been enabled + fn_ = os.path.join( + self.opts['cachedir'], + 'minion_jobs', + load['jid'], + 'return.p') + jdir = os.path.dirname(fn_) + if not os.path.isdir(jdir): + os.makedirs(jdir) + open(fn_, 'w+').write(self.serial.dumps(ret)) + return ret_val def authenticate(self): ''' diff --git a/salt/modules/apache.py b/salt/modules/apache.py old mode 100755 new mode 100644 index a952e90d725..84464bf303b --- a/salt/modules/apache.py +++ b/salt/modules/apache.py @@ -3,12 +3,23 @@ Support for Apache ''' import re +import salt.utils __outputter__ = { 'signal': 'txt', } +def __virtual__(): + ''' + Only load the module if apache is installed + ''' + cmd = __detect_os() + if salt.utils.which(cmd): + return 'apache' + return False + + def __detect_os(): ''' Apache commands and paths differ depending on packaging diff --git a/salt/modules/cmd.py b/salt/modules/cmd.py index 4586386d50f..c49cea56468 100644 --- a/salt/modules/cmd.py +++ b/salt/modules/cmd.py @@ -123,7 +123,7 @@ def retcode(cmd, cwd=DEFAULT_CWD): salt '*' cmd.retcode "file /bin/bash" ''' log.info('Executing command {0} in directory {1}'.format(cmd, cwd)) - return subprocess.call(cmd, shell=True, cwd=cwd) + return _run(cmd, cwd=cwd)['retcode'] def has_exec(cmd): diff --git a/salt/modules/mysql.py b/salt/modules/mysql.py old mode 100755 new mode 100644 diff --git a/salt/modules/nginx.py b/salt/modules/nginx.py old mode 100755 new mode 100644 index 0769332e7d0..fd78ab74c66 --- a/salt/modules/nginx.py +++ b/salt/modules/nginx.py @@ -2,10 +2,24 @@ Support for nginx ''' +import salt.utils + __outputter__ = { 'signal': 'txt', } +def __virtual__(): + ''' + Only load the module if nginx is installed + ''' + cmd = __detect_os() + if salt.utils.which(cmd): + return 'nginx' + return False + +def __detect_os(): + return 'nginx' + def version(): ''' Return server version from nginx -v @@ -14,7 +28,7 @@ def version(): salt '*' nginx.version ''' - cmd = 'nginx -v' + cmd = __detect_os() + ' -v' out = __salt__['cmd.run'](cmd).split('\n') ret = out[0].split(': ') return ret[2] @@ -37,7 +51,7 @@ def signal(signal=None): arguments = ' -s {0}'.format(signal) else: arguments = ' {0}'.format(signal) - cmd = 'nginx' + arguments + cmd = __detect_os() + arguments out = __salt__['cmd.run_all'](cmd) # A non-zero return code means fail diff --git a/salt/modules/solr.py b/salt/modules/solr.py index 7d9af8ba28b..4eff2e24a73 100644 --- a/salt/modules/solr.py +++ b/salt/modules/solr.py @@ -59,11 +59,15 @@ verbose : True Get verbose output ''' +# Import Python Libs import urllib2 import json import socket import os +# Import Salt libs +import salt.utils + #sane defaults __opts__ = {'solr.cores': [], 'solr.host': 'localhost', @@ -86,16 +90,11 @@ def __virtual__(): Solr needs to be installed to use this. Return: str/bool:: - - TODO:// currently __salt__ is not available to call in this method because - all the salt modules have not been loaded yet. Use a grains module? ''' - return 'solr' - names = ['solr', 'apache-solr'] - for name in names: - if __salt__['pkg.version'](name): - return 'solr' - + if salt.utils.which('solr'): + return 'solr' + if salt.utils.which('apache-solr'): + return 'solr' return False def _get_none_or_value(value): diff --git a/salt/returners/cassandra_return.py b/salt/returners/cassandra_return.py index 588f3e6e303..971640fe40c 100644 --- a/salt/returners/cassandra_return.py +++ b/salt/returners/cassandra_return.py @@ -43,5 +43,5 @@ def returner(ret): else: columns['return'] = str(ret['return']) - log.debug(back) + log.debug(columns) cf.insert(ret['jid'], columns) diff --git a/salt/state.py b/salt/state.py index c3a2f85e6f6..f588e96df5c 100644 --- a/salt/state.py +++ b/salt/state.py @@ -989,6 +989,14 @@ class HighState(object): high, errors = self.render_highstate(matches) if errors: return errors + if not high: + return {'no.states': { + 'result': False, + 'comment': 'No states found for this minion', + 'name': 'No States', + 'changes': {} + } + } return self.state.call_high(high) def compile_highstate(self): diff --git a/salt/states/file.py b/salt/states/file.py index 73d2efb8e7d..b7c92ef3636 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -69,6 +69,7 @@ import os import shutil import difflib import hashlib +import imp import logging import tempfile import traceback @@ -223,6 +224,43 @@ def _jinja(sfn, name, source, user, group, mode, env, context=None): 'data': trb} +def _py(sfn, name, source, user, group, mode, env, context=None): + ''' + Render a template from a python source file + + Returns:: + + {'result': bool, + 'data': } + ''' + if not os.path.isfile(sfn): + return {} + + mod = imp.load_source( + os.path.basename(sfn).split('.')[0], + sfn + ) + mod.salt = __salt__ + mod.grains = __grains__ + mod.name = name + mod.source = source + mod.user = user + mod.group = group + mod.mode = mode + mod.env = env + mod.context = context + + try: + tgt = tempfile.mkstemp()[1] + open(tgt, 'w+').write(mod.run()) + return {'result': True, + 'data': tgt} + except: + trb = traceback.format_exc() + return {'result': False, + 'data': trb} + + def symlink(name, target, force=False, makedirs=False): ''' Create a symlink @@ -345,11 +383,21 @@ def managed(name, The location of the file to manage source - The source file, this file is located on the salt master file server - and is specified with the salt:// protocol. If the file is located on + The source file to download to the minion, this source file can be + hosted on either the salt master server, or on an http or ftp server. + For files hosted on the salt file server, if the file is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs. If source is left blank or None, the file - will be created as an empty file and the content will not be managed + will be created as an empty file and the content will not be managed + + If the file is hosted on a http or ftp server then the source_hash + argument is also required + + source_hash: + This can be either a file which contains a source hash string for + the source, or a source hash string. The source hash string is the + hash algorithm followed by the hash of the file: + md5=e138491e9d5b97023cea823fe17bac22 user The user to own the file, this defaults to the user salt is running as @@ -432,24 +480,40 @@ def managed(name, ret['comment'] = 'Source file {0} not found'.format(source) return ret elif source_hash: - hash_fn = __salt__['cp.cache_file'](source_hash) - if not hash_fn: - ret['result'] = False - ret['comment'] = 'Source hash file {0} not found'.format( - source_hash - ) - return ret - comps = open(hash_fn, 'r').read().split('=') - if len(comps) < 2: - ret['result'] = False - ret['comment'] = ('Source hash file {0} contains an ' - ' invalid hash format, it must be in ' - ' the format =').format( - source_hash - ) - return ret - source_sum['hsum'] = comps[1] - source_sum['hash_type'] = comps[0] + protos = ['salt', 'http', 'ftp'] + if urlparse.urlparse(source_hash).scheme in protos: + # The sourc_hash is a file on a server + hash_fn = __salt__['cp.cache_file'](source_hash) + if not hash_fn: + ret['result'] = False + ret['comment'] = 'Source hash file {0} not found'.format( + source_hash + ) + return ret + comps = open(hash_fn, 'r').read().split('=') + if len(comps) < 2: + ret['result'] = False + ret['comment'] = ('Source hash file {0} contains an ' + ' invalid hash format, it must be in ' + ' the format =').format( + source_hash + ) + return ret + source_sum['hsum'] = comps[1].strip() + source_sum['hash_type'] = comps[0].strip() + else: + # The source_hash is a hash string + comps = source_hash.split('=') + if len(comps) < 2: + ret['result'] = False + ret['comment'] = ('Source hash file {0} contains an ' + ' invalid hash format, it must be in ' + ' the format =').format( + source_hash + ) + return ret + source_sum['hsum'] = comps[1].strip() + source_sum['hash_type'] = comps[0].strip() else: ret['result'] = False ret['comment'] = ('Unable to determine upstream hash of' diff --git a/salt/states/mysql_database.py b/salt/states/mysql_database.py old mode 100755 new mode 100644 diff --git a/salt/states/mysql_user.py b/salt/states/mysql_user.py old mode 100755 new mode 100644 diff --git a/salt/utils/find.py b/salt/utils/find.py old mode 100755 new mode 100644 diff --git a/scripts/salt b/scripts/salt index 2c245c83f4c..d3878288649 100755 --- a/scripts/salt +++ b/scripts/salt @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Publish commands to the salt system from the command line on the master. ''' diff --git a/scripts/salt-call b/scripts/salt-call index b2f3585b5bd..0cee11d2f68 100755 --- a/scripts/salt-call +++ b/scripts/salt-call @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Directly call a salt command in the modules, does not require a running salt minion to run. diff --git a/scripts/salt-cp b/scripts/salt-cp index b38151d953c..e3a1fa426e7 100755 --- a/scripts/salt-cp +++ b/scripts/salt-cp @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Publish commands to the salt system from the command line on the master. ''' diff --git a/scripts/salt-key b/scripts/salt-key index 0a0fec5112d..e8a91d571ae 100755 --- a/scripts/salt-key +++ b/scripts/salt-key @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Manage the authentication keys with salt-key ''' diff --git a/scripts/salt-master b/scripts/salt-master index e409281e5ce..96e586685f2 100755 --- a/scripts/salt-master +++ b/scripts/salt-master @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Start the salt-master ''' diff --git a/scripts/salt-minion b/scripts/salt-minion index f6745445582..d9e0782559f 100755 --- a/scripts/salt-minion +++ b/scripts/salt-minion @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python ''' This script is used to kick off a salt minion daemon ''' diff --git a/scripts/salt-run b/scripts/salt-run index e5e996c96f3..0c933690065 100755 --- a/scripts/salt-run +++ b/scripts/salt-run @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python ''' Execute a salt convenience routine ''' diff --git a/scripts/salt-syndic b/scripts/salt-syndic index b122993bfac..5a46a52c450 100755 --- a/scripts/salt-syndic +++ b/scripts/salt-syndic @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python ''' This script is used to kick off a salt syndic daemon '''