Remove Information Coordinator Service
[nonrtric.git] / sdnc-a1-controller / oam / installation / sdnc-a1 / src / main / scripts / healthcheck.py
1 # ============LICENSE_START=======================================================
2 #  Copyright (C) 2019 Nordix Foundation.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # SPDX-License-Identifier: Apache-2.0
17 # ============LICENSE_END=========================================================
18 #
19
20
21 # coding=utf-8
22 import os
23 import httplib
24 import base64
25 import time
26
27 username = os.environ['ODL_ADMIN_USERNAME']
28 password = os.environ['ODL_ADMIN_PASSWORD']
29 TIMEOUT=1000
30 INTERVAL=30
31 timePassed=0
32
33 headers = {'Authorization':'Basic %s' % base64.b64encode(username + ":" + password),
34            'X-FromAppId': 'csit-sdnc',
35            'X-TransactionId': 'csit-sdnc',
36            'Accept':"application/json",
37            'Content-type':"application/json"}
38
39 def makeHealthcheckCall(headers, timePassed):
40     connected = False
41     # WAIT 10 minutes maximum and test every 30 seconds if HealthCheck API is returning 200
42     while timePassed < TIMEOUT:
43         try:
44             conn = httplib.HTTPConnection("localhost",8181)
45             req = conn.request("POST", "/restconf/operations/SLI-API:healthcheck",headers=headers)
46             res = conn.getresponse()
47             res.read()
48             if res.status == 200:
49                 print ("Healthcheck Passed in %d seconds." %timePassed)
50                 connected = True
51                 break
52             else:
53                 print ("Sleep: %d seconds before testing if Healthcheck worked. Total wait time up now is: %d seconds. Timeout is: %d seconds" %(INTERVAL, timePassed, TIMEOUT))
54         except:
55             print ("Cannot execute REST call. Sleep: %d seconds before testing if Healthcheck worked. Total wait time up now is: %d seconds. Timeout is: %d seconds" %(INTERVAL, timePassed, TIMEOUT))
56         timePassed = timeIncrement(timePassed)
57
58     if timePassed > TIMEOUT:
59         print ("TIME OUT: Healthcheck not passed in  %d seconds... Could cause problems for testing activities..." %TIMEOUT)
60     return connected
61
62
63 def timeIncrement(timePassed):
64     time.sleep(INTERVAL)
65     timePassed = timePassed + INTERVAL
66     return timePassed
67
68 makeHealthcheckCall(headers, timePassed)