Internal API

pas.case

Collection of utilities to deal with the management of the different test cases of the suite.

pas.case.compile(name, localdir=None, remotedir=None)[source]

Compiles the given test case on all the hosts in the system.

The building details and the respect of the convention are enforced by the Makefile and not further explained here.

pas.case.execute(name, remotedir=None)[source]

Executes the given test case on all client hosts (normally onle one).

pas.case.select(name=None, basedir=None)[source]

Scans the basedir (or the test-cases directory defined in the settings) for directories and returns a choice based on different criteria:

  1. No directories are found; raise a RuntimeError
  2. The name is set; check if it was found and if so return it
  3. Only one directory is found; return the found directory
  4. Multiple directories are found; ask the user to pick one
  1. If no measure case exist yet, a RuntimeError is thrown;
  2. If only one measure case is found, its path is returned;
  3. If more than one measure cases are found, then the user is asked to choose one between them.

The list presented to the user when asked to choose a case will be something like the following:

Multiple test cases found:

     [0]: simple
     [1]: complex

Select a test case: _

pas.conf

Settings support for the whole pas package.

This module contains methods to load and temporarily store setting directives for the current execution.

Various shortcuts to access the different settings in a usage-oriented way are also provided.

pas.conf.all_hosts()[source]

Returns a set of all hosts obtained by chaining all hosts in the ROLES settings directive.

pas.conf.role(role_name)[source]

Returns a list of all hosts for a given role.

pas.conf.map_interfaces()[source]

Returns a dict mapping host connection strings to interfaces, obtained by combining the INTERFACES and ROLES settings directives.

pas.env

General test suite environment management functions.

pas.env.setup(dstdir)[source]

Sets up a new environment in the given directory by recursively copying all the files inside pas.conf.suite_template to the given directory.

The destination directory must already exist.

pas.jobmgr

Remote JobMgr management utilities.

The following functions provide some wrappers around remote shell commands to easily start, stop, restart or otherwise interact with a POP-C++ job manager.

pas.jobmgr.kill()[source]

Kills ALL running job managers (and the relative search nodes) on the hosts provided by the context or (by default) on all known hosts.

pas.jobmgr.killall()[source]

Alias for the kill function, as no special treatment is needed here.

pas.jobmgr.restart()[source]

Stops and restarts a currently running JobMgr instance on one or more (depending on the current context) remote nodes in a unique command.

This function is intended to be used to restart a single node. To restart all nodes of a system, use the startall function, which introduces some delays to allow a correct registration of the slaves by the master.

pas.jobmgr.restartall()[source]

Restarts all nodes in the system using the stopall and startall functions.

Due to the introduction of the delays, the stop and start calls will not happen in the same command as for the restart function.

pas.jobmgr.start()[source]

Starts a JobMgr instance on one or more (depending on the current context) remote nodes.

This function is intended to be used to start a single node. To start all nodes of a system, use the startall function, which introduces some delays to allow a correct registration of the slaves by the master.

pas.jobmgr.startall()[source]

Starts all nodes of the system grouped by roles with the necessary delays to allow a proper registration to the parent JobMgr.

The delay between the invocations can be set in the settings.

pas.jobmgr.stop()[source]

Stops a currently running JobMgr instance on one or more (depending on the current context) remote nodes.

This function is intended to be used to stop a single node. To stop all nodes of a system, use the startall function, which introduces some delays to allow a correct registration of the slaves by the master.

pas.jobmgr.stopall()[source]

Stops all nodes of the system grouped by roles with the necessary delays to allow a proper registration to the parent JobMgr.

The delay between the invocations can be set in the settings.

Note that in this case the delays are not as important as in the start function on could probably safely be omitted. The behavior is preserved to grant compatibility with future versions of the JobMgr which possibly wants to execute some cleanup code before terminating.

In the meanwhile it is possible to set the delay to 0 in the settings.

pas.measure

Measure management functions.

pas.measure.collect(name, overwrite=False)[source]

Moves the relevant files to the shared directory by asking to empty the destination directory if needed.

pas.measure.decode(name, measure_case, prettyprint=False)[source]

Decodes the simplified XML representation of the given measure by adding a “decoded” element to each packet containing a payload.

The decoding is done using an XSL transformation coupled with an xslt python extension function which provides the “decoded” element given a payload text string.

pas.measure.kill()[source]

Alias for tshark.kill

pas.measure.report(name, measure_case)[source]

Assembles all the acquired resources (such as source code, measures and log files) and generates an html page suitable for human interaction and analysis.

pas.measure.select(name=None, basedir=None)[source]

Scans the basedir (or the shared-measures directory defined in the settings) for directories and returns a choice based on different criteria:

  1. No directories are found; raise a RuntimeError
  2. The name is set; check if it was found and if so return it
  3. Only one directory is found; return the found directory
  4. Multiple directories are found; ask the user to pick one
pas.measure.simplify(name, prettyprint=True)[source]

Simplifies all the measure files in pdxml format of the given measure, converting them using the simplify XSL stylesheet. Old simplifications will be overwritten.

If the prettyprint optional argument is True, the result will be formatted using the xmllint tool.

pas.measure.start(name)[source]

Start a new named measure session in background on all interested hosts.

The hosts are retrieved from the ROLES setting directive and a measure is started for each one.

pas.measure.stop(name)[source]

Start a new named measure session in background on all interested hosts.

As for the start function, the hosts are retrieved from the interfaces setting directive and the stop command issued on each one.

pas.measure.toxml(name)[source]

Converts all raw measure files for the given measure to xml using a remote tshark command.

This will overwrite all already converted files with matching names.

pas.shell

Local and remote shell commands execution.

These functions are mainly wrappers around those found in the fabric library.

pas.shell.ignore_warnings()[source]

Returns a fabric context manager configured to silently ignore all warnings about running commands.

pas.shell.workon(hosts)[source]

Returns a fabric context manager which sets the hosts list to the given list.

If the passed hosts argument is a single string, it is silently converted to a list before.

pas.shell.local(cmd)[source]

Executes a local command without capturing and returning the output.

Thin wraper around the fabric.operations.local function

pas.shell.remote(cmd, pty=False, user=None, sudo=False)[source]

Executes the given remote command on the hosts list set in the current context.

If user is given or sudo evaluates to True, then a fabric.operations.sudo call is made, otherwise a simple fabric.operations.run.

pas.shell.cd(path)

Context manager that keeps directory state when calling operations.

Any calls to run, sudo or local within the wrapped block will implicitly have a string similar to "cd <path> && " prefixed in order to give the sense that there is actually statefulness involved.

Because use of cd affects all such invocations, any code making use of run/sudo/local, such as much of the contrib section, will also be affected by use of cd. However, at this time, get and put do not honor cd; we expect this to be addressed in future releases.

Like the actual ‘cd’ shell builtin, cd may be called with relative paths (keep in mind that your default starting directory is your remote user’s $HOME) and may be nested as well.

Below is a “normal” attempt at using the shell ‘cd’, which doesn’t work due to how shell-less SSH connections are implemented – state is not kept between invocations of run or sudo:

run('cd /var/www')
run('ls')

The above snippet will list the contents of the remote user’s $HOME instead of /var/www. With cd, however, it will work as expected:

with cd('/var/www'):
    run('ls') # Turns into "cd /var/www && ls"

Finally, a demonstration (see inline comments) of nesting:

with cd('/var/www'):
    run('ls') # cd /var/www && ls
    with cd('website1'):
        run('ls') # cd /var/www/website1 && ls

Note

This context manager is currently implemented by appending to (and, as always, restoring afterwards) the current value of an environment variable, env.cwd. However, this implementation may change in the future, so we do not recommend manually altering env.cwd – only the behavior of cd will have any guarantee of backwards compatibility.

pas.shell.prompt(text, key=None, default='', validate=None)

Prompt user with text and return the input (like raw_input).

A single space character will be appended for convenience, but nothing else. Thus, you may want to end your prompt text with a question mark or a colon, e.g. prompt("What hostname?").

If key is given, the user’s input will be stored as env.<key> in addition to being returned by prompt. If the key already existed in env, its value will be overwritten and a warning printed to the user.

If default is given, it is displayed in square brackets and used if the user enters nothing (i.e. presses Enter without entering any text). default defaults to the empty string. If non-empty, a space will be appended, so that a call such as prompt("What hostname?", default="foo") would result in a prompt of What hostname? [foo] (with a trailing space after the [foo].)

The optional keyword argument validate may be a callable or a string:

  • If a callable, it is called with the user’s input, and should return the value to be stored on success. On failure, it should raise an exception with an exception message, which will be printed to the user.
  • If a string, the value passed to validate is used as a regular expression. It is thus recommended to use raw strings in this case. Note that the regular expression, if it is not fully matching (bounded by ^ and $) it will be made so. In other words, the input must fully match the regex.

Either way, prompt will re-prompt until validation passes (or the user hits Ctrl-C).

Examples:

# Simplest form:
environment = prompt('Please specify target environment: ')

# With default, and storing as env.dish:
prompt('Specify favorite dish: ', 'dish', default='spam & eggs')

# With validation, i.e. requiring integer input:
prompt('Please specify process nice level: ', key='nice', validate=int)

# With validation against a regular expression:
release = prompt('Please supply a release name',
        validate=r'^\w+-\d+(\.\d+)?$')
pas.shell.confirm(question, default=True)

Ask user a yes/no question and return their response as True or False.

question should be a simple, grammatically complete question such as “Do you wish to continue?”, and will have a string similar to ” [Y/n] ” appended automatically. This function will not append a question mark for you.

By default, when the user presses Enter without typing anything, “yes” is assumed. This can be changed by specifying default=False.

pas.tshark

Various utilities to deal with remote tshark operations with support for features such as background execution, stop on request, and advanced tshark interactions.

Note that all of the commands which operate on remote hosts, respect the current set context to retrieve the host lists. When this list is not set or is empty, the command will be run on all hosts. Refer to the documentation on pas.shell to obtain further information.

Most of the command below use the tshark command-line tool directly; refer to its man page for the details about the usage.

pas.tshark.kill()[source]

Kills ALL running measures on the hosts provided by the context or (by default) on all known hosts.

pas.tshark.pcaptoxml(infile, outfile, display_filter='')[source]

Converts the pcap input file to XML and writes the output to outfile while filtering using the given display filter.

Refer directly to the tshark man page for further informations about the display filter syntax.

pas.tshark.start(name, iface='lo', outfile='-', capture_filter='')[source]

Starts a new tshark capture in background using a named screen session.

The name of the spawned screen session will be the provided name joined with the interface by a dot.

pas.tshark.stop(name, interface)[source]

Stops the named tshark capture session on the given interface.

The final name passed to the screen command will be the name joined with the interface by a dot.

pas.xml

class pas.xml.Transformation(stylesheet)[source]

Object oriented wrapper for XSL transformations using lxml.

pas.xml.prettyprint(infile, outfile=None, local=True)[source]

Reformats an xml document using xmllint.

Table Of Contents

Previous topic

Built-in parser types

Next topic

Glossary

This Page