Raise sync error in Executor
This commit is contained in:
parent
8ad488a866
commit
a73746a621
@ -39,8 +39,7 @@ class AnsibleTemplate(TempFileHandler):
|
|||||||
self._copy_templates_and_scripts(resource, action_name)
|
self._copy_templates_and_scripts(resource, action_name)
|
||||||
self.transport_sync.copy(resource, self.dst, '/tmp')
|
self.transport_sync.copy(resource, self.dst, '/tmp')
|
||||||
self.transport_sync.copy(resource, '/vagrant/library', '/tmp')
|
self.transport_sync.copy(resource, '/vagrant/library', '/tmp')
|
||||||
sync_results = self.transport_sync.sync_all()
|
self.transport_sync.sync_all()
|
||||||
self.verify_sync_results(sync_results)
|
|
||||||
|
|
||||||
# remote paths are not nested inside solar_local
|
# remote paths are not nested inside solar_local
|
||||||
remote_playbook_file = playbook_file.replace(
|
remote_playbook_file = playbook_file.replace(
|
||||||
|
@ -43,15 +43,6 @@ class BaseHandler(object):
|
|||||||
self.transport_sync.bind_with(self.transport_run)
|
self.transport_sync.bind_with(self.transport_run)
|
||||||
self.transport_run.bind_with(self.transport_sync)
|
self.transport_run.bind_with(self.transport_sync)
|
||||||
|
|
||||||
def verify_sync_results(self, results):
|
|
||||||
for result in results:
|
|
||||||
if isinstance(result, tuple) and len(result) == 3:
|
|
||||||
# TODO Include file information in result
|
|
||||||
rc, out, err = result
|
|
||||||
log.debug('RC %s OUT %s ERR %s', rc, out, err)
|
|
||||||
if rc:
|
|
||||||
raise errors.SolarError(err)
|
|
||||||
|
|
||||||
def verify_run_result(self, cmd, result):
|
def verify_run_result(self, cmd, result):
|
||||||
rc, out, err = result
|
rc, out, err = result
|
||||||
log.debug('CMD %r RC %s OUT %s ERR %s', cmd, rc, out, err)
|
log.debug('CMD %r RC %s OUT %s ERR %s', cmd, rc, out, err)
|
||||||
|
@ -27,5 +27,4 @@ class NaiveSync(BaseHandler):
|
|||||||
# to understand where src comes from
|
# to understand where src comes from
|
||||||
for item in args['sources']:
|
for item in args['sources']:
|
||||||
self.transport_sync.copy(resource, item['src'], item['dst'])
|
self.transport_sync.copy(resource, item['src'], item['dst'])
|
||||||
results = self.transport_sync.sync_all()
|
self.transport_sync.sync_all()
|
||||||
self.verify_sync_results(results)
|
|
||||||
|
@ -37,8 +37,7 @@ class Puppet(TempFileHandler):
|
|||||||
|
|
||||||
self.prepare_templates_and_scripts(resource, action_file, '')
|
self.prepare_templates_and_scripts(resource, action_file, '')
|
||||||
self.transport_sync.copy(resource, action_file, action_file_name)
|
self.transport_sync.copy(resource, action_file, action_file_name)
|
||||||
sync_results = self.transport_sync.sync_all()
|
self.transport_sync.sync_all()
|
||||||
self.verify_sync_results(sync_results)
|
|
||||||
|
|
||||||
cmd_args = ['puppet', 'apply', '-vd',
|
cmd_args = ['puppet', 'apply', '-vd',
|
||||||
action_file_name,
|
action_file_name,
|
||||||
|
@ -33,9 +33,7 @@ class Shell(TempFileHandler):
|
|||||||
self._copy_templates_and_scripts(resource, action_name)
|
self._copy_templates_and_scripts(resource, action_name)
|
||||||
|
|
||||||
self.transport_sync.copy(resource, self.dst, '/tmp')
|
self.transport_sync.copy(resource, self.dst, '/tmp')
|
||||||
sync_results = self.transport_sync.sync_all()
|
self.transport_sync.sync_all()
|
||||||
# TODO Include file information in result
|
|
||||||
self.verify_sync_results(sync_results)
|
|
||||||
|
|
||||||
rst = self.transport_run.run(
|
rst = self.transport_run.run(
|
||||||
resource,
|
resource,
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from solar.core.log import log
|
||||||
|
from solar import errors
|
||||||
|
|
||||||
|
|
||||||
class Executor(object):
|
class Executor(object):
|
||||||
|
|
||||||
@ -38,7 +41,13 @@ class Executor(object):
|
|||||||
|
|
||||||
def run(self, transport):
|
def run(self, transport):
|
||||||
if self.valid:
|
if self.valid:
|
||||||
return self._executor(transport)
|
result = self._executor(transport)
|
||||||
|
if isinstance(result, tuple) and len(result) == 3:
|
||||||
|
# TODO Include file information in result
|
||||||
|
rc, out, err = result
|
||||||
|
log.debug('RC %s OUT %s ERR %s', rc, out, err)
|
||||||
|
if rc:
|
||||||
|
raise errors.SolarError(err)
|
||||||
|
|
||||||
|
|
||||||
class SolarRunResultWrp(object):
|
class SolarRunResultWrp(object):
|
||||||
@ -131,10 +140,8 @@ class SyncTransport(SolarTransport):
|
|||||||
self.preprocess(executor)
|
self.preprocess(executor)
|
||||||
|
|
||||||
def run_all(self):
|
def run_all(self):
|
||||||
rst = []
|
|
||||||
for executor in self.executors:
|
for executor in self.executors:
|
||||||
rst.append(executor.run(self))
|
executor.run(self)
|
||||||
return rst
|
|
||||||
|
|
||||||
def sync_all(self):
|
def sync_all(self):
|
||||||
"""Syncs all
|
"""Syncs all
|
||||||
@ -144,9 +151,8 @@ class SyncTransport(SolarTransport):
|
|||||||
Could be someday changed to parallel thing.
|
Could be someday changed to parallel thing.
|
||||||
"""
|
"""
|
||||||
self.preprocess_all()
|
self.preprocess_all()
|
||||||
rst = self.run_all()
|
self.run_all()
|
||||||
self.executors = [] # clear after all
|
self.executors = [] # clear after all
|
||||||
return rst
|
|
||||||
|
|
||||||
|
|
||||||
class RunTransport(SolarTransport):
|
class RunTransport(SolarTransport):
|
||||||
|
@ -60,12 +60,8 @@ class OnAll(object):
|
|||||||
|
|
||||||
def __get__(self, obj, objtype):
|
def __get__(self, obj, objtype):
|
||||||
def _inner(*args, **kwargs):
|
def _inner(*args, **kwargs):
|
||||||
results = []
|
|
||||||
for transport in obj._used_transports:
|
for transport in obj._used_transports:
|
||||||
rst = getattr(transport, self._target)(*args, **kwargs)
|
getattr(transport, self._target)(*args, **kwargs)
|
||||||
if rst:
|
|
||||||
results.extend(rst)
|
|
||||||
return results
|
|
||||||
return _inner
|
return _inner
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user