Skip to content

Commit

Permalink
Merge pull request #30308 from rallytime/bp-30257
Browse files Browse the repository at this point in the history
Back-port #30257 to 2015.8
  • Loading branch information
Mike Place committed Jan 13, 2016
2 parents afa61c0 + 0b0d737 commit 10b5728
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion salt/modules/npm.py
Expand Up @@ -65,7 +65,8 @@ def install(pkg=None,
dir=None,
runas=None,
registry=None,
env=None):
env=None,
dry_run=False):
'''
Install an NPM package.
Expand Down Expand Up @@ -101,6 +102,11 @@ def install(pkg=None,
.. versionadded:: 2014.7.0
dry_run
Whether or not to run NPM install with --dry-run flag.
.. versionadded::2015.8.4
CLI Example:
.. code-block:: bash
Expand Down Expand Up @@ -129,6 +135,9 @@ def install(pkg=None,
if registry:
cmd.append(' --registry="{0}"'.format(registry))

if dry_run:
cmd.append('--dry-run')

if pkg:
cmd.append(pkg)
elif pkgs:
Expand Down
13 changes: 13 additions & 0 deletions salt/states/npm.py
Expand Up @@ -274,6 +274,18 @@ def bootstrap(name,
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}

if __opts__['test']:
try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None, dry_run=True)
except (CommandNotFoundError, CommandExecutionError) as err:
ret['result'] = False
ret['comment'] = 'Error Bootstrapping {0!r}: {1}'.format(name, err)
return ret
ret['result'] = None
ret['changes'] = {'old': [], 'new': call}
ret['comment'] = '{0} is set to be bootstrapped'.format(name)
return ret

try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None)
except (CommandNotFoundError, CommandExecutionError) as err:
Expand All @@ -289,6 +301,7 @@ def bootstrap(name,
# npm.install will return a string if it can't parse a JSON result
if isinstance(call, str):
ret['result'] = False
ret['changes'] = call
ret['comment'] = 'Could not bootstrap directory'
else:
ret['result'] = True
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/states/npm_test.py
Expand Up @@ -22,7 +22,7 @@
from salt.states import npm

npm.__salt__ = {}
npm.__opts__ = {}
npm.__opts__ = {'test': False}


@skipIf(NO_MOCK, NO_MOCK_REASON)
Expand Down

0 comments on commit 10b5728

Please sign in to comment.