Fixes KeyError while updating bgp peer
This will fix the issue of KeyError being thrown when 'password' is not supplied while updating bgp peer. The dict get() method is used to return None when 'password' key is not available. Two unit tests are also added which will test the cases 1) Exception thrown if the auth type is 'none', and a password is supplied when updating 2) When the password is not supplied Change-Id: Ief9e88ca12b04eb08b0cc4e60f9d883f1e282ae9 Closes-Bug: #1616066
This commit is contained in:
parent
2c4a8bfd2a
commit
89ed530fec
|
@ -267,7 +267,7 @@ class BgpDbMixin(common_db.CommonDbMixin):
|
|||
bp = bgp_peer[bgp_ext.BGP_PEER_BODY_KEY_NAME]
|
||||
with context.session.begin(subtransactions=True):
|
||||
bgp_peer_db = self._get_bgp_peer(context, bgp_peer_id)
|
||||
if ((bp['password'] is not None) and
|
||||
if ((bp.get('password') is not None) and
|
||||
(bgp_peer_db['auth_type'] == 'none')):
|
||||
raise bgp_ext.BgpPeerNotAuthenticated(bgp_peer_id=bgp_peer_id)
|
||||
bgp_peer_db.update(bp)
|
||||
|
|
|
@ -273,6 +273,43 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase,
|
|||
for key in args:
|
||||
self.assertEqual(args[key], peer[key])
|
||||
|
||||
def test_update_bgp_peer_auth_type_none(self):
|
||||
args = {'tenant_id': _uuid(),
|
||||
'remote_as': '1111',
|
||||
'peer_ip': '10.10.10.10',
|
||||
'auth_type': 'md5'}
|
||||
with self.bgp_peer(tenant_id=args['tenant_id'],
|
||||
remote_as=args['remote_as'],
|
||||
peer_ip=args['peer_ip'],
|
||||
auth_type='none',
|
||||
name="my-peer") as peer:
|
||||
data = {'bgp_peer': {'password': "my-secret",
|
||||
'name': "my-peer1"}}
|
||||
self.assertRaises(bgp.BgpPeerNotAuthenticated,
|
||||
self.bgp_plugin.update_bgp_peer,
|
||||
self.context, peer['id'], data)
|
||||
|
||||
def test_update_bgp_peer_password_none(self):
|
||||
args = {'tenant_id': _uuid(),
|
||||
'remote_as': 1111,
|
||||
'peer_ip': '10.10.10.10',
|
||||
'name': 'my-peer',
|
||||
'auth_type': 'none'}
|
||||
with self.bgp_peer(tenant_id=args['tenant_id'],
|
||||
remote_as=args['remote_as'],
|
||||
peer_ip=args['peer_ip'],
|
||||
auth_type=args['auth_type'],
|
||||
name=args['name']) as peer:
|
||||
data = {'bgp_peer': {'name': "my-peer1"}}
|
||||
updated_peer = self.bgp_plugin.update_bgp_peer(self.context,
|
||||
peer['id'],
|
||||
data)
|
||||
for key in args:
|
||||
if key == 'name':
|
||||
self.assertEqual('my-peer1', updated_peer[key])
|
||||
else:
|
||||
self.assertEqual(peer[key], updated_peer[key])
|
||||
|
||||
def test_bgp_peer_show_non_existent(self):
|
||||
self.assertRaises(bgp.BgpPeerNotFound,
|
||||
self.bgp_plugin.get_bgp_peer,
|
||||
|
|
Loading…
Reference in New Issue