summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-03-08 14:46:16 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-03-17 11:23:35 +0900
commite7a2c8e4a47405b53b81d602dd862fc455ae1abf (patch)
treec41b1bdadf3b2dcc48cbe0f12b4804959fd35aa4 /test
parentd9d1eb3eea53906e209f8e9b0163cd4408d0c81c (diff)
scenario_test: Support OSPFd in Quagga container
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/lib/base.py28
-rw-r--r--test/lib/quagga.py109
2 files changed, 137 insertions, 0 deletions
diff --git a/test/lib/base.py b/test/lib/base.py
index b6e77118..18fa487c 100644
--- a/test/lib/base.py
+++ b/test/lib/base.py
@@ -465,3 +465,31 @@ class BGPContainer(Container):
def reload_config(self):
raise Exception('implement reload_config() method')
+
+
+class OSPFContainer(Container):
+ WAIT_FOR_BOOT = 1
+
+ def __init__(self, name, ctn_image_name):
+ self.config_dir = '/'.join((TEST_BASE_DIR, TEST_PREFIX, name))
+ local('if [ -e {0} ]; then rm -rf {0}; fi'.format(self.config_dir))
+ local('mkdir -p {0}'.format(self.config_dir))
+ local('chmod 777 {0}'.format(self.config_dir))
+
+ # Example:
+ # networks = {
+ # '192.168.1.0/24': '0.0.0.0', # <network>: <area>
+ # }
+ self.networks = {}
+ super(OSPFContainer, self).__init__(name, ctn_image_name)
+
+ def __repr__(self):
+ return str({'name': self.name, 'networks': self.networks})
+
+ def run(self):
+ self.create_config()
+ super(OSPFContainer, self).run()
+ return self.WAIT_FOR_BOOT
+
+ def create_config(self):
+ raise NotImplementedError
diff --git a/test/lib/quagga.py b/test/lib/quagga.py
index 897648ae..e7b9f9bf 100644
--- a/test/lib/quagga.py
+++ b/test/lib/quagga.py
@@ -21,6 +21,7 @@ import netaddr
from lib.base import (
BGPContainer,
+ OSPFContainer,
CmdBuffer,
BGP_FSM_IDLE,
BGP_FSM_ACTIVE,
@@ -282,3 +283,111 @@ class RawQuaggaBGPContainer(QuaggaBGPContainer):
print colors.yellow('[{0}\'s new bgpd.conf]'.format(self.name))
print colors.yellow(indent(self.config))
f.writelines(self.config)
+
+
+class QuaggaOSPFContainer(OSPFContainer):
+ SHARED_VOLUME = '/etc/quagga'
+ ZAPI_V2_IMAGE = 'osrg/quagga'
+ ZAPI_V3_IMAGE = 'osrg/quagga:v1.0'
+
+ def __init__(self, name, image=ZAPI_V2_IMAGE, zapi_verion=2,
+ zebra_config=None, ospfd_config=None):
+ if zapi_verion != 2:
+ image = self.ZAPI_V3_IMAGE
+ super(QuaggaOSPFContainer, self).__init__(name, image)
+ self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME))
+
+ self.zapi_vserion = zapi_verion
+
+ # Example:
+ # zebra_config = {
+ # 'interfaces': { # interface settings
+ # 'eth0': [
+ # 'ip address 192.168.0.1/24',
+ # ],
+ # },
+ # 'routes': [ # static route settings
+ # 'ip route 172.16.0.0/16 172.16.0.1',
+ # ],
+ # }
+ self.zebra_config = zebra_config or {}
+
+ # Example:
+ # ospfd_config = {
+ # 'redistribute_types': [
+ # 'connected',
+ # ],
+ # 'networks': {
+ # '192.168.1.0/24': '0.0.0.0', # <network>: <area>
+ # },
+ # }
+ self.ospfd_config = ospfd_config or {}
+
+ def run(self):
+ super(QuaggaOSPFContainer, self).run()
+ # self.create_config() is called in super(...).run()
+ self._start_zebra()
+ self._start_ospfd()
+ return self.WAIT_FOR_BOOT
+
+ def create_config(self):
+ self._create_config_zebra()
+ self._create_config_ospfd()
+
+ def _create_config_zebra(self):
+ c = CmdBuffer()
+ c << 'hostname zebra'
+ c << 'password zebra'
+ for name, settings in self.zebra_config.get('interfaces', {}).items():
+ c << 'interface {0}'.format(name)
+ for setting in settings:
+ c << str(setting)
+ for route in self.zebra_config.get('routes', []):
+ c << str(route)
+ c << 'log file {0}/zebra.log'.format(self.SHARED_VOLUME)
+ c << 'debug zebra packet'
+ c << 'debug zebra kernel'
+ c << 'debug zebra rib'
+ c << ''
+
+ with open('{0}/zebra.conf'.format(self.config_dir), 'w') as f:
+ print colors.yellow('[{0}\'s new zebra.conf]'.format(self.name))
+ 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():
+ self.networks[network] = area # for superclass
+ 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 _start_zebra(self):
+ if self.zapi_vserion == 2:
+ # Do nothing. supervisord will automatically start Zebra daemon.
+ return
+
+ self.local(
+ '/usr/local/sbin/zebra '
+ '-u root -g root -f {0}/zebra.conf'.format(self.SHARED_VOLUME),
+ detach=True)
+
+ def _start_ospfd(self):
+ if self.zapi_vserion == 2:
+ ospfd_cmd = '/usr/lib/quagga/ospfd'
+ else:
+ ospfd_cmd = '/usr/local/sbin/ospfd -u root -g root'
+ self.local(
+ '{0} -f {1}/ospfd.conf'.format(ospfd_cmd, self.SHARED_VOLUME),
+ detach=True)