def test_set_mode(self): daemon = SystemMonitorDaemon(Conf.PID_FILE_PATH) mode = "mnc" daemon.set_mode(mode) self.assertTrue(daemon._memory) self.assertTrue(daemon._network) self.assertTrue(daemon._cpu)
par = argparse.ArgumentParser(description="System monitor daemon") par.add_argument('action', choices=[Conf.ARG_START, Conf.ARG_STOP, Conf.ARG_RESTART]) par.add_argument(Conf.ARG_CPU, action="store_true", help=Conf.ARG_CPU_HELP) par.add_argument(Conf.ARG_MEM, action="store_true", help=Conf.ARG_MEM_HELP) par.add_argument(Conf.ARG_NET, action="store_true", help=Conf.ARG_NET_HELP) return par if __name__ == "__main__": parser = setup_parser() args = parser.parse_args() daemon = SystemMonitorDaemon(Conf.PID_FILE_PATH) if args.action == "start": mode = "" if getattr(args, Conf.ARG_CPU[1:]): mode += "c" if getattr(args, Conf.ARG_MEM[1:]): mode += "m" if getattr(args, Conf.ARG_NET[1:]): mode += "n" if not mode: mode = "cnm" daemon.set_mode(mode) daemon.start() elif args.action == "stop":
def setup_parser(): par = argparse.ArgumentParser(description="System monitor daemon") par.add_argument('action', choices=[Configuration.ARG_START, Configuration.ARG_STOP, Configuration.ARG_RESTART]) par.add_argument(Configuration.ARG_CPU, action="store_true", help=Configuration.ARG_CPU_HELP) par.add_argument(Configuration.ARG_MEM, action="store_true", help=Configuration.ARG_MEM_HELP) par.add_argument(Configuration.ARG_NET, action="store_true", help=Configuration.ARG_NET_HELP) return par if __name__ == "__main__": parser = setup_parser() args = parser.parse_args() daemon = SystemMonitorDaemon(Configuration.PID_FILE_PATH) if args.action == "start": mode = "" if getattr(args, Configuration.ARG_CPU[1:]): mode += "c" if getattr(args, Configuration.ARG_MEM[1:]): mode += "m" if getattr(args, Configuration.ARG_NET[1:]): mode += "n" if not mode: mode = "cnm" daemon.set_mode(mode) daemon.start() elif args.action == "stop": daemon.stop()
def test_init(self): daemon = SystemMonitorDaemon(Conf.PID_FILE_PATH) self.assertEqual(Conf.PID_FILE_PATH, daemon.pidfile) self.assertFalse(daemon._memory) self.assertFalse(daemon._network) self.assertFalse(daemon._cpu)