Support to reset dnsname_servers and host_routes to empty
Bug #1086232 Change-Id: Ia27170b206f755577c8607c5b27dc5cf57d19633
This commit is contained in:
parent
61a5870b71
commit
98a9872c73
@ -289,6 +289,11 @@ def convert_kvp_list_to_dict(kvp_list):
|
||||
kvp_map[key].add(value)
|
||||
return dict((x, list(y)) for x, y in kvp_map.iteritems())
|
||||
|
||||
|
||||
def convert_none_to_empty_list(value):
|
||||
return [] if value is None else value
|
||||
|
||||
|
||||
HOSTNAME_PATTERN = ("(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]"
|
||||
"{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)")
|
||||
|
||||
@ -436,10 +441,12 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'validate': {'type:ip_pools': None},
|
||||
'is_visible': True},
|
||||
'dns_nameservers': {'allow_post': True, 'allow_put': True,
|
||||
'convert_to': convert_none_to_empty_list,
|
||||
'default': ATTR_NOT_SPECIFIED,
|
||||
'validate': {'type:nameservers': None},
|
||||
'is_visible': True},
|
||||
'host_routes': {'allow_post': True, 'allow_put': True,
|
||||
'convert_to': convert_none_to_empty_list,
|
||||
'default': ATTR_NOT_SPECIFIED,
|
||||
'validate': {'type:hostroutes': None},
|
||||
'is_visible': True},
|
||||
|
@ -57,6 +57,12 @@ class TestMetaSubnetsV2(test_plugin.TestSubnetsV2,
|
||||
def test_update_subnet_route(self):
|
||||
pass
|
||||
|
||||
def test_update_subnet_dns_to_None(self):
|
||||
pass
|
||||
|
||||
def test_update_subnet_route_to_None(self):
|
||||
pass
|
||||
|
||||
def test_update_subnet_dns(self):
|
||||
pass
|
||||
|
||||
|
@ -416,6 +416,16 @@ class TestConvertToInt(unittest2.TestCase):
|
||||
attributes.convert_to_int,
|
||||
None)
|
||||
|
||||
def test_convert_none_to_empty_list_none(self):
|
||||
self.assertEqual(
|
||||
[], attributes.convert_none_to_empty_list(None))
|
||||
|
||||
def test_convert_none_to_empty_list_value(self):
|
||||
values = ['1', 3, [], [1], {}, {'a':3}]
|
||||
for value in values:
|
||||
self.assertEqual(
|
||||
value, attributes.convert_none_to_empty_list(value))
|
||||
|
||||
|
||||
class TestConvertKvp(unittest2.TestCase):
|
||||
|
||||
|
@ -2094,8 +2094,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
||||
# Check nameservers
|
||||
nameserver_pools = [['1100.0.0.2'],
|
||||
['1.1.1.2', '1.1000.1.3'],
|
||||
['1.1.1.2', '1.1.1.2'],
|
||||
None]
|
||||
['1.1.1.2', '1.1.1.2']]
|
||||
tenant_id = network['network']['tenant_id']
|
||||
for nameservers in nameserver_pools:
|
||||
data = {'subnet': {'network_id': network['network']['id'],
|
||||
@ -2116,8 +2115,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
||||
[{'nexthop': '10.0.2.20',
|
||||
'destination': '100.0.0.0/8'},
|
||||
{'nexthop': '10.0.2.20',
|
||||
'destination': '100.0.0.0/8'}],
|
||||
None]
|
||||
'destination': '100.0.0.0/8'}]]
|
||||
tenant_id = network['network']['tenant_id']
|
||||
for hostroutes in hostroute_pools:
|
||||
data = {'subnet': {'network_id': network['network']['id'],
|
||||
@ -2690,6 +2688,20 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
||||
self.assertEqual(res['subnet']['dns_nameservers'],
|
||||
data['subnet']['dns_nameservers'])
|
||||
|
||||
def test_update_subnet_dns_to_None(self):
|
||||
with self.subnet(dns_nameservers=['11.0.0.1']) as subnet:
|
||||
data = {'subnet': {'dns_nameservers': None}}
|
||||
req = self.new_update_request('subnets', data,
|
||||
subnet['subnet']['id'])
|
||||
res = self.deserialize('json', req.get_response(self.api))
|
||||
self.assertEqual([], res['subnet']['dns_nameservers'])
|
||||
data = {'subnet': {'dns_nameservers': ['11.0.0.3']}}
|
||||
req = self.new_update_request('subnets', data,
|
||||
subnet['subnet']['id'])
|
||||
res = self.deserialize('json', req.get_response(self.api))
|
||||
self.assertEqual(data['subnet']['dns_nameservers'],
|
||||
res['subnet']['dns_nameservers'])
|
||||
|
||||
def test_update_subnet_dns_with_too_many_entries(self):
|
||||
with self.subnet() as subnet:
|
||||
dns_list = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
|
||||
@ -2709,6 +2721,22 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
||||
self.assertEqual(res['subnet']['host_routes'],
|
||||
data['subnet']['host_routes'])
|
||||
|
||||
def test_update_subnet_route_to_None(self):
|
||||
with self.subnet(host_routes=[{'destination': '12.0.0.0/8',
|
||||
'nexthop': '1.2.3.4'}]) as subnet:
|
||||
data = {'subnet': {'host_routes': None}}
|
||||
req = self.new_update_request('subnets', data,
|
||||
subnet['subnet']['id'])
|
||||
res = self.deserialize('json', req.get_response(self.api))
|
||||
self.assertEqual([], res['subnet']['host_routes'])
|
||||
data = {'subnet': {'host_routes': [{'destination': '12.0.0.0/8',
|
||||
'nexthop': '1.2.3.4'}]}}
|
||||
req = self.new_update_request('subnets', data,
|
||||
subnet['subnet']['id'])
|
||||
res = self.deserialize('json', req.get_response(self.api))
|
||||
self.assertEqual(data['subnet']['host_routes'],
|
||||
res['subnet']['host_routes'])
|
||||
|
||||
def test_update_subnet_route_with_too_many_entries(self):
|
||||
with self.subnet() as subnet:
|
||||
data = {'subnet': {'host_routes': [
|
||||
|
Loading…
Reference in New Issue
Block a user