utils

utils

Utility functions and classes for QA scripts

otto.utils.aoetostr(addr)[source]

Convert var of type aoeaddress or dict to a string.

otto.utils.compare(a, b, expectation=True)[source]

compare two arbitrary items logging results

otto.utils.compare_files(file1, file2, expectation=True)[source]
otto.utils.copy_file(src, dest, background=False)[source]

Copy the source file to the destination.

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.get_size(fname)[source]

Return the size in bytes of the file

otto.utils.md5sum(fname)[source]

Calculate md5 checksum of a file.

otto.utils.now()[source]

Return current epoch time

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:

  1. python yourscript.py –srx1_shelf 99 –srx1_lun1 99.1 –vsx1_hostname VSX_NAME

or

  1. 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
otto.utils.read_bytes(filename, size=8192)[source]

Read a given number of bytes from filename.

otto.utils.remove_file(f)[source]

Remove a file from the system.

otto.utils.since(start)[source]

Return the number of seconds since input time

otto.utils.strtoaoe(addr)[source]

Convert a variable of string to AoE

otto.utils.timefmt(secs)[source]

Nicely format number of secs given secs or µsecs for output.

otto.utils.write_bytes(filename, num, pattern=None, offset=None)[source]

Write a given number of bytes to filename.

otto.utils.write_data(fname, offset, length, char)[source]

Write data to a file.