rt: isolate report and query sched client tests

Prep for future patches that start to add placement API calls to the
scheduler "reporting" client. We simply move the unit tests of the query
and reporting clients into a new nova/tests/unit/scheduler/client/
directory.

Change-Id: I5d5de861078caf3fd9df35600a286c8877b1eb0d
This commit is contained in:
Jay Pipes 2016-08-21 20:26:33 -04:00
parent 9dcf0236b4
commit dd2b38832a
4 changed files with 101 additions and 67 deletions

View File

@ -0,0 +1,58 @@
# 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.
import mock
from nova import context
from nova import objects
from nova.scheduler.client import query
from nova import test
class SchedulerQueryClientTestCase(test.NoDBTestCase):
def setUp(self):
super(SchedulerQueryClientTestCase, self).setUp()
self.context = context.get_admin_context()
self.client = query.SchedulerQueryClient()
def test_constructor(self):
self.assertIsNotNone(self.client.scheduler_rpcapi)
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
def test_select_destinations(self, mock_select_destinations):
fake_spec = objects.RequestSpec()
self.client.select_destinations(
context=self.context,
spec_obj=fake_spec
)
mock_select_destinations.assert_called_once_with(
self.context, fake_spec)
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.update_aggregates')
def test_update_aggregates(self, mock_update_aggs):
aggregates = [objects.Aggregate(id=1)]
self.client.update_aggregates(
context=self.context,
aggregates=aggregates)
mock_update_aggs.assert_called_once_with(
self.context, aggregates)
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.delete_aggregate')
def test_delete_aggregate(self, mock_delete_agg):
aggregate = objects.Aggregate(id=1)
self.client.delete_aggregate(
context=self.context,
aggregate=aggregate)
mock_delete_agg.assert_called_once_with(
self.context, aggregate)

View File

@ -0,0 +1,43 @@
# 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.
import mock
from nova import context
from nova import objects
from nova.objects import pci_device_pool
from nova.scheduler.client import report
from nova import test
class SchedulerReportClientTestCase(test.NoDBTestCase):
def setUp(self):
super(SchedulerReportClientTestCase, self).setUp()
self.context = context.get_admin_context()
self.flags(use_local=True, group='conductor')
self.client = report.SchedulerReportClient()
@mock.patch.object(objects.ComputeNode, 'save')
def test_update_resource_stats_saves(self, mock_save):
cn = objects.ComputeNode(context=self.context)
cn.host = 'fakehost'
cn.hypervisor_hostname = 'fakenode'
cn.pci_device_pools = pci_device_pool.from_pci_stats(
[{"vendor_id": "foo",
"product_id": "foo",
"count": 1,
"a": "b"}])
self.client.update_resource_stats(cn)
mock_save.assert_called_once_with()

View File

@ -16,81 +16,14 @@
import mock
import oslo_messaging as messaging
from nova import context
from nova import objects
from nova.objects import pci_device_pool
from nova.scheduler import client as scheduler_client
from nova.scheduler.client import query as scheduler_query_client
from nova.scheduler.client import report as scheduler_report_client
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import test
"""Tests for Scheduler Client."""
class SchedulerReportClientTestCase(test.NoDBTestCase):
def setUp(self):
super(SchedulerReportClientTestCase, self).setUp()
self.context = context.get_admin_context()
self.flags(use_local=True, group='conductor')
self.client = scheduler_report_client.SchedulerReportClient()
@mock.patch.object(objects.ComputeNode, 'save')
def test_update_resource_stats_saves(self, mock_save):
cn = objects.ComputeNode(context=self.context)
cn.host = 'fakehost'
cn.hypervisor_hostname = 'fakenode'
cn.pci_device_pools = pci_device_pool.from_pci_stats(
[{"vendor_id": "foo",
"product_id": "foo",
"count": 1,
"a": "b"}])
self.client.update_resource_stats(cn)
mock_save.assert_called_once_with()
class SchedulerQueryClientTestCase(test.NoDBTestCase):
def setUp(self):
super(SchedulerQueryClientTestCase, self).setUp()
self.context = context.get_admin_context()
self.client = scheduler_query_client.SchedulerQueryClient()
def test_constructor(self):
self.assertIsNotNone(self.client.scheduler_rpcapi)
@mock.patch.object(scheduler_rpcapi.SchedulerAPI, 'select_destinations')
def test_select_destinations(self, mock_select_destinations):
fake_spec = objects.RequestSpec()
self.client.select_destinations(
context=self.context,
spec_obj=fake_spec
)
mock_select_destinations.assert_called_once_with(
self.context, fake_spec)
@mock.patch.object(scheduler_rpcapi.SchedulerAPI, 'update_aggregates')
def test_update_aggregates(self, mock_update_aggs):
aggregates = [objects.Aggregate(id=1)]
self.client.update_aggregates(
context=self.context,
aggregates=aggregates)
mock_update_aggs.assert_called_once_with(
self.context, aggregates)
@mock.patch.object(scheduler_rpcapi.SchedulerAPI, 'delete_aggregate')
def test_delete_aggregate(self, mock_delete_agg):
aggregate = objects.Aggregate(id=1)
self.client.delete_aggregate(
context=self.context,
aggregate=aggregate)
mock_delete_agg.assert_called_once_with(
self.context, aggregate)
class SchedulerClientTestCase(test.NoDBTestCase):
def setUp(self):