Revision cafb67a9 test_code/babel.py

View differences:

test_code/babel.py
9 9
import time
10 10
from dummyrouting import dummyRoutingRandomTest
11 11
from compute_theoretical_values import ComputeTheoreticalValues
12
import code
13

  
14 12
import signal
15 13

  
14
import code
15

  
16 16
from test_generic import *
17 17

  
18 18

  
19 19
class BABELTest(dummyRoutingRandomTest):
20
    sigtoname=dict([[v,k] for k,v in signal.__dict__.items()])
20 21

  
21 22
    def launchBabel(self, runPrefix, host, cmdargs):
22 23

  
......
47 48
        #params['-N'] = neighfile
48 49
        params['-w'] = ""
49 50
        params.update(cmdargs)
50
        info("### Launching babel on "+hostname+" ###\n")
51
        #info("### Launching babel on "+hostname+" ###\n")
51 52
        return self.bgCmd(host, True, cmd,
52 53
            *reduce(lambda x, y: x + y, params.items()) )
53 54

  
......
69 70
        for run_id in run_ids:
70 71
            info("\nStarting run " + str(run_id) + "\n")
71 72
            if self.stopNodeList:
72
                #code.interact(local=dict(globals(), **locals()))
73 73
                self.nodeCrashed = self.stopNodeList.pop(0)
74 74
            else:
75 75
                self.nodeCrashed = None
......
121 121

  
122 122
            for event in eventList:
123 123
                sleep(event[0])
124
                #code.interact(local=dict(globals(), **locals()))
125
                event[2](**event[3])
126 124
                info(event[1] + str(time.time()) + "\n")
125
                event[2](**event[3])
127 126
            sleep(waitTime)
128 127
            for pid in self.pendingProc.keys():
129 128
                self.sendSig(pid, signal.SIGTERM)
......
233 232
        dest_ip = d.intfList()[0].ip
234 233
        return dest_ip
235 234

  
235
    def number_to_host(self, host_number):
236
        host_list = self.getAllHosts()
237
        for host in host_list:
238
            number = int(host.name.split("_")[0][1:])
239
            if host_number == number:
240
                return host
241
        print "ERROR: no host number:", number, "in host_list:"
242
        print "  ", self.getAllHosts() 
243
        return None
244

  
236 245
    def sendSignal(self, sig, hostName=""):
237 246
        strsig="uknown signal"
238
        if (sig == signal.SIGUSR1):
247
        '''if (sig == signal.SIGUSR1):
239 248
            strsig="SIGUSR1"
240 249
        if (sig == signal.SIGQUIT):
241 250
            strsig="SIGQUIT"
242 251
        elif (sig == signal.SIGTERM):
243 252
            strsig="SIGTERM"
244 253
        elif (sig == signal.SIGKILL):
245
            strsig="SIGKILL"
246
        for pid, h in self.pendingProc.items():
247
            if hostName:
248
                if h.name == hostName:
249
                    print "sending signal to host:", h.name, ", pid", pid
254
            strsig="SIGKILL"'''
255
        strsig = BABELTest.sigtoname[sig]
256
        if hostName:
257
            #code.interact(local=dict(globals(), **locals()))
258
            for pid, h in self.pendingProc.items():
259
                if h == hostName:
260
                    print "sending " + strsig + " to host:", h.name, ", pid", pid
250 261
                    self.sendSig(pid, sig)
251
            # send to all
252
            else:
253
                print "sending signal to all hosts:", strsig
262
        # send to all
263
        else:
264
            print "sending " + strsig + " to all hosts"
265
            for pid, h in self.pendingProc.items():
254 266
                self.sendSig(pid, sig)
255 267

  
256 268
    def __init__(self, mininet, name, args):

Also available in: Unified diff