1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Unit Tests for nova.scheduler.rpcapi
21
from nova import context
22
from nova import flags
24
from nova.scheduler import rpcapi as scheduler_rpcapi
31
class SchedulerRpcAPITestCase(test.TestCase):
34
super(SchedulerRpcAPITestCase, self).setUp()
37
super(SchedulerRpcAPITestCase, self).tearDown()
39
def _test_scheduler_api(self, method, rpc_method, **kwargs):
40
ctxt = context.RequestContext('fake_user', 'fake_project')
41
rpcapi = scheduler_rpcapi.SchedulerAPI()
42
expected_retval = 'foo' if method == 'call' else None
43
expected_msg = rpcapi.make_msg(method, **kwargs)
44
expected_msg['version'] = rpcapi.RPC_API_VERSION
45
if rpc_method == 'cast' and method == 'run_instance':
46
kwargs['call'] = False
49
self.fake_kwargs = None
51
def _fake_rpc_method(*args, **kwargs):
53
self.fake_kwargs = kwargs
55
return expected_retval
57
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
59
retval = getattr(rpcapi, method)(ctxt, **kwargs)
61
self.assertEqual(retval, expected_retval)
62
expected_args = [ctxt, FLAGS.scheduler_topic, expected_msg]
63
for arg, expected_arg in zip(self.fake_args, expected_args):
64
self.assertEqual(arg, expected_arg)
66
def test_run_instance_call(self):
67
self._test_scheduler_api('run_instance', rpc_method='call',
68
topic='fake_topic', request_spec='fake_request_spec',
69
admin_password='pw', injected_files='fake_injected_files',
70
requested_networks='fake_requested_networks',
71
is_first_time=True, filter_properties='fake_filter_properties')
73
def test_run_instance_cast(self):
74
self._test_scheduler_api('run_instance', rpc_method='cast',
75
topic='fake_topic', request_spec='fake_request_spec',
76
admin_password='pw', injected_files='fake_injected_files',
77
requested_networks='fake_requested_networks',
78
is_first_time=True, filter_properties='fake_filter_properties')
80
def test_prep_resize(self):
81
self._test_scheduler_api('prep_resize', rpc_method='cast',
82
topic='fake_topic', instance_uuid='fake_uuid',
83
instance_type_id='fake_type_id', image='fake_image',
84
update_db='fake_update_db', request_spec='fake_request_spec',
85
filter_properties='fake_props')
87
def test_show_host_resources(self):
88
self._test_scheduler_api('show_host_resources', rpc_method='call',
91
def test_live_migration(self):
92
self._test_scheduler_api('live_migration', rpc_method='call',
93
block_migration='fake_block_migration',
94
disk_over_commit='fake_disk_over_commit',
95
instance_id='fake_id', dest='fake_dest', topic='fake_topic')
97
def test_update_service_capabilities(self):
98
self._test_scheduler_api('update_service_capabilities',
99
rpc_method='fanout_cast', service_name='fake_name',
100
host='fake_host', capabilities='fake_capabilities')
102
def test_get_host_list(self):
103
self._test_scheduler_api('get_host_list', rpc_method='call')