NSXv BGP: Fix get_bgp_peer 'esg_id' attr visibility
Change-Id: I70c357a0ca77864f107174b07d3446fd1cef2504
This commit is contained in:
parent
819045af6c
commit
c9b4b37753
@ -93,17 +93,17 @@ class NSXvBgpPlugin(service_base.ServicePluginBase, bgp_db.BgpDbMixin):
|
|||||||
super(NSXvBgpPlugin, self).delete_bgp_speaker(context,
|
super(NSXvBgpPlugin, self).delete_bgp_speaker(context,
|
||||||
bgp_speaker_id)
|
bgp_speaker_id)
|
||||||
|
|
||||||
def _get_esg_peer_info(self, context, bgp_peer_id):
|
def _add_esg_peer_info(self, context, peer):
|
||||||
binding = nsxv_db.get_nsxv_bgp_peer_edge_binding(context.session,
|
binding = nsxv_db.get_nsxv_bgp_peer_edge_binding(context.session,
|
||||||
bgp_peer_id)
|
peer['id'])
|
||||||
if binding:
|
if binding:
|
||||||
return binding['edge_id']
|
peer['esg_id'] = binding['edge_id']
|
||||||
|
|
||||||
def get_bgp_peer(self, context, bgp_peer_id, fields=None):
|
def get_bgp_peer(self, context, bgp_peer_id, fields=None):
|
||||||
peer = super(NSXvBgpPlugin, self).get_bgp_peer(context,
|
peer = super(NSXvBgpPlugin, self).get_bgp_peer(context,
|
||||||
bgp_peer_id, fields)
|
bgp_peer_id, fields)
|
||||||
if fields is None or 'esg_id' in fields:
|
if not fields or 'esg_id' in fields:
|
||||||
peer['esg_id'] = self._get_esg_peer_info(context, bgp_peer_id)
|
self._add_esg_peer_info(context, peer)
|
||||||
return peer
|
return peer
|
||||||
|
|
||||||
def get_bgp_peers_by_bgp_speaker(self, context,
|
def get_bgp_peers_by_bgp_speaker(self, context,
|
||||||
@ -112,7 +112,7 @@ class NSXvBgpPlugin(service_base.ServicePluginBase, bgp_db.BgpDbMixin):
|
|||||||
context, bgp_speaker_id, fields=fields)
|
context, bgp_speaker_id, fields=fields)
|
||||||
if fields is None or 'esg_id' in fields:
|
if fields is None or 'esg_id' in fields:
|
||||||
for peer in ret:
|
for peer in ret:
|
||||||
peer['esg_id'] = self._get_esg_peer_info(context, peer['id'])
|
self._add_esg_peer_info(context, peer)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def create_bgp_peer(self, context, bgp_peer):
|
def create_bgp_peer(self, context, bgp_peer):
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import contextlib
|
||||||
|
import mock
|
||||||
|
|
||||||
from neutron.api import extensions
|
from neutron.api import extensions
|
||||||
from neutron_dynamic_routing.db import bgp_db # noqa
|
from neutron_dynamic_routing.db import bgp_db # noqa
|
||||||
from neutron_dynamic_routing import extensions as dr_extensions
|
from neutron_dynamic_routing import extensions as dr_extensions
|
||||||
@ -22,6 +25,7 @@ from neutron_lib import exceptions as n_exc
|
|||||||
from neutron_lib.plugins import directory
|
from neutron_lib.plugins import directory
|
||||||
|
|
||||||
from vmware_nsx.services.dynamic_routing import bgp_plugin
|
from vmware_nsx.services.dynamic_routing import bgp_plugin
|
||||||
|
from vmware_nsx.services.dynamic_routing.nsx_v import driver as bgp_driver
|
||||||
from vmware_nsx.tests.unit.nsx_v import test_plugin
|
from vmware_nsx.tests.unit.nsx_v import test_plugin
|
||||||
|
|
||||||
BGP_PLUGIN = 'vmware_nsx.services.dynamic_routing.bgp_plugin.NSXvBgpPlugin'
|
BGP_PLUGIN = 'vmware_nsx.services.dynamic_routing.bgp_plugin.NSXvBgpPlugin'
|
||||||
@ -39,6 +43,20 @@ class TestNSXvBgpPlugin(test_plugin.NsxVPluginV2TestCase,
|
|||||||
self.plugin.init_is_complete = True
|
self.plugin.init_is_complete = True
|
||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def esg_bgp_peer(self, esg_id):
|
||||||
|
data = {'name': '',
|
||||||
|
'peer_ip': '192.168.1.10',
|
||||||
|
'remote_as': '65000',
|
||||||
|
'esg_id': esg_id,
|
||||||
|
'auth_type': 'none',
|
||||||
|
'password': '',
|
||||||
|
'tenant_id': ''}
|
||||||
|
bgp_peer = self.bgp_plugin.create_bgp_peer(self.context,
|
||||||
|
{'bgp_peer': data})
|
||||||
|
yield bgp_peer
|
||||||
|
self.bgp_plugin.delete_bgp_peer(self.context, bgp_peer['id'])
|
||||||
|
|
||||||
def test_create_v6_bgp_speaker(self):
|
def test_create_v6_bgp_speaker(self):
|
||||||
fake_bgp_speaker = {
|
fake_bgp_speaker = {
|
||||||
"bgp_speaker": {
|
"bgp_speaker": {
|
||||||
@ -64,6 +82,18 @@ class TestNSXvBgpPlugin(test_plugin.NsxVPluginV2TestCase,
|
|||||||
self.bgp_plugin.create_bgp_peer,
|
self.bgp_plugin.create_bgp_peer,
|
||||||
self.context, fake_bgp_peer)
|
self.context, fake_bgp_peer)
|
||||||
|
|
||||||
|
def test_bgp_peer_esg_id(self):
|
||||||
|
edge_id = 'edge-123'
|
||||||
|
with mock.patch.object(bgp_driver.NSXvBgpDriver,
|
||||||
|
'_validate_bgp_configuration_on_peer_esg',
|
||||||
|
side_effect=None):
|
||||||
|
with self.esg_bgp_peer(esg_id='edge-123') as esg_peer:
|
||||||
|
self.assertEqual(edge_id, esg_peer['esg_id'])
|
||||||
|
|
||||||
|
peer_id = esg_peer['id']
|
||||||
|
bgp_peer = self.bgp_plugin.get_bgp_peer(self.context, peer_id)
|
||||||
|
self.assertEqual(edge_id, bgp_peer['esg_id'])
|
||||||
|
|
||||||
def test_create_bgp_peer_md5_auth_no_password(self):
|
def test_create_bgp_peer_md5_auth_no_password(self):
|
||||||
# TODO(roeyc): Test requires a minor fix in base class.
|
# TODO(roeyc): Test requires a minor fix in base class.
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user