Commit 68839a61 authored by Federico Sismondi's avatar Federico Sismondi

big imports refact, fixed setup.py

parent 79ef7f60
Agent for the f-interop platform (ioppytest-agent) Agent for the f-interop platform (ioppytest-agent)
-------------------------------------------------- --------------------------------------------------
About
-----
Agent (~VPN client) is a component which connects the environment where
the IUT runs to testing tool using the AMQP bus.
This component is part of the ioppytest framework ecosystem.
This components needs to run in the user's host and must share some
kind on interface with the implementation under test (IUT), it will
enable the creation of a private network between all devices in the
session.
Installation
------------
create virtual env for not messing up your current environment
```
pip install virtualenv
virtualenv -p /usr/bin/python2.7 my_venv
source my_venv/bin/activate
```
install ioppytest-agent using pip
```
pip install ioppytest-agent
```
Design Design
------ ------
The design of the f-interop agent is modular by design.
An agent is made of different processes that connect to AMQP message An agent is made of different processes that connect to AMQP message
broker and exchange messages (in and out) with other components using broker and exchange messages (in and out) with other components using
the same AMQP broker. the same AMQP broker.
...@@ -19,13 +44,10 @@ charge of launching all the other components. ...@@ -19,13 +44,10 @@ charge of launching all the other components.
If new components needs to be added they just need to be launched If new components needs to be added they just need to be launched
from this component. from this component.
Core open the default ZMQ socket that is used by other components to
communicate with each others.
Error handling Error handling
-------------- --------------
When there is a Ctrl-C the agent should kill all other components and When there is a user interrupt signal (Ctrl-C) the agent should kill
disconnect as gracefully as possible. all other components and disconnect as gracefully as possible.
Serial mode (with 802.15.4 probe) Serial mode (with 802.15.4 probe)
......
...@@ -25,19 +25,15 @@ Features of the agent ...@@ -25,19 +25,15 @@ Features of the agent
""" """
from __future__ import absolute_import from __future__ import absolute_import
import sys
import logging import logging
import click import click
import uuid
import multiprocessing
from .connectors.tun import TunConnector from .connectors import TunConnector
from .connectors.core import CoreConnector from .connectors import CoreConnector
from .connectors.http import HTTPConnector from .connectors import SerialConnector
from .connectors.serialconn import SerialConnector
from .utils import arrow_down, arrow_up, ioppytest_banner from .utils import ioppytest_banner
from .utils.packet_dumper import launch_amqp_data_to_pcap_dumper from .utils import packet_dumper
try: try:
from urllib.parse import urlparse from urllib.parse import urlparse
...@@ -58,9 +54,12 @@ class Agent(object): ...@@ -58,9 +54,12 @@ class Agent(object):
""" """
header = """ header = """
Agent (~VPN client) is a component which connects to testing tool using the AMQP bus. This component is part of the Agent (~VPN client) is a component which connects the environment where
ioppytest framework ecosystem. This components needs to run in the user's host and must share some kind on interface the IUT runs to testing tool using the AMQP bus.
with the implementation under test (IUT), it will enable the creation of a private network between all devices in the This component is part of the ioppytest framework ecosystem.
This components needs to run in the user's host and must share some
kind on interface with the implementation under test (IUT), it will
enable the creation of a private network between all devices in the
session. session.
Some examples on the different modes of running the agent (depending on the cabling and networking of your IUT): Some examples on the different modes of running the agent (depending on the cabling and networking of your IUT):
...@@ -265,7 +264,7 @@ For more information: README.md ...@@ -265,7 +264,7 @@ For more information: README.md
# TODO fix pcap_dumper support for py2, python3 -m utils.packet_dumper works fine tho # TODO fix pcap_dumper support for py2, python3 -m utils.packet_dumper works fine tho
# if dump: # if dump:
# dump_p = multiprocessing.Process(target=launch_amqp_data_to_pcap_dumper, args=()) # dump_p = multiprocessing.Process(target=packet_dumper.launch_amqp_data_to_pcap_dumper, args=())
# dump_p.start() # dump_p.start()
def run(self): def run(self):
......
from __future__ import absolute_import from __future__ import absolute_import
from . import core from .tun import TunConnector
from . import serialconn from .core import CoreConnector
from . import tun from .serialconn import SerialConnector
from . import base
\ No newline at end of file
...@@ -24,7 +24,6 @@ class CoreConsumer(BaseConsumer): ...@@ -24,7 +24,6 @@ class CoreConsumer(BaseConsumer):
subscriptions) subscriptions)
def on_consume_ready(self, connection, channel, consumers, wakeup=True, **kwargs): def on_consume_ready(self, connection, channel, consumers, wakeup=True, **kwargs):
log.info("Backend ready to consume data")
# let's send bootstrap message # let's send bootstrap message
msg = MsgTestingToolComponentReady( msg = MsgTestingToolComponentReady(
...@@ -39,9 +38,11 @@ class CoreConsumer(BaseConsumer): ...@@ -39,9 +38,11 @@ class CoreConsumer(BaseConsumer):
routing_key=msg.routing_key routing_key=msg.routing_key
) )
log.info("Agent READY, listening on the event bus for ctrl messages and data packets..")
def _on_message(self, message): def _on_message(self, message):
self.log.debug( self.log.warning(
"Consumer specialized handler <{consumer_name}> got: {message}".format( "<{consumer_name}> got {message}, no callback bound to it.".format(
consumer_name=self.consumer_name, consumer_name=self.consumer_name,
message=repr(message) message=repr(message)
) )
......
import json
import logging
from requests import Request, Session
from .base import BaseController, BaseConsumer
log = logging.getLogger(__name__)
class HTTPConsumer(BaseConsumer):
"""
AMQP helper
"""
def __init__(self, user, password, session, server, exchange, name, consumer_name):
super(HTTPConsumer, self).__init__(user, password, session, server, exchange, name, consumer_name)
def handle_control(self, body, message):
"""
Args:
body:
message:
Returns:
"""
required_keys = {"url", "verb", "data"}
msg = None
try:
msg = json.loads(body)
self.log.debug(message)
except ValueError as e:
message.ack()
self.log.error(e)
self.log.error("Incorrect message: {0}".format(body))
if msg is not None:
present_keys = set(msg.keys())
if not present_keys.issuperset(required_keys):
self.log.error("Error you need those keys: %s" % required_keys)
else:
s = Session()
req = Request(msg["verb"], msg["url"], data=msg["data"])
prepped = s.prepare_request(req)
resp = s.send(prepped)
self.log.info(resp.status_code)
class HTTPConnector(BaseController):
NAME = "http"
def __init__(self, **kwargs):
super(HTTPConnector, self).__init__(name=HTTPConnector.NAME)
kwargs["consumer_name"] = HTTPConnector.NAME
self.consumer = HTTPConsumer(**kwargs)
self.consumer.log = logging.getLogger(__name__)
self.consumer.log.setLevel(logging.DEBUG)
def run(self):
self.consumer.run()
...@@ -11,7 +11,7 @@ from kombu import Producer ...@@ -11,7 +11,7 @@ from kombu import Producer
from .base import BaseController, BaseConsumer from .base import BaseController, BaseConsumer
from ..utils.opentun import OpenTunLinux, OpenTunMACOS from ..utils.opentun import OpenTunLinux, OpenTunMACOS
from ..utils import arrow_up from ..utils import arrow_up, arrow_down
from ..utils import messages from ..utils import messages
...@@ -147,21 +147,13 @@ class TunConsumer(BaseConsumer): ...@@ -147,21 +147,13 @@ class TunConsumer(BaseConsumer):
self.log.info("Message received from testing tool. Injecting in Tun. Message count (downlink): %s" self.log.info("Message received from testing tool. Injecting in Tun. Message count (downlink): %s"
% self.packet_count) % self.packet_count)
print(arrow_up) print(arrow_down)
self.log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' + self.log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' +
'\n data packet EventBus -> TUN interface' + '\n data packet EventBus -> TUN interface' +
'\n' + message.to_json() + '\n' + message.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # #' '\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'
) )
# print(arrow_down)
# self.log.debug('\n* * * * * * HANDLE INCOMING PACKET (%s) * * * * * * *' % self.packet_count)
# self.log.debug("TIME: %s" % datetime.datetime.time(datetime.datetime.now()))
# self.log.debug(" - - - ")
# self.log.debug(("Interface", message.interface_name))
# self.log.debug(("Data", message.data))
# self.log.debug('\n* * * * * * * * * * * * * * * * * * * * * * *')
self.tun._eventBusToTun( self.tun._eventBusToTun(
sender="Testing Tool", sender="Testing Tool",
signal="tun inject", signal="tun inject",
......
from __future__ import absolute_import
from . import messages from . import messages
from . import packet_dumper
from . import serial_listener
import logging import logging
import os import os
......
...@@ -548,7 +548,7 @@ class OpenTunLinux(object): ...@@ -548,7 +548,7 @@ class OpenTunLinux(object):
# write over tuntap interface # write over tuntap interface
os.write(self.tunIf, data) os.write(self.tunIf, data)
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug("data dispatched to tun correctly {0}, {1}".format(signal, sender)) log.debug("data dispatched to tun correctly, event: {0}, sender: {1}".format(signal, sender))
except Exception as err: except Exception as err:
errMsg = formatCriticalMessage(err) errMsg = formatCriticalMessage(err)
log.critical(errMsg) log.critical(errMsg)
...@@ -778,7 +778,7 @@ class OpenTunMACOS(object): ...@@ -778,7 +778,7 @@ class OpenTunMACOS(object):
# write over tuntap interface # write over tuntap interface
os.write(self.tunIf, data) os.write(self.tunIf, data)
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug("data dispatched to tun correctly {0}, {1}".format(signal, sender)) log.debug("data dispatched to tun correctly, event: {0}, sender: {1}".format(signal, sender))
except Exception as err: except Exception as err:
errMsg = formatCriticalMessage(err) errMsg = formatCriticalMessage(err)
log.critical(errMsg) log.critical(errMsg)
......
...@@ -8,8 +8,7 @@ import sys ...@@ -8,8 +8,7 @@ import sys
from kombu import Exchange from kombu import Exchange
from collections import OrderedDict from collections import OrderedDict
from . import messages from ..utils import messages
from . import arrow_down, arrow_up, finterop_banner
STATE_OK = 0 STATE_OK = 0
STATE_ESC = 1 STATE_ESC = 1
......
...@@ -2,5 +2,4 @@ click ...@@ -2,5 +2,4 @@ click
six six
kombu kombu
pika pika
pyserial pyserial
requests \ No newline at end of file
\ No newline at end of file
...@@ -8,7 +8,7 @@ from setuptools import setup, find_packages ...@@ -8,7 +8,7 @@ from setuptools import setup, find_packages
MAJOR = 0 MAJOR = 0
MINOR = 1 MINOR = 1
PATCH = 2 PATCH = 8
VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH)
name = 'ioppytest-agent' name = 'ioppytest-agent'
...@@ -17,15 +17,12 @@ CLASSIFIERS = [ ...@@ -17,15 +17,12 @@ CLASSIFIERS = [
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research", "Intended Audience :: Science/Research",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"Intended Audience :: Testers",
# "License :: OSI Approved :: BSD License",
"Programming Language :: Python", "Programming Language :: Python",
"Programming Language :: Python :: 2", "Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7", "Programming Language :: Python :: 2.7",
"Topic :: Networks", "Topic :: Internet",
"Topic :: Interoperability testing", "Topic :: Software Development :: Testing",
"Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering",
# "Operating System :: Microsoft :: Windows", not there yet..
"Operating System :: POSIX", "Operating System :: POSIX",
"Operating System :: Unix", "Operating System :: Unix",
"Operating System :: MacOS" "Operating System :: MacOS"
...@@ -38,11 +35,14 @@ setup( ...@@ -38,11 +35,14 @@ setup(
name=name, name=name,
author='Federico Sismondi', author='Federico Sismondi',
author_email="federicosismondi@gmail.com", author_email="federicosismondi@gmail.com",
maintainer='Federico Sismondi',
maintainer_email="federicosismondi@gmail.com",
url='https://gitlab.f-interop.eu/f-interop-contributors/agent',
description="Component for setting up user's environment for the tests", description="Component for setting up user's environment for the tests",
version=VERSION, version=VERSION,
license='GPLv3+', license='GPLv3+',
classifiers=CLASSIFIERS, classifiers=CLASSIFIERS,
packages=['agent'], packages=find_packages(exclude=["tests"]),
long_description=io.open('README.md', 'r', encoding='utf-8').read(), long_description=io.open('README.md', 'r', encoding='utf-8').read(),
install_requires=[ install_requires=[
'click', 'click',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment