Merge "Allow str for ip_version param in create_subnet"
This commit is contained in:
commit
28f6e66621
@ -5271,6 +5271,13 @@ class OpenStackCloud(object):
|
||||
raise OpenStackCloudException(
|
||||
'arg:disable_gateway_ip is not allowed with arg:gateway_ip')
|
||||
|
||||
# Be friendly on ip_version and allow strings
|
||||
if isinstance(ip_version, six.string_types):
|
||||
try:
|
||||
ip_version = int(ip_version)
|
||||
except ValueError:
|
||||
raise OpenStackCloudException('ip_version must be an integer')
|
||||
|
||||
# The body of the neutron message for the subnet we wish to create.
|
||||
# This includes attributes that are required or have defaults.
|
||||
subnet = {
|
||||
|
@ -371,6 +371,29 @@ class TestShade(base.TestCase):
|
||||
host_routes=routes)
|
||||
self.assertTrue(mock_client.create_subnet.called)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'search_networks')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_create_subnet_string_ip_version(self, mock_client, mock_search):
|
||||
'''Allow ip_version as a string'''
|
||||
net1 = dict(id='123', name='donald')
|
||||
mock_search.return_value = [net1]
|
||||
self.cloud.create_subnet('donald', '192.168.199.0/24', ip_version='4')
|
||||
self.assertTrue(mock_client.create_subnet.called)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'search_networks')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_create_subnet_bad_ip_version(self, mock_client, mock_search):
|
||||
'''String ip_versions must be convertable to int'''
|
||||
net1 = dict(id='123', name='donald')
|
||||
mock_search.return_value = [net1]
|
||||
|
||||
with testtools.ExpectedException(
|
||||
exc.OpenStackCloudException,
|
||||
"ip_version must be an integer"
|
||||
):
|
||||
self.cloud.create_subnet('donald', '192.168.199.0/24',
|
||||
ip_version='4x')
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'search_networks')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_create_subnet_without_gateway_ip(self, mock_client, mock_search):
|
||||
|
Loading…
x
Reference in New Issue
Block a user