def testTaskCleanup(self): myTask1 = BasicTestTask() myTask1.name = "myTask1.1" myTask1.configId = "myTask1" myTask2 = BasicTestTask() myTask2.name = "myTask1.2" myTask2.configId = "myTask1" myTask2.state = "DOING_SOMETHING" # keep this task from being cleaned scheduler = Scheduler() scheduler.addTask(myTask1) scheduler.addTask(myTask2) self.assertTrue(scheduler._isTaskCleanable(myTask1)) self.assertFalse(scheduler._isTaskCleanable(myTask2)) # call cleanupTasks directly so we don't have to wait for a # looping call to start it self.assertFalse(myTask1.cleaned) self.assertFalse(myTask2.cleaned) scheduler.removeTasksForConfig(myTask1.configId) scheduler._cleanupTasks() self.assertTrue(myTask1.cleaned) self.assertFalse(myTask2.cleaned)
def testTaskDoneCallback(self): myTask1 = BasicTestTask() myTask1.name = "myTask1" myTask1.configId = "myTask1" called = False def myCallback(taskName): self.assertEquals(taskName, myTask1.name) called = True scheduler = Scheduler() scheduler.addTask(myTask1, myCallback)
def testDeleteTasks(self): myTask1 = BasicTestTask() myTask1.name = "myDevice:myTask1" myTask1.configId = "myDevice" myTask2 = BasicTestTask() myTask2.name = "myDevice:myTask2" myTask2.configId = "myDevice" myTask3 = BasicTestTask() myTask3.name = "myDevice2:myTask3" myTask3.configId = "myDevice2" scheduler = Scheduler() scheduler.addTask(myTask1) scheduler.addTask(myTask2) scheduler.addTask(myTask3) self.assertEquals(len(scheduler._tasks), 3) self.assertTrue(myTask1.name in scheduler._tasks) self.assertTrue(myTask2.name in scheduler._tasks) self.assertTrue(myTask3.name in scheduler._tasks) scheduler.removeTasksForConfig("myDevice") self.assertEquals(len(scheduler._tasks), 1) self.assertFalse(myTask1.name in scheduler._tasks) self.assertFalse(myTask2.name in scheduler._tasks) self.assertTrue(myTask3.name in scheduler._tasks)
def __init__(self, *args, **kwargs): CyclingDaemon.__init__(self, *args, **kwargs) self.options.cycletime = 10 self.log.info("Kicking off init") print "did init" self.schedule = Scheduler(self.options) self.schedule.sendEvent = self.dmd.ZenEventManager.sendEvent self.schedule.monitor = self.options.monitor self.sendEvent(dict( device=self.options.monitor, component="zenactions", eventClass='/Cmd', severity=0, summary="zenactions started"))
def __init__(self): self._configProxy = ConfigurationProxy() self._scheduler = Scheduler() self._configurationLoader = ConfigurationLoaderTask
def __init__(self, *args, **kwargs): CyclingDaemon.__init__(self, *args, **kwargs) log.info("zxchassisdaemon __init__") # Set up slots dictionary self.slots = [None] * self.options.numSlots for slotNum in range(0, len(self.slots)): self.slots[slotNum] = { 'ip': eval("self.options.slot%s_IP" % slotNum) } # Set up ports dictionary # self.ports = [x[:] for x in [["down"]*self.options.maxPorts]*self.options.numSlots] # Set up current model of the chassis using data from Shelf Manager self.setup_chassis(self.slots) # Either do first-time initialization or get device properties. doInit = True devices = self.dmd.Devices.getSubDevices() if devices: for device in self.dmd.Devices.getSubDevices(): groups = device.getDeviceGroupNames() for a in range(0, len(groups)): if groups[a].find(self.options.chassisName) != -1: doInit = False break if doInit == False: break #if os.path.isfile(self.zxdevicesFileName) or os.path.isfile(self.zxchassisFileName): #self.doInit = False if (doInit == True): log.info("__init__ first-time initialization") # Determine the class of the device in each slot. # NOTE: Must call setup_chassis first. See above. self.get_device_classes(self.slots) # Generate a name for each device # NOTE: Class needed to generate name. for slotNum in range(0, len(self.slots)): self.get_device_name(self.slots[slotNum]) # If zxdevice.xml doesn't exist, have Zenoss generate it. if (os.path.isfile(self.zxdevicesFileName) == False): os.system(self.cmdPrefix + "/bin/zendevicedump -o %s" % self.zxdevicesFileName) # Read and parse zxdevice.xml. deviceFile = open(self.zxdevicesFileName) deviceDoc = parse(deviceFile) deviceFile.close() # Generate device for each IP address. for slotNum in range(0, len(self.slots)): self.add_device(deviceDoc, self.slots[slotNum]) # Output document. tempFile = open(self.tempdevicesFileName, 'w') deviceDoc.writexml(tempFile) tempFile.close() # Upload zxdevice.xml to Zenoss if (os.path.isfile(self.tempdevicesFileName) == True): os.system(self.cmdPrefix + "/bin/zendeviceload -i %s" % self.tempdevicesFileName) # Delete the temporary file. os.remove(self.tempdevicesFileName) # Need to commit changes prior to setting properties. commit() # Set device properties via Zenoss: SLOT, NAME, SERIAL NUMBER. self.set_device_properties() # Generate zxdevices.xml to reflect new configuration. os.system(self.cmdPrefix + "/bin/zendevicedump -o %s" % self.zxdevicesFileName) else: log.info("__init__ not first-time initialization") # Use Zenoss device info to set up slots. self.get_device_properties() # Initialize the ports dictionary log.info("before setup_znyxSlot") self.setup_znyxSlot(self.slots) self.schedule = Scheduler(self.options) self.schedule.sendEvent = self.dmd.ZenEventManager.sendEvent self.schedule.monitor = self.options.monitor self.sendEvent( dict(device=self.options.monitor, component="zxchassisdaemon", eventClass='/App/Znyx', severity=0, summary="zxchassisdaemon started"))