mirror of
https://github.com/Telecominfraproject/oopt-tai-implementations.git
synced 2025-10-29 17:22:39 +00:00
mux: add tests for exec platform adapter
Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
This commit is contained in:
1
tai_mux/.gitignore
vendored
1
tai_mux/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.so
|
||||
test/test
|
||||
build
|
||||
__pycache__
|
||||
|
||||
Submodule tai_mux/oopt-tai updated: ba4b1ba6a6...3448aca2a1
@@ -6,9 +6,12 @@ ifndef TAI_LIB_DIR
|
||||
TAI_LIB_DIR := $(TAI_DIR)/tools/framework
|
||||
endif
|
||||
|
||||
all: libtai.so static.json libtai-a.so libtai-b.so
|
||||
all: exec-pa
|
||||
TAI_MUX_STATIC_CONFIG_FILE=$(abspath static.json) TAI_TEST_TARGET=$(abspath libtai.so) $(MAKE) -C $(TAI_DIR)/tests
|
||||
|
||||
exec-pa: libtai.so static.json libtai-a.so libtai-b.so
|
||||
TAI_MUX_PLATFORM_ADAPTER="exec" TAI_MUX_EXEC_SCRIPT=$(abspath exec.py) LD_LIBRARY_PATH=. python -m unittest -vf
|
||||
|
||||
libtai.so:
|
||||
$(MAKE) -C ..
|
||||
ln -sf ../$@ $@
|
||||
|
||||
23
tai_mux/tests/exec.py
Executable file
23
tai_mux/tests/exec.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
sys.exit(1)
|
||||
|
||||
arg = sys.argv[1]
|
||||
|
||||
if arg == "list":
|
||||
print("\n".join(str(v) for v in range(1, 8)))
|
||||
return
|
||||
|
||||
time.sleep(.5)
|
||||
|
||||
print("libtai-a.so")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
56
tai_mux/tests/test.py
Normal file
56
tai_mux/tests/test.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import unittest
|
||||
import subprocess as sp
|
||||
import threading
|
||||
import os
|
||||
import time
|
||||
import taish
|
||||
import asyncio
|
||||
|
||||
TAI_TEST_MODULE_LOCATION = os.environ.get("TAI_TEST_MODULE_LOCATION", "")
|
||||
if not TAI_TEST_MODULE_LOCATION:
|
||||
TAI_TEST_MODULE_LOCATION = "0"
|
||||
|
||||
TAI_TEST_TAISH_SERVER_ADDRESS = os.environ.get("TAI_TEST_TAISH_SERVER_ADDRESS", "")
|
||||
if not TAI_TEST_TAISH_SERVER_ADDRESS:
|
||||
TAI_TEST_TAISH_SERVER_ADDRESS = taish.DEFAULT_SERVER_ADDRESS
|
||||
|
||||
TAI_TEST_TAISH_SERVER_PORT = os.environ.get("TAI_TEST_TAISH_SERVER_PORT", "")
|
||||
if not TAI_TEST_TAISH_SERVER_PORT:
|
||||
TAI_TEST_TAISH_SERVER_PORT = taish.DEFAULT_SERVER_PORT
|
||||
|
||||
TAI_TEST_NO_LOCAL_TAISH_SERVER = (
|
||||
True if os.environ.get("TAI_TEST_NO_LOCAL_TAISH_SERVER", "") else False
|
||||
)
|
||||
|
||||
|
||||
def output_reader(proc):
|
||||
for line in iter(proc.stdout.readline, b""):
|
||||
print("taish-server: {}".format(line.decode("utf-8")), end="")
|
||||
|
||||
|
||||
class TestTAI(unittest.IsolatedAsyncioTestCase):
|
||||
def setUp(self):
|
||||
if TAI_TEST_NO_LOCAL_TAISH_SERVER:
|
||||
return
|
||||
proc = sp.Popen(["taish_server", "-v", "-n"], stderr=sp.STDOUT, stdout=sp.PIPE)
|
||||
self.d = threading.Thread(target=output_reader, args=(proc,))
|
||||
self.d.start()
|
||||
self.proc = proc
|
||||
time.sleep(1) # wait for the server to be ready
|
||||
|
||||
def tearDown(self):
|
||||
if TAI_TEST_NO_LOCAL_TAISH_SERVER:
|
||||
return
|
||||
self.proc.terminate()
|
||||
self.proc.wait(timeout=0.2)
|
||||
self.d.join()
|
||||
self.proc.stdout.close()
|
||||
|
||||
async def test_create_and_remove(self):
|
||||
cli = taish.AsyncClient(
|
||||
TAI_TEST_TAISH_SERVER_ADDRESS, TAI_TEST_TAISH_SERVER_PORT
|
||||
)
|
||||
m = await cli.list()
|
||||
v = await asyncio.gather(*(cli.create_module(k) for k in m.keys()))
|
||||
await asyncio.gather(*(cli.remove(v.oid) for v in v))
|
||||
cli.close()
|
||||
Reference in New Issue
Block a user