Cloth crash when name lookup failed when celery is triggered by eventlet

I have a celery task to run a sudo command on a remote machine using a tag:

@app.task(soft_time_limit=600)
def run_puppet_agent(hostname):
    try:
        fabric_client = Fabric(hostname)
        result = fabric_client.run_command('puppet agent -t', True, True)
        if result.return_code == 0 or result.return_code == 2:
                return True, 'Puppet agent run successfully'
        else:
            raise Exception('Command %s run failed with a non zero or non-2 error code, '
                            '0 and 2 are status codes for successful puppet runs, returned     code %s'
                            % ('sudo puppet agent -t', result.return_code))
    except SoftTimeLimitExceeded:
        raise Exception('Puppet agent run took more than 600 seconds')
    except Exception as e:
        #run_puppet_agent.retry(args=[hostname], countdown=20)
        LOG.info('')
        raise Exception('Puppet agent failed with error message %s' % e.message)

      

if I manage celery like:

celery -A phantom.celery.manage worker --loglevel=info

      

it works great !! But when I run workers with eventlet like:

celery -A phantom.celery.manage worker --loglevel=info -P eventlet -c 15

      

This is terribly bad and gives me this exception:

[WARNING/MainProcess] File     "/Users/uruddarraju/Phantom/phantom/tasks/fabric_tasks.py", line 19, in run_puppet_agent
[WARNING/MainProcess] result = fabric_client.run_command('puppet agent -t', True, True)
[WARNING/MainProcess] File "/Users/uruddarraju/Phantom/phantom/util/fabric/fabric_util.py", line 43, in run_command
[WARNING/MainProcess] return sudo(command, quiet=False)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 639, in host_prompting_wrapper
[WARNING/MainProcess] return func(*args, **kwargs)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/operations.py", line 1095, in sudo
[stderr=stderr, timeout=timeout, shell_escape=shell_escape,
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/operations.py", line 909, in _run_command
[WARNING/MainProcess] channel=default_channel(), command=wrapped_command, pty=pty,
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/state.py", line 390, in default_channel
[WARNING/MainProcess] chan = _open_session()
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/state.py", line 382, in _open_session
[WARNING/MainProcess] return connections[env.host_string].get_transport().open_session()
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 151, in __getitem__
[WARNING/MainProcess] self.connect(key)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 143, in connect
[WARNING/MainProcess] self[key] = connect(user, host, port, cache=self)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 533, in connect
[WARNING/MainProcess] raise NetworkError('Name lookup failed for %s' % host, e)
[WARNING/MainProcess] NetworkError: Name lookup failed for <hostname>

      

WARNING / Main Process] No

FYI: I have other tasks that have different HTTP API calls and hence although eventlet would have helped me not to work in this case

+3


source to share


1 answer


I used gevent instead to work ... solved my problem !! Thanks for the help though



0


source







All Articles