diff --git a/Dockerfile b/Dockerfile index 126dd1224..0316f2c7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,10 +11,13 @@ RUN apt-get install autotools-dev automake pkg-config libsodium-dev -y RUN apt-get install libgtest-dev python valgrind python-pip libpython2.7-dev -y +RUN pip install pyzmq + RUN apt-get install python3 python3-pip -y RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2 RUN pip3 install pyzmq + RUN git clone git://github.com/zeromq/libzmq.git; \ cd libzmq; \ git checkout e9b9860752ffac1a561fdb64f5f72bbfc5515b34; \ diff --git a/scripts/remote_control.py b/scripts/remote_control.py index 0e22c310e..c98479d47 100755 --- a/scripts/remote_control.py +++ b/scripts/remote_control.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python2.7 import struct import time diff --git a/test_helper/instrumentation_client.py b/test_helper/instrumentation_client.py index 6a1c6dd8f..49deb3d93 100755 --- a/test_helper/instrumentation_client.py +++ b/test_helper/instrumentation_client.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python2.7 import time import sys diff --git a/test_helper/leopytest/RemoteControl.py b/test_helper/leopytest/RemoteControl.py index 737ef4521..062688847 100644 --- a/test_helper/leopytest/RemoteControl.py +++ b/test_helper/leopytest/RemoteControl.py @@ -121,7 +121,7 @@ class ModuleConfigCommand(Command): """ Command object to retrieve the configuration of a Leosac module. - Config format is force to XML. + Config format is forced to XML. """ def __init__(self, module_name): @@ -152,3 +152,53 @@ def feed_response(self, frames): def __str__(self): return "" + + +class ModuleListCommand(Command): + """ + Command object to retrieve the list of modules running on Leosac. + """ + + def __init__(self): + """ + Initialize the command + :return: + """ + self.modules = None + + def to_zmq_message(self): + return ["MODULE_LIST".encode("utf-8")] + + def feed_response(self, frames): + self.status = True + self.modules = [] + for frame in frames: + self.modules.append(frame.decode("ascii")) + + def __str__(self): + return "" + + +class SaveCommand(Command): + """ + Command object to retrieve to trigger configuration save. + """ + + def __init__(self): + """ + Initialize the command + :return: + """ + pass + + def to_zmq_message(self): + return ["SAVE".encode("utf-8")] + + def feed_response(self, frames): + if frames[0] == bytes("OK", "ascii"): + self.status = True + else: + self.status = False + + def __str__(self): + return "" diff --git a/test_helper/leopytest/Utils.py b/test_helper/leopytest/Utils.py index d1cdbe2cc..f4d6880b5 100644 --- a/test_helper/leopytest/Utils.py +++ b/test_helper/leopytest/Utils.py @@ -1,5 +1,6 @@ import logging import os +import subprocess def test_assert(res, msg): @@ -23,16 +24,12 @@ def get_leosac_path(): """ path = os.getcwd() + "/install/bin/leosac" + if not os.path.isfile(path): + path = subprocess.check_output(["which", "leosac"]) + test_assert(os.path.isfile(path), "Cannot find leosac binary") return path - if os.environ.get("INSTALL_DIR"): - path = os.environ["INSTALL_DIR"] + "/install/bin/leosac" - test_assert(os.path.isfile(path), "Cannot find leosac binary") - return path - logging.error("Cannot find Leosac.") - exit(-1) - def preconfigure(): """ diff --git a/test_helper/run_tests.sh b/test_helper/run_tests.sh index 23be934a0..55db69fb3 100755 --- a/test_helper/run_tests.sh +++ b/test_helper/run_tests.sh @@ -19,7 +19,7 @@ total_test=`find . -maxdepth 1 -mindepth 1 -type d | wc -l` echo -e ${Yel} "We will run ${total_test} tests" ${RCol} ## the run_docker script require a test-folder name. -find . -maxdepth 1 -mindepth 1 -type d | parallel ./run_docker.sh {} ; +find . -name "test-*" -maxdepth 1 -mindepth 1 -type d | parallel ./run_docker.sh {} ; RET_VALUE=$? ## parallel ret value is our test suite return value. diff --git a/test_helper/test-module-config/test-invalid.py b/test_helper/test-module-config/test-invalid.py deleted file mode 100755 index 359d010a9..000000000 --- a/test_helper/test-module-config/test-invalid.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -import remote_control -import sys - -def main(): - print "Hello, I will query the config of an invalid module." - - p = ["", "127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT", "module_config", "INVALID_MODULE"] - ret = remote_control.run(p) - - print ret - if len(ret) != 2 or ret[0] != "KO": - print "Didn't fail for invalid module..." - return 1 - return 0 - -if __name__ == "__main__": - ret = main() - exit(ret) diff --git a/test_helper/test-module-config/test-valid.py b/test_helper/test-module-config/test-valid.py deleted file mode 100755 index 23479d29f..000000000 --- a/test_helper/test-module-config/test-valid.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -import remote_control -import sys - -def main(): - print "Hello, querying config for the MONITOR module" - - p = ["", "127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT", "module_config", "MONITOR"] - ret = remote_control.run(p) - - print ret - - if len(ret) >= 3 and ret[0] == "OK" and ret[1] == "MONITOR": - return 0; - print "Didn't succeed for valid module" - return 1 - -if __name__ == "__main__": - ret = main() - exit(ret) diff --git a/test_helper/test-module-list/run_test.py b/test_helper/test-module-list/run_test.py new file mode 100644 index 000000000..b0077c1c1 --- /dev/null +++ b/test_helper/test-module-list/run_test.py @@ -0,0 +1,27 @@ +# Test the MODULE_LIST command. +# + +from RemoteControl import RemoteController, ModuleListCommand +from Utils import * +from Runner import LeosacRunner + + +def main(): + leosac = LeosacRunner("this_test/test-module-list.xml") + + rc = RemoteController("127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT") + cmd = ModuleListCommand() + + rc.execute_command(cmd) + test_assert(cmd.status is True + and ("MONITOR" in cmd.modules) + and ("WIEGAND_READER" in cmd.modules) + and ("NOT_A_MODULE" not in cmd.modules), + "Failed to retrieve config from valid module.") + + leosac.interrupt() + leosac.wait_abort(30) + +if __name__ == "__main__": + preconfigure() + main() diff --git a/test_helper/test-module-list/run_test.sh b/test_helper/test-module-list/run_test.sh index cbf1ceaff..15fb8d08d 100755 --- a/test_helper/test-module-list/run_test.sh +++ b/test_helper/test-module-list/run_test.sh @@ -1,36 +1,8 @@ #!/bin/bash # # Test the MODULE_LIST command. -# One running Leosac. We use the remote_control script to query the results. -# [ -r ../shell_helper.sh ] || { echo "Cannot source shell_helper.sh"; exit -1; } source ../shell_helper.sh -set -e -set -x - -config_file="$TMP_DIR/this_test/test-module-list.xml" - -(${REMOTE_CONTROL} "127.0.0.1:12345" 'TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT' "module_list" > remote_result - sleep $SLEEP_TIME - kill $(cat pid-file) -)& - - -## start leosac and wait for return value -## Use custom work directory to access the factory config file -(valgrind --error-exitcode=42 ./install/bin/leosac -k $config_file > leosac-log & - echo $! > pid-file; wait $! && echo $? > exit-status) - -if ! grep "MONITOR" remote_result ; then - fail "MONITOR module should be reported present." -fi - -if ! grep "WIEGAND_READER" remote_result ; then - fail "WIEGAND_READER module should be reported present." -fi - -[ $(cat exit-status) -eq 0 ] || fail "Non zero return code" - -die 0 +python this_test/run_test.py diff --git a/test_helper/test-save-fail/test-save.py b/test_helper/test-save-fail/test-save.py index 13723eedc..312ad414d 100755 --- a/test_helper/test-save-fail/test-save.py +++ b/test_helper/test-save-fail/test-save.py @@ -1,21 +1,18 @@ -#!/usr/bin/env python +# Test the SAVE command. +# -import remote_control -import sys +from RemoteControl import RemoteController, SaveCommand +from Utils import * -def main(): - print "Hello, will attempt to SAVE" - - p = ["", "127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT", "save"] - ret = remote_control.run(p) - print ret +def main(): + rc = RemoteController("127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT") + cmd = SaveCommand() - if len(ret) == 2 and ret[0] == "KO": - return 0; - print "Looks like SAVE succeeded but should have failed" - return 1 + rc.execute_command(cmd) + test_assert(cmd.status is False, + "Successfully saved configuration while it was supposed to fail") if __name__ == "__main__": - ret = main() - exit(ret) + preconfigure() + main()