backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / integrated / bgp / base.py
1 # Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 from __future__ import absolute_import
18
19 import logging
20 import sys
21 import unittest
22
23 from ryu.tests.integrated.common import docker_base as ctn_base
24 from ryu.tests.integrated.common import ryubgp
25 from ryu.tests.integrated.common import quagga
26
27
28 LOG = logging.getLogger(__name__)
29
30
31 class BgpSpeakerTestBase(unittest.TestCase):
32     images = []
33     containers = []
34     bridges = []
35     checktime = 120
36
37     @classmethod
38     def setUpClass(cls):
39         cls.brdc1 = ctn_base.Bridge(name='brdc1',
40                                     subnet='192.168.10.0/24')
41         cls.bridges.append(cls.brdc1)
42
43         cls.dockerimg = ctn_base.DockerImage()
44         image = 'python:%d.%d' % (
45             sys.version_info.major, sys.version_info.minor)
46         cls.r_img = cls.dockerimg.create_ryu(image=image, check_exist=True)
47         cls.images.append(cls.r_img)
48         cls.q_img = 'osrg/quagga'
49         cls.images.append(cls.q_img)
50
51         cls.r1 = ryubgp.RyuBGPContainer(name='r1', asn=64512,
52                                         router_id='192.168.0.1',
53                                         ctn_image_name=cls.r_img)
54         cls.containers.append(cls.r1)
55         cls.r1.add_route('10.10.0.0/28')
56         cls.r1.run(wait=True)
57         cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
58         cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
59
60         cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
61                                            router_id='192.168.0.2',
62                                            ctn_image_name=cls.q_img)
63         cls.containers.append(cls.q1)
64         cls.q1.add_route('192.168.160.0/24')
65         cls.q1.run(wait=True)
66         cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
67         cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
68
69         cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name)
70         cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name)
71
72         super(BgpSpeakerTestBase, cls).setUpClass()
73
74     @classmethod
75     def tearDownClass(cls):
76         for ctn in cls.containers:
77             try:
78                 ctn.stop()
79             except ctn_base.CommandError as e:
80                 LOG.exception('Exception when stopping containers: %s', e)
81             ctn.remove()
82         for br in cls.bridges:
83             br.delete()
84         super(BgpSpeakerTestBase, cls).tearDownClass()