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)
--------------------------------------------------
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
------
The design of the f-interop agent is modular by design.
An agent is made of different processes that connect to AMQP message
broker and exchange messages (in and out) with other components using
the same AMQP broker.
......@@ -19,13 +44,10 @@ charge of launching all the other components.
If new components needs to be added they just need to be launched
from this component.
Core open the default ZMQ socket that is used by other components to
communicate with each others.
Error handling
--------------
When there is a Ctrl-C the agent should kill all other components and
disconnect as gracefully as possible.
When there is a user interrupt signal (Ctrl-C) the agent should kill
all other components and disconnect as gracefully as possible.
Serial mode (with 802.15.4 probe)
......
......@@ -25,19 +25,15 @@ Features of the agent
"""
from __future__ import absolute_import
import sys
import logging
import click
import uuid
import multiprocessing
from .connectors.tun import TunConnector
from .connectors.core import CoreConnector
from .connectors.http import HTTPConnector
from .connectors.serialconn import SerialConnector
from .connectors import TunConnector
from .connectors import CoreConnector
from .connectors import SerialConnector
from .utils import arrow_down, arrow_up, ioppytest_banner
from .utils.packet_dumper import launch_amqp_data_to_pcap_dumper
from .utils import ioppytest_banner
from .utils import packet_dumper
try:
from urllib.parse import urlparse
......@@ -58,9 +54,12 @@ class Agent(object):
"""
header = """
Agent (~VPN client) is a component which connects 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
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.
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
# TODO fix pcap_dumper support for py2, python3 -m utils.packet_dumper works fine tho
# 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()
def run(self):
......
from __future__ import absolute_import
from . import core
from . import serialconn
from . import tun
from . import base
\ No newline at end of file
from .tun import TunConnector
from .core import CoreConnector
from .serialconn import SerialConnector
......@@ -24,7 +24,6 @@ class CoreConsumer(BaseConsumer):
subscriptions)
def on_consume_ready(self, connection, channel, consumers, wakeup=True, **kwargs):
log.info("Backend ready to consume data")
# let's send bootstrap message
msg = MsgTestingToolComponentReady(
......@@ -39,9 +38,11 @@ class CoreConsumer(BaseConsumer):
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):
self.log.debug(
"Consumer specialized handler <{consumer_name}> got: {message}".format(
self.log.warning(
"<{consumer_name}> got {message}, no callback bound to it.".format(
consumer_name=self.consumer_name,
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
from .base import BaseController, BaseConsumer
from ..utils.opentun import OpenTunLinux, OpenTunMACOS
from ..utils import arrow_up
from ..utils import arrow_up, arrow_down
from ..utils import messages
......@@ -147,21 +147,13 @@ class TunConsumer(BaseConsumer):
self.log.info("Message received from testing tool. Injecting in Tun. Message count (downlink): %s"
% self.packet_count)
print(arrow_up)
print(arrow_down)
self.log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' +
'\n data packet EventBus -> TUN interface' +
'\n' + message.to_json() +
'\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(
sender="Testing Tool",
signal="tun inject",
......
from __future__ import absolute_import
from . import messages
from . import packet_dumper
from . import serial_listener
import logging
import os
......
......@@ -548,7 +548,7 @@ class OpenTunLinux(object):
# write over tuntap interface
os.write(self.tunIf, data)
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:
errMsg = formatCriticalMessage(err)
log.critical(errMsg)
......@@ -778,7 +778,7 @@ class OpenTunMACOS(object):
# write over tuntap interface
os.write(self.tunIf, data)
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:
errMsg = formatCriticalMessage(err)
log.critical(errMsg)
......
......@@ -8,8 +8,7 @@ import sys
from kombu import Exchange
from collections import OrderedDict
from . import messages
from . import arrow_down, arrow_up, finterop_banner
from ..utils import messages
STATE_OK = 0
STATE_ESC = 1
......
......@@ -3,4 +3,3 @@ six
kombu
pika
pyserial
\ No newline at end of file
requests
\ No newline at end of file
......@@ -8,7 +8,7 @@ from setuptools import setup, find_packages
MAJOR = 0
MINOR = 1
PATCH = 2
PATCH = 8
VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH)
name = 'ioppytest-agent'
......@@ -17,15 +17,12 @@ CLASSIFIERS = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Intended Audience :: Testers",
# "License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Topic :: Networks",
"Topic :: Interoperability testing",
"Topic :: Internet",
"Topic :: Software Development :: Testing",
"Topic :: Scientific/Engineering",
# "Operating System :: Microsoft :: Windows", not there yet..
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS"
......@@ -38,11 +35,14 @@ setup(
name=name,
author='Federico Sismondi',
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",
version=VERSION,
license='GPLv3+',
classifiers=CLASSIFIERS,
packages=['agent'],
packages=find_packages(exclude=["tests"]),
long_description=io.open('README.md', 'r', encoding='utf-8').read(),
install_requires=[
'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