From e8563aada44532c7d54ce73461dff84bc9d6ca30 Mon Sep 17 00:00:00 2001 From: xiulin yin Date: Mon, 13 Feb 2017 11:42:33 +0800 Subject: [PATCH] Add get bottom_id by top_id and region_name test case 1. What is the problem Tricircle does not have get bottom id by top_id and region_name test case 2. What is the solution to the problem Implement related test case 3. What the features need to be implemented to the Tricircle No new features Change-Id: I0ec873f16ff596c28e4c517d6790a3cc1d5f13df --- tricircle/tests/unit/db/test_api.py | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tricircle/tests/unit/db/test_api.py b/tricircle/tests/unit/db/test_api.py index 62b8d168..045ebc8e 100644 --- a/tricircle/tests/unit/db/test_api.py +++ b/tricircle/tests/unit/db/test_api.py @@ -39,12 +39,7 @@ class APITest(unittest.TestCase): } api.create_pod(self.context, pod_body) - def test_get_bottom_mappings_by_top_id(self): - for i in xrange(3): - pod = {'pod_id': 'test_pod_uuid_%d' % i, - 'region_name': 'test_pod_%d' % i, - 'az_name': 'test_az_uuid_%d' % i} - api.create_pod(self.context, pod) + def _create_resource_mappings(self): route1 = { 'top_id': 'top_uuid', 'pod_id': 'test_pod_uuid_0', @@ -59,11 +54,35 @@ class APITest(unittest.TestCase): 'pod_id': 'test_pod_uuid_2', 'bottom_id': 'bottom_uuid_2', 'resource_type': 'neutron'} + routes = [route1, route2, route3] with self.context.session.begin(): for route in routes: core.create_resource( self.context, models.ResourceRouting, route) + + def test_get_bottom_id_by_top_id_region_name(self): + self._create_pod(0, 'test_az_uuid_0') + self._create_pod(1, 'test_az_uuid_1') + self._create_pod(2, 'test_az_uuid_2') + self._create_resource_mappings() + region_name = 'test_pod_0' + bottom_id = api.get_bottom_id_by_top_id_region_name( + self.context, 'top_uuid', region_name, 'port') + self.assertIsNone(bottom_id) + + region_name = 'test_pod_1' + bottom_id = api.get_bottom_id_by_top_id_region_name( + self.context, 'top_uuid', region_name, 'port') + self.assertEqual(bottom_id, 'bottom_uuid_1') + + def test_get_bottom_mappings_by_top_id(self): + for i in xrange(3): + pod = {'pod_id': 'test_pod_uuid_%d' % i, + 'region_name': 'test_pod_%d' % i, + 'az_name': 'test_az_uuid_%d' % i} + api.create_pod(self.context, pod) + self._create_resource_mappings() mappings = api.get_bottom_mappings_by_top_id(self.context, 'top_uuid', 'port') self.assertEqual('test_pod_uuid_1', mappings[0][0]['pod_id'])