Coverage for nova/scheduler/rpcapi.py: 100%

51 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Copyright 2013, Red Hat, Inc. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15""" 

16Client side of the scheduler manager RPC API. 

17""" 

18 

19import oslo_messaging as messaging 

20 

21import nova.conf 

22from nova import exception as exc 

23from nova.objects import base as objects_base 

24from nova import profiler 

25from nova import rpc 

26 

27CONF = nova.conf.CONF 

28RPC_TOPIC = "scheduler" 

29 

30 

31@profiler.trace_cls("rpc") 

32class SchedulerAPI(object): 

33 '''Client side of the scheduler rpc API. 

34 

35 API version history: 

36 

37 * 1.0 - Initial version. 

38 * 1.1 - Changes to prep_resize(): 

39 * remove instance_uuid, add instance 

40 * remove instance_type_id, add instance_type 

41 * remove topic, it was unused 

42 * 1.2 - Remove topic from run_instance, it was unused 

43 * 1.3 - Remove instance_id, add instance to live_migration 

44 * 1.4 - Remove update_db from prep_resize 

45 * 1.5 - Add reservations argument to prep_resize() 

46 * 1.6 - Remove reservations argument to run_instance() 

47 * 1.7 - Add create_volume() method, remove topic from live_migration() 

48 

49 * 2.0 - Remove 1.x backwards compat 

50 * 2.1 - Add image_id to create_volume() 

51 * 2.2 - Remove reservations argument to create_volume() 

52 * 2.3 - Remove create_volume() 

53 * 2.4 - Change update_service_capabilities() 

54 * accepts a list of capabilities 

55 * 2.5 - Add get_backdoor_port() 

56 * 2.6 - Add select_hosts() 

57 

58 ... Grizzly supports message version 2.6. So, any changes to existing 

59 methods in 2.x after that point should be done such that they can 

60 handle the version_cap being set to 2.6. 

61 

62 * 2.7 - Add select_destinations() 

63 * 2.8 - Deprecate prep_resize() -- JUST KIDDING. It is still used 

64 by the compute manager for retries. 

65 * 2.9 - Added the legacy_bdm_in_spec parameter to run_instance() 

66 

67 ... Havana supports message version 2.9. So, any changes to existing 

68 methods in 2.x after that point should be done such that they can 

69 handle the version_cap being set to 2.9. 

70 

71 * Deprecated live_migration() call, moved to conductor 

72 * Deprecated select_hosts() 

73 

74 3.0 - Removed backwards compat 

75 

76 ... Icehouse and Juno support message version 3.0. So, any changes to 

77 existing methods in 3.x after that point should be done such that they 

78 can handle the version_cap being set to 3.0. 

79 

80 * 3.1 - Made select_destinations() send flavor object 

81 

82 * 4.0 - Removed backwards compat for Icehouse 

83 * 4.1 - Add update_aggregates() and delete_aggregate() 

84 * 4.2 - Added update_instance_info(), delete_instance_info(), and 

85 sync_instance_info() methods 

86 

87 ... Kilo and Liberty support message version 4.2. So, any 

88 changes to existing methods in 4.x after that point should be 

89 done such that they can handle the version_cap being set to 

90 4.2. 

91 

92 * 4.3 - Modify select_destinations() signature by providing a 

93 RequestSpec obj 

94 

95 ... Mitaka, Newton, and Ocata support message version 4.3. So, any 

96 changes to existing methods in 4.x after that point should be done such 

97 that they can handle the version_cap being set to 4.3. 

98 

99 * 4.4 - Modify select_destinations() signature by providing the 

100 instance_uuids for the request. 

101 

102 ... Pike supports message version 4.4. So any changes to existing 

103 methods in 4.x after that point should be done such 

104 that they can handle the version_cap being set to 4.4. 

105 

106 * 4.5 - Modify select_destinations() to optionally return a list of 

107 lists of Selection objects, along with zero or more alternates. 

108 ''' 

109 

110 VERSION_ALIASES = { 

111 'grizzly': '2.6', 

112 'havana': '2.9', 

113 'icehouse': '3.0', 

114 'juno': '3.0', 

115 'kilo': '4.2', 

116 'liberty': '4.2', 

117 'mitaka': '4.3', 

118 'newton': '4.3', 

119 'ocata': '4.3', 

120 'pike': '4.4', 

121 } 

122 

123 def __init__(self): 

124 super(SchedulerAPI, self).__init__() 

125 target = messaging.Target(topic=RPC_TOPIC, version='4.0') 

126 version_cap = self.VERSION_ALIASES.get(CONF.upgrade_levels.scheduler, 

127 CONF.upgrade_levels.scheduler) 

128 serializer = objects_base.NovaObjectSerializer() 

129 self.client = rpc.get_client(target, version_cap=version_cap, 

130 serializer=serializer) 

131 

132 def select_destinations(self, ctxt, spec_obj, instance_uuids, 

133 return_objects=False, return_alternates=False): 

134 # Modify the parameters if an older version is requested 

135 version = '4.5' 

136 msg_args = {'instance_uuids': instance_uuids, 

137 'spec_obj': spec_obj, 

138 'return_objects': return_objects, 

139 'return_alternates': return_alternates} 

140 if not self.client.can_send_version(version): 

141 if msg_args['return_objects'] or msg_args['return_alternates']: 

142 # The client is requesting an RPC version we can't support. 

143 raise exc.SelectionObjectsWithOldRPCVersionNotSupported( 

144 version=self.client.version_cap) 

145 del msg_args['return_objects'] 

146 del msg_args['return_alternates'] 

147 version = '4.4' 

148 if not self.client.can_send_version(version): 

149 del msg_args['instance_uuids'] 

150 version = '4.3' 

151 if not self.client.can_send_version(version): 

152 del msg_args['spec_obj'] 

153 msg_args['request_spec'] = spec_obj.to_legacy_request_spec_dict() 

154 msg_args['filter_properties' 

155 ] = spec_obj.to_legacy_filter_properties_dict() 

156 version = '4.0' 

157 cctxt = self.client.prepare( 

158 version=version, call_monitor_timeout=CONF.rpc_response_timeout, 

159 timeout=CONF.long_rpc_timeout) 

160 return cctxt.call(ctxt, 'select_destinations', **msg_args) 

161 

162 def update_aggregates(self, ctxt, aggregates): 

163 # NOTE(sbauza): Yes, it's a fanout, we need to update all schedulers 

164 cctxt = self.client.prepare(fanout=True, version='4.1') 

165 cctxt.cast(ctxt, 'update_aggregates', aggregates=aggregates) 

166 

167 def delete_aggregate(self, ctxt, aggregate): 

168 # NOTE(sbauza): Yes, it's a fanout, we need to update all schedulers 

169 cctxt = self.client.prepare(fanout=True, version='4.1') 

170 cctxt.cast(ctxt, 'delete_aggregate', aggregate=aggregate) 

171 

172 def update_instance_info(self, ctxt, host_name, instance_info): 

173 cctxt = self.client.prepare(version='4.2', fanout=True) 

174 cctxt.cast(ctxt, 'update_instance_info', host_name=host_name, 

175 instance_info=instance_info) 

176 

177 def delete_instance_info(self, ctxt, host_name, instance_uuid): 

178 cctxt = self.client.prepare(version='4.2', fanout=True) 

179 cctxt.cast(ctxt, 'delete_instance_info', host_name=host_name, 

180 instance_uuid=instance_uuid) 

181 

182 def sync_instance_info(self, ctxt, host_name, instance_uuids): 

183 cctxt = self.client.prepare(version='4.2', fanout=True) 

184 cctxt.cast(ctxt, 'sync_instance_info', host_name=host_name, 

185 instance_uuids=instance_uuids)