Merge "Fix get_pod_by_top_id method in common.utils"
This commit is contained in:
commit
fcd1b661d6
@ -22,7 +22,6 @@ from oslo_log import log as logging
|
||||
from tricircle.common import client
|
||||
from tricircle.common import constants as cons
|
||||
from tricircle.common.i18n import _LE
|
||||
from tricircle.common import utils
|
||||
from tricircle.db import api as db_api
|
||||
|
||||
|
||||
@ -162,7 +161,7 @@ def get_res_routing_ref(context, _id, t_url, s_type):
|
||||
:param s_type: service type
|
||||
:returns: service context
|
||||
"""
|
||||
pod = utils.get_pod_by_top_id(context, _id)
|
||||
pod = db_api.get_pod_by_top_id(context, _id)
|
||||
|
||||
if not pod:
|
||||
return None
|
||||
|
@ -22,7 +22,6 @@ from oslo_utils import uuidutils
|
||||
from tricircle.common import constants as cons
|
||||
import tricircle.common.exceptions as t_exceptions
|
||||
from tricircle.common.i18n import _
|
||||
import tricircle.db.api as db_api
|
||||
|
||||
|
||||
def get_import_path(cls):
|
||||
@ -166,19 +165,3 @@ def format_nova_error(code, message, error_type=None):
|
||||
|
||||
def format_cinder_error(code, message, error_type=None):
|
||||
return format_error(code, message, error_type)
|
||||
|
||||
|
||||
def get_pod_by_top_id(context, _id):
|
||||
"""Get pod resource from pod table .
|
||||
|
||||
:param _id: the top id of resource
|
||||
:returns: pod resource
|
||||
"""
|
||||
mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
context, _id,
|
||||
cons.RT_VOLUME)
|
||||
|
||||
if not mappings or len(mappings) != 1:
|
||||
return None
|
||||
|
||||
return mappings[0][0]
|
||||
|
@ -179,6 +179,25 @@ def delete_pre_created_resource_mapping(context, name):
|
||||
entries[0]['id'])
|
||||
|
||||
|
||||
def get_pod_by_top_id(context, _id):
|
||||
"""Get pod resource from pod table by top id of resource
|
||||
|
||||
:param context: context object
|
||||
:param _id: the top id of resource
|
||||
:returns: pod resource
|
||||
"""
|
||||
route_filters = [{'key': 'top_id', 'comparator': 'eq', 'value': _id}]
|
||||
with context.session.begin():
|
||||
routes = core.query_resource(
|
||||
context, models.ResourceRouting, route_filters, [])
|
||||
if not routes or len(routes) != 1:
|
||||
return None
|
||||
route = routes[0]
|
||||
if not route['bottom_id']:
|
||||
return None
|
||||
return core.get_resource(context, models.Pod, route['pod_id'])
|
||||
|
||||
|
||||
def get_bottom_id_by_top_id_region_name(context, top_id,
|
||||
region_name, resource_type):
|
||||
"""Get resource bottom id by top id and bottom pod name
|
||||
|
@ -183,6 +183,53 @@ class APITest(unittest.TestCase):
|
||||
self.assertEqual(routings['top_uuid_3']['top_id'], 'top_uuid_3')
|
||||
self.assertEqual(routings['top_uuid_3']['bottom_id'], 'top_uuid_3')
|
||||
|
||||
def test_get_pod_by_top_id(self):
|
||||
self._create_pod(1, 'test_az_uuid1')
|
||||
self._create_pod(2, 'test_az_uuid2')
|
||||
routes = [
|
||||
{
|
||||
'top_id': 'top_uuid_1',
|
||||
'bottom_id': 'bottom_uuid_1',
|
||||
'pod_id': 'test_pod_uuid_1',
|
||||
'project_id': 'test_project_uuid_1',
|
||||
'resource_type': 'port'
|
||||
},
|
||||
{
|
||||
'top_id': 'top_uuid_2',
|
||||
'bottom_id': 'bottom_uuid_2-1',
|
||||
'pod_id': 'test_pod_uuid_1',
|
||||
'project_id': 'test_project_uuid_1',
|
||||
'resource_type': 'network'
|
||||
},
|
||||
{
|
||||
'top_id': 'top_uuid_2',
|
||||
'bottom_id': 'bottom_uuid_2-2',
|
||||
'pod_id': 'test_pod_uuid_2',
|
||||
'project_id': 'test_project_uuid_1',
|
||||
'resource_type': 'network'
|
||||
},
|
||||
{
|
||||
'top_id': 'top_uuid_3',
|
||||
'bottom_id': '',
|
||||
'pod_id': 'test_pod_uuid_1',
|
||||
'project_id': 'test_project_uuid_1',
|
||||
'resource_type': 'port'
|
||||
}
|
||||
]
|
||||
|
||||
with self.context.session.begin():
|
||||
for route in routes:
|
||||
core.create_resource(
|
||||
self.context, models.ResourceRouting, route)
|
||||
pod = api.get_pod_by_top_id(self.context, 'top_uuid_1')
|
||||
self.assertEqual(pod['pod_id'], 'test_pod_uuid_1')
|
||||
pod = api.get_pod_by_top_id(self.context, 'top_uuid_2')
|
||||
# more than one routing entries found, method returns None
|
||||
self.assertIsNone(pod)
|
||||
pod = api.get_pod_by_top_id(self.context, 'top_uuid_3')
|
||||
# bottom_id is empty, method returns None
|
||||
self.assertIsNone(pod)
|
||||
|
||||
def test_get_next_bottom_pod(self):
|
||||
next_pod = api.get_next_bottom_pod(self.context)
|
||||
self.assertIsNone(next_pod)
|
||||
|
Loading…
x
Reference in New Issue
Block a user