Table Of Contents

Previous topic

Scheduler

Next topic

Common and Misc Libraries

This Page

Psst... hey. You're reading the latest content, but it might be out of sync with code. You can read Nova 2011.1 docs or all OpenStack docs too.

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 nova.virt.fake.FakeConnection

Bases: nova.virt.driver.ComputeDriver

The interface to this class talks in terms of ‘instances’ (Amazon EC2 and internal Nova terminology), by which we mean ‘running virtual machine’ (XenAPI terminology) or domain (Xen or libvirt terminology).

An instance has an ID, which is the identifier chosen by Nova to represent the instance further up the stack. This is unfortunately also called a ‘name’ elsewhere. As far as this layer is concerned, ‘instance ID’ and ‘instance name’ are synonyms.

Note that the instance ID or name is not human-readable or customer-controlled – it’s an internal ID chosen by Nova. At the nova.virt layer, instances do not have human-readable names at all – such things are only known higher up the stack.

Most virtualization platforms will also have their own identity schemes, to uniquely identify a VM or domain. These IDs must stay internal to the platform-specific layer, and never escape the connection interface. The platform-specific layer is responsible for keeping track of which instance ID maps to which platform-specific ID, and vice versa.

In contrast, the list_disks and list_interfaces calls may return platform-specific IDs. These identify a specific virtual disk or specific virtual network interface, and these IDs are opaque to the rest of Nova.

Some methods here take an instance of nova.compute.service.Instance. This is the datastructure used by nova.compute to store details regarding an instance, and pass them into this layer. This layer is responsible for translating that generic datastructure into terms that are specific to the virtualization platform.

FakeConnection.attach_disk(instance, disk_info)

Attaches the disk to an instance given the metadata disk_info

FakeConnection.attach_volume(instance_name, device_path, mountpoint)

Attach the disk at device_path to the instance at mountpoint

FakeConnection.block_stats(instance_name, disk_id)

Return performance counters associated with the given disk_id on the given instance_name. These are returned as [rd_req, rd_bytes, wr_req, wr_bytes, errs], where rd indicates read, wr indicates write, req is the total number of I/O requests made, bytes is the total number of bytes transferred, and errs is the number of requests held up due to a full pipeline.

All counters are long integers.

This method is optional. On some platforms (e.g. XenAPI) performance statistics can be retrieved directly in aggregate form, without Nova having to do the aggregation. On those platforms, this method is unused.

Note that this function takes an instance ID, not a compute.service.Instance, so that it can be called by compute.monitor.

FakeConnection.compare_cpu(xml)

This method is supported only by libvirt.

FakeConnection.destroy(instance)
FakeConnection.detach_volume(instance_name, mountpoint)

Detach the disk attached to the instance at mountpoint

FakeConnection.ensure_filtering_rules_for_instance(instance_ref)

This method is supported only by libvirt.

FakeConnection.get_ajax_console(instance)
FakeConnection.get_console_output(instance)
FakeConnection.get_console_pool_info(console_type)
FakeConnection.get_diagnostics(instance_name)
FakeConnection.get_host_ip_addr()

Retrieves the IP address of the dom0

FakeConnection.get_info(instance_name)

Get a block of information about the given instance. This is returned as a dictionary containing ‘state’: The power_state of the instance, ‘max_mem’: The maximum memory for the instance, in KiB, ‘mem’: The current memory the instance has, in KiB, ‘num_cpu’: The current number of virtual CPUs the instance has, ‘cpu_time’: The total CPU time used by the instance, in nanoseconds.

This method should raise exception.NotFound if the hypervisor has no knowledge of the instance

FakeConnection.get_vnc_console(instance)
FakeConnection.init_host(host)

Initialize anything that is necessary for the driver to function, including catching up with currently running VM’s on the given host.

FakeConnection.inject_file(instance, b64_path, b64_contents)

Writes a file on the specified instance.

The first parameter is an instance of nova.compute.service.Instance, and so the instance is being specified as instance.name. The second parameter is the base64-encoded path to which the file is to be written on the instance; the third is the contents of the file, also base64-encoded.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

classmethod FakeConnection.instance()
FakeConnection.interface_stats(instance_name, iface_id)

Return performance counters associated with the given iface_id on the given instance_id. These are returned as [rx_bytes, rx_packets, rx_errs, rx_drop, tx_bytes, tx_packets, tx_errs, tx_drop], where rx indicates receive, tx indicates transmit, bytes and packets indicate the total number of bytes or packets transferred, and errs and dropped is the total number of packets failed / dropped.

All counters are long integers.

This method is optional. On some platforms (e.g. XenAPI) performance statistics can be retrieved directly in aggregate form, without Nova having to do the aggregation. On those platforms, this method is unused.

Note that this function takes an instance ID, not a compute.service.Instance, so that it can be called by compute.monitor.

FakeConnection.list_disks(instance_name)

Return the IDs of all the virtual disks attached to the specified instance, as a list. These IDs are opaque to the caller (they are only useful for giving back to this layer as a parameter to disk_stats). These IDs only need to be unique for a given instance.

Note that this function takes an instance ID, not a compute.service.Instance, so that it can be called by compute.monitor.

FakeConnection.list_instances()

Return the names of all the instances known to the virtualization layer, as a list.

FakeConnection.list_instances_detail()
FakeConnection.list_interfaces(instance_name)

Return the IDs of all the virtual network interfaces attached to the specified instance, as a list. These IDs are opaque to the caller (they are only useful for giving back to this layer as a parameter to interface_stats). These IDs only need to be unique for a given instance.

Note that this function takes an instance ID, not a compute.service.Instance, so that it can be called by compute.monitor.

FakeConnection.live_migration(context, instance_ref, dest, post_method, recover_method)

This method is supported only by libvirt.

FakeConnection.migrate_disk_and_power_off(instance, dest)

Transfers the disk of a running instance in multiple phases, turning off the instance before the end.

FakeConnection.pause(instance, callback)

Pause the specified instance.

FakeConnection.reboot(instance)

Reboot the specified instance.

The given parameter is an instance of nova.compute.service.Instance, and so the instance is being specified as instance.name.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

FakeConnection.refresh_security_group_members(security_group_id)

This method is called when a security group is added to an instance.

This message is sent to the virtualization drivers on hosts that are running an instance that belongs to a security group that has a rule that references the security group identified by security_group_id. It is the responsiblity of this method to make sure any rules that authorize traffic flow with members of the security group are updated and any new members can communicate, and any removed members cannot.

Scenario:
  • we are running on host ‘H0’ and we have an instance ‘i-0’.
  • instance ‘i-0’ is a member of security group ‘speaks-b’
  • group ‘speaks-b’ has an ingress rule that authorizes group ‘b’
  • another host ‘H1’ runs an instance ‘i-1’
  • instance ‘i-1’ is a member of security group ‘b’

When ‘i-1’ launches or terminates we will recieve the message to update members of group ‘b’, at which time we will make any changes needed to the rules for instance ‘i-0’ to allow or deny traffic coming from ‘i-1’, depending on if it is being added or removed from the group.

In this scenario, ‘i-1’ could just as easily have been running on our host ‘H0’ and this method would still have been called. The point was that this method isn’t called on the host where instances of that group are running (as is the case with :method:`refresh_security_group_rules`) but is called where references are made to authorizing those instances.

An error should be raised if the operation cannot complete.

FakeConnection.refresh_security_group_rules(security_group_id)

This method is called after a change to security groups.

All security groups and their associated rules live in the datastore, and calling this method should apply the updated rules to instances running the specified security group.

An error should be raised if the operation cannot complete.

FakeConnection.rescue(instance)

Rescue the specified instance.

FakeConnection.resize(instance, flavor)

Resizes/Migrates the specified instance.

The flavor parameter determines whether or not the instance RAM and disk space are modified, and if so, to what size.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

FakeConnection.resume(instance, callback)

resume the specified instance

FakeConnection.set_admin_password(instance, new_pass)

Set the root password on the specified instance.

The first parameter is an instance of nova.compute.service.Instance, and so the instance is being specified as instance.name. The second parameter is the value of the new password.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

FakeConnection.snapshot(instance, name)

Snapshots the specified instance.

The given parameter is an instance of nova.compute.service.Instance, and so the instance is being specified as instance.name.

The second parameter is the name of the snapshot.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

FakeConnection.spawn(instance)

Create a new instance/VM/domain on the virtualization platform.

The given parameter is an instance of nova.compute.service.Instance. This function should use the data there to guide the creation of the new instance.

The work will be done asynchronously. This function returns a task that allows the caller to detect when it is complete.

Once this successfully completes, the instance should be running (power_state.RUNNING).

If this fails, any partial instance should be completely cleaned up, and the virtualization platform should be in the state that it was before this call began.

FakeConnection.suspend(instance, callback)

suspend the specified instance

FakeConnection.test_remove_vm(instance_name)

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

FakeConnection.unfilter_instance(instance_ref)

This method is supported only by libvirt.

FakeConnection.unpause(instance, callback)

Unpause the specified instance.

FakeConnection.unrescue(instance)

Unrescue the specified instance.

FakeConnection.update_available_resource(ctxt, host)

This method is supported only by libvirt.

class nova.virt.fake.FakeInstance(name, state)

Bases: object

nova.virt.fake.get_connection(_)

The nova.auth.fakeldap Module

Fake LDAP server for test harness.

This class does very little error checking, and knows nothing about ldap class definitions. It implements the minimum emulation of the python ldap library to work with nova.

class nova.auth.fakeldap.FakeLDAP

Bases: object

Fake LDAP connection.

FakeLDAP.add_s(dn, attr)

Add an object with the specified attributes at dn.

FakeLDAP.delete_s(dn)

Remove the ldap object at specified dn.

FakeLDAP.modify_s(dn, attrs)

Modify the object at dn using the attribute list.

Args: dn – a dn attrs – a list of tuples in the following form:

([MOD_ADD | MOD_DELETE | MOD_REPACE], attribute, value)
FakeLDAP.search_s(dn, scope, query=None, fields=None)

Search for all matching objects under dn using the query.

Args: dn – dn to search under scope – only SCOPE_BASE and SCOPE_SUBTREE are supported query – query to filter objects by fields – fields to return. Returns all fields if not specified

FakeLDAP.simple_bind_s(dn, password)

This method is ignored, but provided for compatibility.

FakeLDAP.unbind_s()

This method is ignored, but provided for compatibility.

exception nova.auth.fakeldap.NO_SUCH_OBJECT

Bases: exceptions.Exception

Duplicate exception class from real LDAP module.

exception nova.auth.fakeldap.OBJECT_CLASS_VIOLATION

Bases: exceptions.Exception

Duplicate exception class from real LDAP module.

class nova.auth.fakeldap.Store

Bases: object

classmethod Store.instance()
nova.auth.fakeldap.initialize(_uri)

Opens a fake connection with an LDAP server.

The nova.fakerabbit Module

Based a bit on the carrot.backeds.queue backend... but a lot better.

class nova.fakerabbit.Backend(connection, **kwargs)

Bases: carrot.backends.base.BaseBackend

Backend.consume(limit=None)
Backend.declare_consumer(queue, callback, *args, **kwargs)
Backend.exchange_declare(exchange, type, *args, **kwargs)
Backend.get(queue, no_ack=False)
Backend.prepare_message(message_data, delivery_mode, content_type, content_encoding, **kwargs)

Prepare message for sending.

Backend.publish(message, exchange, routing_key, **kwargs)
Backend.queue_bind(queue, exchange, routing_key, **kwargs)
Backend.queue_declare(queue, **kwargs)
class nova.fakerabbit.Exchange(name, exchange_type)

Bases: object

Exchange.bind(callback, routing_key)
Exchange.publish(message, routing_key=None)
class nova.fakerabbit.Message(backend, **kwargs)

Bases: carrot.backends.base.BaseMessage

class nova.fakerabbit.Queue(name)

Bases: object

Queue.pop()
Queue.push(message, routing_key=None)
Queue.size()
nova.fakerabbit.reset_all()

The nova.volume.driver.FakeAOEDriver Class

class nova.volume.driver.FakeAOEDriver(*args, **kwargs)

Bases: nova.volume.driver.AOEDriver

Logs calls instead of executing.

FakeAOEDriver.check_for_setup_error()

No setup necessary in fake mode.

static FakeAOEDriver.fake_execute(cmd, *_args, **_kwargs)

Execute that simply logs the command.

The nova.tests.service_unittest.FakeManager Class

The nova.tests.api.openstack.fakes Module

class nova.tests.api.openstack.fakes.Context

Bases: object

class nova.tests.api.openstack.fakes.FakeAuthDatabase

Bases: object

static FakeAuthDatabase.auth_token_create(context, token)
static FakeAuthDatabase.auth_token_destroy(context, token_id)
static FakeAuthDatabase.auth_token_get(context, token_hash)
class nova.tests.api.openstack.fakes.FakeAuthManager

Bases: object

FakeAuthManager.add_user(user)
classmethod FakeAuthManager.clear_fakes()
FakeAuthManager.create_project(name, manager_user, description=None, member_users=None)
FakeAuthManager.create_user(name, access=None, secret=None, admin=False)
FakeAuthManager.delete_project(pid)
FakeAuthManager.delete_user(uid)
FakeAuthManager.get_project(pid)
FakeAuthManager.get_projects(user=None)
FakeAuthManager.get_user(uid)
FakeAuthManager.get_user_from_access_key(key)
FakeAuthManager.get_users()
FakeAuthManager.is_admin(user)
FakeAuthManager.is_project_member(user, project)
FakeAuthManager.modify_project(project, manager_user=None, description=None)
FakeAuthManager.modify_user(user_id, access=None, secret=None, admin=None)
classmethod FakeAuthManager.reset_fake_data()
class nova.tests.api.openstack.fakes.FakeRateLimiter(application)

Bases: object

class nova.tests.api.openstack.fakes.FakeRequestContext(user, project, *args, **kwargs)

Bases: object

class nova.tests.api.openstack.fakes.FakeRouter

Bases: nova.wsgi.Router

class nova.tests.api.openstack.fakes.FakeToken(**kwargs)

Bases: object

nova.tests.api.openstack.fakes.fake_auth_init(self, application)
nova.tests.api.openstack.fakes.stub_out_auth(stubs)
nova.tests.api.openstack.fakes.stub_out_compute_api_snapshot(stubs)
nova.tests.api.openstack.fakes.stub_out_glance(stubs, initial_fixtures=None)
nova.tests.api.openstack.fakes.stub_out_glance_add_image(stubs, sent_to_glance)

We return the metadata sent to glance by modifying the sent_to_glance dict in place.

nova.tests.api.openstack.fakes.stub_out_image_service(stubs)
nova.tests.api.openstack.fakes.stub_out_key_pair_funcs(stubs, have_key_pair=True)
nova.tests.api.openstack.fakes.stub_out_networking(stubs)
nova.tests.api.openstack.fakes.stub_out_rate_limiting(stubs)
nova.tests.api.openstack.fakes.wsgi_app(inner_app10=None, inner_app11=None)