summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQiu Tingting <qiutt@fujitsu.com>2021-04-02 13:30:04 +0800
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2021-08-19 14:49:52 +0000
commit8717445b8311afe7c6782d10aed2e292034aabb8 (patch)
treeba79389e9c4c23289f66202d3c782091d942addb
parenta6716d25e123a918edd303b3cf85b5a95fd685b1 (diff)
Add testcase of get_extra_info and kill_process api to taskmanager service module.
Bug-AGL: SPEC-3946 Signed-off-by: Qiu Tingting <qiutt@fujitsu.com> Change-Id: Id9cb3e3df6f6c13c95acfa0875f708ed98fb29f6
-rw-r--r--pyagl/services/taskmanager.py20
-rw-r--r--pyagl/tests/test_taskmanager.py24
2 files changed, 44 insertions, 0 deletions
diff --git a/pyagl/services/taskmanager.py b/pyagl/services/taskmanager.py
index 388b931..488094e 100644
--- a/pyagl/services/taskmanager.py
+++ b/pyagl/services/taskmanager.py
@@ -26,6 +26,8 @@ class TaskManagerService(AGLBaseService):
parser.add_argument('--get_process_list', action='store_true')
parser.add_argument('--get_netstat', action='store_true')
parser.add_argument('--get_load_avg', action='store_true')
+ parser.add_argument('--get_extra_info', help='unique process ID', type=int)
+ parser.add_argument('--kill_process', help='unique process ID', type=int)
def __init__(self, ip, port=None, service='agl-service-taskmanager'):
super().__init__(api='taskmanager', ip=ip, port=port, service=service)
@@ -39,6 +41,12 @@ class TaskManagerService(AGLBaseService):
async def get_netstat(self):
return await self.request('get_netstat')
+ async def kill_process(self, tid=None):
+ return await self.request('kill_process', tid)
+
+ async def get_extra_info(self, tid=None):
+ return await self.request('get_extra_info', tid)
+
async def agent_response(self):
pass
@@ -64,6 +72,18 @@ async def main(loop):
resp = await tasks.afbresponse()
print(resp.data)
+ if args.get_extra_info:
+ msgid = await tasks.get_extra_info(args.get_extra_info)
+ print(f'Sent tid={args.get_extra_info} request with messageid {msgid}')
+ resp = await tasks.afbresponse()
+ print(resp)
+
+ if args.kill_process:
+ msgid = await tasks.kill_process(args.kill_process)
+ print(f'Sent tid={args.kill_process} request with messageid {msgid}')
+ resp = await tasks.afbresponse()
+ print(resp)
+
if args.listener:
for response in nets.listener():
print(response)
diff --git a/pyagl/tests/test_taskmanager.py b/pyagl/tests/test_taskmanager.py
index 10c1855..fc1f489 100644
--- a/pyagl/tests/test_taskmanager.py
+++ b/pyagl/tests/test_taskmanager.py
@@ -21,6 +21,12 @@ import logging
from pyagl.services.base import AFBResponse, AFBT
from pyagl.services.taskmanager import TaskManagerService as TASK
+import multiprocessing
+import time
+
+def action(max):
+ time.sleep(max)
+
pytestmark = [pytest.mark.asyncio, pytest.mark.taskmanager]
@pytest.fixture(scope='module')
@@ -52,3 +58,21 @@ async def test_get_load_avg(event_loop, service: TASK):
msgid = await service.get_load_avg()
resp = await service.afbresponse()
assert resp.status == 'success'
+
+@pytest.mark.xfail(reason='Tests that are known to fail, until the agl-service-taskmanager is fixed in master.')
+async def test_get_extra_info(event_loop, service: TASK):
+ msgid = await service.get_extra_info(1)
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+async def test_kill_process(event_loop, service: TASK):
+ mp1 = multiprocessing.Process(target=action,args=(10,))
+ mp1.start()
+ time.sleep(3)
+ print(f'process id: '+str(mp1.pid))
+ msgid = await service.kill_process(mp1.pid)
+ resp = await service.afbresponse()
+ assert resp.status == 'not-replied'
+ time.sleep(1)
+ assert mp1.is_alive() == False
+