aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarraghEgan <darragh.egan@est.tech>2019-05-20 13:25:13 +0000
committerDarraghEgan <darragh.egan@est.tech>2019-05-20 13:25:13 +0000
commit2739fc5cf1b15f736e93d884a0b769deeda7b682 (patch)
tree624879594c880d6807e175cb1c9b053e5a036edf
parent9fda47895727309b1bfa5b67d3d87defa2633d51 (diff)
SDNC-766: Refactoring of installCerts.py
Refactoring the script based on comments made on code in SDNC-759. Issue-ID: SDNC-766 Change-Id: Id6d3d8b265b61b6437a029e5cf74d685a2cf8c37 Signed-off-by: DarraghEgan <darragh.egan@est.tech> Former-commit-id: bcd48edd5a8b23ceec4ca665bfedb43437f6b05f
-rw-r--r--installation/sdnc/src/main/scripts/installCerts.py64
1 files changed, 30 insertions, 34 deletions
diff --git a/installation/sdnc/src/main/scripts/installCerts.py b/installation/sdnc/src/main/scripts/installCerts.py
index 1cc74546..17ada4c1 100644
--- a/installation/sdnc/src/main/scripts/installCerts.py
+++ b/installation/sdnc/src/main/scripts/installCerts.py
@@ -32,9 +32,9 @@ zipFileList = []
username = os.environ['ODL_ADMIN_USERNAME']
password = os.environ['ODL_ADMIN_PASSWORD']
-timeOut=1000
-interval=30
-time=0
+TIMEOUT=1000
+INTERVAL=30
+timePassed=0
postKeystore= "/restconf/operations/netconf-keystore:add-keystore-entry"
postPrivateKey= "/restconf/operations/netconf-keystore:add-private-key"
@@ -153,38 +153,37 @@ def processFiles(folder, count):
makeRestconfPost(conn, json_private_key, postPrivateKey)
makeRestconfPost(conn, json_trusted_cert, postTrustedCertificate)
-def makeHealthcheckCall(headers, time):
- conn = httplib.HTTPConnection("localhost",8181)
- req = conn.request("POST", "/restconf/operations/SLI-API:healthcheck",headers=headers)
- res = conn.getresponse()
- res.read()
- if res.status == 200:
- print ("Healthcheck Passed in %d seconds." %time)
- else:
- print ("Sleep: %d seconds before testing if Healtcheck worked. Total wait time up now is: %d seconds. Timeout is: %d seconds" %(interval, time, timeOut))
- return res.status
-
-
-def timeIncrement(time):
- time.sleep(interval)
- time = time + interval
- return time
-
-def healthcheck(time):
+def makeHealthcheckCall(headers, timePassed):
+ connected = False
# WAIT 10 minutes maximum and test every 30 seconds if HealthCheck API is returning 200
- while time < timeOut:
+ while timePassed < TIMEOUT:
try:
- status = makeHealthcheckCall(headers, time)
- #if status == 200:
- connected = True
- break
+ conn = httplib.HTTPConnection("localhost",8181)
+ req = conn.request("POST", "/restconf/operations/SLI-API:healthcheck",headers=headers)
+ res = conn.getresponse()
+ res.read()
+ if res.status == 200:
+ print ("Healthcheck Passed in %d seconds." %timePassed)
+ connected = True
+ break
+ else:
+ print ("Sleep: %d seconds before testing if Healthcheck worked. Total wait time up now is: %d seconds. Timeout is: %d seconds" %(INTERVAL, timePassed, TIMEOUT))
except:
- print ("Sleep: %d seconds before testing if Healthcheck worked. Total wait time up now is: %d seconds. Timeout is: %d seconds" %(interval, time, timeOut))
+ 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))
+ timePassed = timeIncrement(timePassed)
+
+ if timePassed > TIMEOUT:
+ print ("TIME OUT: Healthcheck not passed in %d seconds... Could cause problems for testing activities..." %TIMEOUT)
+ return connected
+
- time = timeIncrement(time)
+def timeIncrement(timePassed):
+ time.sleep(INTERVAL)
+ timePassed = timePassed + INTERVAL
+ return timePassed
- if time > timeOut:
- print ("TIME OUT: Healthcheck not passed in %d seconds... Could cause problems for testing activities..." %timeOut)
+def readCertProperties():
+ connected = makeHealthcheckCall(headers, timePassed)
if connected:
count = 0
@@ -199,8 +198,5 @@ def healthcheck(time):
del zipFileList[:]
else:
print "Error: File not found in path entered"
- else:
- print "This was a problem here, Healthcheck never passed, please check is your instance up and running."
-
-healthcheck(time)
+readCertProperties()