Fix mgm api server edge case
Fixes the small case where the API server has given a node count, the pool manager server spins up a node and then the pool manager cannot give the details to the API server. In this scenario the new node is deleted if possible. Fixes bug #1076446 Change-Id: If1f3ff13046fcee78dd865b27dd269cf9937cb48
This commit is contained in:
parent
8f1fa33a97
commit
2cef1f6b84
@ -120,11 +120,21 @@ class Server(object):
|
|||||||
if not address['addr'].startswith('10.'):
|
if not address['addr'].startswith('10.'):
|
||||||
break
|
break
|
||||||
body['address'] = address['addr']
|
body['address'] = address['addr']
|
||||||
self.logger.info('Adding server {name} on {ip}'
|
self.logger.info('Adding node {name} on {ip}'
|
||||||
.format(name=body['name'], ip=body['address']))
|
.format(name=body['name'], ip=body['address']))
|
||||||
# TODO: store failed uploads to API server to retry
|
# TODO: store failed uploads to API server to retry
|
||||||
status, response = api.add_node(body)
|
status, response = api.add_node(body)
|
||||||
if not status:
|
if not status:
|
||||||
|
self.logger.error(
|
||||||
|
'Could not upload node {name} to API server, deleting'
|
||||||
|
.format(name=data['name'])
|
||||||
|
)
|
||||||
|
status, response = nova.delete(data['id'])
|
||||||
|
if not status:
|
||||||
|
self.logger.error(response)
|
||||||
|
else:
|
||||||
|
self.logger.info('Delete succeeded')
|
||||||
|
self.logger.warning('Aborting node building')
|
||||||
return
|
return
|
||||||
count = count - 1
|
count = count - 1
|
||||||
|
|
||||||
|
@ -71,12 +71,16 @@ class Node(object):
|
|||||||
try:
|
try:
|
||||||
resp = self._delete(node_id)
|
resp = self._delete(node_id)
|
||||||
except:
|
except:
|
||||||
return False
|
return False, 'Error deleting node {nid} exception {exc}'.format(
|
||||||
|
nid=node_id, exc=sys.exc_info()[0]
|
||||||
|
)
|
||||||
|
|
||||||
if resp['status'] != '204':
|
if resp['status'] != '204':
|
||||||
return False
|
return False, 'Error deleting node {nid} status {stat}'.format(
|
||||||
|
node=node_id, stat=status['status']
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True, ''
|
||||||
|
|
||||||
def _create(self, node_id):
|
def _create(self, node_id):
|
||||||
""" create a nova node """
|
""" create a nova node """
|
||||||
|
@ -56,11 +56,11 @@ class TestLBaaSMgmNova(unittest.TestCase):
|
|||||||
def testDeleteNodeFail(self):
|
def testDeleteNodeFail(self):
|
||||||
with mock.patch.object(httplib2.Http, "request", mock_bad_request):
|
with mock.patch.object(httplib2.Http, "request", mock_bad_request):
|
||||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||||
resp = self.api.delete('1234')
|
resp, data = self.api.delete('1234')
|
||||||
self.assertFalse(resp)
|
self.assertFalse(resp)
|
||||||
|
|
||||||
def testDeleteNodeSucceed(self):
|
def testDeleteNodeSucceed(self):
|
||||||
with mock.patch.object(httplib2.Http, "request", mock_del_request):
|
with mock.patch.object(httplib2.Http, "request", mock_del_request):
|
||||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||||
resp = self.api.delete('1234')
|
resp, data = self.api.delete('1234')
|
||||||
self.assertTrue(resp)
|
self.assertTrue(resp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user