Merge "Remove LazyLoad of Scheduler Clients"
This commit is contained in:
commit
e7751a4b06
@ -13,38 +13,17 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import functools
|
from nova.scheduler.client import query
|
||||||
|
from nova.scheduler.client import report
|
||||||
from oslo_utils import importutils
|
|
||||||
|
|
||||||
from nova.scheduler import utils
|
from nova.scheduler import utils
|
||||||
|
|
||||||
|
|
||||||
class LazyLoader(object):
|
|
||||||
|
|
||||||
def __init__(self, klass, *args, **kwargs):
|
|
||||||
self.klass = klass
|
|
||||||
self.args = args
|
|
||||||
self.kwargs = kwargs
|
|
||||||
self.instance = None
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
return functools.partial(self.__run_method, name)
|
|
||||||
|
|
||||||
def __run_method(self, __name, *args, **kwargs):
|
|
||||||
if self.instance is None:
|
|
||||||
self.instance = self.klass(*self.args, **self.kwargs)
|
|
||||||
return getattr(self.instance, __name)(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class SchedulerClient(object):
|
class SchedulerClient(object):
|
||||||
"""Client library for placing calls to the scheduler."""
|
"""Client library for placing calls to the scheduler."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.queryclient = LazyLoader(importutils.import_class(
|
self.queryclient = query.SchedulerQueryClient()
|
||||||
'nova.scheduler.client.query.SchedulerQueryClient'))
|
self.reportclient = report.SchedulerReportClient()
|
||||||
self.reportclient = LazyLoader(importutils.import_class(
|
|
||||||
'nova.scheduler.client.report.SchedulerReportClient'))
|
|
||||||
|
|
||||||
@utils.retry_select_destinations
|
@utils.retry_select_destinations
|
||||||
def select_destinations(self, context, spec_obj, instance_uuids,
|
def select_destinations(self, context, spec_obj, instance_uuids,
|
||||||
|
@ -629,12 +629,12 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
|
|||||||
|
|
||||||
@mock.patch.object(objects.ComputeNode, 'get_by_host_and_nodename',
|
@mock.patch.object(objects.ComputeNode, 'get_by_host_and_nodename',
|
||||||
side_effect=exception.ComputeHostNotFound(host='host'))
|
side_effect=exception.ComputeHostNotFound(host='host'))
|
||||||
def test_remove_host_allocations_compute_host_not_found(self, get_cn):
|
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||||
|
'remove_provider_tree_from_instance_allocation')
|
||||||
|
def test_remove_host_allocations_compute_host_not_found(
|
||||||
|
self, remove_provider, get_cn):
|
||||||
"""Tests that failing to find a ComputeNode will not blow up
|
"""Tests that failing to find a ComputeNode will not blow up
|
||||||
the _remove_host_allocations method.
|
the _remove_host_allocations method.
|
||||||
"""
|
"""
|
||||||
with mock.patch.object(
|
|
||||||
self.task.scheduler_client.reportclient,
|
|
||||||
'remove_provider_from_instance_allocation') as remove_provider:
|
|
||||||
self.task._remove_host_allocations('host', 'node')
|
self.task._remove_host_allocations('host', 'node')
|
||||||
remove_provider.assert_not_called()
|
remove_provider.assert_not_called()
|
||||||
|
@ -40,12 +40,10 @@ class SchedulerClientTestCase(test.NoDBTestCase):
|
|||||||
def test_select_destinations(self, mock_select_destinations):
|
def test_select_destinations(self, mock_select_destinations):
|
||||||
fake_spec = objects.RequestSpec()
|
fake_spec = objects.RequestSpec()
|
||||||
fake_spec.instance_uuid = uuids.instance
|
fake_spec.instance_uuid = uuids.instance
|
||||||
self.assertIsNone(self.client.queryclient.instance)
|
|
||||||
|
|
||||||
self.client.select_destinations('ctxt', fake_spec,
|
self.client.select_destinations('ctxt', fake_spec,
|
||||||
[fake_spec.instance_uuid])
|
[fake_spec.instance_uuid])
|
||||||
|
|
||||||
self.assertIsNotNone(self.client.queryclient.instance)
|
|
||||||
mock_select_destinations.assert_called_once_with('ctxt', fake_spec,
|
mock_select_destinations.assert_called_once_with('ctxt', fake_spec,
|
||||||
[fake_spec.instance_uuid], False, False)
|
[fake_spec.instance_uuid], False, False)
|
||||||
|
|
||||||
@ -97,11 +95,8 @@ class SchedulerClientTestCase(test.NoDBTestCase):
|
|||||||
@mock.patch.object(scheduler_report_client.SchedulerReportClient,
|
@mock.patch.object(scheduler_report_client.SchedulerReportClient,
|
||||||
'update_compute_node')
|
'update_compute_node')
|
||||||
def test_update_compute_node(self, mock_update_compute_node):
|
def test_update_compute_node(self, mock_update_compute_node):
|
||||||
self.assertIsNone(self.client.reportclient.instance)
|
|
||||||
|
|
||||||
self.client.update_compute_node(mock.sentinel.ctx, mock.sentinel.cn)
|
self.client.update_compute_node(mock.sentinel.ctx, mock.sentinel.cn)
|
||||||
|
|
||||||
self.assertIsNotNone(self.client.reportclient.instance)
|
|
||||||
mock_update_compute_node.assert_called_once_with(
|
mock_update_compute_node.assert_called_once_with(
|
||||||
mock.sentinel.ctx, mock.sentinel.cn)
|
mock.sentinel.ctx, mock.sentinel.cn)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user