distaflibs.gluster.volume_ops module

distaflibs.gluster.volume_ops.create_volume(volname, mnode=None, dist=1, rep=1, stripe=1, trans='tcp', servers=None, disp=1, dispd=1, red=1)
Create the gluster volume specified configuration
volname and distribute count are mandatory argument
Parameters:volname (str) – volume name that has to be created
Kwargs:
mnode(str): server on which command has to be execeuted,
defaults to tc.servers[0]

dist(int): distribute count, defaults to 1 rep(int): replica count, defaults to 1 stripe(int): stripe count, defaults to 1 trans(str): transport type, defaults to tcp servers(list): servers on which volume has to be created,

defaults to number of servers in pool list, if that is None, then takes tc.servers

disp(int): disperse count, defaults to 1 dispd(int): disperse-data count, defaults to 1 red(int): rdundancy count, defaults to 1

Returns:
Tuple containing three elements (ret, out, err).
The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

(-1, ‘’, ‘’): If not enough bricks are available to create volume. (ret, out, err): As returned by volume create command execution.

Return type:tuple

Example

create_volume(volname)

distaflibs.gluster.volume_ops.start_volume(volname, mnode=None, force=False)

Starts the gluster volume

Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
force (bool): If this option is set to True, then start volume
will get executed with force option. If it is set to False, then start volume will get executed without force option
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

start_volume(“testvol”)

distaflibs.gluster.volume_ops.stop_volume(volname, mnode=None, force=False)

Stops the gluster volume

Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
force (bool): If this option is set to True, then stop volume
will get executed with force option. If it is set to False, then stop volume will get executed without force option
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

stop_volume(“testvol”)

distaflibs.gluster.volume_ops.delete_volume(volname, mnode=None)
Deletes the gluster volume if given volume exists in
gluster and deletes the directories in the bricks associated with the given volume
Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
Returns:True, if volume is deleted False, otherwise
Return type:bool
distaflibs.gluster.volume_ops.reset_volume(volname, mnode=None, force=False)

Resets the gluster volume

Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
force (bool): If this option is set to True, then reset volume
will get executed with force option. If it is set to False, then reset volume will get executed without force option
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

reset_volume(“testvol”)

distaflibs.gluster.volume_ops.cleanup_volume(volname, mnode=None)
deletes snapshots in the volume, stops and deletes the gluster
volume if given volume exists in gluster and deletes the directories in the bricks associated with the given volume
Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
Returns:True, if volume is deleted successfully False, otherwise
Return type:bool

Example

cleanup_volume(“testvol”)

distaflibs.gluster.volume_ops.setup_vol(volname, mnode=None, dist=1, rep=1, dispd=1, red=1, stripe=1, trans='tcp', servers=None)

Setup a gluster volume for testing. It first formats the back-end bricks and then creates a trusted storage pool by doing peer probe. And then it creates a volume of specified configuration.

When the volume is created, it sets a global flag to indicate that the volume is created. If another testcase calls this function for the second time with same volume name, the function checks for the flag and if found, will return True.

Parameters:volname (str) – volume name that has to be created
Kwargs:
mnode(str): server on which command has to be execeuted,
defaults to tc.servers[0]

dist(int): distribute count, defaults to 1 rep(int): replica count, defaults to 1 stripe(int): stripe count, defaults to 1 trans(str): transport type, defaults to tcp servers(list): servers on which volume has to be created,

defaults to number of servers in pool list, if that is None, then takes tc.servers

disp(int): disperse count, defaults to 1 dispd(int): disperse-data count, defaults to 1 red(int): rdundancy count, defaults to 1

Returns:True on success and False for failure.
Return type:bool
distaflibs.gluster.volume_ops.volume_status(volname='all', service='', options='', mnode=None)

Executes gluster volume status cli command

Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].

volname (str): volume name. Defaults to ‘all’ service (str): name of the service to get status.

serivce can be, [nfs|shd|<BRICK>|quotad]], If not given, the function returns all the services
options (str): options can be,
[detail|clients|mem|inode|fd|callpool|tasks]. If not given, the function returns the output of gluster volume status
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

volume_status()

distaflibs.gluster.volume_ops._parse_volume_status_xml(root_xml)

Helper module for get_volume_status. It takes root xml object as input, parses and returns the ‘volume’ tag xml object.

distaflibs.gluster.volume_ops.parse_xml(tag_obj)

This helper module takes any xml element object and parses all the child nodes and returns the parsed data in dictionary format

distaflibs.gluster.volume_ops.get_volume_status(volname='all', service='', options='', mnode=None)

This module gets the status of all or specified volume(s)/brick

Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].

volname (str): volume name. Defaults to ‘all’ service (str): name of the service to get status.

serivce can be, [nfs|shd|<BRICK>|quotad]], If not given, the function returns all the services
options (str): options can be,
[detail|clients|mem|inode|fd|callpool|tasks]. If not given, the function returns the output of gluster volume status
Returns:volume status in dict of dictionary format, on success NoneType: on failure
Return type:dict

Example

get_volume_status(volname=”testvol”) >>>{‘testvol’: {‘10.70.47.89’: {‘/bricks/brick1/a11’: {‘status’: ‘1’, ‘pid’: ‘28963’, ‘bricktype’: ‘cold’, ‘port’: ‘49163’, ‘peerid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘49163’}}, ‘/bricks/brick2/a31’: {‘status’: ‘1’, ‘pid’: ‘28982’, ‘bricktype’: ‘cold’, ‘port’: ‘49164’, ‘peerid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘49164’}}, ‘NFS Server’: {‘status’: ‘1’, ‘pid’: ‘30525’, ‘port’: ‘2049’, ‘peerid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘2049’}}, ‘/bricks/brick1/a12’: {‘status’: ‘1’, ‘pid’: ‘30505’, ‘bricktype’: ‘hot’, ‘port’: ‘49165’, ‘peerid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘49165’}}}, ‘10.70.47.118’: {‘/bricks/brick1/a21’: {‘status’: ‘1’, ‘pid’: ‘5427’, ‘bricktype’: ‘cold’, ‘port’: ‘49162’, ‘peerid’: ‘5397d8f5-2986-453a-b0b5-5c40a9bb87ff’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘49162’}}, ‘/bricks/brick2/a41’: {‘status’: ‘1’, ‘pid’: ‘5446’, ‘bricktype’: ‘cold’, ‘port’: ‘49163’, ‘peerid’: ‘5397d8f5-2986-453a-b0b5-5c40a9bb87ff’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘49163’}}, ‘NFS Server’: {‘status’: ‘1’, ‘pid’: ‘6397’, ‘port’: ‘2049’, ‘peerid’: ‘5397d8f5-2986-453a-b0b5-5c40a9bb87ff’, ‘ports’: {‘rdma’: ‘N/A’, ‘tcp’: ‘2049’}}}}}

distaflibs.gluster.volume_ops.get_volume_option(volname, option='all', mnode=None)

gets the option values for the given volume.

Parameters:volname (str) – volume name
Kwargs:
option (str): volume option to get status.
If not given, the function returns all the options for the given volume
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
Returns:value for the given volume option in dict format, on success NoneType: on failure
Return type:dict

Example

get_volume_option(“testvol”)

distaflibs.gluster.volume_ops.set_volume_options(volname, options, mnode=None)

sets the option values for the given volume.

Parameters:
  • volname (str) – volume name
  • options (dict) – volume options in key value format
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
Returns:True, if the volume option is set False, on failure
Return type:bool

Example

options = {“user.cifs”:”enable”,”user.smb”:”enable”} set_volume_option(“testvol”, options=options)

distaflibs.gluster.volume_ops.volume_info(volname='all', mnode=None)

Executes gluster volume info cli command

Kwargs:

volname (str): volume name. Defaults to ‘all’ mnode (str): Node on which cmd has to be executed.

If None, defaults to servers[0].
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

volume_status()

distaflibs.gluster.volume_ops.get_volume_info(volname='all', mnode=None)
Fetches the volume information as displayed in the volume info.
Uses xml output of volume info and parses the into to a dict
Kwargs:

volname (str): volume name. Defaults to ‘all’ mnode (str): Node on which cmd has to be executed.

If None, defaults to servers[0].
Returns:If there are errors dict: volume info in dict of dicts
Return type:NoneType

Example

get_volume_info(volname=”testvol”) >>>{‘testvol’: {‘status’: ‘1’, ‘xlators’: None, ‘disperseCount’: ‘0’, ‘bricks’: {‘coldBricks’: {‘colddisperseCount’: ‘0’, ‘coldarbiterCount’: ‘0’, ‘coldBrickType’: ‘Distribute’, ‘coldbrickCount’: ‘4’, ‘numberOfBricks’: ‘4’, ‘brick’: [{‘isArbiter’: ‘0’, ‘name’: ‘10.70.47.89:/bricks/brick1/a11’, ‘hostUuid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’}, {‘isArbiter’: ‘0’, ‘name’: ‘10.70.47.118:/bricks/brick1/a21’, ‘hostUuid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’}, {‘isArbiter’: ‘0’, ‘name’: ‘10.70.47.89:/bricks/brick2/a31’, ‘hostUuid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’}, {‘isArbiter’: ‘0’, ‘name’: ‘10.70.47.118:/bricks/brick2/a41’, ‘hostUuid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’}], ‘coldreplicaCount’: ‘1’}, ‘hotBricks’: {‘hotBrickType’: ‘Distribute’, ‘numberOfBricks’: ‘1’, ‘brick’: [{‘name’: ‘10.70.47.89:/bricks/brick1/a12’, ‘hostUuid’: ‘7fc9015e-8134-4753-b837-54cbc6030c98’}], ‘hotbrickCount’: ‘1’, ‘hotreplicaCount’: ‘1’}}, ‘type’: ‘5’, ‘distCount’: ‘1’, ‘replicaCount’: ‘1’, ‘brickCount’: ‘5’, ‘options’: {‘cluster.tier-mode’: ‘cache’, ‘performance.readdir-ahead’: ‘on’, ‘features.ctr-enabled’: ‘on’}, ‘redundancyCount’: ‘0’, ‘transport’: ‘0’, ‘typeStr’: ‘Tier’, ‘stripeCount’: ‘1’, ‘arbiterCount’: ‘0’, ‘id’: ‘ffa8a8d1-546f-4ebf-8e82-fcc96c7e4e05’, ‘statusStr’: ‘Started’, ‘optCount’: ‘3’}}

distaflibs.gluster.volume_ops.sync_volume(hostname, volname='all', mnode=None)

syncs the volume

Parameters:hostname (str) – host name
Kwargs:

volname (str): volume name. Defaults to ‘all’. mnode (str): Node on which cmd has to be executed.

If None, defaults to servers[0].
Returns:Tuple containing three elements (ret, out, err). The first element ‘ret’ is of type ‘int’ and is the return value of command execution.

The second element ‘out’ is of type ‘str’ and is the stdout value of the command execution.

The third element ‘err’ is of type ‘str’ and is the stderr value of the command execution.

Return type:tuple

Example

sync_volume(“abc.xyz.com”,volname=”testvol”)

distaflibs.gluster.volume_ops.get_subvols(volname, mnode=None)

Gets the subvolumes in the given volume

Parameters:volname (str) – volume name
Kwargs:
mnode (str): Node on which cmd has to be executed.
If None, defaults to servers[0].
Returns:with empty list values for all keys, if volume doesn’t exist dict: Dictionary of subvols, value of each key is list of lists
containing subvols
Return type:dict

Example

get_subvols(“testvol”)