add verification status logging to update-rs-db.py
outputs a csv file with the data and the update success statuses for the api link, guideline, and target fields, as well as a success status for the verification update itself. see update-rs-db.rst for format details on the log file. Change-Id: Ib21e84b177229af25420506ff5fd7060fe3ec163
This commit is contained in:
parent
92bf63aa9d
commit
74b7a6904b
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import requests
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import datetime
|
||||||
|
import requests
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -50,34 +52,50 @@ def linkChk(link, token):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def updateResult(apiLink, target, guideline, token):
|
def updateResult(apiLink, target, guideline, token, results_log):
|
||||||
response = requests.post(apiLink + '/meta/shared', headers={
|
success = True
|
||||||
'Authorization': 'Bearer ' + token}, data='true')
|
with open(results_log, 'a') as logfile:
|
||||||
if response.status_code != 201:
|
logfile.write(str(datetime.datetime.now()) + ",")
|
||||||
print("Update shared status response_status_code=" +
|
response = requests.post(apiLink + '/meta/shared', headers={
|
||||||
str(response.status_code))
|
'Authorization': 'Bearer ' + token}, data='true')
|
||||||
return False
|
if response.status_code != 201:
|
||||||
if ".json" not in guideline:
|
print("Update shared status response_status_code=" +
|
||||||
guideline = str(guideline) + ".json"
|
str(response.status_code))
|
||||||
response = requests.post(apiLink + '/meta/guideline', headers={
|
logfile.write(apiLink + ",0,")
|
||||||
'Authorization': 'Bearer ' + token}, data=guideline)
|
success = False
|
||||||
if response.status_code != 201:
|
else:
|
||||||
print("Update guideline response_status_code=" +
|
logfile.write(apiLink + ",1,")
|
||||||
str(response.status_code))
|
if ".json" not in guideline:
|
||||||
return False
|
guideline = str(guideline) + ".json"
|
||||||
response = requests.post(apiLink + '/meta/target', headers={
|
response = requests.post(apiLink + '/meta/guideline', headers={
|
||||||
'Authorization': 'Bearer ' + token}, data=target)
|
'Authorization': 'Bearer ' + token}, data=guideline)
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
print("Update target response_status_code=" +
|
print("Update guideline response_status_code=" +
|
||||||
str(response.status_code))
|
str(response.status_code))
|
||||||
return False
|
logfile.write(guideline + ",0,")
|
||||||
print("test result updated. Verifying.")
|
success = False
|
||||||
response = requests.put(apiLink, headers={
|
else:
|
||||||
'Authorization': 'Bearer ' + token}, json={'verification_status': 1})
|
logfile.write(guideline + ",1,")
|
||||||
if response.status_code != 201:
|
response = requests.post(apiLink + '/meta/target', headers={
|
||||||
return False
|
'Authorization': 'Bearer ' + token}, data=target)
|
||||||
print("Test result verified.")
|
if response.status_code != 201:
|
||||||
return True
|
print("Update target response_status_code=" +
|
||||||
|
str(response.status_code))
|
||||||
|
logfile.write(target + ",0,")
|
||||||
|
success = False
|
||||||
|
else:
|
||||||
|
logfile.write(target + ",1,")
|
||||||
|
if success:
|
||||||
|
print("test result updated. Verifying.")
|
||||||
|
response = requests.put(apiLink, headers={
|
||||||
|
'Authorization': 'Bearer ' + token},
|
||||||
|
json={'verification_status': 1})
|
||||||
|
if response.status_code != 201:
|
||||||
|
success = False
|
||||||
|
else:
|
||||||
|
print("Test result verified.")
|
||||||
|
logfile.write(str(int(success)) + '\n')
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -93,8 +111,12 @@ def main():
|
||||||
help="the base URL of the endpoint. ex: http://examplerefstack.com/v1")
|
help="the base URL of the endpoint. ex: http://examplerefstack.com/v1")
|
||||||
parser.add_argument("--token", "-t", metavar="t", type=str,
|
parser.add_argument("--token", "-t", metavar="t", type=str,
|
||||||
action="store", required=True, help="API auth token")
|
action="store", required=True, help="API auth token")
|
||||||
|
parser.add_argument("--logfile", "-l", metavar="l", type=str,
|
||||||
|
action="store", default="verification_results.csv",
|
||||||
|
help="name of logfile to output data into")
|
||||||
result = parser.parse_args()
|
result = parser.parse_args()
|
||||||
infile = result.file
|
infile = result.file
|
||||||
|
logfile = result.logfile
|
||||||
endpoint = result.endpoint
|
endpoint = result.endpoint
|
||||||
token = result.token
|
token = result.token
|
||||||
with open(infile) as f:
|
with open(infile) as f:
|
||||||
|
@ -118,7 +140,7 @@ def main():
|
||||||
"Result link is valid. Updating result with ID " +
|
"Result link is valid. Updating result with ID " +
|
||||||
testId)
|
testId)
|
||||||
success = updateResult(apiLink, target, guideline,
|
success = updateResult(apiLink, target, guideline,
|
||||||
token)
|
token, logfile)
|
||||||
if not success:
|
if not success:
|
||||||
print("update of the results with the ID " +
|
print("update of the results with the ID " +
|
||||||
testId + " failed. please recheck your " +
|
testId + " failed. please recheck your " +
|
||||||
|
|
|
@ -53,5 +53,18 @@ It then uses that test ID to update the internal db using refstack's built
|
||||||
in RESTful api.
|
in RESTful api.
|
||||||
|
|
||||||
Lastly, if at least one of the links has proven to be valid, we will
|
Lastly, if at least one of the links has proven to be valid, we will
|
||||||
then use the same RESTful api, and test ID to update the verification_status
|
then use the same RESTful api and test ID to update the verification_status
|
||||||
field associated with that test result.
|
field associated with that test result.
|
||||||
|
|
||||||
|
The status of each of these steps will be output to "verification_status.csv"
|
||||||
|
by default. A '1' will denote that the resource was successfully updated while
|
||||||
|
a '0' will denote that the resource was not successfully updated. The order of
|
||||||
|
fields of this file are as follows:
|
||||||
|
- Date modified
|
||||||
|
- API link
|
||||||
|
- Shared update status
|
||||||
|
- Guideline
|
||||||
|
- Guideline update success status
|
||||||
|
- Target
|
||||||
|
- Target update success status
|
||||||
|
- Verification update success status
|
||||||
|
|
Loading…
Reference in New Issue