Fix create_server() with a named network
If 'network' was supplied to create_server() along with an empty 'nics' list, we would never attempt to find the network. The os_server Ansible module uses the API this way. This treats an empty list the same as if the 'nics' parameter were never supplied. Change-Id: Idc844fab2c4c08f158c892104d065e5554ed90f3
This commit is contained in:
parent
a7fe2520ae
commit
f236869b77
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- The create_server() API call would not use the supplied 'network'
|
||||||
|
parameter if the 'nics' parameter was also supplied, even though it would
|
||||||
|
be an empty list. It now uses 'network' if 'nics' is not supplied or if
|
||||||
|
it is an empty list.
|
@ -3350,7 +3350,7 @@ class OpenStackCloud(object):
|
|||||||
raise OpenStackCloudException(
|
raise OpenStackCloudException(
|
||||||
'nics parameter to create_server takes a list of dicts.'
|
'nics parameter to create_server takes a list of dicts.'
|
||||||
' Got: {nics}'.format(nics=kwargs['nics']))
|
' Got: {nics}'.format(nics=kwargs['nics']))
|
||||||
if network and 'nics' not in kwargs:
|
if network and ('nics' not in kwargs or not kwargs['nics']):
|
||||||
network_obj = self.get_network(name_or_id=network)
|
network_obj = self.get_network(name_or_id=network)
|
||||||
if not network_obj:
|
if not network_obj:
|
||||||
raise OpenStackCloudException(
|
raise OpenStackCloudException(
|
||||||
|
@ -250,3 +250,28 @@ class TestCreateServer(base.TestCase):
|
|||||||
OpenStackCloudException, self.client.create_server,
|
OpenStackCloudException, self.client.create_server,
|
||||||
'server-name', 'image-id', 'flavor-id',
|
'server-name', 'image-id', 'flavor-id',
|
||||||
wait=True)
|
wait=True)
|
||||||
|
|
||||||
|
@patch('shade.OpenStackCloud.nova_client')
|
||||||
|
@patch('shade.OpenStackCloud.get_network')
|
||||||
|
def test_create_server_network_with_no_nics(self, mock_get_network,
|
||||||
|
mock_nova):
|
||||||
|
"""
|
||||||
|
Verify that if 'network' is supplied, and 'nics' is not, that we
|
||||||
|
attempt to get the network for the server.
|
||||||
|
"""
|
||||||
|
self.client.create_server('server-name', 'image-id', 'flavor-id',
|
||||||
|
network='network-name')
|
||||||
|
mock_get_network.assert_called_once_with(name_or_id='network-name')
|
||||||
|
|
||||||
|
@patch('shade.OpenStackCloud.nova_client')
|
||||||
|
@patch('shade.OpenStackCloud.get_network')
|
||||||
|
def test_create_server_network_with_empty_nics(self,
|
||||||
|
mock_get_network,
|
||||||
|
mock_nova):
|
||||||
|
"""
|
||||||
|
Verify that if 'network' is supplied, along with an empty 'nics' list,
|
||||||
|
it's treated the same as if 'nics' were not included.
|
||||||
|
"""
|
||||||
|
self.client.create_server('server-name', 'image-id', 'flavor-id',
|
||||||
|
network='network-name', nics=[])
|
||||||
|
mock_get_network.assert_called_once_with(name_or_id='network-name')
|
||||||
|
Loading…
Reference in New Issue
Block a user