diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-11-09 14:13:39 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-11-11 00:47:17 +0900 |
commit | 660b38e5aecfec22563b90f43e0ed7a99bb4cc0d (patch) | |
tree | 4f2a57c75bfc1a0a5b55450ae1645faf1dcd4954 /test/lib/bird.py | |
parent | 34bd365bb4534f2321acea686996e2293727923c (diff) |
test: add BIRD for performance test target
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test/lib/bird.py')
-rw-r--r-- | test/lib/bird.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/lib/bird.py b/test/lib/bird.py new file mode 100644 index 00000000..c08a381c --- /dev/null +++ b/test/lib/bird.py @@ -0,0 +1,78 @@ +# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from base import * + +class BirdContainer(BGPContainer): + + WAIT_FOR_BOOT = 1 + SHARED_VOLUME = '/etc/bird' + + def __init__(self, name, asn, router_id, ctn_image_name='osrg/bird'): + super(BirdContainer, self).__init__(name, asn, router_id, + ctn_image_name) + self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME)) + + def _start_bird(self): + c = CmdBuffer() + c << '#!/bin/bash' + c << 'bird' + cmd = 'echo "{0:s}" > {1}/start.sh'.format(c, self.config_dir) + local(cmd) + cmd = 'chmod 755 {0}/start.sh'.format(self.config_dir) + local(cmd) + self.local('{0}/start.sh'.format(self.SHARED_VOLUME)) + + def run(self): + super(BirdContainer, self).run() + self.reload_config() + return self.WAIT_FOR_BOOT + + def create_config(self): + c = CmdBuffer() + c << 'router id {0};'.format(self.router_id) + for peer, info in self.peers.iteritems(): + c << 'protocol bgp {' + c << ' local as {0};'.format(self.asn) + n_addr = info['neigh_addr'].split('/')[0] + c << ' neighbor {0} as {1};'.format(n_addr, peer.asn) + c << ' multihop;' + c << '}' + + with open('{0}/bird.conf'.format(self.config_dir), 'w') as f: + print colors.yellow('[{0}\'s new config]'.format(self.name)) + print colors.yellow(indent(str(c))) + f.writelines(str(c)) + + def reload_config(self): + if len(self.peers) == 0: + return + + def _reload(): + def _is_running(): + ps = self.local('ps', capture=True) + running = False + for line in ps.split('\n')[1:]: + if 'bird' in line: + running = True + return running + if _is_running(): + self.local('birdc configure') + else: + self._start_bird() + time.sleep(1) + if not _is_running(): + raise RuntimeError() + try_several_times(_reload) |