def test_120_busnode_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) 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') 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_120_busnode_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) 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") 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_020_busnodeman_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) 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, 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_020_busnodeman_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) 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, 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")
class TestNetworkState1(CommonNetworkState): """Test the network state machine Split cause freeze """ def test_001_request_secondary(self): #~ self.wipTest("Freeze") 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') 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') timeout = 30 stopevent = threading.Event() for i in range(0,timeout*10): self.nodeman.loop(stopevent) #~ self.network.loop(None, stopevent) time.sleep(0.1) 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)