def assertMinionEventReceived(self, desired_event): queue_wait = 5 # 2.5s while self.q.empty(): time.sleep(0.5) # Wait for events to be pushed into the queue queue_wait -= 1 if queue_wait <= 0: raise AssertionError('Queue wait timer expired') while not self.q.empty(): # This is not thread-safe and may be inaccurate event = self.q.get() if isinstance(event, dict): event.pop('_stamp') if desired_event == event: self.fetch_proc.terminate() return True self.fetch_proc.terminate() raise AssertionError('Event {0} was not received by minion'.format(desired_event))
def assertMinionEventReceived(self, desired_event, queue_wait=2.5): max_time = time.time() + queue_wait while self.q.empty(): time.sleep(0.5) # Wait for events to be pushed into the queue if time.time() >= max_time: raise AssertionError( 'Queue wait timer expired after {} seconds.'.format( queue_wait)) while not self.q.empty( ): # This is not thread-safe and may be inaccurate event = self.q.get() if isinstance(event, dict): event.pop('_stamp') if desired_event == event: self.fetch_proc.terminate() return True self.fetch_proc.terminate() raise AssertionError( 'Event {0} was not received by minion'.format(desired_event))
def assertMinionEventReceived(self, desired_event, timeout=5, sleep_time=0.5): start = time.time() while True: try: event = self.q.get(False) except Empty: time.sleep(sleep_time) if time.time() - start >= timeout: break continue if isinstance(event, dict): event.pop('_stamp') if desired_event == event: self.fetch_proc.terminate() return True if time.time() - start >= timeout: break self.fetch_proc.terminate() raise AssertionError('Event {0} was not received by minion'.format(desired_event))
def print_async_event(self, suffix, event): ''' Print all of the events with the prefix 'tag' ''' # some suffixes we don't want to print if suffix in ('new', ): return # TODO: clean up this event print out. We probably want something # more general, since this will get *really* messy as # people use more events that don't quite fit into this mold if suffix == 'ret': # for "ret" just print out return salt.output.display_output(event['return'], '', self.opts) elif isinstance(event, dict) and 'outputter' in event and event['outputter'] is not None: print(self.outputters[event['outputter']](event['data'])) # otherwise fall back on basic printing else: event.pop('_stamp') # remove the timestamp before printing print('{tag}: {event}'.format(tag=suffix, event=event))