Merge "NEC plugin: Remove a colon from binding:profile key due to XML problem"

This commit is contained in:
Jenkins 2014-03-22 02:04:21 +00:00 committed by Gerrit Code Review
commit a17a1ca278
3 changed files with 33 additions and 35 deletions

View File

@ -57,13 +57,13 @@ class PortInfoNotFound(qexc.NotFound):
class ProfilePortInfoInvalidDataPathId(qexc.InvalidInput): class ProfilePortInfoInvalidDataPathId(qexc.InvalidInput):
message = _('Invalid input for operation: ' message = _('Invalid input for operation: '
'portinfo:datapath_id should be a hex string ' 'datapath_id should be a hex string '
'with at most 8 bytes') 'with at most 8 bytes')
class ProfilePortInfoInvalidPortNo(qexc.InvalidInput): class ProfilePortInfoInvalidPortNo(qexc.InvalidInput):
message = _('Invalid input for operation: ' message = _('Invalid input for operation: '
'portinfo:port_no should be [0:65535]') 'port_no should be [0:65535]')
class RouterExternalGatewayNotSupported(qexc.BadRequest): class RouterExternalGatewayNotSupported(qexc.BadRequest):

View File

@ -407,24 +407,24 @@ class NECPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
def _extend_port_dict_binding_portinfo(self, port_res, portinfo): def _extend_port_dict_binding_portinfo(self, port_res, portinfo):
if portinfo: if portinfo:
port_res[portbindings.PROFILE] = { port_res[portbindings.PROFILE] = {
'portinfo:datapath_id': portinfo['datapath_id'], 'datapath_id': portinfo['datapath_id'],
'portinfo:port_no': portinfo['port_no'], 'port_no': portinfo['port_no'],
} }
elif portbindings.PROFILE in port_res: elif portbindings.PROFILE in port_res:
del port_res[portbindings.PROFILE] del port_res[portbindings.PROFILE]
def _validate_portinfo(self, profile): def _validate_portinfo(self, profile):
key_specs = { key_specs = {
'portinfo:datapath_id': {'type:string': None, 'required': True}, 'datapath_id': {'type:string': None, 'required': True},
'portinfo:port_no': {'type:non_negative': None, 'required': True, 'port_no': {'type:non_negative': None, 'required': True,
'convert_to': attrs.convert_to_int} 'convert_to': attrs.convert_to_int}
} }
msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs) msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs)
if msg: if msg:
raise n_exc.InvalidInput(error_message=msg) raise n_exc.InvalidInput(error_message=msg)
datapath_id = profile.get('portinfo:datapath_id') datapath_id = profile.get('datapath_id')
port_no = profile.get('portinfo:port_no') port_no = profile.get('port_no')
try: try:
dpid = int(datapath_id, 16) dpid = int(datapath_id, 16)
except ValueError: except ValueError:

View File

@ -51,24 +51,22 @@ class TestNecPortBindingHost(
class TestNecPortBindingPortInfo(test_nec_plugin.NecPluginV2TestCase): class TestNecPortBindingPortInfo(test_nec_plugin.NecPluginV2TestCase):
def _get_portinfo(self, datapath_id=None, port_no=None, prefix=None): def _get_portinfo(self, datapath_id=None, port_no=None):
if datapath_id is None: if datapath_id is None:
datapath_id = '0xabc' datapath_id = '0xabc'
if port_no is None: if port_no is None:
port_no = 1 port_no = 1
if prefix is None: return {'datapath_id': datapath_id,
prefix = 'portinfo:' 'port_no': port_no}
return {prefix + 'datapath_id': datapath_id,
prefix + 'port_no': port_no}
def _check_response_portbinding_profile(self, port, datapath_id=None, def _check_response_portbinding_profile(self, port, datapath_id=None,
port_no=None): port_no=None):
expected = self._get_portinfo(datapath_id, port_no, prefix='') expected = self._get_portinfo(datapath_id, port_no)
profile = port[portbindings.PROFILE] profile = port[portbindings.PROFILE]
self.assertEqual(len(profile), 2) self.assertEqual(len(profile), 2)
self.assertEqual(profile['portinfo:datapath_id'], self.assertEqual(profile['datapath_id'],
expected['datapath_id']) expected['datapath_id'])
self.assertEqual(profile['portinfo:port_no'], self.assertEqual(profile['port_no'],
expected['port_no']) expected['port_no'])
def _check_response_portbinding_no_profile(self, port): def _check_response_portbinding_no_profile(self, port):
@ -267,8 +265,8 @@ class TestNecPortBindingPortInfo(test_nec_plugin.NecPluginV2TestCase):
def test_port_create_portinfo_validation_called(self): def test_port_create_portinfo_validation_called(self):
# Check validate_portinfo is called. # Check validate_portinfo is called.
profile_arg = {portbindings.PROFILE: profile_arg = {portbindings.PROFILE:
{'portinfo:datapath_id': '0xabc', {'datapath_id': '0xabc',
'portinfo:port_no': 0xffff + 1}} 'port_no': 0xffff + 1}}
try: try:
with self.port(arg_list=(portbindings.PROFILE,), with self.port(arg_list=(portbindings.PROFILE,),
expected_res_status=400, expected_res_status=400,
@ -281,8 +279,8 @@ class TestNecPortBindingPortInfo(test_nec_plugin.NecPluginV2TestCase):
class TestNecPortBindingValidatePortInfo(test_nec_plugin.NecPluginV2TestCase): class TestNecPortBindingValidatePortInfo(test_nec_plugin.NecPluginV2TestCase):
def test_validate_portinfo_ok(self): def test_validate_portinfo_ok(self):
profile = {'portinfo:datapath_id': '0x1234567890abcdef', profile = {'datapath_id': '0x1234567890abcdef',
'portinfo:port_no': 123} 'port_no': 123}
portinfo = self.plugin._validate_portinfo(profile) portinfo = self.plugin._validate_portinfo(profile)
# NOTE(mriedem): Handle long integer conversion universally. # NOTE(mriedem): Handle long integer conversion universally.
self.assertEqual( self.assertEqual(
@ -292,8 +290,8 @@ class TestNecPortBindingValidatePortInfo(test_nec_plugin.NecPluginV2TestCase):
self.assertEqual(portinfo['port_no'], 123) self.assertEqual(portinfo['port_no'], 123)
def test_validate_portinfo_ok_without_0x(self): def test_validate_portinfo_ok_without_0x(self):
profile = {'portinfo:datapath_id': '1234567890abcdef', profile = {'datapath_id': '1234567890abcdef',
'portinfo:port_no': 123} 'port_no': 123}
portinfo = self.plugin._validate_portinfo(profile) portinfo = self.plugin._validate_portinfo(profile)
# NOTE(mriedem): Handle long integer conversion universally. # NOTE(mriedem): Handle long integer conversion universally.
self.assertEqual( self.assertEqual(
@ -311,36 +309,36 @@ class TestNecPortBindingValidatePortInfo(test_nec_plugin.NecPluginV2TestCase):
expected_msg = ("Invalid input for operation: " expected_msg = ("Invalid input for operation: "
"Validation of dictionary's keys failed.") "Validation of dictionary's keys failed.")
profile = {'portinfo:port_no': 123} profile = {'port_no': 123}
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)
profile = {'portinfo:datapath_id': '0xabcdef'} profile = {'datapath_id': '0xabcdef'}
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)
def test_validate_portinfo_negative_port_number(self): def test_validate_portinfo_negative_port_number(self):
profile = {'portinfo:datapath_id': '0x1234567890abcdef', profile = {'datapath_id': '0x1234567890abcdef',
'portinfo:port_no': -1} 'port_no': -1}
expected_msg = ("Invalid input for operation: " expected_msg = ("Invalid input for operation: "
"'-1' should be non-negative.") "'-1' should be non-negative.")
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)
def test_validate_portinfo_invalid_datapath_id(self): def test_validate_portinfo_invalid_datapath_id(self):
expected_msg = ("Invalid input for operation: " expected_msg = ("Invalid input for operation: "
"portinfo:datapath_id should be a hex string") "datapath_id should be a hex string")
# non hexidecimal datapath_id # non hexidecimal datapath_id
profile = {'portinfo:datapath_id': 'INVALID', profile = {'datapath_id': 'INVALID',
'portinfo:port_no': 123} 'port_no': 123}
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)
# Too big datapath_id # Too big datapath_id
profile = {'portinfo:datapath_id': '0x10000000000000000', profile = {'datapath_id': '0x10000000000000000',
'portinfo:port_no': 123} 'port_no': 123}
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)
def test_validate_portinfo_too_big_port_number(self): def test_validate_portinfo_too_big_port_number(self):
profile = {'portinfo:datapath_id': '0x1234567890abcdef', profile = {'datapath_id': '0x1234567890abcdef',
'portinfo:port_no': 65536} 'port_no': 65536}
expected_msg = ("Invalid input for operation: " expected_msg = ("Invalid input for operation: "
"portinfo:port_no should be [0:65535]") "port_no should be [0:65535]")
self._test_validate_exception(profile, expected_msg) self._test_validate_exception(profile, expected_msg)