Handle exception when comparing of MACs fails in check_dhcp_resp
In case MAC's value is empty string comparing utils.is_same_mac fails with ValueError exception which may leads to responses from other nodes not being processed. We need to properly handle such situation. Change-Id: I8843f9eabd139222ac326fdc26a43f5702ba751b Related-Bug: #1569339 Related-Bug: #1569325
This commit is contained in:
parent
5e5e7284cf
commit
51690232de
|
@ -1103,14 +1103,34 @@ class NailgunReceiver(object):
|
|||
result[node['uid']] = node.get('data')
|
||||
|
||||
elif node['status'] == consts.NODE_STATUSES.ready:
|
||||
incorrect_input = False
|
||||
for row in node.get('data', []):
|
||||
if not net_utils.is_same_mac(row['mac'],
|
||||
master_network_mac):
|
||||
row['node_name'] = node_db.name
|
||||
message = message_template.format(**row)
|
||||
messages.append(message)
|
||||
try:
|
||||
if not net_utils.is_same_mac(row['mac'],
|
||||
master_network_mac):
|
||||
row['node_name'] = node_db.name
|
||||
message = message_template.format(**row)
|
||||
messages.append(message)
|
||||
# NOTE(aroma): for example when mac's value
|
||||
# is an empty string
|
||||
except ValueError as e:
|
||||
logger.warning(
|
||||
"Failed to compare mac address "
|
||||
"from response data (row = {0}) "
|
||||
"from node with id={1}. "
|
||||
"Original error:\n {2}"
|
||||
.format(row, node['uid'], six.text_type(e)))
|
||||
incorrect_input = True
|
||||
finally:
|
||||
result[node['uid']].append(row)
|
||||
|
||||
if incorrect_input:
|
||||
messages.append(
|
||||
"Something is wrong with response data from node with "
|
||||
"id={}. Check logs for details."
|
||||
.format(node['uid'])
|
||||
)
|
||||
|
||||
status = status if not messages else consts.TASK_STATUSES.error
|
||||
error_msg = '\n'.join(messages) if messages else error_msg
|
||||
logger.debug('Check dhcp message %s', error_msg)
|
||||
|
|
|
@ -833,6 +833,35 @@ class TestDhcpCheckTask(BaseReciverTestCase):
|
|||
)
|
||||
self.assertIn(err_msg, self.task.message)
|
||||
|
||||
def test_check_dhcp_resp_empty_mac(self):
|
||||
err_data = [{'mac': ''}]
|
||||
kwargs = {
|
||||
'task_uuid': self.task.uuid,
|
||||
'nodes': [
|
||||
{'uid': str(self.node1.id),
|
||||
'status': 'ready',
|
||||
'data': err_data},
|
||||
{'uid': str(self.node2.id),
|
||||
'status': 'ready',
|
||||
'data': [{'mac': settings.ADMIN_NETWORK['mac'],
|
||||
'server_id': '10.20.0.20',
|
||||
'yiaddr': '10.20.0.131',
|
||||
'iface': 'eth0'}]}
|
||||
]
|
||||
}
|
||||
|
||||
self.receiver.check_dhcp_resp(**kwargs)
|
||||
self.db.flush()
|
||||
self.db.refresh(self.task)
|
||||
self.assertEqual(self.task.status, consts.TASK_STATUSES.error)
|
||||
self.assertEqual(self.task.result[self.node1.uid], err_data)
|
||||
|
||||
err_msg = (
|
||||
"Something is wrong with response data from node with id={}"
|
||||
.format(self.node1.id)
|
||||
)
|
||||
self.assertIn(err_msg, self.task.message)
|
||||
|
||||
|
||||
class TestConsumer(BaseReciverTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue