[riot-notifications] [RIOT-OS/RIOT] riotnode: node abstraction package (#10949)

Gaƫtan Harter notifications at github.com
Tue Feb 5 15:25:23 CET 2019

### Contribution description

This is a start to try providing a common interface that could be used as a test agnostic base that could be used for automating experiments but also, on a shorter term for testing with the current tests, the i2c testing, some framework directions with tests (RobotFramework/pytest), release specs with multiple nodes under test.

Different parallel directions have been taken with different low level wrapper. The goal here would be to share a common base where then every usage could benefit of the common developments.

It is currently only a base class without any `shell` abstraction but wanted to publish earlier to get feedback and it could also be used in this state. I focused to put the test ecosystem around to help developing.

Usage can be seen in `testrunner` wrapping and in `test_running_error_cases(app_pidfile_env)` test.
Current usage in code is

    node = riotnode.node.RIOTNode(application_directory=`optional_dir_if_not_curr_dir`, env=node_specific_env_dict)
    node.start_term(logfile=sys.stdout)  # or use the context manager

One important thing I think, is that it implements wrapping for only one node, as it is the only thing we can do in RIOT. Handling two nodes means having two different environments (specific env variables) with two instances of one node.

This pull requests is an aggregate of:

1. empty python package integration with test suite
2. an object implementation of a node abstraction. It gives access to the serial port as an `expect` spawn object. So somehow what `testrunner` does but with a different interface. 
3. @miri64 pull request https://github.com/RIOT-OS/RIOT/pull/10431
4. Usage of this object with previous pull request
5. Some other changes that could come in

#### Upcoming work

After different IRL discussions, I am thinking about providing other abstraction classes for shell commands more as a composition than inherited objects (or more let other provide abstractions, as it is the goal to share this between different developers).
And implemented with independent classes that you use alone instead of an aggregated object with everything in the same object.
This could allow a light usage with a specific object, while still allowing to create an aggregated objects if needed but not enforcing it.

class RIOTNodeShellIfconfig():
    def __init__(self, node):
        self.node = node
        self.term = self.RIOTNODE_SHELL_CLASS(node)
    def get_default_interface(self):
        ret = self.term.send_command("ifconfig get_interfaces")
        interface = # parse ret to get the correct string
        return int(interface)

node = RIOTNode()
ifconfig_node = RIOTNodeShellIfconfig(node)
interface_num = ifconfig_node.get_default_interface()

This one could still maybe use a common `RIOTNodeShellWrapper` as base class, it is thing that should be discussed depending on the usages.

### Reviewing procedure

I would advise to review commit by commit as they are focusing on different concepts.
Also see if the abstraction could currently work for you.

I still have `TODO` comments in the code I want to address before merging I would gladly get feedback on them. They are shown when running `tox` test command.
There is also a `TODO.rst` for things that were here before in `testrunner` and could be addressed later.

I was told that `node` that I took from my work on IoT-LAB was maybe not a good name for this.

Please show me where this could help you or not and if you already have needs around this.

### Testing procedure

Running the test suite can be run with `tox` (`pip install --user tox`).

Note: there should now be TODO` warning as I thought about something I want to address before any merging.

See if it can be used a as base for your cases and if you have feedback on the next steps.

### Issues/PRs references

My comment on RobotFramework RFC https://github.com/RIOT-OS/RIOT/issues/10241#issuecomment-446561797

Some example place where it could be used as a base

* https://github.com/RIOT-OS/Release-Specs/pull/79
* https://github.com/RIOT-OS/Release-Specs/blob/a1a46649574cc2b7885869789fd924ad672d2915/07-multi-hop/IOTLABHelper.py (but it currently uses `serial_aggregator` as a base)
* our tests, even more for `shell` tests
* as a base for a `RIOTDriver` in `riot_pal`.
You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * riotnode: add an empty package directory for 'riotnode'
  * riotnode: add node implementation and tests
  * dist/pythonlibs: expose functions to setup/teardown pexpect spawn
  * dist/pythonlibs: provide unittest TestCase wrapper for testrunner
  * testrunner: use riotnode inside
  * testrunner/spawn: take pexpect_path as argument
  * riotnode: Replace pexpect exception value with pattern
  * TODO ADD TESTS riotnode: Remove exception context from inside pexpect implementation
  * squash! riotnode: add node implementation and tests

-- File Changes --

    A dist/pythonlibs/riotnode/.coveragerc (2)
    A dist/pythonlibs/riotnode/.gitignore (112)
    A dist/pythonlibs/riotnode/README.rst (28)
    A dist/pythonlibs/riotnode/TODO.rst (24)
    A dist/pythonlibs/riotnode/out.pdf (0)
    A dist/pythonlibs/riotnode/requirements.txt (2)
    A dist/pythonlibs/riotnode/riotnode/__init__.py (11)
    A dist/pythonlibs/riotnode/riotnode/node.py (197)
    A dist/pythonlibs/riotnode/riotnode/tests/__init__.py (1)
    A dist/pythonlibs/riotnode/riotnode/tests/node_test.py (132)
    A dist/pythonlibs/riotnode/riotnode/tests/riotnode_test.py (10)
    A dist/pythonlibs/riotnode/riotnode/tests/utils/application/Makefile (16)
    A dist/pythonlibs/riotnode/riotnode/tests/utils/application/echo.py (16)
    A dist/pythonlibs/riotnode/riotnode/tests/utils/application/node.py (49)
    A dist/pythonlibs/riotnode/setup.cfg (15)
    A dist/pythonlibs/riotnode/setup.py (48)
    A dist/pythonlibs/riotnode/tox.ini (33)
    A dist/pythonlibs/sitecustomize.py (7)
    M dist/pythonlibs/testrunner/__init__.py (65)
    A dist/pythonlibs/testrunner/spawn.py (62)
    A dist/pythonlibs/testrunner/unittest.py (23)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190205/1ba25079/attachment.html>

More information about the notifications mailing list