Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit c215db0

Browse files
committed
Fix stand alone mode test failure
Since listener config is hard-coded with container service name and it is failing in standlone mode. Added command line option to listener to read zmq_url and defact value in config file is localhost and command line argument takes precedence. Signed-off-by: Ramakrishna Srinivasamurthy <ramakrishna.srinivasamurthy@intel.com>
1 parent 2b84d7f commit c215db0

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ services:
114114
- 5555
115115
command: |
116116
bash -c "
117-
avalon_listener --bind http://avalon-listener:1947 --lmdb_url http://avalon-lmdb:9090
117+
avalon_listener --bind http://avalon-listener:1947 --lmdb_url http://avalon-lmdb:9090 --zmq_url tcp://avalon-enclave-manager:5555
118118
tail -f /dev/null
119119
"
120120
depends_on:

listener/avalon_listener/tcs_listener.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sys
2828
import logging
2929
import argparse
30+
from urllib.parse import urlparse
3031

3132
from avalon_listener.tcs_work_order_handler import TCSWorkOrderHandler
3233
from avalon_listener.tcs_work_order_handler_sync import TCSWorkOrderHandlerSync
@@ -72,8 +73,7 @@ def __init__(self, config):
7273
self.workorder_handler = TCSWorkOrderHandlerSync(
7374
self.kv_helper,
7475
config["Listener"]["max_work_order_count"],
75-
config["Listener"]["zmq_url"],
76-
config["Listener"]["zmq_port"])
76+
config["Listener"]["zmq_url"])
7777
else:
7878
self.workorder_handler = TCSWorkOrderHandler(
7979
self.kv_helper,
@@ -121,6 +121,13 @@ def parse_command_line(config, args):
121121
'--bind', help='URI to listen for requests ', type=str)
122122
parser.add_argument(
123123
'--lmdb_url', help='DB url to connect to LMDB ', type=str)
124+
# Check if listener is running in sync work load
125+
# execution mode then add additional argument zmq url
126+
is_sync = config["WorkloadExecution"]["sync_workload_execution"]
127+
if is_sync:
128+
parser.add_argument(
129+
'--zmq_url',
130+
help='ZMQ url to connect to enclave manager ', type=str)
124131

125132
options = parser.parse_args(args)
126133

@@ -150,6 +157,21 @@ def parse_command_line(config, args):
150157
logger.error("Quit : remote_storage_url is not \
151158
present in config for Listener")
152159
sys.exit(-1)
160+
if options.zmq_url:
161+
if not is_sync:
162+
logger.error("Invalid option zmq_url! It should be supported"
163+
"in work order sync mode")
164+
sys.exit(-1)
165+
else:
166+
if config.get("Listener") is None or \
167+
config["Listener"].get("zmq_url") is None:
168+
logger.error("Quit : no zmq_url config found for Listener")
169+
sys.exit(-1)
170+
parse_res = urlparse(options.zmq_url)
171+
if parse_res.scheme != "tcp" or parse_res.port == "":
172+
logger.error("Invalid zmq url. It should tcp://<host>:<port>")
173+
sys.exit(-1)
174+
config["Listener"]["zmq_url"] = options.zmq_url
153175

154176
return host_name, port
155177

listener/avalon_listener/tcs_work_order_handler_sync.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ class TCSWorkOrderHandlerSync(TCSWorkOrderHandler):
5252
"""
5353
# ------------------------------------------------------------------------------------------------
5454

55-
def __init__(self, kv_helper, max_wo_count, zmq_url, zmq_port):
55+
def __init__(self, kv_helper, max_wo_count, zmq_url):
5656
"""
5757
Function to perform init activity
5858
Parameters:
5959
- kv_helper is a object of lmdb database
6060
"""
6161
self.zmq_url = zmq_url
62-
self.zmq_port_number = zmq_port
6362
super(TCSWorkOrderHandlerSync, self).__init__(kv_helper, max_wo_count)
6463

6564
# ---------------------------------------------------------------------------------------------
@@ -145,11 +144,11 @@ def WorkOrderSubmit(self, **params):
145144
# ZeroMQ for sync workorder processing
146145
try:
147146
socket = context.socket(zmq.REQ)
148-
socket.connect(self.zmq_url + self.zmq_port_number)
147+
socket.connect(self.zmq_url)
149148
socket.send_string(wo_id, flags=0, encoding='utf-8')
150149
replymessage = socket.recv()
151150
logger.info(replymessage)
152-
socket.disconnect(self.zmq_url + self.zmq_port_number)
151+
socket.disconnect(self.zmq_url)
153152
except Exception as er:
154153
raise JSONRPCDispatchException(
155154
WorkOrderStatus.UNKNOWN_ERROR,

listener/listener_config.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ bind = "http://localhost:1947"
2828
max_work_order_count = 10
2929
# ZMQ configurations the listener would connect to
3030
# Same as the url and port of enclave manager socket
31-
zmq_url = "tcp://avalon-enclave-manager:"
32-
zmq_port = '5555'
31+
zmq_url = "tcp://localhost:5555"
3332

3433
# ------------------------------------------------------------------
3534
# Work load execution-settings for workload execution(synchronous/asynchronous)

scripts/tcs_startup.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ COMPONENTS="$ENCLAVE_MANAGER" # #KV_STORAGE added if -s passed
2323
START_STOP_AVALON_SERVICES=0 # default if -s not passed
2424
LMDB_URL="http://localhost:9090" # -l default
2525
LISTENER_URL="http://localhost:1947"
26+
ENCLAVE_ZMQ_URL="tcp://localhost:5555"
2627
# Trap handler
2728
trap 'stop_avalon_components' HUP INT QUIT ABRT ALRM TERM
2829

30+
is_sync_mode()
31+
{
32+
return grep "sync_workload_execution" ${TCF_HOME}/listener/listener_config.toml | awk -F'=' '{print $2}'
33+
}
34+
2935
start_avalon_components()
3036
{
3137
if [ $START_STOP_AVALON_SERVICES = 1 ] ; then
3238
echo "Starting Avalon KV Storage $VERSION ..."
3339
$KV_STORAGE --bind $LMDB_URL &
3440
echo "Avalon KV Storage started"
35-
36-
echo "Starting Avalon Listener $VERSION ..."
37-
$LISTENER --bind $LISTENER_URL --lmdb_url $LMDB_URL &
38-
echo "Avalon Listener started"
3941
fi
4042

4143
# START_STOP_AVALON_SERVICES doesn't control enclave manager. It will be
@@ -44,6 +46,18 @@ start_avalon_components()
4446
python3 $ENCLAVE_MANAGER --lmdb_url $LMDB_URL &
4547
echo "Avalon Enclave Manager started"
4648

49+
if [ $START_STOP_AVALON_SERVICES = 1 ] ; then
50+
echo "Starting Avalon Listener $VERSION ..."
51+
is_sync_mode
52+
is_sync_mode_on=$?
53+
if [ "$is_sync_mode_on" -eq "1" ]; then
54+
$LISTENER --bind $LISTENER_URL --lmdb_url $LMDB_URL --zmq_url $ENCLAVE_ZMQ_URL &
55+
else
56+
$LISTENER --bind $LISTENER_URL --lmdb_url $LMDB_URL &
57+
fi
58+
echo "Avalon Listener started"
59+
fi
60+
4761
sleep 5s
4862
check_avalon_components
4963

0 commit comments

Comments
 (0)