Remove pool_id attr from creation request body of pool_member

There are some properties defined in resources which will only be
used as path_args for generating request url for resource creation.
These properties will be carried in request body although they are
actually not required by backend service. For these extra arguments,
most services will just ignore them when doing parameter check.
However, some services, e.g. neutron lbaas will complain these
arguments are 'unrecognized attributes' and throw exception. So we
may need to remove these attributes in path_args from request body
before sending request for resource creation.

Since some proxy calls like create_pool_member are still broken for
this issue, hope we can use this fix as a workaround before more
complete solution is provided.

Change-Id: Ib0303cda6ef6b43939a9a7e151698c223e6c648b
This commit is contained in:
yanyanhu
2015-06-03 05:22:03 -04:00
parent 0ea34d1e34
commit 7a11f3b01c
2 changed files with 16 additions and 0 deletions

View File

@@ -44,3 +44,11 @@ class PoolMember(resource.Resource):
#: with a weight of 10 receives five times as much traffic as a member
#: with weight of 2.
weight = resource.prop('weight', type=int)
@classmethod
def _get_create_body(cls, attrs):
# Exclude pool_id from attrs since it is not expected by LBaaS service
if 'pool_id' in attrs:
attrs.pop('pool_id')
return {cls.resource_key: attrs}

View File

@@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import testtools
from openstack.network.v2 import pool_member
@@ -49,3 +51,9 @@ class TestPoolMember(testtools.TestCase):
self.assertEqual(EXAMPLE['protocol_port'], sot.protocol_port)
self.assertEqual(EXAMPLE['subnet_id'], sot.subnet_id)
self.assertEqual(EXAMPLE['weight'], sot.weight)
def test_create_body(self):
params = copy.deepcopy(EXAMPLE)
params['pool_id'] = {'POOL1_ID'}
body = pool_member.PoolMember._get_create_body(params)
self.assertEqual(EXAMPLE, body['member'])