Fake Drivers

Todo

document general info about fakes

When the real thing isn’t available and you have some development to do these fake implementations of various drivers let you get on with your day.

The nova.virt.fake Module

A fake (in-memory) hypervisor+api.

Allows nova testing w/o a hypervisor. This module also documents the semantics of real hypervisor connections.

class FakeDriver(virtapi, read_only=False)

Bases: nova.virt.driver.ComputeDriver

FakeDriver.add_to_aggregate(context, aggregate, host, **kwargs)
FakeDriver.attach_interface(instance, image_meta, vif)
FakeDriver.attach_volume(context, connection_info, instance, mountpoint, encryption=None)

Attach the disk to the instance at mountpoint using info.

FakeDriver.block_stats(instance_name, disk_id)
FakeDriver.capabilities = {'supports_recreate': True, 'has_imagecache': True}

Fake hypervisor driver.

FakeDriver.check_can_live_migrate_destination(ctxt, instance_ref, src_compute_info, dst_compute_info, block_migration=False, disk_over_commit=False)
FakeDriver.check_can_live_migrate_destination_cleanup(ctxt, dest_check_data)
FakeDriver.check_can_live_migrate_source(ctxt, instance_ref, dest_check_data)
FakeDriver.confirm_migration(migration, instance, network_info)
FakeDriver.destroy(instance, network_info, block_device_info=None, destroy_disks=True, context=None)
FakeDriver.detach_interface(instance, vif)
FakeDriver.detach_volume(connection_info, instance, mountpoint, encryption=None)

Detach the disk attached to the instance.

FakeDriver.ensure_filtering_rules_for_instance(instance_ref, network_info)
FakeDriver.finish_migration(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info=None, power_on=True)
FakeDriver.finish_revert_migration(instance, network_info, block_device_info=None, power_on=True)
FakeDriver.get_all_bw_counters(instances)

Return bandwidth usage counters for each interface on each running VM.

FakeDriver.get_all_volume_usage(context, compute_host_bdms)

Return usage info for volumes attached to vms on a given host.

FakeDriver.get_available_nodes(refresh=False)
FakeDriver.get_available_resource(nodename)

Updates compute manager resource info on ComputeNode table.

Since we don’t have a real hypervisor, pretend we have lots of disk and ram.

FakeDriver.get_console_output(instance)
FakeDriver.get_console_pool_info(console_type)
FakeDriver.get_diagnostics(instance_name)
FakeDriver.get_disk_available_least()
static FakeDriver.get_host_ip_addr()
FakeDriver.get_host_stats(refresh=False)

Return fake Host Status of ram, disk, network.

FakeDriver.get_info(instance)
FakeDriver.get_instance_disk_info(instance_name)
FakeDriver.get_spice_console(instance)
FakeDriver.get_vnc_console(instance)
FakeDriver.get_volume_connector(instance)
FakeDriver.host_maintenance_mode(host, mode)

Start/Stop host maintenance window. On start, it triggers guest VMs evacuation.

FakeDriver.host_power_action(host, action)

Reboots, shuts down or powers up the host.

FakeDriver.init_host(host)
FakeDriver.inject_file(instance, b64_path, b64_contents)
FakeDriver.instance_on_disk(instance)
FakeDriver.interface_stats(instance_name, iface_id)
FakeDriver.list_instance_uuids()
FakeDriver.list_instances()
FakeDriver.live_migration(context, instance_ref, dest, post_method, recover_method, block_migration=False, migrate_data=None)
FakeDriver.live_snapshot(context, instance, name, update_task_state)
FakeDriver.migrate_disk_and_power_off(context, instance, dest, instance_type, network_info, block_device_info=None)
FakeDriver.pause(instance)
FakeDriver.plug_vifs(instance, network_info)

Plug VIFs into networks.

FakeDriver.poll_rebooting_instances(timeout, instances)
FakeDriver.post_live_migration_at_destination(context, instance, network_info, block_migration=False, block_device_info=None)
FakeDriver.power_off(instance)
FakeDriver.power_on(context, instance, network_info, block_device_info)
FakeDriver.pre_live_migration(context, instance_ref, block_device_info, network_info, disk, migrate_data=None)
FakeDriver.reboot(context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None)
FakeDriver.refresh_instance_security_rules(instance)
FakeDriver.refresh_provider_fw_rules()
FakeDriver.refresh_security_group_members(security_group_id)
FakeDriver.refresh_security_group_rules(security_group_id)
FakeDriver.remove_from_aggregate(context, aggregate, host, **kwargs)
FakeDriver.rescue(context, instance, network_info, image_meta, rescue_password)
FakeDriver.restore(instance)
FakeDriver.resume(context, instance, network_info, block_device_info=None)
FakeDriver.resume_state_on_host_boot(context, instance, network_info, block_device_info=None)
FakeDriver.set_admin_password(instance, new_pass)
FakeDriver.set_host_enabled(host, enabled)

Sets the specified host’s ability to accept new instances.

FakeDriver.snapshot(context, instance, name, update_task_state)
FakeDriver.soft_delete(instance)
FakeDriver.spawn(context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None)
FakeDriver.suspend(instance)
FakeDriver.swap_volume(old_connection_info, new_connection_info, instance, mountpoint)

Replace the disk attached to the instance.

FakeDriver.test_remove_vm(instance_name)

Removes the named VM, as if it crashed. For testing.

FakeDriver.unfilter_instance(instance_ref, network_info)
FakeDriver.unpause(instance)
FakeDriver.unplug_vifs(instance, network_info)

Unplug VIFs from networks.

FakeDriver.unrescue(instance, network_info)
class FakeInstance(name, state)

Bases: object

class FakeVirtAPI

Bases: nova.virt.virtapi.VirtAPI

FakeVirtAPI.agent_build_get_by_triple(context, hypervisor, os, architecture)
FakeVirtAPI.aggregate_get_by_host(context, host, key=None)
FakeVirtAPI.aggregate_metadata_add(context, aggregate, metadata, set_delete=False)
FakeVirtAPI.aggregate_metadata_delete(context, aggregate, key)
FakeVirtAPI.block_device_mapping_get_all_by_instance(context, instance, legacy=True)
FakeVirtAPI.block_device_mapping_update(context, bdm_id, values)
FakeVirtAPI.instance_type_get(context, instance_type_id)
FakeVirtAPI.instance_update(context, instance_uuid, updates)
FakeVirtAPI.provider_fw_rule_get_all(context)
FakeVirtAPI.security_group_get_by_instance(context, instance)
FakeVirtAPI.security_group_rule_get_by_security_group(context, security_group)
restore_nodes()

Resets FakeDriver’s node list modified by set_nodes().

Usually called from tearDown().

set_nodes(nodes)

Sets FakeDriver’s node.list.

It has effect on the following methods:
get_available_nodes() get_available_resource get_host_stats()

To restore the change, call restore_nodes()

The nova.auth.fakeldap Module

The nova.tests.service_unittest.FakeManager Class

The nova.tests.api.openstack.fakes Module