From: Robert Eby Date: Fri, 4 Oct 2019 14:03:04 +0000 (-0400) Subject: Create podevents as the installer reports them. X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=rec.git;a=commitdiff_plain;h=e9585ab225af5e910238902ef8fa86129e6b2638 Create podevents as the installer reports them. Get logging credentials from the environment (LOGGING_USER/LOGGING_PASSWORD) Signed-off-by: Robert Eby Change-Id: I4fdb39be9774ff78b5797ddb7ec9dbcbdc94cdf7 --- diff --git a/workflows/REC_create.py b/workflows/REC_create.py index 8e8fb92..3467b53 100755 --- a/workflows/REC_create.py +++ b/workflows/REC_create.py @@ -142,6 +142,16 @@ def send_request(ri_ip, CLOUDNAME, ISO, BOOTISO): print(response) return response.json().get('uuid') +def create_podevent(msg='Default msg', level='INFO'): + API_HOST = 'http://arc-api:8080' + if os.environ.get('LOGGING_USER') and os.environ.get('LOGGING_PASSWORD'): + payload = {'name': os.environ['LOGGING_USER'], 'password': os.environ['LOGGING_PASSWORD']} + response = requests.post(API_HOST+'/api/v1/login', json=payload) + token = response.headers['X-ARC-Token'] + headers = {'X-ARC-Token': token} + payload = {'uuid': POD.POD, 'level': level, 'message': msg} + response = requests.post(API_HOST+'/api/v1/podevent', headers=headers, json=payload) + def wait_for_completion(ri_ip, id, ntimes): """ Wait (up to ntimes minutes) for the remote_installer to finish. @@ -150,17 +160,21 @@ def wait_for_completion(ri_ip, id, ntimes): status = 'ongoing' URL = 'https://%s:%d/v1/installations/%s/state' % (ri_ip, API_PORT, id) certs = (CERT_DIR+'/clientcert.pem', CERT_DIR+'/clientkey.pem') + lastevent = '' while status == 'ongoing' and ntimes > 0: time.sleep(60) response = requests.get(URL, cert=certs, verify=False) j = response.json() t = ( - datetime.datetime.now().strftime('%x %X'), str(j.get('status')), str(j.get('percentage')), str(j.get('description')) ) - print('%s: Status is %s (%s) %s' % t) + event = 'Status is %s (%s) %s' % t + print('%s: %s' % (datetime.datetime.now().strftime('%x %X'), event)) + if event != lastevent: + create_podevent(event) + lastevent = event status = j.get('status') ntimes = ntimes - 1 return status != 'completed'