コード例 #1
0
    def fail(self):
        """
            Throw an exception, mimicing something going wrong inside an app.
        """
        msg = "Entering failure mode..."
        LOG.info("[log] %s", msg)
        write_output("[out] %s" % msg)

        raise Exception("User-forced failure")
コード例 #2
0
def do_run(network_id, scenario_id, timeout=5, fail=False):
    msg = "Running Utility on Network %s, Scenario %s", network_id, scenario_id
    LOG.info("[log] %s", msg)
    write_output("[out] %s" % msg)
    runner = Runner()
    if fail is True:
        runner.fail()
    else:
        runner.wait(timeout)
    LOG.info("[log] Network Utility Run")
コード例 #3
0
    def wait(self, timeout):
        msg = "Waiting {0} seconds".format(timeout)
        write_output("[out] %s"%msg)
        LOG.info("[log] %s", msg)

        for i in range(0, timeout):
            sleep(1)
            write_progress(i+1, timeout)

        msg = "Waiting complete"
        write_output("[out] %s"%msg)
        LOG.info("[log] %s", msg)
コード例 #4
0
    def wait(self, timeout):
        """
            Wait for the specified number of seconds.
        """
        msg = "Waiting for {0} seconds".format(timeout)
        LOG.info("[log] %s", msg)
        write_output("[out] %s" % msg)

        for i in range(0, timeout):
            sleep(1)
            write_progress(i + 1, timeout)

        msg = "Waiting Complete".format(timeout)
        LOG.info("[log] %s", msg)
        write_output("[out] %s" % msg)
コード例 #5
0
def do_run(network_id, timeout=5, fail=False, heavy_load=False):

    msg = "Calling Runner"
    write_output("[out] %s"%msg)
    LOG.info("[log] %s", msg)

    runner = Runner(network_id)

    if heavy_load is True:
        runner.do_heavy_load()
    elif fail is True:
        runner.fail()
    else:
        runner.wait(timeout)

    msg = "Finished Calling Runner"
    write_output("[out] %s"%msg)
    LOG.info("[log] %s", msg)
コード例 #6
0
    def _run_loop_process(self, process=None):
        write_output("v.0.2 - Running "+ str(process.name))
        a=0
        st=100000000
        limit=randint(st / 10,2*st)

        start_time=time()

        while a<limit:
            a = a + 1
            current_time=time()
            if current_time > start_time+1:
                print(process.name)
                write_progress(a, limit)
                start_time=current_time

        msg = "[Network ID: {}] End Process {} for a total of {} cycles".format(
            self.network_id, str(process.name),a)

        write_output("[out] %s"%msg)
        LOG.info("[log] %s", msg)
コード例 #7
0
ファイル: exporter.py プロジェクト: UMWRG/debug-app
def do_export(network_id, scenario_id, dummy1, dummy2, dummy3, switch_on, fail, data_dir):
    LOG.info("[log] Exporting data")
    write_output("[out] Exporting data")
    jobdetails = {
        'network_id'  : network_id,
        'scenario_id' : scenario_id,
        'dummy1'      : dummy1,
        'dummy2'      : dummy2,
        'dummy3'      : dummy3,
        'switch_on'   : switch_on,
        'fail'        : fail,
    }

    if fail is not False:
        raise Exception("Forced to fail using the 'fail' flag!")

    filepath = os.path.join(data_dir, 'DebugExport.json')
    with open(filepath, 'w') as f:
        json.dump(jobdetails, f)

    LOG.info("[log] Data Exported")
    write_output("[out] Data Exported")
コード例 #8
0
    def do_heavy_load(self):
        msg = "Doing a heavy load"
        write_output("[out] %s"%msg)
        LOG.info("[log] %s", msg)

        processes=[]
        for i in range(0,4):
            process = Object()
            process.name = "process_{}".format(i)

            processes.append(multiprocessing.Process(name=process.name,
                                                     target=self._run_loop_process,
                                                     args=(process,)))

        for p in processes:
            p.start()

        for p in processes:
            p.join()

        msg = "Heavy Load Done"
        write_output("[out] %s"%msg)
        LOG.info("[log] %s", msg)
コード例 #9
0
 def fail(self):
     msg = "Forcing a user-defined failure"
     write_output("[out] %s"%msg)
     LOG.info("[log] %s", msg)
     raise Exception("[Network ID: {}] - User-forced failure".format(self.network_id))