Merge pull request #38 from Mirantis/handle_puppet
Use detailed error codes to handle puppet errors
This commit is contained in:
commit
4eb33c9f61
@ -7,6 +7,7 @@ from solar.core import resource
|
|||||||
from solar.core import signals
|
from solar.core import signals
|
||||||
from solar.core import validation
|
from solar.core import validation
|
||||||
from solar.core.resource import virtual_resource as vr
|
from solar.core.resource import virtual_resource as vr
|
||||||
|
from solar import errors
|
||||||
|
|
||||||
from solar.interfaces.db import get_db
|
from solar.interfaces.db import get_db
|
||||||
|
|
||||||
@ -350,7 +351,10 @@ def undeploy():
|
|||||||
resources = {r.name: r for r in resources}
|
resources = {r.name: r for r in resources}
|
||||||
|
|
||||||
for name in to_remove:
|
for name in to_remove:
|
||||||
|
try:
|
||||||
actions.resource_action(resources[name], 'remove')
|
actions.resource_action(resources[name], 'remove')
|
||||||
|
except errors.SolarError as e:
|
||||||
|
print 'WARNING: %s' % str(e)
|
||||||
|
|
||||||
#actions.resource_action(resources['nova_keystone_service_endpoint'], 'remove' )
|
#actions.resource_action(resources['nova_keystone_service_endpoint'], 'remove' )
|
||||||
# actions.resource_action(resources['nova_network_puppet'], 'remove' )
|
# actions.resource_action(resources['nova_network_puppet'], 'remove' )
|
||||||
|
@ -9,20 +9,7 @@ import os
|
|||||||
from solar.core.log import log
|
from solar.core.log import log
|
||||||
from solar.core.handlers.base import TempFileHandler
|
from solar.core.handlers.base import TempFileHandler
|
||||||
from solar.core.provider import GitProvider
|
from solar.core.provider import GitProvider
|
||||||
|
from solar import errors
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# puppet wont always return 0 on error, example:
|
|
||||||
# http://unix.stackexchange.com/questions/165333/how-to-get-non-zero-exit-code-from-puppet-when-configuration-cannot-be-applied
|
|
||||||
|
|
||||||
# in fuel there is special handler based on puppet summary, but i think we can also use --detailed-exitcode
|
|
||||||
# https://docs.puppetlabs.com/references/3.6.2/man/agent.html
|
|
||||||
# --detailed-exitcodes
|
|
||||||
# Provide transaction information via exit codes. If this is enabled, an exit
|
|
||||||
# code of '2' means there were changes, an exit code of '4' means there were
|
|
||||||
# failures during the transaction, and an exit code of '6' means there were
|
|
||||||
# both changes and failures.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceSSHMixin(object):
|
class ResourceSSHMixin(object):
|
||||||
@ -48,6 +35,10 @@ class ResourceSSHMixin(object):
|
|||||||
fabric_api.shell_env(**kwargs['env'])
|
fabric_api.shell_env(**kwargs['env'])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if 'warn_only' in kwargs:
|
||||||
|
managers.append(
|
||||||
|
fabric_api.warn_only())
|
||||||
|
|
||||||
with nested(*managers):
|
with nested(*managers):
|
||||||
return executor(' '.join(args))
|
return executor(' '.join(args))
|
||||||
|
|
||||||
@ -161,14 +152,21 @@ class Puppet(ResourceSSHMixin, TempFileHandler):
|
|||||||
|
|
||||||
self._scp_command(resource, action_file, '/tmp/action.pp')
|
self._scp_command(resource, action_file, '/tmp/action.pp')
|
||||||
|
|
||||||
self._ssh_command(
|
cmd = self._ssh_command(
|
||||||
resource,
|
resource,
|
||||||
'puppet', 'apply', '-vd', '/tmp/action.pp',
|
'puppet', 'apply', '-vd', '/tmp/action.pp', '--detailed-exitcodes',
|
||||||
env={
|
env={
|
||||||
'FACTER_resource_name': resource.name,
|
'FACTER_resource_name': resource.name,
|
||||||
},
|
},
|
||||||
use_sudo=True
|
use_sudo=True,
|
||||||
|
warn_only=True,
|
||||||
)
|
)
|
||||||
|
# 0 - no changes, 2 - successfull changes
|
||||||
|
if cmd.return_code not in [0, 2]:
|
||||||
|
raise errors.SolarError(
|
||||||
|
'Puppet for {} failed with {}'.format(
|
||||||
|
resource.name, cmd.return_code))
|
||||||
|
return cmd
|
||||||
|
|
||||||
def clone_manifests(self, resource):
|
def clone_manifests(self, resource):
|
||||||
git = resource.args['git'].value
|
git = resource.args['git'].value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user