summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/completion/list_bgp_neighbors.sh3
-rwxr-xr-xsrc/completion/list_bgp_peer_groups.sh3
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py8
-rw-r--r--src/tests/test_template.py10
4 files changed, 19 insertions, 5 deletions
diff --git a/src/completion/list_bgp_neighbors.sh b/src/completion/list_bgp_neighbors.sh
index 77c626452..f74f102ef 100755
--- a/src/completion/list_bgp_neighbors.sh
+++ b/src/completion/list_bgp_neighbors.sh
@@ -30,8 +30,7 @@ while [[ "$#" -gt 0 ]]; do
done
declare -a vals
-eval "bgp_as=$(cli-shell-api listActiveNodes protocols bgp)"
-eval "vals=($(cli-shell-api listActiveNodes protocols bgp $bgp_as neighbor))"
+eval "vals=($(cli-shell-api listActiveNodes protocols bgp neighbor))"
if [ $ipv4 -eq 1 ] && [ $ipv6 -eq 1 ]; then
echo -n '<x.x.x.x>' '<h:h:h:h:h:h:h:h>' ${vals[@]}
diff --git a/src/completion/list_bgp_peer_groups.sh b/src/completion/list_bgp_peer_groups.sh
index 4503d608f..1684271f8 100755
--- a/src/completion/list_bgp_peer_groups.sh
+++ b/src/completion/list_bgp_peer_groups.sh
@@ -16,8 +16,7 @@
# Return BGP peer-groups from CLI
declare -a vals
-eval "bgp_as=$(cli-shell-api listNodes protocols bgp)"
-eval "vals=($(cli-shell-api listNodes protocols bgp $bgp_as peer-group))"
+eval "vals=($(cli-shell-api listNodes protocols bgp peer-group))"
echo -n ${vals[@]}
exit 0
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py
index 73cfa9b83..8304df2e5 100755
--- a/src/conf_mode/protocols_bgp.py
+++ b/src/conf_mode/protocols_bgp.py
@@ -22,6 +22,7 @@ from sys import argv
from vyos.config import Config
from vyos.configdict import dict_merge
from vyos.template import is_ip
+from vyos.template import is_interface
from vyos.template import render_to_string
from vyos.util import call
from vyos.util import dict_search
@@ -128,7 +129,12 @@ def verify(bgp):
# Only checks for ipv4 and ipv6 neighbors
# Check if neighbor address is assigned as system interface address
if is_ip(peer) and is_addr_assigned(peer):
- raise ConfigError(f'Can\'t configure local address as neighbor "{peer}"')
+ raise ConfigError(f'Can not configure a local address as neighbor "{peer}"')
+ elif is_interface(peer):
+ if 'peer_group' in peer_config:
+ raise ConfigError(f'peer-group must be set under the interface node of "{peer}"')
+ if 'remote_as' in peer_config:
+ raise ConfigError(f'remote-as must be set under the interface node of "{peer}"')
for afi in ['ipv4_unicast', 'ipv6_unicast', 'l2vpn_evpn']:
# Bail out early if address family is not configured
diff --git a/src/tests/test_template.py b/src/tests/test_template.py
index 7800d007f..67c0fe84a 100644
--- a/src/tests/test_template.py
+++ b/src/tests/test_template.py
@@ -14,13 +14,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
import vyos.template
+
from unittest import TestCase
class TestVyOSTemplate(TestCase):
def setUp(self):
pass
+ def test_is_interface(self):
+ for interface in ['lo', 'eth0']:
+ if os.path.exists(f'/sys/class/net/{interface}'):
+ self.assertTrue(vyos.template.is_interface(interface))
+ else:
+ self.assertFalse(vyos.template.is_interface(interface))
+ self.assertFalse(vyos.template.is_interface('non-existent'))
+
def test_is_ip(self):
self.assertTrue(vyos.template.is_ip('192.0.2.1'))
self.assertTrue(vyos.template.is_ip('2001:db8::1'))