mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #9088 from makinacorpus/last-buildout-errors
fix last zcbuildout pylint errors
This commit is contained in:
commit
8631715671
@ -70,8 +70,7 @@ def _salt_callback(func):
|
||||
LOG.clear()
|
||||
|
||||
def _call_callback(*a, **kw):
|
||||
ret, out = None, ''
|
||||
status = BASE_STATUS.copy()
|
||||
st = BASE_STATUS.copy()
|
||||
directory = kw.get('directory', '.')
|
||||
onlyif = kw.get('onlyif', None)
|
||||
unless = kw.get('unless', None)
|
||||
@ -79,21 +78,28 @@ def _salt_callback(func):
|
||||
env = kw.get('env', ())
|
||||
try:
|
||||
# may rise _ResultTransmission
|
||||
_check_onlyif_unless(onlyif,
|
||||
unless,
|
||||
directory=directory,
|
||||
runas=runas,
|
||||
env=env)
|
||||
comment, st, out = '', True, None
|
||||
if not status['status']:
|
||||
# may rise _ResultTransmission
|
||||
status = _check_onlyif_unless(onlyif,
|
||||
unless,
|
||||
directory=directory,
|
||||
runas=runas,
|
||||
env=env)
|
||||
# if onlyif/unless returns, we are done
|
||||
if status is None:
|
||||
status = BASE_STATUS.copy()
|
||||
comment, st = '', True
|
||||
out = func(*a, **kw)
|
||||
if isinstance(out, dict):
|
||||
comment = out.get('comment', '')
|
||||
out = out.get('out', None)
|
||||
status = _set_status(status, status=st, comment=comment, out=out)
|
||||
except _ResultTransmission, ex:
|
||||
status = ex.args[0]
|
||||
# we may have already final statuses not to be touched
|
||||
# merged_statuses flag is there to check that !
|
||||
if not isinstance(out, dict):
|
||||
status = _valid(status, out=out)
|
||||
else:
|
||||
if out.get('merged_statuses', False):
|
||||
status = out
|
||||
else:
|
||||
status = _set_status(status,
|
||||
status=out.get('status', True),
|
||||
comment=out.get('comment', ''),
|
||||
out=out.get('out', out))
|
||||
except Exception:
|
||||
trace = traceback.format_exc(None)
|
||||
LOG.error(trace)
|
||||
@ -246,18 +252,10 @@ def _Popen(command,
|
||||
return ret
|
||||
|
||||
|
||||
class _ResultTransmission(Exception):
|
||||
'''General Buildout Error.'''
|
||||
|
||||
|
||||
class _BuildoutError(CommandExecutionError):
|
||||
'''General Buildout Error.'''
|
||||
|
||||
|
||||
class _MrDeveloperError(_BuildoutError):
|
||||
'''Arrives when mr.developer fails'''
|
||||
|
||||
|
||||
def _has_old_distribute(python=sys.executable, runas=None, env=()):
|
||||
old_distribute = False
|
||||
try:
|
||||
@ -265,7 +263,7 @@ def _has_old_distribute(python=sys.executable, runas=None, env=()):
|
||||
'-c',
|
||||
'\'import pkg_resources;'
|
||||
'print pkg_resources.'
|
||||
'get_distribution(\'distribute\').location\'']
|
||||
'get_distribution(\"distribute\").location\'']
|
||||
#LOG.debug('Run %s' % ' '.join(cmd))
|
||||
ret = _Popen(cmd, runas=runas, env=env, output=True)
|
||||
if 'distribute-0.6' in ret:
|
||||
@ -280,9 +278,9 @@ def _has_setuptools7(python=sys.executable, runas=None, env=()):
|
||||
try:
|
||||
cmd = [python,
|
||||
'-c',
|
||||
"'import pkg_resources;"
|
||||
'\'import pkg_resources;'
|
||||
'print not pkg_resources.'
|
||||
"get_distribution('setuptools').version.startswith('0.6')'"]
|
||||
'get_distribution("setuptools").version.startswith("0.6")\'']
|
||||
#LOG.debug('Run %s' % ' '.join(cmd))
|
||||
ret = _Popen(cmd, runas=runas, env=env, output=True)
|
||||
if 'true' in ret.lower():
|
||||
@ -793,6 +791,7 @@ def run_buildout(directory='.',
|
||||
def _merge_statuses(statuses):
|
||||
status = BASE_STATUS.copy()
|
||||
status['status'] = None
|
||||
status['merged_statuses'] = True
|
||||
status['out'] = []
|
||||
for st in statuses:
|
||||
if status['status'] is not False:
|
||||
@ -929,10 +928,11 @@ def buildout(directory='.',
|
||||
verbose=verbose,
|
||||
debug=debug)
|
||||
# signal the decorator or our return
|
||||
raise _ResultTransmission(_merge_statuses([boot_ret, buildout_ret]))
|
||||
return _merge_statuses([boot_ret, buildout_ret])
|
||||
|
||||
|
||||
def _check_onlyif_unless(onlyif, unless, directory, runas=None, env=()):
|
||||
ret = None
|
||||
status = BASE_STATUS.copy()
|
||||
if os.path.exists(directory):
|
||||
directory = os.path.abspath(directory)
|
||||
@ -953,6 +953,7 @@ def _check_onlyif_unless(onlyif, unless, directory, runas=None, env=()):
|
||||
if retcode(unless, cwd=directory, runas=runas, env=env) == 0:
|
||||
_valid(status, 'unless execution succeeded')
|
||||
if status['status']:
|
||||
raise _ResultTransmission(status)
|
||||
ret = status
|
||||
return ret
|
||||
|
||||
# vim:set et sts=4 ts=4 tw=80:
|
||||
|
@ -42,6 +42,13 @@ boot_init = {
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def download_to(url, dest):
|
||||
with salt.utils.fopen(dest, 'w') as fic:
|
||||
fic.write(
|
||||
urllib2.urlopen(url, timeout=10).read()
|
||||
)
|
||||
|
||||
|
||||
class Base(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@ -52,14 +59,10 @@ class Base(TestCase):
|
||||
dest = os.path.join(
|
||||
cls.rdir, '{0}_bootstrap.py'.format(idx)
|
||||
)
|
||||
with salt.utils.fopen(dest, 'w') as fic:
|
||||
try:
|
||||
req = urllib2.Request(url)
|
||||
fic.write(
|
||||
urllib2.urlopen(url, timeout=10).read()
|
||||
)
|
||||
except urllib2.URLError:
|
||||
log.debug('Failed to download {0}'.format(url))
|
||||
try:
|
||||
download_to(url, dest)
|
||||
except urllib2.URLError:
|
||||
log.debug('Failed to download {0}'.format(url))
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@ -107,10 +110,8 @@ class BuildoutTestCase(Base):
|
||||
getattr(buildout.LOG, i)('{0}bar'.format(i[0]))
|
||||
return 'foo'
|
||||
|
||||
@buildout._salt_callback
|
||||
def callback2(a, b=1):
|
||||
raise Exception('foo')
|
||||
return 1 # make pylint happy
|
||||
|
||||
ret1 = callback1(1, b=3)
|
||||
self.assertEqual(ret1['status'], True)
|
||||
@ -138,7 +139,7 @@ class BuildoutTestCase(Base):
|
||||
)
|
||||
self.assertTrue('by level' in ret1['outlog_by_level'])
|
||||
self.assertEqual(ret1['out'], 'foo')
|
||||
ret2 = callback2(2, b=6)
|
||||
ret2 = buildout._salt_callback(callback2)(2, b=6)
|
||||
self.assertEqual(ret2['status'], False)
|
||||
self.assertTrue(
|
||||
ret2['logs_by_level']['error'][0].startswith('Traceback'))
|
||||
@ -296,16 +297,24 @@ class BuildoutOnlineTestCase(Base):
|
||||
'{0}/bin/easy_install -U distribute;'
|
||||
).format(cls.ppy_st))
|
||||
# creating a distribute based install
|
||||
ret20 = buildout._Popen((
|
||||
'virtualenv --no-site-packages --no-setuptools --no-pip {0}'
|
||||
''.format(cls.ppy_dis)))
|
||||
download_to(' https://pypi.python.org/packages/source'
|
||||
'/d/distribute/distribute-0.6.43.tar.gz',
|
||||
os.path.join(cls.ppy_dis, 'distribute-0.6.43.tar.gz'))
|
||||
ret2 = buildout._Popen((
|
||||
'virtualenv --no-site-packages {0};'
|
||||
'{0}/bin/easy_install -U setuptools==0.6c9;'
|
||||
'{0}/bin/easy_install -U distribute==0.6.43;'
|
||||
'cd {0} &&'
|
||||
' tar xzvf distribute-0.6.43.tar.gz && cd distribute-0.6.43 &&'
|
||||
' {0}/bin/python setup.py install'
|
||||
).format(cls.ppy_dis))
|
||||
# creating a blank based install
|
||||
ret3 = buildout._Popen((
|
||||
'virtualenv --no-site-packages --no-setuptools --no-pip {0}'
|
||||
''.format(cls.ppy_blank)))
|
||||
assert ret1['retcode'] == 0
|
||||
assert ret20['retcode'] == 0
|
||||
assert ret2['retcode'] == 0
|
||||
assert ret2['retcode'] == 0
|
||||
assert ret3['retcode'] == 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user