This module implements connection handling. Using the classes from this module you can connect directly to a target device via serial or ssh. Example:
import monk_tf.conn as mc
# create a serial connection
serial=mc.SerialConn(port="/dev/ttyUSB3", user="tester", pw="test")
# create a ssh connection
ssh=mc.SshConn(host="192.168.2.123", user="tester", pw="test")
# send a command
print serial.cmd("ls -al")
[...]
# send a command
ssh.cmd("ls -al")
[...]
Bases: object
is the base class for all connections.
Don’t instantiate this class directly.
This class implements the behaviour of cmd() interactions, and it makes sure that it doesn’t login a user that is already logged in.
Extending this class requires to implement _get_exp() and _login().
send a shell command and retreive its output.
Parameters: |
|
---|---|
Returns: | the stdout and stderr of the shell command |
attempts to authenticate to the connection.
Default for user and password are the one’s given to the connection on instantiation.
Parameters: |
|
---|
Bases: monk_tf.conn.ConnectionBase
implements a serial connection.
Parameters: |
|
---|
Bases: monk_tf.conn.ConnectionBase
implements an ssh connection.
Parameters: |
|
---|
This module implements device handling. Using the classes from this module you can abstract a complete target device in a single object. On instantiation you give it some connections and then (theoretically) let the device handle the rest.
Example:
import monk_tf.dev as md
import monk_tf.conn as mc
# create a device with a ssh connection and a serial connection
d=md.Device(
mc.SshConn('192.168.2.100', 'tester', 'secret'),
mc.SerialConn('/dev/ttyUSB2', 'root', 'muchmoresecret'),
)
# send a command (the same way as with connections)
print d.cmd('ls -al')
[...]
Bases: monk_tf.dev.DeviceException
is raised when a request cannot be handled by the connections of a Device.
Bases: monk_tf.dev.Hydra
Use this class instead of your other classes for development purposes
It does not reset anything and does not update. Everything else should work fine, though.
Bases: object
is the API abstraction of a target device.
Parameters: |
|
---|
Send a shell command to the target device.
Parameters: |
|
---|---|
Returns: | the standard output of the shell command. |
Bases: exceptions.Exception
Base class for exceptions of the device layer.
Bases: monk_tf.dev.Device
is the device type of DResearch Fahrzeugelektronik GmbH.
Bases: monk_tf.dev.DeviceException
is raised if an update didn’t get finished or was rolled back.
Instead of creating Device and AConnection objects by yourself, you can also choose to put corresponding data in a separate file and let this layer handle the object concstruction and destruction for you. Doing this will probably make your test code look more clean, keep the number of places where you need to change something as small as possible, and lets you reuse data that you already have described.
A hello world test with it looks like this:
import nose
from monk_tf import fixture
def test_hello():
''' say hello
'''
# set up
h = fixture.Fixture('target_device.cfg')
expected_out = "hello"
# execute
out = h.devs[0].cmd('echo "hello"')
# assert
nose.tools.eq_(expected_out, out)
# tear down
h.tear_down()
When using this layer setting up a device only takes one line of code. The rest of the information is in the target_device.cfg file. MONK currently comes with one text format parser predefined, which is the XiniParser. Xini is short for extended INI. You may, however, use any data format you want, if you extend the AParser class accordingly.
An example Xini data file might look like this:
[device1]
type=Device
[[serial1]]
type=SerialConnection
port=/dev/ttyUSB1
user=example
password=secret
As you can see it looks like an INI file. There are sections, consisting of a title enclosed in squared brackets ([]) and lists of properties, consisting of key-value pairs separated by equality signs (=). The unusual part is that the section serial1 is surrounded by two pairs of squared brackets ([]). This is the specialty of this format indicating that serial1 is a subsection of device1 and therefore is a nested section. This nesting can be done unlimited, by surrounding a section with more and more pairs of squared brackets ([]) according to the level of nesting intended. In this example serial1 belongs to device1 and the types indicate the corresponding MONK object to be created.
Bases: exceptions.Exception
Base class for exceptions of the fixture layer.
If you want to make sure that you catch all exceptions that are related to this layer, you should catch AFixtureExceptions. This also means that if you extend this list of exceptions you should inherit from this exception and not from Exception.
Bases: monk_tf.fixture.AFixtureException
Base class for exceptions concerning parsing errors.
Bases: dict
Base class for all parsers.
Do not instantiate this class! This basically just provides the API that is needed by Fixture to interact with the data that is parsed. Each child class should make sure that it always provides its parsed data like a dict would. If you require your own parser, you can extend this. XiniParser provides a very basic example.
Bases: monk_tf.fixture.AFixtureException
is raised when a Fixture cannot parse a given file.
Bases: object
Creates MONK objects based on dictionary like objects.
This is the class that provides the fundamental feature of this layer. It reads data files by trying to parse them via its list of known parsers and if it succeeds, it creates MONK objects based on the configuration given by the data file. Most likely these objects are one or more Device objects that have at least one AConnection object each. If more than one fixture file is read containing the same name on the highest level, then the latest data gets used. This does not work on lower levels of nesting, though. If you attempt to overwrite lower levels of nesting, what actually happens is that the highest layer gets overwritten and you lose the data that was stored in the older objects. This is simply how set.update() works.
One source of data (either a file name or a child class of AParser) can be given to an object of this class by its constructer, others can be added afterwards with the read() method. An example looks like this:
import monk_tf.fixture as mf
fixture = mf.Fixture('/etc/monk_tf/default_devices.cfg')
.read('~/.monk/default_devices.cfg')
# can also be a parser object
.read(XiniParser('~/testsuite12345/suite_devices.cfg'))
Parameters: |
|
---|
Bases: monk_tf.fixture.AFixtureException
is raised when a :py:clas:`~monk_tf.fixture.Fixture` requires a device but has none.
Bases: monk_tf.fixture.AParseException
is raised when a fixture file could not be parsed as extended INI.
Bases: configobj.ConfigObj, monk_tf.fixture.AParser
Reads config files in extended INI format.
Parse a config file or create a config file object.
This is the package overview of MONK. If anything is unclear, you might have a look into Getting Started.
The following texts describe the three layers that were explained in The Layers: