2013-08-10 07:14:57 +00:00
|
|
|
#!/usr/bin/env python
|
2014-11-21 19:05:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-08-10 07:14:57 +00:00
|
|
|
'''
|
2013-08-11 05:50:47 +00:00
|
|
|
This script is used to test Salt from a Jenkins server, specifically
|
|
|
|
jenkins.saltstack.com.
|
2013-08-10 07:14:57 +00:00
|
|
|
|
2013-08-11 05:50:47 +00:00
|
|
|
This script is intended to be shell-centric!!
|
2013-08-10 07:14:57 +00:00
|
|
|
'''
|
|
|
|
|
2013-08-10 07:23:32 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2014-09-08 17:23:44 +00:00
|
|
|
import glob
|
2013-08-13 04:54:47 +00:00
|
|
|
import os
|
|
|
|
import re
|
2013-08-10 07:23:32 +00:00
|
|
|
import sys
|
2014-04-06 14:50:39 +00:00
|
|
|
import json
|
2013-09-06 16:35:30 +00:00
|
|
|
import time
|
2013-09-08 15:32:35 +00:00
|
|
|
import shutil
|
2013-08-10 07:14:57 +00:00
|
|
|
import optparse
|
2013-12-09 23:06:17 +00:00
|
|
|
import subprocess
|
2015-12-16 21:48:51 +00:00
|
|
|
import random
|
2013-08-10 07:14:57 +00:00
|
|
|
|
2014-01-10 17:24:55 +00:00
|
|
|
# Import Salt libs
|
2017-07-18 16:31:01 +00:00
|
|
|
import salt.utils.files
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
import salt.utils.stringutils
|
2013-08-13 04:54:47 +00:00
|
|
|
try:
|
2013-12-09 23:06:17 +00:00
|
|
|
from salt.utils.nb_popen import NonBlockingPopen
|
2013-08-13 04:54:47 +00:00
|
|
|
except ImportError:
|
2013-12-09 23:06:17 +00:00
|
|
|
# Salt not installed, or nb_popen was not yet shipped with it
|
2013-09-06 11:14:27 +00:00
|
|
|
SALT_LIB = os.path.abspath(
|
2013-08-13 04:54:47 +00:00
|
|
|
os.path.dirname(os.path.dirname(__file__))
|
|
|
|
)
|
2013-09-06 11:14:27 +00:00
|
|
|
if SALT_LIB not in sys.path:
|
|
|
|
sys.path.insert(0, SALT_LIB)
|
2013-08-13 04:54:47 +00:00
|
|
|
try:
|
|
|
|
# Let's try using the current checked out code
|
2013-12-09 23:06:17 +00:00
|
|
|
from salt.utils.nb_popen import NonBlockingPopen
|
2013-08-13 04:54:47 +00:00
|
|
|
except ImportError:
|
|
|
|
# Still an ImportError??? Let's use some "brute-force"
|
|
|
|
sys.path.insert(
|
|
|
|
0,
|
2013-09-06 11:14:27 +00:00
|
|
|
os.path.join(SALT_LIB, 'salt', 'utils')
|
2013-08-13 04:54:47 +00:00
|
|
|
)
|
2013-12-09 23:06:17 +00:00
|
|
|
from nb_popen import NonBlockingPopen
|
2013-08-13 04:54:47 +00:00
|
|
|
|
2014-01-10 17:24:55 +00:00
|
|
|
# Import 3rd-party libs
|
2014-04-13 10:05:18 +00:00
|
|
|
import yaml
|
2014-01-10 17:24:55 +00:00
|
|
|
try:
|
2014-11-21 23:33:29 +00:00
|
|
|
import requests
|
|
|
|
HAS_REQUESTS = True
|
2014-01-10 17:24:55 +00:00
|
|
|
except ImportError:
|
2014-11-21 23:33:29 +00:00
|
|
|
HAS_REQUESTS = False
|
2013-08-13 04:54:47 +00:00
|
|
|
|
2014-01-11 16:30:23 +00:00
|
|
|
SALT_GIT_URL = 'https://github.com/saltstack/salt.git'
|
|
|
|
|
2014-01-10 17:28:07 +00:00
|
|
|
|
2014-04-13 10:05:18 +00:00
|
|
|
def build_pillar_data(options):
|
|
|
|
'''
|
|
|
|
Build a YAML formatted string to properly pass pillar data
|
|
|
|
'''
|
2014-08-30 23:38:39 +00:00
|
|
|
pillar = {'test_transport': options.test_transport,
|
2014-12-08 17:32:28 +00:00
|
|
|
'cloud_only': options.cloud_only,
|
|
|
|
'with_coverage': options.test_without_coverage is False}
|
2014-04-13 11:07:56 +00:00
|
|
|
if options.test_git_commit is not None:
|
|
|
|
pillar['test_git_commit'] = options.test_git_commit
|
|
|
|
if options.test_git_url is not None:
|
|
|
|
pillar['test_git_url'] = options.test_git_url
|
|
|
|
if options.bootstrap_salt_url is not None:
|
|
|
|
pillar['bootstrap_salt_url'] = options.bootstrap_salt_url
|
|
|
|
if options.bootstrap_salt_commit is not None:
|
|
|
|
pillar['bootstrap_salt_commit'] = options.bootstrap_salt_commit
|
2014-09-11 22:05:09 +00:00
|
|
|
if options.package_source_dir:
|
|
|
|
pillar['package_source_dir'] = options.package_source_dir
|
|
|
|
if options.package_build_dir:
|
|
|
|
pillar['package_build_dir'] = options.package_build_dir
|
|
|
|
if options.package_artifact_dir:
|
|
|
|
pillar['package_artifact_dir'] = options.package_artifact_dir
|
2014-04-13 10:05:18 +00:00
|
|
|
if options.pillar:
|
|
|
|
pillar.update(dict(options.pillar))
|
2014-04-13 12:16:22 +00:00
|
|
|
return yaml.dump(pillar, default_flow_style=True, indent=0, width=sys.maxint).rstrip()
|
2014-04-13 10:05:18 +00:00
|
|
|
|
|
|
|
|
2014-04-15 10:19:44 +00:00
|
|
|
def build_minion_target(options, vm_name):
|
2014-04-15 11:28:01 +00:00
|
|
|
target = vm_name
|
|
|
|
for grain in options.grain_target:
|
|
|
|
target += ' and G@{0}'.format(grain)
|
2014-04-15 11:35:48 +00:00
|
|
|
if options.grain_target:
|
2014-08-20 15:49:49 +00:00
|
|
|
return '"{0}"'.format(target)
|
2014-04-15 11:28:01 +00:00
|
|
|
return target
|
2014-04-15 10:19:44 +00:00
|
|
|
|
|
|
|
|
2014-04-17 18:19:40 +00:00
|
|
|
def generate_vm_name(options):
|
2013-09-06 11:14:27 +00:00
|
|
|
'''
|
|
|
|
Generate a random enough vm name
|
|
|
|
'''
|
2013-09-06 16:13:05 +00:00
|
|
|
if 'BUILD_NUMBER' in os.environ:
|
|
|
|
random_part = 'BUILD{0:0>6}'.format(os.environ.get('BUILD_NUMBER'))
|
|
|
|
else:
|
2014-10-02 13:08:28 +00:00
|
|
|
random_part = os.urandom(3).encode('hex')
|
2013-09-06 16:13:05 +00:00
|
|
|
|
2014-04-17 18:19:40 +00:00
|
|
|
return '{0}-{1}-{2}'.format(options.vm_prefix, options.platform, random_part)
|
2013-08-17 06:59:13 +00:00
|
|
|
|
2013-09-06 11:14:27 +00:00
|
|
|
|
2013-09-09 19:45:57 +00:00
|
|
|
def delete_vm(options):
|
2013-09-06 11:14:27 +00:00
|
|
|
'''
|
|
|
|
Stop a VM
|
|
|
|
'''
|
2013-09-09 19:45:57 +00:00
|
|
|
cmd = 'salt-cloud -d {0} -y'.format(options.delete_vm)
|
2013-08-17 06:59:13 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = NonBlockingPopen(
|
2013-08-17 06:59:13 +00:00
|
|
|
cmd,
|
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2013-12-09 23:06:17 +00:00
|
|
|
stream_stds=True
|
2013-08-17 06:59:13 +00:00
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.communicate()
|
2013-08-17 06:59:13 +00:00
|
|
|
|
|
|
|
|
2014-11-24 18:58:24 +00:00
|
|
|
def echo_parseable_environment(options, parser):
|
2013-09-06 11:14:27 +00:00
|
|
|
'''
|
|
|
|
Echo NAME=VAL parseable output
|
|
|
|
'''
|
2014-01-10 17:28:07 +00:00
|
|
|
output = []
|
|
|
|
|
|
|
|
if options.platform:
|
2014-04-17 18:19:40 +00:00
|
|
|
name = generate_vm_name(options)
|
2014-01-10 17:28:07 +00:00
|
|
|
output.extend([
|
|
|
|
'JENKINS_SALTCLOUD_VM_PLATFORM={0}'.format(options.platform),
|
2014-01-10 19:24:23 +00:00
|
|
|
'JENKINS_SALTCLOUD_VM_NAME={0}'.format(name)
|
2014-01-10 17:28:07 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
if options.provider:
|
|
|
|
output.append(
|
|
|
|
'JENKINS_SALTCLOUD_VM_PROVIDER={0}'.format(options.provider)
|
|
|
|
)
|
|
|
|
|
2014-01-10 18:29:01 +00:00
|
|
|
if options.pull_request:
|
2014-01-10 17:24:55 +00:00
|
|
|
# This is a Jenkins triggered Pull Request
|
|
|
|
# We need some more data about the Pull Request available to the
|
|
|
|
# environment
|
2014-11-21 23:33:29 +00:00
|
|
|
if HAS_REQUESTS is False:
|
|
|
|
parser.error(
|
|
|
|
'The python \'requests\' library needs to be installed'
|
|
|
|
)
|
|
|
|
|
|
|
|
headers = {}
|
2014-11-22 02:11:19 +00:00
|
|
|
url = 'https://api.github.com/repos/saltstack/salt/pulls/{0}'.format(options.pull_request)
|
2014-01-10 17:24:55 +00:00
|
|
|
|
|
|
|
github_access_token_path = os.path.join(
|
2014-11-21 23:33:29 +00:00
|
|
|
os.environ.get('JENKINS_HOME', os.path.expanduser('~')),
|
|
|
|
'.github_token'
|
2014-01-10 17:24:55 +00:00
|
|
|
)
|
2014-11-21 23:33:29 +00:00
|
|
|
if os.path.isfile(github_access_token_path):
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(github_access_token_path) as rfh:
|
2017-04-04 12:11:54 +00:00
|
|
|
headers = {
|
|
|
|
'Authorization': 'token {0}'.format(rfh.read().strip())
|
|
|
|
}
|
2014-11-21 23:33:29 +00:00
|
|
|
|
|
|
|
http_req = requests.get(url, headers=headers)
|
|
|
|
if http_req.status_code != 200:
|
|
|
|
parser.error(
|
|
|
|
'Unable to get the pull request: {0[message]}'.format(http_req.json())
|
2014-01-10 17:24:55 +00:00
|
|
|
)
|
2014-11-21 23:33:29 +00:00
|
|
|
|
|
|
|
pr_details = http_req.json()
|
|
|
|
output.extend([
|
|
|
|
'SALT_PR_GIT_URL={0}'.format(pr_details['head']['repo']['clone_url']),
|
|
|
|
'SALT_PR_GIT_BRANCH={0}'.format(pr_details['head']['ref']),
|
2014-11-22 02:11:19 +00:00
|
|
|
'SALT_PR_GIT_COMMIT={0}'.format(pr_details['head']['sha']),
|
2014-11-21 23:35:37 +00:00
|
|
|
'SALT_PR_GIT_BASE_BRANCH={0}'.format(pr_details['base']['ref']),
|
2014-11-21 23:33:29 +00:00
|
|
|
])
|
2014-01-10 19:37:22 +00:00
|
|
|
|
2014-01-10 21:30:26 +00:00
|
|
|
sys.stdout.write('\n\n{0}\n\n'.format('\n'.join(output)))
|
2013-09-06 11:14:27 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
2013-09-09 19:45:57 +00:00
|
|
|
def download_unittest_reports(options):
|
2013-09-08 17:48:32 +00:00
|
|
|
print('Downloading remote unittest reports...')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2014-01-05 00:10:24 +00:00
|
|
|
workspace = options.workspace
|
|
|
|
xml_reports_path = os.path.join(workspace, 'xml-test-reports')
|
|
|
|
if os.path.isdir(xml_reports_path):
|
|
|
|
shutil.rmtree(xml_reports_path)
|
2013-09-08 15:32:35 +00:00
|
|
|
|
2014-01-05 00:10:24 +00:00
|
|
|
os.makedirs(xml_reports_path)
|
2013-09-08 15:32:35 +00:00
|
|
|
|
|
|
|
cmds = (
|
2014-12-15 19:27:25 +00:00
|
|
|
'salt {0} archive.tar zcvf /tmp/xml-test-reports.tar.gz \'*.xml\' cwd=/tmp/xml-unittests-output/',
|
2013-09-09 20:52:58 +00:00
|
|
|
'salt {0} cp.push /tmp/xml-test-reports.tar.gz',
|
2014-04-15 12:01:05 +00:00
|
|
|
'mv -f /var/cache/salt/master/minions/{1}/files/tmp/xml-test-reports.tar.gz {2} && '
|
2014-08-20 16:07:12 +00:00
|
|
|
'tar zxvf {2}/xml-test-reports.tar.gz -C {2}/xml-test-reports && '
|
2014-04-15 12:01:05 +00:00
|
|
|
'rm -f {2}/xml-test-reports.tar.gz'
|
2013-09-08 15:32:35 +00:00
|
|
|
)
|
|
|
|
|
2013-09-09 19:45:57 +00:00
|
|
|
vm_name = options.download_unittest_reports
|
2013-09-08 15:32:35 +00:00
|
|
|
for cmd in cmds:
|
2014-04-15 12:01:05 +00:00
|
|
|
cmd = cmd.format(build_minion_target(options, vm_name), vm_name, workspace)
|
2013-09-09 19:45:57 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
2013-09-08 15:32:35 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = NonBlockingPopen(
|
2013-09-09 19:45:57 +00:00
|
|
|
cmd,
|
2013-09-08 15:32:35 +00:00
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
stream_stds=True
|
2013-09-08 15:32:35 +00:00
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.communicate()
|
|
|
|
if proc.returncode != 0:
|
2013-09-08 15:32:35 +00:00
|
|
|
print(
|
2013-09-09 10:48:59 +00:00
|
|
|
'\nFailed to execute command. Exit code: {0}'.format(
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.returncode
|
2013-09-08 15:32:35 +00:00
|
|
|
)
|
|
|
|
)
|
2013-10-03 14:08:50 +00:00
|
|
|
time.sleep(0.25)
|
2013-09-08 15:32:35 +00:00
|
|
|
|
2013-09-08 17:18:21 +00:00
|
|
|
|
2013-09-09 19:45:57 +00:00
|
|
|
def download_coverage_report(options):
|
2013-09-08 17:48:32 +00:00
|
|
|
print('Downloading remote coverage report...')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-09-09 20:52:58 +00:00
|
|
|
workspace = options.workspace
|
2013-09-10 11:15:19 +00:00
|
|
|
vm_name = options.download_coverage_report
|
2013-09-09 20:52:58 +00:00
|
|
|
|
|
|
|
if os.path.isfile(os.path.join(workspace, 'coverage.xml')):
|
|
|
|
os.unlink(os.path.join(workspace, 'coverage.xml'))
|
2013-09-09 10:24:25 +00:00
|
|
|
|
2013-09-08 16:43:55 +00:00
|
|
|
cmds = (
|
2013-09-09 10:24:25 +00:00
|
|
|
'salt {0} archive.gzip /tmp/coverage.xml',
|
|
|
|
'salt {0} cp.push /tmp/coverage.xml.gz',
|
2014-04-15 10:19:44 +00:00
|
|
|
'gunzip /var/cache/salt/master/minions/{1}/files/tmp/coverage.xml.gz',
|
|
|
|
'mv /var/cache/salt/master/minions/{1}/files/tmp/coverage.xml {2}'
|
2013-09-08 16:43:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for cmd in cmds:
|
2014-04-15 10:19:44 +00:00
|
|
|
cmd = cmd.format(build_minion_target(options, vm_name), vm_name, workspace)
|
2013-09-08 17:48:32 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
2013-09-08 16:43:55 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = NonBlockingPopen(
|
2013-09-08 17:48:32 +00:00
|
|
|
cmd,
|
2013-09-08 16:43:55 +00:00
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
stream_stds=True
|
2013-09-08 16:43:55 +00:00
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.communicate()
|
|
|
|
if proc.returncode != 0:
|
2013-09-08 16:43:55 +00:00
|
|
|
print(
|
2013-09-09 10:48:59 +00:00
|
|
|
'\nFailed to execute command. Exit code: {0}'.format(
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.returncode
|
2013-09-08 16:43:55 +00:00
|
|
|
)
|
|
|
|
)
|
2013-10-03 14:08:50 +00:00
|
|
|
time.sleep(0.25)
|
2013-09-08 16:43:55 +00:00
|
|
|
|
|
|
|
|
2013-10-03 11:52:05 +00:00
|
|
|
def download_remote_logs(options):
|
|
|
|
print('Downloading remote logs...')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
workspace = options.workspace
|
|
|
|
vm_name = options.download_remote_logs
|
|
|
|
|
|
|
|
for fname in ('salt-runtests.log', 'minion.log'):
|
|
|
|
if os.path.isfile(os.path.join(workspace, fname)):
|
|
|
|
os.unlink(os.path.join(workspace, fname))
|
|
|
|
|
2014-04-13 14:52:57 +00:00
|
|
|
if not options.remote_log_path:
|
|
|
|
options.remote_log_path = [
|
|
|
|
'/tmp/salt-runtests.log',
|
|
|
|
'/var/log/salt/minion'
|
|
|
|
]
|
|
|
|
|
|
|
|
cmds = []
|
|
|
|
|
|
|
|
for remote_log in options.remote_log_path:
|
|
|
|
cmds.extend([
|
|
|
|
'salt {{0}} archive.gzip {0}'.format(remote_log),
|
|
|
|
'salt {{0}} cp.push {0}.gz'.format(remote_log),
|
2014-04-15 10:19:44 +00:00
|
|
|
'gunzip /var/cache/salt/master/minions/{{1}}/files{0}.gz'.format(remote_log),
|
|
|
|
'mv /var/cache/salt/master/minions/{{1}}/files{0} {{2}}/{1}'.format(
|
2014-04-13 14:52:57 +00:00
|
|
|
remote_log,
|
|
|
|
'{0}{1}'.format(
|
|
|
|
os.path.basename(remote_log),
|
2014-04-27 12:56:17 +00:00
|
|
|
'' if remote_log.endswith('.log') else '.log'
|
2014-04-13 14:52:57 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
])
|
2013-10-03 11:52:05 +00:00
|
|
|
|
|
|
|
for cmd in cmds:
|
2014-04-15 10:19:44 +00:00
|
|
|
cmd = cmd.format(build_minion_target(options, vm_name), vm_name, workspace)
|
2013-10-03 11:52:05 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = NonBlockingPopen(
|
2013-10-03 11:52:05 +00:00
|
|
|
cmd,
|
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
stream_stds=True
|
2013-10-03 11:52:05 +00:00
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.communicate()
|
|
|
|
if proc.returncode != 0:
|
2013-10-03 11:52:05 +00:00
|
|
|
print(
|
|
|
|
'\nFailed to execute command. Exit code: {0}'.format(
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.returncode
|
2013-10-03 11:52:05 +00:00
|
|
|
)
|
|
|
|
)
|
2013-10-03 14:08:50 +00:00
|
|
|
time.sleep(0.25)
|
2013-10-03 11:52:05 +00:00
|
|
|
|
|
|
|
|
2014-09-08 17:23:44 +00:00
|
|
|
def download_packages(options):
|
|
|
|
print('Downloading packages...')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
workspace = options.workspace
|
|
|
|
vm_name = options.download_packages
|
|
|
|
|
|
|
|
for fglob in ('salt-*.rpm',
|
|
|
|
'salt-*.deb',
|
|
|
|
'salt-*.pkg.xz',
|
2014-09-11 22:05:09 +00:00
|
|
|
'salt-buildpackage.log'):
|
2014-09-08 17:23:44 +00:00
|
|
|
for fname in glob.glob(os.path.join(workspace, fglob)):
|
|
|
|
if os.path.isfile(fname):
|
|
|
|
os.unlink(fname)
|
|
|
|
|
|
|
|
cmds = [
|
|
|
|
('salt {{0}} archive.tar czf {0}.tar.gz sources=\'*.*\' cwd={0}'
|
2014-09-11 22:05:09 +00:00
|
|
|
.format(options.package_artifact_dir)),
|
|
|
|
'salt {{0}} cp.push {0}.tar.gz'.format(options.package_artifact_dir),
|
2014-09-11 17:56:45 +00:00
|
|
|
('tar -C {{2}} -xzf /var/cache/salt/master/minions/{{1}}/files{0}.tar.gz'
|
2014-09-11 22:05:09 +00:00
|
|
|
.format(options.package_artifact_dir)),
|
2014-09-08 17:23:44 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for cmd in cmds:
|
|
|
|
cmd = cmd.format(build_minion_target(options, vm_name), vm_name, workspace)
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
proc = NonBlockingPopen(
|
|
|
|
cmd,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
stream_stds=True
|
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2014-09-08 17:23:44 +00:00
|
|
|
proc.communicate()
|
|
|
|
if proc.returncode != 0:
|
|
|
|
print(
|
|
|
|
'\nFailed to execute command. Exit code: {0}'.format(
|
|
|
|
proc.returncode
|
|
|
|
)
|
|
|
|
)
|
|
|
|
time.sleep(0.25)
|
|
|
|
|
|
|
|
|
2013-09-06 11:14:27 +00:00
|
|
|
def run(opts):
|
2013-08-10 07:14:57 +00:00
|
|
|
'''
|
|
|
|
RUN!
|
|
|
|
'''
|
2013-09-06 11:14:27 +00:00
|
|
|
vm_name = os.environ.get(
|
2013-09-06 13:42:20 +00:00
|
|
|
'JENKINS_SALTCLOUD_VM_NAME',
|
2014-04-17 18:19:40 +00:00
|
|
|
generate_vm_name(opts)
|
2013-09-06 11:14:27 +00:00
|
|
|
)
|
|
|
|
|
2013-09-10 11:21:41 +00:00
|
|
|
if opts.download_remote_reports:
|
2014-12-08 17:32:28 +00:00
|
|
|
if opts.test_without_coverage is False:
|
|
|
|
opts.download_coverage_report = vm_name
|
2013-09-10 11:21:41 +00:00
|
|
|
opts.download_unittest_reports = vm_name
|
2014-09-08 17:23:44 +00:00
|
|
|
opts.download_packages = vm_name
|
2013-09-10 11:15:39 +00:00
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if opts.bootstrap_salt_commit is not None:
|
|
|
|
if opts.bootstrap_salt_url is None:
|
|
|
|
opts.bootstrap_salt_url = 'https://github.com/saltstack/salt.git'
|
2014-04-13 10:40:58 +00:00
|
|
|
cmd = (
|
|
|
|
'salt-cloud -l debug'
|
2014-06-07 12:06:09 +00:00
|
|
|
' --script-args "-D -g {bootstrap_salt_url} -n git {1}"'
|
|
|
|
' -p {provider}_{platform} {0}'.format(
|
|
|
|
vm_name,
|
|
|
|
os.environ.get(
|
|
|
|
'SALT_MINION_BOOTSTRAP_RELEASE',
|
|
|
|
opts.bootstrap_salt_commit
|
|
|
|
),
|
|
|
|
**opts.__dict__
|
|
|
|
)
|
2014-04-13 10:40:58 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
cmd = (
|
|
|
|
'salt-cloud -l debug'
|
2014-06-07 12:06:09 +00:00
|
|
|
' --script-args "-D -n git {1}" -p {provider}_{platform} {0}'.format(
|
|
|
|
vm_name,
|
|
|
|
os.environ.get(
|
|
|
|
'SALT_MINION_BOOTSTRAP_RELEASE',
|
|
|
|
opts.bootstrap_salt_commit
|
|
|
|
),
|
|
|
|
**opts.__dict__
|
|
|
|
)
|
2014-04-13 10:40:58 +00:00
|
|
|
)
|
2015-12-16 21:48:51 +00:00
|
|
|
if opts.splay is not None:
|
|
|
|
# Sleep a random number of seconds
|
|
|
|
cloud_downtime = random.randint(0, opts.splay)
|
|
|
|
print('Sleeping random period before calling salt-cloud: {0}'.format(cloud_downtime))
|
|
|
|
time.sleep(cloud_downtime)
|
2013-12-09 23:05:17 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = NonBlockingPopen(
|
2013-12-09 23:05:17 +00:00
|
|
|
cmd,
|
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2013-12-09 23:06:17 +00:00
|
|
|
stream_stds=True
|
2013-12-09 23:05:17 +00:00
|
|
|
)
|
2014-11-19 17:56:44 +00:00
|
|
|
proc.poll_and_read_until_finish(interval=0.5)
|
2013-12-09 23:06:17 +00:00
|
|
|
proc.communicate()
|
2013-12-09 23:05:17 +00:00
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
retcode = proc.returncode
|
2013-12-09 23:05:17 +00:00
|
|
|
if retcode != 0:
|
|
|
|
print('Failed to bootstrap VM. Exit code: {0}'.format(retcode))
|
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2013-12-09 23:05:17 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
|
|
|
print('VM Bootstrapped. Exit code: {0}'.format(retcode))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2015-12-16 21:48:51 +00:00
|
|
|
# Sleep a random number of seconds
|
|
|
|
bootstrap_downtime = random.randint(0, opts.splay)
|
|
|
|
print('Sleeping for {0} seconds to allow the minion to breathe a little'.format(bootstrap_downtime))
|
2013-12-09 23:05:17 +00:00
|
|
|
sys.stdout.flush()
|
2015-12-16 21:48:51 +00:00
|
|
|
time.sleep(bootstrap_downtime)
|
2013-12-09 23:05:17 +00:00
|
|
|
|
2014-04-13 11:49:00 +00:00
|
|
|
if opts.bootstrap_salt_commit is not None:
|
2014-04-06 18:10:56 +00:00
|
|
|
# Let's find out if the installed version matches the passed in pillar
|
2014-04-06 14:50:39 +00:00
|
|
|
# information
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Grabbing bootstrapped minion version information ... ')
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd = 'salt -t 100 {0} --out json test.version'.format(build_minion_target(opts, vm_name))
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
2014-04-15 11:40:05 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-08 13:50:03 +00:00
|
|
|
proc = subprocess.Popen(
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd,
|
2014-04-06 14:50:39 +00:00
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2014-04-06 14:50:39 +00:00
|
|
|
)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the bootstrapped minion version. Exit code: {0}'.format(retcode))
|
2014-04-06 14:50:39 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-06 14:50:39 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
outstr = salt.utils.stringutils.to_str(stdout).strip()
|
2015-06-06 13:47:52 +00:00
|
|
|
if not outstr:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the bootstrapped minion version(no output). Exit code: {0}'.format(retcode))
|
2014-04-06 14:50:39 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-06 14:50:39 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-04-29 23:43:41 +00:00
|
|
|
try:
|
2015-06-06 13:47:52 +00:00
|
|
|
version_info = json.loads(outstr)
|
2014-06-07 12:06:09 +00:00
|
|
|
bootstrap_minion_version = os.environ.get(
|
|
|
|
'SALT_MINION_BOOTSTRAP_RELEASE',
|
|
|
|
opts.bootstrap_salt_commit[:7]
|
2014-06-07 12:53:02 +00:00
|
|
|
)
|
2015-01-06 22:29:21 +00:00
|
|
|
print('Minion reported salt version: {0}'.format(version_info))
|
2014-06-07 12:06:09 +00:00
|
|
|
if bootstrap_minion_version not in version_info[vm_name]:
|
2014-04-29 23:43:41 +00:00
|
|
|
print('\n\nATTENTION!!!!\n')
|
|
|
|
print('The boostrapped minion version commit does not contain the desired commit:')
|
2015-08-27 04:26:08 +00:00
|
|
|
print(
|
|
|
|
' \'{0}\' does not contain \'{1}\''.format(
|
|
|
|
version_info[vm_name],
|
|
|
|
bootstrap_minion_version
|
|
|
|
)
|
|
|
|
)
|
2014-04-29 23:43:41 +00:00
|
|
|
print('\n\n')
|
|
|
|
sys.stdout.flush()
|
|
|
|
#if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
|
|
|
# delete_vm(opts)
|
|
|
|
#sys.exit(retcode)
|
|
|
|
else:
|
|
|
|
print('matches!')
|
|
|
|
except ValueError:
|
2015-08-27 04:26:08 +00:00
|
|
|
print('Failed to load any JSON from \'{0}\''.format(outstr))
|
2014-04-06 14:50:39 +00:00
|
|
|
|
2014-08-31 02:18:12 +00:00
|
|
|
if opts.cloud_only:
|
2014-08-30 23:38:39 +00:00
|
|
|
# Run Cloud Provider tests preparation SLS
|
2015-12-16 21:48:51 +00:00
|
|
|
cloud_provider_downtime = random.randint(3, opts.splay)
|
|
|
|
time.sleep(cloud_provider_downtime)
|
2014-08-30 23:38:39 +00:00
|
|
|
cmd = (
|
|
|
|
'salt -t 900 {target} state.sls {cloud_prep_sls} pillar="{pillar}" '
|
|
|
|
'--no-color'.format(
|
|
|
|
target=build_minion_target(opts, vm_name),
|
|
|
|
cloud_prep_sls='cloud-only',
|
|
|
|
pillar=build_pillar_data(opts),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# Run standard preparation SLS
|
2015-12-16 21:48:51 +00:00
|
|
|
standard_sls_downtime = random.randint(3, opts.splay)
|
|
|
|
time.sleep(standard_sls_downtime)
|
2014-08-30 23:38:39 +00:00
|
|
|
cmd = (
|
|
|
|
'salt -t 1800 {target} state.sls {prep_sls} pillar="{pillar}" '
|
|
|
|
'--no-color'.format(
|
|
|
|
target=build_minion_target(opts, vm_name),
|
|
|
|
prep_sls=opts.prep_sls,
|
|
|
|
pillar=build_pillar_data(opts),
|
|
|
|
)
|
2014-04-06 18:10:56 +00:00
|
|
|
)
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2014-04-07 22:14:27 +00:00
|
|
|
proc = subprocess.Popen(
|
2014-04-06 18:10:56 +00:00
|
|
|
cmd,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2014-04-06 18:10:56 +00:00
|
|
|
)
|
2014-06-06 11:25:01 +00:00
|
|
|
stdout, stderr = proc.communicate()
|
2014-04-07 22:14:27 +00:00
|
|
|
|
|
|
|
if stdout:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stdout))
|
2014-06-06 11:25:01 +00:00
|
|
|
if stderr:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stderr))
|
2015-06-06 13:47:52 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-06 18:10:56 +00:00
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
|
|
|
print('Failed to execute the preparation SLS file. Exit code: {0}'.format(retcode))
|
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-06 18:10:56 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-08-31 02:18:12 +00:00
|
|
|
if opts.cloud_only:
|
2015-12-16 21:48:51 +00:00
|
|
|
cloud_provider_pillar = random.randint(3, opts.splay)
|
|
|
|
time.sleep(cloud_provider_pillar)
|
2014-08-30 23:38:39 +00:00
|
|
|
# Run Cloud Provider tests pillar preparation SLS
|
|
|
|
cmd = (
|
2014-08-31 15:31:12 +00:00
|
|
|
'salt -t 600 {target} state.sls {cloud_prep_sls} pillar="{pillar}" '
|
2014-08-30 23:38:39 +00:00
|
|
|
'--no-color'.format(
|
|
|
|
target=build_minion_target(opts, vm_name),
|
|
|
|
cloud_prep_sls='cloud-test-configs',
|
|
|
|
pillar=build_pillar_data(opts),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
cmd,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
|
|
|
stdout, stderr = proc.communicate()
|
|
|
|
|
|
|
|
if stdout:
|
|
|
|
# DO NOT print the state return here!
|
|
|
|
print('Cloud configuration files provisioned via pillar.')
|
|
|
|
if stderr:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stderr))
|
2015-06-06 13:47:52 +00:00
|
|
|
sys.stdout.flush()
|
2014-08-30 23:38:39 +00:00
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
|
|
|
print('Failed to execute the preparation SLS file. Exit code: {0}'.format(retcode))
|
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
|
|
|
delete_vm(opts)
|
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-04-14 10:49:51 +00:00
|
|
|
if opts.prep_sls_2 is not None:
|
2015-12-16 21:48:51 +00:00
|
|
|
sls_2_downtime = random.randint(3, opts.splay)
|
|
|
|
time.sleep(sls_2_downtime)
|
2014-04-14 10:49:51 +00:00
|
|
|
|
|
|
|
# Run the 2nd preparation SLS
|
|
|
|
cmd = (
|
2014-04-15 10:19:44 +00:00
|
|
|
'salt -t 30 {target} state.sls {prep_sls_2} pillar="{pillar}" '
|
2014-04-14 10:49:51 +00:00
|
|
|
'--no-color'.format(
|
|
|
|
prep_sls_2=opts.prep_sls_2,
|
|
|
|
pillar=build_pillar_data(opts),
|
2014-04-15 10:19:44 +00:00
|
|
|
target=build_minion_target(opts, vm_name),
|
2014-04-14 10:49:51 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
cmd,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
2014-06-06 11:25:01 +00:00
|
|
|
stdout, stderr = proc.communicate()
|
2014-04-14 10:49:51 +00:00
|
|
|
|
|
|
|
if stdout:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stdout))
|
2014-06-06 11:25:01 +00:00
|
|
|
if stderr:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stderr))
|
2015-06-06 13:47:52 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-14 10:49:51 +00:00
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
|
|
|
print('Failed to execute the 2nd preparation SLS file. Exit code: {0}'.format(retcode))
|
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
|
|
|
delete_vm(opts)
|
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-04-14 10:08:24 +00:00
|
|
|
# Run remote checks
|
2014-04-13 11:07:56 +00:00
|
|
|
if opts.test_git_url is not None:
|
2015-12-16 21:48:51 +00:00
|
|
|
test_git_downtime = random.randint(1, opts.splay)
|
|
|
|
time.sleep(test_git_downtime)
|
2014-04-07 20:16:36 +00:00
|
|
|
# Let's find out if the cloned repository if checked out from the
|
|
|
|
# desired repository
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Grabbing the cloned repository remotes information ... ')
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd = 'salt -t 100 {0} --out json git.remote_get /testing'.format(build_minion_target(opts, vm_name))
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
2014-04-15 11:40:05 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-07 22:25:01 +00:00
|
|
|
proc = subprocess.Popen(
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd,
|
2014-04-07 20:16:36 +00:00
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2014-04-07 20:16:36 +00:00
|
|
|
)
|
2014-06-06 11:25:01 +00:00
|
|
|
|
2015-06-06 13:47:52 +00:00
|
|
|
stdout, _ = proc.communicate()
|
2014-04-07 20:16:36 +00:00
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the cloned repository remote. Exit code: {0}'.format(retcode))
|
2014-04-07 20:16:36 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-07 20:16:36 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
|
|
|
if not stdout:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the cloned repository remote(no output). Exit code: {0}'.format(retcode))
|
2014-04-07 20:16:36 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-07 20:16:36 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-04-30 07:39:49 +00:00
|
|
|
try:
|
|
|
|
remotes_info = json.loads(stdout.strip())
|
|
|
|
if remotes_info is None or remotes_info[vm_name] is None or opts.test_git_url not in remotes_info[vm_name]:
|
|
|
|
print('The cloned repository remote is not the desired one:')
|
2015-08-27 04:26:08 +00:00
|
|
|
print(' \'{0}\' is not in {1}'.format(opts.test_git_url, remotes_info))
|
2014-04-30 07:39:49 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
|
|
|
delete_vm(opts)
|
|
|
|
sys.exit(retcode)
|
|
|
|
print('matches!')
|
|
|
|
except ValueError:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print('Failed to load any JSON from \'{0}\''.format(salt.utils.stringutils.to_str(stdout).strip()))
|
2014-04-07 20:16:36 +00:00
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if opts.test_git_commit is not None:
|
2015-12-16 21:48:51 +00:00
|
|
|
test_git_commit_downtime = random.randint(1, opts.splay)
|
|
|
|
time.sleep(test_git_commit_downtime)
|
2014-04-14 10:08:24 +00:00
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
# Let's find out if the cloned repository is checked out at the desired
|
2014-04-06 18:10:56 +00:00
|
|
|
# commit
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Grabbing the cloned repository commit information ... ')
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd = 'salt -t 100 {0} --out json git.revision /testing'.format(build_minion_target(opts, vm_name))
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
2014-04-15 11:40:05 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-07 22:25:01 +00:00
|
|
|
proc = subprocess.Popen(
|
2014-04-15 11:18:45 +00:00
|
|
|
cmd,
|
2014-04-06 18:10:56 +00:00
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2014-04-06 18:10:56 +00:00
|
|
|
)
|
|
|
|
stdout, _ = proc.communicate()
|
2014-04-07 20:16:36 +00:00
|
|
|
sys.stdout.flush()
|
2014-04-06 18:10:56 +00:00
|
|
|
|
|
|
|
retcode = proc.returncode
|
|
|
|
if retcode != 0:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the cloned repository revision. Exit code: {0}'.format(retcode))
|
2014-04-06 18:10:56 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-06 18:10:56 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
|
|
|
if not stdout:
|
2014-04-15 11:40:05 +00:00
|
|
|
print('Failed to get the cloned repository revision(no output). Exit code: {0}'.format(retcode))
|
2014-04-06 18:10:56 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2014-04-06 18:10:56 +00:00
|
|
|
sys.exit(retcode)
|
|
|
|
|
2014-04-30 07:39:49 +00:00
|
|
|
try:
|
|
|
|
revision_info = json.loads(stdout.strip())
|
|
|
|
if revision_info[vm_name][7:] != opts.test_git_commit[7:]:
|
|
|
|
print('The cloned repository commit is not the desired one:')
|
2015-08-27 04:26:08 +00:00
|
|
|
print(' \'{0}\' != \'{1}\''.format(revision_info[vm_name][:7], opts.test_git_commit[:7]))
|
2014-04-30 07:39:49 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
|
|
|
delete_vm(opts)
|
|
|
|
sys.exit(retcode)
|
|
|
|
print('matches!')
|
|
|
|
except ValueError:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print('Failed to load any JSON from \'{0}\''.format(salt.utils.stringutils.to_str(stdout).strip()))
|
2014-04-06 18:10:56 +00:00
|
|
|
|
2013-12-09 23:05:17 +00:00
|
|
|
# Run tests here
|
2015-12-16 21:48:51 +00:00
|
|
|
test_begin_downtime = random.randint(3, opts.splay)
|
|
|
|
time.sleep(test_begin_downtime)
|
2013-12-09 23:05:17 +00:00
|
|
|
cmd = (
|
2014-04-15 10:19:44 +00:00
|
|
|
'salt -t 1800 {target} state.sls {sls} pillar="{pillar}" --no-color'.format(
|
2013-09-06 11:14:27 +00:00
|
|
|
sls=opts.sls,
|
2014-04-13 10:05:18 +00:00
|
|
|
pillar=build_pillar_data(opts),
|
2014-04-15 10:19:44 +00:00
|
|
|
target=build_minion_target(opts, vm_name),
|
2013-09-06 11:14:27 +00:00
|
|
|
)
|
|
|
|
)
|
2013-08-17 05:06:51 +00:00
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-12-09 23:06:17 +00:00
|
|
|
proc = subprocess.Popen(
|
2013-08-17 05:06:51 +00:00
|
|
|
cmd,
|
|
|
|
shell=True,
|
2013-12-09 23:06:17 +00:00
|
|
|
stdout=subprocess.PIPE,
|
2014-04-30 07:39:49 +00:00
|
|
|
stderr=subprocess.PIPE,
|
2013-08-17 05:06:51 +00:00
|
|
|
)
|
2014-06-06 11:25:01 +00:00
|
|
|
stdout, stderr = proc.communicate()
|
2013-12-09 23:06:17 +00:00
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
outstr = salt.utils.stringutils.to_str(stdout)
|
2015-06-06 13:47:52 +00:00
|
|
|
if outstr:
|
|
|
|
print(outstr)
|
2014-06-06 11:25:01 +00:00
|
|
|
if stderr:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stderr))
|
2015-06-06 13:47:52 +00:00
|
|
|
sys.stdout.flush()
|
2013-12-09 23:06:17 +00:00
|
|
|
|
|
|
|
try:
|
2015-06-06 13:47:52 +00:00
|
|
|
match = re.search(r'Test Suite Exit Code: (?P<exitcode>[\d]+)', outstr)
|
2013-12-09 23:06:17 +00:00
|
|
|
retcode = int(match.group('exitcode'))
|
|
|
|
except AttributeError:
|
|
|
|
# No regex matching
|
|
|
|
retcode = 1
|
|
|
|
except ValueError:
|
|
|
|
# Not a number!?
|
|
|
|
retcode = 1
|
|
|
|
except TypeError:
|
|
|
|
# No output!?
|
|
|
|
retcode = 1
|
2015-06-06 13:47:52 +00:00
|
|
|
if outstr:
|
2013-12-09 23:06:17 +00:00
|
|
|
# Anything else, raise the exception
|
|
|
|
raise
|
2013-08-13 04:54:47 +00:00
|
|
|
|
2014-09-08 17:23:44 +00:00
|
|
|
if retcode == 0:
|
|
|
|
# Build packages
|
|
|
|
time.sleep(3)
|
|
|
|
cmd = (
|
|
|
|
'salt -t 1800 {target} state.sls buildpackage pillar="{pillar}" --no-color'.format(
|
|
|
|
pillar=build_pillar_data(opts),
|
|
|
|
target=build_minion_target(opts, vm_name),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print('Running CMD: {0}'.format(cmd))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
cmd,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
)
|
|
|
|
stdout, stderr = proc.communicate()
|
|
|
|
|
|
|
|
if stdout:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stdout))
|
2014-09-08 17:23:44 +00:00
|
|
|
if stderr:
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
print(salt.utils.stringutils.to_str(stderr))
|
2015-06-06 13:47:52 +00:00
|
|
|
sys.stdout.flush()
|
2014-09-08 17:23:44 +00:00
|
|
|
|
2014-12-02 23:45:57 +00:00
|
|
|
# Grab packages and log file (or just log file if build failed)
|
|
|
|
download_packages(opts)
|
2014-09-08 17:23:44 +00:00
|
|
|
|
2013-09-10 11:21:41 +00:00
|
|
|
if opts.download_remote_reports:
|
2013-09-10 11:05:59 +00:00
|
|
|
# Download unittest reports
|
2013-09-10 11:21:41 +00:00
|
|
|
download_unittest_reports(opts)
|
2013-09-10 11:05:59 +00:00
|
|
|
# Download coverage report
|
2014-12-08 18:07:04 +00:00
|
|
|
if opts.test_without_coverage is False:
|
2014-12-08 17:32:28 +00:00
|
|
|
download_coverage_report(opts)
|
2013-09-10 11:05:59 +00:00
|
|
|
|
2013-09-06 13:40:01 +00:00
|
|
|
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
|
2014-04-08 13:37:40 +00:00
|
|
|
delete_vm(opts)
|
2013-08-10 08:33:58 +00:00
|
|
|
return retcode
|
2013-08-10 07:23:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse():
|
|
|
|
'''
|
2013-08-11 05:50:47 +00:00
|
|
|
Parse the CLI options
|
2013-08-10 07:23:32 +00:00
|
|
|
'''
|
|
|
|
parser = optparse.OptionParser()
|
2014-04-17 18:19:40 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--vm-prefix',
|
|
|
|
default=os.environ.get('JENKINS_VM_NAME_PREFIX', 'ZJENKINS'),
|
|
|
|
help='The bootstrapped machine name prefix'
|
|
|
|
)
|
2013-09-09 19:43:27 +00:00
|
|
|
parser.add_option(
|
|
|
|
'-w', '--workspace',
|
|
|
|
default=os.path.abspath(
|
|
|
|
os.environ.get(
|
|
|
|
'WORKSPACE',
|
|
|
|
os.path.dirname(os.path.dirname(__file__))
|
|
|
|
)
|
|
|
|
),
|
|
|
|
help='Path the execution workspace'
|
|
|
|
)
|
2013-09-08 22:41:38 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--platform',
|
2013-09-06 13:40:01 +00:00
|
|
|
default=os.environ.get('JENKINS_SALTCLOUD_VM_PLATFORM', None),
|
2013-09-06 11:14:27 +00:00
|
|
|
help='The target platform, choose from:\ncent6\ncent5\nubuntu12.04')
|
2013-09-08 22:41:38 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--provider',
|
2013-09-06 13:40:01 +00:00
|
|
|
default=os.environ.get('JENKINS_SALTCLOUD_VM_PROVIDER', None),
|
2013-09-06 11:14:27 +00:00
|
|
|
help='The vm provider')
|
2014-01-02 21:43:44 +00:00
|
|
|
parser.add_option(
|
2014-04-13 11:07:56 +00:00
|
|
|
'--bootstrap-salt-url',
|
|
|
|
default=None,
|
|
|
|
help='The salt git repository url used to boostrap a minion')
|
|
|
|
parser.add_option(
|
|
|
|
'--bootstrap-salt-commit',
|
|
|
|
default=None,
|
|
|
|
help='The salt git commit used to boostrap a minion')
|
|
|
|
parser.add_option(
|
|
|
|
'--test-git-url',
|
2014-04-13 10:40:58 +00:00
|
|
|
default=None,
|
2014-04-13 11:07:56 +00:00
|
|
|
help='The testing git repository url')
|
2013-09-08 22:41:38 +00:00
|
|
|
parser.add_option(
|
2014-04-13 11:07:56 +00:00
|
|
|
'--test-git-commit',
|
2014-04-13 10:40:58 +00:00
|
|
|
default=None,
|
2014-04-13 11:07:56 +00:00
|
|
|
help='The testing git commit to track')
|
2014-06-16 10:19:14 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--test-transport',
|
|
|
|
default='zeromq',
|
2015-07-20 22:56:00 +00:00
|
|
|
choices=('zeromq', 'raet', 'tcp'),
|
|
|
|
help=('Select which transport to run the integration tests with, '
|
|
|
|
'zeromq, raet, or tcp. Default: %default')
|
|
|
|
)
|
2014-12-08 17:32:28 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--test-without-coverage',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Do not generate coverage reports'
|
|
|
|
)
|
2014-04-06 18:10:56 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--prep-sls',
|
|
|
|
default='git.salt',
|
|
|
|
help='The sls file to execute to prepare the system')
|
2014-04-14 10:49:51 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--prep-sls-2',
|
|
|
|
default=None,
|
|
|
|
help='An optional 2nd system preparation SLS')
|
2013-09-08 22:41:38 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--sls',
|
2014-04-07 22:00:53 +00:00
|
|
|
default='testrun-no-deps',
|
2014-04-06 18:10:56 +00:00
|
|
|
help='The final sls file to execute')
|
2013-09-08 22:41:38 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--pillar',
|
2014-04-13 10:05:18 +00:00
|
|
|
action='append',
|
|
|
|
nargs=2,
|
|
|
|
help='Pillar (key, value)s to pass to the sls file. '
|
|
|
|
'Example: \'--pillar pillar_key pillar_value\'')
|
2013-09-09 10:24:25 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--no-clean',
|
2013-09-06 11:14:27 +00:00
|
|
|
dest='clean',
|
|
|
|
default=True,
|
|
|
|
action='store_false',
|
|
|
|
help='Clean up the built vm')
|
|
|
|
parser.add_option(
|
|
|
|
'--echo-parseable-environment',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Print a parseable KEY=VAL output'
|
|
|
|
)
|
2014-01-10 18:29:01 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--pull-request',
|
|
|
|
type=int,
|
|
|
|
help='Include the PR info only'
|
|
|
|
)
|
2013-09-06 11:14:27 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--delete-vm',
|
2013-09-08 23:02:08 +00:00
|
|
|
default=None,
|
2013-09-06 13:40:01 +00:00
|
|
|
help='Delete a running VM'
|
2013-09-06 11:14:27 +00:00
|
|
|
)
|
2013-09-10 11:05:59 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--download-remote-reports',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Download remote reports when running remote \'testrun\' state'
|
|
|
|
)
|
2013-09-08 15:32:35 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--download-unittest-reports',
|
2013-09-08 23:02:08 +00:00
|
|
|
default=None,
|
2013-09-08 16:43:55 +00:00
|
|
|
help='Download the XML unittest results'
|
|
|
|
)
|
|
|
|
parser.add_option(
|
|
|
|
'--download-coverage-report',
|
2013-09-08 23:02:08 +00:00
|
|
|
default=None,
|
2013-09-08 16:43:55 +00:00
|
|
|
help='Download the XML coverage reports'
|
2013-09-08 15:32:35 +00:00
|
|
|
)
|
2014-04-13 14:52:57 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--remote-log-path',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
help='Provide additional log paths to download from remote minion'
|
|
|
|
)
|
2013-10-03 11:52:05 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--download-remote-logs',
|
|
|
|
default=None,
|
|
|
|
help='Download remote minion and runtests log files'
|
|
|
|
)
|
2014-04-15 10:19:44 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--grain-target',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
help='Match minions using compound matchers, the minion ID, plus the passed grain.'
|
|
|
|
)
|
2014-08-30 23:38:39 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--cloud-only',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run the cloud provider tests only.'
|
|
|
|
)
|
2014-09-08 17:23:44 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--build-packages',
|
|
|
|
default=True,
|
|
|
|
action='store_true',
|
|
|
|
help='Run buildpackage.py to create packages off of the git build.'
|
|
|
|
)
|
2014-09-11 22:05:09 +00:00
|
|
|
# These next three options are ignored if --build-packages is False
|
2014-09-08 17:23:44 +00:00
|
|
|
parser.add_option(
|
2014-09-11 22:05:09 +00:00
|
|
|
'--package-source-dir',
|
|
|
|
default='/testing',
|
|
|
|
help='Directory where the salt source code checkout is found '
|
|
|
|
'(default: %default)',
|
|
|
|
)
|
|
|
|
parser.add_option(
|
|
|
|
'--package-build-dir',
|
|
|
|
default='/tmp/salt-buildpackage',
|
|
|
|
help='Build root for automated package builds (default: %default)',
|
|
|
|
)
|
|
|
|
parser.add_option(
|
|
|
|
'--package-artifact-dir',
|
2014-09-08 17:23:44 +00:00
|
|
|
default='/tmp/salt-packages',
|
2014-09-11 22:05:09 +00:00
|
|
|
help='Location on the minion from which packages should be '
|
2014-09-08 17:23:44 +00:00
|
|
|
'retrieved (default: %default)',
|
|
|
|
)
|
2015-12-16 21:48:51 +00:00
|
|
|
parser.add_option(
|
|
|
|
'--splay',
|
|
|
|
default='10',
|
|
|
|
help='The number of seconds across which calls to provisioning components should be made'
|
|
|
|
)
|
2013-09-06 11:14:27 +00:00
|
|
|
|
2013-08-10 07:23:32 +00:00
|
|
|
options, args = parser.parse_args()
|
2013-09-06 11:14:27 +00:00
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if options.delete_vm is not None and not options.test_git_commit:
|
2013-09-09 19:45:57 +00:00
|
|
|
delete_vm(options)
|
2013-09-06 11:14:27 +00:00
|
|
|
parser.exit(0)
|
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if options.download_unittest_reports is not None and not options.test_git_commit:
|
2013-09-09 19:45:57 +00:00
|
|
|
download_unittest_reports(options)
|
2013-09-08 15:32:35 +00:00
|
|
|
parser.exit(0)
|
|
|
|
|
2014-12-08 17:32:28 +00:00
|
|
|
if options.test_without_coverage is False:
|
|
|
|
if options.download_coverage_report is not None and not options.test_git_commit:
|
|
|
|
download_coverage_report(options)
|
|
|
|
parser.exit(0)
|
2013-09-08 16:43:55 +00:00
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if options.download_remote_logs is not None and not options.test_git_commit:
|
2013-10-03 11:52:05 +00:00
|
|
|
download_remote_logs(options)
|
|
|
|
parser.exit(0)
|
|
|
|
|
2014-01-10 18:32:05 +00:00
|
|
|
if not options.platform and not options.pull_request:
|
2014-01-10 18:29:01 +00:00
|
|
|
parser.exit('--platform or --pull-request is required')
|
2013-09-06 11:14:27 +00:00
|
|
|
|
2014-01-10 18:32:05 +00:00
|
|
|
if not options.provider and not options.pull_request:
|
2014-01-10 18:29:01 +00:00
|
|
|
parser.exit('--provider or --pull-request is required')
|
2013-09-06 11:14:27 +00:00
|
|
|
|
|
|
|
if options.echo_parseable_environment:
|
2014-11-24 18:58:24 +00:00
|
|
|
echo_parseable_environment(options, parser)
|
2013-09-06 11:14:27 +00:00
|
|
|
parser.exit(0)
|
|
|
|
|
2014-04-13 11:07:56 +00:00
|
|
|
if not options.test_git_commit and not options.pull_request:
|
2014-01-10 18:29:01 +00:00
|
|
|
parser.exit('--commit or --pull-request is required')
|
2013-09-10 11:15:19 +00:00
|
|
|
|
2013-09-06 11:14:27 +00:00
|
|
|
return options
|
2013-08-10 07:23:32 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-09-06 11:14:27 +00:00
|
|
|
exit_code = run(parse())
|
2013-08-10 07:40:47 +00:00
|
|
|
print('Exit Code: {0}'.format(exit_code))
|
2013-08-10 07:23:32 +00:00
|
|
|
sys.exit(exit_code)
|