This adds some scenario tests using a scenario test tool.

Signed-off-by: Fumihiko Kakuma <[email protected]>
---
 ryu/tests/integrated/bgp/__init__.py       |  0
 ryu/tests/integrated/bgp/base.py           | 80 ++++++++++++++++++++++++++++++
 ryu/tests/integrated/bgp/base_ip6.py       | 80 ++++++++++++++++++++++++++++++
 ryu/tests/integrated/bgp/test_basic.py     | 47 ++++++++++++++++++
 ryu/tests/integrated/bgp/test_ip6_basic.py | 47 ++++++++++++++++++
 ryu/tests/integrated/run_test.py           | 54 ++++++++++++++++++++
 6 files changed, 308 insertions(+)
 create mode 100644 ryu/tests/integrated/bgp/__init__.py
 create mode 100644 ryu/tests/integrated/bgp/base.py
 create mode 100644 ryu/tests/integrated/bgp/base_ip6.py
 create mode 100644 ryu/tests/integrated/bgp/test_basic.py
 create mode 100644 ryu/tests/integrated/bgp/test_ip6_basic.py
 create mode 100644 ryu/tests/integrated/run_test.py

diff --git a/ryu/tests/integrated/bgp/__init__.py 
b/ryu/tests/integrated/bgp/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/ryu/tests/integrated/bgp/base.py b/ryu/tests/integrated/bgp/base.py
new file mode 100644
index 0000000..abcd914
--- /dev/null
+++ b/ryu/tests/integrated/bgp/base.py
@@ -0,0 +1,80 @@
+# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
+#
+# 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 __future__ import absolute_import
+
+import unittest
+
+from ryu.tests.integrated.common import docker_base as ctn_base
+from ryu.tests.integrated.common import ryubgp
+from ryu.tests.integrated.common import quagga
+
+
+class BgpSpeakerTestBase(unittest.TestCase):
+
+    checktime = 120
+
+    @classmethod
+    def setUpClass(cls):
+        cls.images = []
+        cls.containers = []
+        cls.bridges = []
+
+        cls.brdc1 = ctn_base.Bridge(name='brdc1',
+                                    subnet='192.168.10.0/24')
+        cls.bridges.append(cls.brdc1)
+
+        cls.dockerimg = ctn_base.DockerImage()
+        cls.r_img = cls.dockerimg.create_ryu(image='osrg/ryu',
+                                             check_exist=True)
+        cls.images.append(cls.r_img)
+        cls.q_img = 'osrg/quagga'
+        cls.images.append(cls.q_img)
+
+        cls.r1 = ryubgp.RyuBGPContainer(name='r1', asn=64512,
+                                        router_id='192.168.0.1',
+                                        ctn_image_name=cls.r_img)
+        cls.containers.append(cls.r1)
+        cls.r1.add_route('10.10.0.0/28')
+        cls.r1.run(wait=True)
+        cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
+        cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
+
+        cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
+                                           router_id='192.168.0.2',
+                                           ctn_image_name=cls.q_img)
+        cls.containers.append(cls.q1)
+        cls.q1.add_route('192.168.160.0/24')
+        cls.q1.run(wait=True)
+        cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
+        cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
+
+        cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name)
+        cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name)
+
+        super(BgpSpeakerTestBase, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        for ctn in cls.containers:
+            try:
+                ctn.stop()
+            except ctn_base.CommandError as e:
+                pass
+            ctn.remove()
+        for br in cls.bridges:
+            br.delete()
+        super(BgpSpeakerTestBase, cls).tearDownClass()
diff --git a/ryu/tests/integrated/bgp/base_ip6.py 
b/ryu/tests/integrated/bgp/base_ip6.py
new file mode 100644
index 0000000..858a1ae
--- /dev/null
+++ b/ryu/tests/integrated/bgp/base_ip6.py
@@ -0,0 +1,80 @@
+# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
+#
+# 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 __future__ import absolute_import
+
+import unittest
+
+from ryu.tests.integrated.common import docker_base as ctn_base
+from ryu.tests.integrated.common import ryubgp
+from ryu.tests.integrated.common import quagga
+
+
+class BgpSpeakerTestBase(unittest.TestCase):
+
+    checktime = 120
+
+    @classmethod
+    def setUpClass(cls):
+        cls.images = []
+        cls.containers = []
+        cls.bridges = []
+
+        cls.brdc1 = ctn_base.Bridge(name='brip6dc1',
+                                    subnet='2001:10::/32')
+        cls.bridges.append(cls.brdc1)
+
+        cls.dockerimg = ctn_base.DockerImage()
+        cls.r_img = cls.dockerimg.create_ryu(image='osrg/ryu',
+                                             check_exist=True)
+        cls.images.append(cls.r_img)
+        cls.q_img = 'osrg/quagga'
+        cls.images.append(cls.q_img)
+
+        cls.r1 = ryubgp.RyuBGPContainer(name='r1', asn=64512,
+                                        router_id='192.168.0.1',
+                                        ctn_image_name=cls.r_img)
+        cls.containers.append(cls.r1)
+        cls.r1.add_route('fc00:10::/64', route_info={'rf': 'ipv6'})
+        cls.r1.run(wait=True)
+        cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
+        cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
+
+        cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
+                                           router_id='192.168.0.2',
+                                           ctn_image_name=cls.q_img)
+        cls.containers.append(cls.q1)
+        cls.q1.add_route('fc00:100::/64', route_info={'rf': 'ipv6'})
+        cls.q1.run(wait=True)
+        cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
+        cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
+
+        cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name, v6=True)
+        cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name, v6=True)
+
+        super(BgpSpeakerTestBase, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        for ctn in cls.containers:
+            try:
+                ctn.stop()
+            except ctn_base.CommandError as e:
+                pass
+            ctn.remove()
+        for br in cls.bridges:
+            br.delete()
+        super(BgpSpeakerTestBase, cls).tearDownClass()
diff --git a/ryu/tests/integrated/bgp/test_basic.py 
b/ryu/tests/integrated/bgp/test_basic.py
new file mode 100644
index 0000000..6321191
--- /dev/null
+++ b/ryu/tests/integrated/bgp/test_basic.py
@@ -0,0 +1,47 @@
+# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
+#
+# 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 __future__ import absolute_import
+
+import time
+
+from . import base
+from ryu.tests.integrated.common import docker_base as ctn_base
+
+
+class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
+    def setUp(self):
+        super(BgpSpeakerBasicTest, self).setUp()
+        self.r1.stop_ryubgp(retry=True)
+        self.r1.start_ryubgp(retry=True)
+
+    def test_check_neighbor_established(self):
+        for i in range(0, self.checktime):
+            neighbor_state = self.q1.get_neighbor_state(self.r1)
+            if neighbor_state == ctn_base.BGP_FSM_ESTABLISHED:
+                break
+            time.sleep(1)
+        self.assertEqual(neighbor_state, ctn_base.BGP_FSM_ESTABLISHED)
+
+    def test_check_rib_nexthop(self):
+        for i in range(0, self.checktime):
+            neighbor_state = self.q1.get_neighbor_state(self.r1)
+            if neighbor_state == ctn_base.BGP_FSM_ESTABLISHED:
+                break
+            time.sleep(1)
+        self.assertEqual(neighbor_state, ctn_base.BGP_FSM_ESTABLISHED)
+        rib = self.q1.get_global_rib(prefix='10.10.0.0/28')
+        self.assertEqual(self.r1_ip, rib[0]['nexthop'])
diff --git a/ryu/tests/integrated/bgp/test_ip6_basic.py 
b/ryu/tests/integrated/bgp/test_ip6_basic.py
new file mode 100644
index 0000000..9b27e3c
--- /dev/null
+++ b/ryu/tests/integrated/bgp/test_ip6_basic.py
@@ -0,0 +1,47 @@
+# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
+#
+# 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 __future__ import absolute_import
+
+import time
+
+from . import base_ip6 as base
+from ryu.tests.integrated.common import docker_base as ctn_base
+
+
+class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
+    def setUp(self):
+        super(BgpSpeakerBasicTest, self).setUp()
+        self.r1.stop_ryubgp(retry=True)
+        self.r1.start_ryubgp(retry=True)
+
+    def test_check_neighbor_established(self):
+        for i in range(0, self.checktime):
+            neighbor_state = self.q1.get_neighbor_state(self.r1)
+            if neighbor_state == ctn_base.BGP_FSM_ESTABLISHED:
+                break
+            time.sleep(1)
+        self.assertEqual(neighbor_state, ctn_base.BGP_FSM_ESTABLISHED)
+
+    def test_check_rib_nexthop(self):
+        for i in range(0, self.checktime):
+            neighbor_state = self.q1.get_neighbor_state(self.r1)
+            if neighbor_state == ctn_base.BGP_FSM_ESTABLISHED:
+                break
+            time.sleep(1)
+        self.assertEqual(neighbor_state, ctn_base.BGP_FSM_ESTABLISHED)
+        rib = self.q1.get_global_rib(prefix='fc00:10::/64', rf='ipv6')
+        self.assertEqual(self.r1_ip, rib[0]['nexthop'])
diff --git a/ryu/tests/integrated/run_test.py b/ryu/tests/integrated/run_test.py
new file mode 100644
index 0000000..2aca03d
--- /dev/null
+++ b/ryu/tests/integrated/run_test.py
@@ -0,0 +1,54 @@
+# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2016 Fumihiko Kakuma <kakuma at valinux co jp>
+#
+# 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 __future__ import absolute_import
+
+import logging
+import os
+import sys
+import unittest
+
+from ryu import log
+
+
+def load_tests(loader, tests, pattern):
+    dirname = os.path.dirname(os.path.abspath(__file__))
+    base_path = os.path.abspath(dirname + '/../../..')
+    suite = unittest.TestSuite()
+    for test_dir in ['ryu/tests/integrated/bgp']:
+        if not pattern:
+            suite.addTests(loader.discover(test_dir,
+                                           top_level_dir=base_path))
+        else:
+            suite.addTests(loader.discover(test_dir, pattern=pattern,
+                                           top_level_dir=base_path))
+    return suite
+
+
+if __name__ == '__main__':
+    log.early_init_log(logging.DEBUG)
+    log.init_log()
+    LOG = logging.getLogger(__name__)
+    pattern = None
+    if len(sys.argv) == 2:
+        pattern = sys.argv[1]
+    loader = unittest.defaultTestLoader
+    suite = load_tests(loader, None, pattern)
+    res = unittest.TextTestRunner(verbosity=2).run(suite)
+    ret = 0
+    if res.errors or res.failures:
+        ret = 1
+    sys.exit(ret)
-- 
1.9.1


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to