fixed refactoring issues in mobility.py, fixed issue with parsing config files in a tuple string format
This commit is contained in:
parent
4d21314798
commit
05ce19b0c0
4 changed files with 24 additions and 15 deletions
|
@ -106,7 +106,9 @@ def maketuplefromstr(s, value_type):
|
|||
:return: tuple from string
|
||||
:rtype: tuple
|
||||
"""
|
||||
return tuple(value_type(i) for i in s.split(","))
|
||||
# remove tuple braces and strip commands and space from all values in the tuple string
|
||||
values = [x.strip("' ") for x in s.strip("(), ").split(",")]
|
||||
return tuple(value_type(i) for i in values)
|
||||
|
||||
|
||||
def mutecall(*args, **kwargs):
|
||||
|
|
|
@ -722,13 +722,13 @@ class WayPointMobility(WirelessModel):
|
|||
nexttime = self.queue[0].time - now
|
||||
if nexttime > (0.001 * self.refresh_ms):
|
||||
nexttime -= 0.001 * self.refresh_ms
|
||||
self.session.evq.add_event(nexttime, self.runround)
|
||||
self.session.event_loop.add_event(nexttime, self.runround)
|
||||
return
|
||||
else:
|
||||
# no more waypoints or queued items, loop?
|
||||
if not self.empty_queue_stop:
|
||||
# keep running every refresh_ms, even with empty queue
|
||||
self.session.evq.add_event(0.001 * self.refresh_ms, self.runround)
|
||||
self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround)
|
||||
return
|
||||
if not self.loopwaypoints():
|
||||
return self.stop(move_initial=False)
|
||||
|
@ -751,7 +751,7 @@ class WayPointMobility(WirelessModel):
|
|||
self.session.mobility.updatewlans(moved, moved_netifs)
|
||||
|
||||
# TODO: check session state
|
||||
self.session.evq.add_event(0.001 * self.refresh_ms, self.runround)
|
||||
self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
|
@ -1107,9 +1107,9 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
def findfile(self, file_name):
|
||||
"""
|
||||
Locate a script file. If the specified file doesn't exist, look in the
|
||||
same directory as the scenario file (session.filename), or in the default
|
||||
same directory as the scenario file, or in the default
|
||||
configs directory (~/.core/configs). This allows for sample files without
|
||||
absolute pathnames.
|
||||
absolute path names.
|
||||
|
||||
:param str file_name: file name to find
|
||||
:return: absolute path to the file
|
||||
|
@ -1118,8 +1118,8 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
if os.path.exists(file_name):
|
||||
return file_name
|
||||
|
||||
if self.session.filename is not None:
|
||||
d = os.path.dirname(self.session.filename)
|
||||
if self.session.file_name is not None:
|
||||
d = os.path.dirname(self.session.file_name)
|
||||
sessfn = os.path.join(d, file_name)
|
||||
if os.path.exists(sessfn):
|
||||
return sessfn
|
||||
|
@ -1163,7 +1163,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
try:
|
||||
return self.nodemap[nodenum]
|
||||
except KeyError:
|
||||
logger.exception("error find value in node map")
|
||||
logger.exception("error finding value in node map, ignored and returns node id")
|
||||
return nodenum
|
||||
|
||||
def startup(self):
|
||||
|
@ -1186,7 +1186,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
self.movenodesinitial()
|
||||
logger.info("scheduling ns-2 script for %s autostart at %s" % (self.wlan.name, t))
|
||||
self.state = self.STATE_RUNNING
|
||||
self.session.evq.add_event(t, self.run)
|
||||
self.session.event_loop.add_event(t, self.run)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
|
|
|
@ -350,14 +350,17 @@ class CoreServices(ConfigurableManager):
|
|||
:param bool use_startup_service: flag to use startup services or not
|
||||
:return: nothing
|
||||
"""
|
||||
logger.info("starting service %s (%s)(custom)" % (service._name, service._startindex))
|
||||
logger.info("starting service(%s) %s (%s)(custom)",
|
||||
service, service._name, service._startindex)
|
||||
for directory in service._dirs:
|
||||
try:
|
||||
node.privatedir(directory)
|
||||
except:
|
||||
logger.exception("Error making node %s dir %s", node.name, directory)
|
||||
logger.exception("error making node %s dir %s", node.name, directory)
|
||||
|
||||
logger.info("service configurations: %s", service._configs)
|
||||
for i, filename in enumerate(service._configs):
|
||||
logger.info("generating service config: %s", filename)
|
||||
if len(filename) == 0:
|
||||
continue
|
||||
cfg = self.getservicefiledata(service, filename)
|
||||
|
|
|
@ -14,8 +14,11 @@ class Zebra(CoreService):
|
|||
_name = "zebra"
|
||||
_group = "Quagga"
|
||||
_dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
|
||||
_configs = ("/usr/local/etc/quagga/Quagga.conf",
|
||||
"quaggaboot.sh", "/usr/local/etc/quagga/vtysh.conf")
|
||||
_configs = (
|
||||
"/usr/local/etc/quagga/Quagga.conf",
|
||||
"quaggaboot.sh",
|
||||
"/usr/local/etc/quagga/vtysh.conf"
|
||||
)
|
||||
_startindex = 35
|
||||
_startup = ("sh quaggaboot.sh zebra",)
|
||||
_shutdown = ("killall zebra",)
|
||||
|
@ -33,7 +36,8 @@ class Zebra(CoreService):
|
|||
elif filename == cls._configs[2]:
|
||||
return cls.generateVtyshConf(node, services)
|
||||
else:
|
||||
raise ValueError
|
||||
raise ValueError("file name (%s) is not a known configuration: %s",
|
||||
filename, cls._configs)
|
||||
|
||||
@classmethod
|
||||
def generateVtyshConf(cls, node, services):
|
||||
|
|
Loading…
Add table
Reference in a new issue