Commit 08ef6d7f authored by Federico Sismondi's avatar Federico Sismondi

Merge branch 'jenkins_local_rmq_instance' into 'develop'

Jenkins local rmq instance

See merge request coap_testing_tool!43
parents 36f830db de3a06c1
Pipeline #1489 passed with stage
in 0 seconds
......@@ -2,7 +2,7 @@ properties([[$class: 'GitLabConnectionProperty', gitLabConnection: 'figitlab']])
if(env.JOB_NAME =~ 'coap_testing_tool/'){
node('sudo'){
env.AMQP_URL="amqp://paul:iamthewalrus@f-interop.rennes.inria.fr/jenkins.coap_testing_tool"
env.AMQP_URL="amqp://guest:guest@localhost/"
env.AMQP_EXCHANGE="amq.topic"
stage ("Setup dependencies"){
......@@ -20,6 +20,11 @@ if(env.JOB_NAME =~ 'coap_testing_tool/'){
sudo apt-get install --fix-missing -y libssl-dev openssl
sudo apt-get install --fix-missing -y libffi-dev
sudo apt-get install --fix-missing -y curl tree netcat
sudo apt-get install --fix-missing -y rabbitmq-server
echo 'restarting rmq server and app'
sudo rabbitmq-server -detached || true
sudo rabbitmqctl stop_app || true
sudo rabbitmqctl start_app || true
'''
/* Show deployed code */
......@@ -166,7 +171,7 @@ if(env.JOB_NAME =~ 'coap_testing_tool_ansible_container/'){
if(env.JOB_NAME =~ 'coap_testing_tool_docker_build/'){
node('docker'){
env.AMQP_URL = "amqp://paul:iamthewalrus@f-interop.rennes.inria.fr/jenkins.coap_testing_tool_docker_build"
env.AMQP_URL="amqp://guest:guest@localhost/"
env.AMQP_EXCHANGE="amq.topic"
env.DOCKER_CLIENT_TIMEOUT=3000
env.COMPOSE_HTTP_TIMEOUT=3000
......@@ -215,7 +220,7 @@ if(env.JOB_NAME =~ 'coap_testing_tool_docker_build/'){
if(env.JOB_NAME =~ 'coap_automated_iuts_docker_build_and_run/'){
node('docker'){
env.AMQP_URL = "amqp://paul:iamthewalrus@f-interop.rennes.inria.fr/jenkins.coap_automated_iuts"
env.AMQP_URL="amqp://guest:guest@localhost/"
env.AMQP_EXCHANGE="amq.topic"
env.DOCKER_CLIENT_TIMEOUT=3000
env.COMPOSE_HTTP_TIMEOUT=3000
......@@ -309,7 +314,8 @@ if(env.JOB_NAME =~ 'coap_automated_iuts_docker_build_and_run/'){
if(env.JOB_NAME =~ 'full_coap_interop_session/'){
node('docker'){
env.AMQP_URL = "amqp://paul:iamthewalrus@f-interop.rennes.inria.fr/jenkins.full_coap_interop_session"
/* attention, here we use external RMQ server, else we would need to allow docker containers to access host's loopback ports */
env.AMQP_URL="amqp://paul:iamthewalrus@f-interop.rennes.inria.fr/jenkins.full_coap_interop_session"
env.AMQP_EXCHANGE="amq.topic"
env.DOCKER_CLIENT_TIMEOUT=3000
env.COMPOSE_HTTP_TIMEOUT=3000
......
......@@ -41,9 +41,12 @@ class PacketRouter(threading.Thread):
],
}
def __init__(self, conn, routing_table=None):
def __init__(self, amqp_url, amqp_exchange, routing_table=None):
threading.Thread.__init__(self)
self.exchange_name = amqp_exchange
self.url = amqp_url
if routing_table:
self.routing_table = routing_table
else:
......@@ -51,11 +54,8 @@ class PacketRouter(threading.Thread):
logger.info('routing table (rkey_src:[rkey_dst]) : {table}'.format(table=json.dumps(self.routing_table)))
# queues & default exchange declaration
self.message_count = 0
self.connection = conn
self.channel = self.connection.channel()
self.channel.basic_qos(prefetch_count=1)
self.set_up_connection()
self.queues_init()
msg = MsgTestingToolComponentReady(
......@@ -65,6 +65,18 @@ class PacketRouter(threading.Thread):
logger.info('packet router waiting for new messages in the data plane..')
def set_up_connection(self):
try:
logger.info('Setting up AMQP connection..')
# setup AMQP connection
self.connection = pika.BlockingConnection(pika.URLParameters(self.url))
self.channel = self.connection.channel()
self.channel.basic_qos(prefetch_count=1)
except pika.exceptions.ConnectionClosed as cc:
logger.error(' AMQP cannot be established, is message broker up? \n More: %s' % cc)
sys.exit(1)
def queues_init(self):
for src_rkey, dst_rkey_list in self.routing_table.items():
assert type(src_rkey) is str
......@@ -77,7 +89,7 @@ class PacketRouter(threading.Thread):
# start with clean queues
self.channel.queue_purge(src_queue)
self.channel.queue_bind(exchange=AMQP_EXCHANGE,
self.channel.queue_bind(exchange=self.exchange_name,
queue=src_queue,
routing_key=src_rkey)
......@@ -86,6 +98,8 @@ class PacketRouter(threading.Thread):
def stop(self):
self.shutdown_notification()
# delete routing all queues
for src_rkey in self.routing_table.keys():
# convention on queue naming
......@@ -121,7 +135,7 @@ class PacketRouter(threading.Thread):
self.channel.basic_publish(
body=m.to_json(),
routing_key=dst_rkey,
exchange=AMQP_EXCHANGE,
exchange=self.exchange_name,
properties=pika.BasicProperties(
content_type='application/json',
)
......@@ -136,50 +150,30 @@ class PacketRouter(threading.Thread):
logger.warning('No known route for r_key source: {r_key}'.format(r_key=src_rkey))
return
def run(self):
self.channel.start_consuming()
logger.info('Bye byes!')
def shutdown_notification(self):
###############################################################################
if __name__ == '__main__':
try:
logger.info('Setting up AMQP connection..')
# setup AMQP connection
connection = pika.BlockingConnection(pika.URLParameters(AMQP_URL))
channel = connection.channel()
except pika.exceptions.ConnectionClosed as cc:
logger.error(' AMQP cannot be established, is message broker up? \n More: %s' % cc)
sys.exit(1)
def signal_int_handler(channel):
# FINISHING... let's send a goodbye message
msg = {
'message': '{component} is out! Bye bye..'.format(component=COMPONENT_ID),
"_type": '{component}.shutdown'.format(component=COMPONENT_ID)
}
channel.basic_publish(
self.channel.basic_publish(
body=json.dumps(msg),
routing_key='control.session.info',
exchange=AMQP_EXCHANGE,
exchange=self.exchange_name,
properties=pika.BasicProperties(
content_type='application/json',
)
)
logger.info('got SIGINT. Bye bye!')
def run(self):
self.channel.start_consuming()
self.shutdown_notification()
sys.exit(0)
###############################################################################
# signal.signal(signal.SIGINT, signal_int_handler)
if __name__ == '__main__':
# routing tables for between agents' TUNs interfaces and also between agents' serial interfaces
iut_routing_table_serial = {
......@@ -205,9 +199,10 @@ if __name__ == '__main__':
routing_table.update(iut_routing_table_tun)
# start amqp router thread
r = PacketRouter(connection, routing_table)
r = PacketRouter(AMQP_URL, AMQP_EXCHANGE, routing_table)
try:
r.start()
r.join()
except (KeyboardInterrupt, SystemExit):
logger.info('got SIGINT. Bye bye!')
r.stop()
......@@ -42,12 +42,11 @@ class PacketRouterTestCase(unittest.TestCase):
}
# start packet router
packet_router = PacketRouter(self.connection, self.routing_table )
packet_router = PacketRouter(AMQP_URL, AMQP_EXCHANGE, self.routing_table)
packet_router.daemon = True
packet_router.start()
def test_packet_routing(self):
assert self.channel.is_open, 'no channel opened for tests'
self._send_packet_fromAgent1()
......@@ -95,9 +94,11 @@ class PacketRouterTestCase(unittest.TestCase):
{
'_type': 'packet.sniffed.raw',
'data': [96, 0, 0, 0, 0, 56, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 174, 188, 50, 255, 254, 205, 243,
139, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 1, 0, 5, 2, 0, 0, 143, 0, 166,
127, 0, 0, 0, 2, 4, 0, 0, 0, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 0, 0, 1, 4, 0, 0, 0,
255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 205, 243, 139],
139, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 1, 0, 5, 2, 0, 0, 143, 0,
166,
127, 0, 0, 0, 2, 4, 0, 0, 0, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 0, 0, 1, 4, 0, 0,
0,
255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 205, 243, 139],
'description': 'hello world',
}
),
......@@ -119,9 +120,11 @@ class PacketRouterTestCase(unittest.TestCase):
{
'_type': 'packet.sniffed.raw',
'data': [96, 0, 0, 0, 0, 56, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 174, 188, 50, 255, 254, 205, 243,
139, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 1, 0, 5, 2, 0, 0, 143, 0, 166,
127, 0, 0, 0, 2, 4, 0, 0, 0, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 0, 0, 1, 4, 0, 0, 0,
255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 205, 243, 139],
139, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 1, 0, 5, 2, 0, 0, 143, 0,
166,
127, 0, 0, 0, 2, 4, 0, 0, 0, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 0, 0, 1, 4, 0, 0,
0,
255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 205, 243, 139],
'description': 'hello world',
}
),
......
test_analysis_tool @ 0e4d9b16
Subproject commit 0d4da11b561c9a58a130237e09c3d9b0e0153ba6
Subproject commit 0e4d9b16f6a72aa6f4b804c7b273ea8a81470ec7
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