Don't send empty remote_address_group_id for security groups
We are seeing an error raised by older Neutron's 400: Client Error for url: <cloud>/v2.0/security-group-rules, Unrecognized attribute(s) 'remote_address_group_id' This field was added unconditionally with I50374c339ab7685a6e74f25f9521b8810c532e13 but, per above, appears to cause problems for older Neutron instances. To work around this, remove the argument from the body when blank by overriding the _prepare_request function of SecurityGroupRule. Two tests where this are used are updated; one checks the body is not sent when None and the other is modified to send a remote_address_group_id value to validate the other path. Story: #2008577 Task: #41729 Change-Id: I25dabfde27b843df1c91c7fc37a1fe8d207b8010
This commit is contained in:
parent
e13b59c7bd
commit
b562d779e6
@ -87,3 +87,15 @@ class SecurityGroupRule(_base.NetworkResource, resource.TagMixin):
|
||||
tenant_id = resource.Body('tenant_id')
|
||||
#: Timestamp when the security group rule was last updated.
|
||||
updated_at = resource.Body('updated_at')
|
||||
|
||||
def _prepare_request(self, *args, **kwargs):
|
||||
_request = super(SecurityGroupRule, self)._prepare_request(
|
||||
*args, **kwargs)
|
||||
# Old versions of Neutron do not handle being passed a
|
||||
# remote_address_group_id and raise and error. Remove it from
|
||||
# the body if it is blank.
|
||||
if not self.remote_address_group_id:
|
||||
if 'security_group_rule' in _request.body:
|
||||
_rule = _request.body['security_group_rule']
|
||||
_rule.pop('remote_address_group_id', None)
|
||||
return _request
|
||||
|
@ -347,7 +347,7 @@ class TestSecurityGroups(base.TestCase):
|
||||
protocol='tcp',
|
||||
remote_ip_prefix='0.0.0.0/0',
|
||||
remote_group_id='456',
|
||||
remote_address_group_id=None,
|
||||
remote_address_group_id='1234-5678',
|
||||
direction='egress',
|
||||
ethertype='IPv6'
|
||||
)
|
||||
@ -415,6 +415,10 @@ class TestSecurityGroups(base.TestCase):
|
||||
expected_new_rule['id'] = '1234'
|
||||
expected_new_rule['project_id'] = expected_new_rule['tenant_id']
|
||||
|
||||
# This is not sent in body if == None so should not be in the
|
||||
# JSON; see SecurityGroupRule where it is removed.
|
||||
expected_args.pop('remote_address_group_id')
|
||||
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes a regression sending an unsupported field
|
||||
``remote_address_group_id`` when creating security groups with an
|
||||
older Neutron (introduced 0.53.0).
|
Loading…
Reference in New Issue
Block a user