utils¶
utils¶
Utility functions and classes for QA scripts
-
otto.utils.fill_volume(fname, offset=None, char=None)[source]¶ Write a repeating character at to a file. Defaults to ‘0’ and no offset.
-
otto.utils.parse_args(required_args, optional_args=None)[source]¶ Returns a dict of args to a script obtained from either a config file or the command line. Any argument on the command line will override its value in the config file.
- arguments:
- required_args: list of arguments that a script requires optional_args: list of optional arguments
- example:
This example is for a script that requires the args: ‘srx1_shelf’, ‘srx1_lun1’, and ‘vsx1_hostname’ and has an optional arg: raid_type
To use this function, place the following 3 lines in your script:
args = utils.parse _args(['srx1_shelf', 'srx1_lun1', 'vsx1_hostname'],['raid_type']) for arg in args: vars()[arg] = args[arg]
The last 2 lines above are optional, but make it cleaner to use arguments in your script e.g. you can use vsx1_hostname instead of args[‘vsx1_hostname’]
then, you can call your script either of the following 2 ways:
- python yourscript.py –srx1_shelf 99 –srx1_lun1 99.1 –vsx1_hostname VSX_NAME
or
- python yourscript.py –config your_config.cfg
in which your config file contains the following:
[General] srx1_shelf = 99 srx1_lun1 = 99.0 vsx1_hostname = VSX_NAME
In your script, arguments can be called by their name. e.g. print(vsx1_hostname)
tip: If you want your script to have a default value for some arg (e.g. raid_type ), you can do the following: raid_type = args.get(‘raid_type’) or ‘raid5’
Note: please see: https://twiki.coraid.com/cgi-bin/twiki/view/EngDev/OttoTestConfigFile for suggested naming conventions for arguments.
-
otto.utils.random_string(length)[source]¶ Generates a random string of a given length consisting of only the set of:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789