From: stevenvanrossem Date: Thu, 19 May 2016 10:19:36 +0000 (+0200) Subject: prepare son-emu-cli for son-cli integration X-Git-Tag: v3.1~119^2~3 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=1a6843a29e131df6719e5a859e1460d957879458;p=osm%2Fvim-emu.git prepare son-emu-cli for son-cli integration --- diff --git a/setup.py b/setup.py index 3657816..b8af834 100755 --- a/setup.py +++ b/setup.py @@ -25,7 +25,8 @@ setup(name='emuvim', 'requests', 'prometheus_client', 'paramiko', - 'urllib3' + 'urllib3', + 'requests' ], zip_safe=False, entry_points={ diff --git a/setup_cli_only.py b/setup_cli_only.py index 320ddc3..6ab0777 100755 --- a/setup_cli_only.py +++ b/setup_cli_only.py @@ -14,6 +14,7 @@ setup(name='emuvim', 'zerorpc', 'tabulate', 'argparse', + 'requests' ], zip_safe=False, entry_points={ diff --git a/src/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py index 7be7374..20bfc25 100755 --- a/src/emuvim/cli/monitor.py +++ b/src/emuvim/cli/monitor.py @@ -1,12 +1,13 @@ """ son-emu monitor CLI (c) 2016 by Manuel Peuster +Steven Van Rossem """ import argparse import pprint import zerorpc -import prometheus +from emuvim.cli import prometheus pp = pprint.PrettyPrinter(indent=4) diff --git a/src/emuvim/cli/network.py b/src/emuvim/cli/network.py index bfd1127..48ff33a 100755 --- a/src/emuvim/cli/network.py +++ b/src/emuvim/cli/network.py @@ -1,6 +1,7 @@ """ son-emu network CLI (c) 2016 by Manuel Peuster +Steven Van Rossem """ import argparse diff --git a/src/emuvim/cli/prometheus.py b/src/emuvim/cli/prometheus.py index 26f18bf..9432408 100755 --- a/src/emuvim/cli/prometheus.py +++ b/src/emuvim/cli/prometheus.py @@ -3,8 +3,9 @@ Prometheus API helper functions (c) 2016 by Steven Van Rossem """ -import urllib2 -import ast +#import urllib2 +import requests +#import ast # set this to localhost for now # this is correct for son-emu started outside of a container or as a container with net=host @@ -16,9 +17,11 @@ prometheus_REST_api = 'http://{0}:{1}'.format(prometheus_ip, prometheus_port) def query_Prometheus(query): url = prometheus_REST_api + '/' + 'api/v1/query?query=' + query # logging.info('query:{0}'.format(url)) - req = urllib2.Request(url) - ret = urllib2.urlopen(req).read() - ret = ast.literal_eval(ret) + #req = urllib2.Request(url) + req = requests.get(url) + #ret = urllib2.urlopen(req).read() + #ret = ast.literal_eval(ret) + ret = req.json() if ret['status'] == 'success': # logging.info('return:{0}'.format(ret)) try: diff --git a/utils/ci/test_sdk_monitor.sh b/utils/ci/test_sdk_monitor.sh index afd4b8c..51e5e7a 100755 --- a/utils/ci/test_sdk_monitor.sh +++ b/utils/ci/test_sdk_monitor.sh @@ -29,6 +29,9 @@ son-emu-cli compute stop -d datacenter1 -n vnf1 # test if prometheus query worked echo $cpu_load + +regex='\[[0-9.]*, .*\]' + if [[ $cpu_load =~ $regex ]] ; then echo " cpu monitor test OK" exit 0 @@ -36,3 +39,5 @@ else echo "cpu monitor test not OK" exit 1 fi + +