Merge "Clean up ClientRouter debt"

This commit is contained in:
Jenkins
2017-04-25 23:24:22 +00:00
committed by Gerrit Code Review
4 changed files with 84 additions and 168 deletions

View File

@@ -400,7 +400,7 @@ class ComputeAPI(object):
:param host: This is the host to send the message to. :param host: This is the host to send the message to.
''' '''
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'add_aggregate_host', cctxt.cast(ctxt, 'add_aggregate_host',
aggregate=aggregate, host=host_param, aggregate=aggregate, host=host_param,
@@ -408,7 +408,7 @@ class ComputeAPI(object):
def add_fixed_ip_to_instance(self, ctxt, instance, network_id): def add_fixed_ip_to_instance(self, ctxt, instance, network_id):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'add_fixed_ip_to_instance', cctxt.cast(ctxt, 'add_fixed_ip_to_instance',
instance=instance, network_id=network_id) instance=instance, network_id=network_id)
@@ -416,7 +416,7 @@ class ComputeAPI(object):
def attach_interface(self, ctxt, instance, network_id, port_id, def attach_interface(self, ctxt, instance, network_id, port_id,
requested_ip): requested_ip):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'attach_interface', return cctxt.call(ctxt, 'attach_interface',
instance=instance, network_id=network_id, instance=instance, network_id=network_id,
@@ -424,13 +424,13 @@ class ComputeAPI(object):
def attach_volume(self, ctxt, instance, bdm): def attach_volume(self, ctxt, instance, bdm):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'attach_volume', instance=instance, bdm=bdm) cctxt.cast(ctxt, 'attach_volume', instance=instance, bdm=bdm)
def change_instance_metadata(self, ctxt, instance, diff): def change_instance_metadata(self, ctxt, instance, diff):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'change_instance_metadata', cctxt.cast(ctxt, 'change_instance_metadata',
instance=instance, diff=diff) instance=instance, diff=diff)
@@ -438,7 +438,7 @@ class ComputeAPI(object):
def check_can_live_migrate_destination(self, ctxt, instance, destination, def check_can_live_migrate_destination(self, ctxt, instance, destination,
block_migration, disk_over_commit): block_migration, disk_over_commit):
version = '4.11' version = '4.11'
client = self.router.by_host(ctxt, destination) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
# NOTE(eliqiao): This is a new feature that is only available # NOTE(eliqiao): This is a new feature that is only available
# once all compute nodes support at least version 4.11. # once all compute nodes support at least version 4.11.
@@ -466,7 +466,7 @@ class ComputeAPI(object):
def check_can_live_migrate_source(self, ctxt, instance, dest_check_data): def check_can_live_migrate_source(self, ctxt, instance, dest_check_data):
dest_check_data_obj = dest_check_data dest_check_data_obj = dest_check_data
version = '4.8' version = '4.8'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
if dest_check_data: if dest_check_data:
@@ -486,11 +486,7 @@ class ComputeAPI(object):
def check_instance_shared_storage(self, ctxt, instance, data, host=None): def check_instance_shared_storage(self, ctxt, instance, data, host=None):
version = '4.0' version = '4.0'
if not host: cctxt = self.router.client(ctxt).prepare(
client = self.router.by_instance(ctxt, instance)
else:
client = self.router.by_host(ctxt, host)
cctxt = client.prepare(
server=_compute_host(host, instance), version=version) server=_compute_host(host, instance), version=version)
return cctxt.call(ctxt, 'check_instance_shared_storage', return cctxt.call(ctxt, 'check_instance_shared_storage',
instance=instance, instance=instance,
@@ -499,11 +495,7 @@ class ComputeAPI(object):
def confirm_resize(self, ctxt, instance, migration, host, def confirm_resize(self, ctxt, instance, migration, host,
reservations=None, cast=True): reservations=None, cast=True):
version = '4.0' version = '4.0'
if not host: cctxt = self.router.client(ctxt).prepare(
client = self.router.by_instance(ctxt, instance)
else:
client = self.router.by_host(ctxt, host)
cctxt = client.prepare(
server=_compute_host(host, instance), version=version) server=_compute_host(host, instance), version=version)
rpc_method = cctxt.cast if cast else cctxt.call rpc_method = cctxt.cast if cast else cctxt.call
return rpc_method(ctxt, 'confirm_resize', return rpc_method(ctxt, 'confirm_resize',
@@ -512,7 +504,7 @@ class ComputeAPI(object):
def detach_interface(self, ctxt, instance, port_id): def detach_interface(self, ctxt, instance, port_id):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'detach_interface', cctxt.cast(ctxt, 'detach_interface',
instance=instance, port_id=port_id) instance=instance, port_id=port_id)
@@ -520,7 +512,7 @@ class ComputeAPI(object):
def detach_volume(self, ctxt, instance, volume_id, attachment_id=None): def detach_volume(self, ctxt, instance, volume_id, attachment_id=None):
extra = {'attachment_id': attachment_id} extra = {'attachment_id': attachment_id}
version = '4.7' version = '4.7'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
extra.pop('attachment_id') extra.pop('attachment_id')
@@ -532,7 +524,7 @@ class ComputeAPI(object):
def finish_resize(self, ctxt, instance, migration, image, disk_info, def finish_resize(self, ctxt, instance, migration, image, disk_info,
host, reservations=None): host, reservations=None):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'finish_resize', cctxt.cast(ctxt, 'finish_resize',
instance=instance, migration=migration, instance=instance, migration=migration,
@@ -541,7 +533,7 @@ class ComputeAPI(object):
def finish_revert_resize(self, ctxt, instance, migration, host, def finish_revert_resize(self, ctxt, instance, migration, host,
reservations=None): reservations=None):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'finish_revert_resize', cctxt.cast(ctxt, 'finish_revert_resize',
instance=instance, migration=migration, instance=instance, migration=migration,
@@ -549,33 +541,33 @@ class ComputeAPI(object):
def get_console_output(self, ctxt, instance, tail_length): def get_console_output(self, ctxt, instance, tail_length):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_console_output', return cctxt.call(ctxt, 'get_console_output',
instance=instance, tail_length=tail_length) instance=instance, tail_length=tail_length)
def get_console_pool_info(self, ctxt, host, console_type): def get_console_pool_info(self, ctxt, host, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'get_console_pool_info', return cctxt.call(ctxt, 'get_console_pool_info',
console_type=console_type) console_type=console_type)
def get_console_topic(self, ctxt, host): def get_console_topic(self, ctxt, host):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'get_console_topic') return cctxt.call(ctxt, 'get_console_topic')
def get_diagnostics(self, ctxt, instance): def get_diagnostics(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_diagnostics', instance=instance) return cctxt.call(ctxt, 'get_diagnostics', instance=instance)
def get_instance_diagnostics(self, ctxt, instance): def get_instance_diagnostics(self, ctxt, instance):
version = '4.13' version = '4.13'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
instance = objects_base.obj_to_primitive(instance) instance = objects_base.obj_to_primitive(instance)
@@ -585,42 +577,42 @@ class ComputeAPI(object):
def get_vnc_console(self, ctxt, instance, console_type): def get_vnc_console(self, ctxt, instance, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_vnc_console', return cctxt.call(ctxt, 'get_vnc_console',
instance=instance, console_type=console_type) instance=instance, console_type=console_type)
def get_spice_console(self, ctxt, instance, console_type): def get_spice_console(self, ctxt, instance, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_spice_console', return cctxt.call(ctxt, 'get_spice_console',
instance=instance, console_type=console_type) instance=instance, console_type=console_type)
def get_rdp_console(self, ctxt, instance, console_type): def get_rdp_console(self, ctxt, instance, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_rdp_console', return cctxt.call(ctxt, 'get_rdp_console',
instance=instance, console_type=console_type) instance=instance, console_type=console_type)
def get_mks_console(self, ctxt, instance, console_type): def get_mks_console(self, ctxt, instance, console_type):
version = '4.3' version = '4.3'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_mks_console', return cctxt.call(ctxt, 'get_mks_console',
instance=instance, console_type=console_type) instance=instance, console_type=console_type)
def get_serial_console(self, ctxt, instance, console_type): def get_serial_console(self, ctxt, instance, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'get_serial_console', return cctxt.call(ctxt, 'get_serial_console',
instance=instance, console_type=console_type) instance=instance, console_type=console_type)
def validate_console_port(self, ctxt, instance, port, console_type): def validate_console_port(self, ctxt, instance, port, console_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'validate_console_port', return cctxt.call(ctxt, 'validate_console_port',
instance=instance, port=port, instance=instance, port=port,
@@ -636,20 +628,20 @@ class ComputeAPI(object):
:param host: This is the host to send the message to. :param host: This is the host to send the message to.
''' '''
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'host_maintenance_mode', return cctxt.call(ctxt, 'host_maintenance_mode',
host=host_param, mode=mode) host=host_param, mode=mode)
def host_power_action(self, ctxt, host, action): def host_power_action(self, ctxt, host, action):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'host_power_action', action=action) return cctxt.call(ctxt, 'host_power_action', action=action)
def inject_network_info(self, ctxt, instance): def inject_network_info(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'inject_network_info', instance=instance) cctxt.cast(ctxt, 'inject_network_info', instance=instance)
@@ -657,7 +649,7 @@ class ComputeAPI(object):
migration, migrate_data=None): migration, migrate_data=None):
args = {'migration': migration} args = {'migration': migration}
version = '4.8' version = '4.8'
client = self.router.by_host(ctxt, host) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.2' version = '4.2'
if migrate_data: if migrate_data:
@@ -674,10 +666,7 @@ class ComputeAPI(object):
def live_migration_force_complete(self, ctxt, instance, migration): def live_migration_force_complete(self, ctxt, instance, migration):
version = '4.12' version = '4.12'
kwargs = {} kwargs = {}
if not migration.source_compute: client = self.router.client(ctxt)
client = self.router.by_instance(ctxt, instance)
else:
client = self.router.by_host(ctxt, migration.source_compute)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.9' version = '4.9'
kwargs['migration_id'] = migration.id kwargs['migration_id'] = migration.id
@@ -689,21 +678,21 @@ class ComputeAPI(object):
def live_migration_abort(self, ctxt, instance, migration_id): def live_migration_abort(self, ctxt, instance, migration_id):
version = '4.10' version = '4.10'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'live_migration_abort', instance=instance, cctxt.cast(ctxt, 'live_migration_abort', instance=instance,
migration_id=migration_id) migration_id=migration_id)
def pause_instance(self, ctxt, instance): def pause_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'pause_instance', instance=instance) cctxt.cast(ctxt, 'pause_instance', instance=instance)
def post_live_migration_at_destination(self, ctxt, instance, def post_live_migration_at_destination(self, ctxt, instance,
block_migration, host): block_migration, host):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'post_live_migration_at_destination', return cctxt.call(ctxt, 'post_live_migration_at_destination',
instance=instance, block_migration=block_migration) instance=instance, block_migration=block_migration)
@@ -712,7 +701,7 @@ class ComputeAPI(object):
host, migrate_data=None): host, migrate_data=None):
migrate_data_orig = migrate_data migrate_data_orig = migrate_data
version = '4.8' version = '4.8'
client = self.router.by_host(ctxt, host) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
if migrate_data: if migrate_data:
@@ -745,7 +734,7 @@ class ComputeAPI(object):
'node': node, 'node': node,
'clean_shutdown': clean_shutdown} 'clean_shutdown': clean_shutdown}
version = '4.1' version = '4.1'
client = self.router.by_host(ctxt, host) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
msg_args['instance_type'] = objects_base.obj_to_primitive( msg_args['instance_type'] = objects_base.obj_to_primitive(
@@ -756,7 +745,7 @@ class ComputeAPI(object):
def reboot_instance(self, ctxt, instance, block_device_info, def reboot_instance(self, ctxt, instance, block_device_info,
reboot_type): reboot_type):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'reboot_instance', cctxt.cast(ctxt, 'reboot_instance',
instance=instance, instance=instance,
@@ -775,10 +764,7 @@ class ComputeAPI(object):
'scheduled_node': node, 'scheduled_node': node,
'limits': limits} 'limits': limits}
version = '4.5' version = '4.5'
if not host: client = self.router.client(ctxt)
client = self.router.by_instance(ctxt, instance)
else:
client = self.router.by_host(ctxt, host)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
extra.pop('migration') extra.pop('migration')
@@ -805,7 +791,7 @@ class ComputeAPI(object):
:param host: This is the host to send the message to. :param host: This is the host to send the message to.
''' '''
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'remove_aggregate_host', cctxt.cast(ctxt, 'remove_aggregate_host',
aggregate=aggregate, host=host_param, aggregate=aggregate, host=host_param,
@@ -813,14 +799,14 @@ class ComputeAPI(object):
def remove_fixed_ip_from_instance(self, ctxt, instance, address): def remove_fixed_ip_from_instance(self, ctxt, instance, address):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'remove_fixed_ip_from_instance', cctxt.cast(ctxt, 'remove_fixed_ip_from_instance',
instance=instance, address=address) instance=instance, address=address)
def remove_volume_connection(self, ctxt, instance, volume_id, host): def remove_volume_connection(self, ctxt, instance, volume_id, host):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'remove_volume_connection', return cctxt.call(ctxt, 'remove_volume_connection',
instance=instance, volume_id=volume_id) instance=instance, volume_id=volume_id)
@@ -833,13 +819,13 @@ class ComputeAPI(object):
'rescue_image_ref': rescue_image_ref, 'rescue_image_ref': rescue_image_ref,
'instance': instance, 'instance': instance,
} }
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'rescue_instance', **msg_args) cctxt.cast(ctxt, 'rescue_instance', **msg_args)
def reset_network(self, ctxt, instance): def reset_network(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'reset_network', instance=instance) cctxt.cast(ctxt, 'reset_network', instance=instance)
@@ -851,7 +837,7 @@ class ComputeAPI(object):
'clean_shutdown': clean_shutdown, 'clean_shutdown': clean_shutdown,
} }
version = '4.1' version = '4.1'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
msg_args['instance_type'] = objects_base.obj_to_primitive( msg_args['instance_type'] = objects_base.obj_to_primitive(
instance_type) instance_type)
@@ -862,18 +848,14 @@ class ComputeAPI(object):
def resume_instance(self, ctxt, instance): def resume_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'resume_instance', instance=instance) cctxt.cast(ctxt, 'resume_instance', instance=instance)
def revert_resize(self, ctxt, instance, migration, host, def revert_resize(self, ctxt, instance, migration, host,
reservations=None): reservations=None):
version = '4.0' version = '4.0'
if not host: cctxt = self.router.client(ctxt).prepare(
client = self.router.by_instance(ctxt, instance)
else:
client = self.router.by_host(ctxt, host)
cctxt = client.prepare(
server=_compute_host(host, instance), version=version) server=_compute_host(host, instance), version=version)
cctxt.cast(ctxt, 'revert_resize', cctxt.cast(ctxt, 'revert_resize',
instance=instance, migration=migration, instance=instance, migration=migration,
@@ -883,7 +865,7 @@ class ComputeAPI(object):
destroy_disks=True, destroy_disks=True,
migrate_data=None): migrate_data=None):
version = '4.8' version = '4.8'
client = self.router.by_host(ctxt, host) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
if migrate_data: if migrate_data:
@@ -897,20 +879,20 @@ class ComputeAPI(object):
def set_admin_password(self, ctxt, instance, new_pass): def set_admin_password(self, ctxt, instance, new_pass):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'set_admin_password', return cctxt.call(ctxt, 'set_admin_password',
instance=instance, new_pass=new_pass) instance=instance, new_pass=new_pass)
def set_host_enabled(self, ctxt, host, enabled): def set_host_enabled(self, ctxt, host, enabled):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'set_host_enabled', enabled=enabled) return cctxt.call(ctxt, 'set_host_enabled', enabled=enabled)
def swap_volume(self, ctxt, instance, old_volume_id, new_volume_id): def swap_volume(self, ctxt, instance, old_volume_id, new_volume_id):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'swap_volume', cctxt.cast(ctxt, 'swap_volume',
instance=instance, old_volume_id=old_volume_id, instance=instance, old_volume_id=old_volume_id,
@@ -918,7 +900,7 @@ class ComputeAPI(object):
def get_host_uptime(self, ctxt, host): def get_host_uptime(self, ctxt, host):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
return cctxt.call(ctxt, 'get_host_uptime') return cctxt.call(ctxt, 'get_host_uptime')
@@ -929,14 +911,14 @@ class ComputeAPI(object):
'device_type': device_type} 'device_type': device_type}
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'reserve_block_device_name', **kw) return cctxt.call(ctxt, 'reserve_block_device_name', **kw)
def backup_instance(self, ctxt, instance, image_id, backup_type, def backup_instance(self, ctxt, instance, image_id, backup_type,
rotation): rotation):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'backup_instance', cctxt.cast(ctxt, 'backup_instance',
instance=instance, instance=instance,
@@ -946,7 +928,7 @@ class ComputeAPI(object):
def snapshot_instance(self, ctxt, instance, image_id): def snapshot_instance(self, ctxt, instance, image_id):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'snapshot_instance', cctxt.cast(ctxt, 'snapshot_instance',
instance=instance, instance=instance,
@@ -954,7 +936,7 @@ class ComputeAPI(object):
def start_instance(self, ctxt, instance): def start_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'start_instance', instance=instance) cctxt.cast(ctxt, 'start_instance', instance=instance)
@@ -962,14 +944,14 @@ class ComputeAPI(object):
msg_args = {'instance': instance, msg_args = {'instance': instance,
'clean_shutdown': clean_shutdown} 'clean_shutdown': clean_shutdown}
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
rpc_method = cctxt.cast if do_cast else cctxt.call rpc_method = cctxt.cast if do_cast else cctxt.call
return rpc_method(ctxt, 'stop_instance', **msg_args) return rpc_method(ctxt, 'stop_instance', **msg_args)
def suspend_instance(self, ctxt, instance): def suspend_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'suspend_instance', instance=instance) cctxt.cast(ctxt, 'suspend_instance', instance=instance)
@@ -979,7 +961,7 @@ class ComputeAPI(object):
# the method signature has to match with `terminate_instance()` # the method signature has to match with `terminate_instance()`
# method of cells rpcapi. # method of cells rpcapi.
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'terminate_instance', cctxt.cast(ctxt, 'terminate_instance',
instance=instance, bdms=bdms, instance=instance, bdms=bdms,
@@ -987,26 +969,26 @@ class ComputeAPI(object):
def unpause_instance(self, ctxt, instance): def unpause_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'unpause_instance', instance=instance) cctxt.cast(ctxt, 'unpause_instance', instance=instance)
def unrescue_instance(self, ctxt, instance): def unrescue_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'unrescue_instance', instance=instance) cctxt.cast(ctxt, 'unrescue_instance', instance=instance)
def soft_delete_instance(self, ctxt, instance, reservations=None): def soft_delete_instance(self, ctxt, instance, reservations=None):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'soft_delete_instance', cctxt.cast(ctxt, 'soft_delete_instance',
instance=instance, reservations=reservations) instance=instance, reservations=reservations)
def restore_instance(self, ctxt, instance): def restore_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'restore_instance', instance=instance) cctxt.cast(ctxt, 'restore_instance', instance=instance)
@@ -1015,7 +997,7 @@ class ComputeAPI(object):
msg_args = {'instance': instance, 'image_id': image_id, msg_args = {'instance': instance, 'image_id': image_id,
'clean_shutdown': clean_shutdown} 'clean_shutdown': clean_shutdown}
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'shelve_instance', **msg_args) cctxt.cast(ctxt, 'shelve_instance', **msg_args)
@@ -1023,7 +1005,7 @@ class ComputeAPI(object):
clean_shutdown=True): clean_shutdown=True):
msg_args = {'instance': instance, 'clean_shutdown': clean_shutdown} msg_args = {'instance': instance, 'clean_shutdown': clean_shutdown}
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'shelve_offload_instance', **msg_args) cctxt.cast(ctxt, 'shelve_offload_instance', **msg_args)
@@ -1036,14 +1018,14 @@ class ComputeAPI(object):
'filter_properties': filter_properties, 'filter_properties': filter_properties,
'node': node, 'node': node,
} }
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'unshelve_instance', **msg_kwargs) cctxt.cast(ctxt, 'unshelve_instance', **msg_kwargs)
def volume_snapshot_create(self, ctxt, instance, volume_id, def volume_snapshot_create(self, ctxt, instance, volume_id,
create_info): create_info):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'volume_snapshot_create', instance=instance, cctxt.cast(ctxt, 'volume_snapshot_create', instance=instance,
volume_id=volume_id, create_info=create_info) volume_id=volume_id, create_info=create_info)
@@ -1051,7 +1033,7 @@ class ComputeAPI(object):
def volume_snapshot_delete(self, ctxt, instance, volume_id, snapshot_id, def volume_snapshot_delete(self, ctxt, instance, volume_id, snapshot_id,
delete_info): delete_info):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'volume_snapshot_delete', instance=instance, cctxt.cast(ctxt, 'volume_snapshot_delete', instance=instance,
volume_id=volume_id, snapshot_id=snapshot_id, volume_id=volume_id, snapshot_id=snapshot_id,
@@ -1059,7 +1041,7 @@ class ComputeAPI(object):
def external_instance_event(self, ctxt, instances, events, host=None): def external_instance_event(self, ctxt, instances, events, host=None):
instance = instances[0] instance = instances[0]
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(host, instance), server=_compute_host(host, instance),
version='4.0') version='4.0')
cctxt.cast(ctxt, 'external_instance_event', instances=instances, cctxt.cast(ctxt, 'external_instance_event', instances=instances,
@@ -1071,7 +1053,7 @@ class ComputeAPI(object):
block_device_mapping=None, node=None, limits=None): block_device_mapping=None, node=None, limits=None):
version = '4.0' version = '4.0'
cctxt = self.router.by_host(ctxt, host).prepare( cctxt = self.router.client(ctxt).prepare(
server=host, version=version) server=host, version=version)
cctxt.cast(ctxt, 'build_and_run_instance', instance=instance, cctxt.cast(ctxt, 'build_and_run_instance', instance=instance,
image=image, request_spec=request_spec, image=image, request_spec=request_spec,
@@ -1085,20 +1067,20 @@ class ComputeAPI(object):
def quiesce_instance(self, ctxt, instance): def quiesce_instance(self, ctxt, instance):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
return cctxt.call(ctxt, 'quiesce_instance', instance=instance) return cctxt.call(ctxt, 'quiesce_instance', instance=instance)
def unquiesce_instance(self, ctxt, instance, mapping=None): def unquiesce_instance(self, ctxt, instance, mapping=None):
version = '4.0' version = '4.0'
cctxt = self.router.by_instance(ctxt, instance).prepare( cctxt = self.router.client(ctxt).prepare(
server=_compute_host(None, instance), version=version) server=_compute_host(None, instance), version=version)
cctxt.cast(ctxt, 'unquiesce_instance', instance=instance, cctxt.cast(ctxt, 'unquiesce_instance', instance=instance,
mapping=mapping) mapping=mapping)
def refresh_instance_security_rules(self, ctxt, instance, host): def refresh_instance_security_rules(self, ctxt, instance, host):
version = '4.4' version = '4.4'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
version = '4.0' version = '4.0'
instance = objects_base.obj_to_primitive(instance) instance = objects_base.obj_to_primitive(instance)
@@ -1109,7 +1091,7 @@ class ComputeAPI(object):
def trigger_crash_dump(self, ctxt, instance): def trigger_crash_dump(self, ctxt, instance):
version = '4.6' version = '4.6'
client = self.router.by_instance(ctxt, instance) client = self.router.client(ctxt)
if not client.can_send_version(version): if not client.can_send_version(version):
raise exception.TriggerCrashDumpNotSupported() raise exception.TriggerCrashDumpNotSupported()

View File

@@ -410,24 +410,11 @@ class ClientRouter(periodic_task.PeriodicTasks):
# Prevent this empty context from overwriting the thread local copy # Prevent this empty context from overwriting the thread local copy
self.run_periodic_tasks(nova.context.RequestContext(overwrite=False)) self.run_periodic_tasks(nova.context.RequestContext(overwrite=False))
def _client(self, context, transport=None): def client(self, context):
transport = context.mq_connection
if transport: if transport:
return messaging.RPCClient(transport, self.target, return messaging.RPCClient(transport, self.target,
version_cap=self.version_cap, version_cap=self.version_cap,
serializer=self.serializer) serializer=self.serializer)
else: else:
return self.default_client return self.default_client
def by_instance(self, context, instance):
"""Deprecated."""
if context.mq_connection:
return self._client(context, transport=context.mq_connection)
else:
return self.default_client
def by_host(self, context, host):
"""Deprecated."""
if context.mq_connection:
return self._client(context, transport=context.mq_connection)
else:
return self.default_client

View File

@@ -225,9 +225,9 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
rpcapi = compute_rpcapi.ComputeAPI() rpcapi = compute_rpcapi.ComputeAPI()
cast_mock = mock.Mock() cast_mock = mock.Mock()
cctxt_mock = mock.Mock(cast=cast_mock) cctxt_mock = mock.Mock(cast=cast_mock)
rpcapi.router.by_instance = mock.Mock() rpcapi.router.client = mock.Mock()
mock_client = mock.Mock() mock_client = mock.Mock()
rpcapi.router.by_instance.return_value = mock_client rpcapi.router.client.return_value = mock_client
with test.nested( with test.nested(
mock.patch.object(mock_client, 'can_send_version', mock.patch.object(mock_client, 'can_send_version',
return_value=False), return_value=False),
@@ -335,9 +335,9 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
ctxt = context.RequestContext('fake_user', 'fake_project') ctxt = context.RequestContext('fake_user', 'fake_project')
version = '4.12' version = '4.12'
rpcapi = compute_rpcapi.ComputeAPI() rpcapi = compute_rpcapi.ComputeAPI()
rpcapi.router.by_host = mock.Mock() rpcapi.router.client = mock.Mock()
mock_client = mock.MagicMock() mock_client = mock.MagicMock()
rpcapi.router.by_host.return_value = mock_client rpcapi.router.client.return_value = mock_client
mock_client.can_send_version.return_value = True mock_client.can_send_version.return_value = True
mock_cctx = mock.MagicMock() mock_cctx = mock.MagicMock()
mock_client.prepare.return_value = mock_cctx mock_client.prepare.return_value = mock_cctx
@@ -356,9 +356,9 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
version = '4.9' version = '4.9'
ctxt = context.RequestContext('fake_user', 'fake_project') ctxt = context.RequestContext('fake_user', 'fake_project')
rpcapi = compute_rpcapi.ComputeAPI() rpcapi = compute_rpcapi.ComputeAPI()
rpcapi.router.by_host = mock.Mock() rpcapi.router.client = mock.Mock()
mock_client = mock.MagicMock() mock_client = mock.MagicMock()
rpcapi.router.by_host.return_value = mock_client rpcapi.router.client.return_value = mock_client
mock_client.can_send_version.return_value = False mock_client.can_send_version.return_value = False
mock_cctx = mock.MagicMock() mock_cctx = mock.MagicMock()
mock_client.prepare.return_value = mock_cctx mock_client.prepare.return_value = mock_cctx
@@ -625,10 +625,8 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
calltype='call', can_send=False): calltype='call', can_send=False):
rpc = compute_rpcapi.ComputeAPI() rpc = compute_rpcapi.ComputeAPI()
mock_client = mock.Mock() mock_client = mock.Mock()
rpc.router.by_instance = mock.Mock() rpc.router.client = mock.Mock()
rpc.router.by_instance.return_value = mock_client rpc.router.client.return_value = mock_client
rpc.router.by_host = mock.Mock()
rpc.router.by_host.return_value = mock_client
@mock.patch.object(compute_rpcapi, '_compute_host') @mock.patch.object(compute_rpcapi, '_compute_host')
def _test(mock_ch): def _test(mock_ch):
@@ -638,19 +636,7 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
ctxt = context.RequestContext() ctxt = context.RequestContext()
result = getattr(rpc, method)(ctxt, **inargs) result = getattr(rpc, method)(ctxt, **inargs)
call.assert_called_once_with(ctxt, method, **callargs) call.assert_called_once_with(ctxt, method, **callargs)
# Get the target of the prepare call: prepare(server=<target>, ...) rpc.router.client.assert_called_once_with(ctxt)
prepare_target = mock_client.prepare.call_args[1]['server']
# If _compute_host(None, instance) was called, then by_instance
# should have been called with the instance. Otherwise by_host
# should have been called with the same host as the prepare target.
if mock_ch.called and mock_ch.call_args[0][0] is None:
instance = mock_ch.call_args[0][1]
rpc.router.by_instance.assert_called_once_with(ctxt, instance)
rpc.router.by_host.assert_not_called()
else:
rpc.router.by_host.assert_called_once_with(ctxt,
prepare_target)
rpc.router.by_instance.assert_not_called()
return result return result
return _test() return _test()

View File

@@ -21,10 +21,8 @@ from oslo_serialization import jsonutils
import testtools import testtools
from nova import context from nova import context
from nova import objects
from nova import rpc from nova import rpc
from nova import test from nova import test
from nova.tests import uuidsentinel as uuids
# Make a class that resets all of the global variables in nova.rpc # Make a class that resets all of the global variables in nova.rpc
@@ -465,10 +463,9 @@ class TestClientRouter(test.NoDBTestCase):
mock_rpcclient.return_value = cell_client mock_rpcclient.return_value = cell_client
ctxt = mock.Mock() ctxt = mock.Mock()
ctxt.mq_connection = mock.sentinel.transport ctxt.mq_connection = mock.sentinel.transport
instance = objects.Instance(uuid=uuids.instance)
router = rpc.ClientRouter(default_client) router = rpc.ClientRouter(default_client)
client = router.by_instance(ctxt, instance) client = router.client(ctxt)
# verify a client was created by ClientRouter # verify a client was created by ClientRouter
mock_rpcclient.assert_called_once_with( mock_rpcclient.assert_called_once_with(
@@ -485,45 +482,9 @@ class TestClientRouter(test.NoDBTestCase):
mock_rpcclient.return_value = cell_client mock_rpcclient.return_value = cell_client
ctxt = mock.Mock() ctxt = mock.Mock()
ctxt.mq_connection = None ctxt.mq_connection = None
instance = objects.Instance(uuid=uuids.instance)
router = rpc.ClientRouter(default_client) router = rpc.ClientRouter(default_client)
client = router.by_instance(ctxt, instance) client = router.client(ctxt)
self.assertEqual(router.default_client, client)
self.assertFalse(mock_rpcclient.called)
@mock.patch('oslo_messaging.RPCClient')
def test_by_host(self, mock_rpcclient):
default_client = mock.Mock()
cell_client = mock.Mock()
mock_rpcclient.return_value = cell_client
ctxt = mock.Mock()
ctxt.mq_connection = mock.sentinel.transport
host = 'fake-host'
router = rpc.ClientRouter(default_client)
client = router.by_host(ctxt, host)
# verify a client was created by ClientRouter
mock_rpcclient.assert_called_once_with(
mock.sentinel.transport, default_client.target,
version_cap=default_client.version_cap,
serializer=default_client.serializer)
# verify cell client was returned
self.assertEqual(cell_client, client)
@mock.patch('oslo_messaging.RPCClient')
def test_by_host_untargeted(self, mock_rpcclient):
default_client = mock.Mock()
cell_client = mock.Mock()
mock_rpcclient.return_value = cell_client
ctxt = mock.Mock()
ctxt.mq_connection = None
host = 'fake-host'
router = rpc.ClientRouter(default_client)
client = router.by_host(ctxt, host)
self.assertEqual(router.default_client, client) self.assertEqual(router.default_client, client)
self.assertFalse(mock_rpcclient.called) self.assertFalse(mock_rpcclient.called)