Fake Drivers

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 fake_compute Module

class API

Bases: object

Fake Compute API.

add_security_group_to_server(*args, **kwargs)
instance_volume_attach(ctx, server_id, volume_id, mount_path)
instance_volume_detach(ctx, server_id, volume_id)
instance_volumes_list(ctx, server_id)
keypair_delete(*args, **kwargs)
keypair_import(*args, **kwargs)
keypair_list(*args, **kwargs)
server_create(*args, **kwargs)
server_delete(*args, **kwargs)
server_get(*args, **kwargs)
server_get_by_name_or_id(*args, **kwargs)
server_reboot(*args, **kwargs)
class FakeKeypair(**kwargs)

Bases: object

class FakeServer(**kwargs)

Bases: object

get(attr, default)
update(*args, **kwargs)

The fake_driver Module

class FakeShareDriver(*args, **kwargs)

Bases: ShareDriver

Fake share driver.

This fake driver can be also used as a test driver within a real running manila-share instance. To activate it use this in manila.conf:

enabled_share_backends = fake

[fake]
driver_handles_share_servers = True
share_backend_name = fake
share_driver = manila.tests.fake_driver.FakeShareDriver

With it you basically mocked all backend driver calls but e.g. networking will still be activated.

allow_access(context, share, access, share_server=None)

Allow access to the share.

create_share(context, share, share_server=None)

Is called to create share.

create_share_from_snapshot(context, share, snapshot, share_server=None, parent_share=None)

Is called to create share from snapshot.

Creating a share from snapshot can take longer than a simple clone operation if data copy is required from one host to another. For this reason driver will be able complete this creation asynchronously, by providing a ‘creating_from_snapshot’ status in the model update.

When answering asynchronously, drivers must implement the call ‘get_share_status’ in order to provide updates for shares with ‘creating_from_snapshot’ status.

It is expected that the driver returns a model update to the share manager that contains: share status and a list of export_locations. A list of ‘export_locations’ is mandatory only for share in ‘available’ status. The current supported status are ‘available’ and ‘creating_from_snapshot’.

Parameters:
  • context – Current context

  • share – Share instance model with share data.

  • snapshot – Snapshot instance model .

  • share_server – Share server model or None.

  • parent_share – Share model from parent snapshot with share data and share server model.

Returns:

a dictionary of updates containing current share status and its export_location (if available).

Example:

{
    'status': 'available',
    'export_locations': [{...}, {...}],
}

Raises:

ShareBackendException. A ShareBackendException in this method will set the instance to ‘error’ and the operation will end.

create_share_group(context, group_id, share_server=None)

Create a share group.

Parameters:
  • context

  • share_group_dict – The share group details EXAMPLE: { ‘status’: ‘creating’, ‘project_id’: ‘13c0be6290934bd98596cfa004650049’, ‘user_id’: ‘a0314a441ca842019b0952224aa39192’, ‘description’: None, ‘deleted’: ‘False’, ‘created_at’: datetime.datetime(2015, 8, 10, 15, 14, 6), ‘updated_at’: None, ‘source_share_group_snapshot_id’: ‘some_fake_uuid’, ‘share_group_type_id’: ‘some_fake_uuid’, ‘host’: ‘hostname@backend_name’, ‘share_network_id’: None, ‘share_server_id’: None, ‘deleted_at’: None, ‘share_types’: [<models.ShareGroupShareTypeMapping>], ‘id’: ‘some_fake_uuid’, ‘name’: None }

Returns:

(share_group_model_update, share_update_list) share_group_model_update - a dict containing any values to be updated for the SG in the database. This value may be None.

create_snapshot(context, snapshot, share_server=None)

Is called to create snapshot.

Parameters:
  • context – Current context

  • snapshot – Snapshot model. Share model could be retrieved through snapshot[‘share’].

  • share_server – Share server model or None.

Returns:

None or a dictionary with key ‘export_locations’ containing a list of export locations, if snapshots can be mounted.

delete_share(context, share, share_server=None)

Is called to remove share.

delete_share_group(context, group_id, share_server=None)

Delete a share group

Parameters:
  • context – The request context

  • share_group_dict

    The share group details EXAMPLE: .. code:

    {
    'status': 'creating',
    'project_id': '13c0be6290934bd98596cfa004650049',
    'user_id': 'a0314a441ca842019b0952224aa39192',
    'description': None,
    'deleted': 'False',
    'created_at': datetime.datetime(2015, 8, 10, 15, 14, 6),
    'updated_at': None,
    'source_share_group_snapshot_id': 'some_fake_uuid',
    'share_share_group_type_id': 'some_fake_uuid',
    'host': 'hostname@backend_name',
    'deleted_at': None,
    'shares': [<models.Share>], # The new shares being created
    'share_types': [<models.ShareGroupShareTypeMapping>],
    'id': 'some_fake_uuid',
    'name': None
    }
    

Returns:

share_group_model_update share_group_model_update - a dict containing any values to be updated for the group in the database. This value may be None.

delete_snapshot(context, snapshot, share_server=None)

Is called to remove snapshot.

Parameters:
  • context – Current context

  • snapshot – Snapshot model. Share model could be retrieved through snapshot[‘share’].

  • share_server – Share server model or None.

deny_access(context, share, access, share_server=None)

Deny access to the share.

do_setup(context)

Any initialization the share driver does while starting.

property driver_handles_share_servers
ensure_share(context, share, share_server=None)

Invoked to ensure that share is exported.

Driver can use this method to update the list of export locations of the share if it changes. To do that, you should return list with export locations.

It is preferred if the driver implements “get_backend_info” and “ensure_shares” instead of this routine.

Returns:

None or list with export locations

get_network_allocations_number()

Returns number of network allocations for creating VIFs.

Drivers that use Nova for share servers should return zero (0) here same as Generic driver does. Because Nova will handle network resources allocation. Drivers that handle networking itself should calculate it according to their own requirements. It can have 1+ network interfaces.

get_share_stats(refresh=False)

Get share status.

If ‘refresh’ is True, run update the stats first.

get_share_status(share, share_server=None)

Invoked periodically to get the current status of a given share.

Driver can use this method to update the status of a share that is still pending from other operations. This method is expected to be called in a periodic interval set by the ‘periodic_interval’ configuration in seconds.

Parameters:
  • share – share to get updated status from.

  • share_server – share server model or None.

Returns:

a dictionary of updates with the current share status, that must be ‘available’, ‘creating_from_snapshot’ or ‘error’, a list of export locations, if available, and a progress field which indicates the completion of the share creation operation. EXAMPLE:

{
    'status': 'available',
    'export_locations': [{...}, {...}],
    'progress': '50%'
}

Raises:

ShareBackendException. A ShareBackendException in this method will set the instance status to ‘error’.

manage_existing(share, driver_options, share_server=None)

Brings an existing share under Manila management.

If the provided share is not valid, then raise a ManageInvalidShare exception, specifying a reason for the failure.

If the provided share is not in a state that can be managed, such as being replicated on the backend, the driver MUST raise ManageInvalidShare exception with an appropriate message.

The share has a share_type, and the driver can inspect that and compare against the properties of the referenced backend share. If they are incompatible, raise a ManageExistingShareTypeMismatch, specifying a reason for the failure.

This method is invoked when the share is being managed with a share type that has driver_handles_share_servers extra-spec set to False.

Parameters:
  • share – Share model

  • driver_options – Driver-specific options provided by admin.

Returns:

share_update dictionary with required key ‘size’, which should contain size of the share.

setup_server(*args, **kwargs)
teardown_server(*args, **kwargs)
unmanage(share, share_server=None)

Removes the specified share from Manila management.

Does not delete the underlying backend share.

For most drivers, this will not need to do anything. However, some drivers might use this call as an opportunity to clean up any Manila-specific configuration that they have associated with the backend share.

If provided share cannot be unmanaged, then raise an UnmanageInvalidShare exception, specifying a reason for the failure.

This method is invoked when the share is being unmanaged with a share type that has driver_handles_share_servers extra-spec set to False.

The fake_network Module

class FakeNeutronNetworkHelper

Bases: object

setup_connectivity_with_service_instances()
class FakeServiceInstanceManager(*args, **kwargs)

Bases: object

get_service_instance(context, share_network_id, create=True)
property network_helper

The fake_utils Module

This modules stubs out functions in manila.utils.

fake_execute(*cmd_parts, **kwargs)

This function stubs out execute.

It optionally executes a preconfigued function to return expected data.

fake_execute_clear_log()
fake_execute_default_reply_handler(*ignore_args, **ignore_kwargs)

A reply handler for commands that haven’t been added to the reply list.

Returns empty strings for stdout and stderr.

fake_execute_get_log()
fake_execute_set_repliers(repliers)

Allows the client to configure replies to commands.

get_fake_lock_context()
stub_out_utils_execute(testcase)

The fake_volume Module

class API

Bases: object

Fake Volume API.

create(*args, **kwargs)
create_snapshot_force(*args, **kwargs)
delete(volume_id)
delete_snapshot(*args, **kwargs)
extend(*args, **kwargs)
get(*args, **kwargs)
get_all(search_opts)
get_all_snapshots(search_opts)
get_snapshot(*args, **kwargs)
class FakeVolume(**kwargs)

Bases: object

class FakeVolumeSnapshot(**kwargs)

Bases: object