Fix exception if no "networks" in server creation

1.What is the problem:
If 'networks' is not carried in the request to Nova API-GW,
then in current implementation, server_body['networks'] will
not be initialized before it is used in the "nics = [ {'port-id':
_port['port']} for _port in server_body['networks']]" clause,
then exception will happen, and return error to the API caller.
In fact, it should works, no exception should happen.

2.What's need to be fixed:
Move the server_body['networks'] initialization outside
the "if  'networks' in kw['server']" clause will ensure
server_body['networks'] being initialized before it is used
later, and eliminate the exception happened in "nics = ...
for _port in server_body['networks']]" clause.

3.What is the purpose of this patch set:
Eliminate the unusual exception happened in server creation

Change-Id: I50a6ac8e6bba78233e063bcfc24c0a1d4663e9f6
Signed-off-by: joehuang <joehuang@huawei.com>
This commit is contained in:
joehuang 2016-08-12 02:54:02 -04:00
parent 0d0ca11e95
commit 1e495007ea
1 changed files with 1 additions and 1 deletions

View File

@ -166,8 +166,8 @@ class ServerController(rest.RestController):
t_sg_ids, b_sg_ids, is_news = self._handle_security_group(
context, pod, top_sg_map, security_groups)
server_body['networks'] = []
if 'networks' in kw['server']:
server_body['networks'] = []
for net_info in kw['server']['networks']:
if 'uuid' in net_info:
network = top_client.get_networks(context,