Skip to content

Commit

Permalink
Merge branch 'develop' into fix-file-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Mar 6, 2019
2 parents 9b7ce29 + a15d4bc commit faf87cf
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 133 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'

gem 'test-kitchen', '~>1.23.3'
gem 'kitchen-salt', '~>0.4.1'
gem 'kitchen-salt', :git => 'https://github.com/s0undt3ch/kitchen-salt.git', :branch => 'features/nox'
gem 'kitchen-sync'
gem 'git'

Expand All @@ -13,7 +13,8 @@ end

group :windows do
gem 'winrm', '~>2.0'
gem 'winrm-fs', '~>1.3.1'
# gem 'winrm-fs', '~>1.3.1'
gem 'winrm-fs', :git => 'https://github.com/s0undt3ch/winrm-fs.git', :branch => 'hotfix/saltstack-ci'
end

group :ec2 do
Expand Down
19 changes: 17 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
SITECUSTOMIZE_DIR = os.path.join(REPO_ROOT, 'tests', 'support', 'coverage')

# We can't just import salt because if this is running under a frozen nox, there
# will be no salt to import
IS_WINDOWS = sys.platform.lower().startswith('win')

# Python versions to run against
_PYTHON_VERSIONS = ('2', '2.7', '3', '3.4', '3.5', '3.6')

Expand All @@ -41,15 +45,16 @@ def _create_ci_directories():

def _install_requirements(session, *extra_requirements):
# Install requirements
_requirements_files = []
_requirements_files = [
os.path.join(REPO_ROOT, 'requirements', 'pytest.txt')
]
if sys.platform.startswith('linux'):
requirements_files = [
os.path.join(REPO_ROOT, 'requirements', 'tests.txt')
]
elif sys.platform.startswith('win'):
requirements_files = [
os.path.join(REPO_ROOT, 'pkg', 'windows', 'req.txt'),
os.path.join(REPO_ROOT, 'pkg', 'windows', 'req_testing.txt'),
]
elif sys.platform.startswith('darwin'):
requirements_files = [
Expand All @@ -61,6 +66,10 @@ def _install_requirements(session, *extra_requirements):
if not requirements_files:
break
requirements_file = requirements_files.pop(0)

if requirements_file not in _requirements_files:
_requirements_files.append(requirements_file)

session.log('Processing {}'.format(requirements_file))
with open(requirements_file) as rfh: # pylint: disable=resource-leakage
for line in rfh:
Expand All @@ -80,8 +89,14 @@ def _install_requirements(session, *extra_requirements):
if extra_requirements:
session.install(*extra_requirements)

if IS_WINDOWS:
# Windows hacks :/
nox_windows_setup = os.path.join(REPO_ROOT, 'tests', 'support', 'nox-windows-setup.py')
session.run('python', nox_windows_setup)


def _run_with_coverage(session, *test_cmd):
session.install('coverage')
session.run('coverage', 'erase')
python_path_env_var = os.environ.get('PYTHONPATH') or None
if python_path_env_var is None:
Expand Down
15 changes: 9 additions & 6 deletions salt/client/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import salt.utils.versions
import salt.transport.client
import salt.log.setup
import salt.output
import salt.utils.text

from salt.ext import six

# Import 3rd-party libs
Expand Down Expand Up @@ -376,7 +379,10 @@ def low(self, fun, low, print_event=True, full_return=False):
try:
data['return'] = func(*args, **kwargs)
except TypeError as exc:
data['return'] = '\nPassed invalid arguments: {0}\n\nUsage:\n{1}'.format(exc, func.__doc__)
data['return'] = salt.utils.text.cli_info('Error: {exc}\nUsage:\n{doc}'.format(
exc=exc, doc=func.__doc__), 'Passed invalid arguments')
except Exception as exc:
data['return'] = salt.utils.text.cli_info(six.text_type(exc), 'General error occurred')
try:
data['success'] = self.context.get('retcode', 0) == 0
except AttributeError:
Expand All @@ -389,11 +395,8 @@ def low(self, fun, low, print_event=True, full_return=False):
if isinstance(ex, salt.exceptions.NotImplemented):
data['return'] = six.text_type(ex)
else:
data['return'] = 'Exception occurred in {0} {1}: {2}'.format(
self.client,
fun,
traceback.format_exc(),
)
data['return'] = 'Exception occurred in {client} {fun}: {tb}'.format(
client=self.client, fun=fun, tb=traceback.format_exc())
data['success'] = False

if self.store_job:
Expand Down
44 changes: 30 additions & 14 deletions salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,7 @@ def run_chroot(root,
group=None,
shell=DEFAULT_SHELL,
python_shell=True,
binds=None,
env=None,
clean_env=False,
template=None,
Expand Down Expand Up @@ -3096,19 +3097,17 @@ def run_chroot(root,
:param str root: Path to the root of the jail to use.
stdin
A string of standard input can be specified for the command to be run using
the ``stdin`` parameter. This can be useful in cases where sensitive
information must be read from standard input.:
:param str stdin: A string of standard input can be specified for
the command to be run using the ``stdin`` parameter. This can
be useful in cases where sensitive information must be read
from standard input.:
runas
User to run script as.
:param str runas: User to run script as.
group
Group to run script as.
:param str group: Group to run script as.
shell
Shell to execute under. Defaults to the system default shell.
:param str shell: Shell to execute under. Defaults to the system
default shell.
:param str cmd: The command to run. ex: ``ls -lart /home``
Expand All @@ -3132,6 +3131,9 @@ def run_chroot(root,
arguments. Set to True to use shell features, such as pipes or
redirection.
:param list binds: List of directories that will be exported inside
the chroot with the bind option.
:param dict env: Environment variables to be set prior to execution.
.. note::
Expand All @@ -3150,11 +3152,11 @@ def run_chroot(root,
engine will be used to render the downloaded file. Currently jinja,
mako, and wempy are supported.
:param bool rstrip:
Strip all whitespace off the end of output before it is returned.
:param bool rstrip: Strip all whitespace off the end of output
before it is returned.
:param str umask:
The umask (in octal) to use when running the command.
:param str umask: The umask (in octal) to use when running the
command.
:param str output_encoding: Control the encoding used to decode the
command's output.
Expand Down Expand Up @@ -3242,6 +3244,15 @@ def run_chroot(root,
'sysfs',
fstype='sysfs')

binds = binds if binds else []
for bind_exported in binds:
bind_exported_to = os.path.relpath(bind_exported, os.path.sep)
bind_exported_to = os.path.join(root, bind_exported_to)
__salt__['mount.mount'](
bind_exported_to,
bind_exported,
opts='default,bind')

# Execute chroot routine
sh_ = '/bin/sh'
if os.path.isfile(os.path.join(root, 'bin/bash')):
Expand Down Expand Up @@ -3294,6 +3305,11 @@ def run_chroot(root,
log.error('Processes running in chroot could not be killed, '
'filesystem will remain mounted')

for bind_exported in binds:
bind_exported_to = os.path.relpath(bind_exported, os.path.sep)
bind_exported_to = os.path.join(root, bind_exported_to)
__salt__['mount.umount'](bind_exported_to)

__salt__['mount.umount'](os.path.join(root, 'sys'))
__salt__['mount.umount'](os.path.join(root, 'proc'))
__salt__['mount.umount'](os.path.join(root, 'dev'))
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/win_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def remove(path, force=False):
raise SaltInvocationError('File path must be absolute: {0}'.format(path))

# Does the file/folder exists
if not os.path.exists(path):
if not os.path.exists(path) and not is_link(path):
raise CommandExecutionError('Path not found: {0}'.format(path))

# Remove ReadOnly Attribute
Expand Down
Loading

0 comments on commit faf87cf

Please sign in to comment.