Merge pull request #46577 from gtmanfred/2017.7.5

Fix npm issue
This commit is contained in:
Nicole Thomas 2018-03-19 07:51:03 -04:00 committed by GitHub
commit cdd768fa4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -31,7 +31,7 @@ provisioner:
salt_version: latest
salt_bootstrap_url: https://bootstrap.saltstack.com
salt_bootstrap_options: -X -p rsync stable <%= version %>
log_level: info
log_level: debug
sudo: true
require_chef: false
retry_on_exit_code:

View File

@ -157,7 +157,7 @@ def install(pkg=None,
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = ' '.join(cmd)
result = __salt__['cmd.run_all'](cmd, python_shell=True, cwd=dir, runas=runas, env=env)
@ -236,7 +236,7 @@ def uninstall(pkg, dir=None, runas=None, env=None):
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = ['npm', 'uninstall', '"{0}"'.format(pkg)]
if not dir:
@ -295,7 +295,7 @@ def list_(pkg=None, dir=None, runas=None, env=None, depth=None):
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = ['npm', 'list', '--json', '--silent']
@ -358,7 +358,7 @@ def cache_clean(path=None, runas=None, env=None, force=False):
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = ['npm', 'cache', 'clean']
if path:
@ -405,7 +405,7 @@ def cache_list(path=None, runas=None, env=None):
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = ['npm', 'cache', 'ls']
if path:
@ -445,7 +445,7 @@ def cache_path(runas=None, env=None):
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = 'npm config get cache'

View File

@ -6,12 +6,14 @@
'''
# Import Python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest, requires_network
from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.runtests import RUNTIME_VARS
# Import salt libs
import salt.utils
@ -42,10 +44,14 @@ class NpmStateTest(ModuleCase, SaltReturnAssertsMixin):
'''
Determine if URL-referenced NPM module can be successfully installed.
'''
ret = self.run_state('npm.installed', name='request/request#v2.81.1')
user = os.environ.get('SUDO_USER', 'root')
npm_dir = os.path.join(RUNTIME_VARS.TMP, 'git-install-npm')
self.run_state('file.directory', name=npm_dir, user=user, dir_mode='755')
ret = self.run_state('npm.installed', name='request/request#v2.81.1', runas=user, dir=npm_dir)
self.assertSaltTrueReturn(ret)
ret = self.run_state('npm.removed', name='git://github.com/request/request')
ret = self.run_state('npm.removed', name='git://github.com/request/request', runas=user, dir=npm_dir)
self.assertSaltTrueReturn(ret)
self.run_state('file.absent', name=npm_dir)
@requires_network()
@destructiveTest