Merge "Fix a bug some optional field in LBaaS are mandatory"

This commit is contained in:
Jenkins 2013-10-24 21:32:49 +00:00 committed by Gerrit Code Review
commit f8df4592f8
3 changed files with 51 additions and 32 deletions

View File

@ -136,9 +136,10 @@ def vip_create(request, **kwargs):
'protocol': kwargs['protocol'],
'pool_id': kwargs['pool_id'],
'session_persistence': kwargs['session_persistence'],
'connection_limit': kwargs['connection_limit'],
'admin_state_up': kwargs['admin_state_up']
}}
if kwargs.get('connection_limit'):
body['vip']['connection_limit'] = kwargs['connection_limit']
vip = neutronclient(request).create_vip(body).get('vip')
return Vip(vip)
@ -275,9 +276,10 @@ def member_create(request, **kwargs):
body = {'member': {'pool_id': kwargs['pool_id'],
'address': kwargs['address'],
'protocol_port': kwargs['protocol_port'],
'weight': kwargs['weight'],
'admin_state_up': kwargs['admin_state_up']
}}
if kwargs.get('weight'):
body['member']['weight'] = kwargs['weight']
member = neutronclient(request).create_member(body).get('member')
return Member(member)

View File

@ -277,9 +277,15 @@ class LoadBalancerTests(test.TestCase):
else:
self.assertContains(res, default_provider)
def test_add_vip_post(self):
self._test_add_vip_post()
def test_add_vip_post_no_connection_limit(self):
self._test_add_vip_post(with_conn_limit=False)
@test.create_stubs({api.lbaas: ('pool_get', 'vip_create'),
api.neutron: ('subnet_get', )})
def test_add_vip_post(self):
def _test_add_vip_post(self, with_conn_limit=True):
vip = self.vips.first()
subnet = self.subnets.first()
@ -291,22 +297,24 @@ class LoadBalancerTests(test.TestCase):
api.neutron.subnet_get(
IsA(http.HttpRequest), subnet.id).AndReturn(subnet)
params = {'name': vip.name,
'description': vip.description,
'pool_id': vip.pool_id,
'address': vip.address,
'floatip_address': vip.floatip_address,
'other_address': vip.other_address,
'subnet': vip.subnet,
'subnet_id': vip.subnet_id,
'protocol_port': vip.protocol_port,
'protocol': vip.protocol,
'session_persistence': vip.session_persistence['type'],
'cookie_name': vip.session_persistence['cookie_name'],
'admin_state_up': vip.admin_state_up,
}
if with_conn_limit:
params['connection_limit'] = vip.connection_limit
api.lbaas.vip_create(
IsA(http.HttpRequest),
name=vip.name,
description=vip.description,
pool_id=vip.pool_id,
address=vip.address,
floatip_address=vip.floatip_address,
other_address=vip.other_address,
subnet=vip.subnet,
subnet_id=vip.subnet_id,
protocol_port=vip.protocol_port,
protocol=vip.protocol,
session_persistence=vip.session_persistence['type'],
cookie_name=vip.session_persistence['cookie_name'],
connection_limit=vip.connection_limit,
admin_state_up=vip.admin_state_up).AndReturn(vip)
IsA(http.HttpRequest), **params).AndReturn(vip)
self.mox.ReplayAll()
@ -322,8 +330,9 @@ class LoadBalancerTests(test.TestCase):
'protocol': vip.protocol,
'session_persistence': vip.session_persistence['type'],
'cookie_name': vip.session_persistence['cookie_name'],
'connection_limit': vip.connection_limit,
'admin_state_up': vip.admin_state_up}
if with_conn_limit:
form_data['connection_limit'] = vip.connection_limit
res = self.client.post(
reverse(self.ADDVIP_PATH, args=(pool.id,)), form_data)
@ -457,10 +466,16 @@ class LoadBalancerTests(test.TestCase):
expected_objs = ['<AddMonitorStep: addmonitoraction>', ]
self.assertQuerysetEqual(workflow.steps, expected_objs)
def test_add_member_post(self):
self._test_add_member_post()
def test_add_member_post_without_weight(self):
self._test_add_member_post(with_weight=False)
@test.create_stubs({api.lbaas: ('pools_get', 'member_create'),
api.neutron: ('port_list',),
api.nova: ('server_list',)})
def test_add_member_post(self):
def _test_add_member_post(self, with_weight=True):
member = self.members.first()
server1 = self.AttributeDict({'id':
@ -481,24 +496,26 @@ class LoadBalancerTests(test.TestCase):
api.neutron.port_list(IsA(http.HttpRequest),
device_id=server1.id).AndReturn([port1, ])
api.lbaas.member_create(
IsA(http.HttpRequest),
pool_id=member.pool_id,
address=member.address,
protocol_port=member.protocol_port,
weight=member.weight,
members=[server1.id],
admin_state_up=member.admin_state_up).AndReturn(
lbaas.Member(member))
params = {'pool_id': member.pool_id,
'address': member.address,
'protocol_port': member.protocol_port,
'members': [server1.id],
'admin_state_up': member.admin_state_up,
}
if with_weight:
params['weight'] = member.weight
api.lbaas.member_create(IsA(http.HttpRequest),
**params).AndReturn(lbaas.Member(member))
self.mox.ReplayAll()
form_data = {'pool_id': member.pool_id,
'address': member.address,
'protocol_port': member.protocol_port,
'weight': member.weight,
'members': [server1.id],
'admin_state_up': member.admin_state_up}
if with_weight:
form_data['weight'] = member.weight
res = self.client.post(reverse(self.ADDMEMBER_PATH), form_data)

View File

@ -171,7 +171,7 @@ class AddVipAction(workflows.Action):
help_text=_("Required for APP_COOKIE persistence;"
" Ignored otherwise."))
connection_limit = forms.IntegerField(
min_value=-1, label=_("Connection Limit"),
required=False, min_value=-1, label=_("Connection Limit"),
help_text=_("Maximum number of connections allowed "
"for the VIP or '-1' if the limit is not set"))
admin_state_up = forms.BooleanField(
@ -292,6 +292,7 @@ class AddMemberAction(workflows.Action):
_('At least one member must be specified')},
help_text=_("Select members for this pool "))
weight = forms.IntegerField(max_value=256, min_value=0, label=_("Weight"),
required=False,
help_text=_("Relative part of requests this "
"pool member serves compared to others"))
protocol_port = forms.IntegerField(label=_("Protocol Port"), min_value=1,
@ -332,7 +333,6 @@ class AddMemberAction(workflows.Action):
self.fields['members'].help_text = _("Select members "
"for this pool ")
self.fields['pool_id'].required = False
self.fields['weight'].required = False
self.fields['protocol_port'].required = False
return