summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-03-07 14:28:27 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-03-17 11:19:18 +0900
commitd9d1eb3eea53906e209f8e9b0163cd4408d0c81c (patch)
tree2b2689a43b89b1d1d7f6aba67d4c1ddaf45f31ff /test
parenta7932d708921c5b2ed4f3fa7ce608a1449146048 (diff)
scenario_test: Enable to start OSPFd in GoBGP container
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/lib/gobgp.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 1a54237a..84e30198 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -53,7 +53,7 @@ class GoBGPContainer(BGPContainer):
def __init__(self, name, asn, router_id, ctn_image_name='osrg/gobgp',
log_level='debug', zebra=False, config_format='toml',
- zapi_version=2):
+ zapi_version=2, ospfd_config=None):
super(GoBGPContainer, self).__init__(name, asn, router_id,
ctn_image_name)
self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME))
@@ -68,6 +68,19 @@ class GoBGPContainer(BGPContainer):
self.zapi_version = zapi_version
self.config_format = config_format
+ # To start OSPFd in GoBGP container, specify 'ospfd_config' as a dict
+ # type value.
+ # Example:
+ # ospfd_config = {
+ # 'redistributes': [
+ # 'connected',
+ # ],
+ # 'networks': {
+ # '192.168.1.0/24': '0.0.0.0', # <network>: <area>
+ # },
+ # }
+ self.ospfd_config = ospfd_config or {}
+
def _start_gobgp(self, graceful_restart=False):
c = CmdBuffer()
c << '#!/bin/bash'
@@ -92,10 +105,21 @@ class GoBGPContainer(BGPContainer):
cmd = 'zebra -u root -g root -f {0}/zebra.conf'.format(self.SHARED_VOLUME)
self.local(cmd, detach=True)
+ def _start_ospfd(self):
+ if self.zapi_version == 2:
+ cmd = 'cp {0}/ospfd.conf {1}/'.format(self.SHARED_VOLUME, self.QUAGGA_VOLUME)
+ self.local(cmd)
+ cmd = '/usr/lib/quagga/ospfd -f {0}/ospfd.conf'.format(self.QUAGGA_VOLUME)
+ else:
+ cmd = 'ospfd -u root -g root -f {0}/ospfd.conf'.format(self.SHARED_VOLUME)
+ self.local(cmd, detach=True)
+
def run(self):
super(GoBGPContainer, self).run()
if self.zebra:
self._start_zebra()
+ if self.ospfd_config:
+ self._start_ospfd()
self._start_gobgp()
return self.WAIT_FOR_BOOT
@@ -269,6 +293,8 @@ class GoBGPContainer(BGPContainer):
self._create_config_bgp()
if self.zebra:
self._create_config_zebra()
+ if self.ospfd_config:
+ self._create_config_ospfd()
def _create_config_bgp(self):
config = {
@@ -434,10 +460,29 @@ class GoBGPContainer(BGPContainer):
print colors.yellow(indent(str(c)))
f.writelines(str(c))
+ def _create_config_ospfd(self):
+ c = CmdBuffer()
+ c << 'hostname ospfd'
+ c << 'password zebra'
+ c << 'router ospf'
+ for redistribute in self.ospfd_config.get('redistributes', []):
+ c << ' redistribute {0}'.format(redistribute)
+ for network, area in self.ospfd_config.get('networks', {}).items():
+ c << ' network {0} area {1}'.format(network, area)
+ c << 'log file {0}/ospfd.log'.format(self.SHARED_VOLUME)
+ c << ''
+
+ with open('{0}/ospfd.conf'.format(self.config_dir), 'w') as f:
+ print colors.yellow('[{0}\'s new ospfd.conf]'.format(self.name))
+ print colors.yellow(indent(str(c)))
+ f.writelines(str(c))
+
def reload_config(self):
daemon = ['gobgpd']
if self.zebra:
daemon.append('zebra')
+ if self.ospfd_config:
+ daemon.append('ospfd')
for d in daemon:
cmd = '/usr/bin/pkill {0} -SIGHUP'.format(d)
self.local(cmd)