Correctly validate member subnet_id in batches

Change-Id: Id759ba6d4b724c4423f68b90dc9f3f87bde17b21
This commit is contained in:
Adam Harwell 2018-04-04 08:38:32 +09:00
parent 389931fbe8
commit 315bc24411
2 changed files with 25 additions and 0 deletions

View File

@ -293,6 +293,13 @@ class MembersController(MemberController):
self._auth_validate_action(context, db_pool.project_id,
constants.RBAC_DELETE)
# Validate member subnets
for member in members:
if member.subnet_id and not validate.subnet_exists(
member.subnet_id):
raise exceptions.NotFound(resource='Subnet',
id=member.subnet_id)
with db_api.get_lock_session() as lock_session:
self._test_lb_and_listener_and_pool_statuses(lock_session)

View File

@ -506,6 +506,24 @@ class TestMember(base.BaseAPITest):
handler_args[1])
self.assertEqual(0, len(handler_args[2]))
def test_create_batch_members_with_bad_subnet(self):
subnet_id = uuidutils.generate_uuid()
member5 = {'address': '10.0.0.5',
'protocol_port': 80,
'subnet_id': subnet_id}
req_dict = [member5]
body = {self.root_tag_list: req_dict}
path = self.MEMBERS_PATH.format(pool_id=self.pool_id)
with mock.patch(
'octavia.common.utils.get_network_driver') as net_mock:
net_mock.return_value.get_subnet = mock.Mock(
side_effect=network_base.SubnetNotFound('Subnet not found'))
response = self.put(path, body, status=400).json
err_msg = 'Subnet ' + subnet_id + ' not found.'
self.assertEqual(response.get('faultstring'), err_msg)
def test_update_batch_members(self):
member1 = {'address': '10.0.0.1', 'protocol_port': 80}
member2 = {'address': '10.0.0.2', 'protocol_port': 80}