Commit c2e8d493 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Catch errors and notify user in a helpful manner

Refs: #4429
parent 81c60832
......@@ -392,7 +392,26 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
personality=self['personality']) for i in range(size)]
if size == 1:
return [self.client.create_server(**servers[0])]
return self.client.async_run(self.client.create_server, servers)
try:
return self.client.async_run(self.client.create_server, servers)
except Exception as e:
if size == 1:
raise e
try:
requested_names = [s['name'] for s in servers]
spawned_servers = [dict(
name=s['name'],
id=s['id']) for s in self.client.list_servers() if (
s['name'] in requested_names)]
self.error('Failed to build %s servers' % size)
self.error('Found %s servers with a "%s" prefix:' % (
len(spawned_servers), prefix))
self._print(spawned_servers, out=self._err)
self.error('Check if any of these servers should be removed\n')
except Exception as ne:
self.error('Error (%s) while notifying about errors' % ne)
finally:
raise e
@errors.generic.all
@errors.cyclades.connection
......@@ -401,15 +420,17 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
def _run(self, name, flavor_id, image_id):
for r in self._create_cluster(
name, flavor_id, image_id, size=self['cluster_size'] or 1):
print 'HEY I GOT A', r
print 'MKEY?????????????????'
usernames = self._uuids2usernames([r['user_id'], r['tenant_id']])
if not r:
self.error('Create %s: server response was %s' % (name, r))
continue
usernames = self._uuids2usernames(
[r['user_id'], r['tenant_id']])
r['user_id'] += ' (%s)' % usernames[r['user_id']]
r['tenant_id'] += ' (%s)' % usernames[r['tenant_id']]
self._print(r, self.print_dict)
if self['wait']:
self._wait(r['id'], r['status'])
self.error('')
self.writeln('')
def main(self, name, flavor_id, image_id):
super(self.__class__, self)._run()
......
......@@ -391,21 +391,16 @@ class Client(Logged):
if thread.isAlive():
unfinished[key] = thread
elif thread.exception:
print 'HERE IS AN EXCEPTION MK?'
raise thread.exception
else:
results[key] = thread.value
print 'NO EXCEPTION', thread.value
flying = unfinished
sendlog.info('- - - wait for threads to finish')
for key, thread in flying.items():
if thread.isAlive():
thread.join()
elif thread.exception:
print 'HERE IS AN EXCEPTION MK-2?'
if thread.exception:
raise thread.exception
results[key] = thread.value
print 'NO EXCEPTION-2', thread.value
return results.values()
def _raise_for_status(self, r):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment