tests for ssl connection for PRH, AAI and DmaaP
[integration/csit.git] / tests / dcaegen2 / prh-testcases / resources / simulator / AAI.py
1 import re
2 import time
3 from http.server import BaseHTTPRequestHandler
4 import httpServerLib
5
6 pnfs = 'Empty'
7
8
9 class AAISetup(BaseHTTPRequestHandler):
10
11     def do_PUT(self):
12         if re.search('/set_pnfs', self.path):
13             global pnfs
14             content_length = int(self.headers['Content-Length'])
15             pnfs = self.rfile.read(content_length)
16             httpServerLib.header_200_and_json(self)
17
18         return
19
20     def do_POST(self):
21         if re.search('/reset', self.path):
22             global pnfs
23             pnfs = 'Empty'
24             httpServerLib.header_200_and_json(self)
25
26         return
27
28
29 class AAIHandler(BaseHTTPRequestHandler):
30
31     def do_PATCH(self):
32         pnfs_name = '/aai/v12/network/pnfs/pnf/' + pnfs.decode()
33         if re.search('wrong_aai_record', self.path):
34             self.send_response(400)
35             self.end_headers()
36         elif re.search(pnfs_name, self.path):
37             self.send_response(200)
38             self.end_headers()
39             
40         return
41
42
43 def _main_(handler_class=AAIHandler, protocol="HTTP/1.0"):
44     handler_class.protocol_version = protocol
45     httpServerLib.start_http_endpoint(3333, AAIHandler)
46     httpServerLib.start_https_endpoint(3334, AAIHandler)
47     httpServerLib.start_http_endpoint(3335, AAISetup)
48     while 1:
49         time.sleep(10)
50
51
52 if __name__ == '__main__':
53     _main_()