def test_100_node_state(self): with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_nodeman.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid) print node_state.state hadds = { 0 : HADD%(self.add_ctrl,0), } node_state.start() i = 0 while node_state.state != 'ONLINE' and i<120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, 'ONLINE') node_state.stop() i = 0 while node_state.state != 'OFFLINE' and i<120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, 'OFFLINE') node_state = None
def test_100_node_state(self): with mock.patch("sys.argv", [self.prog, "start", "--conf_file=tests/data/test_nodeman.conf"]): options = vars(jnt_parse_args()) options = JNTOptions(options) section = "fake" thread_uuid = options.get_option(section, "uuid") if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, "uuid", "%s" % thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid) print node_state.state hadds = {0: HADD % (self.add_ctrl, 0)} node_state.start() i = 0 while node_state.state != "ONLINE" and i < 120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, "ONLINE") node_state.stop() i = 0 while node_state.state != "OFFLINE" and i < 120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, "OFFLINE") node_state = None
def test_052_dbserver_auto_migrate(self): options = JNTOptions({'conf_file':self.getDataFile(self.server_conf)}) options.load() options.set_option('database','auto_migrate', True) self.start() self.assertHeartbeatNode() self.stop()
def setUp(self): JNTTDBServer.onlyDockerTest() JNTTDBServer.setUp(self) tmp_conf = self.cpTempFile(self.server_conf) options = JNTOptions(options={'conf_file':tmp_conf}) options.set_option('database', 'sqlalchemy.url', self.dbconf[1]['dbconf']) self.server_conf = tmp_conf
def test_001_broadcast_secondary(self): #~ self.wipTest("Freeze") with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_nodeman.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) self.nodeman = JNTBusNodeMan(options, FakeBus(options=options, product_name="Http server"), section, thread_uuid) print self.nodeman.state #~ hadds = { 0 : HADD%(self.node_add_ctrl,0), #~ } self.nodeman.start() i = 0 while not self.nodeman.is_started and i<120: i += 1 print self.nodeman.state time.sleep(1) self.assertEqual(self.nodeman.state, 'ONLINE') with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_network.conf']): options = vars(jnt_parse_args()) stopevent = threading.Event() self.network = JNTNetwork(stopevent, JNTOptions(options), is_primary=False, is_secondary=True, do_heartbeat_dispatch=True) print self.network.state hadds = { 0 : HADD%(self.net_add_ctrl,0), } self.network.boot(hadds) i = 0 while not self.network.is_started and i<150: i += 1 print self.network.state time.sleep(1) print self.network.state self.assertEqual(self.network.state, 'STARTED') time.sleep(30) print "network.nodes", self.network.nodes print "network.users", self.network.users print "network.configs", self.network.configs print "network.basics", self.network.basics print "network.systems", self.network.systems print "network.commands", self.network.commands print "HADD", HADD%(self.node_add_ctrl,0) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.nodes) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.systems) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.configs) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.nodes) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.systems) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.configs) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.basics) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.users) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.commands)
def test_051_dbserver_no_auto_migrate(self): options = JNTOptions({'conf_file':self.getDataFile(self.server_conf)}) options.load() options.set_option('database','auto_migrate', False) try: with self.assertRaises(JanitooException): self.start() self.assertHeartbeatNode() self.stop() finally: options.set_option('database','auto_migrate', True)
def test_010_nodeman_sfm_states(self): with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_nodeman.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid, test=True) node_state.start() #~ net_state.fsm_network_start() while node_state.state != 'ONLINE': node_state.fsm_state_next() node_state.stop()
def test_010_nodeman_sfm_states(self): with mock.patch("sys.argv", [self.prog, "start", "--conf_file=tests/data/test_nodeman.conf"]): options = vars(jnt_parse_args()) options = JNTOptions(options) section = "fake" thread_uuid = options.get_option(section, "uuid") if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, "uuid", "%s" % thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid, test=True) node_state.start() # ~ net_state.fsm_network_start() while node_state.state != "ONLINE": node_state.fsm_state_next() node_state.stop()
def test_301_busnode_find_helpers(self): with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_bus.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) bus = FakeBus(options=options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) node_state = JNTBusNodeMan(options, bus, section, thread_uuid) print node_state.state hadds = { 0 : HADD%(self.add_ctrl,0), } node_state.start() i = 0 while node_state.state != 'ONLINE' and i<120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, 'ONLINE') try: node = node_state.find_node('component1') self.assertTrue('rrd1' in node.name) node = node_state.find_node('componentbad') self.assertEqual(node, None) value = node_state.find_value('component1', 'heartbeat') self.assertTrue('component1' in value.node_uuid) self.assertEqual('heartbeat',value.uuid) value = node_state.find_value('componentbad', 'heartbeat') self.assertEqual(value, None) value = node_state.find_value('component1', 'badbeat') self.assertEqual(value, None) finally: node_state.stop() i = 0 while node_state.state != 'OFFLINE' and i<120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, 'OFFLINE')
def test_301_busnode_find_helpers(self): with mock.patch("sys.argv", [self.prog, "start", "--conf_file=tests/data/test_bus.conf"]): options = vars(jnt_parse_args()) options = JNTOptions(options) bus = FakeBus(options=options) section = "fake" thread_uuid = options.get_option(section, "uuid") if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, "uuid", "%s" % thread_uuid) node_state = JNTBusNodeMan(options, bus, section, thread_uuid) print node_state.state hadds = {0: HADD % (self.add_ctrl, 0)} node_state.start() i = 0 while node_state.state != "ONLINE" and i < 120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, "ONLINE") try: node = node_state.find_node("component1") self.assertTrue("rrd1" in node.name) node = node_state.find_node("componentbad") self.assertEqual(node, None) value = node_state.find_value("component1", "heartbeat") self.assertTrue("component1" in value.node_uuid) self.assertEqual("heartbeat", value.uuid) value = node_state.find_value("componentbad", "heartbeat") self.assertEqual(value, None) value = node_state.find_value("component1", "badbeat") self.assertEqual(value, None) finally: node_state.stop() i = 0 while node_state.state != "OFFLINE" and i < 120: i += 1 print node_state.state time.sleep(1) self.assertEqual(node_state.state, "OFFLINE")
def test_112_node_start_wait_random_stop_more(self): #~ self.skipTest("Pass but freeze on Docker/CI. Surely a non stopped thread in the state machine") self.onlyCITest() with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_nodeman.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid) print node_state.state hadds = { 0 : HADD%(self.add_ctrl,0), } node_state.start() time.sleep(6) node_state.stop() i = 0 while node_state.state != 'OFFLINE' and i<120: i += 1 print node_state.state time.sleep(1) node_state.start() time.sleep(15) node_state.stop() i = 0 while node_state.state != 'OFFLINE' and i<120: i += 1 print node_state.state time.sleep(1) node_state.start() time.sleep(32) node_state.stop() i = 0 while node_state.state != 'OFFLINE' and i<120: i += 1 print node_state.state time.sleep(1)
def test_111_node_start_wait_random_stop(self): # ~ self.skipTest("Pass but freeze on Docker/CI. Surely a non stopped thread in the state machine") self.onlyCITest() with mock.patch("sys.argv", [self.prog, "start", "--conf_file=tests/data/test_nodeman.conf"]): options = vars(jnt_parse_args()) options = JNTOptions(options) section = "fake" thread_uuid = options.get_option(section, "uuid") if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, "uuid", "%s" % thread_uuid) node_state = JNTNodeMan(options, section, thread_uuid) print node_state.state hadds = {0: HADD % (self.add_ctrl, 0)} node_state.start() time.sleep(4) node_state.stop() i = 0 while node_state.state != "OFFLINE" and i < 120: i += 1 print node_state.state time.sleep(1) node_state.start() time.sleep(8) node_state.stop() i = 0 while node_state.state != "OFFLINE" and i < 120: i += 1 print node_state.state time.sleep(1) node_state.start() time.sleep(22) node_state.stop() i = 0 while node_state.state != "OFFLINE" and i < 120: i += 1 print node_state.state time.sleep(1)