diff options
-rw-r--r-- | Dockerfile | 10 | ||||
-rwxr-xr-x | bin/run.py | 5 | ||||
-rw-r--r-- | coverage.xml | 255 | ||||
-rw-r--r-- | miss_htbt_service.egg-info/PKG-INFO | 1 | ||||
-rw-r--r-- | miss_htbt_service/htbtworker.py | 132 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | target/checkstyle-cachefile | 2 | ||||
-rw-r--r-- | target/checkstyle-checker.xml | 220 | ||||
-rw-r--r-- | target/checkstyle-header.txt | 40 | ||||
-rw-r--r-- | target/checkstyle-result.xml | 3 | ||||
-rw-r--r-- | target/failsafe-reports/failsafe-summary.xml | 8 | ||||
-rw-r--r-- | tests/test_binding.py | 79 | ||||
-rw-r--r-- | xunit-results.xml | 24 |
13 files changed, 323 insertions, 457 deletions
@@ -11,11 +11,11 @@ RUN pip install pyyaml --upgrade RUN pip install -r requirements.txt RUN pip install -e . -RUN mkdir /opt/config -RUN echo 1.2.3.4 > /opt/config/coll_ip.txt -RUN echo 1234 > /opt/config/coll_port.txt -RUN echo 4.5.6.7 > /opt/config/pol_ip.txt -RUN echo 4567 > /opt/config/pol_port.txt +RUN mkdir /tmp/config +RUN echo 1.2.3.4 > /tmp/config/coll_ip.txt +RUN echo 1234 > /tmp/config/coll_port.txt +RUN echo 4.5.6.7 > /tmp/config/pol_ip.txt +RUN echo 4567 > /tmp/config/pol_port.txt EXPOSE 10000 ENV PYTHONPATH /usr/local/lib/python3.6/site-packages @@ -17,6 +17,9 @@ # ============LICENSE_END========================================================= # # ECOMP is a trademark and service mark of AT&T Intellectual Property. +# +# Author Gokul Singaraju gs244f@att.com +# import sys import yaml @@ -55,7 +58,7 @@ if __name__ == '__main__': #print(cfg['vnfs'][vnf][0]) #print(cfg['vnfs'][vnf][1]) #print(cfg['vnfs'][vnf][2]) - #Start Heartbeat monitoring process on VNFs configured + #Start Heartbeat monitoring process worker thread on VNFs configured p = multiprocessing.Process(target=checkhtbt, args=(cfg['global']['message_router_url'],cfg['vnfs'][vnf][0],cfg['vnfs'][vnf][1],cfg['vnfs'][vnf][2],cfg['vnfs'][vnf][3])) jobs.append(p) p.start() diff --git a/coverage.xml b/coverage.xml index 289994f..ad70a4c 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,140 +1,132 @@ <?xml version="1.0" ?> -<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0" lines-covered="0" lines-valid="135" timestamp="1520200792383" version="4.5.1"> +<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.5926" lines-covered="96" lines-valid="162" timestamp="1522178057938" version="4.5.1"> <!-- Generated by coverage.py: https://coverage.readthedocs.io --> <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> <sources> - <source>/root/heartbeat</source> + <source>/root/fresh/heartbeat</source> </sources> <packages> - <package branch-rate="0" complexity="0" line-rate="0" name="miss_htbt_service"> + <package branch-rate="0" complexity="0" line-rate="0.5926" name="miss_htbt_service"> <classes> - <class branch-rate="0" complexity="0" filename="miss_htbt_service/__init__.py" line-rate="0" name="__init__.py"> + <class branch-rate="0" complexity="0" filename="miss_htbt_service/__init__.py" line-rate="0.8571" name="__init__.py"> <methods/> <lines> - <line hits="0" number="19"/> - <line hits="0" number="20"/> - <line hits="0" number="23"/> - <line hits="0" number="24"/> + <line hits="1" number="19"/> + <line hits="1" number="20"/> + <line hits="1" number="23"/> + <line hits="1" number="24"/> <line hits="0" number="25"/> - <line hits="0" number="26"/> - <line hits="0" number="27"/> - <line hits="0" number="28"/> - <line hits="0" number="29"/> - <line hits="0" number="30"/> - <line hits="0" number="32"/> - <line hits="0" number="33"/> - <line hits="0" number="35"/> + <line hits="1" number="26"/> + <line hits="1" number="27"/> + <line hits="1" number="28"/> + <line hits="1" number="29"/> + <line hits="1" number="30"/> + <line hits="1" number="32"/> + <line hits="1" number="33"/> + <line hits="1" number="35"/> <line hits="0" number="37"/> </lines> </class> - <class branch-rate="0" complexity="0" filename="miss_htbt_service/htbtworker.py" line-rate="0" name="htbtworker.py"> + <class branch-rate="0" complexity="0" filename="miss_htbt_service/htbtworker.py" line-rate="0.5676" name="htbtworker.py"> <methods/> <lines> - <line hits="0" number="16"/> - <line hits="0" number="17"/> - <line hits="0" number="18"/> - <line hits="0" number="19"/> - <line hits="0" number="20"/> - <line hits="0" number="21"/> - <line hits="0" number="24"/> - <line hits="0" number="25"/> - <line hits="0" number="27"/> - <line hits="0" number="29"/> - <line hits="0" number="31"/> - <line hits="0" number="33"/> - <line hits="0" number="34"/> - <line hits="0" number="35"/> - <line hits="0" number="36"/> - <line hits="0" number="37"/> - <line hits="0" number="40"/> - <line hits="0" number="41"/> - <line hits="0" number="42"/> - <line hits="0" number="44"/> - <line hits="0" number="45"/> - <line hits="0" number="46"/> + <line hits="1" number="21"/> + <line hits="1" number="22"/> + <line hits="1" number="23"/> + <line hits="1" number="24"/> + <line hits="1" number="25"/> + <line hits="1" number="26"/> + <line hits="1" number="30"/> + <line hits="1" number="31"/> + <line hits="1" number="33"/> + <line hits="1" number="35"/> + <line hits="1" number="37"/> + <line hits="1" number="39"/> + <line hits="1" number="40"/> + <line hits="1" number="41"/> + <line hits="1" number="42"/> + <line hits="1" number="43"/> + <line hits="1" number="44"/> + <line hits="1" number="47"/> + <line hits="1" number="48"/> <line hits="0" number="49"/> - <line hits="0" number="50"/> + <line hits="1" number="51"/> <line hits="0" number="52"/> - <line hits="0" number="57"/> - <line hits="0" number="58"/> + <line hits="0" number="53"/> + <line hits="1" number="55"/> + <line hits="0" number="56"/> + <line hits="1" number="58"/> <line hits="0" number="59"/> - <line hits="0" number="60"/> - <line hits="0" number="61"/> - <line hits="0" number="62"/> - <line hits="0" number="63"/> - <line hits="0" number="67"/> - <line hits="0" number="69"/> - <line hits="0" number="71"/> - <line hits="0" number="76"/> - <line hits="0" number="77"/> - <line hits="0" number="78"/> + <line hits="1" number="62"/> + <line hits="1" number="67"/> + <line hits="1" number="68"/> + <line hits="1" number="69"/> + <line hits="1" number="70"/> + <line hits="1" number="71"/> + <line hits="1" number="72"/> + <line hits="1" number="73"/> + <line hits="1" number="77"/> <line hits="0" number="79"/> - <line hits="0" number="80"/> - <line hits="0" number="81"/> - <line hits="0" number="82"/> - <line hits="0" number="86"/> - <line hits="0" number="88"/> - <line hits="0" number="92"/> - <line hits="0" number="93"/> - <line hits="0" number="94"/> - <line hits="0" number="96"/> - <line hits="0" number="97"/> - <line hits="0" number="98"/> - <line hits="0" number="101"/> - <line hits="0" number="103"/> - <line hits="0" number="104"/> - <line hits="0" number="106"/> - <line hits="0" number="108"/> - <line hits="0" number="110"/> - <line hits="0" number="111"/> - <line hits="0" number="112"/> - <line hits="0" number="113"/> - <line hits="0" number="114"/> - <line hits="0" number="115"/> - <line hits="0" number="116"/> - <line hits="0" number="118"/> - <line hits="0" number="119"/> - <line hits="0" number="120"/> - <line hits="0" number="121"/> - <line hits="0" number="122"/> - <line hits="0" number="123"/> - <line hits="0" number="125"/> - <line hits="0" number="127"/> - <line hits="0" number="153"/> - <line hits="0" number="154"/> - <line hits="0" number="155"/> - <line hits="0" number="156"/> - <line hits="0" number="158"/> - <line hits="0" number="159"/> - <line hits="0" number="160"/> - <line hits="0" number="161"/> - <line hits="0" number="162"/> - <line hits="0" number="164"/> - <line hits="0" number="165"/> + <line hits="1" number="82"/> + <line hits="1" number="87"/> + <line hits="1" number="88"/> + <line hits="1" number="89"/> + <line hits="1" number="90"/> + <line hits="1" number="91"/> + <line hits="1" number="92"/> + <line hits="1" number="93"/> + <line hits="1" number="97"/> + <line hits="0" number="99"/> + <line hits="1" number="103"/> + <line hits="1" number="106"/> + <line hits="1" number="107"/> + <line hits="1" number="109"/> + <line hits="1" number="110"/> + <line hits="1" number="111"/> + <line hits="1" number="114"/> + <line hits="1" number="116"/> + <line hits="1" number="118"/> + <line hits="1" number="121"/> + <line hits="1" number="122"/> + <line hits="1" number="123"/> + <line hits="1" number="125"/> + <line hits="1" number="126"/> + <line hits="1" number="127"/> + <line hits="1" number="128"/> + <line hits="0" number="129"/> + <line hits="0" number="130"/> + <line hits="0" number="131"/> + <line hits="0" number="133"/> + <line hits="0" number="134"/> + <line hits="0" number="135"/> + <line hits="0" number="136"/> + <line hits="0" number="137"/> + <line hits="0" number="138"/> + <line hits="0" number="140"/> <line hits="0" number="166"/> <line hits="0" number="167"/> <line hits="0" number="168"/> <line hits="0" number="169"/> <line hits="0" number="170"/> - <line hits="0" number="171"/> <line hits="0" number="172"/> <line hits="0" number="173"/> <line hits="0" number="174"/> + <line hits="0" number="175"/> + <line hits="0" number="176"/> <line hits="0" number="177"/> - <line hits="0" number="202"/> - <line hits="0" number="203"/> - <line hits="0" number="204"/> - <line hits="0" number="205"/> - <line hits="0" number="206"/> - <line hits="0" number="207"/> - <line hits="0" number="208"/> - <line hits="0" number="209"/> - <line hits="0" number="210"/> - <line hits="0" number="211"/> - <line hits="0" number="212"/> - <line hits="0" number="213"/> - <line hits="0" number="215"/> - <line hits="0" number="216"/> + <line hits="1" number="179"/> + <line hits="1" number="180"/> + <line hits="1" number="181"/> + <line hits="1" number="182"/> + <line hits="1" number="183"/> + <line hits="1" number="184"/> + <line hits="1" number="185"/> + <line hits="1" number="186"/> + <line hits="1" number="187"/> + <line hits="1" number="188"/> + <line hits="0" number="189"/> + <line hits="0" number="190"/> + <line hits="0" number="192"/> <line hits="0" number="217"/> <line hits="0" number="218"/> <line hits="0" number="219"/> @@ -142,15 +134,50 @@ <line hits="0" number="221"/> <line hits="0" number="222"/> <line hits="0" number="223"/> - <line hits="0" number="224"/> + <line hits="1" number="224"/> + <line hits="1" number="225"/> <line hits="0" number="226"/> <line hits="0" number="227"/> <line hits="0" number="228"/> <line hits="0" number="229"/> - <line hits="0" number="230"/> - <line hits="0" number="232"/> - <line hits="0" number="233"/> - <line hits="0" number="234"/> + <line hits="1" number="230"/> + <line hits="1" number="233"/> + <line hits="1" number="235"/> + <line hits="1" number="236"/> + <line hits="1" number="237"/> + <line hits="1" number="238"/> + <line hits="1" number="239"/> + <line hits="1" number="240"/> + <line hits="1" number="241"/> + <line hits="1" number="242"/> + <line hits="1" number="243"/> + <line hits="1" number="244"/> + <line hits="1" number="245"/> + <line hits="1" number="249"/> + <line hits="0" number="252"/> + <line hits="0" number="253"/> + <line hits="0" number="254"/> + <line hits="0" number="255"/> + <line hits="0" number="256"/> + <line hits="0" number="257"/> + <line hits="0" number="258"/> + <line hits="0" number="259"/> + <line hits="0" number="260"/> + <line hits="0" number="263"/> + <line hits="0" number="264"/> + <line hits="0" number="265"/> + <line hits="1" number="267"/> + <line hits="0" number="268"/> + <line hits="0" number="269"/> + <line hits="0" number="270"/> + <line hits="0" number="271"/> + <line hits="0" number="272"/> + <line hits="0" number="273"/> + <line hits="0" number="274"/> + <line hits="0" number="275"/> + <line hits="1" number="279"/> + <line hits="0" number="281"/> + <line hits="0" number="282"/> </lines> </class> </classes> diff --git a/miss_htbt_service.egg-info/PKG-INFO b/miss_htbt_service.egg-info/PKG-INFO index 019ebf2..1137abf 100644 --- a/miss_htbt_service.egg-info/PKG-INFO +++ b/miss_htbt_service.egg-info/PKG-INFO @@ -6,7 +6,6 @@ Home-page: https://gerrit.onap.org/r/#/admin/projects/dcaegen2/platform/heartbea Author: Gokul Singaraju Author-email: gs244f@att.com License: UNKNOWN -Description-Content-Type: UNKNOWN Description: UNKNOWN Keywords: missing heartbeat microservice Platform: UNKNOWN diff --git a/miss_htbt_service/htbtworker.py b/miss_htbt_service/htbtworker.py index b8eadb4..b81deae 100644 --- a/miss_htbt_service/htbtworker.py +++ b/miss_htbt_service/htbtworker.py @@ -12,6 +12,11 @@ # 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. +# +# Author Gokul Singaraju gs244f@att.com +# Simple Microservice +# Tracks Heartbeat messages on input topic in DMaaP +# and generates Missing Heartbeat signal for Policy Engine import requests import math @@ -21,6 +26,7 @@ import string import sys +# Initialise tracking hash tables intvl = 60 missing_htbt = 2 #tracks last epoch time @@ -31,10 +37,11 @@ heartstate = {} heartflag = {} #saves heartbeat message for policy heartmsg = {} -mr_url = 'http://mrrouter.att.com:3904' -pol_url = 'http://mrrouter.att.com:3904' +mr_url = 'http://mrrouter.onap.org:3904' +pol_url = 'http://mrrouter.onap.org:3904' intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT' outopic = 'POLICY-HILOTCA-EVENT-OUTPUT' +periodic_scheduler = None # Checks for heartbeat event on periodic basis class PeriodicScheduler(object): @@ -45,19 +52,22 @@ class PeriodicScheduler(object): action(*actionargs) self.scheduler.enter(interval, 1, self.setup, (interval, action, actionargs)) - def run(self): self.scheduler.run() + def stop(self): + list(map(self.scheduler.cancel, self.scheduler.queue)) + +# Formats collector uri from config files of heat template def get_collector_uri(): """ This method waterfalls reads an envioronmental variable called COLLECTOR_HOST If that doesn't work, it raises an Exception """ - with open('/opt/config/coll_ip.txt', 'r') as myfile: + with open('/tmp/config/coll_ip.txt', 'r') as myfile: coll_ip=myfile.read().replace('\n', '') myfile.close() - with open('/opt/config/coll_port.txt', 'r') as myfile2: + with open('/tmp/config/coll_port.txt', 'r') as myfile2: coll_port=myfile2.read().replace('\n', '') myfile2.close() if coll_ip and coll_port: @@ -68,15 +78,16 @@ def get_collector_uri(): else: raise BadEnviornmentENVNotFound("COLLECTOR_HOST") +# Formats Policy uri from config files of heat template def get_policy_uri(): """ This method waterfalls reads an envioronmental variable called POLICY_HOST If that doesn't work, it raises an Exception """ - with open('/opt/config/coll_ip.txt', 'r') as myfile: + with open('/tmp/config/coll_ip.txt', 'r') as myfile: pol_ip=myfile.read().replace('\n', '') myfile.close() - with open('/opt/config/coll_port.txt', 'r') as myfile2: + with open('/tmp/config/coll_port.txt', 'r') as myfile2: pol_port=myfile2.read().replace('\n', '') myfile2.close() if pol_ip and pol_port : @@ -90,21 +101,25 @@ def get_policy_uri(): # Process the heartbeat event on input topic def periodic_event(): - print("Checking... ") - print(datetime.datetime.now()) + global periodic_scheduler + global mr_url, pol_url, missing_htbt, intvl, intopic, outopic + ret = 0 + print("Checking..." , datetime.datetime.now()) #Read heartbeat get_url = mr_url+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' - print(get_url) + print("Getting :"+get_url) res = requests.get(get_url) #print(res) #print(res.headers) print(res.text) #print(res.json) inputString = res.text - jlist = json.loads(inputString); + #jlist = json.loads(inputString) + jlist = inputString.split('\n'); #print("List:"+jlist[0]) + # Process the DMaaP input message retreived for line in jlist: - #print(line) + print("Line:"+line) jobj = json.loads(line) #print(jobj) srcid = (jobj['event']['commonEventHeader']['sourceId']) @@ -122,9 +137,7 @@ def periodic_event(): heartflag[srcid] = sdiff; heartmsg[srcid] = jobj; else: - print("Heartbeat Dead raising alarm event") - #payload = {'Event': 'Heartbeat Failure', 'Host': srcid, 'LastTimestamp': hearttrack[srcid], 'Sequence': heartstate[srcid]} - payload = {"event": { + payload = json.dumps({"event": { "commonEventHeader": { "reportingEntityName": "VNFVM", "reportingEntityName": "VNFVM", @@ -149,14 +162,16 @@ def periodic_event(): "sourceId": "cff8656d-0b42-4eda-ab5d-3d2b7f2d74c8" } } - } + }) payload = heartmsg[srcid] print(payload) - send_url = pol_url+'/events/'+outopic+'/DefaultGroup/1?timeout=15000' - print(send_url) + psend_url = pol_url+'/events/'+outopic+'/DefaultGroup/1?timeout=15000' + print(psend_url) + print("Heartbeat Dead raising alarm event "+psend_url) #Send response for policy on output topic - r = requests.post(send_url, data=payload) + r = requests.post(psend_url, data=payload) print(r.status_code, r.reason) + ret = r.status_code del heartstate[srcid] del hearttrack[srcid] del heartflag[srcid] @@ -166,15 +181,15 @@ def periodic_event(): heartstate[srcid] = seqnum heartflag[srcid] = 1 heartmsg[srcid] = jobj; + ret = 1 chkeys = [] - for key in heartstate.iterkeys(): + for key in heartstate.keys(): print(key,heartstate[key]) if( heartflag[key] == 0 ): print("Heartbeat Dead raise alarm event"+key) chkeys.append( key ) - #payload = {'Event': 'Heartbeat Failure', 'Host': key, 'LastTimestamp': hearttrack[key], 'Sequence': heartstate[key]} #print payload - payload = {"event": { + payload = json.dumps({"event": { "commonEventHeader": { "reportingEntityName": "VNFVM", "startEpochMicrosec": 1508641592248000, @@ -198,37 +213,70 @@ def periodic_event(): "sourceId": "cff8656d-0b42-4eda-ab5d-3d2b7f2d74c8" } } - } + }) payload = heartmsg[key] print(payload) send_url = pol_url+'/events/'+outopic+'/DefaultGroup/1?timeout=15000' print(send_url) r = requests.post(send_url, data=payload) print(r.status_code, r.reason) + ret = r.status_code heartflag[key] = 0 for chkey in chkeys: print(chkey) del heartstate[chkey] del hearttrack[chkey] del heartflag[chkey] + return ret + +#test setup for coverage +def test_setup(args): + global mr_url, pol_url, missing_htbt, intvl, intopic, outopic + mr_url = get_collector_uri() + pol_url = get_policy_uri() + missing_htbt = float(int(args[2])) + intvl = float(int(args[3])) + intopic = args[4] + outopic = args[5] + print ("Message router url %s " % mr_url) + print ("Policy url %s " % pol_url) + print ("Interval %s " % intvl) + print ("Input topic %s " % intopic) + print ("Output topic %s " % outopic) + #intvl = 60 # every second + +#Main invocation +def main(args): + global periodic_scheduler + global mr_url, pol_url, missing_htbt, intvl, intopic, outopic + mr_url = get_collector_uri() + pol_url = get_policy_uri() + missing_htbt = int(args[2]) + intvl = int(args[3]) + intopic = args[4] + outopic = args[5] + print ("Message router url %s " % mr_url) + print ("Policy router url %s " % pol_url) + print ("Interval %s " % intvl) + #intvl = 60 # every second + #Start periodic scheduler runs every interval + periodic_scheduler = PeriodicScheduler() + periodic_scheduler.setup(intvl, periodic_event) # it executes the event just once + periodic_scheduler.run() # it starts the scheduler -total = len(sys.argv) -cmdargs = str(sys.argv) -print ("The total numbers of args passed to the script: %d " % total) -print ("Args list: %s " % cmdargs) -print ("Script name: %s" % str(sys.argv[0])) -for i in range(total): +if __name__ == "__main__": + total = len(sys.argv) + cmdargs = str(sys.argv) + print ("The total numbers of args passed to the script: %d " % total) + print ("Missing Heartbeat Args list: %s " % cmdargs) + print ("Script name: %s" % str(sys.argv[0])) + for i in range(total): print ("Argument # %d : %s" % (i, str(sys.argv[i]))) -if( total >= 6 ): - mr_url = get_collector_uri() - pol_url = get_policy_uri() - #mr_url = sys.argv[1] - missing_htbt = float(int(sys.argv[2])) - intvl = float(int(sys.argv[3])) - intopic = sys.argv[4] - outopic = sys.argv[5] -print ("Interval %s " % intvl) -#intvl = 60 # every second -periodic_scheduler = PeriodicScheduler() -periodic_scheduler.setup(intvl, periodic_event) # it executes the event just once -periodic_scheduler.run() # it starts the scheduler + main(sys.argv[1:]) + + +#force stop scheduler +def stop(): + global periodic_scheduler + if not periodic_scheduler is None: + periodic_scheduler.stop() diff --git a/requirements.txt b/requirements.txt index b838342..9617d32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ connexion==1.1.12 requests==2.18.2 six==1.10.0 PyYAML==3.12 +HTTPretty==0.8.14 diff --git a/target/checkstyle-cachefile b/target/checkstyle-cachefile deleted file mode 100644 index a0970bf..0000000 --- a/target/checkstyle-cachefile +++ /dev/null @@ -1,2 +0,0 @@ -#Tue Feb 27 23:21:54 EST 2018 -configuration*?=15B4FB894B57CADB17418F12E3274FB4B864070B diff --git a/target/checkstyle-checker.xml b/target/checkstyle-checker.xml deleted file mode 100644 index 32439e2..0000000 --- a/target/checkstyle-checker.xml +++ /dev/null @@ -1,220 +0,0 @@ -<?xml version="1.0"?> -<!-- - Copyright (c) 2016 Huawei Technologies Co., Ltd. - - 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. ---> -<!DOCTYPE module PUBLIC - "-//Puppy Crawl//DTD Check Configuration 1.3//EN" - "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - -<!-- - - Checkstyle configuration that checks the Google coding conventions from: - - - Google Java Style - https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html - - Checkstyle is very configurable. Be sure to read the documentation at - http://checkstyle.sf.net (or in your downloaded distribution). - - Most Checks are configurable, be sure to consult the documentation. - - To completely disable a check, just comment it out or delete it from the file. - - Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. - - --> - -<module name = "Checker"> - <property name="charset" value="UTF-8"/> - - <property name="severity" value="warning"/> - - <property name="fileExtensions" value="java, properties, xml"/> - <!-- Checks for whitespace --> - <!-- See http://checkstyle.sf.net/config_whitespace.html --> - <module name="FileTabCharacter"> - <property name="eachLine" value="true"/> - </module> - - <module name="TreeWalker"> - <module name="OuterTypeFilename"/> - <module name="IllegalTokenText"> - <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> - <property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/> - <property name="message" value="Avoid using corresponding octal or Unicode escape."/> - </module> - <module name="AvoidEscapedUnicodeCharacters"> - <property name="allowEscapesForControlCharacters" value="true"/> - <property name="allowByTailComment" value="true"/> - <property name="allowNonPrintableEscapes" value="true"/> - </module> - <module name="LineLength"> - <property name="max" value="120"/> - <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> - </module> - <module name="AvoidStarImport"/> - <module name="OneTopLevelClass"/> - <module name="NoLineWrap"/> - <module name="EmptyBlock"> - <property name="option" value="TEXT"/> - <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> - </module> - <module name="NeedBraces"/> - <module name="LeftCurly"> - <property name="maxLineLength" value="120"/> - </module> - <module name="RightCurly"> - <property name="option" value="alone"/> - <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/> - </module> - <module name="WhitespaceAround"> - <property name="allowEmptyConstructors" value="true"/> - <property name="allowEmptyMethods" value="true"/> - <property name="allowEmptyTypes" value="true"/> - <property name="allowEmptyLoops" value="true"/> - <message key="ws.notFollowed" - value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> - <message key="ws.notPreceded" - value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/> - </module> - <module name="OneStatementPerLine"/> - <module name="MultipleVariableDeclarations"/> - <module name="ArrayTypeStyle"/> - <module name="MissingSwitchDefault"/> - <module name="FallThrough"/> - <module name="UpperEll"/> - <module name="ModifierOrder"/> - <module name="EmptyLineSeparator"> - <property name="allowNoEmptyLineBetweenFields" value="true"/> - </module> - <module name="SeparatorWrap"> - <property name="tokens" value="DOT"/> - <property name="option" value="nl"/> - </module> - <module name="SeparatorWrap"> - <property name="tokens" value="COMMA"/> - <property name="option" value="EOL"/> - </module> - <module name="PackageName"> - <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> - <message key="name.invalidPattern" - value="Package name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="TypeName"> - <message key="name.invalidPattern" - value="Type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MemberName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <message key="name.invalidPattern" - value="Member name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ParameterName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <message key="name.invalidPattern" - value="Parameter name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="LocalVariableName"> - <property name="tokens" value="VARIABLE_DEF"/> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <property name="allowOneCharVarInForLoop" value="true"/> - <message key="name.invalidPattern" - value="Local variable name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ClassTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Class type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MethodTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Method type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="NoFinalizer"/> - <module name="GenericWhitespace"> - <message key="ws.followed" - value="GenericWhitespace ''{0}'' is followed by whitespace."/> - <message key="ws.preceded" - value="GenericWhitespace ''{0}'' is preceded with whitespace."/> - <message key="ws.illegalFollow" - value="GenericWhitespace ''{0}'' should followed by whitespace."/> - <message key="ws.notPreceded" - value="GenericWhitespace ''{0}'' is not preceded with whitespace."/> - </module> - <module name="Indentation"> - <property name="basicOffset" value="4"/> - <property name="braceAdjustment" value="0"/> - <property name="caseIndent" value="4"/> - <property name="throwsIndent" value="4"/> - <property name="lineWrappingIndentation" value="4"/> - <property name="arrayInitIndent" value="4"/> - </module> - <module name="AbbreviationAsWordInName"> - <property name="ignoreFinal" value="false"/> - <property name="allowedAbbreviationLength" value="1"/> - </module> - <module name="OverloadMethodsDeclarationOrder"/> - <module name="VariableDeclarationUsageDistance"/> - <module name="CustomImportOrder"> - <property name="sortImportsInGroupAlphabetically" value="true"/> - <property name="separateLineBetweenGroups" value="true"/> - <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/> - </module> - <module name="MethodParamPad"/> - <module name="OperatorWrap"> - <property name="option" value="NL"/> - <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/> - </module> - <module name="AnnotationLocation"> - <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/> - </module> - <module name="AnnotationLocation"> - <property name="tokens" value="VARIABLE_DEF"/> - <property name="allowSamelineMultipleAnnotations" value="true"/> - </module> - <module name="NonEmptyAtclauseDescription"/> - <module name="JavadocTagContinuationIndentation"/> - <module name="SummaryJavadocCheck"> - <property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/> - </module> - <module name="JavadocParagraph"/> - <module name="AtclauseOrder"> - <property name="tagOrder" value="@param, @return, @throws, @deprecated"/> - <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> - </module> - <module name="JavadocMethod"> - <property name="scope" value="public"/> - <property name="allowMissingParamTags" value="true"/> - <property name="allowMissingThrowsTags" value="true"/> - <property name="allowMissingReturnTag" value="true"/> - <property name="minLineCount" value="2"/> - <property name="allowedAnnotations" value="Override, Test"/> - <property name="allowThrowsTagsForSubclasses" value="true"/> - </module> - <module name="MethodName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> - <message key="name.invalidPattern" - value="Method name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="SingleLineJavadoc"> - <property name="ignoreInlineTags" value="false"/> - </module> - <module name="EmptyCatchBlock"> - <property name="exceptionVariableName" value="expected"/> - </module> - <module name="CommentsIndentation"/> - </module> -</module> diff --git a/target/checkstyle-header.txt b/target/checkstyle-header.txt deleted file mode 100644 index 9536f0b..0000000 --- a/target/checkstyle-header.txt +++ /dev/null @@ -1,40 +0,0 @@ -/* -* ============LICENSE_START========================================== -* =================================================================== -* Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. -* =================================================================== -* -* Unless otherwise specified, all software contained herein is licensed -* under the Apache License, Version 2.0 (the "License"); -* you may not use this software 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. -* -* -* -* Unless otherwise specified, all documentation contained herein is licensed -* under the Creative Commons License, Attribution 4.0 Intl. (the "License"); -* you may not use this documentation except in compliance with the License. -* You may obtain a copy of the License at -* -* https://creativecommons.org/licenses/by/4.0/ -* -* Unless required by applicable law or agreed to in writing, documentation -* 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. -* -* ============LICENSE_END============================================ -* -* ECOMP is a trademark and service mark of AT&T Intellectual Property. -* -*/ - diff --git a/target/checkstyle-result.xml b/target/checkstyle-result.xml deleted file mode 100644 index 472022e..0000000 --- a/target/checkstyle-result.xml +++ /dev/null @@ -1,3 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<checkstyle version="6.11.2"> -</checkstyle> diff --git a/target/failsafe-reports/failsafe-summary.xml b/target/failsafe-reports/failsafe-summary.xml deleted file mode 100644 index ac2b7cb..0000000 --- a/target/failsafe-reports/failsafe-summary.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<failsafe-summary result="254" timeout="false"> - <completed>0</completed> - <errors>0</errors> - <failures>0</failures> - <skipped>0</skipped> - <failureMessage/> -</failsafe-summary>
\ No newline at end of file diff --git a/tests/test_binding.py b/tests/test_binding.py index cb1f212..2e16f13 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -16,36 +16,77 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. +import os +import io import requests -#from miss_htbt_service import htbtworker -#from miss_htbt_service import get_collector_uri,get_policy_uri +import httpretty +#import miss_htbt_service +from miss_htbt_service import htbtworker +#from miss_htbt_service.htbtworker import get_collector_uri,get_policy_uri import pytest import json -from requests.exceptions import HTTPError, RequestException -from requests import Response import base64 +import errno +import imp +MODULE_EXTENSIONS = ('.py', '.pyc', '.pyo') + +def package_contents(package_name): + file, pathname, description = imp.find_module(package_name) + if file: + raise ImportError('Not a package: %r', package_name) + # Use a set because some may be both source and compiled. + return set([os.path.splitext(module)[0] + for module in os.listdir(pathname) + if module.endswith(MODULE_EXTENSIONS)]) ##### # MONKEYPATCHES ##### -mr_url = 'http://0.0.0.0:3904' -intopic = 'INPUT_TOPIC_v1' +#mr_url = 'http://127.0.0.1:3904' +mr_url = 'http://mrrouter.att.com:3904' +intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT' +outopic = 'OUTPUT_TOPIC_v1' +@httpretty.activate def test_resolve_all(monkeypatch): - htbtmsg = {"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}} + #htbtmsg = "Find the best daily deals" + htbtmsg = '{"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}}' send_url = mr_url+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' print(send_url) - #send_url = get_collector_uri()+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' - #print(send_url) - #send_url = get_policy_uri()+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' - #print(send_url) - #r = requests.post(send_url, data=htbtmsg) - #sleep(60) - #r = requests.post(send_url, data=htbtmsg) - #sleep(60) - #r = requests.post(send_url, data=htbtmsg) - #print(r.status_code, r.reason) - #assert(r.status_code == 404) - assert(404 == 404) + httpretty.register_uri(httpretty.GET, send_url, body=htbtmsg) + #Use + response = requests.get(send_url) + print(response) + print(response.text) + assert(response.text == htbtmsg) + try: + os.makedirs('/tmp/config') + except OSError as e: + if e.errno != errno.EEXIST: + raise + with open("/tmp/config/coll_ip.txt", "w") as file: + #file.write('127.0.0.1') + file.write('mytest.onap.org') + file.close() + with open("/tmp/config/coll_port.txt", "w") as file2: + file2.write('3904') + file2.close() + #print(package_contents('miss_htbt_service')) + #response = requests.get(send_url) + #print(response) + #print(response.text) + #assert(response.text == htbtmsg) + htbtmsg = json.dumps({"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}}) + send_url = htbtworker.get_collector_uri()+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' + print("Send URL : "+send_url) + httpretty.register_uri(httpretty.GET, send_url, body=htbtmsg, content_type="application/json") + pol_url = htbtworker.get_policy_uri()+'/events/'+outopic+'/DefaultGroup/1?timeout=15000' + pol_body = json.dumps({"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}}) + print("Policy URL : "+pol_url) + httpretty.register_uri(httpretty.POST, pol_url, body=pol_body, status=200, content_type='text/json') + htbtworker.test_setup([send_url,send_url,3,60,intopic,outopic]) + ret = htbtworker.periodic_event() + print("Returned",ret) + assert(ret == 1) diff --git a/xunit-results.xml b/xunit-results.xml index d17e68f..ce0fd44 100644 --- a/xunit-results.xml +++ b/xunit-results.xml @@ -1,2 +1,22 @@ -<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="1" time="0.250"><testcase classname="tests.test_binding" file="tests/test_binding.py" line="34" name="test_resolve_all" time="0.0022954940795898438"><system-out>http://0.0.0.0:3904/events/INPUT_TOPIC_v1/DefaultGroup/1?timeout=15000 -</system-out></testcase></testsuite>
\ No newline at end of file +<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="1" time="0.303"><testcase classname="tests.test_binding" file="tests/test_binding.py" line="50" name="test_resolve_all" time="0.025246858596801758"><system-out>http://mrrouter.att.com:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 +<Response [200]> +{"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}} +Send URL : http://mytest.onap.org:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 +Policy URL : http://mytest.onap.org:3904/events/OUTPUT_TOPIC_v1/DefaultGroup/1?timeout=15000 +Message router url http://mytest.onap.org:3904 +Policy url http://mytest.onap.org:3904 +Interval 60.0 +Input topic VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT +Output topic OUTPUT_TOPIC_v1 +Checking... 2018-03-27 15:14:17.651127 +Getting :http://mytest.onap.org:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 +{"event": {"commonEventHeader": {"startEpochMicrosec": 1518616063564475, "sourceId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "eventId": "10048640", "reportingEntityId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "priority": "Normal", "version": 3, "reportingEntityName": "SWMSVM", "sequence": 10048640, "domain": "heartbeat", "lastEpochMicrosec": 1518616063564476, "eventName": "Heartbeat_vMrf", "sourceName": "SWMSVM", "nfNamingCode": "vMRF"}}} +Line:{"event": {"commonEventHeader": {"startEpochMicrosec": 1518616063564475, "sourceId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "eventId": "10048640", "reportingEntityId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "priority": "Normal", "version": 3, "reportingEntityName": "SWMSVM", "sequence": 10048640, "domain": "heartbeat", "lastEpochMicrosec": 1518616063564476, "eventName": "Heartbeat_vMrf", "sourceName": "SWMSVM", "nfNamingCode": "vMRF"}}} +Adding new source +587c14b3-72c0-4581-b5cb-6567310b9bb7 10048640 +Returned 1 +</system-out><system-err>2018-03-27 15:14:17,645 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mrrouter.att.com +2018-03-27 15:14:17,648 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mrrouter.att.com:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 415 +2018-03-27 15:14:17,652 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mytest.onap.org +2018-03-27 15:14:17,662 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mytest.onap.org:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 442 +</system-err></testcase></testsuite>
\ No newline at end of file |