diff options
author | liuyahui <liuyh.fnst@fujitsu.com> | 2021-06-02 12:44:44 +0800 |
---|---|---|
committer | Edi Feschiyan <edi.feschiyan@konsulko.com> | 2021-06-04 08:33:12 +0000 |
commit | 9f132032cd2896cc4024cac7e7a481baad7a920e (patch) | |
tree | 79a236f4add4c5583eda237efb66b2c3f0d103fe | |
parent | b1e192d43258d370460bd882230584116cacf8d1 (diff) |
Add main function to taskmanager service module
and add pytest python script to taskmanager service module
Bug-AGL: SPEC-3946
Signed-off-by: liuyahui <liuyh.fnst@fujitsu.com>
Change-Id: I403c7004d87bc4f3171363a678a8d50a5fa50aca
-rw-r--r-- | pyagl/pytest.ini | 1 | ||||
-rw-r--r-- | pyagl/services/taskmanager.py | 47 | ||||
-rw-r--r-- | pyagl/tests/test_taskmanager.py | 54 |
3 files changed, 102 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini index 53a16df..8794024 100644 --- a/pyagl/pytest.ini +++ b/pyagl/pytest.ini @@ -20,3 +20,4 @@ markers = signal_composer: agl-service-signal-composer tests weather: agl-service-weather tests hvac: agl-service-hvac tests + taskmanager: agl-service-taskmanager tests diff --git a/pyagl/services/taskmanager.py b/pyagl/services/taskmanager.py index e4bd810..388b931 100644 --- a/pyagl/services/taskmanager.py +++ b/pyagl/services/taskmanager.py @@ -23,5 +23,52 @@ class TaskManagerService(AGLBaseService): service = 'agl-service-taskmanager' parser = AGLBaseService.getparser() + 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') + def __init__(self, ip, port=None, service='agl-service-taskmanager'): super().__init__(api='taskmanager', ip=ip, port=port, service=service) + + async def get_process_list(self): + return await self.request('get_process_list') + + async def get_load_avg(self): + return await self.request('get_load_avg') + + async def get_netstat(self): + return await self.request('get_netstat') + + async def agent_response(self): + pass + +async def main(loop): + args = TaskManagerService.parser.parse_args() + tasks = await TaskManagerService(ip=args.ipaddr, port=args.port) + + if args.get_process_list: + msgid = await tasks.get_process_list() + print(f'Sent status request with messageid {msgid}') + resp = await tasks.afbresponse() + print(resp.data) + + if args.get_netstat: + msgid = await tasks.get_netstat() + print(f'Sent status request with messageid {msgid}') + resp = await tasks.afbresponse() + print(resp.data) + + if args.get_load_avg: + msgid = await tasks.get_load_avg() + print(f'Sent status request with messageid {msgid}') + resp = await tasks.afbresponse() + print(resp.data) + + if args.listener: + for response in nets.listener(): + print(response) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(loop)) + diff --git a/pyagl/tests/test_taskmanager.py b/pyagl/tests/test_taskmanager.py new file mode 100644 index 0000000..10c1855 --- /dev/null +++ b/pyagl/tests/test_taskmanager.py @@ -0,0 +1,54 @@ +# Copyright (C) 2021 Fujitsu +# Author: liu yahui +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import asyncio +import os +import pytest +import logging +from pyagl.services.base import AFBResponse, AFBT +from pyagl.services.taskmanager import TaskManagerService as TASK + +pytestmark = [pytest.mark.asyncio, pytest.mark.taskmanager] + +@pytest.fixture(scope='module') +def event_loop(): + loop = asyncio.get_event_loop() + yield loop + + +@pytest.fixture(scope='module') +async def service(): + address = os.environ.get('AGL_TGT_IP', 'localhost') + port = os.environ.get('AGL_TGT_PORT', None) + tasks = await TASK(ip=address, port=port) + yield tasks + await tasks.websocket.close() + + +async def test_get_process_list(event_loop, service: TASK): + msgid = await service.get_process_list() + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_get_netstat(event_loop, service: TASK): + msgid = await service.get_netstat() + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_get_load_avg(event_loop, service: TASK): + msgid = await service.get_load_avg() + resp = await service.afbresponse() + assert resp.status == 'success' |