Skip to content

Commit

Permalink
Merge branch '2014.7' into '2015.2'
Browse files Browse the repository at this point in the history
Conflicts:
	salt/modules/localemod.py
  • Loading branch information
rallytime committed Jan 27, 2015
2 parents d54f3b5 + cc1e81a commit dc23823
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 53 deletions.
8 changes: 4 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ persistent=yes

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=salttesting.pylintplugins.pep8,
salttesting.pylintplugins.pep263,
salttesting.pylintplugins.strings,
salttesting.pylintplugins.fileperms
load-plugins=saltpylint.pep8,
saltpylint.pep263,
saltpylint.strings,
saltpylint.fileperms


# Fileperms Lint Plugin Settings
Expand Down
8 changes: 4 additions & 4 deletions .testing.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ init-hook="
# Pickle collected data for later comparisons.
persistent=no

load-plugins=salttesting.pylintplugins.pep8,
salttesting.pylintplugins.pep263,
salttesting.pylintplugins.strings,
salttesting.pylintplugins.fileperms
load-plugins=saltpylint.pep8,
saltpylint.pep263,
saltpylint.strings,
saltpylint.fileperms

# Fileperms Lint Plugin Settings
fileperms-default=0644
Expand Down
4 changes: 2 additions & 2 deletions doc/topics/installation/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ minion exe>` should match the contents of the corresponding md5 file.
* Salt-Minion-2014.7.0-1-win32-Setup.exe | md5
* Salt-Minion-2014.7.0-AMD64-Setup.exe | md5
.. note::
The 2014.7.0 exe's have been removed because of a regression. Please use the 2014.7.1 release instead.
The 2014.7.0 installers have been removed because of a regression. Please use the 2014.7.1 release instead.

* 2014.1.13
* `Salt-Minion-2014.1.13-x86-Setup.exe <http://docs.saltstack.com/downloads/Salt-Minion-2014.1.13-x86-Setup.exe>`__ | `md5 <http://docs.saltstack.com/downloads/Salt-Minion-2014.1.13-x86-Setup.exe.md5>`__
Expand Down Expand Up @@ -380,4 +380,4 @@ this, salt-minion can't report some installed packages.
.. _pywin32: http://sourceforge.net/projects/pywin32/files/pywin32
.. _Cython: http://www.lfd.uci.edu/~gohlke/pythonlibs/#cython
.. _jinja2: http://www.lfd.uci.edu/~gohlke/pythonlibs/#jinja2
.. _msgpack: http://www.lfd.uci.edu/~gohlke/pythonlibs/#msgpack
.. _msgpack: http://www.lfd.uci.edu/~gohlke/pythonlibs/#msgpack
67 changes: 43 additions & 24 deletions salt/modules/localemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# Import python libs
import logging
import re
import os

# Import salt libs
import salt.utils
import salt.ext.six as six
import salt.utils.decorators as decorators

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -173,41 +175,62 @@ def avail(locale):
salt '*' locale.avail 'en_US.UTF-8'
'''
normalized_locale = _normalize_locale(locale)
try:
normalized_locale = _normalize_locale(locale)
except IndexError:
log.error('Unable to validate locale "{0}"'.format(locale))
return False
avail_locales = __salt__['locale.list_avail']()
locale_exists = next((True for x in avail_locales
if _normalize_locale(x.strip()) == normalized_locale), False)
return locale_exists


def gen_locale(locale):
@decorators.which('locale-gen')
def gen_locale(locale, charmap=None):
'''
Generate a locale.
.. versionadded:: 2014.7.0
:param locale: Any locale listed in /usr/share/i18n/locales or
/usr/share/i18n/SUPPORTED for debian and gentoo based distros
:param charmap: debian and gentoo based systems require the charmap to be
specified independently of the locale.
CLI Example:
.. code-block:: bash
salt '*' locale.gen_locale 'en_US.UTF-8'
salt '*' locale.gen_locale en_US.UTF-8
salt '*' locale.gen_locale en_US.UTF-8 UTF-8 # debian and gentoo only
'''
# validate the supplied locale
valid = __salt__['file.replace'](
'/usr/share/i18n/SUPPORTED',
'^{0}$'.format(locale),
'^{0}$'.format(locale),
search_only=True
)
on_debian = __grains__.get('os') == 'Debian'
on_gentoo = __grains__.get('os_family') == 'Gentoo'

if on_debian or on_gentoo:
if not charmap:
log.error('On debian and gentoo systems you must provide a charmap')
return False

search = '/usr/share/i18n/SUPPORTED'
locale_format = '{0} {1}'.format(locale, charmap)
valid = __salt__['file.search'](search, '^{0}$'.format(locale_format))
else:
search = '/usr/share/i18n/locales'
locale_format = locale
valid = locale_format in os.listdir(search)

if not valid:
log.error('The provided locale "{0}" is invalid'.format(locale))
log.error('The provided locale "{0}" is not found in {1}'.format(locale, search))
return False

if __grains__.get('os') == 'Debian' or __grains__.get('os_family') == 'Gentoo':
if on_debian or on_gentoo:
__salt__['file.replace'](
'/etc/locale.gen',
'# {0} '.format(locale),
'{0} '.format(locale),
r'^#\s*{0}$'.format(locale_format),
'{0}'.format(locale_format),
append_if_not_found=True
)
elif __grains__.get('os') == 'Ubuntu':
Expand All @@ -222,13 +245,9 @@ def gen_locale(locale):
'locale-gen'
)

if __grains__.get('os_family') == 'Gentoo':
return __salt__['cmd.retcode'](
'locale-gen --generate "{0}"'.format(locale),
python_shell=False
)
else:
return __salt__['cmd.retcode'](
'locale-gen "{0}"'.format(locale),
python_shell=False
)
cmd = ['locale-gen']
if on_gentoo:
cmd.append('--generate')
cmd.append(locale_format)

return __salt__['cmd.retcode'](cmd, python_shell=False)
25 changes: 14 additions & 11 deletions salt/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,7 @@ def nproc():
salt '*' status.nproc
'''
data = __salt__['cmd.run']('nproc')
try:
ret = int(data.strip())
except Exception:
return 0
return ret
return __grains__.get('num_cpus', 0)


def netstats():
Expand Down Expand Up @@ -548,12 +543,20 @@ def version():
salt '*' status.version
'''
procf = '/proc/version'
if not os.path.isfile(procf):
return {}
ret = salt.utils.fopen(procf, 'r').read().strip()
def linux_version():
procf = '/proc/version'
if not os.path.isfile(procf):
return {}
return salt.utils.fopen(procf, 'r').read().strip()

return ret
# dict that return a function that does the right thing per platform
get_version = {
'Linux': linux_version,
'FreeBSD': lambda: __salt__['cmd.run']('sysctl -n kern.version'),
}

errmsg = 'This method is unsupported on the current operating system!'
return get_version.get(__grains__['kernel'], lambda: errmsg)()


def master(master=None, connected=True):
Expand Down
10 changes: 6 additions & 4 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2053,11 +2053,13 @@ def _cleanup_accumulator_data():
)
try:
os.remove(accum_data_path)
log.debug('Deleted accumulator data file %s',
accum_data_path)
log.debug('Deleted accumulator data file {0}'.format(
accum_data_path)
)
except OSError:
log.debug('File %s does not exist, no need to cleanup.',
accum_data_path)
log.debug('File {0} does not exist, no need to cleanup.'.format(
accum_data_path)
)
_cleanup_accumulator_data()

return ret
Expand Down
4 changes: 2 additions & 2 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def exists(name):
if not name:
return _error(ret, 'Must provide name to file.exists')
if not os.path.exists(name):
return _error(ret, ('Specified path {0} does not exist').format(name))
return _error(ret, 'Specified path {0} does not exist'.format(name))

ret['comment'] = 'Path {0} exists'.format(name)
return ret
Expand All @@ -1016,7 +1016,7 @@ def missing(name):
if not name:
return _error(ret, 'Must provide name to file.missing')
if os.path.exists(name):
return _error(ret, ('Specified path {0} exists').format(name))
return _error(ret, 'Specified path {0} exists'.format(name))

ret['comment'] = 'Path {0} is missing'.format(name)
return ret
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rackspace-test:
provider: rackspace-config
size: 2 GB Performance
image: Ubuntu 14.04 LTS (Trusty Tahr)
image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
3 changes: 2 additions & 1 deletion tests/unit/states/file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

filestate.__env__ = 'base'
filestate.__salt__ = {'file.manage_file': False}
filestate.__opts__ = {'test': False}
filestate.__opts__ = {'test': False, 'cachedir': ''}
filestate.__instance_id__ = ''


@skipIf(NO_MOCK, NO_MOCK_REASON)
Expand Down

0 comments on commit dc23823

Please sign in to comment.