def wait_for_job_to_finish(self, job_name, execution_id, start_time='now-10m'): ops_h = self.connections.ops_inspects[self.inputs.collector_ips[0]] table = 'ObjectJobExecutionTable' query = '(Messagetype=JobLog)' response = ops_h.post_query( table, start_time=start_time, end_time='now', select_fields=['MessageTS', 'Messagetype', 'ObjectLog'], where_clause=query) if response: for resp in response: dct = elem2dict(etree.fromstring(resp['ObjectLog'])) log = dct['log_entry']['JobLogEntry'] if log['name'] == job_name and \ log['execution_id'] == execution_id: if log['status'].upper() == 'SUCCESS': self.logger.debug('job %s with exec id %s finished' % (job_name, execution_id)) return (True, log) elif log['status'].upper() == 'FAILURE': assert False, 'job %s with exec id %s failed' % ( job_name, execution_id) else: self.logger.warn('job %s with exec id %s hasnt completed' % (job_name, execution_id)) else: self.logger.warn( 'Query failed for table ObjectJobExecutionTable. Will retry...' ) return (False, None)
def check_gdo_details(self, gdo_type): #todo: skiranh . Check if the response is correct instead of the below routine start_time='now-5m' ops_h = self.connections.ops_inspects[self.inputs.collector_ips[0]] table = 'ObjectJobExecutionTable' query = '(Messagetype=JobLog)' response = ops_h.post_query(table, start_time=start_time,end_time='now',select_fields=['MessageTS', 'Messagetype', 'ObjectLog'],where_clause=query) gdo_occurence = 0 if response: for resp in response: dct = elem2dict(etree.fromstring(resp['ObjectLog'])) if "Imported system info for juniper device" in dct: gdo_occurence = gdo_occurence + 1 if gdo_occurence != len(self.fabric.devices): return True else: return False
def wait_for_job_to_finish(self, job_name, execution_id, start_time='now-10m'): ops_h = self.connections.ops_inspects[self.inputs.collector_ips[0]] table = 'ObjectJobExecutionTable' query = '(Messagetype=JobLog)' response = ops_h.post_query(table, start_time=start_time, end_time='now', select_fields=['MessageTS', 'Messagetype', 'ObjectLog'], where_clause=query) if response: for resp in response: dct = elem2dict(etree.fromstring(resp['ObjectLog'])) log = dct['log_entry']['JobLogEntry'] if log['name'] == job_name and \ log['execution_id'] == execution_id: if log['status'].upper() == 'SUCCESS': self.logger.debug('job %s with exec id %s finished'%(job_name, execution_id)) return True elif log['status'].upper() == 'FAILURE': assert False, 'job %s with exec id %s failed'%(job_name, execution_id) else: self.logger.warn('job %s with exec id %s hasnt completed'%(job_name, execution_id)) else: self.logger.warn('Query failed for table ObjectJobExecutionTable. Will retry...') return False