def test_event_write(self):
     logger.debug("something")
     cyvents.event("unittest", "TRIAL1", logger)
     logger.debug("something-else")
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].source == "unittest"
     assert events[0].name == "TRIAL1"
 def test_timestamp(self):
     utc_now = datetime.datetime.utcnow()
     cyvents.event("unittest", "TRIAL1", logger)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     ts = events[0].timestamp
     
     # It is possible that any of these values could have rolled over
     # between acquiring utc_now and recording the event.  But this is
     # unlikely enough that we'll keep this important UTC sanity check:
     assert ts.year == utc_now.year
     assert ts.month == utc_now.month
     assert ts.day == utc_now.day
     assert ts.hour == utc_now.hour
 def test_extra_hierarchy(self):
     # note the conflicting "hello3" key in higher level:
     innerdict = {"hello3":"hello4"}
     adict = {"hello1":"hello2", "hello5":innerdict, "hello3":"hello6"}
     
     cyvents.event("unittest", "TRIAL1", logger, extra=adict)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == "hello2"
     assert events[0].extra["hello3"] == "hello6"
     
     innerdict = events[0].extra["hello5"]
     assert isinstance(innerdict, dict)
     assert innerdict["hello3"] == "hello4"
 def test_manual_event_write(self):
     cruft = "some cruft %s" % cyvents.event_logtxt("unittest", "TRIAL1")
     logger.warning(cruft)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     
     cyvents.event("unittest", "TRIAL2", logger)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 2
     
     cruft = "cruft2 %s" % cyvents.event_logtxt("unittest", "TRIAL3")
     logger.warning(cruft)
     
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 3
     
     found = {"TRIAL1":False, "TRIAL2":False, "TRIAL3":False}
     for ev in events:
         if found.has_key(ev.name):
             found[ev.name] = True
     for val in found.values():
         assert val
 def test_event_nameandsourcefilter(self):
     cyvents.event("SRC1", "NX1", logger)
     logger.debug("something not an event")
     cyvents.event("SRX2", "NM2", logger)
     cyvents.event("SRC3", "XX3", logger)
     cyvents.event("SRX4", "XX4", logger)
     cyvents.event("SRC5", "NM5", logger)
     logger.debug("something not an event")
     cyvents.event("SRC6", "NM6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, sourcefilter="SRC", namefilter="NM")
     assert len(events) == 2
 def test_event_sourcefilter2(self):
     cyvents.event("SRC1", "NM1", logger)
     logger.debug("something not an event")
     cyvents.event("SRX2", "NM2", logger)
     cyvents.event("SRC3", "NM3", logger)
     logger.debug("something not an event")
     cyvents.event("SRX4", "NM4", logger)
     cyvents.event("SRC5", "NM5", logger)
     cyvents.event("SRC6", "NM6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, sourcefilter="SRC")
     assert len(events) == 4
 def test_event_namefilter2(self):
     cyvents.event("unittest", "NM1", logger)
     logger.debug("something not an event")
     cyvents.event("unittest", "XX2", logger)
     cyvents.event("unittest", "NM3", logger)
     logger.debug("something not an event")
     cyvents.event("unittest", "XX4", logger)
     cyvents.event("unittest", "NM5", logger)
     cyvents.event("unittest", "XX6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, namefilter="NM")
     assert len(events) == 3
 def test_extra_integer_values(self):
     adict = {"hello1":34}
     cyvents.event("unittest", "TRIAL1", logger, extra=adict)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == 34
 def test_unique_keys(self):
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 7
     uniqs = {}
     for ev in events:
         uniqs[ev.timestamp] = None
     assert len(uniqs) == 7
def fetch_kill_byID(p, c, m, run_name, cloudinitd, tokill_list, get_workerstatus=True):
    """Get logs and then kills a list of workers

    tokill_list -- RunVM instances
    """

    m.remote_svc_adapter.initialize(m, run_name, cloudinitd)

    if get_workerstatus:
        # Get the latest information, especially for IaaS status and controller correlation
        em_core_status.find_latest_status(p, c, m, run_name, cloudinitd, findworkersfirst=False)

    threads = []
    for one_kill in tokill_list:
        scpcmd = m.runlogs.get_scp_command_str(c, one_kill, cloudinitd)
        threads.append(FetchThread(one_kill, c, m, scpcmd))

    txt = "%d worker" % len(tokill_list)
    if len(tokill_list) != 1:
        txt += "s"
    c.log.info("Beginning to fetch and kill %s" % txt)

    done = False
    idx = 0
    while not done:
        current_batch = threads[idx:idx+THREADS_PER_BATCH]
        idx += THREADS_PER_BATCH
        if idx > len(threads):
            done = True
            
        for thr in current_batch:
            thr.start()
           
        for thr in current_batch:
            thr.join()
        
    error_count = 0
    for thr in threads:
        if thr.error:
            error_count += 1
            msg = "** Issue with %s:\n" % thr.worker.instanceid
            msg += str(thr.error)
            c.log.error("\n\n%s\n" % msg)

    # terminate even if there was an error log fetching

    # provisioner is given the nodeid, not instanceid
    nodeid_list = []
    for one_kill in tokill_list:
        nodeid_list.append(one_kill.nodeid)

    m.remote_svc_adapter.kill_workers(nodeid_list)

    for one_kill in tokill_list:
        extradict = {"iaas_id":one_kill.instanceid, "controller": one_kill.parent}
        cyvents.event("epumgmt", "fetch_killed", c.log, extra=extradict)

    if error_count:
        c.log.info("All fetched and killed with %d fetch errors" % error_count)
    else:
        c.log.info("All fetched and killed")

    return error_count